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,Nr as c,Sr as l,Wr as u,Zt as d,br as f,fr 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,agent:y,loading:b=!1})=>{let{control:x,handleSubmit:S,reset:C,formState:{errors:w}}=t({defaultValues:{code:``,name:``,phone:``,email:``}});(0,_.useEffect)(()=>{e&&C({code:y?.code||``,name:y?.name||``,phone:y?.phone||``,email:y?.email||``})},[e,y,C]);let T=async e=>{await h(e),C()},E=()=>{b||(C(),m())};return(0,v.jsxs)(g,{open:e,onClose:(e,t)=>{t!==`backdropClick`&&t!==`escapeKeyDown`&&E()},maxWidth:`md`,fullWidth:!0,children:[(0,v.jsxs)(f,{sx:{display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[y?`Edit Agent`:`Add Agent`,(0,v.jsx)(u,{onClick:E,size:`small`,disabled:b,sx:{color:`text.secondary`},children:(0,v.jsx)(d,{})})]}),(0,v.jsxs)(`form`,{onSubmit:S(T),children:[(0,v.jsx)(l,{sx:{py:1},children:(0,v.jsxs)(p,{container:!0,spacing:2,children:[(0,v.jsx)(p,{size:{xs:12,sm:6},children:(0,v.jsxs)(a,{children:[(0,v.jsx)(s,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600},children:`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:`Auto-generated`,fullWidth:!0,disabled:b,helperText:`Leave empty for auto-generation`,sx:{"& .MuiInputBase-root":{height:42,borderRadius:1}}})})]})}),(0,v.jsx)(p,{size:{xs:12,sm:6},children:(0,v.jsxs)(a,{children:[(0,v.jsxs)(s,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600},children:[`Name `,(0,v.jsx)(a,{component:`span`,sx:{color:`#f44336`},children:`*`})]}),(0,v.jsx)(n,{name:`name`,control:x,rules:{required:`Name is required`,minLength:{value:2,message:`Min 2 characters`}},render:({field:e})=>(0,v.jsx)(r,{...e,placeholder:`Agent name`,fullWidth:!0,error:!!w.name,helperText:w.name?.message,disabled:b,sx:{"& .MuiInputBase-root":{height:42,borderRadius:1}}})})]})}),(0,v.jsx)(p,{size:{xs:12,sm:6},children:(0,v.jsxs)(a,{children:[(0,v.jsxs)(s,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600},children:[`Phone `,(0,v.jsx)(a,{component:`span`,sx:{color:`#f44336`},children:`*`})]}),(0,v.jsx)(n,{name:`phone`,control:x,rules:{required:`Phone is required`,pattern:{value:/^[0-9]{10,15}$/,message:`Enter valid phone number`}},render:({field:e})=>(0,v.jsx)(r,{...e,placeholder:`Phone number`,fullWidth:!0,error:!!w.phone,helperText:w.phone?.message,disabled:b,sx:{"& .MuiInputBase-root":{height:42,borderRadius:1}}})})]})}),(0,v.jsx)(p,{size:{xs:12,sm:6},children:(0,v.jsxs)(a,{children:[(0,v.jsx)(s,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600},children:`Email`}),(0,v.jsx)(n,{name:`email`,control:x,rules:{pattern:{value:/^[^\s@]+@[^\s@]+\.[^\s@]+$/,message:`Invalid email`}},render:({field:e})=>(0,v.jsx)(r,{...e,placeholder:`Email (optional)`,fullWidth:!0,error:!!w.email,helperText:w.email?.message,disabled:b,sx:{"& .MuiInputBase-root":{height:42,borderRadius:1}}})})]})})]})}),(0,v.jsxs)(i,{sx:{px:3,pb:2},children:[(0,v.jsx)(c,{onClick:E,variant:`outlined`,disabled:b,sx:{minWidth:100},children:`Cancel`}),(0,v.jsx)(c,{type:`submit`,variant:`contained`,disabled:b,startIcon:b&&(0,v.jsx)(o,{size:16}),sx:{minWidth:100},children:b?`Saving...`:y?`Update`:`Create`})]})]})]})};export{y as t};