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,Kr as a,Lr as o,Mn as s,Sr as c,Tr as l,Wr as u,Zt as d,ii as f,mr as p,oi as m,qr as h,wr as g}from"./mui-vendor-DsoH2_ot.js";var _=e(m(),1),v=f(),y=({open:e,onClose:f,onSubmit:m,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 m(e),C()},E=()=>{b||(C(),f())};return(0,v.jsxs)(r,{open:e,onClose:(e,t)=>{t!==`backdropClick`&&t!==`escapeKeyDown`&&E()},maxWidth:`md`,fullWidth:!0,children:[(0,v.jsxs)(c,{sx:{display:`flex`,alignItems:`center`,justifyContent:`space-between`},children:[y?`Edit Agent`:`Add Agent`,(0,v.jsx)(a,{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)(g,{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)(o,{children:[(0,v.jsxs)(u,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600},children:[`Name `,(0,v.jsx)(o,{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)(s,{...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)(o,{children:[(0,v.jsxs)(u,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600},children:[`Phone `,(0,v.jsx)(o,{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)(s,{...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)(o,{children:[(0,v.jsx)(u,{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)(s,{...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)(l,{sx:{px:3,pb:2},children:[(0,v.jsx)(i,{onClick:E,variant:`outlined`,disabled:b,sx:{minWidth:100},children:`Cancel`}),(0,v.jsx)(i,{type:`submit`,variant:`contained`,disabled:b,startIcon:b&&(0,v.jsx)(h,{size:16}),sx:{minWidth:100},children:b?`Saving...`:y?`Update`:`Create`})]})]})]})};export{y as t};