import{o as e}from"./rolldown-runtime-GyhWBpbT.js";import{i as t,r as n}from"./react-vendor-ChE_eana.js";import{An as r,Cr as i,Fr as a,Gr as o,Hr as s,Kn as c,Nr as l,Sr as u,Wr as d,Zt as f,br as p,ii as m,ni as h,wr as g}from"./mui-vendor-K60S-ugg.js";var _=e(m(),1),v=h(),y=({open:e,onClose:m,onSubmit:h,country:y,loading:b=!1})=>{let{control:x,handleSubmit:S,reset:C,formState:{errors:w}}=t({defaultValues:{code:``,name:``}});(0,_.useEffect)(()=>{e&&C({code:y?.code||``,name:y?.name||``})},[e,y,C]);let T=e=>{h(e)},E=()=>{C(),m()};return(0,v.jsxs)(g,{open:e,onClose:(e,t)=>{t===`backdropClick`||t===`escapeKeyDown`||E()},maxWidth:`sm`,fullWidth:!0,children:[(0,v.jsxs)(p,{sx:{display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[y?`Edit Country`:`Add Country`,(0,v.jsx)(d,{"aria-label":`close`,onClick:E,size:`small`,disabled:b,sx:{color:`text.secondary`},children:(0,v.jsx)(f,{})})]}),(0,v.jsxs)(`form`,{onSubmit:S(T),children:[(0,v.jsx)(u,{sx:{py:1},children:(0,v.jsxs)(c,{spacing:2,children:[(0,v.jsxs)(a,{children:[(0,v.jsx)(s,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600,color:`text.primary`},children:`Country Code`}),(0,v.jsx)(n,{name:`code`,control:x,render:({field:e})=>(0,v.jsx)(r,{...e,onChange:t=>e.onChange(t.target.value.toUpperCase()),placeholder:`Leave empty for auto-generation`,fullWidth:!0,error:!!w.code,helperText:w.code?.message||`Leave empty for auto-generation`,disabled:b,autoFocus:!0,sx:{"& .MuiInputBase-root":{height:42,borderRadius:1}}})})]}),(0,v.jsxs)(a,{children:[(0,v.jsxs)(s,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600,color:`text.primary`},children:[`Country Name `,(0,v.jsx)(a,{component:`span`,sx:{color:`#f44336`,fontWeight:600},children:`*`})]}),(0,v.jsx)(n,{name:`name`,control:x,rules:{required:`Country name is required`,maxLength:{value:100,message:`Country name must not exceed 100 characters`}},render:({field:e})=>(0,v.jsx)(r,{...e,placeholder:`e.g., United States, India`,fullWidth:!0,error:!!w.name,helperText:w.name?.message,sx:{"& .MuiInputBase-root":{height:42,borderRadius:1}},disabled:b})})]})]})}),(0,v.jsxs)(i,{sx:{px:3,pb:2,justifyContent:`flex-end`},children:[(0,v.jsx)(l,{onClick:E,disabled:b,children:`Cancel`}),(0,v.jsx)(l,{type:`submit`,variant:`contained`,disabled:b,startIcon:b?(0,v.jsx)(o,{size:20}):null,children:b?`Saving...`:`Save`})]})]})]})};export{y as t};