1import{r as i,s as Y,j as e,b as we,L as ie}from"./site-C5SUB8ov.js";import{u as me,X as $e,L as oe,aL as pe,aN as ye,aO as be,aP as ce,aQ as _e,bd as fe,bp as Se,k as De,c as F,aJ as Ce,C as Te,bo as ke,bx as he,bF as xe,x as Ue}from"./main-_fPdXjGG.js";import{L as Ne}from"./LineChart-DQITDbHq.js";import{L as re}from"./Line-D2xIp0fE.js";import{P as je}from"./percent-udzuaBsR.js";import{C as Le}from"./coins-DNSa8lar.js";const se="admin.nayax.common",o="admin.nayax.discounts";function P(s){try{return new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN",maximumFractionDigits:2}).format(s||0)}catch{return`${(s||0).toFixed(2)} PLN`}}function ae(s,t){try{return new Intl.NumberFormat(t,{maximumFractionDigits:0}).format(s||0)}catch{return String(s||0)}}function Oe(s,t){if(!s)return"â";const u=new Date(s);return Number.isNaN(u.getTime())?String(s):u.toLocaleString(t,{year:"numeric",month:"2-digit",day:"2-digit",hour:"2-digit",minute:"2-digit"})}function Ie(s,t){if(!s)return"â";const u=new Date(s);return Number.isNaN(u.getTime())?String(s):u.toLocaleDateString(t,{year:"numeric",month:"long",day:"numeric"})}function Me({isOpen:s,onClose:t,companyId:u,scope:m,start:w,end:Z,statuses:j,types:q,prepaidFilter:T="exclude"}){const[R,$]=i.useState(!1),[z,S]=i.useState(null),[k,L]=i.useState(null),[ee,D]=i.useState([]),[C,O]=i.useState([]),[f,I]=i.useState(0),[K,G]=i.useState(!1),{t:n,language:h}=me(),v=h==="pl"?"pl-PL":h==="en"?"en-GB":"uk-UA",U=100,X=i.useMemo(()=>m?m.kind==="operator"?m.title||n(`${se}.terminalTitle`,{id:m.operatorId}):m.title||n(`${se}.franchiseeDefault`):n(`${o}.drilldown.defaultTitle`),[m,n]),M=i.useMemo(()=>({p_company_id:u,p_start:w,p_end:Z,p_statuses:j&&j.length>0?j:null,p_types:q&&q.length>0?q:null,p_prepaid_filter:T}),[u,w,Z,j,q,T]),A=i.useCallback(async()=>{if(!(!s||!u||!m))try{$(!0),S(null);const d=m.kind==="operator"?m.operatorId:null,b=m.kind==="user"?m.userId:null,[_,E,W]=await Promise.all([Y.rpc("get_nayax_discount_kpis",{...M,p_operator_id:d,p_user_id:b}),Y.rpc("get_nayax_discount_timeseries",{...M,p_operator_id:d,p_user_id:b}),Y.rpc("get_nayax_discount_recent_transactions",{...M,p_operator_id:d,p_user_id:b,p_limit:U,p_offset:f*U})]);if(_.error)throw _.error;if(E.error)throw E.error;if(W.error)throw W.error;const g=(_.data||[])[0];L({total_discount_amount:Number((g==null?void 0:g.total_discount_amount)||0),discount_tx_count:Number((g==null?void 0:g.discount_tx_count)||0),avg_discount:Number((g==null?void 0:g.avg_discount)||0),unique_terminals:Number((g==null?void 0:g.unique_terminals)||0),unique_discount_cards:Number((g==null?void 0:g.unique_discount_cards)||0)}),D((E.data||[]).map(l=>({day:String(l.day),total_discount_amount:Number(l.total_discount_amount||0),discount_tx_count:Number(l.discount_tx_count||0),avg_discount:Number(l.avg_discount||0),unique_terminals:Number(l.unique_terminals||0)}))),O((W.data||[]).map(l=>({transaction_id:String(l.transaction_id),operator_id:String(l.operator_id),coffee_bar_name:l.coffee_bar_name??null,coffee_bar_address:l.coffee_bar_address??null,mapping_user_name:l.mapping_user_name??null,discount_card_number:l.discount_card_number??null,machine_price:Number(l.machine_price||0),payed_value:Number(l.payed_value||0),discount_amount:Number(l.discount_amount||0),product_discount_amount:Number(l.product_discount_amount||0),product_discount_percentage:Number(l.product_discount_percentage||0),currency:l.currency??null,transaction_type:l.transaction_type??null,transaction_status:l.transaction_status??null,payment_method:l.payment_method??null,product_name:l.product_name??null,transaction_date:l.transaction_date??null})))}catch(d){console.error("NayaxDiscountDrilldownModal load error",d),S((d==null?void 0:d.message)||n(`${o}.drilldown.loadFailed`)),L(null),D([]),O([])}finally{$(!1)}},[M,u,s,f,m,n]);return i.useEffect(()=>{A()},[A]),i.useEffect(()=>{s||(I(0),G(!1))},[s]),!s||!m?null:e.jsx("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 p-4",children:e.jsxs("div",{className:"relative w-full max-w-6xl max-h-[90vh] bg-white rounded-lg shadow-xl flex flex-col overflow-hidden",children:[e.jsxs("div",{className:"flex items-center justify-between border-b px-6 py-4",children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:X}),e.jsx("button",{onClick:t,className:"text-gray-400 hover:text-gray-600 transition-colors","aria-label":n(`${se}.close`),children:e.jsx($e,{className:"h-5 w-5"})})]}),e.jsxs("div",{className:"flex-1 overflow-y-auto p-6",children:[R&&e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(oe,{className:"h-8 w-8 animate-spin text-blue-600"})}),z&&e.jsx("div",{className:"bg-red-50 border border-red-200 rounded-lg p-4 mb-6",children:e.jsx("p",{className:"text-red-800 text-sm",children:z})}),!R&&!z&&k&&e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-5 ga
1p-4",children:[e.jsxs("div",{className:"bg-gradient-to-br from-orange-50 to-orange-100 rounded-lg p-4 border border-orange-200",children:[e.jsx("div",{className:"text-sm text-orange-600 font-medium mb-1",children:n(`${o}.kpi.totalDiscountAmount`)}),e.jsx("div",{className:"text-2xl font-bold text-orange-900",children:P(k.total_discount_amount)})]}),e.jsxs("div",{className:"bg-gradient-to-br from-blue-50 to-blue-100 rounded-lg p-4 border border-blue-200",children:[e.jsx("div",{className:"text-sm text-blue-600 font-medium mb-1",children:n(`${o}.kpi.discountTxCount`)}),e.jsx("div",{className:"text-2xl font-bold text-blue-900",children:ae(k.discount_tx_count,v)})]}),e.jsxs("div",{className:"bg-gradient-to-br from-purple-50 to-purple-100 rounded-lg p-4 border border-purple-200",children:[e.jsx("div",{className:"text-sm text-purple-600 font-medium mb-1",children:n(`${o}.kpi.avgDiscount`)}),e.jsx("div",{className:"text-2xl font-bold text-purple-900",children:P(k.avg_discount)})]}),e.jsxs("div",{className:"bg-gradient-to-br from-green-50 to-green-100 rounded-lg p-4 border border-green-200",children:[e.jsx("div",{className:"text-sm text-green-600 font-medium mb-1",children:n(`${o}.kpi.uniqueTerminals`)}),e.jsx("div",{className:"text-2xl font-bold text-green-900",children:ae(k.unique_terminals,v)})]}),e.jsxs("div",{className:"bg-gradient-to-br from-pink-50 to-pink-100 rounded-lg p-4 border border-pink-200",children:[e.jsx("div",{className:"text-sm text-pink-600 font-medium mb-1",children:n(`${o}.kpi.uniqueCards`)}),e.jsx("div",{className:"text-2xl font-bold text-pink-900",children:ae(k.unique_discount_cards,v)})]})]}),e.jsxs("div",{className:"bg-white border rounded-lg p-4",children:[e.jsx("h3",{className:"text-lg font-semibold text-gray-900 mb-4",children:n(`${o}.charts.chartDaily`)}),ee.length===0?e.jsx("p",{className:"text-gray-500 text-center py-8",children:n(`${se}.noData`)}):e.jsx(pe,{width:"100%",height:300,children:e.jsxs(Ne,{data:ee,children:[e.jsx(ye,{strokeDasharray:"3 3"}),e.jsx(be,{dataKey:"day",tick:{fontSize:12}}),e.jsx(ce,{yAxisId:"left",tick:{fontSize:12}}),e.jsx(ce,{yAxisId:"right",orientation:"right",tick:{fontSize:12}}),e.jsx(_e,{content:({active:d,payload:b})=>{if(!d||!b||b.length===0)return null;const _=b[0].payload;return e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg shadow-lg p-3",children:[e.jsx("div",{className:"font-semibold text-gray-900 mb-2",children:Ie(_.day,v)}),e.jsxs("div",{className:"space-y-1 text-sm",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-gray-600",children:n(`${o}.tooltips.discountAmount`)}),e.jsx("span",{className:"font-semibold text-orange-600",children:P(_.total_discount_amount)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-gray-600",children:n(`${o}.tooltips.transactions`)}),e.jsx("span",{className:"font-semibold text-blue-600",children:ae(_.discount_tx_count,v)})]}),e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsx("span",{className:"text-gray-600",children:n(`${o}.tooltips.avgDiscount`)}),e.jsx("span",{className:"font-semibold text-purple-600",children:P(_.avg_discount)})]})]})]})}}),e.jsx(fe,{}),e.jsx(re,{yAxisId:"left",type:"monotone",dataKey:"total_discount_amount",stroke:"#f97316",strokeWidth:2,name:n(`${o}.charts.legendAmountPln`),dot:{r:3}}),e.jsx(re,{yAxisId:"right",type:"monotone",dataKey:"discount_tx_count",stroke:"#3b82f6",strokeWidth:2,name:n(`${o}.charts.legendTxCount`),dot:{r:3}})]})})]}),e.jsxs("div",{className:"bg-white border rounded-lg",children:[e.jsxs("button",{onClick:()=>G(!K),className:"w-full flex items-center justify-between p-4 hover:bg-gray-50 transition-colors",children:[e.jsxs("h3",{className:"text-lg font-semibold text-gray-900",children:[n(`${o}.drilldown.transactions.title`)," ",C.length>0&&`(${C.length})`]}),K?e.jsx(Se,{className:"h-5 w-5 text-gray-400"}):e.jsx(De,{className:"h-5 w-5 text-gray-400"})]}),K&&e.jsx("div",{className:"border-t",children:C.length===0?e.jsx("p",{className:"text-gray-500 text-center py-8",children:n(`${o}.drilldown.transactions.empty`)}):e.jsxs(e.Fragment,{children:[e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-gray-900",children:n(`${o}.drilldown.columns.date`)}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-gray-900",children:n(`${o}.drilldown.columns.terminal`)}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-gray-900",children:n(`${o}.drilldown.columns.franchisee`)}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-gray-900",children:n(`${o}.drilldown.columns.discountCard`)}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold text-gray-900",children:n(`${o}.drilldown.columns.price`)}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold text-gray-900",children:n(`${o}.drilldown.columns.paid`)}),e.jsx("th",{className:"px-4 py-3 text-right font-semibold text-gray-900",children:n(`${o}.drilldown.columns.discount`)}),e.jsx("th",{className:"px-4 py-3 text-left font-semibold text-gray-900",children:n(`${o}.drilldown.columns.product`)})]})}),e.jsx("tbody",{className:"divide-y divide-gray-200",children:C.map((d,b)=>e.jsxs("tr",{className:"hover:bg-gray-50",children:[e.jsx("td",{className:"px-4 py-3 whitespace-nowrap text-gray-600",children:Oe(d.transaction_date,v)}),e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{className:"text-gray-900 font-medium",children:d.coffee_bar_name||d.operator_id}),d.coffee_bar_address&&e.jsx("div",{className:"text-xs text-gray-500",children:d.coffee_bar_address})]}),e.jsx("td",{className:"px-4 py-3 text-gray-600",children:d.mapping_user_name||"â"}),e.jsx("td",{className:"px-4 py-3",children:e.jsx("span",{className:"font-mono text-xs bg-gray-100 px-2 py-1 rounded",children:d.discount_card_number||"â"})}),e.jsx("td",{className:"px-4 py-3 text-right text-gray-900",children:P(d.machine_price)}),e.jsx("td",{className:"px-4 py-3 text-right text-gray-900",children:P(d.payed_value)}),e.jsx("td",{className:"px-4 py-3 text-right",children:e.jsx("span",{className:"font-semibold text-orange-600",children:P(d.discount_amount)})}),e.jsx("td",{className:"px-4 py-3 text-gray-600",children:d.product_name||"â"})]},`${d.transaction_id}-${b}`))})]})}),C.length>=U&&e.jsxs("div",{className:"flex items-center justify-between border-t px-4 py-3 bg-gray-50",children:[e.jsxs("button",{onClick:()=>I(Math.max(0,f-1)),disabled:f===0,className:F("flex items-center gap-2 px-3 py-1.5 rounded text-sm font-medium transition-colors",f===0?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-200"),children:[e.jsx(Ce,{className:"h-4 w-4"}),n(`${o}.drilldown.transactions.prev`)]}),e.jsx("span",{className:"text-sm text-gray-600",children:n(`${o}.drilldown.transactions.page`,{page:f+1})}),e.jsxs("button",{onClick:()=>I(f+1),disabled:C.length<U,className:F("flex items-center gap-2 px-3 py-1.5 rounded text-sm font-medium transition-colors",C.length<U?"text-gray-400 cursor-not-allowed":"text-gray-700 hover:bg-gray-200"),children:[n(`${o}.drilldown.transactions.next`),e.jsx(Te,{className:"h-4 w-4"})]})]})]})})]})]})]})]})})}const r="admin.nayax.common",x="admin.nayax.discounts",Pe=["Settled","Sale","approved","declined","pending"],Fe=["sale","refund","void"],Ye=[{value:"exclude",labelKey:`${r}.filters.prepaidExclude`},{value:"all",labelKey:`${r}.filters.prepaidAll`},{value:"only",labelKey:`${r}.filters.prepaidOnly`}];function H(s){try{return new Intl.NumberFormat("pl-PL",{style:"currency",currency:"PLN",maximumFractionDigits:2}).format(s||0)}catch{return`${(s||0).toFixed(2)} PLN`}}function B(s,t){try{return new Intl.NumberFormat(t,{maximumFractionDigits:0}).format(s||0)}catch{return String(s||0)}}function le(s){const t=new Date;return t.setUTCHours(0,0,0,0),t.setUTCDate(t.getUTCDate()-s),t.toISOString()}function qe(){const s=new Date;return s.setUTCHours(23,59,59,999),s.toISOString()}function Ke(){const s=new Date;return s.setUTCHours(0,0,0,0),s.toISOString()}function Ae(){const s=new Date;return s.setUTCHours(0,0,0,0),s.setUTCDate(s.getUTCDate()-1),s.toISOString()}function Ee(){const s=new Date;return s.setUTCHours(23,59,59,999),s.setUTCDate(s.getUTCDate()-1),s.toISOString()}function We(){const s=new Date,t=s.getUTCDay(),u=t===0?-6:1-t;return s.setUTCDate(s.getUTCDate()+u),s.setUTCHours(0,0,0,0),s.toISOString()}function He(){const s=new Date,t=s.getUTCDay(),u=t===0?-6:1-t;return s.setUTCDate(s.getUTCDate()+u-7),s.setUTCHours(0,0,0,0),s.toISOString()}function Be(){const s=new Date,t=s.getUTCDay(),u=t===0?-6:1-t;return s.setUTCDate(s.getUTCDate()+u-1),s.setUTCHours(23,59,59,999),s.toISOString()}function ze(){const s=new Date;return new Date(Date.UTC(s.getUTCFullYear(),s.getUTCMonth(),1,0,0,0,0)).toISOString()}function Ge(){const s=new Date;return new Date(Date.UTC(s.getUTCFullYear(),s.getUTCMonth()-1,1,0,0,0,0)).toISOString()}function Xe(){const s=new Date;return new Date(Date.UTC(s.getUTCFullYear(),s.getUTCMonth(),0,23,59,59,999)).toISOString()}function Je(){const s=new Date;return new Date(Date.UTC(s.getUTCFullYear(),0,1,0,0,0,0)).toISOString()}function Qe(){const s=new Date;return new Date(Date.UTC(s.getUTCFullYear()-1,0,1,0,0,0,0)).toISOString()}function Ve(){const s=new Date;return new Date(Date.UTC(s.getUTCFullYear()-1,11,31,23,59,59,999)).toISOString()}const N={today:`${r}
1.period.today`,yesterday:`${r}.period.yesterday`,thisWeek:`${r}.period.thisWeek`,lastWeek:`${r}.period.lastWeek`,"7d":`${r}.period.last7d`,"30d":`${r}.period.last30d`,thisMonth:`${r}.period.thisMonth`,lastMonth:`${r}.period.lastMonth`,thisYear:`${r}.period.thisYear`,lastYear:`${r}.period.lastYear`},Ze=[{preset:"today",labelKey:`${r}.period.today`},{preset:"yesterday",labelKey:`${r}.period.yesterday`},{preset:"thisWeek",labelKey:`${r}.period.thisWeek`},{preset:"lastWeek",labelKey:`${r}.period.lastWeek`},{preset:"7d",labelKey:`${r}.period.last7d`},{preset:"30d",labelKey:`${r}.period.last30d`},{preset:"thisMonth",labelKey:`${r}.period.thisMonth`},{preset:"lastMonth",labelKey:`${r}.period.lastMonth`},{preset:"thisYear",labelKey:`${r}.period.thisYear`},{preset:"lastYear",labelKey:`${r}.period.lastYear`},{preset:"custom",labelKey:`${r}.period.custom`}];function Re({companyId:s}){const{t,language:u}=me(),m=u==="pl"?"pl-PL":u==="en"?"en-GB":"uk-UA",[w,Z]=i.useState("30d"),[j,q]=i.useState(""),[T,R]=i.useState(""),[$,z]=i.useState(["Settled","Sale"]),[S,k]=i.useState(["sale"]),[L,ee]=i.useState("exclude"),[D,C]=i.useState(""),[O,f]=i.useState(!0),[I,K]=i.useState(!1),[G,n]=i.useState(null),[h,v]=i.useState(null),[U,X]=i.useState([]),[M,A]=i.useState([]),[d,b]=i.useState([]),[_,E]=i.useState("amount"),[W,g]=i.useState(null),l=i.useMemo(()=>{if(w==="custom"&&j&&T)return{start:new Date(j).toISOString(),end:new Date(T+"T23:59:59.999Z").toISOString(),label:`${j} â ${T}`};const a=qe();switch(w){case"today":return{start:Ke(),end:a,label:t(N.today)};case"yesterday":return{start:Ae(),end:Ee(),label:t(N.yesterday)};case"thisWeek":return{start:We(),end:a,label:t(N.thisWeek)};case"lastWeek":return{start:He(),end:Be(),label:t(N.lastWeek)};case"7d":return{start:le(6),end:a,label:t(N["7d"])};case"30d":return{start:le(29),end:a,label:t(N["30d"])};case"thisMonth":return{start:ze(),end:a,label:t(N.thisMonth)};case"lastMonth":return{start:Ge(),end:Xe(),label:t(N.lastMonth)};case"thisYear":return{start:Je(),end:a,label:t(N.thisYear)};case"lastYear":return{start:Qe(),end:Ve(),label:t(N.lastYear)};default:return{start:le(29),end:a,label:t(N["30d"])}}},[w,j,T,t]),J=i.useMemo(()=>({p_company_id:s,p_start:l.start,p_end:l.end,p_statuses:$.length>0?$:null,p_types:S.length>0?S:null,p_prepaid_filter:L}),[s,l.start,l.end,$,S,L]),te=i.useCallback(async()=>{if(!s){v(null),X([]),A([]),b([]),f(!1);return}try{n(null),f(!0);const[a,p,Q,ne]=await Promise.all([Y.rpc("get_nayax_discount_kpis",{...J,p_operator_id:null,p_actor_id:null,p_user_id:null}),Y.rpc("get_nayax_discount_timeseries",{...J,p_operator_id:null,p_actor_id:null,p_user_id:null}),Y.rpc("get_nayax_discount_stats_by_terminal",{...J,p_query:D.trim()?D.trim():null,p_limit:50}),Y.rpc("get_nayax_discount_stats_by_franchisee",{...J,p_query:D.trim()?D.trim():null,p_limit:50})]);if(a.error)throw a.error;if(p.error)throw p.error;if(Q.error)throw Q.error;if(ne.error)throw ne.error;const y=(a.data||[])[0];v({total_discount_amount:Number((y==null?void 0:y.total_discount_amount)||0),discount_tx_count:Number((y==null?void 0:y.discount_tx_count)||0),avg_discount:Number((y==null?void 0:y.avg_discount)||0),unique_terminals:Number((y==null?void 0:y.unique_terminals)||0),unique_discount_cards:Number((y==null?void 0:y.unique_discount_cards)||0)}),X((p.data||[]).map(c=>({day:String(c.day),total_discount_amount:Number(c.total_discount_amount||0),discount_tx_count:Number(c.discount_tx_count||0),avg_discount:Number(c.avg_discount||0),unique_terminals:Number(c.unique_terminals||0)}))),A((Q.data||[]).map(c=>({operator_id:String(c.operator_id),terminal_name:c.terminal_name??null,address:c.address??null,total_discount_amount:Number(c.total_discount_amount||0),discount_transaction_count:Number(c.discount_transaction_count||0),avg_discount:Number(c.avg_discount||0),linked_actor_id:c.linked_actor_id??null,linked_user_id:c.linked_user_id??null,linked_first_name:c.linked_first_name??null,linked_last_name:c.linked_last_name??null}))),b((ne.data||[]).map(c=>({mapping_user_id:String(c.mapping_user_id),mapping_user_name:c.mapping_user_name??null,total_discount_amount:Number(c.total_discount_amount||0),discount_transaction_count:Number(c.discount_transaction_count||0),unique_terminals_with_discounts:Number(c.unique_terminals_with_discounts||0),avg_discount:Number(c.avg_discount||0)})))}catch(a){console.error("NayaxDiscountsAnalytics load error",a),n((a==null?void 0:a.message)||t(`${x}.errors.loadFailed`)),v(null),X([]),A([]),b([])}finally{f(!1)}},[s,J,D,t]);i.useEffect(()=>{const a=window.setTimeout(()=>{te()},200);return()=>window.clearTimeout(a)},[te]);const ve=i.useCallback(async()=>{try{K(!0),await te()}finally{K(!1)}},[te]),ue=i.useMemo(()=>U.map(a=>({...a,label:a.day.slice(5)})),[U]),ge=(a,p)=>a.includes(p)?a.filter(Q=>Q!==p):[...a,p];return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm p-4",children:[e.jsxs("div",{className:"flex flex-col lg:flex-row lg:items-center lg:justify-between gap-3",children:[e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsx("div",{className:"text-sm font-medium text-gray-700",children:t(`${r}
1.period.label`)}),Ze.map(({preset:a,labelKey:p})=>e.jsx("button",{className:F("px-2 py-1 rounded text-xs font-medium border",w===a?"bg-indigo-600 text-white border-indigo-600":"bg-white text-gray-700 border-gray-300 hover:bg-gray-50"),onClick:()=>Z(a),children:t(p)},a)),w!=="custom"&&e.jsx("div",{className:"text-xs text-gray-500 ml-2",children:l.label}),w==="custom"&&e.jsxs("div",{className:"flex items-center gap-2 ml-2",children:[e.jsx("input",{type:"date",value:j,onChange:a=>q(a.target.value),className:"px-2 py-1 text-xs border border-gray-300 rounded"}),e.jsx("span",{className:"text-xs text-gray-500",children:"â"}),e.jsx("input",{type:"date",value:T,onChange:a=>R(a.target.value),className:"px-2 py-1 text-xs border border-gray-300 rounded"})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{className:"border border-gray-300 rounded-md px-3 py-2 text-sm w-full lg:w-80",placeholder:t(`${x}.search.placeholder`),value:D,onChange:a=>C(a.target.value)}),e.jsxs("button",{onClick:ve,className:F("inline-flex items-center gap-2 px-3 py-2 rounded-md border text-sm","border-gray-300 bg-white hover:bg-gray-50",(I||O)&&"opacity-60 cursor-not-allowed"),disabled:I||O,title:t(`${r}.refresh`),children:[I||O?e.jsx(oe,{className:"h-4 w-4 animate-spin"}):e.jsx(ke,{className:"h-4 w-4"}),t(`${r}.refresh`)]})]})]}),e.jsxs("div",{className:"mt-3 grid grid-cols-1 lg:grid-cols-2 gap-3",children:[e.jsxs("div",{className:"rounded-md border border-gray-200 p-3",children:[e.jsx("div",{className:"text-xs font-medium text-gray-500 mb-2",children:t(`${r}.filters.statuses`)}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Pe.map(a=>e.jsxs("label",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:$.includes(a),onChange:()=>z(p=>ge(p,a))}),e.jsx("span",{className:"font-mono text-xs",children:a})]},a))})]}),e.jsxs("div",{className:"rounded-md border border-gray-200 p-3",children:[e.jsx("div",{className:"text-xs font-medium text-gray-500 mb-2",children:t(`${r}.filters.transactionTypes`)}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Fe.map(a=>e.jsxs("label",{className:"inline-flex items-center gap-2 text-sm",children:[e.jsx("input",{type:"checkbox",checked:S.includes(a),onChange:()=>k(p=>ge(p,a))}),e.jsx("span",{className:"font-mono text-xs",children:a})]},a))})]}),e.jsxs("div",{className:"rounded-md border border-gray-200 p-3",children:[e.jsx("div",{className:"text-xs font-medium text-gray-500 mb-2",children:t(`${r}.filters.prepaid`)}),e.jsx("div",{className:"flex flex-wrap gap-2",children:Ye.map(a=>e.jsx("button",{className:F("px-2 py-1 rounded text-xs font-medium border",L===a.value?"bg-indigo-600 text-white border-indigo-600":"bg-white text-gray-700 border-gray-300 hover:bg-gray-50"),onClick:()=>
1ee(a.value),children:t(a.labelKey)},a.value))})]})]}),G?e.jsx("div",{className:"mt-3 text-sm text-red-600",children:G}):null]}),O?e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm p-6 flex items-center justify-center",children:[e.jsx(oe,{className:"h-6 w-6 animate-spin text-indigo-600"}),e.jsx("span",{className:"ml-3 text-sm text-gray-600",children:t(`${x}.loadingAnalytics`)})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-5 gap-3",children:[e.jsxs("div",{className:"rounded-lg border border-red-200 p-4 bg-red-50 shadow-sm",children:[e.jsx("div",{className:"text-xs text-red-700",children:t(`${x}.kpi.totalDiscountAmount`)}),e.jsxs("div",{className:"text-2xl font-semibold text-red-900 mt-1 flex items-center gap-2",children:[e.jsx(he,{className:"h-5 w-5"}),H((h==null?void 0:h.total_discount_amount)||0)]})]}),e.jsxs("div",{className:"rounded-lg border border-gray-200 p-4 bg-white shadow-sm",children:[e.jsx("div",{className:"text-xs text-gray-500",children:t(`${x}.kpi.discountTxCount`)}),e.jsx("div",{className:"text-2xl font-semibold text-gray-900 mt-1",children:B((h==null?void 0:h.discount_tx_count)||0,m)})]}),e.jsxs("div",{className:"rounded-lg border border-gray-200 p-4 bg-white shadow-sm",children:[e.jsx("div",{className:"text-xs text-gray-500",children:t(`${x}.kpi.avgDiscount`)}),e.jsxs("div",{className:"text-2xl font-semibold text-gray-900 mt-1 flex items-center gap-2",children:[e.jsx(je,{className:"h-4 w-4"}),H((h==null?void 0:h.avg_discount)||0)]})]}),e.jsxs("div",{className:"rounded-lg border border-gray-200 p-4 bg-white shadow-sm",children:[e.jsx("div",{className:"text-xs text-gray-500",children:t(`${x}.kpi.uniqueTerminals`)}),e.jsx("div",{className:"text-2xl font-semibold text-gray-900 mt-1",children:B((h==null?void 0:h.unique_terminals)||0,m)})]}),e.jsxs("div",{className:"rounded-lg border border-gray-200 p-4 bg-white shadow-sm",children:[e.jsx("div",{className:"text-xs text-gray-500",children:t(`${x}.kpi.uniqueCards`)}),e.jsx("div",{className:"text-2xl font-semibold text-gray-900 mt-1",children:B((h==null?void 0:h.unique_discount_cards)||0,m)})]})]}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-10 w-10 rounded-full bg-red-50 flex items-center justify-center border border-red-100",children:e.jsx(he,{className:"h-5 w-5 text-red-600"})}),e.jsxs("div",{children:[e.jsx("div",{className:"text-lg font-medium text-gray-900",children:t(`${x}.charts.title`)}),e.jsx("div",{className:"text-sm text-gray-500",children:t(`${x}.charts.subtitle`)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("button",{className:F("px-2 py-1 rounded text-xs font-medium border",_==="amount"?"bg-indigo-600 text-white border-indigo-600":"bg-white text-gray-700 border-gray-300 hover:bg-gray-50"),onClick:()=>E("amount"),children:t(`${x}.charts.metricAmount`)}),e.jsx("button",{className:F("px-2 py-1 rounded text-xs font-medium border",_==="tx"?"bg-indigo-600 text-white border-indigo-600":"bg-white text-gray-700 border-gray-300 hover:bg-gray-50"),onClick:()=>E("tx"),children:t(`${x}.charts.metricTx`)})]})]}),e.jsx("div",{className:"p-6 h-[320px]",children:ue.length===0?e.jsx("div",{className:"h-full flex items-center justify-center text-sm text-gray-500",children:t(`${r}.noDataForPeriod`)}):e.jsx(pe,{width:"100%",height:"100%",children:e.jsxs(Ne,{data:ue,children:[e.jsx(ye,{strokeDasharray:"3 3"}),e.jsx(be,{dataKey:"label"}),e.jsx(ce,{}),e.jsx(_e,{}),e.jsx(fe,{}),_==="amount"?e.jsx(re,{type:"monotone",dataKey:"total_discount_amount",name:t(`${x}.charts.legendAmount`),stroke:"#dc2626",strokeWidth:2,dot:!1}):e.jsx(re,{type:"monotone",dataKey:"discount_tx_count",name:t(`${x}.charts.legendTx`),stroke:"#dc2626",strokeWidth:2,dot:!1})]})})})]}),e.jsxs("div",{className:"grid grid-cols-1 xl:grid-cols-2 gap-6",children:[e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-5 w-5 text-gray-700"}),e.jsx("div",{className:"text-lg font-medium text-gray-900",children:t(`${x}.table.topTerminals`)})]}),e.jsx("div",{className:"text-xs text-gray-500",children:t(`${r}.topN`,{n:50})})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:t(`${r}
1.table.operatorId`)}),e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:t(`${r}.table.coffeeBar`)}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:t(`${x}.table.discounts`)}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:t(`${r}.table.transactions`)}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:t(`${x}.table.avgDiscountShort`)})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:M.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-4 py-6 text-center text-gray-500",children:t(`${r}.noData`)})}):M.map((a,p)=>e.jsxs("tr",{className:"hover:bg-gray-50 cursor-pointer",onClick:()=>g({kind:"operator",operatorId:a.operator_id,title:a.terminal_name||a.operator_id}),children:[e.jsx("td",{className:"px-4 py-3 font-mono text-xs text-gray-800",children:a.operator_id}),e.jsxs("td",{className:"px-4 py-3 text-gray-800",children:[e.jsx("div",{className:"font-medium",children:a.terminal_name||"â"}),e.jsx("div",{className:"text-xs text-gray-500 truncate max-w-[320px]",children:a.linked_first_name&&a.linked_last_name?t(`${x}.table.linkedFranchisee`,{name:`${a.linked_first_name} ${a.linked_last_name}`.trim()}):a.linked_actor_id?`actor_id: ${a.linked_actor_id}`:"â"})]}),e.jsx("td",{className:"px-4 py-3 text-right font-medium text-red-700",children:H(a.total_discount_amount)}),e.jsx("td",{className:"px-4 py-3 text-right",children:B(a.discount_transaction_count,m)}),e.jsx("td",{className:"px-4 py-3 text-right text-gray-600",children:H(a.avg_discount)})]},`terminal-${a.operator_id}-${p}`))})]})})]}),e.jsxs("div",{className:"bg-white border border-gray-200 rounded-lg shadow-sm overflow-hidden",children:[e.jsxs("div",{className:"px-6 py-4 border-b border-gray-200 flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(xe,{className:"h-5 w-5 text-gray-700"}),e.jsx("div",{className:"text-lg font-medium text-gray-900",children:t(`${x}.table.topFranchisees`)})]}),e.jsx("div",{className:"text-xs text-gray-500",children:t(`${r}.topN`,{n:50})})]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"min-w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider",children:t(`${r}.table.franchisee`)}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:t(`${r}.table.terminals`)}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:t(`${x}.table.discounts`)}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:t(`${r}.table.transactions`)}),e.jsx("th",{className:"px-4 py-3 text-right text-xs font-medium text-gray-500 uppercase tracking-wider",children:t(`${x}.table.avgDiscountShort`)})]})}),e.jsx("tbody",{className:"divide-y divide-gray-100",children:d.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-4 py-6 text-center text-gray-500",children:t(`${r}.noData`)})}):d.map((a,p)=>e.jsxs("tr",{className:"hover:bg-gray-50 cursor-pointer",onClick:()=>g({kind:"user",userId:a.mapping_user_id,title:a.mapping_user_name||t(`${r}.franchiseeDefault`)}),children:[e.jsxs("td",{className:"px-4 py-3 text-gray-800",children:[e.jsx("div",{className:"font-medium",children:a.mapping_user_name||t(`${r}.unassignedClient`)}),e.jsxs("div",{className:"text-xs text-gray-500",children:[t(`${r}.idLabel`),": ",a.mapping_user_id]})]}),e.jsx("td",{className:"px-4 py-3 text-right",children:B(a.unique_terminals_with_discounts,m)}),e.jsx("td",{className:"px-4 py-3 text-right font-medium text-red-700",children:H(a.total_discount_amount)}),e.jsx("td",{className:"px-4 py-3 text-right",children:B(a.discount_transaction_count,m)}),e.jsx("td",{className:"px-4 py-3 text-right text-gray-600",children:H(a.avg_discount)})]},`franchisee-${a.mapping_user_id}-${p}`))})]})})]})]})]}),e.jsx(Me,{isOpen:!!W,onClose:()=>g(null),companyId:s,scope:W,start:l.start,end:l.end,statuses:$.length>0?$:null,types:S.length>0?S:null,prepaidFilter:L})]})}
1const V="admin.nayax.common",de="admin.nayax.discounts";function it(){const{companyId:s}=we(),{t}=me();return e.jsxs("div",{className:"p-4 md:p-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4 mb-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-gray-900 flex items-center gap-2",children:[e.jsx(je,{className:"h-6 w-6 text-red-600"}),t(`${de}.title`)]}),e.jsx("div",{className:"text-sm text-gray-500 mt-1",children:t(`${de}.subtitle`,{table:t(`${V}.dataSourceTable`),companyLabel:t(`${V}.companyLabel`),companyId:s||"â"})}),e.jsx("div",{className:"text-xs text-gray-400 mt-1",children:t(`${de}.subtitleHint`)})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(ie,{to:`/${s}/admin/nayax-sales-dashboard`,className:"inline-flex items-center gap-2 px-4 py-2 bg-indigo-600 text-white rounded-lg hover:bg-indigo-700 transition-colors shadow-sm",children:[e.jsx(xe,{className:"h-4 w-4"}),t(`${V}.nav.sales`)]}),e.jsxs(ie,{to:`/${s}/admin/nayax-device-errors`,className:"inline-flex items-center gap-2 px-4 py-2 bg-orange-600 text-white rounded-lg hover:bg-orange-700 transition-colors shadow-sm",children:[e.jsx(Ue,{className:"h-4 w-4"}),t(`${V}.nav.errors`)]}),e.jsxs(ie,{to:`/${s}/admin/nayax-royalty`,className:"inline-flex items-center gap-2 px-4 py-2 bg-green-600 text-white rounded-lg hover:bg-green-700 transition-colors shadow-sm",children:[e.jsx(Le,{className:"h-4 w-4"}),t(`${V}.nav.royalty`)]})]})]}),e.jsx(Re,{companyId:s||""})]})}export{it as NayaxDiscountsPage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.