import{o as e}from"./rolldown-runtime-GyhWBpbT.js";import{i as t,r as n}from"./react-vendor-BD_NkAgt.js";import{Er as r,Fr as i,Jn as a,Kr as o,Lr as s,Mn as c,Sr as l,Tr as u,Wr as d,Zt as f,ii as p,oi as m,qr as h,wr as g}from"./mui-vendor-DsoH2_ot.js";var _=e(m(),1),v=p(),y=({open:e,onClose:p,onSubmit:m,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=>{m(e)},E=()=>{C(),p()};return(0,v.jsxs)(r,{open:e,onClose:(e,t)=>{t===`backdropClick`||t===`escapeKeyDown`||E()},maxWidth:`sm`,fullWidth:!0,children:[(0,v.jsxs)(l,{sx:{display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[y?`Edit Country`:`Add Country`,(0,v.jsx)(o,{"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)(g,{sx:{py:1},children:(0,v.jsx)(a,{spacing:2,children:(0,v.jsxs)(s,{children:[(0,v.jsxs)(d,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600,color:`text.primary`},children:[`Country Name `,(0,v.jsx)(s,{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)(c,{...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)(u,{sx:{px:3,pb:2,justifyContent:`flex-end`},children:[(0,v.jsx)(i,{onClick:E,disabled:b,children:`Cancel`}),(0,v.jsx)(i,{type:`submit`,variant:`contained`,disabled:b,startIcon:b?(0,v.jsx)(h,{size:20}):null,children:b?`Saving...`:`Save`})]})]})]})};export{y as t};