2 lines
19 KiB
JavaScript
2 lines
19 KiB
JavaScript
import{r as ie,j as e,i as ae,a as x,B as i,N as g,T as n,H as le,S as h,C as q,c as ce,O as de,Q as xe,L as Q,M as A,I as K}from"./index-mDUCEeiv.js";import{d as he,D as V,a as Z,b as J,c as X,e as ge}from"./EditOutlined-DPEfueeg.js";import{d as ee,T as ue,D as pe,a as fe}from"./PhoneOutlined-D4BtJark.js";import{c as M,d as me,a as je,b as O,e as be}from"./StorefrontOutlined-IamnnXx-.js";import{d as ye}from"./MapOutlined-8orJpqdf.js";import{P as ve,G as a,a as z,A as _e}from"./PageHeader-BsmqkaPM.js";import{C as re}from"./Link-BkghO-68.js";import{T as y}from"./TextField-CdVeyUgA.js";import{I as Ce}from"./InputAdornment-Bt0pkIZg.js";import{B as S}from"./Button-D2bq7RYw.js";import"./TableCell-DO9lQMOx.js";var U={},Se=ae;Object.defineProperty(U,"__esModule",{value:!0});var W=U.default=void 0,Ie=Se(ie()),ke=e;W=U.default=(0,Ie.default)((0,ke.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 $="https://api.doormile.com/api/v1",se=()=>{const r=localStorage.getItem("auth_token");return{"Content-Type":"application/json",...r?{Authorization:`Bearer ${r}`}:{}}},Re={textTransform:"uppercase",letterSpacing:.4,fontSize:"0.68rem",fontWeight:700,color:"grey.700"};function Y({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:Re,children:r}),e.jsx(i,{sx:{mt:.5},children:o})]})}function L({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 T({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 ze(){const r=await fetch(`${$}/admin/competitor-branches?limit=1000`,{headers:se()});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 We(r){const o=!!r.id,l=o?`${$}/admin/competitor-branches/${r.id}`:`${$}/admin/competitor-branches`,s=await fetch(l,{method:o?"PUT":"POST",headers:se(),body:JSON.stringify(r)});if(!s.ok){const c=await s.json().catch(()=>({}));throw new Error(c.error||c.message||"Failed to save survey")}return s.status===204?{}:s.json().catch(()=>({}))}function Pe({open:r,onClose:o,onSave:l,initialData:u}){const[s,c]=x.useState({}),[p,m]=x.useState(!1),[d,I]=x.useState(null);x.useEffect(()=>{r&&(c(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=>{c(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 We(C),l(),o()}catch(C){console.error(C),I(C.message||"Failed to save. Please try again.")}finally{m(!1)}};return e.jsxs(V,{open:r,onClose:p?void 0:o,maxWidth:"sm",fullWidth:!0,children:[e.jsx(Z,{sx:{fontWeight:800},children:u?"Edit Survey Record":"Add New Survey"}),e.jsxs(J,{dividers:!0,children:[d&&e.jsx(_e,{severity:"error",sx:{mb:2},children:d}),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(A,{value:"yes",children:"Yes"}),e.jsx(A,{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(A,{value:"yes",children:"Yes"}),e.jsx(A,{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(X,{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 we({row:r,onEdit:o,onDelete:l,users:u}){const[s,c]=x.useState(!1),p=u.find(d=>d.id===r.created_by),m=u.find(d=>d.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:()=>c(!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(O,{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(ee,{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(Y,{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(K,{size:"small",onClick:d=>{d.stopPropagation(),o(r)},sx:{color:"grey.400","&:hover":{color:"#c01227",bgcolor:g("#c01227",.1)}},children:e.jsx(ge,{fontSize:"small"})}),e.jsx(K,{size:"small",onClick:d=>{d.stopPropagation(),l(r)},sx:{color:"grey.400","&:hover":{color:"#ef4444",bgcolor:g("#ef4444",.1)}},children:e.jsx(fe,{fontSize:"small"})})]})]}),e.jsx(Q,{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(T,{icon:M,title:"ENQUIRY DETAILS",children:[e.jsx(b,{label:"RATE PER KG",children:e.jsx(Y,{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(T,{icon:be,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(T,{icon:O,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(O,{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(ye,{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(T,{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 Ee({companyName:r,branches:o,onEdit:l,onDelete:u,users:s}){const[c,p]=x.useState(!1);return e.jsxs(re,{elevation:0,sx:{borderRadius:3,border:"1px solid",borderColor:c?"#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(!c),sx:{cursor:"pointer",userSelect:"none"},children:[e.jsxs(h,{direction:"row",spacing:2.5,alignItems:"center",children:[e.jsx(xe,{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(M,{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:c?"#c01227":"grey.700",bgcolor:c?g("#c01227",.1):"grey.100","&:hover":{bgcolor:g("#c01227",.15),color:"#c01227"}},endIcon:c?e.jsx(me,{}):e.jsx(je,{}),children:c?"Hide Locations":"View Locations"})})]})]}),e.jsx(Q,{in:c,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,d)=>e.jsx(we,{row:m,onEdit:l,onDelete:u,users:s},m.id??d))})})})]})}function Ne(){const[r,o]=x.useState([]),[l,u]=x.useState(!0),[s,c]=x.useState(""),[p,m]=x.useState(0),[d,I]=x.useState(5),[j,k]=x.useState(!1),[C,P]=x.useState(null),[v,w]=x.useState(null),[E,B]=x.useState(!1),[te,oe]=x.useState([]),D=()=>{let t=!1;return u(!0),Promise.all([ze(),ce().catch(()=>[])]).then(([f,R])=>{t||(o(f.data||f||[]),oe(R||[]))}).catch(f=>console.error("Error fetching data:",f)).finally(()=>{t||u(!1)}),()=>{t=!0}};x.useEffect(()=>D(),[]);const ne=async()=>{B(!0);try{await de(v.id),w(null),D()}catch(t){console.error(t)}finally{B(!1)}},F=r.filter(t=>(t.company||"").toLowerCase().includes(s.toLowerCase())||(t.area||"").toLowerCase().includes(s.toLowerCase())||(t.phone||"").toLowerCase().includes(s.toLowerCase())),H=F.reduce((t,f)=>{const R=f.company||"Unknown Company";return t[R]||(t[R]=[]),t[R].push(f),t},{}),N=Object.keys(H).sort(),G=N.slice(p*d,p*d+d),_={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(ve,{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(L,{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(L,{title:"RATES QUOTED",value:l?"...":_.quoted,icon:M,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(L,{title:"MISSING INFO",value:l?"...":_.missing,icon:ee,gradient:"linear-gradient(135deg, #334155 0%, #0f172a 100%)",percentage:_.total?`${Math.round(_.missing/_.total*100)}%`:"0%"})})]}),e.jsxs(re,{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=>{c(t.target.value),m(0)},sx:{width:{xs:"100%",md:400}},InputProps:{startAdornment:e.jsx(Ce,{position:"start",children:e.jsx(le,{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:[F.length," records"]}),e.jsx(S,{variant:"contained",startIcon:e.jsx(he,{}),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(q,{})}):G.length>0?e.jsx(i,{children:G.map(t=>e.jsx(Ee,{companyName:t,branches:H[t],onEdit:f=>{P(f),k(!0)},onDelete:f=>w(f),users:te},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(ue,{component:"div",count:N.length,page:p,onPageChange:(t,f)=>m(f),rowsPerPage:d,onRowsPerPageChange:t=>{I(parseInt(t.target.value,10)),m(0)},rowsPerPageOptions:[5,10,25],labelRowsPerPage:"Companies per page:"})})]}),e.jsx(Pe,{open:j,onClose:()=>k(!1),onSave:()=>D(),initialData:C}),e.jsxs(V,{open:!!v,onClose:E?void 0:()=>w(null),children:[e.jsx(Z,{children:"Delete survey record?"}),e.jsx(J,{children:e.jsxs(pe,{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."]})}),e.jsxs(X,{sx:{px:3,py:2},children:[e.jsx(S,{onClick:()=>w(null),disabled:E,color:"inherit",children:"Cancel"}),e.jsx(S,{color:"error",variant:"contained",onClick:ne,disabled:E,startIcon:E?e.jsx(q,{size:16,color:"inherit"}):null,children:"Delete"})]})]})]})}export{Ne as default};
|