1import{r as x,j as e}from"./vendor-react-DKbe1Umz.js";import{b6 as L,a as I,B as f,r as g,l as h,aF as P,bg as O,u as q,q as B,o as N,D as z,Z as F,c as M,d as R,e as W,f as $,L as w,S as y,g as b,h as v,i as T,j as k,n as U}from"./index-DZ74KeH3.js";import{u as E,a as K}from"./vendor-data-CjSe2wkl.js";import{T as V}from"./TakeoffWorkspace-DVeiaop8.js";import{W as A}from"./WidgetErrorBoundary-DX-KzBV8.js";import{c0 as j,F as S,c1 as D,E as G,dr as Q,bH as C,Z as H,_ as Z}from"./vendor-ui-DMaW9-Ov.js";import"./vendor-charts-DWX9qznF.js";import"./vendor-dates-5UNeOyFW.js";import"./vendor-forms-C2vWC2ab.js";import"./crm-upgrade-Cd4-EfZp.js";import"./AiEstimatorIntroCallout-DY79Krw5.js";import"./alert-dialog-CA9oB9-z.js";import"./checkbox-B-BhVsyi.js";import"./vendor-canvas-CU4anwGL.js";import"./DimInputCursorBadge-DlSbQafz.js";import"./CostCodeCombobox-BEUxBMgG.js";import"./tradeTypeUtils-Cur7Goun.js";import"./use-job-progress-B6X7C-Y5.js";import"./JobProgressBar-h5Xy0LNS.js";import"./table-CAeITjOT.js";import"./radio-group-NU-uess9.js";import"./ObjectUploader-BErHjEh8.js";import"./vendor-xlsx-CuKvrqns.js";function _({takeoffId:r}){const{data:c=[]}=P(),{data:o=[]}=O(),{toast:m}=q(),[t,n]=x.useState(!1),[i,u]=x.useState("bid"),[p,a]=x.useState(""),s=K({mutationFn:async d=>(await N("POST",`/api/takeoff/standalone/${r}/tags`,d)).json(),onSuccess:()=>{m({title:"Takeoff tagged",description:"This takeoff now appears in the destination's Suggested Takeoffs."}),B.invalidateQueries({queryKey:["/api/takeoff/standalone",r,"tags"]}),n(!1),a("")},onError:()=>m({title:"Tag failed",variant:"destructive"})});return e.jsxs(z,{open:t,onOpenChange:n,children:[e.jsx(F,{asChild:!0,children:e.jsxs(f,{size:"sm",variant:"outline",className:"h-8 gap-1 px-2 sm:px-3 shrink-0","data-testid":"button-tag-takeoff-workspace",children:[e.jsx(Q,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Tag"})]})}),e.jsxs(M,{"data-testid":"dialog-tag-takeoff-workspace",children:[e.jsxs(R,{children:[e.jsx(W,{children:"Tag this takeoff"}),e.jsx($,{children:"Linking attaches the takeoff to a bid or project â it will appear in their Suggested Takeoffs and can be sent to their estimate."})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(w,{children:"Destination type"}),e.jsxs(y,{value:i,onValueChange:d=>{u(d==="project"?"project":"bid"),a("")},children:[e.jsx(b,{"data-testid":"select-workspace-dest-kind",children:e.jsx(v,{})}),e.jsxs(T,{children:[e.jsx(k,{value:"bid",children:"Bid"}),e.jsx(k,{value:"project",children:"Project"})]})]})]}),e.jsxs("div",{children:[e.jsx(w,{children:i==="bid"?"Bid":"Project"}),e.jsxs(y,{value:p,onValueChange:a,children:[e.jsx(b,{"data-testid":"select-workspace-dest-id",children:e.jsx(v,{placeholder:"Select..."})}),e.jsx(T,{children:(i==="bid"?c:o).map(d=>{const l=d;return e.jsx(k,{value:l.id,children:l.name||l.code||l.id},l.id)})})]})]})]}),e.jsx(U,{children:e.jsx(f,{onClick:()=>s.mutate(i==="bid"?{bidId:p}:{projectId:p}),disabled:!p||s.isPending,"data-testid":"button-confirm-tag-workspace",children:s.isPending?e.jsx(j,{className:"w-4 h-4 animate-spin"}):"Tag"})})]})]})}function we(){const[,r]=L("/takeoff/standalone/:id/workspace"),[c]=I(),o=(r==null?void 0:r.id)??"",m=E({queryKey:["/api/takeoff/standalone",o],enabled:!!o}),t=x.useMemo(()=>{const i=typeof window>"u"?"":window.location.search;if(!i)return null;const u=new URLSearchParams(i).get("sheet");return u&&u.length>0?u:null},[c]);if(x.useEffect(()=>{if(!(!o||!t))try{sessionStorage.setItem(`takeoff-sheet-standalone-${o}`,t)}catch{}},[o,t]),!o)return e.jsx("div",{className:"flex items-center justify-center h-full p-8","data-testid":"standalone-workspace-missing-id",children:e.jsx("p",{className:"text-muted-foreground",children:"No takeoff id in URL."})});if(m.isLoading)return e.jsx("div",{className:"flex items-center justify-center h-full","data-testid":"standalone-workspace-loading",children:e.jsx(j,{className:"h-8 w-8 animate-spin text-muted-foreground"})});const n=m.data;return n?e.jsxs("div",{className:"flex flex-col h-[calc(100vh-3.5rem)] min-h-0","data-testid":"standalone-workspace-page",children:[e.jsxs("div",{className:"flex items-center gap-2 sm:gap-3 px-2 sm:px-4 py-2 border-b bg-muted/20 shrink-0",children:[e.jsx(f,{asChild:!0,size:"sm",variant:"ghost",className:"h-8 gap-1 px-2 shrink-0","data-testid":"button-back-to-standalone-detail",children:e.jsxs(g,{href:`/takeoff/standalone/${n.id}`,children:[e.jsx(D,{className:"w-4 h-4"}),"Takeoff"]})}),e.jsx("div",{className:"h-5 w-px bg-border shrink-0"}),e.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[e.jsx(S,{className:"w-4 h-4 text-muted-foreground shrink-0 hidden sm:inline-flex"}),e.jsx("span",{className:"font-semibold text-sm truncate min-w-0","data-testid":"text-standalone-workspace-title",children:n.title}),n.tradeType&&e.jsx(h,{variant:"outline",className:"text-[10px] uppercase tracking-wide shrink-0",children:n.tradeType}),e.jsx(h,{variant:"secondary",className:"text-[10px] shrink-0 hidden sm:inline-flex",children:"Standalone"})]}),e.jsx(_,{takeoffId:n.id}),e.jsx(f,{asChild:!0,size:"sm",variant:"outline",className:"h-8 gap-1 px-2 sm:px-3 shrink-0","data-testid":"button-open-standalone-detail",children:e.jsxs(g,{href:`/takeoff/standalone/${n.id}`,children:[e.jsx(G,{className:"w-3.5 h-3.5"}),e.jsx("span",{className:"hidden sm:inline",children:"Open Detail"})]})})]}),e.jsx("div",{className:"flex-1 min-h-0 overflow-hidden",children:e.jsx(A,{fallbackTitle:"Takeoff Workspace",children:e.jsx(V,{context:{type:"standalone",standaloneTakeoffId:n.id,standaloneTitle:n.title},fullscreenScaleModal:!0,unifiedRibbon:!0})})}),e.jsx(J,{takeoffId:n.id})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center h-full gap-4 p-8","data-testid":"standalone-workspace-not-found",children:[e.jsx(S,{className:"h-12 w-12 text-muted-foreground
1/40"}),e.jsxs("div",{className:"text-center",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Takeoff not found"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"The standalone takeoff you tried to open doesn't exist or you don't have access."})]}),e.jsx(f,{asChild:!0,variant:"outline","data-testid":"button-back-to-takeoff-index",children:e.jsxs(g,{href:"/takeoff",children:[e.jsx(D,{className:"w-4 h-4 mr-2"}),"Back to Takeoffs"]})})]})}function J({takeoffId:r}){const[c,o]=x.useState(!1),m=E({queryKey:["/api/takeoff/standalone",r,"scope"],queryFn:async()=>(await N("GET",`/api/takeoff/standalone/${r}/scope`)).json(),enabled:c,refetchInterval:a=>{const s=a.state.data;return s?s.status==="PROCESSING"?4e3:!1:4e3}}),t=m.data,n=(t==null?void 0:t.status)==="PROCESSING"||!t&&c&&m.isLoading,i=x.useMemo(()=>{var a;return(a=t==null?void 0:t.items)!=null&&a.length?t.items.reduce((s,d)=>{const l=d.csiDivision||"Uncategorized";return s[l]||(s[l]=[]),s[l].push(d),s},{}):{}},[t==null?void 0:t.items]),u=x.useMemo(()=>Object.keys(i).sort((a,s)=>a==="Uncategorized"?1:s==="Uncategorized"?-1:a.localeCompare(s)),[i]),p=async()=>{try{const a=await N("GET",`/api/takeoff/standalone/${r}/scope-document`),{url:s}=await a.json();s&&window.open(s,"_blank")}catch{}};return e.jsxs("div",{className:"border-t bg-background shrink-0","data-testid":"scope-of-work-panel",children:[e.jsxs("button",{className:"w-full flex items-center justify-between px-4 py-2 text-sm font-medium hover:bg-muted/40 transition-colors",onClick:()=>o(a=>!a),"data-testid":"button-toggle-scope-panel",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(C,{className:"w-4 h-4 text-muted-foreground"}),e.jsx("span",{children:"Scope of Work"}),(t==null?void 0:t.status)==="COMPLETED"&&t.items.length>0&&e.jsxs(h,{variant:"secondary",className:"text-[10px]",children:[t.items.length," items"]}),n&&e.jsxs(h,{variant:"outline",className:"text-[10px] gap-1",children:[e.jsx(j,{className:"w-2.5 h-2.5 animate-spin"}),"Analyzingâ¦"]})]}),c?e.jsx(H,{className:"w-4 h-4 text-muted-foreground"}):e.jsx(Z,{className:"w-4 h-4 text-muted-foreground"})]}),c&&e.jsxs("div",{className:"px-4 pb-4 max-h-72 overflow-y-auto","data-testid":"scope-panel-content",children:[n&&e.jsxs("div",{className:"flex items-center gap-2 py-4 text-sm text-muted-foreground",children:[e.jsx(j,{className:"w-4 h-4 animate-spin"}),"AI is extracting the scope of work from your plansâ¦"]}),!n&&(t==null?void 0:t.status)==="FAILED"&&e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Scope analysis failed. Import a plan to retry automatically."}),!n&&(!(t!=null&&t.status)||t.status===null)&&e.jsx("p",{className:"text-sm text-muted-foreground py-4",children:"Import a plan to automatically extract the scope of work."}),!n&&(t==null?void 0:t.status)==="COMPLETED"&&e.jsxs(e.Fragment,{children:[t.hasScopeDocument&&e.jsx("div",{className:"flex justify-end mb-3",children:e.jsxs(f,{size:"sm",variant:"outline",className:"h-7 gap-1 text-xs",onClick:p,"data-testid":"button-view-scope-document-panel",children:[e.jsx(C,{className:"w-3.5 h-3.5"}),"View Scope Document"]})}),u.length===0?e.jsx("p",{className:"text-sm text-muted-foreground py-2",children:"No scope items extracted."}):e.jsx("div",{className:"space-y-3",children:u.map(a=>e.jsxs("div",{"data-testid":`scope-division-${a}`,children:[e.jsx("p",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-1",children:a}),e.jsx("ul",{className:"space-y-0.5 pl-2",children:i[a].map((s,d)=>e.jsxs("li",{className:"text-sm flex items-start gap-1.5",children:[e.jsx("span",{className:"text-muted-foreground mt-0.5",children:"â¢"}),e.jsxs("span",{children:[s.description,s.quantity!=null&&e.jsxs("span",{className:"text-muted-foreground ml-1 text-xs",children:["(",s.quantity," ",s.unit||"LS",")"]})]})]},d))})]},a))})]})]})]})}export{we as default};
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.