2 lines
20 KiB
JavaScript
2 lines
20 KiB
JavaScript
import{r as ce,j as e,i as de,a as c,B as i,N as g,T as n,H as xe,S as h,C as Y,c as he,O as ge,Q as ue,L as Z,M as T,I as Q}from"./index-DToJe2Ku.js";import{d as pe,D as J,a as X,b as ee,c as re,e as fe}from"./EditOutlined-HstnAQKL.js";import{d as se,T as me,D as je,a as be}from"./PhoneOutlined-DwV4_75a.js";import{c as U,d as ye,a as ve,b as L,e as _e}from"./StorefrontOutlined-v_5N-JWE.js";import{d as Ce}from"./MapOutlined-DQTjtFo4.js";import{P as Se,G as a,A as te,a as z}from"./PageHeader-CpHrViiJ.js";import{C as oe}from"./Link-vyutVhMN.js";import{T as y}from"./TextField-BWG9GEvb.js";import{I as Ie}from"./InputAdornment-BhldVMji.js";import{B as S}from"./Button-LbQOCjty.js";import"./TableCell-eZ4CXwlI.js";var F={},ke=de;Object.defineProperty(F,"__esModule",{value:!0});var W=F.default=void 0,Re=ke(ce()),ze=e;W=F.default=(0,Re.default)((0,ze.jsx)("path",{d:"M7 15h7v2H7zm0-4h10v2H7zm0-4h10v2H7zm12-4h-4.18C14.4 1.84 13.3 1 12 1c-1.3 0-2.4.84-2.82 2H5c-.14 0-.27.01-.4.04-.39.08-.74.28-1.01.55-.18.18-.33.4-.43.64-.1.23-.16.49-.16.77v14c0 .27.06.54.16.78s.25.45.43.64c.27.27.62.47 1.01.55.13.02.26.03.4.03h14c1.1 0 2-.9 2-2V5c0-1.1-.9-2-2-2m-7-.25c.41 0 .75.34.75.75s-.34.75-.75.75-.75-.34-.75-.75.34-.75.75-.75M19 19H5V5h14z"}),"AssignmentOutlined");const M="https://api.doormile.com/api/v1",ne=()=>{const r=localStorage.getItem("auth_token");return{"Content-Type":"application/json",...r?{Authorization:`Bearer ${r}`}:{}}},We={textTransform:"uppercase",letterSpacing:.4,fontSize:"0.68rem",fontWeight:700,color:"grey.700"};function V({label:r,color:o="default"}){return r?e.jsx(z,{size:"small",label:r,sx:{fontWeight:600,...o==="default"?{bgcolor:"grey.100",color:"grey.700"}:{bgcolor:`${o}.lighter`,color:`${o}.dark`}}}):e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:"grey.500"},children:"—"})}function b({label:r,children:o}){return e.jsxs(i,{children:[e.jsx(n,{variant:"caption",color:"text.secondary",sx:We,children:r}),e.jsx(i,{sx:{mt:.5},children:o})]})}function $({title:r,value:o,icon:l,gradient:u,percentage:s}){return e.jsxs(i,{sx:{position:"relative",overflow:"hidden",borderRadius:3.5,p:3,color:"white",background:u,boxShadow:"0 10px 30px rgba(0,0,0,0.08)",transition:"box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{boxShadow:"0 20px 40px rgba(0,0,0,0.12)"}},children:[e.jsxs(i,{sx:{position:"relative",zIndex:2},children:[e.jsxs(h,{direction:"row",justifyContent:"space-between",alignItems:"center",children:[e.jsx(n,{variant:"overline",sx:{fontWeight:700,letterSpacing:1.2,opacity:.9},children:r}),e.jsx(i,{sx:{width:36,height:36,borderRadius:"50%",bgcolor:"rgba(255,255,255,0.2)",display:"flex",alignItems:"center",justifyContent:"center",backdropFilter:"blur(4px)"},children:e.jsx(l,{sx:{fontSize:20}})})]}),e.jsxs(h,{direction:"row",alignItems:"baseline",spacing:1.5,sx:{mt:2},children:[e.jsx(n,{variant:"h3",sx:{fontWeight:800,lineHeight:1},children:o}),s&&e.jsx(z,{size:"small",label:s,sx:{height:22,bgcolor:"rgba(255,255,255,0.25)",color:"white",fontWeight:700,borderRadius:1.5,backdropFilter:"blur(4px)"}})]})]}),e.jsx(l,{sx:{position:"absolute",right:-24,bottom:-24,fontSize:160,opacity:.1,zIndex:1,transform:"rotate(-15deg)"}})]})}function D({icon:r,title:o,children:l}){return e.jsxs(i,{sx:{height:"100%",borderRadius:2,border:1,borderColor:"divider",bgcolor:"background.paper",overflow:"hidden"},children:[e.jsxs(h,{direction:"row",spacing:1,alignItems:"center",sx:{px:2,py:1.25,borderBottom:1,borderColor:"divider",bgcolor:g("#c01227",.08)},children:[e.jsx(r,{sx:{fontSize:18,color:"#c01227"}}),e.jsx(n,{variant:"overline",sx:{fontWeight:700,color:"grey.800",letterSpacing:.6,lineHeight:1},children:o})]}),e.jsx(h,{spacing:2,sx:{p:2},children:l})]})}async function Pe(){const r=await fetch(`${M}/admin/competitor-branches?limit=1000`,{headers:ne()});if(!r.ok)throw new Error("Failed to fetch surveys");const o=await r.json(),l=Array.isArray(o)?o:o.data||[];return{data:l,total:l.length}}async function Ee(r){const o=!!r.id,l=o?`${M}/admin/competitor-branches/${r.id}`:`${M}/admin/competitor-branches`,s=await fetch(l,{method:o?"PUT":"POST",headers:ne(),body:JSON.stringify(r)});if(!s.ok){const d=await s.json().catch(()=>({}));throw new Error(d.error||d.message||"Failed to save survey")}return s.status===204?{}:s.json().catch(()=>({}))}function we({open:r,onClose:o,onSave:l,initialData:u}){const[s,d]=c.useState({}),[p,m]=c.useState(!1),[x,I]=c.useState(null);c.useEffect(()=>{r&&(d(u||{company:"",area:"",phone:"",rate_per_kg:"",offers_pickup:"no",offers_drop:"no",packing_charge:"",time_in_days:"",plus_code:"",address:""}),I(null))},[r,u]);const j=C=>P=>{d(v=>({...v,[C]:P.target.value}))},k=async()=>{m(!0),I(null);try{const C={...s.id?{id:s.id}:{},company:s.company||"",area:s.area||"",phone:s.phone||"",rate_per_kg:s.rate_per_kg||"",offers_pickup:s.offers_pickup||"no",offers_drop:s.offers_drop||"no",packing_charge:s.packing_charge||"",time_in_days:s.time_in_days||"",plus_code:s.plus_code||"",address:s.address||""};await Ee(C),l(),o()}catch(C){console.error(C),I(C.message||"Failed to save. Please try again.")}finally{m(!1)}};return e.jsxs(J,{open:r,onClose:p?void 0:o,maxWidth:"sm",fullWidth:!0,children:[e.jsx(X,{sx:{fontWeight:800},children:u?"Edit Survey Record":"Add New Survey"}),e.jsxs(ee,{dividers:!0,children:[x&&e.jsx(te,{severity:"error",sx:{mb:2},children:x}),e.jsxs(a,{container:!0,spacing:2,children:[e.jsx(a,{item:!0,xs:12,sm:6,children:e.jsx(y,{fullWidth:!0,label:"Company",value:s.company||"",onChange:j("company"),size:"small"})}),e.jsx(a,{item:!0,xs:12,sm:6,children:e.jsx(y,{fullWidth:!0,label:"Area / Zone",value:s.area||"",onChange:j("area"),size:"small"})}),e.jsx(a,{item:!0,xs:12,sm:6,children:e.jsx(y,{fullWidth:!0,label:"Phone",value:s.phone||"",onChange:j("phone"),size:"small"})}),e.jsx(a,{item:!0,xs:12,sm:6,children:e.jsx(y,{fullWidth:!0,label:"Rate Per KG",value:s.rate_per_kg||"",onChange:j("rate_per_kg"),size:"small"})}),e.jsx(a,{item:!0,xs:12,sm:6,children:e.jsxs(y,{select:!0,fullWidth:!0,label:"Offers Pickup",value:s.offers_pickup||"no",onChange:j("offers_pickup"),size:"small",children:[e.jsx(T,{value:"yes",children:"Yes"}),e.jsx(T,{value:"no",children:"No"})]})}),e.jsx(a,{item:!0,xs:12,sm:6,children:e.jsxs(y,{select:!0,fullWidth:!0,label:"Offers Drop",value:s.offers_drop||"no",onChange:j("offers_drop"),size:"small",children:[e.jsx(T,{value:"yes",children:"Yes"}),e.jsx(T,{value:"no",children:"No"})]})}),e.jsx(a,{item:!0,xs:12,sm:6,children:e.jsx(y,{fullWidth:!0,label:"Time in Days",value:s.time_in_days||"",onChange:j("time_in_days"),size:"small"})}),e.jsx(a,{item:!0,xs:12,sm:6,children:e.jsx(y,{fullWidth:!0,label:"Packing Charge",value:s.packing_charge||"",onChange:j("packing_charge"),size:"small"})}),e.jsx(a,{item:!0,xs:12,children:e.jsx(y,{fullWidth:!0,label:"Plus Code",value:s.plus_code||"",onChange:j("plus_code"),size:"small"})}),e.jsx(a,{item:!0,xs:12,children:e.jsx(y,{fullWidth:!0,multiline:!0,rows:2,label:"Address",value:s.address||"",onChange:j("address"),size:"small"})})]})]}),e.jsxs(re,{sx:{p:2,bgcolor:"grey.50"},children:[e.jsx(S,{onClick:o,disabled:p,color:"inherit",children:"Cancel"}),e.jsx(S,{onClick:k,disabled:p,variant:"contained",sx:{bgcolor:"#c01227","&:hover":{bgcolor:"#a00f20"},borderRadius:2},children:p?"Saving...":"Save Record"})]})]})}function Ae({row:r,onEdit:o,onDelete:l,users:u}){const[s,d]=c.useState(!1),p=u.find(x=>x.id===r.created_by),m=u.find(x=>x.id===r.updated_by);return e.jsxs(i,{sx:{p:2,borderRadius:2.5,border:"1px solid",borderColor:"divider",bgcolor:"background.paper",transition:"border-color 0.2s ease, box-shadow 0.2s ease","&:hover":{borderColor:"#c01227",boxShadow:"0 4px 12px rgba(192, 18, 39, 0.05)"}},children:[e.jsxs(h,{direction:{xs:"column",md:"row"},spacing:3,alignItems:{xs:"flex-start",md:"center"},justifyContent:"space-between",onClick:()=>d(!s),sx:{cursor:"pointer",userSelect:"none"},children:[e.jsxs(h,{direction:"row",spacing:2,alignItems:"center",sx:{minWidth:240},children:[e.jsx(i,{sx:{p:1.5,borderRadius:2,bgcolor:g("#c01227",.05)},children:e.jsx(L,{sx:{color:"#c01227"}})}),e.jsxs(i,{children:[e.jsx(n,{variant:"subtitle1",sx:{fontWeight:700,color:"grey.900",lineHeight:1.2},children:r.area||"Unknown Area"}),e.jsxs(n,{variant:"body2",sx:{color:"grey.600",display:"flex",alignItems:"center",gap:.5,mt:.5},children:[e.jsx(se,{sx:{fontSize:14}})," ",r.phone||"—"]})]})]}),e.jsxs(h,{direction:"row",spacing:4,sx:{flex:1},justifyContent:{xs:"flex-start",md:"center"},children:[e.jsxs(i,{children:[e.jsx(n,{variant:"caption",sx:{color:"grey.500",fontWeight:700,letterSpacing:.5,display:"block",mb:.5},children:"RATE PER KG"}),e.jsx(V,{label:r.rate_per_kg,color:"success"})]}),e.jsxs(i,{children:[e.jsx(n,{variant:"caption",sx:{color:"grey.500",fontWeight:700,letterSpacing:.5,display:"block",mb:.5},children:"LOGISTICS"}),e.jsx(n,{variant:"body2",sx:{fontWeight:600,color:"grey.800"},children:r.offers_pickup==="yes"||r.offers_drop==="yes"?`${r.offers_pickup==="yes"?"Pickup":""} ${r.offers_drop==="yes"?"Drop":""}`:"—"})]})]}),e.jsxs(h,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(S,{size:"small",sx:{borderRadius:1.5,color:s?"#c01227":"grey.700",bgcolor:s?g("#c01227",.05):"transparent","&:hover":{bgcolor:g("#c01227",.1),color:"#c01227"}},children:s?"Hide Info":"More Info"}),e.jsx(Q,{size:"small",onClick:x=>{x.stopPropagation(),o(r)},sx:{color:"grey.400","&:hover":{color:"#c01227",bgcolor:g("#c01227",.1)}},children:e.jsx(fe,{fontSize:"small"})}),e.jsx(Q,{size:"small",onClick:x=>{x.stopPropagation(),l(r)},sx:{color:"grey.400","&:hover":{color:"#ef4444",bgcolor:g("#ef4444",.1)}},children:e.jsx(be,{fontSize:"small"})})]})]}),e.jsx(Z,{in:s,timeout:"auto",unmountOnExit:!0,children:e.jsx(i,{sx:{mt:2.5,pt:2.5,borderTop:"1px dashed",borderColor:"divider"},children:e.jsxs(a,{container:!0,spacing:2,alignItems:"stretch",children:[e.jsx(a,{item:!0,xs:12,md:4,children:e.jsxs(D,{icon:U,title:"ENQUIRY DETAILS",children:[e.jsx(b,{label:"RATE PER KG",children:e.jsx(V,{label:r.rate_per_kg,color:"success"})}),e.jsx(b,{label:"PICKUP",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:r.offers_pickup?"grey.800":"grey.500"},children:r.offers_pickup||"—"})}),e.jsx(b,{label:"DROP",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:r.offers_drop?"grey.800":"grey.500"},children:r.offers_drop||"—"})}),e.jsx(b,{label:"PACKING",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:r.packing_charge?"grey.800":"grey.500"},children:r.packing_charge||"—"})})]})}),e.jsx(a,{item:!0,xs:12,md:4,children:e.jsxs(D,{icon:_e,title:"LOGISTICS & OPS",children:[e.jsx(b,{label:"TIME IN DAYS",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:r.time_in_days?"grey.800":"grey.500"},children:r.time_in_days||"—"})}),e.jsx(b,{label:"COMPANY",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:"grey.800"},children:r.company||"—"})}),e.jsx(b,{label:"CONTACT NUMBER",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:"grey.800"},children:r.phone||"—"})})]})}),e.jsx(a,{item:!0,xs:12,md:4,children:e.jsxs(D,{icon:L,title:"LOCATION & PINCODE",children:[e.jsx(b,{label:"AREA / ZONE",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:"grey.800"},children:r.area||"—"})}),e.jsx(b,{label:"PLUS CODE",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:r.plus_code?"grey.800":"grey.500"},children:r.plus_code||"—"})}),e.jsx(b,{label:"FULL ADDRESS",children:e.jsxs(h,{spacing:1.5,children:[e.jsxs(h,{direction:"row",spacing:1,sx:{p:1.5,borderRadius:1.5,bgcolor:"grey.50",border:1,borderColor:"divider"},children:[e.jsx(L,{sx:{fontSize:16,color:"grey.400",mt:"2px"}}),e.jsx(n,{variant:"body2",sx:{color:"grey.800",lineHeight:1.5},children:r.address||"—"})]}),(r.address||r.plus_code)&&e.jsx(S,{component:"a",href:`https://www.google.com/maps/search/?api=1&query=${encodeURIComponent(r.plus_code?r.plus_code+" "+(r.address||""):r.address)}`,target:"_blank",rel:"noopener",size:"small",variant:"outlined",startIcon:e.jsx(Ce,{sx:{fontSize:16}}),sx:{alignSelf:"flex-start",py:.5,px:1.5,fontSize:"0.75rem",fontWeight:600,borderRadius:2,color:"#c01227",borderColor:g("#c01227",.5),bgcolor:g("#c01227",.05),"&:hover":{borderColor:"#c01227",bgcolor:g("#c01227",.1)}},children:"View on map"})]})})]})}),e.jsx(a,{item:!0,xs:12,children:e.jsx(D,{icon:W,title:"RECORD METADATA",children:e.jsxs(a,{container:!0,spacing:2,children:[e.jsx(a,{item:!0,xs:6,children:e.jsx(b,{label:"CREATED BY",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:"grey.800"},children:p?p.first_name:r.created_by?`User ID: ${r.created_by}`:"System"})})}),e.jsx(a,{item:!0,xs:6,children:e.jsx(b,{label:"LAST EDITED BY",children:e.jsx(n,{variant:"body2",sx:{fontWeight:500,color:"grey.800"},children:m?m.first_name:r.updated_by?`User ID: ${r.updated_by}`:"—"})})})]})})})]})})})]})}function Te({companyName:r,branches:o,onEdit:l,onDelete:u,users:s}){const[d,p]=c.useState(!1);return e.jsxs(oe,{elevation:0,sx:{borderRadius:3,border:"1px solid",borderColor:d?"#c01227":"grey.200",p:{xs:2.5,md:3},mb:2.5,transition:"border-color 0.3s cubic-bezier(0.4, 0, 0.2, 1), box-shadow 0.3s cubic-bezier(0.4, 0, 0.2, 1)","&:hover":{borderColor:"#c01227",boxShadow:"0 8px 30px rgba(192, 18, 39, 0.08)"}},children:[e.jsxs(h,{direction:{xs:"column",md:"row"},spacing:3,alignItems:{xs:"flex-start",md:"center"},justifyContent:"space-between",onClick:()=>p(!d),sx:{cursor:"pointer",userSelect:"none"},children:[e.jsxs(h,{direction:"row",spacing:2.5,alignItems:"center",children:[e.jsx(ue,{sx:{width:64,height:64,bgcolor:g("#c01227",.1),color:"#c01227",fontWeight:800,fontSize:"1.5rem",borderRadius:2.5},children:(r||"A")[0].toUpperCase()}),e.jsxs(i,{children:[e.jsx(n,{variant:"h5",sx:{fontWeight:800,lineHeight:1.2,color:"grey.900"},children:r||"Unknown Company"}),e.jsxs(n,{variant:"body2",sx:{color:"grey.600",mt:.5,display:"flex",alignItems:"center",gap:.5},children:[e.jsx(U,{sx:{fontSize:16}})," ",o.length," Location",o.length!==1&&"s"," Surveyed"]})]})]}),e.jsxs(h,{direction:"row",spacing:3,alignItems:"center",children:[e.jsxs(h,{direction:"row",spacing:1,sx:{display:{xs:"none",md:"flex"}},children:[e.jsx(z,{size:"small",label:"First Mile",sx:{bgcolor:g("#c01227",.08),color:"#c01227",fontWeight:700,borderRadius:1.5}}),e.jsx(z,{size:"small",label:"Mid Mile",sx:{bgcolor:g("#c01227",.08),color:"#c01227",fontWeight:700,borderRadius:1.5}}),e.jsx(z,{size:"small",label:"Last Mile",sx:{bgcolor:g("#c01227",.08),color:"#c01227",fontWeight:700,borderRadius:1.5}})]}),e.jsx(h,{direction:"row",spacing:1.5,alignItems:"center",children:e.jsx(S,{sx:{borderRadius:2,py:1,px:3,fontWeight:700,color:d?"#c01227":"grey.700",bgcolor:d?g("#c01227",.1):"grey.100","&:hover":{bgcolor:g("#c01227",.15),color:"#c01227"}},endIcon:d?e.jsx(ye,{}):e.jsx(ve,{}),children:d?"Hide Locations":"View Locations"})})]})]}),e.jsx(Z,{in:d,timeout:"auto",unmountOnExit:!0,children:e.jsx(i,{sx:{mt:3,pt:3,borderTop:"2px dashed",borderColor:"grey.200"},children:e.jsx(h,{spacing:2,children:o.map((m,x)=>e.jsx(Ae,{row:m,onEdit:l,onDelete:u,users:s},m.id??x))})})})]})}function qe(){const[r,o]=c.useState([]),[l,u]=c.useState(!0),[s,d]=c.useState(""),[p,m]=c.useState(0),[x,I]=c.useState(5),[j,k]=c.useState(!1),[C,P]=c.useState(null),[v,E]=c.useState(null),[w,B]=c.useState(!1),[H,A]=c.useState(null),[ie,ae]=c.useState([]),O=()=>{let t=!1;return u(!0),Promise.all([Pe(),he().catch(()=>[])]).then(([f,R])=>{t||(o(f.data||f||[]),ae(R||[]))}).catch(f=>console.error("Error fetching data:",f)).finally(()=>{t||u(!1)}),()=>{t=!0}};c.useEffect(()=>O(),[]);const le=async()=>{B(!0),A(null);try{await ge(v.id),E(null),O()}catch(t){A(t.message||"Failed to delete. Please try again.")}finally{B(!1)}},N=r.filter(t=>(t.company||"").toLowerCase().includes(s.toLowerCase())||(t.area||"").toLowerCase().includes(s.toLowerCase())||(t.phone||"").toLowerCase().includes(s.toLowerCase())),G=N.reduce((t,f)=>{const R=f.company||"Unknown Company";return t[R]||(t[R]=[]),t[R].push(f),t},{}),q=Object.keys(G).sort(),K=q.slice(p*x,p*x+x),_={total:r.length,quoted:r.filter(t=>t.rate_per_kg&&!String(t.rate_per_kg).toLowerCase().includes("not answered")).length,missing:r.filter(t=>!t.rate_per_kg||String(t.rate_per_kg).toLowerCase().includes("not answered")).length};return e.jsxs(i,{sx:{pb:6,bgcolor:"#f8fafc",px:{xs:2,md:4},pt:3,minHeight:"100vh"},children:[e.jsx(Se,{title:"Field Surveys",breadcrumbs:[{label:"Survey Management"}]}),e.jsxs(a,{container:!0,spacing:3,sx:{mb:5,mt:1},children:[e.jsx(a,{item:!0,xs:12,md:4,children:e.jsx($,{title:"TOTAL ENQUIRIES",value:l?"...":_.total,icon:W,gradient:"linear-gradient(135deg, #e11d48 0%, #c01227 100%)"})}),e.jsx(a,{item:!0,xs:12,md:4,children:e.jsx($,{title:"RATES QUOTED",value:l?"...":_.quoted,icon:U,gradient:"linear-gradient(135deg, #10b981 0%, #047857 100%)",percentage:_.total?`${Math.round(_.quoted/_.total*100)}%`:"0%"})}),e.jsx(a,{item:!0,xs:12,md:4,children:e.jsx($,{title:"MISSING INFO",value:l?"...":_.missing,icon:se,gradient:"linear-gradient(135deg, #334155 0%, #0f172a 100%)",percentage:_.total?`${Math.round(_.missing/_.total*100)}%`:"0%"})})]}),e.jsxs(oe,{sx:{borderRadius:2,boxShadow:"0 4px 20px rgba(0,0,0,0.05)",overflow:"hidden"},children:[e.jsxs(i,{sx:{p:3,display:"flex",alignItems:"center",gap:2,borderBottom:"1px solid",borderColor:"grey.100"},children:[e.jsx(i,{sx:{width:48,height:48,borderRadius:2.5,bgcolor:g("#c01227",.1),color:"#c01227",display:"flex",alignItems:"center",justifyContent:"center"},children:e.jsx(W,{})}),e.jsxs(i,{children:[e.jsx(n,{variant:"h6",sx:{fontWeight:700,color:"grey.900"},children:"Survey Records"}),e.jsx(n,{variant:"body2",sx:{color:"grey.600",mt:.5},children:"Manage business enquiry and survey data from the field"})]})]}),e.jsxs(i,{sx:{p:2,borderBottom:"1px solid",borderColor:"grey.100",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[e.jsx(y,{size:"small",placeholder:"Search by company, area or phone...",value:s,onChange:t=>{d(t.target.value),m(0)},sx:{width:{xs:"100%",md:400}},InputProps:{startAdornment:e.jsx(Ie,{position:"start",children:e.jsx(xe,{fontSize:"small"})})}}),e.jsxs(h,{direction:"row",spacing:2,alignItems:"center",children:[!l&&e.jsxs(n,{variant:"body2",sx:{color:"grey.500",fontWeight:600},children:[N.length," records"]}),e.jsx(S,{variant:"contained",startIcon:e.jsx(pe,{}),onClick:()=>{P(null),k(!0)},sx:{bgcolor:"#c01227","&:hover":{bgcolor:"#a00f20"},borderRadius:2,px:2,fontWeight:700,whiteSpace:"nowrap"},children:"Add New Survey"})]})]}),e.jsx(i,{sx:{p:3,bgcolor:"grey.50"},children:l?e.jsx(i,{sx:{display:"flex",justifyContent:"center",py:8},children:e.jsx(Y,{})}):K.length>0?e.jsx(i,{children:K.map(t=>e.jsx(Te,{companyName:t,branches:G[t],onEdit:f=>{P(f),k(!0)},onDelete:f=>E(f),users:ie},t))}):e.jsxs(i,{sx:{py:10,textAlign:"center"},children:[e.jsx(W,{sx:{fontSize:48,color:"grey.300",mb:2}}),e.jsx(n,{variant:"h6",color:"text.secondary",children:"No survey records found."}),e.jsx(n,{variant:"body2",color:"text.disabled",sx:{mt:1},children:"Try adjusting your search filters."})]})}),e.jsx(i,{sx:{borderTop:"1px solid",borderColor:"grey.200",bgcolor:"white"},children:e.jsx(me,{component:"div",count:q.length,page:p,onPageChange:(t,f)=>m(f),rowsPerPage:x,onRowsPerPageChange:t=>{I(parseInt(t.target.value,10)),m(0)},rowsPerPageOptions:[5,10,25],labelRowsPerPage:"Companies per page:"})})]}),e.jsx(we,{open:j,onClose:()=>k(!1),onSave:()=>O(),initialData:C}),e.jsxs(J,{open:!!v,onClose:w?void 0:()=>{E(null),A(null)},children:[e.jsx(X,{children:"Delete survey record?"}),e.jsxs(ee,{children:[e.jsxs(je,{children:["This will permanently remove the record for ",e.jsx("strong",{children:(v==null?void 0:v.area)||(v==null?void 0:v.company)}),". This cannot be undone."]}),H&&e.jsx(te,{severity:"error",sx:{mt:2},children:H})]}),e.jsxs(re,{sx:{px:3,py:2},children:[e.jsx(S,{onClick:()=>{E(null),A(null)},disabled:w,color:"inherit",children:"Cancel"}),e.jsx(S,{color:"error",variant:"contained",onClick:le,disabled:w,startIcon:w?e.jsx(Y,{size:16,color:"inherit"}):null,children:"Delete"})]})]})]})}export{qe as default};
|