1import{c as L,a as k,r as n,D as v,j as e,a2 as C,k as H,K as j,a5 as B,W as O,R as $,F as G}from"./index-BY2qKH8z.js";import{S as K}from"./switch-DTy7hWPY.js";import{I as E}from"./input-Bah16nn1.js";import{L as M}from"./label-C-TJcEiP.js";import{B as U}from"./badge-DMxqU6h1.js";import{g as W,s as X,t as Z}from"./gatewaySettingsService-CFufOzIp.js";import{C as Y}from"./circle-alert-BQ1EHdVL.js";import{L as _}from"./loader-circle-DczacYwv.js";import{P as q}from"./plug-hc5bPi3v.js";import{C as J}from"./chevron-up-BrwIicpf.js";import{P as Q}from"./percent-Bblpvznz.js";import{T as A}from"./tag-2PG8VTbT.js";import{D as V}from"./dollar-sign-C7IfMwb9.js";import{S as T}from"./save-ZOTwNX6w.js";import{B as ee}from"./building-2-BgmTKXxk.js";import{E as se}from"./eye-off-BwBfoS1T.js";import{E as ae}from"./eye-eVaAk2NO.js";import{C as te}from"./circle-check-big-XAhfXX-i.js";import{C as le}from"./circle-x-4SDeUz8a.js";import{R as re}from"./refresh-cw-DzMZqUir.js";import"./index-DTJUEOby.js";const oe=[["rect",{width:"20",height:"12",x:"2",y:"6",rx:"2",key:"9lu3g6"}],["circle",{cx:"12",cy:"12",r:"2",key:"1c9p78"}],["path",{d:"M6 12h.01M18 12h.01",key:"113zkx"}]],ne=L("banknote",oe);const ce=[["path",{d:"M6.3 20.3a2.4 2.4 0 0 0 3.4 0L12 18l-6-6-2.3 2.3a2.4 2.4 0 0 0 0 3.4Z",key:"goz73y"}],["path",{d:"m2 22 3-3",key:"19mgm9"}],["path",{d:"M7.5 13.5 10 11",key:"7xgeeb"}],["path",{d:"M10.5 16.5 13 14",key:"10btkg"}],["path",{d:"m18 3-4 4h6l-4 4",key:"16psg9"}]],D=L("plug-zap",ce),I={getAll:()=>k.get("/payment-settings").then(l=>l.data),getPublic:()=>k.get("/payment-methods").then(l=>l.data),update:(l,c)=>k.put(`/payment-settings/${l}`,c).then(s=>s.data)},ie={cod:{icon:e.jsx(ne,{className:"w-5 h-5"}),color:"bg-amber-50 border-amber-200",label:"Cash on Delivery"},stripe:{icon:e.jsx(C,{className:"w-5 h-5"}),color:"bg-violet-50 border-violet-200",label:"Stripe"},paypal:{icon:e.jsx(C,{className:"w-5 h-5"}),color:"bg-blue-50 border-blue-200",label:"PayPal"},bank_transfer:{icon:e.jsx(ee,{className:"w-5 h-5"}),color:"bg-slate-50 border-slate-200",label:"Bank Transfer"},tabby:{icon:e.jsx(A,{className:"w-5 h-5"}),color:"bg-green-50 border-green-200",label:"Tabby"},tamara:{icon:e.jsx(A,{className:"w-5 h-5"}),color:"bg-teal-50 border-teal-200",label:"Tamara"}},F={stripe:[{key:"enabled",label:"Enable in Plugin Manager",type:"info"},{key:"mode",label:"Mode",type:"select",options:["sandbox","live"]},{key:"publishable_key",label:"Publishable Key",type:"text",placeholder:"pk_live_..."},{key:"secret_key",label:"Secret Key",type:"password",placeholder:"sk_live_..."},{key:"webhook_secret",label:"Webhook Secret",type:"password",placeholder:"whsec_..."}],paypal:[{key:"mode",label:"Mode",type:"select",options:["sandbox","live"]},{key:"client_id",label:"Client ID",type:"text",placeholder:"AXxx..."},{key:"client_secret",label:"Client Secret",type:"password",placeholder:"â¢â¢â¢â¢"}],tabby:[{key:"api_key",label:"API Key",type:"password",placeholder:"pk_..."},{key:"merchant_code",label:"Merchant Code",type:"text"},{key:"currency",label:"Currency",type:"text",placeholder:"AED"}],tamara:[{key:"api_key",label:"API Key",type:"password"},{key:"notification_key",label:"Notification Key",type:"password"},{key:"merchant_url",label:"Merchant URL",type:"text"}]},P=j("w-full rounded-xl border border-slate-200 px-3 py-2 text-sm outline-none transition","focus:ring-2 focus:ring-violet-500 focus:border-violet-500 bg-white hover:border-slate-300"),de=({method:l})=>{const c=F[l];if(!c)return null;const[s,d]=n.useState({}),[x,m]=n.useState({}),[p,f]=n.useState({}),[a,b]=n.useState(!0),[y,h]=n.useState(!1),[g,r]=n.useState(!1),[w,N]=n.useState(null);n.useEffect(()=>{W(l).then(t=>{const o={},i={};c.forEach(u=>{u.type==="password"?(o[u.key]="",i[u.key]=!!t[`has_${u.key}`]):u.type==="select"?o[u.key]=t[u.key]??u.options?.[0]??"":u.type!=="info"&&(o[u.key]=t[u.key]??"")}),d(o),m(i)}).catch(()=>v.error("Failed to load credentials")).finally(()=>b(!1))},[l]);const R=async()=>{h(!0),N(null);try{await X(l,s),v.success("Credentials saved");const t={...x};c.forEach(i=>{i.type==="password"&&s[i.key]&&(t[i.key]=!0)}),m(t);const o={...s};
1c.forEach(i=>{i.type==="password"&&(o[i.key]="")}),d(o)}catch{v.error("Failed to save credentials")}finally{h(!1)}},z=async()=>{r(!0),N(null);try{const t=await Z(l);N({success:t.success,message:t.message})}catch{N({success:!1,message:"Connection test failed"})}finally{r(!1)}};return a?e.jsx("div",{className:"flex justify-center py-4",children:e.jsx(_,{className:"h-5 w-5 animate-spin text-violet-500"})}):e.jsxs("div",{className:"space-y-4",children:[c.filter(t=>t.type!=="info").map(t=>e.jsx("div",{children:t.type==="select"?e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-600 mb-1",children:t.label}),e.jsx("select",{value:s[t.key]??"",onChange:o=>d(i=>({...i,[t.key]:o.target.value})),className:P,children:t.options?.map(o=>e.jsx("option",{value:o,children:o.charAt(0).toUpperCase()+o.slice(1)},o))})]}):t.type==="password"?e.jsxs("div",{children:[e.jsxs("label",{className:"block text-xs font-semibold text-slate-600 mb-1",children:[t.label,x[t.key]&&e.jsx("span",{className:"ml-2 text-emerald-600 font-normal",children:"â saved"})]}),e.jsxs("div",{className:"relative",children:[e.jsx("input",{type:p[t.key]?"text":"password",value:s[t.key]??"",onChange:o=>d(i=>({...i,[t.key]:o.target.value})),placeholder:x[t.key]?"â¢â¢â¢â¢â¢â¢â¢â¢":t.placeholder??"",className:j(P,"pr-9"),autoComplete:"new-password"}),e.jsx("button",{type:"button",onClick:()=>f(o=>({...o,[t.key]:!o[t.key]})),className:"absolute right-2.5 top-1/2 -translate-y-1/2 text-slate-400 hover:text-slate-600",children:p[t.key]?e.jsx(se,{className:"h-3.5 w-3.5"}):e.jsx(ae,{className:"h-3.5 w-3.5"})})]})]}):e.jsxs("div",{children:[e.jsx("label",{className:"block text-xs font-semibold text-slate-600 mb-1",children:t.label}),e.jsx("input",{type:"text",value:s[t.key]??"",onChange:o=>d(i=>({...i,[t.key]:o.target.value})),placeholder:t.placeholder??"",className:P})]})},t.key)),w&&e.jsxs("div",{className:j("flex items-start gap-2 rounded-xl px-3 py-2 text-xs",w.success?"bg-emerald-50 text-emerald-700":"bg-red-50 text-red-700"),children:[w.success?e.jsx(te,{className:"h-3.5 w-3.5 flex-shrink-0 mt-0.5"}):e.jsx(le,{className:"h-3.5 w-3.5 flex-shrink-0 mt-0.5"}),w.message]}),e.jsxs("div",{className:"flex gap-2 pt-1",children:[e.jsxs("button",{onClick:R,disabled:y,className:"flex items-center gap-1.5 rounded-xl bg-violet-600 text-white px-4 py-2 text-xs font-bold hover:bg-violet-700 transition disabled:opacity-60",children:[y?e.jsx(_,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(T,{className:"h-3.5 w-3.5"}),"Save Keys"]}),e.jsxs("button",{onClick:z,disabled:g,className:"flex items-center gap-1.5 rounded-xl border border-slate-200 text-slate-600 px-3 py-2 text-xs font-medium hover:bg-slate-50 transition disabled:opacity-60",children:[g?e.jsx(_,{className:"h-3.5 w-3.5 animate-spin"}):e.jsx(re,{className:"h-3.5 w-3.5"}),"Test"]})]})]})},S=({icon:l,label:c,description:s,checked:d,onChange:x,disabled:m=!1})=>e.jsxs("div",{className:j("flex items-center justify-between py-1.5",m&&"opacity-40"),children:[e.jsxs("div",{className:"flex items-center gap-2",children:[l,e.jsxs("div",{children:[e.jsx("div",{className:"text-sm font-medium text-gray-800",children:c}),e.jsx("div",{className:"text-xs text-gray-500",children:s})]})]}),e.jsx(K,{checked:!!d,onCheckedChange:x,disabled:m})]}),xe=({method:l,onSave:c})=>{const[s,d]=n.useState({...l}),[x,m]=n.useState(!1),[p,f]=n.useState(!1),a=(r,w)=>d(N=>({...N,[r]:w})),b=ie[l.method]??{icon:e.jsx(C,{className:"w-5 h-5"}),color:"bg-gray-50 border-gray-200"},y=!!F[l.method],h=l.plugin_enabled!==!1,g=async()=>{m(!0);try{await c(s.method,{label:s.label,is_active:s.is_active,extra_fee:Number(s.extra_fee),extra_fee_type:s.extra_fee_type,coupon_allowed:s.coupon_allowed,gift_card_allowed:s.gift_card_allowed,gift_card_max_percent:Number(s.gift_card_max_percent),allow_coupons_with_gift_card:s.allow_coupons_with_gift_card}),v.success(`${s.label} saved`)}catch{v.error("Failed to save")}finally{m(!1)}};return e.jsxs("div",{className:j("rounded-2xl border overflow-hidden",b.color,!h&&"opacity-70"),children:[e.jsxs("div",{className:"flex items-center justify-between px-5 py-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-white shadow-sm",children:b.icon}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-gray-900",children:s.label}),e.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5 flex-wrap",children:[e.jsx("span",{className:"text-xs text-gray-400 font-mono",children:s.method}),!h&&e.jsxs("span",{className:"text-xs px-1.5 py-0.5 rounded bg-slate-200 text-slate-500 font-medium flex items-center gap-1",children:[e.jsx(q,{className:"h-2.5 w-2.5"})," Plugin disabled"]}),h&&e.jsxs("span",{className:"text-xs px-1.5 py-0.5 rounded bg-emerald-100 text-emerald-700 font-medium flex items-center gap-1",children:[e.jsx(D,{className:"h-2.5 w-2.5"})," Plugin active"]})]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[y&&e.jsxs("button",{type:"button",onClick:()=>f(r=>!r),className:j("flex items-center gap-1.5 rounded-lg border px-3 py-1.5 text-xs font-semibold transition",p?"bg-vi
1olet-600 text-white border-violet-600":"border-violet-200 bg-violet-50 text-violet-700 hover:bg-violet-100"),children:[e.jsx(B,{className:"w-3.5 h-3.5"}),"API Keys",p?e.jsx(J,{className:"w-3 h-3"}):e.jsx(O,{className:"w-3 h-3"})]}),e.jsx(U,{className:s.is_active?"bg-emerald-100 text-emerald-800 border-emerald-200":"bg-slate-100 text-slate-500",children:s.is_active?"Active":"Inactive"}),e.jsx(K,{checked:!!s.is_active,onCheckedChange:r=>a("is_active",r)})]})]}),p&&e.jsxs("div",{className:"border-t border-black/5 bg-white px-5 py-4",children:[e.jsx("p",{className:"text-xs font-bold text-slate-500 uppercase tracking-wider mb-3",children:"API Credentials"}),e.jsx(de,{method:l.method})]}),e.jsxs("div",{className:"px-5 pb-4 space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-3 pt-1",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{className:"text-xs text-gray-600",children:"Extra Fee"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{type:"number",min:0,step:.01,value:s.extra_fee,onChange:r=>a("extra_fee",r.target.value),className:"bg-white h-8 text-sm"}),e.jsxs("select",{value:s.extra_fee_type,onChange:r=>a("extra_fee_type",r.target.value),className:"h-8 rounded-md border border-input bg-white px-2 text-sm",children:[e.jsx("option",{value:"fixed",children:"AED"}),e.jsx("option",{value:"percent",children:"%"})]})]}),e.jsx("p",{className:"text-[11px] text-gray-400",children:"Added at checkout. 0 = no fee."})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(M,{className:"text-xs text-gray-600",children:"Gift Card Max Coverage"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(E,{type:"number",min:0,max:100,value:s.gift_card_max_percent,onChange:r=>a("gift_card_max_percent",r.target.value),disabled:!s.gift_card_allowed,className:"bg-white h-8 text-sm"}),e.jsx(Q,{className:"w-4 h-4 text-gray-400 flex-shrink-0"})]}),e.jsx("p",{className:"text-[11px] text-gray-400",children:"Max % of order total gift card covers."})]})]}),e.jsxs("div",{className:"space-y-1 border-t border-black/5 pt-3",children:[e.jsx(S,{icon:e.jsx(A,{className:"w-4 h-4 text-violet-500"}),label:"Allow Coupon Codes",description:"Customers can apply promo/coupon codes",checked:s.coupon_allowed,onChange:r=>a("coupon_allowed",r)}),e.jsx(S,{icon:e.jsx($,{className:"w-4 h-4 text-pink-500"}),label:"Allow Gift Cards",description:"Customers can redeem gift card balance",checked:s.gift_card_allowed,onChange:r=>{a("gift_card_allowed",r),r||a("gift_card_max_percent",0)}}),e.jsx(S,{icon:e.jsx(V,{className:"w-4 h-4 text-emerald-500"}),label:"Allow Coupon + Gift Card Together",description:"Customer can use both in one order",checked:s.allow_coupons_with_gift_card,onChange:r=>a("allow_coupons_with_gift_card",r),disabled:!s.coupon_allowed||!s.gift_card_allowed})]}),e.jsx("div",{className:"flex justify-end pt-1",children:e.jsxs(G,{size:"sm",onClick:g,disabled:x,style:{background:"var(--brand-primary,#7c3aed)",color:"#fff"},children:[x?e.jsx(_,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(T,{className:"w-4 h-4 mr-2"}),"Save"]})})]})]})},me=()=>{const[l,c]=n.useState(!1),[s,d]=n.useState(2),[x,m]=n.useState(!0),[p,f]=n.useState(!1);n.useEffect(()=>{k.get("/settings").then(b=>{const y=b.data?.coupon??[],h=y.find(r=>r.key==="multi_coupon_enabled"),g=y.find(r=>r.key==="max_coupons_per_order");h&&c(!!h.value),g&&d(Number(g.value)||2)}).catch(()=>{}).finally(()=>m(!1))},[]);const a=async()=>{f(!0);try{await k.post("/settings",{settings:[{key:"multi_coupon_enabled",value:l,group:"coupon"},{key:"max_coupons_per_order",value:Number(s),group:"coupon"}]}),v.success("Coupon settings saved")}catch{v.error("Failed to save")}finally{f(!1)}};return x?null:e.jsxs("div",{className:"rounded-2xl border bg-indigo-50 border-indigo-200 p-5 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"p-2 rounded-xl bg-white shadow-sm",children:e.jsx(B,{className:"w-5 h-5 text-indigo-600"})}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold text-gray-900",children:"Multi-Coupon Settings"}),e.jsx("div",{className:"text-xs text-gray-500",children:"Control whether customers can stack multiple coupons"})]})]}),e.jsx(S,{icon:e.jsx(A,{className:"w-4 h-4 text-indigo-600"}),label:"Allow Multiple Coupons per Order",description:"Customers can a
1pply more than one coupon code",checked:l,onChange:c}),l&&e.jsxs("div",{className:"space-y-1 pl-6",children:[e.jsx(M,{className:"text-xs text-gray-600",children:"Max Coupons per Order"}),e.jsx(E,{type:"number",min:1,max:10,value:s,onChange:b=>d(b.target.value),className:"w-24 bg-white h-8 text-sm"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(G,{size:"sm",onClick:a,disabled:p,style:{background:"#4338ca",color:"#fff"},children:[p?e.jsx(_,{className:"w-4 h-4 animate-spin mr-2"}):e.jsx(T,{className:"w-4 h-4 mr-2"}),"Save"]})})]})};function Le(){const[l,c]=n.useState([]),[s,d]=n.useState(!0);n.useEffect(()=>{I.getAll().then(a=>c(Array.isArray(a)?a:[])).catch(()=>v.error("Failed to load payment methods")).finally(()=>d(!1))},[]);const x=async(a,b)=>{const y=await I.update(a,b);c(h=>h.map(g=>g.method===a?{...g,...y}:g))},m=l.filter(a=>a.is_active).length,p=l.filter(a=>a.plugin_enabled!==!1).length;l.filter(a=>a.extra_fee>0).length;const f=l.filter(a=>!a.coupon_allowed).length;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold flex items-center gap-2",children:[e.jsx(C,{className:"w-6 h-6 text-violet-600"}),"Payment Settings"]}),e.jsx("p",{className:"text-sm text-slate-500 mt-1",children:"Configure all payment gateways â API keys, fees, coupon & gift card rules."})]}),e.jsx("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-4",children:[{label:"Total Gateways",value:l.length,icon:e.jsx(C,{className:"w-5 h-5 text-violet-500"}),bg:"bg-violet-50"},{label:"Active",value:m,icon:e.jsx(H,{className:"w-5 h-5 text-emerald-500"}),bg:"bg-emerald-50"},{label:"Plugin Enabled",value:p,icon:e.jsx(D,{className:"w-5 h-5 text-blue-500"}),bg:"bg-blue-50"},{label:"Coupon Blocked",value:f,icon:e.jsx(Y,{className:"w-5 h-5 text-amber-500"}),bg:"bg-amber-50"}].map(a=>e.jsxs("div",{className:j(a.bg,"rounded-xl p-4 flex items-center gap-3"),children:[a.icon,e.jsxs("div",{children:[e.jsx("div",{className:"text-2xl font-bold",children:a.value}),e.jsx("div",{className:"text-xs text-slate-500",children:a.label})]})]},a.label))}),e.jsxs("div",{className:"rounded-xl border border-blue-100 bg-blue-50 px-4 py-3 text-sm text-blue-800",children:[e.jsx("strong",{children:"How API Keys work:"})," Click ",e.jsx("strong",{children:"API Keys"})," on any gateway card to enter credentials inline. Enable/disable a gateway in ",e.jsx("strong",{children:"Plugins â toggle"})," â the ",e.jsx("em",{children:"Plugin active"})," badge here reflects that state. Active toggle controls whether the method appears at checkout."]}),s?e.jsxs("div",{className:"flex items-center gap-3 py-12 justify-center text-slate-400",children:[e.jsx(_,{className:"w-5 h-5 animate-spin"})," Loading payment methodsâ¦"]}):e.jsx("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:l.map(a=>e.jsx(xe,{method:a,onSave:x},a.method))}),e.jsx(me,{})]})}export{Le 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.