import{d as N,a as T,dO as B,r as G,j as i,I as V,aK as W,g_ as K,g$ as O,h0 as X,h1 as H,h2 as J,h3 as Q,R as E,cs as U,h4 as Y,h5 as Z}from"./index-aa25c5ff.js";import{c as m,b as o,u as D}from"./index.esm-a7f661dc.js";import{o as ee}from"./yup-72cc4918.js";import"./GenericThumbnailView-e0343bac.js";import{F as y}from"./FormInput-dc74a5d8.js";import"./componentStyles-e32842f3.js";import"./ScrollableList-9498bc37.js";import{T as ie}from"./TextArea-d1a16eb1.js";import{S as x}from"./SelectComponent-8b6a2019.js";import{D as re}from"./Dialog-049271f6.js";import{D as oe}from"./DialogTitle-7a3842b8.js";import{D as ne}from"./DialogContent-f207f33c.js";import{G as n}from"./Grid2-d00e0f6a.js";import{D as te}from"./DialogActions-2338d733.js";const qe=({open:u,onClose:c,onSave:_,addressData:e,locationId:M})=>{var q,j,v;const f=N(),{mini:{miniStatesList:p,miniCountryParams:s,miniCountriesList:d,miniCountryLoading:I,miniCityList:h,miniStatesParams:l,miniStateLoading:R,miniCityParams:a,miniCityLoading:k}}=T(r=>B(r)),w=m().shape({address:o().required("Address is required"),country:m().shape({label:o().required("Country is required"),value:o().required("Country is required")}).required("Country is required"),state:m().shape({label:o().required("State is required"),value:o().required("State is required")}).required("State is required"),city:m().shape({label:o().required("City is required"),value:o().required("City is required")}).required("City is required"),pincode:o().required("Pincode is required").matches(/^[0-9]+$/,"Pincode must contain only numbers"),mobile:o().required("Phone number is required"),email:o().email("Invalid email").required("Email is required")}),{control:t,handleSubmit:$,reset:b,setValue:se,getValues:g}=D({resolver:ee(w)});G.useEffect(()=>{u&&b(e?{address:e.address||"",country:e.country?{label:e.country.name,value:e.country.id}:void 0,state:e.state?{label:e.state.name,value:e.state.id}:void 0,city:e.city?{label:e.city.name,value:e.city.id}:void 0,pincode:e.pincode||"",mobile:e.mobile||"",email:e.email||""}:{address:"",country:void 0,state:void 0,city:void 0,pincode:"",mobile:"",email:""})},[e,u]);const F=r=>{var S,C,z,A;const L={...(e==null?void 0:e.id)&&{id:e.id},address:r.address,country_id:(S=r.country)==null?void 0:S.value,state_id:(C=r.state)==null?void 0:C.value,city_id:(z=r.city)==null?void 0:z.value,pincode:r.pincode,mobile:r.mobile,email:r.email,address_type:2,location_id:((A=e==null?void 0:e.location)==null?void 0:A.id)||(e==null?void 0:e.location_id)||M},P=U(L);e!=null&&e.id?f(Y({obj:P,pageParams:{page:1,page_size:100,no_of_pages:1},callback:()=>{_(r),c()}})):f(Z({obj:P,pageParams:{page:1,page_size:100,no_of_pages:1},callback:()=>{_({...r,isNewAddress:!0}),c()}}))};return i.jsxs(re,{open:u,onClose:c,maxWidth:"md",fullWidth:!0,children:[i.jsxs(oe,{sx:{display:"flex",justifyContent:"space-between",alignItems:"center"},children:[e!=null&&e.id?"Edit Shipping Address":"Add Shipping Address",i.jsx(V,{onClick:c,children:i.jsx(W,{})})]}),i.jsxs("form",{onSubmit:$(F),children:[i.jsx(ne,{children:i.jsxs(n,{container:!0,spacing:2,children:[i.jsx(n,{size:{xs:12},children:i.jsx(ie,{name:"address",label:"Address",required:!0,control:t,placeholder:"Enter Address",minRows:3,maxRows:5,containerSx:{display:"grid",gap:1}})}),i.jsx(n,{size:{xs:12,md:6},children:i.jsx(x,{name:"country",label:"Country",control:t,required:!0,options:d==null?void 0:d.map(r=>({id:r.id,name:r.name})),loading:I,selectParams:{page:s.page,page_size:s.page_size,search:s.search,no_of_pages:s.no_of_pages},hasMore:s.page<s.no_of_pages,fetchapi:K,clearData:O})}),i.jsx(n,{size:{xs:12,md:6},children:i.jsx(x,{name:"state",label:"State",control:t,required:!0,options:p==null?void 0:p.map(r=>({id:r.id,name:r.name})),loading:R,selectParams:{page:l.page,page_size:l.page_size,search:l.search,no_of_pages:l.no_of_pages,country:(q=g("country"))==null?void 0:q.value},hasMore:l.page<l.no_of_pages,fetchapi:X,clearData:H})}),i.jsx(n,{size:{xs:12,md:6},children:i.jsx(x,{name:"city",label:"City",control:t,required:!0,options:h==null?void 0:h.map(r=>({id:r.id,name:r.name})),loading:k,selectParams:{page:a.page,page_size:a.page_size,search:a.search,no_of_pages:a.no_of_pages,country:(j=g("country"))==null?void 0:j.value,state:(v=g("state"))==null?void 0:v.value},hasMore:a.page<a.no_of_pages,fetchapi:J,clearData:Q})}),i.jsx(n,{size:{xs:12,md:6},children:i.jsx(y,{name:"pincode",label:"Pincode",required:!0,control:t,placeholder:"Enter Pincode",type:"number"})}),i.jsx(n,{size:{xs:12,md:6},children:i.jsx(y,{name:"mobile",label:"Phone Number",required:!0,control:t,placeholder:"Enter Phone Number"})}),i.jsx(n,{size:{xs:12,md:6},children:i.jsx(y,{name:"email",label:"Email",required:!0,control:t,placeholder:"Enter Email"})})]})}),i.jsxs(te,{children:[i.jsx(E,{onClick:c,variant:"outlined",children:"Cancel"}),i.jsx(E,{type:"submit",variant:"contained",color:"primary",children:"Save"})]})]})]})};export{qe as E};
