1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{};e._posthogReleaseId=e._posthogReleaseId||"01a0f424-0226-0000-d9cc-5d4541f5bf4a";var n=(new e.Error).stack;n&&(e._posthogChunkIds=e._posthogChunkIds||{},e._posthogChunkIds[n]="c7afdd9f-25e3-9e37-d341-6aaf0c136a18")}catch(e){}}();;!function(){try { var e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof global?global:"undefined"!=typeof window?window:"undefined"!=typeof self?self:{},n=(new e.Error).stack;n&&((e._debugIds|| (e._debugIds={}))[n]="c7afdd9f-25e3-9e37-d341-6aaf0c136a18")}catch(e){}}(); 2(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,715332,585373,725442,209019,162107,e=>{"use strict";var t=e.i(843476),s=e.i(522016),r=e.i(483210),a=e.i(761203),i=e.i(271645);e.i(283074);var l=e.i(586892),n=e.i(602228),d=e.i(499971),o=e.i(618566);e.i(924856);var c=e.i(98004),u=e.i(272212),m=e.i(286323);function p(e,t={}){let s=(0,o.useRouter)(),r=(0,o.usePathname)(),a=(0,o.useSearchParams)(),l=(0,m.useProductNeedsList)(e,t),n=(0,i.useMemo)(()=>(l.data?.data??[]).filter(e=>"ARCHIVED"!==e.status),[l.data]),d=(0,i.useMemo)(()=>Array.from(new Set(n.map(e=>e.main_product_id))).sort(),[n]),x=(0,u.useApiV1MainProductsList)({id__in:d,limit:100},{query:{enabled:d.length>0,staleTime:1/0}}),h=(0,i.useMemo)(()=>{let e=new Map;for(let t of x.data?.data??[]){if(!t.id)continue;let s=(0,c.toMainProductEntity)(t);e.set(t.id,{name:t.name,imageUrl:s.image??null})}return e},[x.data]),g=(0,i.useMemo)(()=>((e,t)=>{let s=[],r=new Map;for(let a of e){let e="ACTIVE"!==a.status||a.product_id?null:`family:${a.main_product_id}`;if(null!=e&&r.has(e)){let t=s[r.get(e)];t.groupedNeeds.push(a),t.count+=1;continue}let i={need:a,groupedNeeds:[a],count:1,product:t.get(a.main_product_id)??null};null!=e&&r.set(e,s.length),s.push(i)}return s})(n,h),[n,h]),f=n.filter(e=>"ACTIVE"===e.status).length,j=n.filter(e=>"CONVERTED"===e.status).length,v=a.get("need"),N=l.isError&&"object"==typeof l.error&&null!==l.error&&"status"in l.error&&403===l.error.status;return{state:{rows:g,activeCount:f,convertedCount:j,focusedNeedId:v,hasNeeds:n.length>0,isLoading:l.isLoading,isError:l.isError,isForbidden:N},actions:{clearFocusedNeed:()=>{let e=new URLSearchParams(a.toString());if(!e.has("need")&&!e.has("section"))return;e.delete("need"),e.delete("section");let t=e.toString();s.replace(t?`${r}?${t}`:r,{scroll:!1})}},query:{needsQuery:l}}}function x(e){return"ACTIVE"===e.status&&!!e.product_id&&e.is_pricing_ready}var h=e.i(912598),g=e.i(801579),f=e.i(563893),j=e.i(671398);e.i(632821);var v=e.i(559528),N=e.i(756202);function b(e={}){let t=(0,h.useQueryClient)(),{toast:s}=(0,N.useToast)(),[r,a]=(0,i.useState)(!1);return{archiveNeed:(0,i.useCallback)(async i=>{if(r)return!1;a(!0);try{let r=await (0,u.apiV1UserAddressProductNeedsArchiveUpdate)(i.id,{main_product_id:i.main_product_id,product_id:i.product_id??null},e.requestOptions);
2return(0,f.removeNeedFromCaches)(t,r),(0,v.track)(j.PRODUCT_NEED_ARCHIVED,{need_id:r.id,user_address_id:r.user_address_id,main_product_id:r.main_product_id,product_id:r.product_id??null,surface:e.surface??"customer"}),s({title:l.PLAN_TOASTS.removed}),!0}catch(e){return s({title:"Unable to remove this",description:(0,g.getApiErrorMessage)(e,"Something went wrong. Please try again."),variant:"destructive"}),!1}finally{a(!1)}},[r,e.requestOptions,e.surface,t,s]),isSubmitting:r}}var y=e.i(657688),_=e.i(401851),w=e.i(826514),C=e.i(648119),S=e.i(679258),k=e.i(515281);function P(e,t={}){switch(e.status){case"CONVERTED":return t.supplierName?`${t.supplierName} is handling this â it's in your cart.`:"Booked â this is in your cart.";case"ARCHIVED":return"Removed from this plan.";default:if(!e.product_id)return e.start_date?"Pick a size to see live supplier pricing.":"Pick a size and dates to see live supplier pricing.";if(!e.is_pricing_ready)return"Add dates to see live supplier pricing.";if(null!=t.supplierCount&&t.supplierCount>0)return`Ready to compare â ${t.supplierCount} local supplier${1===t.supplierCount?"":"s"} priced this.`;return"Ready to compare local supplier pricing."}}e.s(["getNeedStatusSentence",0,P],585373);var A=e.i(984716),I=e.i(582629),E=e.i(902470),T=e.i(14602),D=e.i(798833);e.i(986823);var L=e.i(113827),M=e.i(266027),O=e.i(844439),R=e.i(458330);let U=new Set;function q(e,t){let s=!!(e&&"ACTIVE"===e.status&&(t?.enabled??!0));return{...(0,M.useQuery)({queryKey:R.productNeedQueryKeys.supplierComparison(e?.id??""),queryFn:()=>e?(0,O.fetchNeedSupplierComparison)(e.id):null,enabled:s,staleTime:6e4}),pricingLoadingIds:U,pricingErrorIds:U}}e.i(739669);var V=e.i(930150),B=e.i(188273),F=e.i(867927),$=e.i(205702),z=e.i(255664),G=e.i(943907);function K({insights:e,onSetDetails:s,surface:r="customer"}){let a="EXACT"===e.insight_level,n=e.market,o=n?.total_distribution??null,c=n?.availability==="unavailable"||o?.p05==null||o?.p95==null,u=(0,i.useMemo)(()=>(e.data??[]).filter(e=>"unavailable"!==e.ranking.tier),[e]),m=(0,i.useMemo)(()=>{if(!a)return[];let e=(n?.component_distributions??[]).filter(e=>"usd"===e.unit.toLowerCase()).flatMap(e=>{let{p05:t,p25:s,p50:r,p75:a,p95:i,sample_size:l}=e.distribution;return null==r||r<=0?[]:[{code:e.code,p05:t,p25:s,median:r,p75:a,p95:i,high:i??a??r,sampleSize:l}]}).sort((e,t)=>t.median-e.median).slice(0,4),t=Math.max(...e.map(e=>e.high??e.median),0);if(t<=0)return[];let s=e=>Math.min(100,Math.max(0,e/t*100));return e.map(e=>({code:e.code,label:(0,B.metricLabel)(e.code),median:e.median,bandStartPct:s(e.p25??e.median),bandEndPct:s(e.p75??e.median),medianPct:s(e.median),low:e.p05,typicalLow:e.p25,typicalHigh:e.p75,high:e.p95,sampleSize:e.sampleSize}))},[a,n]),p=(0,i.useRef)(null);return((0,i.useEffect)(()=>{if(a)return;let t=e.main_product_id;p.current!==t&&(p.current=t,(0,v.track)(j.PRODUCT_NEED_MARKET_PREVIEW_VIEWED,{main_product_id:e.main_product_id,product_id:e.product_id??null,availability:n?.availability??"unavailable",sample_size:o?.sample_size??0,surface:r}))},[o?.sample_size,e,a,n?.availability,r]),c&&!a)?(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)("p",{className:"text-sm text-foreground",children:l.INDICATIVE_PRICING.unavailable.absence}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:n?.disclaimer??l.INDICATIVE_PRICING.unavailable.explanation}),s?(0,t.jsx)(d.Button,{variant:"link",className:"h-auto p-0 text-sm",onClick:s,children:l.INDICATIVE_PRICING.unavailable.action}):null]}):a&&0===u.length?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"No local suppliers can take this for these dates â try different dates."}):c||null==o?null:(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsx)(G.PriceRangeBand,{low:o.p05,high:o.p95,bandStart:o.p25,bandEnd:o.p75,median:o.p50,sampleSize:o.sample_size,ariaLabel:`Local suppliers charge between ${(0,V.formatCurrency)(o.p05)} and ${(0,V.formatCurrency)(o.p95)}${null!=o.p50?`, most around ${(0,V.formatCurrency)(o.p50)}`:""}`}),m.length>0?(0,t.jsxs)($.Collapsible,{className:"border-t border-border pt-2",children:[(0,t.jsxs)($.CollapsibleTrigger,{className:(0,L.cn)("group flex items-center gap-1 rounded-md py-1 pr-2 text-xs font-medium text-muted-foreground","transition-colors duration-150 hover:text-foreground"),children:[(0,t.jsx)(F.ChevronRight,{className:"h-3.5 w-3.5 transition-transform group-data-[state=open]:rotate-90","aria-hidden":"true"}),"What's in the price"]}),(0,t.jsx)($.CollapsibleContent,{children:(0,t.jsx)(z.TooltipProvider,{delayDuration:150,children:(0,t.jsx)("div",{className:"space-y-2 pt-2",children:m.map(e=>(0,t.jsxs)(z.Tooltip,{children:[(0,t.jsx)(z.TooltipTrigger,{asChild:!0,children:(0,t.jsxs)("div",{tabIndex:0,className:"flex items-center gap-3 rounded-md focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring",children:[(0,t.jsx)("span",{className:"w-28 flex-none truncate text-xs text-muted-foreground",children:e.label}),(0,t.jsx)(G.PriceBandTrack,{className:"min-w-0 flex-1",bandStartPct:e.bandStartPct,bandEndPct:e.bandEndPct,medianPct:e.medianPct}),(0,t.jsx)("span",{className:"w-16 flex-none text-right text-xs font-medium tabular-nums text-foreground",children:(0,V.formatCurrency)(e.median)})]})}),(0,t.jsxs)(z.TooltipContent,{side:"top",className:"space-y-0.5 text-xs",children:[null!=e.typicalLow&&null!=e.typicalHigh?(0,t.jsxs)("p",{children:["Most suppliers charge ",(0,V.formatCurrency)(e.typicalLow),"â",(0,V.formatCurrency)(e.typicalHigh)]}):null,(0,t.jsxs)("p",{className:"text-muted-foreground",children:[null!=e.low?`Low ${(0,V.formatCurrency)(e.low)}
2 \xb7 `:"","Median ",(0,V.formatCurrency)(e.median),null!=e.high?` \xb7 High ${(0,V.formatCurrency)(e.high)}`:"",e.sampleSize>0?` \xb7 ${e.sampleSize} listing${1===e.sampleSize?"":"s"}`:""]})]})]},e.code))})})})]}):null,!a&&o.sample_size>0?(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:n?.disclaimer??l.INDICATIVE_PRICING.footer(o.sample_size)}):null]})}var W=e.i(367363);function Q({suppliers:e,extraCount:s=0,label:r,className:a}){if(0===e.length)return null;let i=e.map(e=>e.name).join(", "),l=`${r??"Suppliers"} Including ${i}${s>0?` and ${s} more`:""}`;return(0,t.jsxs)("div",{className:(0,L.cn)("flex items-center gap-2",a),role:"img","aria-label":l,children:[(0,t.jsxs)("div",{className:"flex items-center",children:[e.map((e,s)=>(0,t.jsx)("span",{className:(0,L.cn)("flex h-6 w-6 items-center justify-center overflow-hidden rounded-full border border-border bg-muted ring-2 ring-card",s>0&&"-ml-2"),children:e.logoUrl?(0,t.jsx)(y.default,{src:e.logoUrl,alt:"",width:24,height:24,className:"h-full w-full object-cover"}):(0,t.jsx)(W.Truck,{className:"h-3 w-3 text-muted-foreground","aria-hidden":"true"})},`${e.name}-${s}`)),s>0?(0,t.jsxs)("span",{className:"-ml-2 flex h-6 min-w-6 items-center justify-center rounded-full border border-border bg-card px-1 text-[10px] font-semibold text-muted-foreground ring-2 ring-card",children:["+",s]}):null]}),r?(0,t.jsx)("p",{className:"text-sm text-foreground",children:r}):null]})}function H({row:e,isFocused:r,onSetDetails:a,onCompareSuppliers:i,onRemove:n,isRemoving:o,surface:c="customer",requestOptions:m,showMarketPreview:p=!0,compareLabel:h=l.PLAN_ACTIONS.compareSuppliers,requireConfiguredToCompare:g=!0}){let{need:f,product:j,count:v}=e,N="ACTIVE"===f.status,b="CONVERTED"===f.status,O=x(f),R=q(N?f:null),U=R.data?.marketInsights??null,V=(0,A.summarizeComparisonSuppliers)(R.data),B=U?.insight_level==="EXACT"?V.totalCount:null,F=function(e,t={}){let s=e?.status==="CONVERTED"&&e.converted_booking_id?e.converted_booking_id:null;return(0,M.useQuery)({queryKey:["converted-need-supplier",s??""],queryFn:async()=>{let e=(await (0,u.apiV1OrderGroupsRetrieve)(s??"",{"expand[]":["seller_product_seller_location.seller_location.seller"]},t.requestOptions)).seller_product_seller_location;return e&&"string"!=typeof e?(0,A.getSupplierDisplay)(e):null},enabled:!!s,staleTime:1/0})}(b?f:null,{requestOptions:m}).data??null,$=e=>(0,_.format)((0,w.parseISO)(e),"MMM d"),z=[];f.start_date&&z.push(f.end_date&&f.end_date!==f.start_date?`${$(f.start_date)} â ${$(f.end_date)}`:$(f.start_date));let G=(0,l.timesPerWeekLabel)(f.times_per_week);G&&z.push(G);let W=(0,l.shiftCountLabel)(f.shift_count);W&&z.push(W);let J=(f.missing_fields??[]).slice(0,2).map(e=>`Add ${(0,l.humanizeFieldCode)(e)}`);return(0,t.jsxs)("div",{id:`need-${f.id}`,className:(0,L.cn)("space-y-3 rounded-xl border border-border bg-card p-5",r&&"ring-2 ring-primary/60"),children:[(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[j?.imageUrl?(0,t.jsx)(y.default,{src:j.imageUrl,alt:"",width:44,height:44,className:"h-11 w-11 shrink-0 rounded-lg border border-border object-cover"}):(0,t.jsx)("span",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-lg border border-border bg-muted",children:(0,t.jsx)(S.Package,{className:"h-5 w-5 text-muted-foreground","aria-hidden":"true"})}),(0,t.jsxs)("div",{className:"min-w-0 flex-1 space-y-1",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsxs)("p",{className:"truncate text-sm font-semibold text-foreground",children:[j?.name??"Product",v>1?` \xd7 ${v}`:""]}),b?(0,t.jsx)(E.Badge,{variant:"secondary",children:"Booked"}):null]}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:P(f,{supplierCount:B,supplierName:F?.name??null})})]}),N&&V.suppliers.length>0?(0,t.jsx)(Q,{suppliers:V.suppliers,extraCount:V.extraCount,className:"mt-1 shrink-0"}):null,N?(0,t.jsxs)(T.AlertDialog,{children:[(0,t.jsxs)(D.DropdownMenu,{children:[(0,t.jsx)(D.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsx)(d.Button,{variant:"ghost",size:"icon",className:"h-8 w-8 shrink-0","aria-label":"More actions",disabled:o,children:(0,t.jsx)(C.MoreHorizontal,{className:"h-4 w-4"})})}),(0,t.jsx)(D.DropdownMenuContent,{align:"end",children:(0,t.jsx)(T.AlertDialogTrigger,{asChild:!0,children:(0,t.jsx)(D.DropdownMenuItem,{className:"text-destructive focus:text-destructive",children:l.PLAN_ACTIONS.remove})})})]}),(0,t.jsxs)(T.AlertDialogContent,{children:[(0,t.jsxs)(T.AlertDialogHeader,{children:[(0,t.jsx)(T.AlertDialogTitle,{children:l.REMOVE_CONFIRM.title}),(0,t.jsx)(T.AlertDialogDescription,{children:l.REMOVE_CONFIRM.description})]}),(0,t.jsxs)(T.AlertDialogFooter,{children:[(0,t.jsx)(T.AlertDialogCancel,{children:l.REMOVE_CONFIRM.cancel}),(0,t.jsx)(T.AlertDialogAction,{className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",onClick:()=>n(e),children:l.REMOVE_CONFIRM.confirm})]})]})]}):null]}),N?(0,t.jsxs)("button",{type:"button",onClick:()=>a(e),"aria-label":`Edit details${z.length?`: ${z.join(", ")}`:""}`,className:(0,L.cn)("flex flex-wrap items-center gap-1.5 rounded-md text-left","focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring"),children:[z.map(e=>(0,t.jsx)("span",{className:"rounded-full border border-border bg-muted/30 px-2 py-0.5 text-xs text-foreground",children:e},e)),J.map(e=>(0,t.jsx)("span",{className:"rounded-full border border-dashed border-border px-2 py-0.5 text-xs text-muted-foreground",children:e},e)),(0,t.jsxs)("span",{className:"inline-flex items-center gap-1 px-1 text-xs font-medium text-primary",children:[(0,t.jsx)(k.Pencil,{className:"h-3 w-3","aria-hidden":"true"}),"Edit"]})]}):null,N&&p&&U?(0,t.jsx)(K,{insights:U,surface:c,onSetDetails:()=>a(e)}):null,N?(0,t.jsx)("div",{className:"flex flex-wrap gap-2",children:g&&!O?(0,t.jsx)(d.Button,{size:"sm",onClick:()=>a(e),children:l.PLAN_ACTIONS.setDetails}):(0,t.jsx)(d.Button,{size:"sm",onClick:()=>i(e),children:h})}):null,b&&f.converted_booking_id?(0,t.jsxs)("div",{className:"flex flex-wrap items-center gap-3",children:[F?(0,t.jsx)(Q,{suppliers:[F],label:F.name}):null,(0,t.jsx)(d.Button,{variant:"outline",size:"sm",asChild:!0,children:(0,t.jsx)(s.default,{href:(0,I.routeCustomerBooking)({orderGroupId:f.converted_booking_id}),children:l.PLAN_ACTIONS.viewBooking})})]}):null]})}var J=e.i(586448),Y=e.i(976452),X=e.i(268531),Z=e.i(781282);function ee({imageUrl:e}){return e?(0,t.jsx)(y.default,{src:e,alt:"",width:44,height:44,className:"h-11 w-11 shrink-0 rounded-lg border border-border object-cover"}):(0,t.jsx)("span",{className:"flex h-11 w-11 shrink-0 items-center justify-center rounded-lg border border-border bg-muted",children:(0,t.jsx)(S.Package,{className:"h-5 w-5 text-muted-foreground","aria-hidden":"true"})})}let et=[{id:"recommended",label:"Recommended"},{id:"cheapest",label:"Cheapest"},{id:"single_supplier",label:"Single supplier"}];function es({open:e,onOpenChange:s,userAddressId:r,rows:a,surface:n="customer"}){let[o,c]=(0,i.useState)("recommended"),[u,m]=(0,i.useState)({}),p=(0,i.useMemo)(()=>a.flatMap(e=>e.groupedNeeds),[a]),h=(0,i.useMemo)(()=>p.filter(e=>x(e)),[p]),g=(0,i.useMemo)(()=>p.filter(e=>"ACTIVE"===e.status&&!x(e)),[p]),f=(0,i.useMemo)(()=>{let e=new Map;for(let t of a)for(let s of t.groupedNeeds)e.set(s.id,{name:t.product?.name??"Product",imageUrl:t.product?.imageUrl??null});return e},[a]),N=(0,J.useQueries)({queries:h.map(t=>({queryKey:R.productNeedQueryKeys.supplierComparison(t.id),queryFn:()=>(0,O.fetchNeedSupplierComparison)(t.id),enabled:e,staleTime:6e4}))}),b=new Map;h.forEach((e,t)=>{b.set(e.id,N[t]?.data??null)});let y=N.some(e=>e.isLoading||e.isFetching),_=new Map;for(let e of(0,Y.applyQuotePreset)(o,b))_.set(e.needId,e.spslId);let w=h.flatMap(e=>{let t=u[e.id]??_.get(e.id);return t?[{needId:e.id,spslId:t}]:[]}),C=Object.keys(u).length>0,S=0,k=0;for(let e of w){let t=(0,Y.listQuotableListings)(b.get(e.needId)).find(t=>
2t.id===e.spslId),s=t?.insights?.listing.evaluated_total??t?.total;null!=s&&(S+=s,k+=1)}let P=k>0?S:null;return(0,t.jsx)(X.ResponsiveModal,{open:e,onOpenChange:s,title:"Generate a quote",children:(0,t.jsxs)("div",{className:"space-y-5 p-1",children:[(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Pick a supplier for each planned product â start from a preset and change any of them."}),(0,t.jsxs)("div",{className:"flex flex-wrap gap-2",children:[et.map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>{c(e.id),m({})},className:(0,L.cn)("rounded-full border px-3 py-1 text-xs font-medium transition-colors duration-150",C||o!==e.id?"border-border text-muted-foreground hover:text-foreground":"border-primary bg-primary/15 text-primary"),children:e.label},e.id)),C?(0,t.jsx)("span",{className:"rounded-full border border-dashed border-border px-3 py-1 text-xs text-muted-foreground",children:"Custom"}):null]}),(0,t.jsxs)("div",{className:"max-h-96 space-y-3 overflow-y-auto pr-1",children:[h.map(e=>{let s=(0,Y.listQuotableListings)(b.get(e.id)),r=u[e.id]??_.get(e.id)??"",a=f.get(e.id);return(0,t.jsxs)("div",{className:"flex items-start gap-3 rounded-xl border border-border bg-card p-3",children:[(0,t.jsx)(ee,{imageUrl:a?.imageUrl??null}),(0,t.jsxs)("div",{className:"min-w-0 flex-1 space-y-1.5",children:[(0,t.jsx)("p",{className:"truncate text-sm font-semibold text-foreground",children:a?.name}),s.length?(0,t.jsx)(Z.SupplierListingSelect,{listings:s,value:r,onValueChange:t=>m(s=>({...s,[e.id]:t}))}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:y?"Loading suppliersâ¦":"No local suppliers can take this right now."}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:s.length>1?`${s.length} suppliers priced this`:null})]})]},e.id)}),g.map(e=>{let s=f.get(e.id);return(0,t.jsxs)("div",{className:"flex items-start gap-3 rounded-xl border border-dashed border-border p-3 opacity-70",children:[(0,t.jsx)(ee,{imageUrl:s?.imageUrl??null}),(0,t.jsxs)("div",{className:"min-w-0 flex-1",children:[(0,t.jsx)("p",{className:"truncate text-sm font-semibold text-foreground",children:s?.name}),(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:[(0,l.missingFieldsSentence)(e.missing_fields)??"Finish this item's details to include it."," ","It won't appear on the quote."]})]})]},e.id)})]}),(0,t.jsxs)("div",{className:"flex items-center justify-between gap-3 border-t border-border pt-4",children:[null!=P?(0,t.jsxs)("div",{children:[(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Quote total"}),(0,t.jsx)("p",{className:"text-base font-semibold tabular-nums text-foreground",children:(0,V.formatCurrency)(P)})]}):(0,t.jsx)("span",{}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(d.Button,{variant:"ghost",onClick:()=>s(!1),children:"Not yet"}),(0,t.jsx)(d.Button,{onClick:()=>{w.length&&((0,v.track)(j.PRODUCT_NEED_QUOTE_GENERATED,{user_address_id:r,need_count:w.length,preset:C?"custom":o,surface:n}),window.open((0,I.routeCustomerProjectPlanQuote)({userAddressId:r,serializedSelections:(0,Y.serializeQuoteSelections)(w),crm:"crm"===n}),"_blank"),s(!1))},disabled:0===w.length||y,children:"Open quote"})]})]})]})})}var er=e.i(263676),ea=e.i(351101);let ei="project_plan_explainer_dismissed";function el(){let[e,s]=(0,i.useState)(()=>"true"===(0,ea.getSafeLocalStorage)().getItem(ei));return e?null:(0,t.jsxs)("div",{className:"relative rounded-xl border border-border bg-card px-4 py-3",children:[(0,t.jsx)(d.Button,{variant:"ghost",size:"icon",className:"absolute right-1.5 top-1.5 h-6 w-6","aria-label":"Dismiss",onClick:()=>{(0,ea.getSafeLocalStorage)().setItem(ei,"true"),s(!0),(0,v.track)(j.BUTTON_CLICKED,{action:"plan_explainer_dismissed",surface:"customer"})},children:(0,t.jsx)(er.X,{className:"h-3.5 w-3.5"})}),(0,t.jsx)("p",{className:"pr-8 text-xs font-semibold text-foreground",children:l.PLAN_EXPLAINER.title}),(0,t.jsx)("ol",{className:"mt-1.5 space-y-1",children:l.PLAN_EXPLAINER.steps.map((e,s)=>(0,t.jsxs)("li",{className:"flex items-baseline gap-1.5 text-xs text-muted-foreground",children:[(0,t.jsx)("span",{className:"flex-none font-semibold tabular-nums text-primary",children:s+1}),e]},e))}),(0,t.jsx)("p",{className:"mt-1.5 text-xs text-muted-foreground
2/80",children:l.PLAN_EXPLAINER.footer})]})}var en=e.i(632781),ed=e.i(418883),eo=e.i(289954),ec=e.i(74245),eu=e.i(138995),em=e.i(885513);let ep=e=>({startDate:e?.start_date??"",endDate:e?.end_date??"",wasteTypeId:e?.waste_type_id||null,timesPerWeek:e?.times_per_week??null,shiftCount:e?.shift_count??null}),ex=l.TIMES_PER_WEEK_CHOICES.map(e=>({value:String(e.value),label:e.label})),eh=l.SHIFT_COUNT_CHOICES.map(e=>({value:String(e.value),label:e.label}));function eg({open:e,onOpenChange:s,need:r,productName:a,surface:n="customer",requestOptions:o,onCompare:c,onSaved:m}){let{state:p,actions:x}=function({need:e,surface:t="customer",requestOptions:s,onSaved:r}){let a=(0,u.useApiV1MainProductsRetrieve)(e?.main_product_id??"",void 0,{query:{enabled:!!e?.main_product_id}}),n=a.data,d=(0,em.useMainProductVariantSelection)(n,e?.product_id),o=e?`${e.id}:${e.updated_on}`:"",[c,m]=(0,i.useState)(()=>({syncKey:o,fields:ep(e)})),p=c.syncKey===o?c.fields:ep(e),x=(e,t)=>m({syncKey:o,fields:{...p,[e]:t}}),[N,b]=(0,i.useState)({}),[y,_]=(0,i.useState)(null),{configureNeed:w,isSubmitting:C}=function(e={}){let t=(0,h.useQueryClient)(),[s,r]=(0,i.useState)(!1);return{configureNeed:(0,i.useCallback)(async(a,i)=>{if(s)return null;r(!0);try{let s=await (0,u.apiV1UserAddressProductNeedsUpdateUpdate)(a,i,e.requestOptions);return(0,f.applyConfiguredNeedToCaches)(t,s),(0,v.track)(j.PRODUCT_NEED_CONFIGURED,{need_id:s.id,user_address_id:s.user_address_id,main_product_id:s.main_product_id,product_id:s.product_id??null,has_variant:!!s.product_id,is_pricing_ready:s.is_pricing_ready,surface:e.surface??"customer"}),s}finally{r(!1)}},[s,e.requestOptions,e.surface,t]),isSubmitting:s}}({surface:t,requestOptions:s}),S=(0,i.useMemo)(()=>(n?.main_product_waste_types??[]).filter(e=>!e.is_deleted).map(e=>({id:e.waste_type.id??"",name:e.waste_type.name})).filter(e=>!!e.id),[n]),k=!!n?.has_service_times_per_week,P=!!n?.has_rental_multi_step,A=!!(n?.has_rental_multi_step||n?.has_rental_one_step),I=async()=>{if(!e||!d.activeProductId)return null;b({}),_(null);let t={main_product_id:e.main_product_id,product_id:d.activeProductId,start_date:p.startDate||null,end_date:A?p.endDate||null:p.startDate||null,...S.length>0?{waste_type_id:p.wasteTypeId}:{},...k?{times_per_week:p.timesPerWeek??1}:{},...P?{shift_count:p.shiftCount??1}:{}};try{let s=await w(e.id,t);return s&&r?.(s),s}catch(s){let e=(0,g.getApiErrorItems)(s),t={};for(let s of e)s.attr&&(t[s.attr]=s.detail);return b(t),_(Object.keys(t).length?null:(0,g.getApiErrorMessage)(s,"Something went wrong saving these details.")),null}};return{state:{addOnGroups:d.addOnGroups,effectiveAddOnSelections:d.effectiveAddOnSelections,activeProductId:d.activeProductId,wasteTypes:S,showTimesPerWeek:k,showShiftCount:P,showEndDate:A,fields:p,missingFieldsHint:e?(0,l.missingFieldsSentence)(e.missing_fields):null,isLoading:a.isLoading,isSaving:C,fieldErrors:N,formError:y},actions:{selectAddOnChoice:(e,t)=>d.setAddOnSelections(s=>({...s,[e]:t})),setStartDate:e=>x("startDate",e),setEndDate:e=>x("endDate",e),setWasteTypeId:e=>x("wasteTypeId",e),setTimesPerWeek:e=>x("timesPerWeek",e),setShiftCount:e=>x("shiftCount",e),saveDetails:I},query:{mainProductQuery:a}}}({need:r,surface:n,requestOptions:o,onSaved:m}),N=async()=>{let e=await x.saveDetails();e?.is_pricing_ready&&c&&(c(e),s(!1))},b=async()=>{await x.saveDetails()&&s(!1)};return(0,t.jsx)(ec.Sheet,{open:e,onOpenChange:s,children:(0,t.jsxs)(ec.SheetContent,{side:"right",className:"flex w-full flex-col p-0 sm:max-w-md",children:[(0,t.jsx)(ec.SheetHeader,{className:"px-5 pb-2 pt-5",children:(0,t.jsx)(ec.SheetTitle,{className:"text-base",children:a?`Set details for ${a}`:"Set details"})}),p.isLoading?(0,t.jsx)("div",{className:"flex flex-1 items-center justify-center",children:(0,t.jsx)(en.Loader2,{className:"h-5 w-5 animate-spin text-muted-foreground","aria-hidden":"true"})}):(0,t.jsxs)("div",{className:"flex-1 space-y-5 overflow-y-auto px-5 pb-5",children:[p.addOnGroups.map(e=>(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(ed.Label,{className:"text-sm font-medium text-foreground",children:e.name}),(0,t.jsxs)(eo.Select,{value:p.effectiveAddOnSelections[e.id]??"",onValueChange:t=>x.selectAddOnChoice(e.id,t),children:[(0,t.jsx)(eo.SelectTrigger,{className:"h-10",children:(0,t.jsx)(eo.SelectValue,{})}),(0,t.jsx)(eo.SelectContent,{children:e.choices.map(e=>(0,t.jsx)(eo.SelectItem,{value:e.id,children:e.name},e.id))})]})]},e.id)),p.wasteTypes.length>1?(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(ed.Label,{className:"text-sm font-medium text-foreground",children:"What goes in it?"}),(0,t.jsxs)(eo.Select,{value:p.fields.wasteTypeId??"",onValueChange:e=>x.setWasteTypeId(e),children:[(0,t.jsx)(eo.SelectTrigger,{className:"h-10",children:(0,t.jsx)(eo.SelectValue,{})}),(0,t.jsx)(eo.SelectContent,{children:p.wasteTypes.map(e=>(0,t.jsx)(eo.SelectItem,{value:e.id,children:e.name},e.id))})]}),p.fieldErrors.waste_type_id?(0,t.jsx)("p",{className:"text-xs text-destructive",children:p.fieldErrors.waste_type_id}):null]}):null,(0,t.jsx)(eu.DsDatePicker,{label:p.showEndDate?"Delivery date":"Service date",value:p.fields.startDate,onChange:e=>x.setStartDate(e.target.value),error:p.fieldErrors.start_date}),p.showEndDate?(0,t.jsx)(eu.DsDatePicker,{label:"Pickup date",value:p.fields.endDate,onChange:e=>x.setEndDate(e.target.value),error:p.fieldErrors.end_date}):null,p.showTimesPerWeek?(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(ed.Label,{className:"text-sm font-medium text-foreground",children:"How often?"}),(0,t.jsxs)(eo.Select,{value:String(p.fields.timesPerWeek??1),onValueChange:e=>x.setTimesPerWeek(Number(e)),children:[(0,t.jsx)(eo.SelectTrigger,{className:"h-10",children:(0,t.jsx)(eo.SelectValue,{})}),(0,t.jsx)(eo.SelectContent,{children:ex.map(e=>(0,t.jsx)(eo.SelectItem,{value:e.value,children:e.label},e.value))})]})]}):null,p.showShiftCount?(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(ed.Label,{className:"text-sm font-medium text-foreground",children:"Daily use"}),(0,t.jsxs)(eo.Select,{value:String(p.fields.shiftCount??1),onValueChange:e=>x.setShiftCount(Number(e)),children:[(0,t.jsx)(eo.SelectTrigger,{className:"h-10",children:(0,t.jsx)(eo.SelectValue,{})}),(0,t.jsx)(eo.SelectContent,{children:eh.map(e=>(0,t.jsx)(eo.SelectItem,{value:e.value,children:e.label},e.value))})]})]}):null,p.formError?(0,t.jsx)("p",{className:"text-sm text-destructive",children:p.formError}):null]}),(0,t.jsxs)("div",{className:"space-y-2 border-t border-border px-5 py-4",children:[p.missingFieldsHint?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:p.missingFieldsHint}):null,(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)(d.Button,{variant:"outline",onClick:b,disabled:p.isSaving||!r,children:"Save details"}),c?(0,t.jsx)(d.Button,{onClick:N,disabled:p.isSaving||!r,children:l.PLAN_ACTIONS.compareSuppliers}):null]})]})]})})}var ef=e.i(862147),ej=e.i(849825),ev=e.i(773885),eN=e.i(78577),eb=e.i(978821);e.i(541718);var ey=e.i(14149);e.i(567254);var e_=e.i(62474),ew=e.i(170723);e.i(765095);var eC=e.i(667164);let eS=(0,eC.resolveGeneratedQueryRoot)((0,u.getApiV1OrderGroupsListQueryKey)()),ek=(e,t)=>
2{e.invalidateQueries({predicate:e=>(0,eC.queryKeyIncludes)(e.queryKey,e=>e===eS||"infinite-order-groups"===e)||(0,eC.queryKeyMatchesResource)(e.queryKey,eS,t)})};e.s(["invalidateOrderGroupProjectCaches",0,ek,"writeOrderGroupToProjectCaches",0,(e,t)=>{let s=t?.id;t&&s&&(e.setQueriesData({predicate:e=>(0,eC.queryKeyMatchesResource)(e.queryKey,eS,s)},e=>(0,ey.mergeOrderGroupPreservingExpanded)(e,t)),e.setQueriesData({predicate:e=>(0,eC.queryKeyIncludes)(e.queryKey,e=>e===eS)},e=>(0,eC.mapPaginatedOrInfiniteQueryData)(e,e=>(0,eC.replaceItemInQueryPageData)(e,t,ey.mergeOrderGroupPreservingExpanded))))}],725442);var eP=e.i(225437);function eA({open:e,onOpenChange:s,need:r,supplier:a,surface:n="customer",requestOptions:o,onConverted:c}){let{convertNeed:m,isSubmitting:p}=function(e={}){let t=(0,h.useQueryClient)(),{toast:s}=(0,N.useToast)(),{profile:r}=(0,eP.useEffectiveUser)(),[a,n]=(0,i.useState)(!1);return{convertNeed:(0,i.useCallback)(async i=>{if(a)return{outcome:"failed",message:"Already submitting."};n(!0);let{need:d}=i,o=r?.id??null;try{if(!o||!d.start_date)return{outcome:"failed",message:"This item isn't ready to book yet."};let{addedCount:r,orderGroups:a}=await (0,eb.addAssetToCart)({userId:o,userAddressId:d.user_address_id,sellerProductSellerLocationId:i.sellerProductSellerLocationId,wasteTypeId:d.waste_type_id||null,startDate:d.start_date,endDate:d.end_date??d.start_date,timeSlotId:i.timeSlotId,isDelivery:i.isDelivery,quantity:1,...null!=d.times_per_week?{timesPerWeek:d.times_per_week}:{},...null!=d.shift_count?{shiftCount:d.shift_count}:{},...null!=i.pricingSnapshotToken?{pricingSnapshotToken:i.pricingSnapshotToken}:{}}),n=a[0]??null;if(0===r||!n?.id)return s({title:"Unable to book this",description:"Something went wrong while booking this. Please try again.",variant:"destructive"}),{outcome:"failed",message:"The booking was not created."};(0,ey.addOrderGroupsToOrderGroupListCaches)(t,a),await (0,e_.invalidateAfterCartChange)(t,{userAddressId:d.user_address_id}),ek(t,n.id),(0,v.track)(j.PRODUCT_NEED_CONVERTED,{need_id:d.id,user_address_id:d.user_address_id,main_product_id:d.main_product_id,product_id:d.product_id??null,seller_product_seller_location_id:i.sellerProductSellerLocationId,converted_booking_id:n.id,surface:e.surface??"customer"});try{let r={converted_booking_id:n.id},a=await (0,u.apiV1UserAddressProductNeedsUpdateUpdate)(d.id,r,e.requestOptions);for(let e of((0,f.replaceNeedInCaches)(t,a),(0,R.productNeedPricingKeyPrefixes)(a.id)))t.removeQueries({queryKey:e});return s({title:"Added to cart",description:l.PLAN_TOASTS.converted}),{outcome:"converted",need:a}}catch{return(0,ew.invalidateNeedListQueries)(t,d.user_address_id),s({title:"Added to cart",description:"The booking is in your cart, but this plan item may still show as planned for a moment."}),{outcome:"converted",need:d}}}catch(e){return s({title:"Unable to book this",description:(0,g.getApiErrorMessage)(e,"Something went wrong while booking this. Please try again."),variant:"destructive"}),{outcome:"failed",message:(0,g.getApiErrorMessage)(e,"The booking was not created.")}}finally{n(!1)}},[a,e.requestOptions,e.surface,r?.id,t,s]),isSubmitting:a}}({surface:n,requestOptions:o}),[x,b]=(0,i.useState)(null),[y,_]=(0,i.useState)(!1),w=(0,ev.useTimeSlots)({enabled:e}),C=(0,i.useMemo)(()=>(w.data?.data??[]).map(e=>({id:e.id??"",name:e.name})).filter(e=>e.id),[w.data]),S=(0,i.useMemo)(()=>x&&C.some(e=>e.id===x)?x:C[0]?.id??null,[x,C]),k=(0,i.useMemo)(()=>{if(!a)return null;let e=(0,ej.toSellerProductSellerLocationEntity)(a.spsl);return e.sellerLocationExpanded?.sellerExpanded?.name??e.sellerLocationExpanded?.name??null},[a]),P=!!a?.spsl?.allows_pick_up,A=!P||!y,I=a?.pricing?.total??a?.total??null,E=async()=>{if(!r||!a||!S)return;let e=await m({need:r,sellerProductSellerLocationId:a.id,timeSlotId:S,isDelivery:A,pricingSnapshotToken:a.pricing?.pricing_snapshot_token});"converted"===e.outcome&&(s(!1),c?.(e.need))};return(0,t.jsx)(X.ResponsiveModal,{open:e&&!!(r&&a),onOpenChange:s,title:k?`Book ${k}`:"Book this supplier",children:(0,t.jsxs)("div",{className:"space-y-5 p-1",children:[(0,t.jsxs)("p",{className:"text-sm text-foreground",children:[k??"This supplier"," will handle this and it will be added to your cart."]}
2),(0,t.jsxs)("div",{className:"space-y-1 text-sm text-muted-foreground",children:[null!=I?(0,t.jsxs)("p",{children:["Price: ",(0,t.jsx)("span",{className:"font-semibold text-foreground",children:(0,V.formatCurrency)(I)})]}):null,r?.start_date?(0,t.jsxs)("p",{children:["Starts ",(0,eN.formatAbsoluteAndRelative)(r.start_date)]}):null,r?.end_date&&r.end_date!==r.start_date?(0,t.jsxs)("p",{children:["Ends ",(0,eN.formatAbsoluteAndRelative)(r.end_date)]}):null]}),P?(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(ed.Label,{className:"text-sm font-medium text-foreground",children:"Delivery or pickup?"}),(0,t.jsxs)(eo.Select,{value:A?"delivery":"pickup",onValueChange:e=>_("pickup"===e),children:[(0,t.jsx)(eo.SelectTrigger,{className:"h-10",children:(0,t.jsx)(eo.SelectValue,{})}),(0,t.jsxs)(eo.SelectContent,{children:[(0,t.jsx)(eo.SelectItem,{value:"delivery",children:"Delivered to the project"}),(0,t.jsx)(eo.SelectItem,{value:"pickup",children:"I'll pick it up"})]})]})]}):(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Delivered to the project."}),C.length>0?(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsx)(ed.Label,{className:"text-sm font-medium text-foreground",children:"Arrival window"}),(0,t.jsxs)(eo.Select,{value:S??"",onValueChange:b,children:[(0,t.jsx)(eo.SelectTrigger,{className:"h-10",children:(0,t.jsx)(eo.SelectValue,{})}),(0,t.jsx)(eo.SelectContent,{children:C.map(e=>(0,t.jsx)(eo.SelectItem,{value:e.id,children:e.name},e.id))})]})]}):null,(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)(d.Button,{variant:"ghost",onClick:()=>s(!1),disabled:p,children:l.PLAN_ACTIONS.notYet}),(0,t.jsx)(d.Button,{onClick:E,disabled:p||!r||!a||!S,children:l.PLAN_ACTIONS.addToCart})]})]})})}function eI({open:e,onOpenChange:s,need:r,productName:a,surface:n="customer",requestOptions:d,onConverted:o}){let[c,u]=(0,i.useState)(null),[m,p]=(0,i.useState)(!1),x=q(r,{enabled:e}),h=x.data,g=(h?.recommended.length??0)+(h?.alternatives.length??0),f=(0,i.useRef)(null);(0,i.useEffect)(()=>{if(!e||!r||!h)return;let t=r.id;f.current!==t&&(f.current=t,(0,v.track)(j.PRODUCT_NEED_SUPPLIERS_COMPARED,{need_id:r.id,user_address_id:r.user_address_id,main_product_id:r.main_product_id,product_id:r.product_id??null,supplier_count:g,surface:n}))},[r,e,h,g,n]);let N=e=>{e||(u(null),p(!1),f.current=null),s(e)};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(ec.Sheet,{open:e,onOpenChange:N,children:(0,t.jsxs)(ec.SheetContent,{side:"right",className:"flex w-full flex-col p-0 sm:max-w-xl",children:[(0,t.jsxs)(ec.SheetHeader,{className:"px-5 pb-2 pt-5",children:[(0,t.jsx)(ec.SheetTitle,{className:"text-base",children:a?`Suppliers for ${a}`:"Compare suppliers"}),g>0?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:(0,l.supplierComparisonHeader)(g)}):null]}),(0,t.jsx)("div",{className:"flex-1 overflow-y-auto px-5 pb-5",children:(0,t.jsx)(ef.SupplierResultsList,{recommended:h?.recommended??[],alternatives:h?.alternatives??[],isLoading:x.isLoading,isError:x.isError,pricingLoadingIds:x.pricingLoadingIds,pricingErrorIds:x.pricingErrorIds,selectedSupplierId:c?.id??null,onSelectSupplier:e=>{u(e),p(!0)},action:{label:l.PLAN_ACTIONS.bookSupplier},collapsibleAlternatives:!1,emptyState:(0,t.jsxs)("div",{className:"space-y-1 py-6 text-center",children:[(0,t.jsx)("p",{className:"text-sm text-foreground",children:"No local suppliers can take this yet."}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Try different dates â availability changes often."})]})})})]})}),(0,t.jsx)(eA,{open:m,onOpenChange:p,need:r,supplier:c,surface:n,requestOptions:d,onConverted:e=>{N(!1),o?.(e)}})]})}function eE({project:e,surface:s="customer",requestOptions:r}){let{state:a,actions:o}=p(e.locationId,{requestOptions:r}),{archiveNeed:c,isSubmitting:u}=b({surface:s,requestOptions:r}),[m,h]=(0,i.useState)(!1),[g,f]=(0,i.useState)(!1),[j,v]=(0,i.useState)(null),[N,y]=(0,i.useState)(null),_=a.rows.some(e=>e.groupedNeeds.some(e=>x(e))),w=a.focusedNeedId;if((0,i.useEffect)(()=>{if(!w||a.isLoading)return;let e=document.getElementById(`need-${w}`);e?.scrollIntoView({block:"center"})},[w,a.isLoading]),a.isForbidden)return(0,t.jsx)("section",{className:"px-4 pt-4",children:(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:l.PLAN_NOTICES.noAccess})});if(a.isLoading||a.isError)return null;let C=!!w&&!a.rows.some(e=>e.groupedNeeds.some(e=>e.id===w));return(0,t.jsxs)("section",{"aria-label":"Planned for this project",className:"space-y-4 px-4 pt-4",children:["customer"===s?(0,t.jsx)(el,{}):null,(0,t.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,t.jsx)("p",{className:"text-sm text-foreground",children:(0,l.planContextSentence)(a.activeCount)}
2),a.hasNeeds?(0,t.jsxs)("div",{className:"flex shrink-0 gap-2",children:[_?(0,t.jsx)(d.Button,{variant:"outline",size:"sm",onClick:()=>f(!0),children:"Generate quote"}):null,(0,t.jsx)(d.Button,{variant:"outline",size:"sm",onClick:()=>h(!0),children:l.PLAN_EMPTY_STATE.action})]}):null]}),C?(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:l.PLAN_NOTICES.needMissing}):null,a.hasNeeds?(0,t.jsx)("div",{className:"space-y-3",children:a.rows.map(e=>(0,t.jsx)(H,{row:e,isFocused:e.groupedNeeds.some(e=>e.id===w),surface:s,requestOptions:r,isRemoving:u,onSetDetails:v,onCompareSuppliers:e=>y({need:e.need,productName:e.product?.name??null}),onRemove:e=>void c(e.need)},e.need.id))}):(0,t.jsxs)("div",{className:"space-y-1 rounded-xl border border-border bg-card p-5",children:[(0,t.jsx)("p",{className:"text-sm text-foreground",children:l.PLAN_EMPTY_STATE.absence}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:l.PLAN_EMPTY_STATE.explanation}),(0,t.jsx)(d.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>h(!0),children:l.PLAN_EMPTY_STATE.action})]}),(0,t.jsx)(n.ProjectAddProductDialog,{open:m,onOpenChange:h,project:e,mode:"plan",entrySource:"project_plan_section"}),(0,t.jsx)(es,{open:g,onOpenChange:f,userAddressId:e.locationId,rows:a.rows,surface:s}),(0,t.jsx)(eg,{open:!!j,onOpenChange:e=>{e||v(null)},need:j?.need??null,productName:j?.product?.name??null,surface:s,requestOptions:r,onCompare:e=>{v(null),y({need:e,productName:j?.product?.name??null})}}),(0,t.jsx)(eI,{open:!!N,onOpenChange:e=>{e||y(null)},need:N?.need??null,productName:N?.productName??null,surface:s,requestOptions:r,onConverted:()=>{y(null),o.clearFocusedNeed()}})]})}var eT=e.i(105416);function eD({open:e,onOpenChange:s,need:r,productName:a}){let i=q(r,{enabled:e}),n=i.data?.marketInsights??null,d=n?.insight_level==="EXACT",o=r?(0,l.missingFieldsSentence)(r.missing_fields):null;return(0,t.jsx)(ec.Sheet,{open:e,onOpenChange:s,children:(0,t.jsxs)(ec.SheetContent,{side:"right",className:"flex w-full flex-col p-0 sm:max-w-xl",children:[(0,t.jsxs)(ec.SheetHeader,{className:"px-5 pb-2 pt-5",children:[(0,t.jsx)(ec.SheetTitle,{className:"text-base",children:a?`Pricing for ${a}`:"Pricing preview"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Preview only â the customer chooses their supplier."})]}),(0,t.jsxs)("div",{className:"flex-1 space-y-6 overflow-y-auto px-5 pb-5",children:[n?(0,t.jsx)(K,{insights:n,surface:"crm"}):null,!d&&o?(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:[o," Finish this quote line's configuration to see the supplier comparison the customer will get."]}):null,d?(0,t.jsx)(ef.SupplierResultsList,{recommended:i.data?.recommended??[],alternatives:i.data?.alternatives??[],isLoading:i.isLoading,isError:i.isError,pricingLoadingIds:i.pricingLoadingIds,pricingErrorIds:i.pricingErrorIds,selectedSupplierId:null,onSelectSupplier:()=>{},action:{label:"",disabled:!0},collapsibleAlternatives:!1,emptyState:(0,t.jsx)("p",{className:"py-6 text-center text-sm text-muted-foreground",children:"No local suppliers can take this for these dates."})}):null]})]})})}e.i(162441);let eL={headers:e.i(884653).BypassImpersonationHeader};function eM({project:e}){let{state:s}=p(e.locationId,{requestOptions:eL}),{archiveNeed:r,isSubmitting:a}=b({surface:"crm",requestOptions:eL}),[l,o]=(0,i.useState)(!1),[c,u]=(0,i.useState)(!1),[m,h]=(0,i.useState)(null),[g,f]=(0,i.useState)(null);if(s.isLoading||s.isError)return null;let j=s.activeCount>0?`This quote has ${s.activeCount} product${1===s.activeCount?"":"s"} waiting on the customer's supplier pick.`:"No quote started for this project yet.";return(0,t.jsxs)("section",{"aria-label":"Quote for this project",className:"space-y-4 px-4 pt-4",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-3",children:[(0,t.jsx)("p",{className:"text-sm text-foreground",children:j}),(0,t.jsxs)("div",{className:"flex shrink-0 gap-2",children:[s.rows.some(e=>e.groupedNeeds.some(e=>x(e)))?(0,t.jsx)(d.Button,{variant:"outline",size:"sm",onClick:()=>u(!0),children:"Generate quote"}):null,(0,t.jsx)(d.Button,{variant:"outline",size:"sm",onClick:()=>o(!0),children:"Add to quote"})]})]}),s.hasNeeds?(0,t.jsx)("div",{className:"space-y-3",children:s.rows.map(e=>(0,t.jsx)(H,{row:e,surface:"crm",requestOptions:eL,isRemoving:a,compareLabel:"Preview pricing",requireConfiguredToCompare:!1,onSetDetails:h,onCompareSuppliers:e=>f({need:e.need,productName:e.product?.name??null}),onRemove:e=>void r(e.need)},e.need.id))}):(0,t.jsxs)("div",{className:"space-y-1 rounded-xl border border-border bg-card p-5",children:[(0,t.jsx)("p",{className:"text-sm text-foreground",children:"Build a quote by adding product needs."}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"The customer sees every qualifying supplier with live pricing and picks one themselves."}),(0,t.jsx)(d.Button,{variant:"outline",size:"sm",className:"mt-2",onClick:()=>o(!0),children:"Add to quote"})]}),(0,t.jsx)(n.ProjectAddProductDialog,{open:l,onOpenChange:o,project:e,mode:"plan",entrySource:"crm_quote_workbench",planStep:{surface:"crm",requestOptions:eL,confirmLabel:"Add to quote"}}),(0,t.jsx)(eg,{open:!!m,onOpenChange:e=>{e||h(null)},need:m?.need??null,productName:m?.product?.name??null,surface:"crm",requestOptions:eL}),(0,t.jsx)(eD,{open:!!g,onOpenChange:e=>{e||f(null)},need:g?.need??null,productName:g?.productName??null}),(0,t.jsx)(es,{open:c,onOpenChange:u,userAddressId:e.locationId,rows:s.rows,surface:"crm"})]})}function eO(){return(0,t.jsxs)("div",{className:"min-h-screen bg-background pb-8 lg:-ml-4 lg:pl-4 w-full max-w-full overflow-x-hidden","aria-busy":"true","aria-live":"polite",children:[(0,t.jsx)("div",{className:"bg-card lg:rounded-2xl lg:border lg:border-border w-full max-w-full overflow-x-hidden",children:(0,t.jsxs)("div",{className:"px-4 pb-5 pt-4",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between",children:[(0,t.jsx)("div",{className:"h-10 w-10 rounded-full bg-muted/40 animate-pulse"}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("div",{className:"h-9 w-9 rounded-lg bg-muted/40 animate-pulse"}),(0,t.jsx)("div",{className:"h-9 w-9 rounded-lg bg-muted/40 animate-pulse"})]})]}),(0,t.jsxs)("div",{className:"mt-4 flex items-center gap-3",children:[(0,t.jsx)("div",{className:"h-12 w-12 rounded-lg bg-muted/40 animate-pulse"}),(0,t.jsxs)("div",{className:"min-w-0 flex-1 space-y-2",children:[(0,t.jsx)("div",{className:"h-4 w-2/3 max-w-full rounded-full bg-muted/40 animate-pulse"}),(0,t.jsx)("div",{className:"h-3 w-1/2 max-w-full rounded-full bg-muted/30 animate-pulse"})]})]})]})}),(0,t.jsx)("div",{className:"border-b border-border px-4 py-4",children:(0,t.jsxs)("div",{className:"flex items-start gap-2.5",children:[(0,t.jsx)("div",{className:"h-8 w-8 rounded-lg bg-muted/40 animate-pulse"}),(0,t.jsxs)("div",{className:"min-w-0 flex-1 space-y-2",children:[(0,t.jsx)("div",{className:"h-4 w-3/4 max-w-full rounded-full bg-muted/40 animate-pulse"}),(0,t.jsx)("div",{className:"h-3 w-5/6 max-w-full rounded-full bg-muted/30 animate-pulse"})]})]})}),(0,t.jsx)("div",{className:"sticky top-0 z-20 bg-background",children:(0,t.jsx)("div",{className:"border-b border-border px-4",children:(0,t.jsx)("div",{className:"flex justify-between",children:Array.from({length:4}).map((e,s)=>(0,t.jsxs)("div",{className:"flex flex-col items-center gap-2 px-4 py-3",children:[(0,t.jsx)("div",{className:"h-5 w-5 rounded-full bg-muted/40 animate-pulse"}),(0,t.jsx)("div",{className:"h-3 w-12 rounded-full bg-muted/40 animate-pulse"})]},`tab-skeleton-${s}`))})})}),(0,t.jsx)("div",{className:"px-4 pt-4",children:(0,t.jsx)("div",{className:"grid gap-3",children:Array.from({length:4}).map((e,s)=>(0,t.jsxs)("div",{className:"rounded-2xl border border-border bg-card p-4 shadow-card",children:[(0,t.jsxs)("div",{className:"flex items-center gap-3 animate-pulse",children:[(0,t.jsx)("div",{className:"h-12 w-12 rounded-full bg-muted/40"}),(0,t.jsxs)("div",{className:"flex-1 space-y-2",children:[(0,t.jsx)("div",{className:"h-4 w-2/3 max-w-full rounded-full bg-muted/40"}),(0,t.jsx)("div",{className:"h-3 w-5/6 max-w-full rounded-full bg-muted/30"})]}),(0,t.jsx)("div",{className:"h-6 w-20 max-w-full rounded-full bg-muted/40"})]}),(0,t.jsxs)("div",{className:"mt-3 flex gap-2 animate-pulse",children:[(0,t.jsx)("div",{className:"h-5 w-20 rounded-full bg-muted/30"}),(0,t.jsx)("div",{className:"h-5 w-24 rounded-full bg-muted/30"})]})]},`booking-skeleton-${s}`))})}),(0,t.jsx)("span",{className:"sr-only",children:"Loading project"})]})}var eR=e.i(716327),eU=e.i(77071);e.i(561364);var eq=e.i(927126),eV=e.i(864086);e.i(398106);var eB=e.i(936707),eF=e.i(872339),e$=e.i(621482),ez=e.i(711819),eG=e.i(33286);function eK(e){let t=e.role,s=t&&"object"==typeof t?t:null;return{id:e.id??e.user_id??e.email,name:[e.first_name,e.last_name].filter(
2Boolean).join(" ")||e.email,role:s?.name??"Unassigned",roleKey:s?.key??"unassigned",email:e.email,phone:e.phone??"",status:!1===e.is_active?"disabled":"active",lastActive:e.last_active??"never",createdAt:e.date_joined??""}}function eW({jobSiteId:e}){let[s,r]=(0,i.useState)(""),[a,l]=(0,i.useState)(""),[n,o]=(0,i.useState)("all"),c=a.trim().toLowerCase(),m=(0,e$.useInfiniteQuery)({queryKey:["job-site-users",{jobSiteId:e,search:c,limit:25}],initialPageParam:void 0,queryFn:({pageParam:t,signal:s})=>(0,u.apiV1UsersList)({user_address:e,search:c||void 0,limit:25,starting_after:t,"expand[]":["role"]},void 0,s),getNextPageParam:e=>{if(!e?.has_more)return;let t=e.data??[];return t[t.length-1]?.id??void 0}}),p=(0,i.useMemo)(()=>(m.data?.pages.flatMap(e=>e.data??[])??[]).map(eK),[m.data?.pages]),x=(0,i.useMemo)(()=>Array.from(new Map(p.map(e=>[e.roleKey,e.role])).entries()),[p]),h=(0,i.useMemo)(()=>"all"===n?p:p.filter(e=>e.roleKey===n),[p,n]),g="all"!==n?h.length:m.data?.pages[0]?.count??h.length,f=m.hasNextPage??!1,j=m.isFetchingNextPage,v=(0,eB.useInfiniteScroll)({enabled:!j,hasNextPage:f,isFetchingNextPage:j,onLoadMore:()=>{m.fetchNextPage()}});(0,i.useEffect)(()=>{let e=setTimeout(()=>{l(s)},350);return()=>clearTimeout(e)},[s]);let N=(e,s)=>(0,t.jsx)(ez.default,{user:{name:e.name,email:e.email,status:"active"===e.status?"active":"inactive"},detailHref:(0,I.routeCustomerUserDetail)({userId:e.id}),isMobileCard:s,compact:!0,hideActions:!0,renderPhoneCell:()=>e.phone?(0,eF.formatPhoneNumber)(e.phone):"â",renderRoleCell:()=>e.role},e.id);return(0,t.jsxs)("div",{className:"grid gap-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-1.5 sm:gap-2",children:[(0,t.jsx)(eV.SearchField,{rootClassName:"min-w-0 flex-1",placeholder:"Search users",value:s,onChange:r,className:"h-9 rounded-xl border-0 bg-[rgba(242,242,242,0.8)] text-xs dark:border dark:border-input dark:bg-background sm:h-10"}),(0,t.jsxs)(D.DropdownMenu,{children:[(0,t.jsx)(D.DropdownMenuTrigger,{asChild:!0,children:(0,t.jsxs)(d.Button,{variant:"outline",className:"h-9 flex-shrink-0 rounded-xl flex items-center gap-1.5 px-2.5 sm:h-10 sm:gap-2 sm:px-4",children:[(0,t.jsx)("span",{className:"text-xs font-medium",children:"all"===n?"All Roles":x.find(([e])=>e===n)?.[1]}),(0,t.jsx)(eR.ChevronDown,{className:"h-3.5 w-3.5 text-muted-foreground sm:h-4 sm:w-4","aria-hidden":!0})]})}),(0,t.jsx)(D.DropdownMenuContent,{align:"end",className:"w-48",children:[["all","All Roles"],...x].map(([e,s])=>(0,t.jsx)(D.DropdownMenuItem,{onClick:()=>{o(e)},children:s},e))})]}),(0,t.jsx)(z.TooltipProvider,{delayDuration:150,children:(0,t.jsxs)(z.Tooltip,{children:[(0,t.jsx)(z.TooltipTrigger,{asChild:!0,children:(0,t.jsx)("span",{tabIndex:0,className:"flex-shrink-0",children:(0,t.jsx)(d.Button,{type:"button",variant:"outline",size:"icon",disabled:!0,"aria-label":"Add user",className:"pointer-events-none h-9 w-9 rounded-xl sm:h-10 sm:w-10",children:(0,t.jsx)(eU.Plus,{className:"h-3.5 w-3.5 sm:h-4 sm:w-4"})})})}),(0,t.jsx)(z.TooltipContent,{children:"You don't have permission to add users to this job site."})]})})]}),(0,t.jsx)("div",{className:"@container pb-4",children:m.isLoading?(0,t.jsx)(eG.UsersListSkeleton,{count:6}):0===h.length?(0,t.jsx)("div",{className:"flex-1 flex items-center justify-center py-12",children:(0,t.jsx)("p",{className:"text-muted-foreground text-center",children:"No users found for the selected filters."})}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"hidden @2xl:block border border-border rounded-lg overflow-hidden bg-card",children:(0,t.jsxs)("table",{className:"w-full",children:[(0,t.jsx)("thead",{children:(0,t.jsx)("tr",{className:"border-b border-border bg-muted/30",children:["Full Name","Email address","Phone","Role","Status"].map(e=>(0,t.jsx)("th",{className:"px-2.5 py-3 text-left text-[11px] font-medium text-muted-foreground uppercase tracking-wider",children:e},e))})}),(0,t.jsx)("tbody",{children:h.map(e=>N(e,!1))})]})}),(0,t.jsx)("div",{className:"@2xl:hidden space-y-3",children:h.map(e=>N(e,!0))})]})}),g>25?(0,t.jsx)(eq.InfiniteListContainer,{isLoading:!1,isError:!1,isEmpty:!1,emptyTitle:"",sentinelRef:v,isLoadingMore:j,hasNextPage:f}):null]})}var eQ=e.i(149882),eH=e.i(420865),eJ=e.i(845110),eY=e.i(381515);function eX(e,t,s){let[r,a]=(0,eJ.normalizeDates)(s?.in,e,t),i=eZ(r,a),l=Math.abs((0,eY.differenceInCalendarDays)(r,a));r.setDate(r.getDate()-i*l);let n=Number(eZ(r,a)===-i),d=i*(l-n);return 0===d?0:d}function eZ(e,t){let s=e.getFullYear()-t.getFullYear()||e.getMonth()-t.getMonth()||e.getDate()-t.getDate()||e.getHours()-t.getHours()||e.getMinutes()-t.getMinutes()||e.getSeconds()-t.getSeconds()||e.getMilliseconds()-t.getMilliseconds();return s<0?-1:s>0?1:s}e.s(["differenceInDays",0,eX],209019),e.i(467541);var e0=e.i(675709);function e1(e){let t=new Date,s=e.startDate?new Date(e.startDate):null,r=e.endDate?new Date(e.endDate):null;return e.isArchived?"archived":e.activeOrderGroups>0?"active":s&&r?r<t?"completed":"upcoming":s&&!r?"upcoming":!s&&r?r<t?"completed":"upcoming":"inactive"}function e5({detail:e,isLoading:s=!1}){if(s)return(0,t.jsx)("span",{"aria-label":"Loading project status",className:"inline-flex h-7 w-24 animate-pulse rounded-full border border-border bg-muted"});let r=e1(e),a=function(e){let t=e1(e);if("archived"===t)return"Archived";if("completed"===t)return"Complete";if("active"===t)return"Active";if("inactive"===t)return"Inactive";if(e.startDate){let t=eX(new Date(e.startDate),new Date);return t>0?`in ${t} day${1===t?"":"s"}`:"Soon"}return"Upcoming"}(e),i=function(e){switch(e){case"active":return{bg:"bg-emerald-50 dark:bg-emerald-500/15",text:"text-emerald-700 dark:text-emerald-400",border:"border-emerald-200 dark:border-emerald-500/30"};case"upcoming":return{bg:"bg-amber-50 dark:bg-amber-500/15",text:"text-amber-700 dark:text-amber-400",border:"border-amber-200 dark:border-amber-500/30"};case"completed":return{bg:"bg-red-50 dark:bg-red-500/15",text:"text-red-700 dark:text-red-400",border:"border-red-200 dark:border-red-500/30"};default:return{bg:"bg-muted",text:"text-muted-foreground",border:"border-border"}}}(r);return(0,t.jsx)("span",{className:`inline-flex items-center rounded-full border px-3 py-1 text-xs font-semibold uppercase tracking-wide ${i.bg} ${i.text} ${i.border}`,children:a})}
2function e2({detail:e,data:s,backHref:r,isStatusLoading:a=!1,onBack:i,headerActions:l}){let n,d,o=(n=e.startDate?(0,w.parseISO)(e.startDate):void 0,d=e.endDate?(0,w.parseISO)(e.endDate):void 0,n&&d?`${(0,_.format)(n,"MMM d")} â ${(0,_.format)(d,"MMM d, yyyy")}`:n?`From ${(0,_.format)(n,"MMM d, yyyy")}`:d?`Until ${(0,_.format)(d,"MMM d, yyyy")}`:null);return(0,t.jsx)("div",{className:"bg-card text-foreground",children:(0,t.jsxs)("div",{className:"px-4 pb-4 pt-3",children:[(0,t.jsxs)("div",{className:"mt-3 flex flex-wrap items-center gap-2",children:[(0,t.jsx)("h1",{className:"text-2xl font-bold leading-tight text-foreground",children:e.name}),l?(0,t.jsx)("div",{className:"ml-auto shrink-0",children:l}):null]}),e.formattedAddress?(0,t.jsxs)("div",{className:"mt-2 flex items-center gap-1.5 text-sm text-muted-foreground",children:[(0,t.jsx)(eH.MapPin,{className:"h-4 w-4 shrink-0 text-primary"}),(0,t.jsx)("span",{className:"truncate",children:e.formattedAddress})]}):null,o?(0,t.jsxs)("div",{className:"mt-1.5 flex items-center gap-1.5 text-sm text-muted-foreground",children:[(0,t.jsx)(eQ.Calendar,{className:"h-4 w-4 shrink-0 text-primary"}),(0,t.jsx)("span",{children:o})]}):null,(0,t.jsx)("div",{className:"mt-3",children:(0,t.jsx)(e5,{detail:e,isLoading:a})})]})})}var e4=e.i(226091),e3=e.i(166794),e6=e.i(899738),e7=e.i(882303);let e8=[{id:"checkout",label:"Checkout",icon:e6.ShoppingCart},{id:"invoices",label:"Invoices",icon:e4.FileText},{id:"users",label:"Users",icon:e7.Users},{id:"settings",label:"Settings",icon:e3.Settings}];function e9({activeTab:e,onChange:s,showUsers:r=!0}){let a=[...e8].filter(e=>r||"users"!==e.id);return(0,t.jsx)("div",{className:"sticky top-0 z-20 bg-card",children:(0,t.jsx)("div",{className:"border-b border-border px-4",children:(0,t.jsx)("div",{className:"flex",children:a.map(r=>{let a=r.icon,i=e===r.id;return(0,t.jsxs)("button",{type:"button",onClick:()=>s(r.id),className:`relative flex flex-1 flex-col items-center gap-0.5 py-3 transition-colors sm:gap-1 ${i?"text-primary":"text-muted-foreground"}`,children:[(0,t.jsx)(a,{className:"h-4 w-4"}),(0,t.jsx)("span",{className:"text-xs font-medium",children:r.label}),i?(0,t.jsx)("div",{className:"absolute bottom-0 left-0 right-0 h-0.5 bg-primary"}):null]},r.id)})})})})}var te=e.i(129768),tt=e.i(971136),ts=e.i(576248),tr=e.i(729210),ta=e.i(573474);let ti=(0,e.i(456420).default)("type",[["path",{d:"M12 4v16",key:"1654pz"}],["path",{d:"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2",key:"e0r10z"}],["path",{d:"M9 20h6",key:"s66wpe"}]]);var tl=e.i(901279);e.i(152758);let tn="exempt";var td=e.i(581847),to=e.i(324804),tc=e.i(705075),tu=e.i(362474),tm=e.i(715638),tp=e.i(645636),tx=e.i(435613),th=e.i(308574),tg=e.i(78135),tf=e.i(220624),tj=e.i(35695),tv=e.i(3321),tN=e.i(401754);function tb(e){return"object"==typeof e&&null!==e&&"id"in e}function ty(e,t){return!!t&&(e.id===t||e.user_id===t)}function t_({detail:e,data:s,ownershipSlot:r,isSavingProjectSettings:a,isArchivingProject:l,isUnarchivingProject:n,archiveProjectDisabledReason:o=null,archiveProjectWarning:c=null,addressEditDisabledReason:m=null,onSaveJobSiteFields:p,onArchiveProject:x,onUnarchiveProject:h,onRefreshJobSiteDetail:g}){var f;let j,N=(0,i.useRef)(null),b=(0,i.useRef)(null),y=(0,i.useRef)(!0),[w,C]=(0,i.useState)(!1),S={street:s.street??"",city:s.city??"",state:s.state??"",postalCode:s.postal_code??""},[P,A]=(0,i.useState)((0,eN.toDateOnly)(e.startDate)??void 0),[I,E]=(0,i.useState)((0,eN.toDateOnly)(e.endDate)??void 0),[T,D]=(0,i.useState)(e.name??""),[L,M]=(0,i.useState)(e.projectId??""),[O,R]=(0,i.useState)(!1),[U,q]=(0,i.useState)(e.description??e.notes??""),[V,B]=(0,i.useState)(e.userAddressType??""),[F,$]=(0,i.useState)(!1),[G,K]=(0,i.useState)(!1),Q=(0,i.useMemo)(()=>Array.isArray(s.users)?s.users.filter(tb):[],[s.users]),H=(0,i.useMemo)(()=>{let e=Q.find(e=>ty(e,s.on_site_contact??null));return e?.id??s.on_site_contact??null},[Q,s.on_site_contact]),[J,Y]=(0,i.useState)(!1),[X,Z]=(0,i.useState)(!1),[ee,et]=(0,i.useState)(S.street),[es,er]=(0,i.useState)([]),[ea,ei]=(0,i.useState)(!1),[el,ec]=(0,i.useState)(S),[eu,em]=(0,i.useState)({}),[ep,ex]=(0,i.useState)(!1),[eh,eg]=(0,i.useState)(""),[ef,ej]=(0,i.useState)(!1),[ev,eb]=(0,i.useState)(!!s.allow_saturday_delivery),[ey,e_]=(0,i.useState)(!!s.allow_sunday_delivery),[ew,eC]=(0,i.useState)(s.access_details??""),[eS,ek]=(0,i.useState)(H),[eP,eA]=(0,i.useState)(H);eS!==H&&(ek(H),eA(e=>e===eS?H:e));let eI=!!o,eE=!!m,eT=function(){let{isAuthenticated:e}=(0,td.useAuthUser)();return(0,u.useApiV1UserAddressTypesList)({limit:100},{query:{enabled:e,staleTime:1/0,gcTime:1/0}})}(),eD=eT.data?.data??[],eL=(0,i.useMemo)(()=>Q.find(e=>ty(e,eP)),[Q,eP]),eM=(0,i.useMemo)(()=>Q.find(e=>ty(e,s.on_site_contact??null)),[Q,s.on_site_contact]);(0,i.useEffect)(()=>{let e=!1;return(0,tc.ensureGooglePlacesLoaded)().then(()=>{e||C(!0)}).catch(()=>{}),()=>{e=!0}},[]),(0,i.useEffect)(()=>
2{w&&!N.current&&window.google?.maps?.places&&(N.current=new window.google.maps.places.AutocompleteService)},[w]),(0,i.useEffect)(()=>{if(!J)return;if(y.current){y.current=!1;return}if(!ee.trim()||!N.current)return;let e=setTimeout(()=>{N.current?.getPlacePredictions({input:ee,componentRestrictions:{country:"us"},types:["address"]},(e,t)=>{if(t===window.google?.maps?.places?.PlacesServiceStatus.OK&&e){let t=e.map(e=>{let t=e.structured_formatting?.main_text||"",[s,r]=(e.structured_formatting?.secondary_text||"").split(",").map(e=>e.trim());return{address:t,city:s||"",state:r?.split(" ")[0]||"",zip:r?.split(" ")[1]||"",placeId:e.place_id}});er(t),ei(t.length>0);return}er([]),ei(!1)})},300);return()=>clearTimeout(e)},[ee,J]);let eO=(0,i.useCallback)(()=>{let e={street:s.street??"",city:s.city??"",state:s.state??"",postalCode:s.postal_code??""};ec(e),et(e.street),em({}),er([]),ei(!1),y.current=!0},[s.city,s.postal_code,s.state,s.street]),eR=(0,i.useCallback)(async e=>{let t,s;if(!e.placeId)return e;try{await (0,tc.ensureGooglePlacesLoaded)()}catch{return e}if(!b.current&&window.google?.maps?.places&&(b.current=new window.google.maps.places.PlacesService(document.createElement("div"))),!b.current)return e;let r=await new Promise(t=>{b.current?.getDetails({placeId:e.placeId??"",fields:["address_components"]},(e,s)=>{t(s===window.google?.maps?.places?.PlacesServiceStatus.OK&&e?e:null)})});return r?(t=r.address_components||[],{address:[(s=(e,s="long_name")=>t.find(t=>t.types?.includes(e))?.[s]||"")("street_number"),s("route")].filter(Boolean).join(" ")||e.address,city:s("locality")||s("sublocality")||s("administrative_area_level_2")||e.city,state:s("administrative_area_level_1","short_name")||s("administrative_area_level_1")||e.state,zip:s("postal_code")||e.zip,placeId:e.placeId}):e},[]),eU=e=>{p(e)},eq=t=>{(0,v.track)(tu.BUTTON_CLICKED,{page:"project_settings",action:t,project_id:e.id})},eV=!!s.allow_saturday_delivery,eB=!!s.allow_sunday_delivery,eF=(s.access_details??"").trim(),e$=H!==eP||eV!==ev||eB!==ey||eF!==ew.trim(),ez=(0,i.useCallback)(()=>{eA(H),eb(!!s.allow_saturday_delivery),e_(!!s.allow_sunday_delivery),eC(s.access_details??"")},[s.access_details,s.allow_saturday_delivery,s.allow_sunday_delivery,H]),eG=async()=>{await p({on_site_contact:eP,allow_saturday_delivery:ev,allow_sunday_delivery:ey,access_details:ew.trim()||null})&&(ej(!1),eq("delivery_preferences_saved"))},eK=async()=>{await g()},eW=async()=>{let e=U.trim();await p({description:e||null})&&(q(e),Z(!1),eq("project_description_saved"))},eQ=async e=>{await p({tax_exempt_status:e?tn:"none"})&&eq(e?"project_tax_exempt_enabled":"project_tax_exempt_disabled")},eJ=async e=>{let t=await eR(e),s=t.zip.replace(/\D/g,"").slice(0,5);y.current=!0,et(t.address),er([]),ei(!1),ec(e=>({...e,street:t.address,city:t.city,state:t.state,postalCode:s||e.postalCode})),em(e=>({...e,street:void 0,city:void 0,state:void 0,postalCode:void 0}))},eY=async()=>{eI||await x()&&(ex(!1),eg(""),eq("project_archived"))},eX=async()=>{await h()&&eq("project_unarchived")},eZ=async()=>{let e;if(!eE&&(e={},el.street.trim()||(e.street="Street address is required."),el.city.trim()||(e.city="City is required."),el.state.trim()||(e.state="State is required."),el.postalCode.trim()?/^\d{5}
2$/.test(el.postalCode.trim())||(e.postalCode="ZIP must be 5 digits."):e.postalCode="ZIP code is required.",em(e),0!==Object.keys(e).length))return;let t={street:eE?S.street:el.street.trim(),city:eE?S.city:el.city.trim(),state:eE?S.state:el.state.trim(),postalCode:eE?S.postalCode:el.postalCode.trim()};ec(t),et(t.street);let s=L.trim()||null;await p({name:T.trim()||null,project_id:s,...O?{invoice_update_scope:"all"}:{},...!eE?{street:t.street,city:t.city,state:t.state,postal_code:t.postalCode}:{}})&&(R(!1),Y(!1),em({}),eq("project_details_updated"))};return(0,t.jsxs)("div",{className:"px-4 py-4 space-y-4",children:[(0,t.jsx)(tx.Card,{children:(0,t.jsxs)(tx.CardContent,{className:"p-4",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"rounded-lg bg-primary/10 p-2 text-primary",children:(0,t.jsx)(e4.FileText,{className:"h-4 w-4"})}),(0,t.jsx)("p",{className:"text-xs font-semibold text-foreground/70 uppercase tracking-wide",children:"Project Details"})]}),!J&&(0,t.jsx)("button",{type:"button",className:"group/edit p-1.5 rounded-md text-muted-foreground transition-colors hover:bg-primary hover:text-white",onClick:()=>{Y(!0),D(e.name??""),M(e.projectId??""),R(!1),eO()},children:(0,t.jsx)(k.Pencil,{className:"h-4 w-4 transition-colors group-hover/edit:text-white"})})]}),J?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(ti,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Project Name"})]}),(0,t.jsx)(tg.Input,{value:T,onChange:e=>D(e.target.value),placeholder:"Enter project name",className:"h-10"})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(e4.FileText,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Project Type"})]}),(0,t.jsxs)(eo.Select,{value:V,onValueChange:e=>{B(e),eU({user_address_type:e||null})},children:[(0,t.jsx)(eo.SelectTrigger,{className:"h-10",disabled:eT.isLoading,children:(0,t.jsx)(eo.SelectValue,{placeholder:"Select type"})}),(0,t.jsx)(eo.SelectContent,{children:eD.map(e=>(0,t.jsx)(eo.SelectItem,{value:e.id,children:e.name},e.id))})]})]})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mt-6",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(tt.Hash,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"PO Number"})]}),(0,t.jsx)(tg.Input,{value:L,onChange:e=>M(e.target.value),placeholder:"e.g. PO-1234",maxLength:50,className:"h-10"}),(0,t.jsxs)("div",{className:"flex items-start gap-2 px-0 py-1 text-xs text-muted-foreground",children:[(0,t.jsx)(th.Checkbox,{id:"project-po-historical-invoices",checked:O,onCheckedChange:e=>R(!0===e),disabled:a,className:"mt-0.5"}),(0,t.jsx)(ed.Label,{htmlFor:"project-po-historical-invoices",className:"text-xs font-normal leading-5 text-muted-foreground",children:"Also update past invoices"}),(0,t.jsx)(z.TooltipProvider,{delayDuration:100,children:(0,t.jsxs)(z.Tooltip,{children:[(0,t.jsx)(z.TooltipTrigger,{asChild:!0,children:(0,t.jsx)("button",{type:"button","aria-label":"Explain historical invoice updates",className:"mt-0.5 rounded-full text-muted-foreground hover:text-foreground",children:(0,t.jsx)(ts.HelpCircle,{className:"h-4 w-4"})})}),(0,t.jsx)(z.TooltipContent,{side:"top",align:"end",className:"max-w-64 text-xs leading-5",children:"Updates local grouped invoices for this project when those invoices do not have product-specific POs. Existing Stripe invoices are not changed."})]})})]})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(te.CalendarDays,{className:"h-3.5 w-3.5 text-muted-foreground
2/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Project Timeline"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2 sm:gap-3",children:[(0,t.jsxs)(tj.Popover,{open:F,onOpenChange:$,children:[(0,t.jsx)(tj.PopoverTrigger,{asChild:!0,children:(0,t.jsxs)(d.Button,{type:"button",variant:"outline",className:`h-10 min-w-0 flex-1 justify-start text-left font-normal ${!P?"text-muted-foreground":""}`,children:[(0,t.jsx)(te.CalendarDays,{className:"mr-2 h-4 w-4 shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:P?(0,_.format)(P,"MMM d, yyyy"):"Start"})]})}),(0,t.jsx)(tj.PopoverContent,{className:"w-auto p-0",align:"start",children:(0,t.jsx)(tp.Calendar,{mode:"single",selected:P,onSelect:e=>{A(e),$(!1),e&&I&&I<e&&E(void 0),eU({estimated_start_date:e?(0,_.format)(e,"yyyy-MM-dd"):null})},initialFocus:!0})})]}),(0,t.jsx)("span",{className:"shrink-0 text-sm text-muted-foreground",children:"to"}),(0,t.jsxs)(tj.Popover,{open:G,onOpenChange:K,children:[(0,t.jsx)(tj.PopoverTrigger,{asChild:!0,children:(0,t.jsxs)(d.Button,{type:"button",variant:"outline",className:`h-10 min-w-0 flex-1 justify-start text-left font-normal ${!I?"text-muted-foreground":""}`,children:[(0,t.jsx)(te.CalendarDays,{className:"mr-2 h-4 w-4 shrink-0"}),(0,t.jsx)("span",{className:"truncate",children:I?(0,_.format)(I,"MMM d, yyyy"):"End"})]})}),(0,t.jsx)(tj.PopoverContent,{className:"w-auto p-0",align:"start",children:(0,t.jsx)(tp.Calendar,{mode:"single",selected:I,onSelect:e=>{E(e),K(!1),eU({estimated_end_date:e?(0,_.format)(e,"yyyy-MM-dd"):null})},disabled:e=>!!P&&e<P,initialFocus:!0})})]})]})]})]}),(0,t.jsxs)("div",{className:"space-y-2 mt-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(eH.MapPin,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Project Address"})]}),(0,t.jsxs)("div",{className:"space-y-4",children:[(0,t.jsxs)("div",{className:"relative",children:[(0,t.jsx)(tg.Input,{id:"project-address-street",placeholder:"Search for address...",value:ee,onChange:e=>{let t=e.target.value;y.current=!1,et(t),ec(e=>({...e,street:t})),t.trim()||(er([]),ei(!1))},onFocus:()=>{es.length>0&&ei(!0)},onBlur:()=>setTimeout(()=>ei(!1),180),className:eu.street?"border-destructive":"",autoComplete:"off",disabled:eE}),ea&&es.length>0?(0,t.jsx)("div",{className:"absolute z-50 mt-1 max-h-48 w-full overflow-y-auto rounded-xl border border-border bg-background shadow-lg",children:es.map((e,s)=>(0,t.jsxs)("button",{type:"button",onMouseDown:t=>{t.preventDefault(),eJ(e)},className:"flex w-full items-center gap-2 px-4 py-3 text-left text-sm transition-colors hover:bg-muted",children:[(0,t.jsx)(eH.MapPin,{className:"h-3.5 w-3.5 flex-shrink-0 text-muted-foreground","aria-hidden":!0}),(0,t.jsxs)("span",{children:[e.address,", ",e.city,", ",e.state," ",e.zip]})]},`${e.address}-${s}`))}):null]}),eu.street?(0,t.jsx)("p",{className:"text-xs text-destructive",children:eu.street}):null,(0,t.jsxs)("div",{className:"grid grid-cols-1 sm:grid-cols-[1fr_auto_auto] gap-3",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(tg.Input,{id:"project-address-city",placeholder:"City",value:el.city,onChange:e=>ec(t=>({...t,city:e.target.value})),className:eu.city?"border-destructive":"",disabled:eE}),eu.city?(0,t.jsx)("p",{className:"text-xs text-destructive",children:eu.city}):null]}),(0,t.jsxs)("div",{className:"space-y-2 sm:w-24",children:[(0,t.jsxs)(eo.Select,{value:el.state,disabled:eE,onValueChange:e=>ec(t=>({...t,state:e})),children:[(0,t.jsx)(eo.SelectTrigger,{id:"project-address-state",className:eu.state?"border-destructive":"",children:(0,t.jsx)(eo.SelectValue,{placeholder:"ST"})}),(0,t.jsx)(eo.SelectContent,{children:to.US_STATES.map(e=>(0,t.jsx)(eo.SelectItem,{value:e.value,children:e.value},e.value))})]}),eu.state?(0,t.jsx)("p",{className:"text-xs text-destructive",children:eu.state}):null]}),(0,t.jsxs)("div",{className:"space-y-2 sm:w-28",children:[(0,t.jsx)(tg.Input,{id:"project-address-zip",placeholder:"ZIP",value:el.postalCode,onChange:e=>{let t=e.target.value.replace(/\D/g,"").slice(0,5);ec(e=>({...e,postalCode:t}))},maxLength:5,inputMode:"numeric",className:eu.postalCode?"border-destructive":"",disabled:eE}),eu.postalCode?(0,t.jsx)("p",{className:"text-xs text-destructive",children:eu.postalCode}):null]})]}),m?(0,t.jsx)("p",{className:"text-xs text-muted-foreground",role:"status",children:m}):null]})]}),(0,t.jsx)("div",{className:"flex justify-center md:justify-end mt-6",children:(0,t.jsxs)("div",{className:"flex w-full flex-col gap-2 md:w-auto md:flex-row",children:[(0,t.jsx)(d.Button,{variant:"outline",onClick:()=>{Y(!1),D(e.name??""),M(e.projectId??""),R(!1),eO()},disabled:a,size:"sm",className:"w-full md:w-auto",children:"Cancel"}),(0,t.jsx)(d.Button,{onClick:eZ,disabled:a,size:"sm",className:"w-full md:w-auto",children:a?"Saving...":"Save"})]})})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(ti,{className:"h-3.5 w-3.5 text-muted-foreground
2/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Project Name"})]}),(0,t.jsx)("p",{className:"text-sm text-foreground",children:T||"Untitled Project"})]}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(e4.FileText,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Project Type"})]}),(0,t.jsx)("p",{className:"text-sm text-foreground",children:eD.find(e=>e.id===V)?.name||"Not set"})]})]}),(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6 mt-5",children:[(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(tt.Hash,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"PO Number"})]}),(0,t.jsx)("p",{className:"text-sm text-foreground",children:L||(0,t.jsx)("span",{className:"text-muted-foreground",children:"Not set"})})]}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(te.CalendarDays,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Project Timeline"})]}),(0,t.jsx)("p",{className:"text-sm text-foreground",children:P||I?(0,t.jsxs)(t.Fragment,{children:[P?(0,_.format)(P,"MMM d, yyyy"):"Not set"," â ",I?(0,_.format)(I,"MMM d, yyyy"):"Not set"]}):(0,t.jsx)("span",{className:"text-muted-foreground",children:"Not set"})})]})]}),(0,t.jsxs)("div",{className:"space-y-1.5 mt-5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(eH.MapPin,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Project Address"})]}),(0,t.jsx)("p",{className:"text-sm text-foreground",children:(f=e.formattedAddress,(j=[el.street,el.city,el.state,el.postalCode].map(e=>e.trim()).filter(Boolean)).length>0?j.join(", "):f||"No address set")})]})]})]})}),r,(0,t.jsx)(tx.Card,{children:(0,t.jsx)(tx.CardContent,{className:"p-4",children:(0,t.jsxs)("div",{className:"flex items-center justify-between gap-4",children:[(0,t.jsxs)("div",{className:"flex items-start gap-3",children:[(0,t.jsx)("span",{className:"rounded-lg bg-primary/10 p-2 text-primary",children:(0,t.jsx)(tr.Landmark,{className:"h-4 w-4"})}),(0,t.jsxs)("div",{className:"space-y-1",children:[(0,t.jsx)(ed.Label,{htmlFor:"project-tax-exempt",className:"text-sm font-medium",children:"Tax exempt"}),(0,t.jsx)("p",{className:"text-xs text-muted-foreground",children:"Do not apply sales tax to eligible orders for this project."})]})]}),(0,t.jsx)(tN.Switch,{id:"project-tax-exempt","aria-label":"Tax exempt",checked:s.tax_exempt_status===tn,disabled:a,onCheckedChange:e=>void eQ(e)})]})})}),(0,t.jsx)(tx.Card,{children:(0,t.jsxs)(tx.CardContent,{className:"p-4",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"rounded-lg bg-primary/10 p-2 text-primary",children:(0,t.jsx)(e4.FileText,{className:"h-4 w-4"})}),(0,t.jsx)("p",{className:"text-xs font-semibold text-foreground/70 uppercase tracking-wide",children:"Description"})]}),!X&&(0,t.jsx)("button",{type:"button",className:"group/edit p-1.5 rounded-md text-muted-foreground transition-colors hover:bg-primary hover:text-white",onClick:()=>{q(e.description??e.notes??""),Z(!0),eq("project_description_edit_opened")},children:(0,t.jsx)(k.Pencil,{className:"h-4 w-4 transition-colors group-hover/edit:text-white"})})]}),X?(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsx)(tv.Textarea,{value:U,onChange:e=>q(e.target.value),placeholder:"Enter project description",className:"min-h-[100px]",autoF
2ocus:!0}),(0,t.jsxs)("div",{className:"flex justify-end gap-2",children:[(0,t.jsx)(d.Button,{variant:"ghost",size:"sm",onClick:()=>{q(e.description??e.notes??""),Z(!1),eq("project_description_edit_cancelled")},disabled:a,children:"Cancel"}),(0,t.jsx)(d.Button,{size:"sm",onClick:eW,disabled:a,children:a?"Saving...":"Save"})]})]}):(0,t.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:U||(0,t.jsx)("span",{className:"text-muted-foreground",children:"No description provided"})})]})}),(0,t.jsx)(tx.Card,{children:(0,t.jsxs)(tx.CardContent,{className:"p-4",children:[(0,t.jsxs)("div",{className:"flex items-center justify-between mb-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"rounded-lg bg-primary/10 p-2 text-primary",children:(0,t.jsx)(W.Truck,{className:"h-4 w-4"})}),(0,t.jsx)("p",{className:"text-xs font-semibold text-foreground/70 uppercase tracking-wide",children:"Delivery Preferences"})]}),ef?null:(0,t.jsx)("button",{type:"button",className:"group/edit p-1.5 rounded-md text-muted-foreground transition-colors hover:bg-primary hover:text-white",onClick:()=>{ez(),ej(!0),eq("delivery_preferences_edit_opened")},children:(0,t.jsx)(k.Pencil,{className:"h-4 w-4 transition-colors group-hover/edit:text-white"})})]}),ef?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(tl.User,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"On-Site Contact"})]}),(0,t.jsx)(tm.DeliveryContactSelect,{size:"contact-card",value:eP,selectedContact:eL,contacts:Q,requirePhone:!0,disabled:a,onChange:e=>eA(e),onContactAdded:eK,onContactUpdated:eK})]}),(0,t.jsxs)("div",{className:"space-y-2",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(te.CalendarDays,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Weekend Deliveries"})]}),(0,t.jsxs)("div",{className:"flex flex-row items-center gap-6 h-10",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(th.Checkbox,{id:"delivery-saturday",checked:ev,onCheckedChange:e=>eb(!!e),disabled:a}),(0,t.jsx)(ed.Label,{htmlFor:"delivery-saturday",className:"text-sm text-foreground cursor-pointer",children:"Saturday"})]}),(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(th.Checkbox,{id:"delivery-sunday",checked:ey,onCheckedChange:e=>e_(!!e),disabled:a}),(0,t.jsx)(ed.Label,{htmlFor:"delivery-sunday",className:"text-sm text-foreground cursor-pointer",children:"Sunday"})]})]})]})]}),(0,t.jsxs)("div",{className:"space-y-2 mt-6",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(e4.FileText,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Access Details"})]}),(0,t.jsx)(tv.Textarea,{placeholder:"Gate codes, parking instructions, etc.",value:ew,onChange:e=>eC(e.target.value),className:"min-h-[80px] resize-none text-sm",disabled:a})]}),(0,t.jsx)("div",{className:"flex justify-center md:justify-end mt-6",children:(0,t.jsxs)("div",{className:"flex w-full flex-col gap-2 md:w-auto md:flex-row",children:[(0,t.jsx)(d.Button,{variant:"outline",onClick:()=>{ez(),ej(!1),eq("delivery_preferences_cancelled")},disabled:a,size:"sm",className:"w-full md:w-auto",children:"Cancel"}),(0,t.jsx)(d.Button,{onClick:eG,disabled:a||!e$,size:"sm",className:"w-full md:w-auto",children:a?"Saving...":"Save"})]})})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(tl.User,{className:"h-3.5 w-3.5 text-muted-foreground
2/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"On-Site Contact"})]}),(0,t.jsx)("p",{className:"text-sm text-foreground",children:eM?[eM.first_name,eM.last_name].filter(Boolean).join(" ").trim()||eM.email||"Unknown contact":"Not set"})]}),(0,t.jsxs)("div",{className:"space-y-1.5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(te.CalendarDays,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Weekend Deliveries"})]}),(0,t.jsx)("p",{className:"text-sm text-foreground",children:eV||eB?[eV?"Saturday":null,eB?"Sunday":null].filter(Boolean).join(", "):"Not allowed"})]})]}),(0,t.jsxs)("div",{className:"space-y-1.5 mt-5",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)(e4.FileText,{className:"h-3.5 w-3.5 text-muted-foreground/70 shrink-0",strokeWidth:1.5}),(0,t.jsx)("p",{className:"text-[10px] font-normal text-muted-foreground uppercase tracking-wide",children:"Access Details"})]}),(0,t.jsx)("p",{className:"text-sm text-foreground whitespace-pre-wrap",children:eF||(0,t.jsx)("span",{className:"text-muted-foreground",children:"No access details"})})]})]})]})}),(0,t.jsx)(tx.Card,{className:"border-destructive/30 bg-destructive/5",children:(0,t.jsxs)(tx.CardContent,{className:"p-4",children:[(0,t.jsxs)("div",{className:"flex items-start justify-between gap-3 mb-3",children:[(0,t.jsxs)("div",{className:"flex items-center gap-2",children:[(0,t.jsx)("span",{className:"rounded-lg bg-destructive/10 p-2 text-destructive",children:(0,t.jsx)(ta.Trash2,{className:"h-4 w-4"})}),(0,t.jsx)("p",{className:"text-xs font-semibold text-destructive uppercase tracking-wide",children:"Danger Zone"})]}),e.isArchived?(0,t.jsx)(d.Button,{variant:"outline",size:"sm",className:"shrink-0",disabled:n||a,onClick:()=>{eX()},children:n?"Unarchiving...":"Unarchive Project"}):(0,t.jsx)(d.Button,{variant:"destructive",size:"sm",className:"shrink-0",disabled:l||a||eI,onClick:()=>{eI||(ex(!0),eg(""),eq("project_archive_modal_opened"))},children:"Archive Project"})]}),(0,t.jsxs)("p",{className:"text-sm text-muted-foreground",children:["Archiving a project will hide it from your active projects list. This action can be undone.",o?(0,t.jsx)("span",{className:"mt-1 block text-destructive",children:o}):null,c?(0,t.jsx)("span",{className:"mt-1 block text-amber-700",children:c}):null]})]})}),(0,t.jsx)(tf.Dialog,{open:ep,onOpenChange:e=>{ex(e),e||(eg(""),eq("project_archive_modal_closed"))},children:(0,t.jsxs)(tf.DialogContent,{className:"max-w-md",children:[(0,t.jsxs)(tf.DialogHeader,{children:[(0,t.jsx)(tf.DialogTitle,{children:"Archive Project"}),(0,t.jsxs)("p",{className:"mt-2 text-sm text-muted-foreground",children:["This will hide the project from active project lists. Type"," ",(0,t.jsx)("span",{className:"font-semibold text-destructive",children:"ARCHIVE"})," to confirm."]}),c?(0,t.jsx)("p",{className:"mt-2 text-sm font-medium text-amber-700",children:c}):null]}),(0,t.jsx)(tg.Input,{value:eh,onChange:e=>eg(e.target.value),placeholder:"Type ARCHIVE",className:"mt-2"}),(0,t.jsxs)("div",{className:"mt-4 flex gap-3",children:[(0,t.jsx)(d.Button,{variant:"outline",className:"flex-1",onClick:()=>{ex(!1),eg(""),eq("project_archive_cancelled")},disabled:l,children:"Cancel"}),(0,t.jsx)(d.Button,{variant:"destructive",className:"flex-1",onClick:()=>{eY()},disabled:"ARCHIVE"!==eh||l||eI,children:l?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(en.Loader2,{className:"mr-2 h-4 w-4 animate-spin"}),"Archiving..."]}):"Archive"})]})]})})]})}let tw=["PENDING","SCHEDULED"];function tC(e){return(e?.count??e?.data?.length??0)>0}let tS=(0,eC.resolveGeneratedQueryRoot)((0,u.getApiV1UserAddressesListQueryKey)()),tk=(e,t)=>(0,eC.mergePreservingExpandedValues)(e,t),tP=(e,t)=>{let s=t?.id;t&&s&&(e.setQueriesData({predicate:e=>(0,eC.queryKeyMatchesResource)(e.queryKey,tS,s)},e=>tk(e,t)),e.getQueryCache().findAll({predicate:e=>(0,eC.queryKeyIncludes)(e.queryKey,e=>e===tS)}
2).forEach(r=>{e.setQueryData(r.queryKey,e=>(0,eC.mapPaginatedOrInfiniteQueryData)(e,e=>{var a;let i,l,n;return(a=r.queryKey,!(n=(i=[],(l=e=>{Array.isArray(e)&&e.forEach((t,s)=>{if(t===tS){let t=e[s+1];(0,eC.isRecord)(t)&&i.push(t)}l(t)})})(a),i).filter(e=>"boolean"==typeof e.is_archived).map(e=>e.is_archived)).length||n.some(e=>!!t.is_archived===e))?(0,eC.replaceItemInQueryPageData)(e,t,tk):(0,eC.removeItemFromQueryPageData)(e,s)}))}))},tA=(e,t)=>{e.invalidateQueries({predicate:e=>(0,eC.queryKeyIncludes)(e.queryKey,e=>e===tS||"infinite-user-addresses"===e)||(0,eC.queryKeyMatchesResource)(e.queryKey,tS,t)})};e.s(["invalidateUserAddressProjectCaches",0,tA,"writeUserAddressToProjectCaches",0,tP],162107),e.i(298820);let tI=eT.PROJECT_NEEDS_ENABLED?["plan","checkout","invoices","users","settings"]:["checkout","invoices","users","settings"];var tE=e.i(189299);e.s(["default",0,function({jobSiteId:e,onBack:l,backHref:n=(0,I.routeCustomerHome)(),initialTab:d,syncTabToUrl:c,renderSettingsOwnership:m,headerActions:p,checkoutVariant:x="default"}){let{state:f,query:j,actions:v}=function(e,t={}){let s,r,a=(0,h.useQueryClient)(),{toast:l}=(0,N.useToast)(),n=(0,o.useRouter)(),d=(0,o.usePathname)(),c=(0,o.useSearchParams)(),{initialTab:m="checkout",syncTabToUrl:p=!0}=t,x=c.get("tab"),f=p&&x&&tI.includes(x)?x:null,[j,v]=(0,i.useState)(()=>f??m),{detail:b,isLoading:y,isError:_,data:w}=(s=(0,u.useApiV1UserAddressesRetrieve)(e??"",{"expand[]":["users"]}),r=(0,i.useMemo)(()=>{var e;let t,r,a;if(!s.data)return null;let i=(e=s.data,{id:(t=(0,e0.toUserAddressEntity)(e)).id,name:t.name||"Unnamed Location",formattedAddress:[[t.street,t.street2].filter(Boolean).join(", "),t.city,t.state,t.postal_code].filter(Boolean).join(", "),city:t.city,state:t.state,postalCode:t.postal_code,country:t.country,latitude:t.latitude||0,longitude:t.longitude||0,activeOrderGroups:t.onSiteBookingIconUrls.length,pastOrderGroups:0,mainProducts:(r=(0,e0.toUserAddressEntity)(t),a=new Map,r.onSiteBookingIconUrls.forEach(e=>{let t,s,r,i,l=(t=(e.split("/").pop()||"").replace(/\.(png|jpg|jpeg|svg)$/i,""),i=(r=Object.keys(s={blue:{accent:"#1e40af",bg:"#dbeafe"},green:{accent:"#047857",bg:"#d1fae5"},red:{accent:"#dc2626",bg:"#fee2e2"},yellow:{accent:"#ca8a04",bg:"#fef3c7"},purple:{accent:"#7c3aed",bg:"#ede9fe"},gray:{accent:"#4b5563",bg:"#f3f4f6"}}).find(e=>t.toLowerCase().includes(e)))?s[r]:{accent:"#6b7280",bg:"#f3f4f6"},{id:t||e,url:e,name:t||"Product",accentColor:i.accent,backgroundColor:i.bg}),n=a.get(l.id);n?n.count+=1:a.set(l.id,{product:l,count:1})}),Array.from(a.values())),isArchived:t.is_archived??!1,startDate:t.estimated_start_date||void 0,endDate:t.estimated_end_date||void 0,userGroupId:t.userGroupId??null,defaultPaymentMethodId:t.default_payment_method??null,projectId:t.project_id??null,description:t.description??null,userAddressType:t.user_address_type??null,allowSaturdayDelivery:t.allow_saturday_delivery??void 0,allowSundayDelivery:t.allow_sunday_delivery??void 0}),l=(0,e0.toUserAddressEntity)(s.data),n=l.on_site_contact,d=l.usersExpanded??[];return{...i,activeOrderGroups:0,pastOrderGroups:0,timezone:"UTC",primaryContact:n??"Primary contact",notes:l.access_details??"",bookings:[],invoices:[],users:d}}
2,[s.data]),{...s,isLoading:s.isLoading,isError:s.isError,detail:r}),C=(0,u.useApiV1OrderGroupsList)({user_address:e?[e]:void 0,active:!0,exclude_lost:!0,limit:1,fields:"id"},{query:{enabled:!!e,staleTime:3e4}}),S=(0,u.useApiV1InvoicesList)({user_address:e??"",status:[u.ApiV1InvoicesListStatusItem.open],paid:!1,limit:1,fields:"id"},{query:{enabled:!!e,staleTime:3e4}}),k=(0,u.useApiV1OrderGroupsList)({user_address:e?[e]:void 0,is_not_submitted:!0,include_not_submitted:!0,exclude_lost:!0,limit:1,fields:"id"},{query:{enabled:!!e,staleTime:3e4}}),P=(0,u.useApiV1OrdersList)({user_address:e??"",status:[...tw],limit:1,fields:"id"},{query:{enabled:!!e&&"settings"===j}}),A=(0,u.useApiV1UserAddressesUpdate)(),I=(0,u.useApiV1UserAddressesUpdate)(),E=(0,u.useApiV1UserAddressesUpdate)(),T=tC(C.data),D=tC(S.data),L=tC(k.data),M=(0,i.useMemo)(()=>b?{...b,activeOrderGroups:+!!T}:null,[T,b]),O=(0,i.useMemo)(()=>(function({isLoading:e,isError:t,hasActiveOrderGroups:s,hasUnpaidInvoices:r}){return e?"Project status is still loading. Wait a moment before archiving this project.":t?"Project status could not be verified. Refresh before archiving this project.":s||r?"Archive is unavailable while this project has active bookings or unpaid invoices.":null})({isLoading:C.isLoading||S.isLoading,isError:C.isError||S.isError,hasActiveOrderGroups:T,hasUnpaidInvoices:D}),[T,C.isError,C.isLoading,D,S.isError,S.isLoading]),R=function({isLoading:e,isError:t,hasPendingOrScheduledOrders:s}){return e?"Address availability is still loading. Wait a moment before editing this address.":t?"Address availability could not be verified. Refresh before editing this address.":s?"The project address cannot be changed while orders are pending or scheduled.":null}({isLoading:P.isLoading,isError:P.isError,hasPendingOrScheduledOrders:tC(P.data)}),U=async()=>{b?.id&&await a.invalidateQueries({queryKey:(0,u.getApiV1UserAddressesRetrieveQueryKey)(b.id)})},q=async e=>{if(!b?.id||!w)return!1;try{return await A.mutateAsync({id:b.id,data:e}),U(),l({title:"Changes saved",description:"Your project settings have been updated."}),!0}catch(e){return l({title:"Save failed",description:(0,g.getApiErrorMessage)(e,"Unable to save changes right now. Please try again."),variant:"destructive"}),!1}},V=async e=>{if(!b?.id||!w)return!1;let t=e?I:E;try{let s=await t.mutateAsync({id:b.id,data:{is_archived:e}});return tP(a,s),tA(a,s.id),l({title:e?"Project archived":"Project unarchived",description:e?"This project is now hidden from active projects.":"This project is now active again."}),!0}catch(t){return l({title:e?"Archive failed":"Unarchive failed",description:(0,g.getApiErrorMessage)(t,e?"Unable to archive this project right now. Please try again.":"Unable to unarchive this project right now. Please try again."),variant:"destructive"}),!1}},B=async()=>V(!0),F=async()=>V(!1),$=async()=>{await U()};
2return{state:{detail:M,jobSiteApiData:w,resolvedActiveTab:j,archiveProjectDisabledReason:O,archiveProjectWarning:L?"This project has an open cart. Archiving the project will delete the cart.":null,addressEditDisabledReason:R},query:{isJobSiteLoading:y,isError:_,isStatusLoading:C.isLoading||S.isLoading||k.isLoading,isSavingProjectSettings:A.isPending,isArchivingProject:I.isPending,isUnarchivingProject:E.isPending},actions:{setActiveTab:e=>{if(v(e),!p)return;let t=new URLSearchParams(c.toString());t.set("tab",e);let s=t.toString();n.replace(s?`${d}?${s}`:d,{scroll:!1})},saveJobSiteFields:q,archiveProject:B,unarchiveProject:F,refreshJobSiteDetail:$}}}(e,{initialTab:d,syncTabToUrl:c});if(j.isJobSiteLoading)return(0,t.jsx)("section",{className:"grid content-start gap-4 px-4 pb-6 pt-4",children:(0,t.jsx)(eO,{})});if(j.isError)return(0,t.jsx)("section",{className:"grid content-start gap-4 px-4 pb-6 pt-4",children:(0,t.jsxs)("div",{className:"rounded-2xl border border-border bg-white p-4 shadow-sm",children:[(0,t.jsx)("h3",{className:"text-lg font-semibold",children:"Job site unavailable"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"Unable to load project details."}),(0,t.jsx)(s.default,{href:n,className:"mt-2 inline-flex items-center justify-center rounded-full border border-primary bg-white px-3 py-2 text-sm font-semibold text-primary transition hover:bg-emerald-50",children:"Back to Job Sites"})]})});if(!f.detail)return(0,t.jsx)("section",{className:"grid content-start gap-4 px-4 pb-6 pt-4",children:(0,t.jsxs)("div",{className:"rounded-2xl border border-border bg-white p-4 shadow-sm",children:[(0,t.jsx)("h3",{className:"text-lg font-semibold",children:"Project not found"}),(0,t.jsx)("p",{className:"text-sm text-muted-foreground",children:"The requested project does not exist in fixtures."}),(0,t.jsx)(s.default,{href:n,className:"mt-2 inline-flex items-center justify-center rounded-full border border-primary bg-white px-3 py-2 text-sm font-semibold text-primary transition hover:bg-emerald-50",children:"Back to Projects"})]})});let b=(0,t.jsx)(a.default,{userAddressIds:[f.detail.id],embedded:!0,variant:x,projectContexts:{[f.detail.id]:{locationId:f.detail.id,name:f.detail.name,latitude:f.detail.latitude,longitude:f.detail.longitude,estimatedStartDate:f.detail.startDate,estimatedEndDate:f.detail.endDate,ownerUserId:"crm"===x?f.jobSiteApiData?.user:void 0}}}),y=f.detail.userGroupId||"users"!==f.resolvedActiveTab?f.resolvedActiveTab:"checkout";return(0,t.jsxs)("section",{className:"min-h-screen bg-card pb-8 w-full max-w-full overflow-x-clip",children:[(0,t.jsx)(e2,{detail:f.detail,data:f.jobSiteApiData,backHref:n,isStatusLoading:j.isStatusLoading,onBack:l,headerActions:p}),(0,t.jsx)(e9,{activeTab:y,onChange:v.setActiveTab,showUsers:!!f.detail.userGroupId}),"plan"===y&&eT.PROJECT_NEEDS_ENABLED?"crm"===x?(0,t.jsx)(eM,{project:{locationId:f.detail.id,name:f.detail.name,latitude:f.detail.latitude,longitude:f.detail.longitude,estimatedStartDate:f.detail.startDate,estimatedEndDate:f.detail.endDate}}):(0,t.jsx)(eE,{project:{locationId:f.detail.id,name:f.detail.name,latitude:f.detail.latitude,longitude:f.detail.longitude,estimatedStartDate:f.detail.startDate,estimatedEndDate:f.detail.endDate}}):"checkout"!==y&&("plan"!==y||eT.PROJECT_NEEDS_ENABLED)?"invoices"===y?(0,t.jsx)(r.default,{jobSiteId:f.detail.id}):"settings"===y?(0,t.jsx)(t_,{detail:f.detail,data:f.jobSiteApiData,ownershipSlot:m?.({userGroupId:f.detail.userGroupId??null}),isSavingProjectSettings:j.isSavingProjectSettings,isArchivingProject:j.isArchivingProject,isUnarchivingProject:j.isUnarchivingProject,archiveProjectDisabledReason:f.archiveProjectDisabledReason,archiveProjectWarning:f.archiveProjectWarning,addressEditDisabledReason:f.addressEditDisabledReason,onSaveJobSiteFields:v.saveJobSiteFields,onArchiveProject:v.archiveProject,onUnarchiveProject:v.unarchiveProject,onRefreshJobSiteDetail:v.refreshJobSiteDetail}):(0,t.jsx)("div",{className:"px-4 pt-4",children:"users"===y?(0,t.jsx)(eW,{jobSiteId:f.detail.id}):null}):"crm"===x?(0,t.jsx)(tE.EffectiveUserGroupOverrideProvider,{userGroupId:f.detail.userGroupId,children:b}):b]})}],715332)}]); 3 4//# debugId=c7afdd9f-25e3-9e37-d341-6aaf0c136a18
5//# chunkId=c7afdd9f-25e3-9e37-d341-6aaf0c136a18
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.