import{j as e}from"./query-PJ0ZdjbV.js";import{a as u}from"./vendor-CWhr2lg4.js";import{q as i}from"./index-BSPIaiZU.js";import{A as h}from"./async-select-BUbwdJEZ.js";import{r as R,x as $,a5 as k}from"./system-admin.api-BT5u-_A_.js";function I({value:t,onChange:c,disabled:r,required:x,hideCity:m,hideState:p,initialLabels:o,className:g}){const[S,j]=u.useState(""),[C,f]=u.useState(""),[Q,N]=u.useState(""),{data:a,isLoading:v}=R(S),{data:n,isLoading:P}=$(t.country,C),{data:d,isLoading:V}=k(t.state,Q),A=(a==null?void 0:a.results)??[],E=(n==null?void 0:n.results)??[],G=(d==null?void 0:d.results)??[],l=x?e.jsx("span",{className:"text-red-500",children:" *"}):null,y=1+(p?0:1)+(m?0:1),q=y===3?"grid-cols-3":y===2?"grid-cols-2":"grid-cols-1";return e.jsx("div",{className:g,children:e.jsxs("div",{className:`grid gap-3 ${q}`,children:[e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(i,{children:["Country",l]}),e.jsx(h,{value:t.country,onValueChange:s=>c({country:s,state:null,city:null}),onSearch:j,isLoading:v,options:A.map(s=>({value:s.id,label:s.name,hint:s.code})),selectedLabel:(o==null?void 0:o.country)??void 0,placeholder:"Country",searchPlaceholder:"Search countries...",disabled:r})]}),!p&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(i,{children:["State",l]}),e.jsx(h,{value:t.state,onValueChange:s=>c({...t,state:s,city:null}),onSearch:f,isLoading:P,options:E.map(s=>({value:s.id,label:s.name,hint:s.code})),selectedLabel:(o==null?void 0:o.state)??void 0,placeholder:t.country?"State":"Select country first",searchPlaceholder:"Search states...",disabled:r||!t.country})]}),!m&&e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs(i,{children:["City",l]}),e.jsx(h,{value:t.city,onValueChange:s=>c({...t,city:s}),onSearch:N,isLoading:V,options:G.map(s=>({value:s.id,label:s.name})),selectedLabel:(o==null?void 0:o.city)??void 0,placeholder:t.state?"City":"Select state first",searchPlaceholder:"Search cities...",disabled:r||!t.state})]})]})})}export{I as G};
