import{d as T,a as $,dN as B,r as G,j as i,I as V,aK as W,gL as K,gM as O,gN as Q,gO as X,gP as H,gQ as J,R as E,cs as U,gR as Y,gS as Z}from"./index-e0c07a84.js";import{c as m,b as o,u as D}from"./index.esm-79617ba5.js";import{o as ee}from"./yup-74a95d85.js";import"./GenericThumbnailView-d192caf7.js";import{F as y}from"./FormInput-7bb37f2a.js";import"./componentStyles-5432a72d.js";import"./ScrollableList-874c742d.js";import{T as ie}from"./TextArea-e9886f56.js";import{S as x}from"./SelectComponent-5a0ffb58.js";import{D as re,a as oe}from"./DialogContent-bfc00e3a.js";import{D as ne}from"./DialogTitle-d1ec1f1a.js";import{G as n}from"./Grid2-05f25635.js";import{D as se}from"./DialogActions-7f92619e.js";const fe=({open:u,onClose:c,onSave:_,addressData:e,locationId:M})=>{var q,j,v;const b=T(),{mini:{miniStatesList:p,miniCountryParams:t,miniCountriesList:d,miniCountryLoading:R,miniCityList:g,miniStatesParams:l,miniStateLoading:I,miniCityParams:a,miniCityLoading:N}}=$(r=>B(r)),k=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:s,handleSubmit:w,reset:f,setValue:te,getValues:h}=D({resolver:ee(k)});G.useEffect(()=>{u&&f(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 L=r=>{var S,C,z,A;const F={...(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(F);e!=null&&e.id?b(Y({obj:P,pageParams:{page:1,page_size:100,no_of_pages:1},callback:()=>{_(r),c()}})):b(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(ne,{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:w(L),children:[i.jsx(oe,{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:s,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:s,required:!0,options:d==null?void 0:d.map(r=>({id:r.id,name:r.name})),loading:R,selectParams:{page:t.page,page_size:t.page_size,search:t.search,no_of_pages:t.no_of_pages},hasMore:t.page<t.no_of_pages,fetchapi:K,clearData:O})}),i.jsx(n,{size:{xs:12,md:6},children:i.jsx(x,{name:"state",label:"State",control:s,required:!0,options:p==null?void 0:p.map(r=>({id:r.id,name:r.name})),loading:I,selectParams:{page:l.page,page_size:l.page_size,search:l.search,no_of_pages:l.no_of_pages,country:(q=h("country"))==null?void 0:q.value},hasMore:l.page<l.no_of_pages,fetchapi:Q,clearData:X})}),i.jsx(n,{size:{xs:12,md:6},children:i.jsx(x,{name:"city",label:"City",control:s,required:!0,options:g==null?void 0:g.map(r=>({id:r.id,name:r.name})),loading:N,selectParams:{page:a.page,page_size:a.page_size,search:a.search,no_of_pages:a.no_of_pages,country:(j=h("country"))==null?void 0:j.value,state:(v=h("state"))==null?void 0:v.value},hasMore:a.page<a.no_of_pages,fetchapi:H,clearData:J})}),i.jsx(n,{size:{xs:12,md:6},children:i.jsx(y,{name:"pincode",label:"Pincode",required:!0,control:s,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:s,placeholder:"Enter Phone Number"})}),i.jsx(n,{size:{xs:12,md:6},children:i.jsx(y,{name:"email",label:"Email",required:!0,control:s,placeholder:"Enter Email"})})]})}),i.jsxs(se,{children:[i.jsx(E,{onClick:c,variant:"outlined",children:"Cancel"}),i.jsx(E,{type:"submit",variant:"contained",color:"primary",children:"Save"})]})]})]})};export{fe as E};
