import{j as e,r}from"./client-BbMi5ewG.js";import{T as P}from"./textarea-QytFj8hO.js";import{F as f}from"./FormField-66vt2hZL.js";import{I as T}from"./ImageUpload-DbfzQEp2.js";import{F,S as q}from"./StatusSwitcher-C3TepXSt.js";import{C as L,b,c as S,a as _}from"./card-CZBIFpqn.js";import{S as s}from"./skeleton-ImO4uxQ7.js";import{a as D,s as N,u as E}from"./store-jX25q14N.js";import{u as y}from"./useMediaUploader-lszBTVoc.js";import{f as M,i as $}from"./index-CM0LBdHD.js";function A(){return e.jsxs("main",{className:"flex-1 grid md:grid-cols-[1fr_300px] gap-6",children:[e.jsx("div",{className:"grid gap-6",children:e.jsxs(L,{children:[e.jsxs(b,{children:[e.jsx(S,{children:e.jsx(s,{className:"h-6 w-48"})}),e.jsx(s,{className:"h-4 w-64 mt-2"})]}),e.jsxs(_,{className:"grid gap-6",children:[e.jsxs("div",{className:"grid gap-2",children:[e.jsx(s,{className:"h-4 w-20"})," ",e.jsx(s,{className:"h-10 w-full"})," "]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(s,{className:"h-4 w-24"})," ",e.jsx(s,{className:"h-[80px] w-full"})," "]}),e.jsxs("div",{className:"grid gap-2",children:[e.jsx(s,{className:"h-4 w-20"})," ",e.jsx(s,{className:"h-10 w-full"})," "]}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:e.jsxs("div",{className:"grid gap-2",children:[e.jsx(s,{className:"h-4 w-16"})," ",e.jsx(s,{className:"h-10 w-full"})," "]})})]})]})}),e.jsxs("div",{className:"grid gap-6",children:[e.jsxs(L,{children:[e.jsx(b,{children:e.jsx(S,{children:e.jsx(s,{className:"h-6 w-24"})})}),e.jsx(_,{children:e.jsxs("div",{className:"grid gap-4",children:[e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(s,{className:"h-4 w-4 rounded-full"})," ",e.jsxs("div",{className:"grid gap-1",children:[e.jsx(s,{className:"h-4 w-20"})," ",e.jsx(s,{className:"h-3 w-48"})," "]})]}),e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(s,{className:"h-4 w-4 rounded-full"})," ",e.jsxs("div",{className:"grid gap-1",children:[e.jsx(s,{className:"h-4 w-20"})," ",e.jsx(s,{className:"h-3 w-48"})," "]})]})]})})]}),e.jsxs(L,{children:[e.jsx(b,{children:e.jsx(S,{children:e.jsx(s,{className:"h-6 w-20"})})}),e.jsxs(_,{children:[e.jsx(s,{className:"h-[180px] w-full rounded-lg"})," "]})]})]})]})}const H=()=>{const u=y(),{setLocationFormField:l,getLocation:o,setLocationData:v,setError:c}=D(N),{id:g}=M(),p=$().pathname,x=/^\/locations\/[^/]+\/edit\/?$/.test(p),a=E(i=>i(N).getLocation(),[]),n=E(i=>i(N).loading(),[]),t=E(i=>i(N).getError(),[]),w=r.useCallback(i=>{const{id:d,value:m}=i.target;console.log(d,m),l({field:d,value:m})},[l]),C=r.useCallback(()=>{u({title:"Select Location Photo",onSelect:({id:i,url:d,sizes:m})=>{var k;l({field:"image_id",value:i}),l({field:"picture_full_path",value:d}),l({field:"picture_thumb_path",value:((k=m==null?void 0:m.thumbnail)==null?void 0:k.url)||d})}})},[u,l]),j=r.useCallback(()=>{["picture_full_path","picture_thumb_path","image_id"].forEach(d=>l({field:d,value:""}))},[l]),U=r.useCallback(i=>{l({field:"status",value:i})},[l]),I=r.useCallback((i,d)=>{l({field:i,value:d})},[l]),R=r.useMemo(()=>[{id:"name",label:"Name",value:a.name,error:t==null?void 0:t.name,required:!0},{id:"description",label:"Description",value:a==null?void 0:a.description,required:!1},{id:"address",label:"Address",value:a==null?void 0:a.address,error:t==null?void 0:t.address,required:!0},{id:"phone",label:"Phone",value:a==null?void 0:a.phone,type:"tel",placeholder:"e.g., +8801234567890",required:!1}],[a,t]);return{location:a,loading:n,errors:t,isEditing:x,id:g,formFields:R,getLocation:o,setLocationData:v,setError:c,handleFieldChange:w,handleImageUpload:C,handleImageRemove:j,handleStatusChange:U,handleSetField:I}};function Z(u){const{resource:l}=u,{location:o,loading:v,isEditing:c,id:g,formFields:h,getLocation:p,setLocationData:x,setError:a,handleFieldChange:n,handleImageUpload:t,handleImageRemove:w,handleStatusChange:C}=H();r.useEffect(()=>(c?p(g):x({}),()=>{x({}),a({})}),[g,c,p,x,a]);const j=l==="sheet";return v?e.jsx(A,{}):e.jsxs("main",{className:`flex-1 grid ${j?"md:grid-cols-1":"md:grid-cols-[1fr_300px]"} gap-6`,children:[e.jsx("div",{className:"grid gap-6",children:e.jsx(F,{title:c?"Edit Location":"Create New Location",description:c?"Update the location details below.":"Fill in the details to add a new location.",children:e.jsxs("div",{className:"space-y-6",children:[e.jsx(f,{...h[0],onChange:n}),e.jsx(f,{...h[1],component:P,className:"min-h-[80px]",onChange:n}),e.jsx(f,{...h[2],onChange:n}),e.jsx(f,{...h[3],onChange:n})]})})}),!j&&e.jsxs("div",{className:"grid gap-6",children:[e.jsx(F,{title:"Status",children:e.jsx(q,{onValueChange:C,value:o==null?void 0:o.status,content:"Location"})}),e.jsx(F,{title:"Photos",children:e.jsx(T,{imagePath:o.picture_full_path,onUpload:t,onRemove:w})})]})]})}export{Z as L};
//# sourceMappingURL=AddLocationForm-9N2H0iL8.js.map
