| Server IP : 35.80.110.71 / Your IP : 216.73.216.221 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ip-172-31-21-44 6.17.0-1019-aws #19~24.04.1-Ubuntu SMP Tue Jun 23 18:53:06 UTC 2026 x86_64 User : ubuntu ( 1000) PHP Version : 8.3.31 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/elite-events-storybook/ |
Upload File : |
"use strict";(self.webpackChunkelite_events_nextjs=self.webpackChunkelite_events_nextjs||[]).push([[6],{"./src/components/features/admin/affiliates/AffiliateProgram/index.tsx":(__unused_webpack_module,__webpack_exports__,__webpack_require__)=>{__webpack_require__.d(__webpack_exports__,{y:()=>AffiliateProgram});var react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__("./node_modules/next/dist/compiled/react/jsx-runtime.js"),react__WEBPACK_IMPORTED_MODULE_1__=__webpack_require__("./node_modules/next/dist/compiled/react/index.js"),_components_ui_icons_Icon__WEBPACK_IMPORTED_MODULE_2__=__webpack_require__("./src/components/ui/icons/Icon.tsx"),console=__webpack_require__("./node_modules/console-browserify/index.js");const TIER_COLORS={BRONZE:"bg-amber-600",SILVER:"bg-gray-400",GOLD:"bg-yellow-500",PLATINUM:"bg-purple-500"},STATUS_COLORS={PENDING:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200",ACTIVE:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200",SUSPENDED:"bg-red-100 text-red-800 dark:bg-red-900 dark:text-red-200",REJECTED:"bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200",INACTIVE:"bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200",APPROVED:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200",PAID:"bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200",PROCESSING:"bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200",CANCELLED:"bg-gray-100 text-gray-800 dark:bg-gray-700 dark:text-gray-200",COMPLETED:"bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200"};function AffiliateProgram({className=""}){const[activeTab,setActiveTab]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)("overview"),[analytics,setAnalytics]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(null),[affiliates,setAffiliates]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)([]),[sales,setSales]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)([]),[payouts,setPayouts]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)([]),[pagination,setPagination]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)({page:1,limit:20,total:0,totalPages:0}),[loading,setLoading]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(!0),[error,setError]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(null),[analyticsPeriod,setAnalyticsPeriod]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)("30d"),[statusFilter,setStatusFilter]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(""),[tierFilter,setTierFilter]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(""),[searchQuery,setSearchQuery]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(""),[,setSelectedAffiliate]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(null),[editingAffiliate,setEditingAffiliate]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(null),[,setShowCreateModal]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(!1),[rejectingId,setRejectingId]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(null),[rejectionReason,setRejectionReason]=(0,react__WEBPACK_IMPORTED_MODULE_1__.useState)(""),fetchAnalytics=(0,react__WEBPACK_IMPORTED_MODULE_1__.useCallback)(async()=>{try{const response=await fetch(`/api/admin/affiliates/analytics?period=${analyticsPeriod}`),data=await response.json();data.success?setAnalytics(data.data):setError(data.error)}catch(err){setError("Failed to fetch analytics"),console.error(err)}},[analyticsPeriod]),fetchAffiliates=(0,react__WEBPACK_IMPORTED_MODULE_1__.useCallback)(async()=>{setLoading(!0);try{const params=new URLSearchParams({page:pagination.page.toString(),limit:pagination.limit.toString()});statusFilter&¶ms.set("status",statusFilter),tierFilter&¶ms.set("tier",tierFilter),searchQuery&¶ms.set("search",searchQuery);const response=await fetch(`/api/admin/affiliates?${params}`),data=await response.json();data.success?(setAffiliates(data.data),setPagination(data.pagination)):setError(data.error)}catch(err){setError("Failed to fetch affiliates"),console.error(err)}finally{setLoading(!1)}},[pagination.page,pagination.limit,statusFilter,tierFilter,searchQuery]),fetchSales=(0,react__WEBPACK_IMPORTED_MODULE_1__.useCallback)(async()=>{setLoading(!0);try{const params=new URLSearchParams({page:pagination.page.toString(),limit:pagination.limit.toString()});statusFilter&¶ms.set("status",statusFilter);const response=await fetch(`/api/admin/affiliates/sales?${params}`),data=await response.json();data.success?(setSales(data.data),setPagination(data.pagination)):setError(data.error)}catch(err){setError("Failed to fetch sales"),console.error(err)}finally{setLoading(!1)}},[pagination.page,pagination.limit,statusFilter]),fetchPayouts=(0,react__WEBPACK_IMPORTED_MODULE_1__.useCallback)(async()=>{setLoading(!0);try{const params=new URLSearchParams({page:pagination.page.toString(),limit:pagination.limit.toString()});statusFilter&¶ms.set("status",statusFilter);const response=await fetch(`/api/admin/affiliates/payouts?${params}`),data=await response.json();data.success?(setPayouts(data.data),setPagination(data.pagination)):setError(data.error)}catch(err){setError("Failed to fetch payouts"),console.error(err)}finally{setLoading(!1)}},[pagination.page,pagination.limit,statusFilter]);(0,react__WEBPACK_IMPORTED_MODULE_1__.useEffect)(()=>{"overview"===activeTab?fetchAnalytics():"affiliates"===activeTab?fetchAffiliates():"sales"===activeTab?fetchSales():"payouts"===activeTab&&fetchPayouts()},[activeTab,fetchAnalytics,fetchAffiliates,fetchSales,fetchPayouts]);const formatCurrency=amount=>new Intl.NumberFormat("en-US",{style:"currency",currency:"USD"}).format(amount),formatDate=dateString=>new Date(dateString).toLocaleDateString("en-US",{year:"numeric",month:"short",day:"numeric"});return(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:`space-y-6 ${className}`,children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"flex items-center justify-between",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("h1",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:"Affiliate Program"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Manage affiliates, track sales, and process payouts"})]})}),error&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"bg-red-100 dark:bg-red-900 border border-red-400 dark:border-red-700 text-red-700 dark:text-red-200 px-4 py-3 rounded",children:[error,(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>setError(null),className:"float-right font-bold",children:"×"})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"border-b border-gray-200 dark:border-gray-700",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("nav",{className:"flex -mb-px gap-4",children:["overview","affiliates","sales","payouts"].map(tab=>(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>{setActiveTab(tab),setStatusFilter(""),setTierFilter(""),setSearchQuery(""),setPagination(p=>({...p,page:1}))},className:"px-4 py-2 text-sm font-medium border-b-2 transition-colors "+(activeTab===tab?"border-blue-600 text-blue-600 dark:border-blue-400 dark:text-blue-400":"border-transparent text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-300"),children:tab.charAt(0).toUpperCase()+tab.slice(1)},tab))})}),loading&&"overview"!==activeTab?(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})}):(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment,{children:["overview"===activeTab&&(analytics?(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"space-y-6",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"flex justify-end",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("select",{value:analyticsPeriod,onChange:e=>setAnalyticsPeriod(e.target.value),className:"rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-3 py-2 text-sm",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"7d",children:"Last 7 days"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"30d",children:"Last 30 days"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"90d",children:"Last 90 days"})]})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow p-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Total Affiliates"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:analytics.overview.totalAffiliates}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"text-xs text-green-600 dark:text-green-400",children:[analytics.overview.activeAffiliates," active"]})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow p-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Total Clicks"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:analytics.overview.totalClicks.toLocaleString()}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:[analytics.overview.conversionRate.toFixed(2),"% conversion"]})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow p-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Sales This Period"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:formatCurrency(analytics.overview.totalSalesAmount)}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:[analytics.overview.totalSalesCount," orders"]})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow p-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:"Commissions"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-2xl font-bold text-gray-900 dark:text-white",children:formatCurrency(analytics.overview.totalCommissionsAllTime)}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"text-xs text-yellow-600 dark:text-yellow-400",children:[formatCurrency(analytics.overview.pendingCommissions)," pending"]})]})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow p-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-4",children:"Affiliates by Tier"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"flex gap-4 flex-wrap",children:analytics.affiliatesByTier.map(tier=>(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"flex items-center gap-2",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:`w-3 h-3 rounded-full ${TIER_COLORS[tier.tier]||"bg-gray-400"}`}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("span",{className:"text-sm text-gray-700 dark:text-gray-300",children:[tier.tier,": ",tier.count]})]},tier.tier))})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow p-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-4",children:"Top Affiliates"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"overflow-x-auto",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("thead",{children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("tr",{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Affiliate"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-2 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Tier"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-2 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Clicks"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-2 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Sales"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-2 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Earnings"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-2 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Conv. Rate"})]})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:analytics.topAffiliates.map(affiliate=>(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("tr",{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-2 whitespace-nowrap",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:affiliate.code}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:affiliate.user?.name||affiliate.user?.email})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-2 whitespace-nowrap",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium text-white ${TIER_COLORS[affiliate.tier]}`,children:affiliate.tier})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-2 whitespace-nowrap text-right text-sm text-gray-700 dark:text-gray-300",children:affiliate.totalClicks.toLocaleString()}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-2 whitespace-nowrap text-right text-sm text-gray-700 dark:text-gray-300",children:formatCurrency(affiliate.totalSales)}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-2 whitespace-nowrap text-right text-sm text-gray-700 dark:text-gray-300",children:formatCurrency(affiliate.totalEarnings)}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-2 whitespace-nowrap text-right text-sm text-gray-700 dark:text-gray-300",children:[affiliate.conversionRate.toFixed(2),"%"]})]},affiliate.id))})]})})]})]}):(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"flex justify-center items-center h-64",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-blue-600"})})),"affiliates"===activeTab&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"space-y-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"flex flex-wrap gap-4 items-center",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("input",{type:"text",placeholder:"Search by code or website...",value:searchQuery,onChange:e=>setSearchQuery(e.target.value),className:"flex-1 min-w-[200px] rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-3 py-2 text-sm"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("select",{value:statusFilter,onChange:e=>setStatusFilter(e.target.value),className:"rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-3 py-2 text-sm",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"",children:"All Status"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"PENDING",children:"Pending"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"ACTIVE",children:"Active"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"SUSPENDED",children:"Suspended"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"REJECTED",children:"Rejected"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"INACTIVE",children:"Inactive"})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("select",{value:tierFilter,onChange:e=>setTierFilter(e.target.value),className:"rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-3 py-2 text-sm",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"",children:"All Tiers"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"BRONZE",children:"Bronze"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"SILVER",children:"Silver"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"GOLD",children:"Gold"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"PLATINUM",children:"Platinum"})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("button",{onClick:()=>setShowCreateModal(!0),className:"px-4 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 text-sm",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)(_components_ui_icons_Icon__WEBPACK_IMPORTED_MODULE_2__.I,{name:"plus",className:"w-4 h-4 inline mr-1"}),"Add Affiliate"]})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow overflow-hidden",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"overflow-x-auto",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("thead",{className:"bg-gray-50 dark:bg-gray-700",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("tr",{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Affiliate"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Status"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Tier"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Commission"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Earnings"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Conv. Rate"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-center text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Actions"})]})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:affiliates.map(affiliate=>(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-700",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:affiliate.code}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:affiliate.user?.name||affiliate.user?.email})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${STATUS_COLORS[affiliate.status]}`,children:affiliate.status})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium text-white ${TIER_COLORS[affiliate.tier]}`,children:affiliate.tier})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap text-right text-sm text-gray-700 dark:text-gray-300",children:[affiliate.commissionRate,"%"]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap text-right text-sm text-gray-700 dark:text-gray-300",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{children:formatCurrency(affiliate.totalEarnings)}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"text-xs text-yellow-600 dark:text-yellow-400",children:[formatCurrency(affiliate.pendingEarnings)," pending"]})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap text-right text-sm text-gray-700 dark:text-gray-300",children:[affiliate.conversionRate.toFixed(2),"%"]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap text-center",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>setSelectedAffiliate(affiliate),className:"text-blue-600 dark:text-blue-400 hover:underline text-sm mr-2",children:"View"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>setEditingAffiliate(affiliate),className:"text-gray-600 dark:text-gray-400 hover:underline text-sm",children:"Edit"})]})]},affiliate.id))})]})}),pagination.totalPages>1&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"px-4 py-3 border-t border-gray-200 dark:border-gray-700 flex items-center justify-between",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"text-sm text-gray-500 dark:text-gray-400",children:["Showing ",(pagination.page-1)*pagination.limit+1," to"," ",Math.min(pagination.page*pagination.limit,pagination.total)," of"," ",pagination.total]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"flex gap-2",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>setPagination(p=>({...p,page:Math.max(1,p.page-1)})),disabled:1===pagination.page,className:"px-3 py-1 rounded border border-gray-300 dark:border-gray-600 text-sm disabled:opacity-50",children:"Previous"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>setPagination(p=>({...p,page:Math.min(p.totalPages,p.page+1)})),disabled:pagination.page===pagination.totalPages,className:"px-3 py-1 rounded border border-gray-300 dark:border-gray-600 text-sm disabled:opacity-50",children:"Next"})]})]})]})]}),"sales"===activeTab&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"space-y-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"flex flex-wrap gap-4 items-center",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("select",{value:statusFilter,onChange:e=>setStatusFilter(e.target.value),className:"rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-3 py-2 text-sm",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"",children:"All Status"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"PENDING",children:"Pending"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"APPROVED",children:"Approved"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"REJECTED",children:"Rejected"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"PAID",children:"Paid"})]})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow overflow-hidden",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"overflow-x-auto",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("thead",{className:"bg-gray-50 dark:bg-gray-700",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("tr",{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Affiliate"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Order"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Order Total"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Commission"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Status"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Date"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-center text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Actions"})]})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:sales.map(sale=>(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-700",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:sale.affiliateCode}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:sale.affiliateUser?.name||sale.affiliateUser?.email})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap text-sm text-gray-700 dark:text-gray-300",children:["#",sale.orderId]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-3 whitespace-nowrap text-right text-sm text-gray-700 dark:text-gray-300",children:formatCurrency(sale.orderTotal)}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap text-right text-sm text-gray-700 dark:text-gray-300",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{children:formatCurrency(sale.commissionAmount)}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:[sale.commissionRate,"%"]})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${STATUS_COLORS[sale.status]}`,children:sale.status})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-3 whitespace-nowrap text-sm text-gray-700 dark:text-gray-300",children:formatDate(sale.createdAt)}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap text-center",children:["PENDING"===sale.status&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment,{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>(async saleId=>{try{const response=await fetch("/api/admin/affiliates/sales",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({saleId,action:"approve"})}),result=await response.json();result.success?fetchSales():setError(result.error)}catch(err){setError("Failed to approve sale"),console.error(err)}})(sale.id),className:"text-green-600 dark:text-green-400 hover:underline text-sm mr-2",children:"Approve"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>setRejectingId(sale.id),className:"text-red-600 dark:text-red-400 hover:underline text-sm",children:"Reject"})]}),"REJECTED"===sale.status&&sale.rejectionReason&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:sale.rejectionReason})]})]},sale.id))})]})})})]}),"payouts"===activeTab&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"space-y-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"flex flex-wrap gap-4 items-center",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("select",{value:statusFilter,onChange:e=>setStatusFilter(e.target.value),className:"rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 px-3 py-2 text-sm",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"",children:"All Status"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"PENDING",children:"Pending"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"PROCESSING",children:"Processing"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"COMPLETED",children:"Completed"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"CANCELLED",children:"Cancelled"})]})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow overflow-hidden",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"overflow-x-auto",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("table",{className:"min-w-full divide-y divide-gray-200 dark:divide-gray-700",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("thead",{className:"bg-gray-50 dark:bg-gray-700",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("tr",{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Affiliate"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Amount"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Method"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Status"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Requested"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("th",{className:"px-4 py-3 text-center text-xs font-medium text-gray-500 dark:text-gray-400 uppercase",children:"Actions"})]})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("tbody",{className:"divide-y divide-gray-200 dark:divide-gray-700",children:payouts.map(payout=>(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("tr",{className:"hover:bg-gray-50 dark:hover:bg-gray-700",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-sm font-medium text-gray-900 dark:text-white",children:payout.affiliateCode}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:payout.affiliateUser?.name||payout.affiliateUser?.email})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-3 whitespace-nowrap text-right text-sm text-gray-700 dark:text-gray-300",children:formatCurrency(payout.amount)}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-3 whitespace-nowrap text-sm text-gray-700 dark:text-gray-300",children:payout.method||"N/A"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-3 whitespace-nowrap",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("span",{className:`inline-flex items-center px-2 py-0.5 rounded text-xs font-medium ${STATUS_COLORS[payout.status]}`,children:payout.status})}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("td",{className:"px-4 py-3 whitespace-nowrap text-sm text-gray-700 dark:text-gray-300",children:formatDate(payout.requestedAt)}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("td",{className:"px-4 py-3 whitespace-nowrap text-center",children:["PENDING"===payout.status&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)(react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.Fragment,{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>(async payoutId=>{try{const response=await fetch("/api/admin/affiliates/payouts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({payoutId,action:"process"})}),result=await response.json();result.success?fetchPayouts():setError(result.error)}catch(err){setError("Failed to process payout"),console.error(err)}})(payout.id),className:"text-green-600 dark:text-green-400 hover:underline text-sm mr-2",children:"Process"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>(async payoutId=>{try{const response=await fetch("/api/admin/affiliates/payouts",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({payoutId,action:"cancel"})}),result=await response.json();result.success?fetchPayouts():setError(result.error)}catch(err){setError("Failed to cancel payout"),console.error(err)}})(payout.id),className:"text-red-600 dark:text-red-400 hover:underline text-sm",children:"Cancel"})]}),payout.transactionId&&(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("span",{className:"text-xs text-gray-500 dark:text-gray-400",children:["Tx: ",payout.transactionId]})]})]},payout.id))})]})})})]})]}),editingAffiliate?(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full mx-4 p-6",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-4",children:"Edit Affiliate"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"space-y-4",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Status"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("select",{value:editingAffiliate.status||"",onChange:e=>setEditingAffiliate({...editingAffiliate,status:e.target.value}),className:"w-full rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 px-3 py-2 text-sm",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"PENDING",children:"Pending"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"ACTIVE",children:"Active"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"SUSPENDED",children:"Suspended"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"REJECTED",children:"Rejected"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"INACTIVE",children:"Inactive"})]})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Tier"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("select",{value:editingAffiliate.tier||"",onChange:e=>setEditingAffiliate({...editingAffiliate,tier:e.target.value}),className:"w-full rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 px-3 py-2 text-sm",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"BRONZE",children:"Bronze"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"SILVER",children:"Silver"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"GOLD",children:"Gold"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("option",{value:"PLATINUM",children:"Platinum"})]})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Commission Rate (%)"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("input",{type:"number",value:editingAffiliate.commissionRate||0,onChange:e=>setEditingAffiliate({...editingAffiliate,commissionRate:parseFloat(e.target.value)}),min:"0",max:"100",step:"0.1",className:"w-full rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 px-3 py-2 text-sm"})]})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>setEditingAffiliate(null),className:"px-4 py-2 rounded border border-gray-300 dark:border-gray-600 text-sm hover:bg-gray-100 dark:hover:bg-gray-700",children:"Cancel"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>editingAffiliate.id&&(async(id,data)=>{try{const response=await fetch(`/api/admin/affiliates/${id}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify(data)}),result=await response.json();result.success?(fetchAffiliates(),setEditingAffiliate(null),setSelectedAffiliate(null)):setError(result.error)}catch(err){setError("Failed to update affiliate"),console.error(err)}})(editingAffiliate.id,{status:editingAffiliate.status,tier:editingAffiliate.tier,commissionRate:editingAffiliate.commissionRate}),className:"px-4 py-2 bg-blue-600 text-white rounded text-sm hover:bg-blue-700",children:"Save Changes"})]})]})}):null,null===rejectingId?null:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50",children:(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"bg-white dark:bg-gray-800 rounded-lg shadow-xl max-w-md w-full mx-4 p-6",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("h3",{className:"text-lg font-medium text-gray-900 dark:text-white mb-4",children:"Reject Sale"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("label",{className:"block text-sm font-medium text-gray-700 dark:text-gray-300 mb-1",children:"Rejection Reason"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("textarea",{value:rejectionReason,onChange:e=>setRejectionReason(e.target.value),rows:3,className:"w-full rounded-md border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 px-3 py-2 text-sm",placeholder:"Please provide a reason for rejecting this sale..."})]}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsxs)("div",{className:"flex justify-end gap-2 mt-6",children:[(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>{setRejectingId(null),setRejectionReason("")},className:"px-4 py-2 rounded border border-gray-300 dark:border-gray-600 text-sm hover:bg-gray-100 dark:hover:bg-gray-700",children:"Cancel"}),(0,react_jsx_runtime__WEBPACK_IMPORTED_MODULE_0__.jsx)("button",{onClick:()=>(async saleId=>{if(rejectionReason.trim())try{const response=await fetch("/api/admin/affiliates/sales",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({saleId,action:"reject",rejectionReason:rejectionReason.trim()})}),result=await response.json();result.success?(fetchSales(),setRejectingId(null),setRejectionReason("")):setError(result.error)}catch(err){setError("Failed to reject sale"),console.error(err)}else setError("Rejection reason is required")})(rejectingId),className:"px-4 py-2 bg-red-600 text-white rounded text-sm hover:bg-red-700",children:"Reject Sale"})]})]})})]})}}}]);