import{o as e}from"./rolldown-runtime-GyhWBpbT.js";import{i as t,r as n}from"./react-vendor-DoSylNpz.js";import{An as r,Bt as i,Cr as a,Dr as o,Fn as s,Fr as c,Hr as l,In as u,Kr as d,Ln as f,Mn as p,Nr as m,Rn as h,Sr as g,Wr as _,Wt as v,br as y,fr as b,hr as x,ii as S,ni as C,wr as w,zn as T,zr as E}from"./mui-vendor-1IGyn9nW.js";import{a as D,i as O,n as k,o as A,r as j,t as M}from"./validation-DnzgDZ_F.js";var N=e(S(),1),P=C(),F=({open:e,onClose:i,onSubmit:s,initialData:u,isSubmitting:d=!1})=>{let{control:f,handleSubmit:p,reset:h,formState:{errors:_}}=t({defaultValues:u||{contact_person:``,phone:``,email:``,designation:``,is_primary:!1}});return N.useEffect(()=>{e&&h(u||{contact_person:``,phone:``,email:``,designation:``,is_primary:!1})},[e,u,h]),(0,P.jsxs)(w,{open:e,onClose:i,maxWidth:`md`,fullWidth:!0,children:[(0,P.jsx)(y,{sx:{pb:1},children:u?`Edit Contact`:`Add Contact`}),(0,P.jsx)(g,{children:(0,P.jsx)(c,{sx:{pt:1},children:(0,P.jsx)(`form`,{id:`contact-form`,onSubmit:p(e=>{s(e)}),children:(0,P.jsxs)(b,{container:!0,spacing:3,children:[(0,P.jsxs)(b,{size:{xs:12},children:[(0,P.jsxs)(l,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600},children:[`Contact Person `,(0,P.jsx)(c,{component:`span`,sx:{color:`#f44336`},children:`*`})]}),(0,P.jsx)(n,{name:`contact_person`,control:f,rules:{required:`Contact person is required`},render:({field:e})=>(0,P.jsx)(r,{...e,placeholder:`e.g., John Doe`,fullWidth:!0,size:`small`,error:!!_.contact_person,helperText:_.contact_person?.message,disabled:d})})]}),(0,P.jsxs)(b,{size:{xs:12,sm:6},children:[(0,P.jsx)(l,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600},children:`Phone`}),(0,P.jsx)(n,{name:`phone`,control:f,rules:{pattern:{value:O,message:`Please enter a valid phone number (e.g., +91 9876543210 or 040-12345678)`},minLength:{value:10,message:`Phone number must be at least 10 digits`},maxLength:{value:15,message:`Phone number cannot exceed 15 characters`}},render:({field:e})=>(0,P.jsx)(r,{...e,placeholder:`e.g., +91 9876543210 or 040-12345678`,fullWidth:!0,size:`small`,error:!!_.phone,helperText:_.phone?.message||`Enter mobile number with country code (up to 15 digits). Example: +91 9876543210`,disabled:d,inputProps:{maxLength:15},onChange:t=>{let n=A(t.target.value);e.onChange(n)}})})]}),(0,P.jsxs)(b,{size:{xs:12,sm:6},children:[(0,P.jsx)(l,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600},children:`Designation`}),(0,P.jsx)(n,{name:`designation`,control:f,render:({field:e})=>(0,P.jsx)(r,{...e,placeholder:`e.g., Manager`,fullWidth:!0,size:`small`,disabled:d})})]}),(0,P.jsxs)(b,{size:{xs:12},children:[(0,P.jsx)(l,{variant:`subtitle2`,sx:{mb:.5,fontWeight:600},children:`Email`}),(0,P.jsx)(n,{name:`email`,control:f,rules:{pattern:{value:M,message:`Please enter a valid email address (e.g., john@company.com)`}},render:({field:e})=>(0,P.jsx)(r,{...e,placeholder:`e.g., john@company.com`,fullWidth:!0,size:`small`,error:!!_.email,helperText:_.email?.message,disabled:d})})]}),(0,P.jsx)(b,{size:{xs:12},children:(0,P.jsx)(n,{name:`is_primary`,control:f,render:({field:e})=>(0,P.jsx)(x,{control:(0,P.jsx)(o,{...e,checked:e.value,disabled:d}),label:`Primary Contact`})})})]})})})}),(0,P.jsxs)(a,{sx:{px:3,pb:2},children:[(0,P.jsx)(m,{onClick:i,disabled:d,children:`Cancel`}),(0,P.jsx)(m,{type:`submit`,form:`contact-form`,variant:`contained`,disabled:d,children:d?`Saving...`:u?`Update`:`Add`})]})]})},I=({contacts:e=[],onEdit:t,onDelete:n,isLoading:r=!1})=>{let a=Array.isArray(e)?e:[];return a.length===0?(0,P.jsx)(c,{sx:{textAlign:`center`,py:4},children:(0,P.jsx)(l,{variant:`body2`,color:`text.secondary`,children:`No contacts added yet. Click "Add Contact" to add one.`})}):(0,P.jsx)(u,{component:d,variant:`outlined`,children:(0,P.jsxs)(T,{size:`small`,children:[(0,P.jsx)(s,{children:(0,P.jsxs)(p,{sx:{bgcolor:`grey.50`},children:[(0,P.jsx)(f,{sx:{fontWeight:600},children:`Contact Person`}),(0,P.jsx)(f,{sx:{fontWeight:600},children:`Phone`}),(0,P.jsx)(f,{sx:{fontWeight:600},children:`Email`}),(0,P.jsx)(f,{sx:{fontWeight:600},children:`Designation`}),(0,P.jsx)(f,{sx:{fontWeight:600},children:`Primary`}),(0,P.jsx)(f,{align:`center`,sx:{fontWeight:600},children:`Actions`})]})}),(0,P.jsx)(h,{children:a.map(e=>(0,P.jsxs)(p,{hover:!0,children:[(0,P.jsx)(f,{children:e.contact_person}),(0,P.jsx)(f,{children:e.phone||`-`}),(0,P.jsx)(f,{children:e.email||`-`}),(0,P.jsx)(f,{children:e.designation||`-`}),(0,P.jsx)(f,{children:e.is_primary&&(0,P.jsx)(E,{label:`Primary`,size:`small`,color:`primary`})}),(0,P.jsxs)(f,{align:`center`,children:[(0,P.jsx)(_,{size:`small`,onClick:()=>t(e),disabled:r,color:`primary`,children:(0,P.jsx)(i,{fontSize:`small`})}),(0,P.jsx)(_,{size:`small`,onClick:()=>n(e.id),disabled:r,color:`error`,children:(0,P.jsx)(v,{fontSize:`small`})})]})]},e.id))})]})})};export{F as n,I as t};