Files
doormile_crm_build/dist/assets/Tenants-BHDAEYpM.js
2026-06-20 15:37:59 +05:30

2 lines
52 KiB
JavaScript

import{a as p,u as vr,h as Lt,k as at,s as jr,_ as w,l as rr,m as nr,n as sr,o as Ke,j as e,p as Me,q as mt,v as or,w as re,P as ar,x as ir,y as Cr,z as Le,I as Ne,A as Ot,r as bt,i as yt,T as C,M as it,D as zt,C as xt,E as Sr,F as Ir,G as Tr,t as ye,S as z,d as Vt,B as W,H as Pr,f as $r,e as Lr,J as Or,U as Gt,K as At,L as Ar}from"./index-DToJe2Ku.js";import{D as lr,a as cr,b as ur,c as dr,d as kr,e as qt}from"./EditOutlined-HstnAQKL.js";import{d as Rr,E as zr}from"./EmptyState-Cayd2Agb.js";import{T as wr,D as Dr,d as _r,a as Wr}from"./PhoneOutlined-DwV4_75a.js";import{d as Mr,a as Nr,b as lt,c as Er,e as Fr}from"./StorefrontOutlined-v_5N-JWE.js";import{S as ct,d as Br,a as pr,b as gr,c as Kt}from"./StatusChip-B16gdA9x.js";import{d as Hr}from"./MapOutlined-DQTjtFo4.js";import{T as Vr,a as Gr,b as qr,d as Kr}from"./TabLabelCount-Do8fdFrz.js";import{C as Ur,a as vt,A as hr,G as g,P as Jr}from"./PageHeader-CpHrViiJ.js";import{d as Zr}from"./Close-CDWIlUqJ.js";import{A as Xr,f as We,o as Ut,i as kt,T as L}from"./TextField-BWG9GEvb.js";import{B as pe}from"./Button-LbQOCjty.js";import{C as Yr}from"./Link-vyutVhMN.js";import{I as Qr}from"./InputAdornment-BhldVMji.js";import{T as en,a as tn,b as rn,c as Ue,d as nn}from"./TableRow-BUnIA1ki.js";import{T as N}from"./TableCell-eZ4CXwlI.js";const sn=t=>{const o=p.useRef({});return p.useEffect(()=>{o.current=t}),o.current};function Jt(t){return typeof t.normalize<"u"?t.normalize("NFD").replace(/[\u0300-\u036f]/g,""):t}function on(t={}){const{ignoreAccents:o=!0,ignoreCase:c=!0,limit:b,matchFrom:$="any",stringify:I,trim:s=!1}=t;return(h,{inputValue:k,getOptionLabel:E})=>{let D=s?k.trim():k;c&&(D=D.toLowerCase()),o&&(D=Jt(D));const _=D?h.filter(H=>{let O=(I||E)(H);return c&&(O=O.toLowerCase()),o&&(O=Jt(O)),$==="start"?O.indexOf(D)===0:O.indexOf(D)>-1}):h;return typeof b=="number"?_.slice(0,b):_}}function ut(t,o){for(let c=0;c<t.length;c+=1)if(o(t[c]))return c;return-1}const an=on(),Zt=5,ln=t=>{var o;return t.current!==null&&((o=t.current.parentElement)==null?void 0:o.contains(document.activeElement))},cn=[];function un(t){const{unstable_isActiveElementInListbox:o=ln,unstable_classNamePrefix:c="Mui",autoComplete:b=!1,autoHighlight:$=!1,autoSelect:I=!1,blurOnSelect:s=!1,clearOnBlur:h=!t.freeSolo,clearOnEscape:k=!1,componentName:E="useAutocomplete",defaultValue:D=t.multiple?cn:null,disableClearable:_=!1,disableCloseOnSelect:H=!1,disabled:O,disabledItemsFocusable:ve=!1,disableListWrap:T=!1,filterOptions:ge=an,filterSelectedOptions:u=!1,freeSolo:v=!1,getOptionDisabled:y,getOptionKey:Y,getOptionLabel:V=n=>{var r;return(r=n.label)!=null?r:n},groupBy:B,handleHomeEndKeys:K=!t.freeSolo,id:xe,includeInputInList:je=!1,inputValue:ne,isOptionEqualToValue:U=(n,r)=>n===r,multiple:S=!1,onChange:Ce,onClose:Se,onHighlightChange:l,onInputChange:m,onOpen:le,open:Mt,openOnFocus:Nt=!1,options:Ee,readOnly:Ie=!1,selectOnFocus:Fe=!t.freeSolo,value:Je}=t,Q=vr(xe);let J=V;J=n=>{const r=V(n);return typeof r!="string"?String(r):r};const Be=p.useRef(!1),Ze=p.useRef(!0),M=p.useRef(null),ee=p.useRef(null),[Oe,jt]=p.useState(null),[Z,He]=p.useState(-1),Xe=$?0:-1,G=p.useRef(Xe),[d,Et]=Lt({controlled:Je,default:D,name:E}),[j,he]=Lt({controlled:ne,default:"",name:E,state:"inputValue"}),[Ae,Ye]=p.useState(!1),Te=p.useCallback((n,r)=>{if(!(S?d.length<r.length:r!==null)&&!h)return;let i;if(S)i="";else if(r==null)i="";else{const x=J(r);i=typeof x=="string"?x:""}j!==i&&(he(i),m&&m(n,i,"reset"))},[J,j,S,m,he,h,d]),[me,Qe]=Lt({controlled:Mt,default:!1,name:E,state:"open"}),[Ct,et]=p.useState(!0),tt=!S&&d!=null&&j===J(d),X=me&&!Ie,P=X?ge(Ee.filter(n=>!(u&&(S?d:[d]).some(r=>r!==null&&U(n,r)))),{inputValue:tt&&Ct?"":j,getOptionLabel:J}):[],se=sn({filteredOptions:P,value:d,inputValue:j});p.useEffect(()=>{const n=d!==se.value;Ae&&!n||v&&!n||Te(null,d)},[d,Te,Ae,se.value,v]);const Ve=me&&P.length>0&&!Ie,ke=at(n=>{n===-1?M.current.focus():Oe.querySelector(`[data-tag-index="${n}"]`).focus()});p.useEffect(()=>{S&&Z>d.length-1&&(He(-1),ke(-1))},[d,S,Z,ke]);function Re(n,r){if(!ee.current||n<0||n>=P.length)return-1;let a=n;for(;;){const i=ee.current.querySelector(`[data-option-index="${a}"]`),x=ve?!1:!i||i.disabled||i.getAttribute("aria-disabled")==="true";if(i&&i.hasAttribute("tabindex")&&!x)return a;if(r==="next"?a=(a+1)%P.length:a=(a-1+P.length)%P.length,a===n)return-1}}const ce=at(({event:n,index:r,reason:a="auto"})=>{if(G.current=r,r===-1?M.current.removeAttribute("aria-activedescendant"):M.current.setAttribute("aria-activedescendant",`${Q}-option-${r}`),l&&l(n,r===-1?null:P[r],a),!ee.current)return;const i=ee.current.querySelector(`[role="option"].${c}-focused`);i&&(i.classList.remove(`${c}-focused`),i.classList.remove(`${c}-focusVisible`));let x=ee.current;if(ee.current.getAttribute("role")!=="listbox"&&(x=ee.current.parentElement.querySelector('[role="listbox"]')),!x)return;if(r===-1){x.scrollTop=0;return}const A=ee.current.querySelector(`[data-option-index="${r}"]`);if(A&&(A.classList.add(`${c}-focused`),a==="keyboard"&&A.classList.add(`${c}-focusVisible`),x.scrollHeight>x.clientHeight&&a!=="mouse"&&a!=="touch")){const R=A,de=x.clientHeight+x.scrollTop,Ht=R.offsetTop+R.offsetHeight;Ht>de?x.scrollTop=Ht-x.clientHeight:R.offsetTop-R.offsetHeight*(B?1.3:0)<x.scrollTop&&(x.scrollTop=R.offsetTop-R.offsetHeight*(B?1.3:0))}}),oe=at(({event:n,diff:r,direction:a="next",reason:i="auto"})=>{if(!X)return;const A=Re((()=>{const R=P.length-1;if(r==="reset")return Xe;if(r==="start")return 0;if(r==="end")return R;const de=G.current+r;return de<0?de===-1&&je?-1:T&&G.current!==-1||Math.abs(r)>1?0:R:de>R?de===R+1&&je?-1:T||Math.abs(r)>1?R:0:de})(),a);if(ce({index:A,reason:i,event:n}),b&&r!=="reset")if(A===-1)M.current.value=j;else{const R=J(P[A]);M.current.value=R,R.toLowerCase().indexOf(j.toLowerCase())===0&&j.length>0&&M.current.setSelectionRange(j.length,R.length)}}),ze=()=>{const n=(r,a)=>{const i=r?J(r):"",x=a?J(a):"";return i===x};if(G.current!==-1&&se.filteredOptions&&se.filteredOptions.length!==P.length&&se.inputValue===j&&(S?d.length===se.value.length&&se.value.every((r,a)=>J(d[a])===J(r)):n(se.value,d))){const r=se.filteredOptions[G.current];if(r)return ut(P,a=>J(a)===J(r))}return-1},Ge=p.useCallback(()=>{if(!X)return;const n=ze();if(n!==-1){G.current=n;return}const r=S?d[0]:d;if(P.length===0||r==null){oe({diff:"reset"});return}if(ee.current){if(r!=null){const a=P[G.current];if(S&&a&&ut(d,x=>U(a,x))!==-1)return;const i=ut(P,x=>U(x,r));i===-1?oe({diff:"reset"}):ce({index:i});return}if(G.current>=P.length-1){ce({index:P.length-1});return}ce({index:G.current})}},[P.length,S?!1:d,u,oe,ce,X,j,S]),St=at(n=>{jr(ee,n),n&&Ge()});p.useEffect(()=>{Ge()},[Ge]);const te=n=>{me||(Qe(!0),et(!0),le&&le(n))},fe=(n,r)=>{me&&(Qe(!1),Se&&Se(n,r))},ue=(n,r,a,i)=>{if(S){if(d.length===r.length&&d.every((x,A)=>x===r[A]))return}else if(d===r)return;Ce&&Ce(n,r,a,i),Et(r)},we=p.useRef(!1),Pe=(n,r,a="selectOption",i="options")=>{let x=a,A=r;if(S){A=Array.isArray(d)?d.slice():[];const R=ut(A,de=>U(r,de));R===-1?A.push(r):i!=="freeSolo"&&(A.splice(R,1),x="removeOption")}Te(n,A),ue(n,A,x,{option:r}),!H&&(!n||!n.ctrlKey&&!n.metaKey)&&fe(n,x),(s===!0||s==="touch"&&we.current||s==="mouse"&&!we.current)&&M.current.blur()};function rt(n,r){if(n===-1)return-1;let a=n;for(;;){if(r==="next"&&a===d.length||r==="previous"&&a===-1)return-1;const i=Oe.querySelector(`[data-tag-index="${a}"]`);if(!i||!i.hasAttribute("tabindex")||i.disabled||i.getAttribute("aria-disabled")==="true")a+=r==="next"?1:-1;else return a}}const nt=(n,r)=>{if(!S)return;j===""&&fe(n,"toggleInput");let a=Z;Z===-1?j===""&&r==="previous"&&(a=d.length-1):(a+=r==="next"?1:-1,a<0&&(a=0),a===d.length&&(a=-1)),a=rt(a,r),He(a),ke(a)},st=n=>{Be.current=!0,he(""),m&&m(n,"","clear"),ue(n,S?[]:null,"clear")},It=n=>r=>{if(n.onKeyDown&&n.onKeyDown(r),!r.defaultMuiPrevented&&(Z!==-1&&["ArrowLeft","ArrowRight"].indexOf(r.key)===-1&&(He(-1),ke(-1)),r.which!==229))switch(r.key){case"Home":X&&K&&(r.preventDefault(),oe({diff:"start",direction:"next",reason:"keyboard",event:r}));break;case"End":X&&K&&(r.preventDefault(),oe({diff:"end",direction:"previous",reason:"keyboard",event:r}));break;case"PageUp":r.preventDefault(),oe({diff:-Zt,direction:"previous",reason:"keyboard",event:r}),te(r);break;case"PageDown":r.preventDefault(),oe({diff:Zt,direction:"next",reason:"keyboard",event:r}),te(r);break;case"ArrowDown":r.preventDefault(),oe({diff:1,direction:"next",reason:"keyboard",event:r}),te(r);break;case"ArrowUp":r.preventDefault(),oe({diff:-1,direction:"previous",reason:"keyboard",event:r}),te(r);break;case"ArrowLeft":nt(r,"previous");break;case"ArrowRight":nt(r,"next");break;case"Enter":if(G.current!==-1&&X){const a=P[G.current],i=y?y(a):!1;if(r.preventDefault(),i)return;Pe(r,a,"selectOption"),b&&M.current.setSelectionRange(M.current.value.length,M.current.value.length)}else v&&j!==""&&tt===!1&&(S&&r.preventDefault(),Pe(r,j,"createOption","freeSolo"));break;case"Escape":X?(r.preventDefault(),r.stopPropagation(),fe(r,"escape")):k&&(j!==""||S&&d.length>0)&&(r.preventDefault(),r.stopPropagation(),st(r));break;case"Backspace":if(S&&!Ie&&j===""&&d.length>0){const a=Z===-1?d.length-1:Z,i=d.slice();i.splice(a,1),ue(r,i,"removeOption",{option:d[a]})}break;case"Delete":if(S&&!Ie&&j===""&&d.length>0&&Z!==-1){const a=Z,i=d.slice();i.splice(a,1),ue(r,i,"removeOption",{option:d[a]})}break}},Ft=n=>{Ye(!0),Nt&&!Be.current&&te(n)},De=n=>{if(o(ee)){M.current.focus();return}Ye(!1),Ze.current=!0,Be.current=!1,I&&G.current!==-1&&X?Pe(n,P[G.current],"blur"):I&&v&&j!==""?Pe(n,j,"blur","freeSolo"):h&&Te(n,d),fe(n,"blur")},q=n=>{const r=n.target.value;j!==r&&(he(r),et(!1),m&&m(n,r,"input")),r===""?!_&&!S&&ue(n,null,"clear"):te(n)},F=n=>{const r=Number(n.currentTarget.getAttribute("data-option-index"));G.current!==r&&ce({event:n,index:r,reason:"mouse"})},ae=n=>{ce({event:n,index:Number(n.currentTarget.getAttribute("data-option-index")),reason:"touch"}),we.current=!0},Bt=n=>{const r=Number(n.currentTarget.getAttribute("data-option-index"));Pe(n,P[r],"selectOption"),we.current=!1},Tt=n=>r=>{const a=d.slice();a.splice(n,1),ue(r,a,"removeOption",{option:d[n]})},Pt=n=>{me?fe(n,"toggleInput"):te(n)},$t=n=>{n.currentTarget.contains(n.target)&&n.target.getAttribute("id")!==Q&&n.preventDefault()},ot=n=>{n.currentTarget.contains(n.target)&&(M.current.focus(),Fe&&Ze.current&&M.current.selectionEnd-M.current.selectionStart===0&&M.current.select(),Ze.current=!1)},qe=n=>{!O&&(j===""||!me)&&Pt(n)};let $e=v&&j.length>0;$e=$e||(S?d.length>0:d!==null);let _e=P;return B&&(_e=P.reduce((n,r,a)=>{const i=B(r);return n.length>0&&n[n.length-1].group===i?n[n.length-1].options.push(r):n.push({key:a,index:a,group:i,options:[r]}),n},[])),O&&Ae&&De(),{getRootProps:(n={})=>w({"aria-owns":Ve?`${Q}-listbox`:null},n,{onKeyDown:It(n),onMouseDown:$t,onClick:ot}),getInputLabelProps:()=>({id:`${Q}-label`,htmlFor:Q}),getInputProps:()=>({id:Q,value:j,onBlur:De,onFocus:Ft,onChange:q,onMouseDown:qe,"aria-activedescendant":X?"":null,"aria-autocomplete":b?"both":"list","aria-controls":Ve?`${Q}-listbox`:void 0,"aria-expanded":Ve,autoComplete:"off",ref:M,autoCapitalize:"none",spellCheck:"false",role:"combobox",disabled:O}),getClearProps:()=>({tabIndex:-1,type:"button",onClick:st}),getPopupIndicatorProps:()=>({tabIndex:-1,type:"button",onClick:Pt}),getTagProps:({index:n})=>w({key:n,"data-tag-index":n,tabIndex:-1},!Ie&&{onDelete:Tt(n)}),getListboxProps:()=>({role:"listbox",id:`${Q}-listbox`,"aria-labelledby":`${Q}-label`,ref:St,onMouseDown:n=>{n.preventDefault()}}),getOptionProps:({index:n,option:r})=>{var a;const i=(S?d:[d]).some(A=>A!=null&&U(r,A)),x=y?y(r):!1;return{key:(a=Y==null?void 0:Y(r))!=null?a:J(r),tabIndex:-1,role:"option",id:`${Q}-option-${n}`,onMouseMove:F,onClick:Bt,onTouchStart:ae,"data-option-index":n,"aria-disabled":x,"aria-selected":i}},id:Q,inputValue:j,value:d,dirty:$e,expanded:X&&Oe,popupOpen:X,focused:Ae||Z!==-1,anchorEl:Oe,setAnchorEl:jt,focusedTag:Z,groupedOptions:_e}}function dn(t){return rr("MuiListSubheader",t)}nr("MuiListSubheader",["root","colorPrimary","colorInherit","gutters","inset","sticky"]);const pn=["className","color","component","disableGutters","disableSticky","inset"],gn=t=>{const{classes:o,color:c,disableGutters:b,inset:$,disableSticky:I}=t,s={root:["root",c!=="default"&&`color${mt(c)}`,!b&&"gutters",$&&"inset",!I&&"sticky"]};return or(s,dn,o)},hn=re("li",{name:"MuiListSubheader",slot:"Root",overridesResolver:(t,o)=>{const{ownerState:c}=t;return[o.root,c.color!=="default"&&o[`color${mt(c.color)}`],!c.disableGutters&&o.gutters,c.inset&&o.inset,!c.disableSticky&&o.sticky]}})(({theme:t,ownerState:o})=>w({boxSizing:"border-box",lineHeight:"48px",listStyle:"none",color:(t.vars||t).palette.text.secondary,fontFamily:t.typography.fontFamily,fontWeight:t.typography.fontWeightMedium,fontSize:t.typography.pxToRem(14)},o.color==="primary"&&{color:(t.vars||t).palette.primary.main},o.color==="inherit"&&{color:"inherit"},!o.disableGutters&&{paddingLeft:16,paddingRight:16},o.inset&&{paddingLeft:72},!o.disableSticky&&{position:"sticky",top:0,zIndex:1,backgroundColor:(t.vars||t).palette.background.paper})),fr=p.forwardRef(function(o,c){const b=sr({props:o,name:"MuiListSubheader"}),{className:$,color:I="default",component:s="li",disableGutters:h=!1,disableSticky:k=!1,inset:E=!1}=b,D=Ke(b,pn),_=w({},b,{color:I,component:s,disableGutters:h,disableSticky:k,inset:E}),H=gn(_);return e.jsx(hn,w({as:s,className:Me(H.root,$),ref:c,ownerState:_},D))});fr.muiSkipListHighlight=!0;function fn(t){return rr("MuiAutocomplete",t)}const f=nr("MuiAutocomplete",["root","expanded","fullWidth","focused","focusVisible","tag","tagSizeSmall","tagSizeMedium","hasPopupIcon","hasClearIcon","inputRoot","input","inputFocused","endAdornment","clearIndicator","popupIndicator","popupIndicatorOpen","popper","popperDisablePortal","paper","listbox","loading","noOptions","option","groupLabel","groupUl"]);var Xt,Yt;const xn=["autoComplete","autoHighlight","autoSelect","blurOnSelect","ChipProps","className","clearIcon","clearOnBlur","clearOnEscape","clearText","closeText","componentsProps","defaultValue","disableClearable","disableCloseOnSelect","disabled","disabledItemsFocusable","disableListWrap","disablePortal","filterOptions","filterSelectedOptions","forcePopupIcon","freeSolo","fullWidth","getLimitTagsText","getOptionDisabled","getOptionKey","getOptionLabel","isOptionEqualToValue","groupBy","handleHomeEndKeys","id","includeInputInList","inputValue","limitTags","ListboxComponent","ListboxProps","loading","loadingText","multiple","noOptionsText","onChange","onClose","onHighlightChange","onInputChange","onOpen","open","openOnFocus","openText","options","PaperComponent","PopperComponent","popupIcon","readOnly","renderGroup","renderInput","renderOption","renderTags","selectOnFocus","size","slotProps","value"],mn=["ref"],bn=["key"],yn=["key"],vn=t=>{const{classes:o,disablePortal:c,expanded:b,focused:$,fullWidth:I,hasClearIcon:s,hasPopupIcon:h,inputFocused:k,popupOpen:E,size:D}=t,_={root:["root",b&&"expanded",$&&"focused",I&&"fullWidth",s&&"hasClearIcon",h&&"hasPopupIcon"],inputRoot:["inputRoot"],input:["input",k&&"inputFocused"],tag:["tag",`tagSize${mt(D)}`],endAdornment:["endAdornment"],clearIndicator:["clearIndicator"],popupIndicator:["popupIndicator",E&&"popupIndicatorOpen"],popper:["popper",c&&"popperDisablePortal"],paper:["paper"],listbox:["listbox"],loading:["loading"],noOptions:["noOptions"],option:["option"],groupLabel:["groupLabel"],groupUl:["groupUl"]};return or(_,fn,o)},jn=re("div",{name:"MuiAutocomplete",slot:"Root",overridesResolver:(t,o)=>{const{ownerState:c}=t,{fullWidth:b,hasClearIcon:$,hasPopupIcon:I,inputFocused:s,size:h}=c;return[{[`& .${f.tag}`]:o.tag},{[`& .${f.tag}`]:o[`tagSize${mt(h)}`]},{[`& .${f.inputRoot}`]:o.inputRoot},{[`& .${f.input}`]:o.input},{[`& .${f.input}`]:s&&o.inputFocused},o.root,b&&o.fullWidth,I&&o.hasPopupIcon,$&&o.hasClearIcon]}})({[`&.${f.focused} .${f.clearIndicator}`]:{visibility:"visible"},"@media (pointer: fine)":{[`&:hover .${f.clearIndicator}`]:{visibility:"visible"}},[`& .${f.tag}`]:{margin:3,maxWidth:"calc(100% - 6px)"},[`& .${f.inputRoot}`]:{[`.${f.hasPopupIcon}&, .${f.hasClearIcon}&`]:{paddingRight:30},[`.${f.hasPopupIcon}.${f.hasClearIcon}&`]:{paddingRight:56},[`& .${f.input}`]:{width:0,minWidth:30}},[`& .${kt.root}`]:{paddingBottom:1,"& .MuiInput-input":{padding:"4px 4px 4px 0px"}},[`& .${kt.root}.${Le.sizeSmall}`]:{[`& .${kt.input}`]:{padding:"2px 4px 3px 0"}},[`& .${Ut.root}`]:{padding:9,[`.${f.hasPopupIcon}&, .${f.hasClearIcon}&`]:{paddingRight:39},[`.${f.hasPopupIcon}.${f.hasClearIcon}&`]:{paddingRight:65},[`& .${f.input}`]:{padding:"7.5px 4px 7.5px 5px"},[`& .${f.endAdornment}`]:{right:9}},[`& .${Ut.root}.${Le.sizeSmall}`]:{paddingTop:6,paddingBottom:6,paddingLeft:6,[`& .${f.input}`]:{padding:"2.5px 4px 2.5px 8px"}},[`& .${We.root}`]:{paddingTop:19,paddingLeft:8,[`.${f.hasPopupIcon}&, .${f.hasClearIcon}&`]:{paddingRight:39},[`.${f.hasPopupIcon}.${f.hasClearIcon}&`]:{paddingRight:65},[`& .${We.input}`]:{padding:"7px 4px"},[`& .${f.endAdornment}`]:{right:9}},[`& .${We.root}.${Le.sizeSmall}`]:{paddingBottom:1,[`& .${We.input}`]:{padding:"2.5px 4px"}},[`& .${Le.hiddenLabel}`]:{paddingTop:8},[`& .${We.root}.${Le.hiddenLabel}`]:{paddingTop:0,paddingBottom:0,[`& .${f.input}`]:{paddingTop:16,paddingBottom:17}},[`& .${We.root}.${Le.hiddenLabel}.${Le.sizeSmall}`]:{[`& .${f.input}`]:{paddingTop:8,paddingBottom:9}},[`& .${f.input}`]:{flexGrow:1,textOverflow:"ellipsis",opacity:0},variants:[{props:{fullWidth:!0},style:{width:"100%"}},{props:{size:"small"},style:{[`& .${f.tag}`]:{margin:2,maxWidth:"calc(100% - 4px)"}}},{props:{inputFocused:!0},style:{[`& .${f.input}`]:{opacity:1}}},{props:{multiple:!0},style:{[`& .${f.inputRoot}`]:{flexWrap:"wrap"}}}]}),Cn=re("div",{name:"MuiAutocomplete",slot:"EndAdornment",overridesResolver:(t,o)=>o.endAdornment})({position:"absolute",right:0,top:"50%",transform:"translate(0, -50%)"}),Sn=re(Ne,{name:"MuiAutocomplete",slot:"ClearIndicator",overridesResolver:(t,o)=>o.clearIndicator})({marginRight:-2,padding:4,visibility:"hidden"}),In=re(Ne,{name:"MuiAutocomplete",slot:"PopupIndicator",overridesResolver:({ownerState:t},o)=>w({},o.popupIndicator,t.popupOpen&&o.popupIndicatorOpen)})({padding:2,marginRight:-2,variants:[{props:{popupOpen:!0},style:{transform:"rotate(180deg)"}}]}),Tn=re(ir,{name:"MuiAutocomplete",slot:"Popper",overridesResolver:(t,o)=>{const{ownerState:c}=t;return[{[`& .${f.option}`]:o.option},o.popper,c.disablePortal&&o.popperDisablePortal]}})(({theme:t})=>({zIndex:(t.vars||t).zIndex.modal,variants:[{props:{disablePortal:!0},style:{position:"absolute"}}]})),Pn=re(ar,{name:"MuiAutocomplete",slot:"Paper",overridesResolver:(t,o)=>o.paper})(({theme:t})=>w({},t.typography.body1,{overflow:"auto"})),$n=re("div",{name:"MuiAutocomplete",slot:"Loading",overridesResolver:(t,o)=>o.loading})(({theme:t})=>({color:(t.vars||t).palette.text.secondary,padding:"14px 16px"})),Ln=re("div",{name:"MuiAutocomplete",slot:"NoOptions",overridesResolver:(t,o)=>o.noOptions})(({theme:t})=>({color:(t.vars||t).palette.text.secondary,padding:"14px 16px"})),On=re("div",{name:"MuiAutocomplete",slot:"Listbox",overridesResolver:(t,o)=>o.listbox})(({theme:t})=>({listStyle:"none",margin:0,padding:"8px 0",maxHeight:"40vh",overflow:"auto",position:"relative",[`& .${f.option}`]:{minHeight:48,display:"flex",overflow:"hidden",justifyContent:"flex-start",alignItems:"center",cursor:"pointer",paddingTop:6,boxSizing:"border-box",outline:"0",WebkitTapHighlightColor:"transparent",paddingBottom:6,paddingLeft:16,paddingRight:16,[t.breakpoints.up("sm")]:{minHeight:"auto"},[`&.${f.focused}`]:{backgroundColor:(t.vars||t).palette.action.hover,"@media (hover: none)":{backgroundColor:"transparent"}},'&[aria-disabled="true"]':{opacity:(t.vars||t).palette.action.disabledOpacity,pointerEvents:"none"},[`&.${f.focusVisible}`]:{backgroundColor:(t.vars||t).palette.action.focus},'&[aria-selected="true"]':{backgroundColor:t.vars?`rgba(${t.vars.palette.primary.mainChannel} / ${t.vars.palette.action.selectedOpacity})`:Ot(t.palette.primary.main,t.palette.action.selectedOpacity),[`&.${f.focused}`]:{backgroundColor:t.vars?`rgba(${t.vars.palette.primary.mainChannel} / calc(${t.vars.palette.action.selectedOpacity} + ${t.vars.palette.action.hoverOpacity}))`:Ot(t.palette.primary.main,t.palette.action.selectedOpacity+t.palette.action.hoverOpacity),"@media (hover: none)":{backgroundColor:(t.vars||t).palette.action.selected}},[`&.${f.focusVisible}`]:{backgroundColor:t.vars?`rgba(${t.vars.palette.primary.mainChannel} / calc(${t.vars.palette.action.selectedOpacity} + ${t.vars.palette.action.focusOpacity}))`:Ot(t.palette.primary.main,t.palette.action.selectedOpacity+t.palette.action.focusOpacity)}}}})),An=re(fr,{name:"MuiAutocomplete",slot:"GroupLabel",overridesResolver:(t,o)=>o.groupLabel})(({theme:t})=>({backgroundColor:(t.vars||t).palette.background.paper,top:-8})),kn=re("ul",{name:"MuiAutocomplete",slot:"GroupUl",overridesResolver:(t,o)=>o.groupUl})({padding:0,[`& .${f.option}`]:{paddingLeft:24}}),dt=p.forwardRef(function(o,c){var b,$,I,s;const h=sr({props:o,name:"MuiAutocomplete"}),{autoComplete:k=!1,autoHighlight:E=!1,autoSelect:D=!1,blurOnSelect:_=!1,ChipProps:H,className:O,clearIcon:ve=Xt||(Xt=e.jsx(Ur,{fontSize:"small"})),clearOnBlur:T=!h.freeSolo,clearOnEscape:ge=!1,clearText:u="Clear",closeText:v="Close",componentsProps:y={},defaultValue:Y=h.multiple?[]:null,disableClearable:V=!1,disableCloseOnSelect:B=!1,disabled:K=!1,disabledItemsFocusable:xe=!1,disableListWrap:je=!1,disablePortal:ne=!1,filterSelectedOptions:U=!1,forcePopupIcon:S="auto",freeSolo:Ce=!1,fullWidth:Se=!1,getLimitTagsText:l=r=>`+${r}`,getOptionLabel:m,groupBy:le,handleHomeEndKeys:Mt=!h.freeSolo,includeInputInList:Nt=!1,limitTags:Ee=-1,ListboxComponent:Ie="ul",ListboxProps:Fe,loading:Je=!1,loadingText:Q="Loading…",multiple:J=!1,noOptionsText:Be="No options",openOnFocus:Ze=!1,openText:M="Open",PaperComponent:ee=ar,PopperComponent:Oe=ir,popupIcon:jt=Yt||(Yt=e.jsx(Xr,{})),readOnly:Z=!1,renderGroup:He,renderInput:Xe,renderOption:G,renderTags:d,selectOnFocus:Et=!h.freeSolo,size:j="medium",slotProps:he={}}=h,Ae=Ke(h,xn),{getRootProps:Ye,getInputProps:Te,getInputLabelProps:me,getPopupIndicatorProps:Qe,getClearProps:Ct,getTagProps:et,getListboxProps:tt,getOptionProps:X,value:P,dirty:se,expanded:Ve,id:ke,popupOpen:Re,focused:ce,focusedTag:oe,anchorEl:ze,setAnchorEl:Ge,inputValue:St,groupedOptions:te}=un(w({},h,{componentName:"Autocomplete"})),fe=!V&&!K&&se&&!Z,ue=(!Ce||S===!0)&&S!==!1,{onMouseDown:we}=Te(),{ref:Pe}=Fe??{},rt=tt(),{ref:nt}=rt,st=Ke(rt,mn),It=Cr(nt,Pe),De=m||(r=>{var a;return(a=r.label)!=null?a:r}),q=w({},h,{disablePortal:ne,expanded:Ve,focused:ce,fullWidth:Se,getOptionLabel:De,hasClearIcon:fe,hasPopupIcon:ue,inputFocused:oe===-1,popupOpen:Re,size:j}),F=vn(q);let ae;if(J&&P.length>0){const r=a=>w({className:F.tag,disabled:K},et(a));d?ae=d(P,r,q):ae=P.map((a,i)=>{const x=r({index:i}),{key:A}=x,R=Ke(x,bn);return e.jsx(vt,w({label:De(a),size:j},R,H),A)})}if(Ee>-1&&Array.isArray(ae)){const r=ae.length-Ee;!ce&&r>0&&(ae=ae.splice(0,Ee),ae.push(e.jsx("span",{className:F.tag,children:l(r)},ae.length)))}const Tt=He||(r=>e.jsxs("li",{children:[e.jsx(An,{className:F.groupLabel,ownerState:q,component:"div",children:r.group}),e.jsx(kn,{className:F.groupUl,ownerState:q,children:r.children})]},r.key)),$t=G||((r,a)=>{const{key:i}=r,x=Ke(r,yn);return e.jsx("li",w({},x,{children:De(a)}),i)}),ot=(r,a)=>{const i=X({option:r,index:a});return $t(w({},i,{className:F.option}),r,{selected:i["aria-selected"],index:a,inputValue:St},q)},qe=(b=he.clearIndicator)!=null?b:y.clearIndicator,$e=($=he.paper)!=null?$:y.paper,_e=(I=he.popper)!=null?I:y.popper,n=(s=he.popupIndicator)!=null?s:y.popupIndicator;return e.jsxs(p.Fragment,{children:[e.jsx(jn,w({ref:c,className:Me(F.root,O),ownerState:q},Ye(Ae),{children:Xe({id:ke,disabled:K,fullWidth:!0,size:j==="small"?"small":void 0,InputLabelProps:me(),InputProps:w({ref:Ge,className:F.inputRoot,startAdornment:ae,onClick:r=>{r.target===r.currentTarget&&we(r)}},(fe||ue)&&{endAdornment:e.jsxs(Cn,{className:F.endAdornment,ownerState:q,children:[fe?e.jsx(Sn,w({},Ct(),{"aria-label":u,title:u,ownerState:q},qe,{className:Me(F.clearIndicator,qe==null?void 0:qe.className),children:ve})):null,ue?e.jsx(In,w({},Qe(),{disabled:K,"aria-label":Re?v:M,title:Re?v:M,ownerState:q},n,{className:Me(F.popupIndicator,n==null?void 0:n.className),children:jt})):null]})}),inputProps:w({className:F.input,disabled:K,readOnly:Z},Te())})})),ze?e.jsx(Tn,w({as:Oe,disablePortal:ne,style:{width:ze?ze.clientWidth:null},ownerState:q,role:"presentation",anchorEl:ze,open:Re},_e,{className:Me(F.popper,_e==null?void 0:_e.className),children:e.jsxs(Pn,w({ownerState:q,as:ee},$e,{className:Me(F.paper,$e==null?void 0:$e.className),children:[Je&&te.length===0?e.jsx($n,{className:F.loading,ownerState:q,children:Q}):null,te.length===0&&!Ce&&!Je?e.jsx(Ln,{className:F.noOptions,ownerState:q,role:"presentation",onMouseDown:r=>{r.preventDefault()},children:Be}):null,te.length>0?e.jsx(On,w({as:Ie,className:F.listbox,ownerState:q},st,Fe,{ref:It,children:te.map((r,a)=>le?Tt({key:r.key,group:r.group,children:r.options.map((i,x)=>ot(i,r.index+x))}):ot(r,a))})):null]}))})):null]})});var wt={},Rn=yt;Object.defineProperty(wt,"__esModule",{value:!0});var xr=wt.default=void 0,zn=Rn(bt()),wn=e;xr=wt.default=(0,zn.default)((0,wn.jsx)("path",{d:"M11 7h2v2h-2zm0 4h2v6h-2zm1-9C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2m0 18c-4.41 0-8-3.59-8-8s3.59-8 8-8 8 3.59 8 8-3.59 8-8 8"}),"InfoOutlined");var Dt={},Dn=yt;Object.defineProperty(Dt,"__esModule",{value:!0});var mr=Dt.default=void 0,_n=Dn(bt()),Wn=e;mr=Dt.default=(0,_n.default)((0,Wn.jsx)("path",{d:"M21 11.01 3 11v2h18zM3 16h12v2H3zM21 6H3v2.01L21 8z"}),"NotesOutlined");var _t={},Mn=yt;Object.defineProperty(_t,"__esModule",{value:!0});var br=_t.default=void 0,Nn=Mn(bt()),En=e;br=_t.default=(0,Nn.default)((0,En.jsx)("path",{d:"M16.01 11H4v2h12.01v3L20 12l-3.99-4z"}),"ArrowRightAlt");var Wt={},Fn=yt;Object.defineProperty(Wt,"__esModule",{value:!0});var yr=Wt.default=void 0,Bn=Fn(bt()),Hn=e;yr=Wt.default=(0,Bn.default)((0,Hn.jsx)("path",{d:"M12 8c-2.21 0-4 1.79-4 4s1.79 4 4 4 4-1.79 4-4-1.79-4-4-4m8.94 3c-.46-4.17-3.77-7.48-7.94-7.94V1h-2v2.06C6.83 3.52 3.52 6.83 3.06 11H1v2h2.06c.46 4.17 3.77 7.48 7.94 7.94V23h2v-2.06c4.17-.46 7.48-3.77 7.94-7.94H23v-2zM12 19c-3.87 0-7-3.13-7-7s3.13-7 7-7 7 3.13 7 7-3.13 7-7 7"}),"MyLocation");const Vn=["retail","wholesale","manufacturer","distributor","services","ecommerce","other"],Gn=["newClient","contacted","onboarded","lost"],qn=["Daily","Weekly","Fortnightly","Monthly","Occasional"],Kn=["basicOnly","full","none"],Un=["Blue Dart","Delhivery","DTDC","India Post / Speed Post","The Professional Couriers","XpressBees","Ecom Express","Shadowfax","Safexpress","VRL Logistics","TCI (Transport Corporation of India)","Om Logistics","Best Roadways","MSS (Mettur Super Services)","ABT Travels & Logistics","Navata Road Transport","KRS (Kerala Roadways)","Parveen Travels / Parveen Express","SRM Transports","KPN Travels & KPN Speed Parcel","SRS Travels","Hindusthan Travels","City Travels","Essaar Travels","No. 1 Air Travels","A1 Travels","Krish Travels","Hebron Transports","Horma Travels","Vivegam Travels","PSS Transport","SRT (Renugambal Travels)","Thamarai Bus Transports","Rathimeena Travels","Ganesh Travels","John Kennedy Bus Service","Arun Travel","Saaji Meera Roadways","ARC Parcel Service","Chakra Travels & Parcel Service","MVA Parcel And Bus Service","Shrinath Travels & Cargo","Hans Travels","Zingbus","Kalpana Travels / City Land Travels","Trackon Couriers","North India Transways","RSRTC Cargo","UPSRTC Cargo"],Rt=["Chennai","Coimbatore","Madurai","Tiruchirappalli","Salem","Tuticorin","Tirupur","Erode","Vellore","Tirunelveli","Thanjavur","Dindigul","Hosur","Nagercoil","Karur","Namakkal","Kanchipuram","Cuddalore","Thoothukudi","Bengaluru","Mysuru","Mangaluru","Hubli","Belagavi","Kalaburagi","Davangere","Ballari","Kochi","Thiruvananthapuram","Kozhikode","Kannur","Thrissur","Kollam","Hyderabad","Warangal","Visakhapatnam","Vijayawada","Tirupati","Guntur","Rajahmundry","Nellore","Mumbai","Pune","Nagpur","Nashik","Aurangabad","Kolhapur","Solapur","New Delhi","Gurugram","Noida","Faridabad","Chandigarh","Amritsar","Ludhiana","Jalandhar","Ahmedabad","Surat","Vadodara","Rajkot","Bhavnagar","Jamnagar","Jaipur","Jodhpur","Udaipur","Kota","Bikaner","Lucknow","Kanpur","Varanasi","Agra","Prayagraj","Gorakhpur","Bhopal","Indore","Gwalior","Jabalpur","Raipur","Kolkata","Siliguri","Durgapur","Patna","Gaya","Ranchi","Jamshedpur","Bhubaneswar","Cuttack","Guwahati","Dibrugarh","Agartala","Imphal","Shillong","Aizawl","Dimapur","Dehradun","Haridwar","Shimla","Srinagar","Jammu","Leh","Panaji","Puducherry","Port Blair"],Qt={name:"",email:"",password:"",phone:"",city:"",businessState:"",businessType:"retail",status:"newClient",frequency:"Daily",parcelVolume:0,activeContracts:0,provider:"",efficiency:"",logisticsSegment:"",transitFrom:"",transitTo:"",neighbourhood:"",surveyAddress:"",surveyLat:"",surveyLng:"",dataConsent:"full",notes:"",pincode:""},pt=t=>typeof t=="string"?t.charAt(0).toUpperCase()+t.slice(1).replace(/([A-Z])/g," $1").trim():t,gt=(t,o)=>o&&!t.includes(o)?[o,...t]:t;function Jn({open:t,mode:o,initial:c,onClose:b,onSaved:$}){const I=o==="edit",[s,h]=p.useState(Qt),[k,E]=p.useState(!1),[D,_]=p.useState(null),[H,O]=p.useState(!1),ve=()=>{if(!navigator.geolocation){alert("Geolocation is not supported by your browser");return}O(!0),navigator.geolocation.getCurrentPosition(async u=>{const v=u.coords.latitude,y=u.coords.longitude;h(Y=>({...Y,surveyLat:v,surveyLng:y}));try{const V=await(await fetch(`https://nominatim.openstreetmap.org/reverse?format=json&lat=${v}&lon=${y}`)).json();if(V&&V.address){const B=V.address,K=B.city||B.town||B.village||B.county||"",xe=B.state||"",je=B.postcode||"",ne=V.display_name||"";h(U=>({...U,city:K||U.city,businessState:xe||U.businessState,pincode:je||U.pincode,surveyAddress:ne||U.surveyAddress}))}}catch(Y){console.error("Reverse geocoding failed",Y)}finally{O(!1)}},u=>{alert("Unable to retrieve your location"),O(!1)})};p.useEffect(()=>{t&&(h({...Qt,...c||{}}),_(null))},[t,c]);const T=u=>v=>h(y=>({...y,[u]:v.target.value})),ge=async()=>{if(!s.name.trim()){_("Client name is required.");return}E(!0),_(null);const u=s.surveyLat===""?void 0:Number(s.surveyLat),v=s.surveyLng===""?void 0:Number(s.surveyLng),y={first_name:s.name.trim(),phone:s.phone,city:s.city,businessState:s.businessState,businessType:s.businessType,status:s.status,frequency:s.frequency,parcelVolume:Number(s.parcelVolume)||0,activeContracts:Number(s.activeContracts)||0,provider:s.provider,efficiency:s.efficiency,logisticsSegment:s.logisticsSegment,transitFrom:s.transitFrom,transitTo:s.transitTo,neighbourhood:s.neighbourhood,pincode:s.pincode,surveyAddress:s.surveyAddress,dataConsent:s.dataConsent,notes:s.notes,lastUpdated:new Date().toISOString().slice(0,10),registration_source:"web",...s.email.trim()?{email:s.email.trim()}:{},...u!=null?{survey_lat:u}:{},...v!=null?{survey_long:v}:{}};try{I?await Sr(c.id,y):await Ir({...y,...s.password?{password:s.password}:{}}),$()}catch(Y){_(Y.message||"Failed to save client")}finally{E(!1)}};return e.jsxs(lr,{open:t,onClose:k?void 0:b,maxWidth:"md",fullWidth:!0,children:[e.jsxs(cr,{sx:{display:"flex",alignItems:"center",justifyContent:"space-between"},children:[I?"Edit Client":"Add Client",e.jsx(Ne,{onClick:b,size:"small",disabled:k,children:e.jsx(Zr,{})})]}),e.jsxs(ur,{dividers:!0,children:[D&&e.jsx(hr,{severity:"error",sx:{mb:2},children:D}),e.jsx(C,{variant:"overline",color:"text.secondary",children:"Business"}),e.jsxs(g,{container:!0,spacing:2,sx:{mt:0,mb:1},children:[e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{fullWidth:!0,size:"small",label:"Client Name *",value:s.name,onChange:T("name")})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{fullWidth:!0,size:"small",label:"Phone",value:s.phone,onChange:T("phone")})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{fullWidth:!0,size:"small",label:"Email",value:s.email,onChange:T("email")})}),!I&&e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{fullWidth:!0,size:"small",label:"Password",type:"password",value:s.password,onChange:T("password")})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{select:!0,fullWidth:!0,size:"small",label:"Business Type",value:s.businessType,onChange:T("businessType"),children:gt(Vn,s.businessType).map(u=>e.jsx(it,{value:u,children:pt(u)},u))})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{select:!0,fullWidth:!0,size:"small",label:"Status",value:s.status,onChange:T("status"),children:gt(Gn,s.status).map(u=>e.jsx(it,{value:u,children:pt(u)},u))})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{select:!0,fullWidth:!0,size:"small",label:"Order Frequency",value:s.frequency,onChange:T("frequency"),children:gt(qn,s.frequency).map(u=>e.jsx(it,{value:u,children:pt(u)},u))})}),e.jsx(g,{item:!0,xs:12,sm:3,children:e.jsx(L,{fullWidth:!0,size:"small",type:"number",label:"Parcel Volume",value:s.parcelVolume,onChange:T("parcelVolume")})}),e.jsx(g,{item:!0,xs:12,sm:3,children:e.jsx(L,{fullWidth:!0,size:"small",type:"number",label:"Active Contracts",value:s.activeContracts,onChange:T("activeContracts")})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(dt,{autoHighlight:!0,options:Un,value:s.provider||null,onChange:(u,v)=>h(y=>({...y,provider:v||""})),renderInput:u=>e.jsx(L,{...u,fullWidth:!0,size:"small",label:"Current Provider"})})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{fullWidth:!0,size:"small",label:"Efficiency",value:s.efficiency,onChange:T("efficiency")})}),e.jsx(g,{item:!0,xs:12,children:e.jsx(L,{fullWidth:!0,size:"small",label:"Logistics Segment",value:s.logisticsSegment,onChange:T("logisticsSegment"),placeholder:"First Mile, Last Mile"})})]}),e.jsx(zt,{sx:{my:1.5}}),e.jsx(C,{variant:"overline",color:"text.secondary",children:"Location & Transit"}),e.jsxs(g,{container:!0,spacing:2,sx:{mt:0,mb:1},children:[e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(dt,{autoHighlight:!0,options:Rt,value:s.city||null,onChange:(u,v)=>h(y=>({...y,city:v||""})),renderInput:u=>e.jsx(L,{...u,fullWidth:!0,size:"small",label:"City"})})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{fullWidth:!0,size:"small",label:"State",value:s.businessState,onChange:T("businessState")})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{fullWidth:!0,size:"small",label:"Pincode",value:s.pincode,onChange:T("pincode")})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{fullWidth:!0,size:"small",label:"Neighbourhood / Zone",value:s.neighbourhood,onChange:T("neighbourhood")})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(dt,{autoHighlight:!0,options:Rt,value:s.transitFrom||null,onChange:(u,v)=>h(y=>({...y,transitFrom:v||""})),renderInput:u=>e.jsx(L,{...u,fullWidth:!0,size:"small",label:"Transit From"})})}),e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(dt,{autoHighlight:!0,options:Rt,value:s.transitTo||null,onChange:(u,v)=>h(y=>({...y,transitTo:v||""})),renderInput:u=>e.jsx(L,{...u,fullWidth:!0,size:"small",label:"Transit To"})})}),e.jsx(g,{item:!0,xs:12,sm:3,children:e.jsx(L,{fullWidth:!0,size:"small",type:"number",label:"Latitude",value:s.surveyLat,onChange:T("surveyLat")})}),e.jsx(g,{item:!0,xs:12,sm:3,children:e.jsx(L,{fullWidth:!0,size:"small",type:"number",label:"Longitude",value:s.surveyLng,onChange:T("surveyLng")})}),e.jsx(g,{item:!0,xs:12,sm:6,display:"flex",alignItems:"center",children:e.jsx(pe,{variant:"outlined",size:"small",onClick:ve,disabled:H,startIcon:H?e.jsx(xt,{size:16}):e.jsx(yr,{}),fullWidth:!0,children:"Get GPS Location"})}),e.jsx(g,{item:!0,xs:12,children:e.jsx(L,{fullWidth:!0,size:"small",label:"Survey Address",value:s.surveyAddress,onChange:T("surveyAddress"),multiline:!0,minRows:2})})]}),e.jsx(zt,{sx:{my:1.5}}),e.jsx(C,{variant:"overline",color:"text.secondary",children:"Other"}),e.jsxs(g,{container:!0,spacing:2,sx:{mt:0},children:[e.jsx(g,{item:!0,xs:12,sm:6,children:e.jsx(L,{select:!0,fullWidth:!0,size:"small",label:"Data Consent",value:s.dataConsent,onChange:T("dataConsent"),children:gt(Kn,s.dataConsent).map(u=>e.jsx(it,{value:u,children:pt(u)},u))})}),e.jsx(g,{item:!0,xs:12,children:e.jsx(L,{fullWidth:!0,size:"small",label:"Notes",value:s.notes,onChange:T("notes"),multiline:!0,minRows:2})})]})]}),e.jsxs(dr,{sx:{px:3,py:2},children:[e.jsx(pe,{onClick:b,disabled:k,children:"Cancel"}),e.jsx(pe,{variant:"contained",onClick:ge,disabled:k,startIcon:k?e.jsx(xt,{size:16,color:"inherit"}):null,children:I?"Save Changes":"Create Client"})]})]})}const Zn=t=>({full:"success",basiconly:"info",none:"default"})[String(t||"").toLowerCase()]||"default",Xn=t=>{const o=String(t||"").toLowerCase();return/high|good|excellent/.test(o)?"success":/med|average|moderate/.test(o)?"warning":/low|poor|bad/.test(o)?"error":"info"},Yn={textTransform:"uppercase",letterSpacing:.4,fontSize:"0.68rem",fontWeight:700,color:"grey.700"};function be({label:t,color:o="default"}){return t==null||t===""?e.jsx(C,{variant:"body2",sx:{fontWeight:500,color:"grey.500"},children:"—"}):e.jsx(vt,{size:"small",label:t,sx:{fontWeight:600,...o==="default"?{bgcolor:"grey.100",color:"grey.700"}:{bgcolor:`${o}.lighter`,color:`${o}.dark`}}})}function ie({label:t,children:o}){return e.jsxs(W,{children:[e.jsx(C,{variant:"caption",color:"text.secondary",sx:Yn,children:t}),e.jsx(W,{sx:{mt:.5},children:o})]})}function ht({label:t,value:o}){return e.jsx(ie,{label:t,children:e.jsx(C,{variant:"body2",sx:{fontWeight:500,color:o?"grey.800":"grey.500",wordBreak:"break-word"},children:o||"—"})})}function ft({icon:t,title:o,accent:c="primary",children:b}){return e.jsxs(W,{sx:{height:"100%",borderRadius:2,border:1,borderColor:"divider",bgcolor:"background.paper",overflow:"hidden"},children:[e.jsxs(z,{direction:"row",spacing:1,alignItems:"center",sx:{px:2,py:1.25,borderBottom:1,borderColor:"divider",bgcolor:`${c}.lighter`,opacity:.999},children:[e.jsx(t,{sx:{fontSize:18,color:`${c}.main`}}),e.jsx(C,{variant:"overline",sx:{fontWeight:700,color:"grey.800",letterSpacing:.6,lineHeight:1},children:o})]}),e.jsx(z,{spacing:1.75,sx:{p:2},children:b})]})}function er({label:t,value:o,icon:c,color:b="primary"}){return e.jsx(W,{sx:{flex:1,p:1.5,borderRadius:1.5,border:1,borderColor:"divider",bgcolor:"grey.50"},children:e.jsxs(z,{direction:"row",spacing:1,alignItems:"center",children:[e.jsx(W,{sx:{width:32,height:32,borderRadius:1,bgcolor:`${b}.lighter`,color:`${b}.main`,display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx(c,{sx:{fontSize:18}})}),e.jsxs(W,{children:[e.jsx(C,{variant:"h5",sx:{fontWeight:700,color:"grey.800",lineHeight:1.1},children:o}),e.jsx(C,{variant:"caption",color:"text.secondary",children:t})]})]})})}function tr({label:t,value:o,color:c="grey.800"}){return e.jsxs(W,{sx:{textAlign:"center",minWidth:56},children:[e.jsx(C,{variant:"body2",sx:{fontWeight:700,color:c,lineHeight:1.2},children:o}),e.jsx(C,{variant:"caption",color:"text.secondary",sx:{fontSize:"0.65rem"},children:t})]})}function Qn({row:t,index:o,onEdit:c,onDelete:b}){const[$,I]=p.useState(!1);return e.jsxs(p.Fragment,{children:[e.jsxs(Ue,{hover:!0,sx:{cursor:"pointer","& > *":{borderBottom:$?"unset":void 0},...$&&{bgcolor:"primary.lighter","&:hover":{bgcolor:"primary.lighter"}}},onClick:()=>I(s=>!s),children:[e.jsx(N,{padding:"checkbox",children:e.jsx(Ne,{size:"small",onClick:s=>{s.stopPropagation(),I(h=>!h)},children:$?e.jsx(Mr,{}):e.jsx(Nr,{})})}),e.jsx(N,{sx:{whiteSpace:"nowrap"},children:e.jsx(C,{variant:"caption",sx:{fontFamily:"monospace",fontWeight:700,color:"primary.main",bgcolor:"primary.lighter",px:1,py:.5,borderRadius:1,border:"1px solid",borderColor:"primary.light",whiteSpace:"nowrap"},children:t.logicalId})}),e.jsx(N,{children:e.jsxs(z,{direction:"row",spacing:1.25,alignItems:"center",children:[e.jsx(Gt,{name:t.name,size:38}),e.jsxs(W,{sx:{minWidth:0},children:[e.jsx(C,{variant:"body2",sx:{fontWeight:600,color:"grey.800"},children:t.name}),e.jsx(z,{direction:"row",spacing:.75,alignItems:"center",sx:{mt:.4},children:t.businessType&&e.jsx(vt,{size:"small",label:ye(t.businessType),sx:{height:20,fontSize:"0.68rem",fontWeight:600,bgcolor:"grey.100",color:"grey.700"}})})]})]})}),e.jsx(N,{children:e.jsxs(z,{direction:"row",spacing:.75,alignItems:"center",children:[e.jsx(_r,{sx:{fontSize:15,color:"grey.400"}}),e.jsxs(W,{children:[e.jsx(C,{variant:"body2",children:t.phone||"—"}),t.frequency&&e.jsx(C,{variant:"caption",color:"text.secondary",children:t.frequency})]})]})}),e.jsx(N,{children:e.jsxs(z,{direction:"row",spacing:.75,alignItems:"center",children:[e.jsx(lt,{sx:{fontSize:15,color:"grey.400"}}),e.jsxs(W,{children:[e.jsxs(C,{variant:"body2",children:[t.city||"—",t.businessState?`, ${t.businessState}`:""]}),t.neighbourhood&&e.jsx(C,{variant:"caption",color:"text.secondary",children:t.neighbourhood})]})]})}),e.jsx(N,{children:e.jsxs(z,{direction:"row",spacing:1.5,alignItems:"center",justifyContent:"center",divider:e.jsx(zt,{orientation:"vertical",flexItem:!0}),children:[e.jsx(tr,{label:"Parcels",value:Number(t.parcelVolume).toLocaleString()}),e.jsx(tr,{label:"Contracts",value:t.activeContracts,color:"primary.main"})]})}),e.jsx(N,{children:e.jsx(Kt,{status:t.status})}),e.jsxs(N,{align:"right",children:[e.jsx(At,{title:"Edit",children:e.jsx(Ne,{size:"small",onClick:s=>{s.stopPropagation(),c(t)},children:e.jsx(qt,{fontSize:"small"})})}),e.jsx(At,{title:"Delete",children:e.jsx(Ne,{size:"small",onClick:s=>{s.stopPropagation(),b(t)},children:e.jsx(Wr,{fontSize:"small"})})})]})]}),e.jsx(Ue,{children:e.jsx(N,{colSpan:8,sx:{py:0,borderBottom:$?void 0:"none"},children:e.jsx(Ar,{in:$,timeout:"auto",unmountOnExit:!0,children:e.jsxs(W,{sx:{m:2,borderRadius:2.5,border:1,borderColor:"divider",overflow:"hidden",boxShadow:"0 4px 16px rgba(0,0,0,0.06)"},children:[e.jsxs(z,{direction:{xs:"column",sm:"row"},justifyContent:"space-between",alignItems:{xs:"flex-start",sm:"center"},spacing:1.5,sx:{px:2.5,py:1.75,borderBottom:1,borderColor:"divider",background:s=>`linear-gradient(90deg, ${s.palette.primary.lighter}88 0%, ${s.palette.background.paper} 75%)`},children:[e.jsxs(z,{direction:"row",spacing:1.5,alignItems:"center",children:[e.jsx(Gt,{name:t.name,size:40}),e.jsxs(W,{children:[e.jsx(C,{variant:"subtitle1",sx:{fontWeight:700,lineHeight:1.2},children:t.name}),e.jsxs(z,{direction:"row",spacing:.75,alignItems:"center",sx:{mt:.25},children:[e.jsx(Kr,{sx:{fontSize:14,color:"grey.400"}}),e.jsx(C,{variant:"caption",color:"text.secondary",children:t.clientId})]})]}),e.jsx(Kt,{status:t.status,sx:{ml:.5}})]}),e.jsx(pe,{size:"small",variant:"contained",startIcon:e.jsx(qt,{}),onClick:()=>c(t),children:"Edit Client"})]}),e.jsx(W,{sx:{p:2.5,bgcolor:"grey.50"},children:e.jsxs(g,{container:!0,spacing:2.5,alignItems:"stretch",children:[e.jsx(g,{item:!0,xs:12,md:4,children:e.jsxs(ft,{icon:Er,title:"Business",accent:"primary",children:[e.jsxs(z,{direction:"row",spacing:1.5,children:[e.jsx(er,{label:"Parcel Volume",value:Number(t.parcelVolume).toLocaleString(),icon:pr,color:"primary"}),e.jsx(er,{label:"Active Contracts",value:t.activeContracts,icon:gr,color:"primary"})]}),e.jsx(ie,{label:"Client ID",children:e.jsx(C,{variant:"body2",sx:{fontFamily:"monospace",fontWeight:600,color:"grey.800"},children:t.clientId})}),e.jsx(ie,{label:"Business Type",children:e.jsx(be,{label:t.businessType&&ye(t.businessType),color:"primary"})}),e.jsx(ie,{label:"Order Frequency",children:e.jsx(be,{label:t.frequency&&ye(t.frequency),color:"info"})})]})}),e.jsx(g,{item:!0,xs:12,md:4,children:e.jsxs(ft,{icon:Fr,title:"Logistics",accent:"primary",children:[e.jsx(ie,{label:"Logistics Segment",children:t.logisticsSegment?e.jsx(z,{direction:"row",spacing:.75,flexWrap:"wrap",useFlexGap:!0,children:String(t.logisticsSegment).split(/[,/]/).map(s=>s.trim()).filter(Boolean).map(s=>e.jsx(be,{label:ye(s),color:"primary"},s))}):e.jsx(be,{label:null})}),e.jsx(ht,{label:"Current Provider",value:t.provider}),e.jsx(ie,{label:"Efficiency",children:e.jsx(be,{label:t.efficiency&&ye(t.efficiency),color:Xn(t.efficiency)})}),e.jsx(ie,{label:"Transit Route",children:(()=>{const s=[t.transitFrom,...String(t.transitTo||"").split(",")].map(h=>h.trim()).filter(Boolean);return s.length?e.jsx(z,{direction:"row",spacing:.75,alignItems:"center",flexWrap:"wrap",useFlexGap:!0,children:s.map((h,k)=>e.jsxs(p.Fragment,{children:[k>0&&e.jsx(br,{sx:{fontSize:20,color:"primary.main"}}),e.jsx(be,{label:ye(h),color:k===0?"default":"info"})]},`${h}-${k}`))}):e.jsx(be,{label:null})})()})]})}),e.jsx(g,{item:!0,xs:12,md:4,children:e.jsxs(ft,{icon:lt,title:"Location & Survey",accent:"primary",children:[e.jsx(ie,{label:"City / State",children:e.jsx(C,{variant:"body2",sx:{fontWeight:500,color:"grey.800"},children:[t.city,t.businessState].filter(Boolean).join(", ")||"—"})}),e.jsx(ht,{label:"Neighbourhood",value:t.neighbourhood}),e.jsx(ie,{label:"Survey Address",children:e.jsxs(z,{direction:"row",spacing:1,sx:{p:1.25,borderRadius:1.5,bgcolor:"grey.50",border:1,borderColor:"divider"},children:[e.jsx(lt,{sx:{fontSize:16,color:"grey.400",mt:"2px"}}),e.jsx(C,{variant:"body2",sx:{color:"grey.800",lineHeight:1.5},children:t.surveyAddress||"—"})]})}),e.jsx(ie,{label:"Coordinates",children:t.surveyLat&&t.surveyLng?e.jsxs(z,{direction:"row",spacing:1.25,alignItems:"center",flexWrap:"wrap",useFlexGap:!0,children:[e.jsx(At,{title:`${t.surveyLat}, ${t.surveyLng}`,arrow:!0,placement:"top",children:e.jsxs(z,{direction:"row",spacing:.5,alignItems:"center",sx:{cursor:"default"},children:[e.jsx(lt,{sx:{fontSize:16,color:"grey.400"}}),e.jsx(C,{variant:"body2",sx:{fontWeight:500,color:"grey.800",borderBottom:"1px dotted",borderColor:"grey.300"},children:[t.neighbourhood,t.city].filter(Boolean).join(", ")||"Pinned location"})]})}),e.jsx(pe,{component:"a",href:`https://www.google.com/maps?q=${t.surveyLat},${t.surveyLng}`,target:"_blank",rel:"noopener",size:"small",variant:"outlined",startIcon:e.jsx(Hr,{sx:{fontSize:16}}),sx:{py:.25,px:1.25,minWidth:0,fontSize:"0.75rem",fontWeight:600,borderRadius:5,color:"primary.main",borderColor:"primary.100",bgcolor:"primary.lighter","&:hover":{borderColor:"primary.main",bgcolor:"primary.lighter"}},children:"View on map"})]}):e.jsx(C,{variant:"body2",sx:{color:"grey.500"},children:"—"})})]})}),e.jsx(g,{item:!0,xs:12,children:e.jsx(ft,{icon:xr,title:"Contact & Compliance",accent:"primary",children:e.jsxs(g,{container:!0,spacing:2.5,children:[e.jsx(g,{item:!0,xs:12,sm:6,md:4,children:e.jsx(ht,{label:"Phone",value:t.phone})}),e.jsx(g,{item:!0,xs:12,sm:6,md:4,children:e.jsx(ie,{label:"Data Consent",children:e.jsx(be,{label:t.dataConsent&&ye(t.dataConsent),color:Zn(t.dataConsent)})})}),e.jsx(g,{item:!0,xs:12,sm:6,md:4,children:e.jsx(ht,{label:"Last Updated",value:t.lastUpdated})}),t.notes&&e.jsx(g,{item:!0,xs:12,children:e.jsxs(W,{sx:{p:2,borderRadius:1.5,bgcolor:"warning.lighter",border:1,borderColor:"warning.light"},children:[e.jsxs(z,{direction:"row",spacing:1,alignItems:"center",sx:{mb:.5},children:[e.jsx(mr,{sx:{fontSize:16,color:"warning.dark"}}),e.jsx(C,{variant:"caption",sx:{color:"warning.dark",textTransform:"uppercase",letterSpacing:.4,fontSize:"0.68rem",fontWeight:700},children:"Notes"})]}),e.jsx(C,{variant:"body2",sx:{color:"grey.800"},children:t.notes})]})})]})})})]})})]})})})})]})}function xs(){var Se;const[t,o]=p.useState([]),[c,b]=p.useState(!0),[$,I]=p.useState(null),[s]=Tr(),[h,k]=p.useState(0),[E,D]=p.useState(s.get("q")||""),[_,H]=p.useState(0),[O,ve]=p.useState(10);p.useEffect(()=>{const l=s.get("q");l!=null&&(D(l),H(0))},[s]);const[T,ge]=p.useState({open:!1,mode:"add",initial:null}),[u,v]=p.useState(null),[y,Y]=p.useState(!1),V=(l=!1)=>{l||(b(!0),I(null)),$r().then(m=>o(m.map(Lr))).catch(m=>{l||I(m.message||"Failed to load clients")}).finally(()=>{l||b(!1)})};p.useEffect(()=>{V();const l=setInterval(()=>{V(!0)},1e4);return()=>clearInterval(l)},[]);const B=p.useMemo(()=>({total:t.length,newCount:t.filter(l=>l.status==="newClient").length,parcels:t.reduce((l,m)=>l+(Number(m.parcelVolume)||0),0),contracts:t.reduce((l,m)=>l+(Number(m.activeContracts)||0),0)}),[t]),K=p.useMemo(()=>{const l=[];return t.forEach(m=>{l.includes(m.status)||l.push(m.status)}),[{key:"all",label:"All"},...l.map(m=>({key:m,label:ye(m)}))]},[t]),xe=((Se=K[Math.min(h,K.length-1)])==null?void 0:Se.key)||"all",je=p.useMemo(()=>{const l={all:t.length};return t.forEach(m=>{l[m.status]=(l[m.status]||0)+1}),l},[t]),ne=p.useMemo(()=>t.filter(l=>{const m=xe==="all"||l.status===xe,le=!E||[l.name,l.phone,l.city,l.businessType,l.clientId,l.neighbourhood].join(" ").toLowerCase().includes(E.toLowerCase());return m&&le}),[t,xe,E]),U=ne.slice(_*O,_*O+O),S=()=>{ge({open:!1,mode:"add",initial:null}),V()},Ce=async()=>{Y(!0);try{await Or(u.id),v(null),V()}catch(l){I(l.message||"Failed to delete client")}finally{Y(!1)}};return e.jsxs(e.Fragment,{children:[e.jsx(Jr,{title:"Clients",breadcrumbs:[{label:"Clients"}],action:e.jsxs(z,{direction:"row",spacing:1.5,children:[e.jsx(pe,{variant:"outlined",startIcon:e.jsx(Rr,{}),onClick:V,disabled:c,children:"Refresh"}),e.jsx(pe,{variant:"contained",startIcon:e.jsx(kr,{}),onClick:()=>ge({open:!0,mode:"add",initial:null}),children:"Add Client"})]})}),e.jsxs(g,{container:!0,spacing:2.5,sx:{mb:3},children:[e.jsx(g,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(ct,{accent:!0,title:"Total Clients",value:B.total,icon:Vt,caption:"All registered"})}),e.jsx(g,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(ct,{accent:!0,title:"New Clients",value:B.newCount,icon:Br,color:"primary",caption:"Awaiting onboarding"})}),e.jsx(g,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(ct,{accent:!0,title:"Total Parcel Volume",value:B.parcels.toLocaleString(),icon:pr,color:"primary",caption:"Across all clients"})}),e.jsx(g,{item:!0,xs:12,sm:6,lg:3,children:e.jsx(ct,{accent:!0,title:"Active Contracts",value:B.contracts,icon:gr,color:"primary",caption:"Currently running"})})]}),e.jsxs(Yr,{sx:{overflow:"hidden"},children:[e.jsxs(W,{sx:{px:2.5,py:2,borderBottom:1,borderColor:"divider",display:"flex",alignItems:"center",gap:1.5,background:l=>`linear-gradient(90deg, ${l.palette.primary.lighter}66 0%, ${l.palette.background.paper} 70%)`},children:[e.jsx(W,{sx:{width:40,height:40,borderRadius:2,bgcolor:"primary.lighter",color:"primary.main",display:"inline-flex",alignItems:"center",justifyContent:"center"},children:e.jsx(Vt,{fontSize:"small"})}),e.jsxs(W,{children:[e.jsx(C,{variant:"subtitle1",sx:{fontWeight:700,color:"grey.800",lineHeight:1.2},children:"Client Directory"}),e.jsx(C,{variant:"caption",color:"text.secondary",children:"Browse, search and manage every client account"})]})]}),e.jsxs(z,{direction:{xs:"column",md:"row"},spacing:1.5,sx:{p:2},alignItems:{md:"center"},children:[e.jsx(L,{size:"small",placeholder:"Search by name, phone, city, ID…",value:E,onChange:l=>{D(l.target.value),H(0)},sx:{minWidth:300},InputProps:{startAdornment:e.jsx(Qr,{position:"start",children:e.jsx(Pr,{fontSize:"small"})})}}),e.jsx(W,{sx:{flexGrow:1}}),!c&&e.jsxs(z,{direction:"row",spacing:1,alignItems:"center",children:[e.jsxs(C,{variant:"body2",color:"text.secondary",children:[ne.length," ",ne.length===1?"client":"clients"]}),e.jsx(vt,{size:"small",label:"live · doormile_clients",sx:{height:22,fontSize:"0.7rem",bgcolor:"success.lighter",color:"success.dark",fontWeight:600}})]})]}),e.jsx(W,{sx:{px:2,borderBottom:1,borderColor:"divider"},children:e.jsx(Vr,{value:Math.min(h,K.length-1),onChange:(l,m)=>{k(m),H(0)},variant:"scrollable",scrollButtons:"auto",children:K.map((l,m)=>e.jsx(Gr,{label:e.jsx(qr,{label:l.label,count:je[l.key]||0,active:h===m})},l.key))})}),$&&e.jsx(hr,{severity:"error",sx:{m:2},action:e.jsx(pe,{color:"inherit",size:"small",onClick:V,children:"Retry"}),children:$}),e.jsx(en,{children:e.jsxs(tn,{sx:{minWidth:900},children:[e.jsx(rn,{children:e.jsxs(Ue,{sx:{"& th":{bgcolor:"grey.50",fontWeight:700,color:"grey.700",textTransform:"uppercase",fontSize:"0.72rem",letterSpacing:.4}},children:[e.jsx(N,{padding:"checkbox"}),e.jsx(N,{children:"ID"}),e.jsx(N,{children:"Client"}),e.jsx(N,{children:"Contact"}),e.jsx(N,{children:"Location"}),e.jsx(N,{align:"center",children:"Volume"}),e.jsx(N,{children:"Status"}),e.jsx(N,{align:"right",children:"Actions"})]})}),e.jsx(nn,{children:c?e.jsx(Ue,{children:e.jsx(N,{colSpan:8,sx:{border:"none"},children:e.jsx(W,{sx:{display:"flex",justifyContent:"center",py:6},children:e.jsx(xt,{})})})}):U.length===0?e.jsx(Ue,{children:e.jsx(N,{colSpan:8,sx:{border:"none"},children:e.jsx(zr,{title:"No clients found",caption:"Try a different tab or search term, or add a client."})})}):U.map((l,m)=>e.jsx(Qn,{row:l,index:_*O+m,onEdit:le=>ge({open:!0,mode:"edit",initial:le}),onDelete:le=>v(le)},l.id))})]})}),e.jsx(wr,{component:"div",count:ne.length,page:_,onPageChange:(l,m)=>H(m),rowsPerPage:O,onRowsPerPageChange:l=>{ve(+l.target.value),H(0)},rowsPerPageOptions:[5,10,25]})]}),e.jsx(Jn,{open:T.open,mode:T.mode,initial:T.initial,onClose:()=>ge({open:!1,mode:"add",initial:null}),onSaved:S}),e.jsxs(lr,{open:!!u,onClose:y?void 0:()=>v(null),children:[e.jsx(cr,{children:"Delete client?"}),e.jsx(ur,{children:e.jsxs(Dr,{children:["This will permanently remove ",e.jsx("strong",{children:u==null?void 0:u.name})," from the doormile_clients collection. This cannot be undone."]})}),e.jsxs(dr,{sx:{px:3,py:2},children:[e.jsx(pe,{onClick:()=>v(null),disabled:y,children:"Cancel"}),e.jsx(pe,{color:"error",variant:"contained",onClick:Ce,disabled:y,startIcon:y?e.jsx(xt,{size:16,color:"inherit"}):null,children:"Delete"})]})]})]})}export{xs as default};