1import{ac as Q,r as a,o as F,ad as j,ap as n,j as e,B as l,Q as L,bX as _,af as I,ag as K,ah as T,ai as t,aj as V,am as i,b7 as B,b8 as H,b9 as O,ba as R,aU as d,I as g,bc as z}from"./index-payoMPV_.js";import{A as G}from"./AdminLayout-BR8ZUW_V.js";import{S as A}from"./switch-XTWKDBAO.js";import{E as M}from"./EmptyState-CdoDlo0h.js";import{D as U}from"./DeleteConfirmationDialog-DlafjgHi.js";import{c}from"./countryService-DZvYXWLQ.js";import{P as X}from"./plus-CdQyvwwQ.js";import{T as $}from"./trash-2-CtvRwBCL.js";import"./layout-dashboard-J8mXpsr5.js";import"./gift-CxKhZXlR.js";import"./calendar-days-jGlrtffW.js";import"./alert-dialog-B1iwHmsa.js";function J(){const u=Q(),[D,r]=a.useState(!1),[h,C]=a.useState(""),[y,b]=a.useState(""),[m,v]=a.useState(""),[f,k]=a.useState(!0),[o,p]=a.useState(null),{data:x=[],isLoading:w}=F({queryKey:["admin-countries"],queryFn:()=>c.listCountries()}),N=j({mutationFn:()=>c.createCountry({name:h,shippable:f?1:0,phone_code:y||void 0,vat_rate:m?Number(m):void 0}),onSuccess:()=>{n.success("Country created"),u.invalidateQueries({queryKey:["admin-countries"]}),r(!1),C(""),b(""),v("")},onError:s=>n.error(s.message)}),S=j({mutationFn:s=>c.deleteCountry(s),onSuccess:()=>{n.success("Country deleted"),u.invalidateQueries({queryKey:["admin-countries"]}),p(null)},onError:s=>n.error(s.message)}),E=j({mutationFn:s=>c.updateCountry(s.id,{shippable:s.shippable}),onSuccess:()=>u.invalidateQueries({queryKey:["admin-countries"]}),onError:s=>n.error(s.message)}),P=x.find(s=>s.id===o);return e.jsxs(G,{children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl sm:text-3xl font-bold",children:"Countries"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Shipping countries and VAT rates"})]}),e.jsxs(l,{onClick:()=>r(!0),children:[e.jsx(X,{className:"h-4 w-4 mr-2"})," Add Country"]})]}),e.jsx(L,{children:w?e.jsx("div",{className:"flex justify-center py-12",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):x.length===0?e.jsx(M,{icon:_,title:"No countries",description:"Add your first country"}):e.jsxs(I,{children:[e.jsx(K,{children:e.jsxs(T,{children:[e.jsx(t,{children:"Name"}),e.jsx(t,{children:"Phone Code"}),e.jsx(t,{children:"VAT"}),e.jsx(t,{children:"Shippable"}),e.jsx(t,{className:"w-[60px]"})]})}),e.jsx(V,{children:x.map(s=>e.jsxs(T,{children:[e.jsx(i,{className:"font-medium",children:s.name}),e.jsx(i,{className:"text-muted-foreground",children:s.phone_code||"â"}),e.jsx(i,{children:s.vat_rate!=null?`${s.vat_rate}%`:"â"}),e.jsx(i,{children:e.jsx(A,{checked:s.shippable===1,onCheckedChange:q=>E.mutate({id:s.id,shippable:q?1:0})})}),e.jsx(i,{children:e.jsx(l,{variant:"ghost",size:"icon",onClick:()=>p(s.id),children:e.jsx($,{className:"h-4 w-4"})})})]},s.id))})]})})]}),e.jsx(B,{open:D,onOpenChange:r,children:e.jsxs(H,{children:[e.jsx(O,{children:e.jsx(R,{children:"Add Country"})}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Name *"}),e.jsx(g,{value:h,onChange:s=>C(s.target.value)})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(d,{children:"Phone Code"}),e.jsx(g,{value:y,onChange:s=>b(s.target.value),placeholder:"+1"})]}),e.jsxs("div",{children:[e.jsx(d,{children:"VAT Rate (%)"}),e.jsx(g,{type:"number",step:"0.01",value:m,onChange:s=>v(s.target.value)})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(A,{checked:f,onCheckedChange:k}),e.jsx(d,{children:"Shippable"})]})]}),e.jsxs(z,{children:[e.jsx(l,{variant:"outline",onClick:()=>r(!1),children:"Cancel"}),e.jsx(l,{onClick:()=>N.mutate(),disabled:!h.trim()||N.isPending,children:"Create"})]})]})}),e.jsx(U,{open:!!o,onOpenChange:s=>!s&&p(null),onConfirm:()=>o&&S.mutate(o),entityType:"country",entityName:P?.name||"",isLoading:S.isPending})]})}const de=J;export{de as component};
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.