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