1import{r as p,j as e}from"./vendor-react-CuUun9aL.js";import{B as S,J as u}from"./index-CffYHF1C.js";import{paymentSettingsService as h}from"./paymentSettingsService-Cfgbt3mp.js";import{C as N,a as F,e as w,b as P,c as C}from"./card-khC1k9a2.js";import{N as T}from"./numeric-input-pMqdwed-.js";import{L as n}from"./label-BaKeqYGc.js";import{S as b}from"./switch-CyagKXjE.js";import{R as E,a as y}from"./radio-group-BgeBZsnN.js";import{aO as A,bn as j,r as D,ad as G,av as M}from"./vendor-icons-9tdgZqZ8.js";import{I as B}from"./input-Ccd_OHYE.js";import{T as $,a as k,b as f,c as v}from"./tabs-tAXZLwp9.js";import{P as L}from"./PaymentTransactionsTab-BVK7bqsU.js";import"./vendor-supabase-V01cKGWO.js";import"./vendor-radix-DHc79Ej6.js";import"./vendor-query-Ch735aT_.js";import"./vendor-router-CIKCSSKp.js";import"./select-BaOXAfxm.js";import"./table-Bf8kae7D.js";import"./badge-tBo3c1at.js";import"./dialog-C-hTN1bv.js";import"./separator-CEghR9ef.js";import"./generateCategoricalChart-B9Q15cqU.js";import"./isEqual-DBOqIkR_.js";import"./step-BFdGCk-a.js";import"./index-BdMtdqQ6.js";import"./linear-CsGqE94n.js";import"./init-Dmth1JHB.js";import"./defaultLocale-C4B-KCzX.js";import"./time-arThTTNy.js";import"./band-CquvqAHh.js";import"./ordinal-DILIJJjt.js";import"./LineChart-BkpOtRsX.js";import"./vendor-date-BqJAPjTW.js";import"./PageRefreshButton-DL5ivP__.js";import"./xlsx-B6sNpj_1.js";const R=({settings:i,onSave:o,isSaving:l})=>{const[s,m]=p.useState(i),c=a=>{m(r=>({...r,processingFee:{...r.processingFee,...a}}))},g=()=>{o(s)},x=()=>{const a=s.processingFee.value;return s.processingFee.type==="percentage"?a>=0&&a<=100:a>=0};return e.jsxs(N,{children:[e.jsxs(F,{children:[e.jsxs(w,{className:"flex items-center gap-2",children:[e.jsx(A,{className:"h-5 w-5"}),"Processing Fee Configuration"]}),e.jsx(P,{children:"Configure processing fees for B2C customers. B2B partners are exempt from processing fees."})]}),e.jsxs(C,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n,{className:"text-base",children:"Enable Processing Fee"}),e.jsx("div",{className:"text-sm text-gray-500",children:"Apply processing fees to B2C customer payments"})]}),e.jsx(b,{checked:s.processingFee.enabled,onCheckedChange:a=>c({enabled:a})})]}),s.processingFee.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(n,{className:"text-base",children:"Fee Type"}),e.jsxs(E,{value:s.processingFee.type,onValueChange:a=>c({type:a}),className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2 border rounded-lg p-4",children:[e.jsx(y,{value:"percentage",id:"percentage"}),e.jsxs(n,{htmlFor:"percentage",className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(j,{className:"h-4 w-4"}),"Percentage"]})]}),e.jsxs("div",{className:"flex items-center space-x-2 border rounded-lg p-4",children:[e.jsx(y,{value:"flat",id:"flat"}),e.jsxs(n,{htmlFor:"flat",className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("span",{className:"text-sm font-medium",children:"AED"}),"Flat Rate"]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:"fee-value",children:s.processingFee.type==="percentage"?"Percentage (%)":"Amount (AED)"}),e.jsxs("div",{className:"relative",children:[e.jsx(T,{id:"fee-value",min:"0",max:s.processingFee.type==="percentage"?100:void 0,step:s.processingFee.type==="percentage"?.1:.01,value:s.processingFee.value,onChange:a=>c({value:parseFloat(a.target.value)||0}),className:`${s.processingFee.type==="percentage"?"pr-8":"pl-12"}`,allowDecimal:!0,allowNegative:!1}),s.processingFee.type==="percentage"?e.jsx(j,{className:"absolute right-3 top-3 h-4 w-4 text-gray-400"}):e.jsx("span",{className:"absolute left-3 top-3 text-sm text-gray-400",children:"AED"})]}),s.processingFee.type==="percentage"&&e.jsx("div",{className:"text-sm text-gray-500",children:"Enter percentage (0-100). Example: 3.5 for 3.5%"})]}),e.jsxs("div",{className:"p-4 bg-blue-50 rounded-lg",children:[e.jsx("div",{className:"text-sm font-medium text-blue-800 mb-2",children:"Preview Example"}),e.jsxs("div",{className:"text-sm text-blue-700",children:["For a AED 100 visa application:",e.
1jsx("br",{}),"Processing fee: AED ",s.processingFee.type==="percentage"?(100*s.processingFee.value/100).toFixed(2):s.processingFee.value.toFixed(2),e.jsx("br",{}),"Total: AED ",s.processingFee.type==="percentage"?(100+100*s.processingFee.value/100).toFixed(2):(100+s.processingFee.value).toFixed(2)]})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsx(S,{onClick:g,disabled:l||!x(),children:l?"Saving...":"Save Settings"})})]})]})},V=({gateway:i,onUpdate:o,isSaving:l})=>{const[s,m]=p.useState(i),c=t=>{m(d=>({...d,processingFee:{...d.processingFee,...t}}))},g=t=>{m(d=>({...d,enabled:t}))},x=()=>{o(s)},a=()=>{const t=s.processingFee.value;return s.processingFee.type==="percentage"?t>=0&&t<=100:t>=0},r=()=>{switch(s.id){case"payby":return e.jsx("div",{className:"h-5 w-5 bg-blue-600 rounded flex items-center justify-center text-white text-xs font-bold",children:"PB"});default:return e.jsx(D,{className:"h-5 w-5"})}};return e.jsxs(N,{className:`${s.enabled?"border-primary":"border-gray-200 opacity-75"}`,children:[e.jsxs(F,{children:[e.jsxs(w,{className:"flex items-center gap-2",children:[r(),s.name," Configuration"]}),e.jsxs(P,{children:["Configure processing fees and settings for ",s.name]})]}),e.jsxs(C,{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsxs(n,{className:"text-base",children:["Enable ",s.name]}),e.jsx("div",{className:"text-sm text-gray-500",children:"Make this payment gateway available to customers"})]}),e.jsx(b,{checked:s.enabled,onCheckedChange:g})]}),s.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"space-y-0.5",children:[e.jsx(n,{className:"text-base",children:"Enable Processing Fee"}),e.jsxs("div",{className:"text-sm text-gray-500",children:["Apply processing fees for ",s.name," payments"]})]}),e.jsx(b,{checked:s.processingFee.enabled,onCheckedChange:t=>c({enabled:t})})]}),s.processingFee.enabled&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3",children:[e.jsx(n,{className:"text-base",children:"Fee Type"}),e.jsxs(E,{value:s.processingFee.type,onValueChange:t=>c({type:t}),className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"flex items-center space-x-2 border rounded-lg p-4",children:[e.jsx(y,{value:"percentage",id:`percentage-${s.id}`}),e.jsxs(n,{htmlFor:`percentage-${s.id}`,className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(j,{className:"h-4 w-4"}),"Percentage"]})]}),e.jsxs("div",{className:"flex items-center space-x-2 border rounded-lg p-4",children:[e.jsx(y,{value:"flat",id:`flat-${s.id}`}),e.jsxs(n,{htmlFor:`flat-${s.id}`,className:"flex items-center gap-2 cursor-pointer",children:[e.jsx(A,{className:"h-4 w-4"}),"Flat Rate"]})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(n,{htmlFor:`fee-value-${s.id}`,children:s.processingFee.type==="percentage"?"Percentage (%)":"Amount (AED)"}),e.jsxs("div",{className:"relative",children:[e.jsx(B,{id:`fee-value-${s.id}`,type:"number",min:"0",max:s.processingFee.type==="percentage"?100:void 0,step:s.processingFee.type==="percentage"?.1:.01,value:s.processingFee.value,onChange:t=>c({value:parseFloat(t.target.value)||0}),className:`${s.processingFee.type==="percentage"?"pr-8":"pl-8"}`}),s.processingFee.type==="percentage"?e.jsx(j,{className:"absolute right-3 top-3 h-4 w-4 text-gray-400"}):e.jsx("span",{className:"absolute left-3 top-3 text-sm text-gray-400",children:"AED"})]}),s.processingFee.type==="percentage"&&e.jsx("div",{className:"text-sm text-gray-500",children:"Enter percentage (0-100). Example: 3.5 for 3.5%"})]}),e.jsxs("div",{className:"p-4 bg-blue-50 rounded-lg",children:[e.jsx("div",{className:"text-sm font-medium text-blue-800 mb-2",children:"Preview Example"}),e.jsxs("div",{className:"text-sm text-blue-700",children:["For a AED 100 visa application:",e.jsx("br",{}),"Processing fee: AED ",s.processingFee.type==="percentage"?(100*s.processingFee.value/100).toFixed(2):s.processingFee.value.toFixed(2),e.jsx("br",{}),"Total: AED ",s.processingFee.type==="percentage"?(100+100*s.processingFee.value/100).toFixed(2):(100+s.processingFee.value).toFixed(2)]})]})]})]}),e.jsx("div",{className:"flex justify-end pt-4 border-t",children:e.jsx(S,{onClick:x,disabled:l||!a(),children:l?"Saving...":"Save Settings"})})]})]})},be=()=>{const[i,o]=p.useState(null),[l,s]=p.useState(!1),[m,c]=p.useState(!0);p.useEffect(()=>{const a=async()=>{try{console.log("PaymentManagement: Loading payment settings from database...");const t=await h.getPaymentSettings();console.log("PaymentManagement: Loaded settings:",t),o(t)}catch(t){console.error("PaymentManagement: Error loading settings:",t),u.error("Failed to load payment settings")}finally{c(!1)}};return a(),h.subscribe(a)},[]);const g=async a=>{console.log("PaymentManagement: Saving settings:",a),s(!0);try{await h.updatePaymentSettings(a),o(a),u.success("Payment settings saved successfully!",{description:"Processing fees and gateway settings have been updated. Changes are now live for all users."}),console.log("PaymentManagement: Settings saved successfully")}catch(r){console.error("PaymentManagement: Error saving payment settings:",r),u.error("Failed to save payment settings",{description:"Please try again or c
1ontact support."})}finally{s(!1)}},x=async(a,r)=>{if(i){console.log("PaymentManagement: Updating gateway:",a,r),s(!0);try{await h.updateGateway(a,r);const t={...i,gateways:i.gateways.map(d=>d.id===a?r:d)};o(t),u.success(`${r.name} settings updated successfully!`,{description:"Changes are now live for all users."}),console.log("PaymentManagement: Gateway updated successfully")}catch(t){console.error("PaymentManagement: Error updating gateway settings:",t),u.error("Failed to update gateway settings")}finally{s(!1)}}};return m?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"animate-pulse",children:[e.jsx("div",{className:"h-8 bg-gray-200 rounded w-1/4 mb-2"}),e.jsx("div",{className:"h-4 bg-gray-200 rounded w-1/2"})]}),e.jsx("div",{className:"animate-pulse bg-gray-200 rounded h-96"})]}):i?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold",children:"Payment Management"}),e.jsx("p",{className:"text-gray-600 mt-1",children:"Configure processing fees and payment gateway settings for your visa applications."})]}),e.jsxs($,{defaultValue:"global",className:"space-y-6",children:[e.jsxs(k,{children:[e.jsxs(f,{value:"global",className:"flex items-center gap-2",children:[e.jsx(G,{className:"h-4 w-4"}),"Global Settings"]}),e.jsxs(f,{value:"gateways",className:"flex items-center gap-2",children:[e.jsx(D,{className:"h-4 w-4"}),"Payment Gateways"]}),e.jsxs(f,{value:"transactions",className:"flex items-center gap-2",children:[e.jsx(M,{className:"h-4 w-4"}),"Transactions"]})]}),e.jsx(v,{value:"global",className:"space-y-6",children:e.jsx(R,{settings:i,onSave:g,isSaving:l})}),e.jsxs(v,{value:"gateways",className:"space-y-6",children:[e.jsx("div",{className:"grid gap-6",children:i.gateways.map(a=>e.jsx(V,{gateway:a,onUpdate:r=>x(a.id,r),isSaving:l},a.id))}),e.jsxs(N,{className:"bg-blue-50 border-blue-200",children:[e.jsxs(F,{children:[e.jsx(w,{className:"text-blue-800",children:"Gateway Information"}),e.jsx(P,{className:"text-blue-600",children:"Configure individual processing fees for each payment gateway"})]}),e.jsx(C,{className:"text-sm text-blue-700",children:e.jsxs("ul",{className:"space-y-1",children:[e.jsx("li",{children:"⢠PayBy: Recommended for UAE-based transactions"}),e.jsx("li",{children:"⢠Processing fees are applied only to B2C customers"}),e.jsx("li",{children:"⢠B2B partners are exempt from processing fees"})]})})]})]}),e.jsx(v,{value:"transactions",children:e.jsx(L,{})})]})]}):e.jsx("div",{className:"text-center py-8",children:e.jsx("p",{className:"text-gray-600",children:"Failed to load payment settings. Please refresh the page."})})};export{be as default};
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.