@metron-labs/quote-react 0.1.35 → 0.1.37
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/QuickQuote.js +8 -2
- package/dist/embed/quote.js +2 -2
- package/package.json +1 -1
package/dist/embed/quote.js
CHANGED
|
@@ -6772,7 +6772,7 @@ Error generating stack: `+r.message+`
|
|
|
6772
6772
|
width: 100%;
|
|
6773
6773
|
height: 100%;
|
|
6774
6774
|
}
|
|
6775
|
-
`;var He=Y(Ke());var js={};function Kb(e){js=e}function pr(){return js}function nd(){return!!js.apiBaseUrl}var U1=e=>e.replace(/\/$/,"");function Lt(e){let t=js.apiBaseUrl;return t?`${U1(t)}${e.replace(/^\/api\//,"/v1/")}`:e}var Sn=Y(Ke());var D1="metron:step",B1="metron_step",Zo=(0,Sn.createContext)(()=>{}),Cn=()=>(0,Sn.useContext)(Zo);function Gs(e,t){return(0,Sn.useCallback)((a,r={})=>{let n=pr(),i=n.analytics??"all";if(i==="none")return;let o={...r,widget:e,step:a};t.current?.dispatchEvent(new CustomEvent(D1,{detail:o,bubbles:!0,composed:!0})),n.onEvent?.(o);let l=window.dataLayer;i==="all"&&Array.isArray(l)&&l.push({event:B1,...o})},[e,t])}var Pb="boq-session-id",Jb="x-boq-session";function Fb(){if(typeof window>"u")return"server";try{let e=window.localStorage.getItem(Pb);return e||(e=crypto.randomUUID(),window.localStorage.setItem(Pb,e)),e}catch{return crypto.randomUUID()}}var O1="x-boq-client";function Qs(){return pr().client}function Ga(){let{client:e,apiKey:t}=pr();return nd()?t?{Authorization:`Bearer ${t}`}:{}:e?{[O1]:e}:{}}function wi(){return{...nd()?{}:{[Jb]:Fb()},...Ga()}}function L1(e){return e&&typeof e=="object"&&e.success===!0&&"data"in e?e.data:e}async function Kt(e){return L1(await e.json().catch(()=>({})))}var Ib=9e4;async function Wb(e,t){let a=new AbortController,r=setTimeout(()=>a.abort(),Ib),n;try{n=await fetch(e,{...t,signal:a.signal})}catch(o){throw o?.name==="AbortError"?new Error(`Request to ${e} timed out after ${Ib/1e3}s. Please try again.`):o}finally{clearTimeout(r)}let i=await Kt(n);if(!n.ok||i?.error){let o=i;throw new Error(o.detail??o.message??o.error??`Server error ${n.status}`)}return i}function ev(e,t,a=!0){let r=new FormData;return r.append("file",e),t?.length&&r.append("provided_lines_json",JSON.stringify(t)),a||r.append("archive_source","false"),Wb(Lt("/api/schedule"),{method:"POST",body:r,headers:wi()})}function tv(e,t){let a=t?`?account=${encodeURIComponent(t)}`:"";return Wb(Lt(`/api/schedule/${e}${a}`),{headers:Ga()})}function av(e,t,a,r){let n=!1,i=null,o=performance.now();return{promise:new Promise((p,f)=>{let b=async()=>{if(!n)try{let d=await e();if(n)return;if(d.status==="completed"||d.status==="failed"){console.log(`[pollJob:${r??"job"}] ${d.status} (${Math.round(performance.now()-o)}ms)`),p(d);return}a?.(),i=setTimeout(b,t)}catch(d){n||f(d)}};i=setTimeout(b,t)}),cancel:()=>{n=!0,i&&(clearTimeout(i),i=null)}}}var ua=Y(Ke());var rv=new URL("../assets/decking/boards/diagonal.webp",import.meta.url).href;var iv=new URL("../assets/decking/boards/no-border.webp",import.meta.url).href;var nv=new URL("../assets/decking/boards/picture-frame.webp",import.meta.url).href;var ov=new URL("../assets/decking/boards/straight.webp",import.meta.url).href;var lv=new URL("../assets/fencing/gates/no-gate.webp",import.meta.url).href;var sv=new URL("../assets/fencing/gates/single-gate.webp",import.meta.url).href;var cv=new URL("../assets/fencing/gravel-board.webp",import.meta.url).href;var uv=new URL("../assets/fencing/height/0.9.webp",import.meta.url).href;var pv=new URL("../assets/fencing/height/1.2.webp",import.meta.url).href;var dv=new URL("../assets/fencing/height/1.5.webp",import.meta.url).href;var mv=new URL("../assets/fencing/height/1.8.webp",import.meta.url).href;var fv=new URL("../assets/fencing/no-gravel-board.webp",import.meta.url).href;var gv=new URL("../assets/quick-order/paste-list.webp",import.meta.url).href;var hv=new URL("../assets/quick-order/photo-list.webp",import.meta.url).href;var bv=new URL("../assets/quick-order/upload-file.webp",import.meta.url).href;var vv=new URL("../assets/schedule-products/building-sand.webp",import.meta.url).href;var wv=new URL("../assets/schedule-products/drywall-screws.webp",import.meta.url).href;var yv=new URL("../assets/schedule-products/loft-insulation-roll.webp",import.meta.url).href;var _v=new URL("../assets/schedule-products/red-multi-stock-bricks.webp",import.meta.url).href;var xv=new URL("../assets/schedule-products/scrim-tape.webp",import.meta.url).href;var kv=new URL("../assets/schedule-products/wall-ties.webp",import.meta.url).href;var Nv=new URL("../assets/tool-images/architrave.webp",import.meta.url).href;var Sv=new URL("../assets/tool-images/brick-block.webp",import.meta.url).href;var Cv=new URL("../assets/tool-images/concrete-aggregate.webp",import.meta.url).href;var qv=new URL("../assets/tool-images/decking.webp",import.meta.url).href;var Ev=new URL("../assets/tool-images/fencing.webp",import.meta.url).href;var Mv=new URL("../assets/tool-images/insulation.webp",import.meta.url).href;var Tv=new URL("../assets/tool-images/paint.webp",import.meta.url).href;var zv=new URL("../assets/tool-images/paving.webp",import.meta.url).href;var Av=new URL("../assets/tool-images/plasterboard.webp",import.meta.url).href;var Rv=new URL("../assets/tool-images/skirting.webp",import.meta.url).href;var Uv=new URL("../assets/tool-images/timber.webp",import.meta.url).href;var Dv=new URL("../assets/tool-images/truss.webp",import.meta.url).href;var
|
|
6775
|
+
`;var He=Y(Ke());var js={};function Kb(e){js=e}function pr(){return js}function nd(){return!!js.apiBaseUrl}var U1=e=>e.replace(/\/$/,"");function Lt(e){let t=js.apiBaseUrl;return t?`${U1(t)}${e.replace(/^\/api\//,"/v1/")}`:e}var Sn=Y(Ke());var D1="metron:step",B1="metron_step",Zo=(0,Sn.createContext)(()=>{}),Cn=()=>(0,Sn.useContext)(Zo);function Gs(e,t){return(0,Sn.useCallback)((a,r={})=>{let n=pr(),i=n.analytics??"all";if(i==="none")return;let o={...r,widget:e,step:a};t.current?.dispatchEvent(new CustomEvent(D1,{detail:o,bubbles:!0,composed:!0})),n.onEvent?.(o);let l=window.dataLayer;i==="all"&&Array.isArray(l)&&l.push({event:B1,...o})},[e,t])}var Pb="boq-session-id",Jb="x-boq-session";function Fb(){if(typeof window>"u")return"server";try{let e=window.localStorage.getItem(Pb);return e||(e=crypto.randomUUID(),window.localStorage.setItem(Pb,e)),e}catch{return crypto.randomUUID()}}var O1="x-boq-client";function Qs(){return pr().client}function Ga(){let{client:e,apiKey:t}=pr();return nd()?t?{Authorization:`Bearer ${t}`}:{}:e?{[O1]:e}:{}}function wi(){return{...nd()?{}:{[Jb]:Fb()},...Ga()}}function L1(e){return e&&typeof e=="object"&&e.success===!0&&"data"in e?e.data:e}async function Kt(e){return L1(await e.json().catch(()=>({})))}var Ib=9e4;async function Wb(e,t){let a=new AbortController,r=setTimeout(()=>a.abort(),Ib),n;try{n=await fetch(e,{...t,signal:a.signal})}catch(o){throw o?.name==="AbortError"?new Error(`Request to ${e} timed out after ${Ib/1e3}s. Please try again.`):o}finally{clearTimeout(r)}let i=await Kt(n);if(!n.ok||i?.error){let o=i;throw new Error(o.detail??o.message??o.error??`Server error ${n.status}`)}return i}function ev(e,t,a=!0){let r=new FormData;return r.append("file",e),t?.length&&r.append("provided_lines_json",JSON.stringify(t)),a||r.append("archive_source","false"),Wb(Lt("/api/schedule"),{method:"POST",body:r,headers:wi()})}function tv(e,t){let a=t?`?account=${encodeURIComponent(t)}`:"";return Wb(Lt(`/api/schedule/${e}${a}`),{headers:Ga()})}function av(e,t,a,r){let n=!1,i=null,o=performance.now();return{promise:new Promise((p,f)=>{let b=async()=>{if(!n)try{let d=await e();if(n)return;if(d.status==="completed"||d.status==="failed"){console.log(`[pollJob:${r??"job"}] ${d.status} (${Math.round(performance.now()-o)}ms)`),p(d);return}a?.(),i=setTimeout(b,t)}catch(d){n||f(d)}};i=setTimeout(b,t)}),cancel:()=>{n=!0,i&&(clearTimeout(i),i=null)}}}var ua=Y(Ke());var rv=new URL("../assets/decking/boards/diagonal.webp",import.meta.url).href;var iv=new URL("../assets/decking/boards/no-border.webp",import.meta.url).href;var nv=new URL("../assets/decking/boards/picture-frame.webp",import.meta.url).href;var ov=new URL("../assets/decking/boards/straight.webp",import.meta.url).href;var lv=new URL("../assets/fencing/gates/no-gate.webp",import.meta.url).href;var sv=new URL("../assets/fencing/gates/single-gate.webp",import.meta.url).href;var cv=new URL("../assets/fencing/gravel-board.webp",import.meta.url).href;var uv=new URL("../assets/fencing/height/0.9.webp",import.meta.url).href;var pv=new URL("../assets/fencing/height/1.2.webp",import.meta.url).href;var dv=new URL("../assets/fencing/height/1.5.webp",import.meta.url).href;var mv=new URL("../assets/fencing/height/1.8.webp",import.meta.url).href;var fv=new URL("../assets/fencing/no-gravel-board.webp",import.meta.url).href;var gv=new URL("../assets/quick-order/paste-list.webp",import.meta.url).href;var hv=new URL("../assets/quick-order/photo-list.webp",import.meta.url).href;var bv=new URL("../assets/quick-order/upload-file.webp",import.meta.url).href;var vv=new URL("../assets/schedule-products/building-sand.webp",import.meta.url).href;var wv=new URL("../assets/schedule-products/drywall-screws.webp",import.meta.url).href;var yv=new URL("../assets/schedule-products/loft-insulation-roll.webp",import.meta.url).href;var _v=new URL("../assets/schedule-products/red-multi-stock-bricks.webp",import.meta.url).href;var xv=new URL("../assets/schedule-products/scrim-tape.webp",import.meta.url).href;var kv=new URL("../assets/schedule-products/wall-ties.webp",import.meta.url).href;var Nv=new URL("../assets/tool-images/architrave.webp",import.meta.url).href;var Sv=new URL("../assets/tool-images/brick-block.webp",import.meta.url).href;var Cv=new URL("../assets/tool-images/concrete-aggregate.webp",import.meta.url).href;var qv=new URL("../assets/tool-images/decking.webp",import.meta.url).href;var Ev=new URL("../assets/tool-images/fencing.webp",import.meta.url).href;var Mv=new URL("../assets/tool-images/insulation.webp",import.meta.url).href;var Tv=new URL("../assets/tool-images/paint.webp",import.meta.url).href;var zv=new URL("../assets/tool-images/paving.webp",import.meta.url).href;var Av=new URL("../assets/tool-images/plasterboard.webp",import.meta.url).href;var Rv=new URL("../assets/tool-images/skirting.webp",import.meta.url).href;var Uv=new URL("../assets/tool-images/timber.webp",import.meta.url).href;var Dv=new URL("../assets/tool-images/truss.webp",import.meta.url).href;var Ae=e=>typeof e=="string"?e:e.src,H1={"/decking/boards/diagonal.webp":Ae(rv),"/decking/boards/no-border.webp":Ae(iv),"/decking/boards/picture-frame.webp":Ae(nv),"/decking/boards/straight.webp":Ae(ov),"/fencing/gates/no-gate.webp":Ae(lv),"/fencing/gates/single-gate.webp":Ae(sv),"/fencing/gravel-board.webp":Ae(cv),"/fencing/height/0.9.webp":Ae(uv),"/fencing/height/1.2.webp":Ae(pv),"/fencing/height/1.5.webp":Ae(dv),"/fencing/height/1.8.webp":Ae(mv),"/fencing/no-gravel-board.webp":Ae(fv),"/quick-order/paste-list.webp":Ae(gv),"/quick-order/photo-list.webp":Ae(hv),"/quick-order/upload-file.webp":Ae(bv),"/schedule-products/building-sand.webp":Ae(vv),"/schedule-products/drywall-screws.webp":Ae(wv),"/schedule-products/loft-insulation-roll.webp":Ae(yv),"/schedule-products/red-multi-stock-bricks.webp":Ae(_v),"/schedule-products/scrim-tape.webp":Ae(xv),"/schedule-products/wall-ties.webp":Ae(kv),"/tool-images/architrave.webp":Ae(Nv),"/tool-images/brick-block.webp":Ae(Sv),"/tool-images/concrete-aggregate.webp":Ae(Cv),"/tool-images/decking.webp":Ae(qv),"/tool-images/fencing.webp":Ae(Ev),"/tool-images/insulation.webp":Ae(Mv),"/tool-images/paint.webp":Ae(Tv),"/tool-images/paving.webp":Ae(zv),"/tool-images/plasterboard.webp":Ae(Av),"/tool-images/skirting.webp":Ae(Rv),"/tool-images/timber.webp":Ae(Uv),"/tool-images/truss.webp":Ae(Dv)};function Pt(e){return H1[e]??e}var od=Y(ae());function Ht(){return(0,od.jsx)("svg",{className:"forward-arrow",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,od.jsx)("path",{d:"M3 8H13M13 8L9 4M13 8L9 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}var ld=Y(ae());function Ko(){return(0,ld.jsx)("svg",{className:"close-icon",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:(0,ld.jsx)("path",{d:"M3.5 3.5L12.5 12.5M12.5 3.5L3.5 12.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}var qn={schedule:[".xlsx",".xls",".csv",".pdf",".docx"],photo:[".png",".jpg",".jpeg",".webp",".gif",".bmp",".heic",".heif"],email:[".eml",".msg"]};var jv=(e,t)=>qn[t].some(a=>e.toLowerCase().endsWith(a)),En=e=>e.type.startsWith("image/")||jv(e.name,"photo"),Q1=e=>En(e)||jv(e.name,"schedule"),Hv=e=>`${Math.max(.1,Math.round(e/1048576*10)/10)} MB`;function sd(e,t=5242880){return Q1(e)?e.size===0?"That file is empty.":e.size>t?`That file is ${Hv(e.size)} - the limit is ${Hv(t)}.`:null:`Please upload a list or image file (${[...qn.schedule,...qn.photo].join(", ")}).`}var Y1=e=>e.split(`
|
|
6776
6776
|
`).map(t=>t.trim()).filter(Boolean);function Gv(e){let t=Y1(e);if(t.length>500)return`That's ${t.length} lines - the limit is 500. Split the list and match it in parts.`;if(e.length>5e4)return`That's ${e.length.toLocaleString("en-GB")} characters - the limit is ${5e4.toLocaleString("en-GB")}. Split the list and match it in parts.`;let a=t.findIndex(r=>r.length>500);return a>=0?`Line ${a+1} is ${t[a].length} characters - keep each item on its own line (max 500).`:null}async function Qv(e){if(e.size<=5242880)return e;let t;try{t=await createImageBitmap(e)}catch{return e}let a=Math.min(1,2e3/Math.max(t.width,t.height)),r=document.createElement("canvas");r.width=Math.round(t.width*a),r.height=Math.round(t.height*a);let n=r.getContext("2d");if(!n)return e;n.fillStyle="#fff",n.fillRect(0,0,r.width,r.height),n.drawImage(t,0,0,r.width,r.height),t.close();let i=await new Promise(o=>r.toBlob(o,"image/jpeg",.85));return!i||i.size>=e.size?e:new File([i],`${e.name.replace(/\.[^.]+$/,"")}.jpg`,{type:"image/jpeg"})}var $r=Y(Ke());var Xs=Y(Ke()),Vs=Y(ae()),V1=[4,5,4],cd=4e3;function dr(){let[e,t]=(0,Xs.useState)(0);(0,Xs.useEffect)(()=>{let r=setInterval(()=>t(n=>n+1),cd);return()=>clearInterval(r)},[]);let a=0;return(0,Vs.jsx)("div",{className:"brick-wall","aria-hidden":!0,children:V1.map((r,n)=>(0,Vs.jsx)("div",{className:"brick-wall__course",children:Array.from({length:r},(i,o)=>(0,Vs.jsx)("span",{className:`brick-wall__brick${r===5&&(o===0||o===4)?" brick-wall__brick--half":""}`,style:{"--i":a++}},o))},n))},e)}var Po=Y(ae()),$s=["Measuring twice, quoting once","Counting bricks so you don't have to","Haggling with the price of timber","Adding a bit extra for the skip","Double-checking nobody ordered too much sand","Rounding up, obviously","Making sure the numbers add up better than the last lot did","Checking if copper pipe is still worth its weight in gold","Squeezing a bit more accuracy out of the numbers","Totting it all up on the back of a fag packet, digitally","Making sure the quote is tighter than your tolerances","Nearly there, unlike most site schedules","Working out if it'll all fit on one pallet","Double-checking the VAT, because someone has to","Giving the calculator a proper workout","Making sure nothing's out of stock before you get excited"];function Yv(e){let t=[...e];for(let a=t.length-1;a>0;a--){let r=Math.floor(Math.random()*(a+1));[t[a],t[r]]=[t[r],t[a]]}return t}function Vv(){let e=(0,$r.useRef)(Yv($s.map((o,l)=>l))),t=(0,$r.useRef)(0),[a,r]=(0,$r.useState)($s[e.current[0]]),[n,i]=(0,$r.useState)(!0);return(0,$r.useEffect)(()=>{let o=setInterval(()=>{i(!1),window.setTimeout(()=>{t.current++,t.current>=e.current.length&&(e.current=Yv($s.map((l,c)=>c)),t.current=0),r($s[e.current[t.current]]),i(!0)},600)},cd);return()=>clearInterval(o)},[]),(0,Po.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",children:[(0,Po.jsx)(dr,{}),(0,Po.jsx)("p",{className:`banter-message${n?" is-visible":""}`,children:a})]})}var P=Y(ae()),X1=[...qn.schedule,...qn.photo].join(","),$1={paste:[{title:"Paste List",desc:"Paste your material list straight from a spreadsheet or document."},{title:"Check Matches",desc:"Review the suggested products and adjust any that need changing."},{title:"Review Quote",desc:"Review the matched materials for your quote."}],upload:[{title:"Upload File",desc:"Upload a photo, spreadsheet, Word document or PDF."},{title:"Check Matches",desc:"Review the suggested products and adjust any that need changing."},{title:"Review Quote",desc:"Review the matched materials for your quote."}]};function ud({onPasteSchedule:e,onUploadSchedule:t,onEntryModeChange:a}){let[r,n]=(0,ua.useState)(null),i=Cn(),[o,l]=(0,ua.useState)(""),[c,p]=(0,ua.useState)(null),[f,b]=(0,ua.useState)(""),[d,h]=(0,ua.useState)(!1),[w,E]=(0,ua.useState)(!1),[D,m]=(0,ua.useState)(null),u=(0,ua.useRef)(0),g=(0,ua.useRef)(null),v=o.split(`
|
|
6777
6777
|
`).filter(Q=>Q.trim()).length,N=Gv(o),R=r==="paste"?!!o:!!c;(0,ua.useEffect)(()=>{if(!c||!En(c)){m(null);return}let Q=URL.createObjectURL(c);return m(Q),()=>URL.revokeObjectURL(Q)},[c]);let T=Q=>{i("method_selected",{method:Q}),n(Q),a(null)},z=()=>{n(null),a(null)},G=Q=>{if(!Q?.length)return;if(Q.length>1)return b("Please choose one file at a time.");let se=Q[0],Ne=sd(se,En(se)?1/0:void 0);if(Ne)return b(Ne);b(""),p(se)},K=async Q=>{h(!0);try{await Q()}finally{h(!1)}},xe=async Q=>{try{let se=await Qv(Q),Ne=sd(se);if(Ne)throw new Error(Ne);let lt=new FormData;lt.append("file",se);let Ye=await fetch(Lt("/api/schedule/extract-photo"),{method:"POST",body:lt,headers:Ga()}),ge=await Kt(Ye);if(!Ye.ok)throw new Error(ge?.error||ge?.message||"Failed to extract line items from image");let We=typeof ge?.text=="string"?ge.text.trim():"";if(!We)throw new Error("No line items were extracted from this image.");let he=Array.isArray(ge?.lines)?ge.lines.filter(W=>!!(W&&typeof W=="object"&&typeof W.text=="string")):void 0;await e(We,he,!1)}catch(se){i("error",{stage:"photo"}),b(se?.message||"Failed to extract line items from image")}},Ee=()=>{if(c)return i("list_submitted",{method:En(c)?"photo":"upload"}),K(()=>En(c)?xe(c):t(c))},Ge=Q=>Q.dataTransfer.types.includes("Files"),Qe=Q=>{Ge(Q)&&(Q.preventDefault(),u.current+=1,E(!0))},Ie=Q=>{Ge(Q)&&(u.current-=1,u.current<=0&&(u.current=0,E(!1)))},ue=Q=>{Ge(Q)&&(Q.preventDefault(),u.current=0,E(!1),G(Q.dataTransfer.files),T("upload"))};return(0,P.jsxs)("div",{className:"wizard-step entry-stage",onDragEnter:Qe,onDragOver:Q=>Ge(Q)&&Q.preventDefault(),onDragLeave:Ie,onDrop:ue,children:[w&&(0,P.jsx)("div",{className:"entry-drop-overlay","aria-hidden":"true",children:"Drop your file to upload"}),(0,P.jsxs)("div",{className:"quick-order-card",children:[(0,P.jsxs)("div",{className:"quick-order-alt",children:[(0,P.jsxs)("div",{className:"quick-order-entry-copy",children:[(0,P.jsx)("div",{className:"quick-order-alt-title",children:"How would you like to get started?"}),(0,P.jsx)("p",{className:"quick-order-alt-intro",children:"Upload a file or type a list of items and quantities. We'll match them to our products and help you build a quote."})]}),(0,P.jsxs)("div",{className:"entry-options entry-options--workflow entry-options--two",children:[(0,P.jsxs)("button",{type:"button",className:`entry-option-card entry-option-card--paste${r==="paste"?" entry-option-card--active":""}`,onClick:()=>T("paste"),children:[(0,P.jsxs)("span",{className:"entry-option-content",children:[(0,P.jsx)("span",{className:"entry-option-title",children:"Type or paste a list"}),(0,P.jsx)("span",{className:"entry-option-desc",children:"Enter your materials and quantities"})]}),(0,P.jsx)("span",{className:"entry-option-media entry-option-media--paste","aria-hidden":"true",children:(0,P.jsx)("img",{className:"fill-img",src:Pt("/quick-order/paste-list.webp"),alt:""})})]}),(0,P.jsxs)("button",{type:"button",className:`entry-option-card entry-option-card--upload${r==="upload"?" entry-option-card--active":""}`,onClick:()=>T("upload"),children:[(0,P.jsxs)("span",{className:"entry-option-content",children:[(0,P.jsx)("span",{className:"entry-option-title",children:"Upload a file"}),(0,P.jsx)("span",{className:"entry-option-desc",children:"A photo, spreadsheet, Word document or PDF"})]}),(0,P.jsx)("span",{className:"entry-option-media entry-option-media--upload","aria-hidden":"true",children:(0,P.jsx)("img",{className:"fill-img",src:Pt("/quick-order/photo-list.webp"),alt:""})})]})]})]}),r&&(0,P.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop",role:"dialog","aria-modal":"true","aria-labelledby":"quick-order-workflow-title",onClick:()=>!R&&z(),children:(0,P.jsxs)("section",{className:`quick-order-workflow-modal${d?" quick-order-workflow-modal--matching":""}`,onClick:Q=>Q.stopPropagation(),children:[(0,P.jsxs)("header",{className:"quick-order-workflow-modal-header",children:[(0,P.jsx)("h2",{id:"quick-order-workflow-title",children:r==="paste"?"Type or paste a list":"Upload a file"}),(0,P.jsx)("button",{type:"button",className:"quick-order-workflow-close",onClick:z,"aria-label":"Close",children:(0,P.jsx)(Ko,{})})]}),(0,P.jsxs)("div",{className:"quick-order-panel",children:[(0,P.jsxs)("div",{className:"quick-order-body","aria-hidden":d,children:[(0,P.jsx)("div",{className:"quick-order-body-main",children:r==="paste"?(0,P.jsxs)(P.Fragment,{children:[(0,P.jsx)("textarea",{className:"paste-textarea",placeholder:`Paste your line items here, one per line, e.g.
|
|
6778
6778
|
insulated plasterboard 50mm
|
|
@@ -6795,7 +6795,7 @@ C24 timber 4.8m`,value:o,onChange:Q=>l(Q.target.value),"aria-label":"Paste sched
|
|
|
6795
6795
|
<rect x="168" y="188" width="250" height="24" rx="12" fill="#aab5c0"/>
|
|
6796
6796
|
<rect x="168" y="232" width="220" height="24" rx="12" fill="#aab5c0"/>
|
|
6797
6797
|
</svg>
|
|
6798
|
-
`)}function Kr(e,t){return{lineId:t.lineId,description:e?.description||t.description||"(no description)",requestedDescription:t.description,productId:e?.product_id??"-",price:e?.price??null,priceBasis:e?.price_basis??null,unit:t.unit,uoi:e?.uoi??t.unit,uoiCount:e?.uoi_count??null,saleUnit:e?.conversion?.sale_unit??null,saleUnitQuantity:e?.conversion?.sale_unit_quantity??null,unitConversions:e?.conversion?.unit_conversions?.map(a=>({requestUom:a.request_uom,quantityPerSaleUnit:a.quantity_per_sale_unit,evidence:a.evidence,confidence:a.confidence})),pdpPhotoUrl:e?.pdp_photo_url??null,measurementsMm:e?.measurements_mm??[],conversionType:e?.conversion?.conversion_type??null,requestUomsSupported:e?.conversion?.request_uoms_supported??null,salesUomNormalised:e?.conversion?.sales_uom_normalised??null,salesUnitSize:e?.conversion?.sales_unit_size??null,salesUnitSizeUom:e?.conversion?.sales_unit_size_uom??null,coverageQty:e?.conversion?.coverage_qty??null,coverageUom:e?.conversion?.coverage_uom??null,itemsPerPallet:e?.conversion?.items_per_pallet??null,itemsPerPack:e?.conversion?.items_per_pack??null,itemsPerBox:e?.conversion?.items_per_box??null,itemsPerM2:e?.conversion?.items_per_m2??null,wasteFactorDefault:e?.conversion?.waste_factor_default??null,roundingRule:e?.conversion?.rounding_rule??null,derivedCoverageM2:e?.conversion?.derived_coverage_m2??null,derivedLengthM:e?.conversion?.derived_length_m??null,quoteQtyFormulaType:e?.conversion?.quote_qty_formula_type??null,conversionConfidence:e?.conversion?.conversion_confidence??null,conversionNotes:e?.conversion?.conversion_notes??null,calculatorWasteIncluded:t.calculatorWasteIncluded,qty:t.qty,linkedContext:t.linkedContext}}var Iv=e=>(e??"").trim().toLowerCase(),J1={sqm:"m2","sq m":"m2","m\xB2":"m2",cbm:"m3","cu m":"m3",lm:"m","lin m":"m",metre:"m",meter:"m",each:"each",ea:"each",nr:"each",no:"each",item:"each",unit:"each",units:"each",pc:"each",pcs:"each",board:"sheet",bags:"bag",length:"length",lengths:"length",pallet:"pallet",pallets:"pallet"},Zv=new Set(["sheet","length","box","bag","pack","roll","set","tub","each"]),Kv=new Set(["box","bag","pack","pallet","roll","set","tub"]),Pv=(e,t)=>t==="ml"?e:["l","litre","litres"].includes(t)?e*1e3:null,Jv=(e,t)=>t==="g"?e:["kg","kilogram","kilograms"].includes(t)?e*1e3:["t","tonne","tonnes"].includes(t)?e*1e6:null,xi=e=>{let t=Iv(e);return J1[t]??t},pt=(e,t)=>{let a=xi(e),r=xi(t);return a.length>0&&a===r},F1=(e,t)=>{let a=Iv(t);return a?a.includes("round_up_1000")?Math.ceil(e):a.includes("allow_decimal")?Math.round(e*1e3)/1e3:a.includes("round_up")?Math.ceil(e):e:e},I1=e=>(e??"").split(",").map(t=>xi(t)).filter(Boolean),W1=(e,t)=>{let a=I1(e.requestUomsSupported);return!!(a.length===0||a.includes(t)||pt(t,"pallet")&&e.itemsPerPallet!=null&&e.itemsPerPallet>0||pt(t,"pack")&&e.itemsPerPack!=null&&e.itemsPerPack>0||pt(t,"box")&&e.itemsPerBox!=null&&e.itemsPerBox>0)},Fv=(e,t)=>pt(t,"pallet")?e.itemsPerPallet??null:pt(t,"pack")?e.itemsPerPack??null:pt(t,"box")?e.itemsPerBox??null:null,e_=(e,t,a)=>{if(!pt(t,"m2"))return null;let r=e.description.match(/(\d+(?:[.,]\d+)?)\s*(m2|m²|sqm|sq\.?\s*m)\s*(?:\/|per)\s*([a-z]+)/i);if(!r||!pt(r[3],a))return null;let n=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(n)&&n>0?n:null};function Zs(e,t){return e.reduce((a,r)=>a+(Ut(r,t).lineTotal??0),0)}function Ut(e,t){let a=e.qty,r=xi(e.saleUnit??e.salesUnitSizeUom??e.uoi??e.salesUomNormalised)||"-",n=xi(e.unit)||(a>0&&Zv.has(r)?r:"-"),i=e.saleUnitQuantity??e.salesUnitSize??e.uoiCount??1,o=t?.wasteFactorEnabled===!1?0:t?.wasteFactorOverride??e.wasteFactorOverride??e.wasteFactorDefault??0,l=e.sellUnitsOverride!=null&&Number.isFinite(e.sellUnitsOverride)&&e.sellUnitsOverride>0,c=l?e.sellUnitsOverride??null:null,p=v=>({requestedAmount:a,requestedUnit:n,salesUnitSize:e.salesUnitSize??e.uoiCount??null,sellUnit:r,calculatedSellUnits:null,requiredSellUnits:c,unitPrice:e.price,lineTotal:e.price!=null&&c!=null?e.price*c:null,calculation:c!=null?`${v} Manually set to ${c} ${r}.`:v,costingMode:"review"});if(!W1(e,n))return p("Requested unit is not supported by this catalogue conversion.");let f=null,b="review",d=e.roundingRule,h=`Quantity review required, initial request needed ${a} ${n}.`,w=1+o,E=e_(e,n,r),D=e.unitConversions?.find(v=>pt(v.requestUom,n));if(!!e.saleUnit&&(pt(n,r)||!!D||pt(n,"each")&&!Kv.has(r)))if(pt(n,r))f=a*w/i,b="direct",h=`${a} ${n}${o>0?` x ${w}`:""}`;else if(D){f=a*w/D.quantityPerSaleUnit,b="derived";let v=1/D.quantityPerSaleUnit,N=Math.round(v);h=pt(r,"each")&&D.quantityPerSaleUnit<1&&Math.abs(v-N)<1e-9?`${a} ${n}${o>0?` x ${w}`:""} x ${N} per ${n}`:`${a} ${n}${o>0?` x ${w}`:""} / ${D.quantityPerSaleUnit} ${n} per ${r}`}else pt(n,"each")&&!Kv.has(r)&&(f=a*w/i,b="derived",h=`${a} ${r}${o>0?` x ${w}`:""}`);else if(pt(n,r)&&i>0)f=a*w/i,b="direct",h=o>0?`${a} ${n} x ${w} / ${i} ${r} per sell unit`:`${a} ${n} / ${i} ${r} per sell unit`;else if(pt(n,"each")&&i>0&&Zv.has(r))f=a*w/i,b="derived",h=o>0?`${a} each x ${w} / ${i} each per ${r}`:`${a} each / ${i} each per ${r}`;else if(Fv(e,n)!=null&&i>0){let v=Fv(e,n)??0;f=a*v*w/i,b="derived";let N=`${a} ${n} x ${v} each${o>0?` x ${w}`:""}`;h=i===1&&pt(r,"each")?N:`${N} / ${i} each per ${r}`}else if(E!=null)f=a*w/E,b="derived",d??(d="round_up_each"),h=`${a} m2 x ${w} / ${E} m2 per ${r} (from product description)`;else if(e.conversionType==="basket_line_unit")i>0&&(f=a*w/i,b="derived",h=`${a} ${n}${o>0?` x ${w}`:""} / ${i} ${n} per ${r}`);else{if(e.conversionType==="count_only")return p(`Quantity review required, initial request needed ${a} ${n}.`);if(["area_from_dims","explicit_coverage_area","roll_area"].includes(e.conversionType??"")){let v=e.coverageQty??e.derivedCoverageM2??null;pt(n,"m2")&&v!=null&&v>0&&(f=a*w/v,b="derived",h=`${a} m2 x ${w} / ${v} m2 per ${r}`)}else if(e.conversionType==="count_per_area"){let v=e.coverageQty??null;pt(n,"m2")&&v!=null&&v>0?(f=a/v,b="derived",h=`${a} m2 / ${v} m2 per sell unit`):pt(n,"m2")&&e.itemsPerM2!=null&&e.itemsPerM2>0&&i>0&&(f=a*e.itemsPerM2*w/i,b="derived",h=`${a} m2 x ${e.itemsPerM2} ${r}/m2 x ${w} / ${i}`)}else if(e.conversionType==="length_from_dims"){let v=e.coverageQty??e.derivedLengthM??null;pt(n,"m")&&v!=null&&v>0&&(f=a*w/v,b="derived",h=`${a} m x ${w} / ${v} m per ${r}`)}else if(e.conversionType==="volume_from_description"){let v=Pv(a,n),N=Pv(e.coverageQty??0,xi(e.coverageUom));v!=null&&N!=null&&N>0&&(f=v*w/N,b="derived",h=`${a} ${n} x ${w} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="weight_from_description"){let v=Jv(a,n),N=Jv(e.coverageQty??0,xi(e.coverageUom));v!=null&&N!=null&&N>0&&(f=v*w/N,b="derived",h=`${a} ${n} x ${w} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="same_unit_volume"){let v=e.coverageQty??null;pt(n,"m3")&&v!=null&&v>0&&(f=a/v,b="derived",h=`${a} m3 / ${v} m3 per ${r}`)}}if(f==null||!Number.isFinite(f)||f<0)return p(`Quantity review required, initial request needed ${a} ${n}.`);let u=F1(f,d),g=l?e.sellUnitsOverride??null:u;return{requestedAmount:a,requestedUnit:n,salesUnitSize:i,sellUnit:r,calculatedSellUnits:u,requiredSellUnits:g,unitPrice:e.price,lineTotal:e.price!=null&&g!=null?e.price*g:null,calculation:l?`${h} = ${u} ${r} (manually set to ${g})`:`${h} = ${g} ${r}`,costingMode:b}}var Wv=()=>import("./xlsx-K4MOA2QM.js"),Wo=["Source Line ID","Split Line ID","Description","Section","Qty","Unit","Procurement intent","Procurement aliases","Build-up type","Layer count","Total thickness (mm)","Installation clues","System clues","Component requirements","Technical classification","Include in quote","Approval required","Approval type","Missing information","Adjudicator confidence","Decision reason","Selected candidate ID","Selected candidate description","Price basis","Price","Line total","Confidence","Status"],t_=Wo.indexOf("Line total");function a_(e){return e.unmatchable?"Not matched (labour/plant/referential)":e.decision?.include_in_quote===!0&&e.decision.approval_required===!0?"Approval required":e.decision?.include_in_quote===!0?"Quoted":e.decision?.technical_classification==="no_suitable_candidate"?"No suitable candidate":(e.best,"No match")}async function ew(e){let t=await Wv(),a=t.utils.book_new(),r=new Date().toISOString().slice(0,10),n=[Wo],i=0;for(let c of e){let{item:p,best:f,qty:b,band:d,unmatchable:h,decision:w}=c,E=[p.section,p.subsection,p.subheading].filter(Boolean).join(" / "),D=!h&&f?.price!=null?f.price*b:null;D!=null&&(i+=D),n.push([p.source_line_id,p.line_id,p.description_original||"(no description)",E,b,p.unit,p.procurement_intent||"-",p.procurement_aliases.join(", "),p.build_up_type,p.layer_count,p.total_required_thickness_mm,p.installation_clues.join(", "),p.system_clues.join(", "),p.component_requirements.join(", "),w?.technical_classification??"",w?.include_in_quote==null?"":w.include_in_quote?"yes":"no",w?.approval_required==null?"":w.approval_required?"yes":"no",w?.approval_type??"",w?.missing_information.join(", ")??"",w?.confidence??"",w?.reason??"",h?"-":f?.product_id??w?.selected_candidate_id??"-",h?"-":f?.description??"-",h?"-":f?.price_basis??"-",h?null:f?.price??null,D,h?"-":d,a_(c)])}n.push(Array(Wo.length).fill(null));let o=Array(Wo.length).fill(null);o[0]="Estimated total",o[t_]=i,n.push(o),n.push(["DISCLAIMER: These matches are generated automatically and should be reviewed before procurement, especially any items flagged as medium or low confidence.",...Array(Wo.length-1).fill(null)]);let l=t.utils.aoa_to_sheet(n);l["!cols"]=[{wch:12},{wch:12},{wch:44},{wch:24},{wch:8},{wch:8},{wch:28},{wch:28},{wch:16},{wch:10},{wch:12},{wch:24},{wch:24},{wch:24},{wch:22},{wch:14},{wch:14},{wch:18},{wch:24},{wch:16},{wch:48},{wch:16},{wch:40},{wch:10},{wch:10},{wch:12},{wch:11},{wch:26}],t.utils.book_append_sheet(a,l,"Schedule match"),t.writeFile(a,`schedule-quote-${r}.xlsx`)}var Io=["Product ID","Description","Costing mode","Required amount","Req unit","Sell unit size","Sell unit","Required sell units","Unit price","Line total"];async function tw(e,t){let a=await Wv(),r=a.utils.book_new(),n=new Date().toISOString().slice(0,10),i=t?[["Account",t.name+" ("+t.id+")"],[],Io]:[Io],o=0;for(let p of e){let f=Ut(p),b=f.lineTotal;b!=null&&(o+=b),i.push([p.productId,p.description,f.costingMode,f.requestedAmount,xa(f.requestedUnit),f.salesUnitSize,xa(f.sellUnit),f.requiredSellUnits,f.unitPrice,b])}i.push(Array(Io.length).fill(null));let l=Array(Io.length).fill(null);l[0]="Estimated total",l[Io.length-1]=o,i.push(l);let c=a.utils.aoa_to_sheet(i);c["!cols"]=[{wch:14},{wch:48},{wch:12},{wch:14},{wch:10},{wch:14},{wch:10},{wch:16},{wch:12},{wch:14}],a.utils.book_append_sheet(r,c,"Basket"),a.writeFile(r,t?`basket-${t.id}-${n}.xlsx`:`basket-${n}.xlsx`)}var s=Y(ae()),gd="__none__",el=24,r_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}];function nw(e){return e==null?"low":e>=.7?"high":e>=.5?"medium":"low"}var i_=e=>e.attrs.supply_nature==="labour_only"||e.attrs.supply_nature==="plant"||e.flags.includes("referential");function n_(e,t){if(t!==gd){if(t)return e?.candidates.find(a=>a.product_id===t);if(e?.decision?.selected_candidate_id!=null)return e.candidates.find(a=>a.product_id===e.decision.selected_candidate_id)}}function aw(e){return{product_id:e.productId,description:e.description,source_list:null,price:e.price,price_basis:e.priceBasis,uoi_count:e.uoiCount??null,uoi:e.uoi,pdp_photo_url:e.pdpPhotoUrl??null,measurements_mm:e.measurementsMm??[],conversion:{sale_unit:e.saleUnit,sale_unit_quantity:e.saleUnitQuantity,unit_conversions:e.unitConversions?.map(t=>({request_uom:t.requestUom,quantity_per_sale_unit:t.quantityPerSaleUnit,evidence:t.evidence,confidence:t.confidence})),sales_uom_normalised:e.salesUomNormalised,conversion_type:e.conversionType,request_uoms_supported:e.requestUomsSupported,sales_unit_size:e.salesUnitSize,sales_unit_size_uom:e.salesUnitSizeUom,coverage_qty:e.coverageQty,coverage_uom:e.coverageUom,items_per_pallet:e.itemsPerPallet,items_per_pack:e.itemsPerPack,items_per_box:e.itemsPerBox,items_per_m2:e.itemsPerM2,waste_factor_default:e.wasteFactorDefault,rounding_rule:e.roundingRule,derived_coverage_m2:e.derivedCoverageM2,derived_length_m:e.derivedLengthM,quote_qty_formula_type:e.quoteQtyFormulaType,conversion_confidence:e.conversionConfidence,conversion_notes:e.conversionNotes},scores:{dimension:0,grade:0,brand:0,fuzzy:0,bm25:0,overall:0},method:"manual_cart_selection"}}function o_(e){return e?e.replace(/_/g," "):"not stated"}function l_({band:e}){return(0,s.jsx)("span",{className:`status-dot status-dot--${e}`,title:e,children:(0,s.jsx)("span",{className:"status-dot__mark"})})}function Tn(e,t){if(e==null)return"-";let a=Fo(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function hd(e){return e&&e.length>0?e.join(" x "):"-"}function s_(e){return e==null?"-":Number.isInteger(e/1e3)?`${e/1e3}m`:`${(e/1e3).toFixed(1)}m`}function Mn(e){let t=(e??[]).map(a=>a.trim()).filter(Boolean);return t.length>0?t.join(", "):"-"}function Pr(e,t){let a=typeof e.description_original=="string"?e.description_original.trim():"";return(typeof e.customer_display_label=="string"?e.customer_display_label.trim():"")||a||"(no description)"}var rw=[{background:"#fff7ed",borderColor:"#fdba74",color:"#9a3412"},{background:"#eff6ff",borderColor:"#93c5fd",color:"#1d4ed8"},{background:"#ecfeff",borderColor:"#67e8f9",color:"#0f766e"},{background:"#f0fdf4",borderColor:"#86efac",color:"#166534"},{background:"#fdf4ff",borderColor:"#f0abfc",color:"#a21caf"}];function c_(e){let t=new Map;return[...new Set(e.filter(mr).map(r=>r.linked_group_id))].forEach((r,n)=>{let i=n%26;t.set(r,{token:String.fromCharCode(65+i),bubbleStyle:rw[n%rw.length]})}),t}function mr(e){return!1}function zn(e){if(!e.linked_group_id)return null;let t=e.linked_group_label||"Linked group",a=e.linked_group_role==="anchor"?"anchor":e.linked_group_role==="dependent"?"dependent":"member",r=e.linked_group_shared_width_mm!=null?`, ${e.linked_group_shared_width_mm}mm family`:"";return`${t} (${a}${r})`}function fd({meta:e}){return e?(0,s.jsx)("span",{className:"results-linked-pill",style:e.bubbleStyle,children:`Link ${e.token}`}):null}function u_(e,t,a){let r=t?.rerank?.recommendedCandidateIds??[];if(r.length===0){let o=e.slice(0,5),l=o.some(c=>c.product_id===a)?void 0:e.find(c=>c.product_id===a);return l?[...o,l]:o}let n=new Map(e.map(o=>[o.product_id,o])),i=r.map(o=>n.get(o)).filter(o=>o!=null);if(a&&!i.some(o=>o.product_id===a)){let o=n.get(a);o&&i.unshift(o)}return[...new Map(i.map(o=>[o.product_id,o])).values()].slice(0,5)}function Ks(e){let t=e?.rerank?.recommendedCandidateIds??[];if(t.length===0||!e)return[];let a=new Map(e.candidates.map(r=>[r.product_id,r]));return t.map(r=>a.get(r)).filter(r=>r!=null)}function Ps(e){if(e>=6e4){let t=Math.floor(e/6e4),a=Math.round(e%6e4/1e3);return a===60?`${t+1}m`:`${t}m ${a}s`}return e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}s`:`${e}ms`}function p_({processStages:e,llmCalls:t,totalDurationMs:a,llmDurationMs:r,llmCallCount:n}){let i=[...t].sort((l,c)=>c.durationMs-l.durationMs).slice(0,12),o=Math.max(0,t.length-i.length);return(0,s.jsxs)("div",{className:"results-detail-block",style:{marginBottom:18},children:[(0,s.jsx)("h3",{style:{margin:"0 0 12px"},children:"Pipeline timings"}),(0,s.jsxs)("div",{className:"results-summary",style:{marginBottom:12},children:[(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:Ps(a)})," total"]}),(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:n})," LLM calls"]}),(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:Ps(r)})," LLM time"]})]}),(0,s.jsxs)("table",{className:"score-breakdown-table",style:{marginBottom:14},children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Process stage"}),(0,s.jsx)("th",{children:"Duration"})]})}),(0,s.jsx)("tbody",{children:e.map((l,c)=>(0,s.jsxs)("tr",{children:[(0,s.jsx)("td",{children:l.label}),(0,s.jsx)("td",{children:Ps(l.durationMs)})]},`${l.key}-${c}`))})]}),t.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("h4",{style:{margin:"0 0 10px"},children:"LLM calls"}),(0,s.jsxs)("table",{className:"score-breakdown-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Call"}),(0,s.jsx)("th",{children:"Duration"})]})}),(0,s.jsx)("tbody",{children:i.map((l,c)=>(0,s.jsxs)("tr",{children:[(0,s.jsx)("td",{children:l.label}),(0,s.jsx)("td",{children:Ps(l.durationMs)})]},`${l.key}-${c}`))})]}),o>0&&(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Showing slowest ",i.length," of ",t.length," LLM calls."]})]})]})}function d_({queries:e}){return e.length===0?null:(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Retrieval by procurement query"}),e.map((t,a)=>(0,s.jsxs)("div",{style:{marginBottom:16},children:[(0,s.jsxs)("div",{className:"results-row-meta",style:{marginBottom:6},children:["Query: ",(0,s.jsx)("strong",{children:t.query})]}),t.candidates.length===0?(0,s.jsx)("p",{className:"results-empty-hint",children:"No candidates returned for this query."}):(0,s.jsxs)("table",{className:"score-breakdown-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Product"}),(0,s.jsx)("th",{children:"Dims (mm)"}),(0,s.jsx)("th",{children:"Unit"}),(0,s.jsx)("th",{children:"bm25"})]})}),(0,s.jsx)("tbody",{children:t.candidates.slice(0,5).map((r,n)=>(0,s.jsxs)("tr",{children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{children:r.description}),(0,s.jsx)("div",{className:"results-row-meta",children:r.product_id})]}),(0,s.jsx)("td",{children:hd(r.measurements_mm)}),(0,s.jsx)("td",{children:Fo(r.price_basis)||"-"}),(0,s.jsx)("td",{children:r.bm25.toFixed(2)})]},`${r.product_id}-${n}`))})]})]},`${t.query}-${a}`))]})}function iw({item:e,result:t}){let a=t?.retrieval_debug.map(n=>n.query).filter(Boolean)??[],r=[["Procurement intent",e.procurement_intent||"-"],["Procurement aliases",Mn(e.procurement_aliases)],["Retrieval queries",Mn(a)],["Category",e.attrs.category||"-"],["Fine category",e.attrs.category_fine||"-"],["Brand",e.attrs.brand||"-"],["Material",e.attrs.material||"-"],["Grade / standard",e.attrs.grade_standard||"-"],["Treatment",e.attrs.treatment||"-"],["Supply nature",e.attrs.supply_nature||"-"],["Measurements (mm)",hd(e.attrs.measurements_mm)],["Stock length",s_(e.attrs.stock_length_mm)],["Matching mode",e.matching_mode||"-"],["Build-up type",e.build_up_type||"-"],["Layer count",e.layer_count!=null?String(e.layer_count):"-"],["Required thickness (mm)",e.total_required_thickness_mm!=null?String(e.total_required_thickness_mm):"-"],["Allowed layer thicknesses (mm)",e.acceptable_layer_thicknesses_mm.length>0?e.acceptable_layer_thicknesses_mm.join(", "):"-"],["Installation clues",Mn(e.installation_clues)],["System clues",Mn(e.system_clues)],["Component requirements",Mn(e.component_requirements)],["Linked group",zn(e)||"-"],["Flags",Mn(e.flags)]];return(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Search context"}),(0,s.jsx)("dl",{className:"results-detail-grid",children:r.map(([n,i])=>(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:n}),(0,s.jsx)("dd",{children:i})]},n))})]})}function m_({item:e}){let t=e.decomposition_debug;return t?(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Decomposition"}),(0,s.jsxs)("dl",{className:"results-detail-grid",children:[(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:"Attempted"}),(0,s.jsx)("dd",{children:t.attempted?"yes":"no"})]}),(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:"Applied"}),(0,s.jsx)("dd",{children:t.applied?"yes":"no"})]}),(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned items"}),(0,s.jsx)("dd",{children:t.returned_item_count??"-"})]}),(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:"Reason"}),(0,s.jsx)("dd",{children:t.reason||"-"})]}),(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned intents"}),(0,s.jsx)("dd",{children:t.items.length>0?t.items.map(a=>`${a.intent}${a.inherits_quantity?" (inherits qty)":""}`).join(", "):"-"})]})]})]}):null}function f_({result:e}){let t=e?.adjudication_debug;if(!t)return null;let a=[["Dependent rerank applied",t.dependent_rerank_applied?"yes":"no"],["Linked parent selected product",t.linked_parent_selected_candidate_description||t.linked_parent_selected_candidate_id||"-"],["Dimension reason overridden",t.dimension_reason_overridden?"yes":"no"]];return(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Adjudication context"}),(0,s.jsx)("dl",{className:"results-detail-grid",children:a.map(([r,n])=>(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:r}),(0,s.jsx)("dd",{children:n})]},r))}),t.rerank_line_item_input?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("h5",{style:{margin:"12px 0 8px"},children:"Rerank input"}),(0,s.jsx)("pre",{className:"results-pre",children:JSON.stringify(t.rerank_line_item_input,null,2)})]}):null]})}function g_({item:e,decision:t,result:a,showRetrievalDebug:r,reviewOnly:n=!1,linkedGroupMeta:i}){if(!t)return null;let o=t.technical_classification==="no_suitable_candidate"?"Exact match not found:":`AI review (${t.confidence??"confidence not stated"}):`;return n?t.reason?(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,s.jsx)("strong",{children:o}),"\xA0",t.reason]}),mr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",i?`Link ${i.token} - `:"",zn(e)]}):null]}):null:!t.reason&&!r?(0,s.jsx)(iw,{item:e,result:a}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(iw,{item:e,result:a}),r&&(0,s.jsx)(m_,{item:e}),r&&(0,s.jsx)(f_,{result:a}),t.reason&&(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,s.jsx)("strong",{children:o}),"\xA0",t.reason]}),mr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",i?`Link ${i.token} - `:"",zn(e)]}):null]}),r&&(0,s.jsx)(d_,{queries:a?.retrieval_debug??[]})]})}function h_({item:e,candidates:t,result:a,decision:r,unmatchable:n,selectedProductId:i,detailMode:o,onPick:l,onClear:c,showAll:p=!1,internal:f=!1,debugEnabled:b=!1,forceReviewNote:d=!1,linkedGroupMeta:h}){let w=f||o==="detailed",E=b&&o==="detailed",D=w||d?(0,s.jsx)(g_,{item:e,decision:r,result:a,showRetrievalDebug:E,reviewOnly:d&&!w,linkedGroupMeta:h}):null;if(n)return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsx)("p",{className:"results-empty-hint",children:"Classified as labour/plant or referencing another line item - skipped by design."})]});if(t.length===0)return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsx)("p",{className:"results-empty-hint",children:"No candidates were returned for this line item."})]});let m=p||f||o==="detailed"?t:u_(t,a,i);return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsxs)("table",{className:"score-breakdown-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Product"}),(0,s.jsx)("th",{children:"Dims (mm)"}),(0,s.jsx)("th",{children:"Price"}),E&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("th",{children:"dimension"}),(0,s.jsx)("th",{children:"grade"}),(0,s.jsx)("th",{children:"brand"}),(0,s.jsx)("th",{children:"fuzzy"}),(0,s.jsx)("th",{children:"bm25"}),(0,s.jsx)("th",{children:"overall"})]}),(0,s.jsx)("th",{"aria-label":"Actions"})]})}),(0,s.jsx)("tbody",{children:m.map((u,g)=>{let v=u.product_id===i;return(0,s.jsxs)("tr",{className:v?"score-breakdown-row--best":"",children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{children:u.description}),(0,s.jsx)("div",{className:"results-row-meta",children:u.product_id})]}),(0,s.jsx)("td",{children:(0,s.jsx)("span",{className:"unit-badge",children:hd(u.measurements_mm??u.debug?.candidate.measurements_mm)})}),(0,s.jsx)("td",{children:Tn(u.price,u.price_basis)}),E&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("td",{children:(u.scores?.dimension??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.grade??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.brand??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.fuzzy??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.bm25??0).toFixed(2)}),(0,s.jsx)("td",{children:(0,s.jsxs)("div",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[(0,s.jsx)(l_,{band:nw(u.scores?.overall)}),(0,s.jsx)("span",{className:"results-overall-cell",children:(u.scores?.overall??0).toFixed(2)})]})})]}),(0,s.jsx)("td",{children:(0,s.jsxs)("label",{className:"switch-toggle",title:v?"Currently selected":"Use this candidate",children:[(0,s.jsx)("input",{type:"checkbox",checked:v,onChange:()=>{v?c?.():l(u)},"aria-label":v?`${u.description} selected`:`Use ${u.description}`}),(0,s.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},`${u.product_id}-${g}`)})})]})]})}function bd({scheduleResult:e,onStartOver:t,cart:a,onAddToCart:r,onRemoveFromCart:n,onGoToBasket:i,cartSeeded:o,onCartSeeded:l,reviewGateComplete:c,onReviewGateComplete:p,internal:f=!1}){let b=!f&&Qs()==="QZA6-MRA4",d=b?"quote":"basket",{results:h,lineItems:w,parseReport:E,timings:D}=e,[m,u]=(0,_e.useState)({}),g=Cn(),[v,N]=(0,_e.useState)({}),[R,T]=(0,_e.useState)({}),[z,G]=(0,_e.useState)(""),[K,xe]=(0,_e.useState)(null),[Ee,Ge]=(0,_e.useState)(1),[Qe,Ie]=(0,_e.useState)(!1);(0,_e.useEffect)(()=>{Ie(new URLSearchParams(window.location.search).get("debug")==="1")},[]);let[ue,Q]=(0,_e.useState)("simple"),[se,Ne]=(0,_e.useState)(f?"list":"tile"),[lt,Ye]=(0,_e.useState)(!1),[ge,We]=(0,_e.useState)(null),[he,W]=(0,_e.useState)(""),[Re,Be]=(0,_e.useState)([]),[ye,et]=(0,_e.useState)(!1),[Ze,M]=(0,_e.useState)(null),[x,A]=(0,_e.useState)(!1),[I,ce]=(0,_e.useState)(null),me=(0,_e.useRef)(null),[ke,k]=(0,_e.useState)(new Set),[j,O]=(0,_e.useState)(new Set),[ne,ee]=(0,_e.useState)(!1);(0,_e.useEffect)(()=>{Ge(1)},[z,K,se]);let C=new Map(h.map(_=>[_.line_id,_])),V=c_(w),X=w.map(_=>{let L=C.get(_.line_id),ve=L?.decision,gt=i_(_),Je=m[_.line_id],Wt=n_(L,Je),zi=a[_.line_id],jw=Je===gd?void 0:v[_.line_id]??(zi&&zi.productId!==Wt?.product_id?aw(zi):Wt),tm=gt?void 0:jw,Gw=_.qty??0;return{item:_,result:L,decision:ve,unmatchable:gt,best:tm,qty:Gw,band:nw(tm?.scores?.overall)}}),pe=Zs(Object.values(a),{wasteFactorEnabled:!1,wasteFactorOverride:0}),Se=0;for(let _ of X){if(_.unmatchable||_.decision?.include_in_quote!==!0||!_.best)continue;let L=a[_.item.line_id];(!L||Ut(L).lineTotal==null)&&(Se+=1)}Se>0&&(pe=null);let ft=_=>!_.unmatchable&&!_.best&&_.decision?.technical_classification!=="no_suitable_candidate"&&Ks(_.result).length>0,Ve=_=>_.best??Ks(_.result)[0],Ir=X.filter(_=>!_.unmatchable&&!_.best).filter(_=>!j.has(_.item.line_id)),ll=X.filter(_=>j.has(_.item.line_id)),Ea=X;if(z.trim()){let _=z.trim().toLowerCase();Ea=Ea.filter(L=>L.item.description_original?.toLowerCase().includes(_)||Ve(L)?.description?.toLowerCase().includes(_))}if(K){let _=K==="asc"?1:-1;Ea=[...Ea].sort((L,ve)=>_*(L.item.description_original||"").localeCompare(ve.item.description_original||""))}let hr=Math.max(1,Math.ceil(Ea.length/el)),Ft=Math.min(Ee,hr),It=Ea.slice((Ft-1)*el,Ft*el),Xd=It.filter(_=>!_.unmatchable&&_.best),$d=It.filter(_=>ft(_)),hc=It.filter(_=>!_.unmatchable&&(_.best||ft(_))),Zd=It.filter(_=>_.unmatchable||!_.best&&!ft(_)),J=ge?X.find(_=>_.item.line_id===ge)??null:null,Rw=!f&&!c&&!J&&Ir.length>0,Gn=(0,_e.useRef)(null),Qn=()=>{let _=me.current;if(!_)return;let{top:L,left:ve,width:gt,height:Je}=_.getBoundingClientRect(),zi=_.querySelector(".bom-toolbar-btn")?.closest("td")?.getBoundingClientRect().left;ce({top:L,left:ve,width:zi?zi-ve:gt,height:Je})};(0,_e.useEffect)(()=>(window.addEventListener("scroll",Qn,!0),window.addEventListener("resize",Qn),()=>{window.removeEventListener("scroll",Qn,!0),window.removeEventListener("resize",Qn)})),(0,_e.useEffect)(()=>{let _=L=>{Gn.current&&!L.composedPath().includes(Gn.current)&&Gn.current.removeAttribute("open")};return document.addEventListener("click",_),()=>document.removeEventListener("click",_)},[]);let Ei=_=>{We(_),W("")},Uw=()=>{if(!ge)return;let _=a[ge];if(_){u(L=>({...L,[ge]:_.productId})),N(L=>({...L,[ge]:aw(_)}));return}u(L=>{let ve={...L};return delete ve[ge],ve}),N(L=>{let ve={...L};return delete ve[ge],ve})},br=(_=!1)=>{let L=ge?a[ge]:void 0;!_&&L&&J?.best&&L.productId!==J.best.product_id&&!window.confirm("You have selected a new product. Leave without updating it?")||(_||Uw(),We(null),ee(!1))},Dw=_=>{if(k(L=>new Set(L).add(_)),Ir.some(L=>L.item.line_id!==_)){br(!0);return}p(),br(!0)},Bw=_=>{if(bc(_),O(L=>new Set(L).add(_)),Ir.some(L=>L.item.line_id!==_)){br(!0);return}p(),br(!0)},Ow=()=>{O(_=>new Set([..._,...Ir.map(L=>L.item.line_id)])),p()},Kd=()=>{J?.best&&(Jd(J.item.line_id,J.best),r(Mi(J)),ne?Dw(J.item.line_id):br(!0))},Pd=Zd.length>0?(0,s.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,s.jsxs)("div",{className:"results-tile-section__head",children:[(0,s.jsx)("h3",{children:"Require Matching"}),(0,s.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,s.jsx)("div",{className:"results-unmatched-list",children:Zd.map(_=>{let{item:L,qty:ve}=_;return(0,s.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>Ei(L.line_id),children:[(0,s.jsx)("span",{className:"results-unmatched-card__main",children:(0,s.jsx)("span",{className:"results-unmatched-card__title",children:Pr(L,w)})}),(0,s.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},L.line_id)})})]}):null,bc=_=>{u(L=>({...L,[_]:gd})),N(L=>({...L,[_]:void 0})),T(L=>({...L,[_]:void 0})),n(_)},vc=(_,L)=>{u(ve=>({...ve,[_]:L.product_id})),N(ve=>({...ve,[_]:L}))},Jd=(_,L)=>{L.method==="catalogue_search"&&T(ve=>({...ve,[_]:L}))};function ix(){g("downloaded",{type:"schedule",lines:X.length}),ew(X.map(({item:_,best:L,qty:ve,band:gt,unmatchable:Je,decision:Wt})=>({item:_,best:L,qty:ve,band:gt,unmatchable:Je,decision:Wt})))}function Mi(_){let L=_.best??Ks(_.result)[0];return Kr(L,{lineId:_.item.line_id,description:_.item.description_original,unit:_.item.unit,qty:_.qty,linkedContext:_.item.linked_group_role==="dependent"&&_.item.linked_group_id?w.filter(ve=>ve.linked_group_id===_.item.linked_group_id&&ve.linked_group_role==="anchor").slice(0,1).map(ve=>{let gt=a[ve.line_id];return{line_id:ve.line_id,product_id:gt?.productId??null,measurements_mm:gt?.measurementsMm??ve.attrs.measurements_mm,description:gt?.description??ve.description_original,qty:ve.qty,unit:ve.unit,role:"anchor"}}):void 0})}(0,_e.useEffect)(()=>{if(!o){for(let _ of X)!_.unmatchable&&_.best&&r(Mi(_));l()}},[o]),(0,_e.useEffect)(()=>{for(let _ of X)!a[_.item.line_id]&&!_.unmatchable&&_.best&&r(Mi(_))},[e]),(0,_e.useEffect)(()=>{if(!ge){Be([]),M(null),et(!1);return}let _=he.trim();if(!_){Be([]),M(null),et(!1);return}let L=!1,ve=window.setTimeout(async()=>{try{et(!0),M(null);let gt=await fetch(Lt(`/api/catalogue/search?q=${encodeURIComponent(_)}`),{headers:wi()}),Je=await Kt(gt);if(!gt.ok)throw new Error(Je?.error||Je?.message||"Failed to search catalogue");L||Be(Array.isArray(Je?.items)?Je.items:[])}catch(gt){L||(Be([]),M(gt?.message||"Failed to search catalogue"))}finally{L||et(!1)}},250);return()=>{L=!0,window.clearTimeout(ve)}},[he,ge]);let wc=Object.keys(a).length,Ma=he.trim(),Fd=Ks(J?.result),sl=J?.decision?.technical_classification==="no_suitable_candidate"||!!J&&!J.best,Id=J?.decision?.technical_classification!=null,Wd=J?.decision?.reason??(sl?"No catalogue candidate found. Refine the request or search the catalogue.":null),Lw=Re.map(_=>({product_id:_.product_id,description:_.description,source_list:_.source_list,price:_.price,price_basis:_.price_basis,uoi_count:_.uoi_count??null,uoi:_.uoi,pdp_photo_url:_.pdp_photo_url??null,conversion:_.conversion,measurements_mm:_.measurements_mm??[],scores:{dimension:0,grade:0,brand:0,fuzzy:0,bm25:0,overall:0},method:"catalogue_search"})),Yn=Ma?Lw:Fd,Ti=J?R[J.item.line_id]:void 0,Vn=!Ma&&Ti&&!Yn.some(_=>_.product_id===Ti.product_id)?[...Yn,Ti]:Yn,em=(()=>{let _=Vn.slice(0,Ma?12:3);return Ma||!Ti||_.some(L=>L.product_id===Ti.product_id)?_:[..._,Ti]})(),cl=!!J?.best&&a[J.item.line_id]?.productId===J.best.product_id,Hw=!!J?.best&&!!a[J.item.line_id]&&!cl;return(0,s.jsxs)("div",{className:"wizard-step entry-stage",children:[(0,s.jsxs)("div",{className:`quick-order-card${f?"":" quick-order-card--customer"}`,children:[(0,s.jsx)("div",{className:`quick-order-hero${f?"":" quick-order-hero--customer"}`,children:f?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,s.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,s.jsx)("h1",{children:"Your Results"}),(0,s.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,s.jsx)("strong",{children:pe==null?"Calculating\u2026":st(pe)})," Est. total"]})]}),(0,s.jsx)("p",{children:"Each line item from your schedule matched against your catalogue, ranked by confidence."})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{children:"Review your matched products"}),(0,s.jsxs)("p",{children:["Check you're happy with these items, then click ",b?"View Quote":"View Basket"," to continue."]})]}),(0,s.jsxs)("button",{type:"button",className:"results-total-action",onClick:i,"aria-label":b?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:b?"View Quote":"View Basket"}),(0,s.jsx)("strong",{children:pe==null?"Calculating\u2026":st(pe)})]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Ht,{})})]})]})}),(0,s.jsxs)("div",{className:"quick-order-panel",style:{paddingTop:16},children:[Qe&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:12},children:(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn","aria-pressed":lt,onClick:()=>Ye(_=>!_),children:lt?"Hide timings":"Show timings"})}),Qe&<&&(0,s.jsx)(p_,{...D}),!b&&(0,s.jsx)("div",{className:"results-toolbar-row",children:!J&&(0,s.jsxs)("div",{className:"results-summary",style:{marginBottom:0},children:[Se>0&&(0,s.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,s.jsx)("strong",{children:Se})," need pricing"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:z,onChange:_=>G(_.target.value),"aria-label":"Search line items"}),!f&&(0,s.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,s.jsx)("button",{type:"button",className:`results-view-toggle__btn${se==="tile"?" is-active":""}`,"aria-pressed":se==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>Ne("tile"),children:(0,s.jsxs)("svg",{width:"18",height:"12",viewBox:"0 0 15 10",fill:"currentColor",children:[(0,s.jsx)("rect",{x:"0.5",y:"0.5",width:"4",height:"4"}),(0,s.jsx)("rect",{x:"5.5",y:"0.5",width:"4",height:"4"}),(0,s.jsx)("rect",{x:"10.5",y:"0.5",width:"4",height:"4"}),(0,s.jsx)("rect",{x:"0.5",y:"5.5",width:"4",height:"4"}),(0,s.jsx)("rect",{x:"5.5",y:"5.5",width:"4",height:"4"}),(0,s.jsx)("rect",{x:"10.5",y:"5.5",width:"4",height:"4"})]})}),(0,s.jsx)("button",{type:"button",className:`results-view-toggle__btn${se==="list"?" is-active":""}`,"aria-pressed":se==="list","aria-label":"List view",title:"List view",onClick:()=>Ne("list"),children:(0,s.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,s.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,s.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,s.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),Qe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Q(_=>_==="simple"?"detailed":"simple"),children:ue==="detailed"?"Hide detailed view":"Show detailed view"}),(0,s.jsxs)("details",{ref:Gn,style:{position:"relative"},children:[(0,s.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort line items",style:{fontSize:16},children:"\u21C5"}),(0,s.jsx)("div",{className:"sort-menu-panel",children:r_.map(_=>{let L=K===_.dir;return(0,s.jsxs)("button",{type:"button",className:`sort-menu-item${L?" is-active":""}`,onClick:()=>{xe(L?null:_.dir),Gn.current?.removeAttribute("open")},children:[(0,s.jsx)("span",{className:"sort-menu-item__check",children:L?"\u2713":""}),_.label]},_.dir)})})]})]})]})}),se==="tile"||J?(0,s.jsxs)(s.Fragment,{children:[J?(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop",role:"dialog","aria-modal":"true","aria-label":"Product options",onClick:()=>br(),children:(0,s.jsxs)("section",{className:"quick-order-workflow-modal results-review-modal",onClick:_=>_.stopPropagation(),children:[(0,s.jsx)("button",{type:"button",className:"quick-order-workflow-close results-review-modal__close",onClick:()=>br(),"aria-label":"Close product options",children:(0,s.jsx)(Ko,{})}),(0,s.jsx)("div",{className:"results-review-page",children:f?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"results-review-page__top",children:[(0,s.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:()=>br(),children:[(0,s.jsx)(Zr,{}),"Back to results"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[Qe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Q(_=>_==="simple"?"detailed":"simple"),children:ue==="detailed"?"Hide detailed info":"Show detailed info"}),(0,s.jsx)("div",{className:"results-review-searchbar",children:(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:he,onChange:_=>W(_.target.value),"aria-label":"Search database candidates"})}),(0,s.jsx)("div",{className:"results-candidate-actions",children:(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>bc(J.item.line_id),children:"Clear selected product"})})]})]}),(0,s.jsxs)("div",{className:"results-review-page__hero",children:[(0,s.jsx)("div",{className:"results-review-page__image-wrap",children:(0,s.jsx)("img",{className:"fill-img results-review-page__image",src:Qa(Ve(J)?.description||J.item.description_original,Ve(J)?.product_id,Ve(J)?.pdp_photo_url),alt:""})}),(0,s.jsxs)("div",{className:"results-review-page__summary",children:[(0,s.jsx)("h2",{children:Pr(J.item,w)}),(0,s.jsxs)("p",{className:"results-review-page__meta",children:[_i(J.qty)," ",ka(J.item.unit,J.qty)]}),J.best?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:J.best.description}),J.best.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Tn(J.best.price,J.best.price_basis)}):null]}):Ve(J)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:Ve(J)?.description}),Ve(J)?.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Tn(Ve(J)?.price??null,Ve(J)?.price_basis??null)}):null,(0,s.jsx)("div",{className:"results-row-meta",children:"Best reviewed alternative - not yet selected"})]}):(0,s.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line item."}),mr(J.item)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[(0,s.jsx)(fd,{meta:V.get(J.item.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:zn(J.item)})]}):null,(0,s.jsx)("div",{className:"results-review-page__actions",children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[J.item.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[J.item.line_id]?n(J.item.line_id):(J.best&&Jd(J.item.line_id,J.best),r(Mi(J)))},disabled:!J.best,"aria-label":a[J.item.line_id]?f?"Remove from selection":`Remove from ${d}`:f?"Add to selection":`Add to ${d}`,children:a[J.item.line_id]?"\u2713 Added":f?"+ Add to selection":`Add to ${d}`})})]})]}),ye?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,!ye&&Ze?(0,s.jsx)("div",{className:"results-empty-card",children:Ze}):null,!ye&&!Ze&&Ma&&Yn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No candidate products match this database search."}):!ye&&!Ze?(0,s.jsx)(h_,{item:J.item,candidates:Yn,result:J.result,decision:J.decision,unmatchable:J.unmatchable,selectedProductId:J.best?.product_id??null,detailMode:ue,linkedGroupMeta:mr(J.item)?V.get(J.item.linked_group_id):void 0,onPick:_=>vc(J.item.line_id,_),onClear:()=>bc(J.item.line_id),showAll:f||Qe||Ma.length>0,internal:f,debugEnabled:Qe,forceReviewNote:!0}):null]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("section",{className:"customer-review-request",children:[(0,s.jsx)("span",{className:"customer-review-eyebrow",children:"Original request"}),(0,s.jsx)("strong",{children:Pr(J.item,w)||"Original request"})]}),Wd?(0,s.jsxs)("section",{className:"customer-review-ai",children:[(0,s.jsx)("strong",{children:sl?"Exact match not found:":"AI review:"})," ",Wd]}):null,(0,s.jsxs)("section",{className:"customer-review-options",children:[(0,s.jsx)("div",{className:"customer-review-options__head",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:sl?"We couldn't find a suitable product":Id?"Choose a product":"We couldn't review this item"}),(0,s.jsx)("p",{children:sl?Fd.length>0?"These AI-reviewed alternatives may be useful, but need approval.":"Search the catalogue to choose an alternative.":Id?`Select the option you want to add to your ${d}.`:"Search the catalogue to choose a product."})]})}),!Ma&&Vn.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:em.map(_=>{let L=_.product_id===J.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${L?" is-selected":""}`,onClick:()=>vc(J.item.line_id,_),"aria-pressed":L,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Qa(_.description,_.product_id,_.pdp_photo_url),alt:"",width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:_.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:_.price!=null?`\xA3${Tn(_.price,_.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:L?"Selected":"Choose"})]},_.product_id)})}):null,Vn.length>0&&(0,s.jsx)("div",{className:"customer-review-divider",children:(0,s.jsx)("span",{children:"or"})}),(0,s.jsxs)("label",{className:"customer-review-search",children:[(0,s.jsx)("span",{children:"Search our full catalogue"}),(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products...",value:he,onChange:_=>W(_.target.value),"aria-label":"Search catalogue"})]}),Ma&&ye?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,Ma&&!ye&&Ze?(0,s.jsx)("div",{className:"results-empty-card",children:Ze}):null,Ma&&!ye&&!Ze&&Vn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No products match this search."}):null,Ma&&!ye&&!Ze&&Vn.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:em.map(_=>{let L=_.product_id===J.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${L?" is-selected":""}`,onClick:()=>vc(J.item.line_id,_),"aria-pressed":L,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Qa(_.description,_.product_id,_.pdp_photo_url),alt:"",width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:_.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:_.price!=null?`\xA3${Tn(_.price,_.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:L?"Selected":"Choose"})]},_.product_id)})}):null]}),J.best?Hw?(0,s.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,s.jsx)("button",{type:"button",className:"cta-btn customer-review-add",onClick:()=>{Kd()},children:(0,s.jsx)("span",{children:"Update product"})}),(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-add",onClick:()=>n(J.item.line_id),children:(0,s.jsx)("span",{children:`Remove from ${d}`})})]}):(0,s.jsx)("button",{type:"button",className:`cta-btn customer-review-add${cl?" cta-btn-secondary":""}`,onClick:()=>{cl?n(J.item.line_id):Kd()},children:(0,s.jsx)("span",{children:cl?`Remove from ${d}`:`Add selected product to ${d}`})}):null,ne?(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-skip",onClick:()=>Bw(J.item.line_id),children:"Skip this item"}):null]})})]})}):null,(0,s.jsxs)("div",{className:"results-tile-layout",children:[Ea.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No line items match the current search/filter."}):null,hc.length>0?(0,s.jsx)("section",{className:"results-tile-section","aria-label":"Matched and review items",children:(0,s.jsx)("div",{className:"results-tile-grid",children:hc.map(_=>{let{item:L,best:ve,qty:gt}=_,Je=Ve(_),Wt=!ve&&ft(_);return(0,s.jsxs)("article",{className:"results-tile-card",children:[(0,s.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>Ei(L.line_id),"aria-label":`Review match for ${Pr(L,w)||"item"}`,children:[(0,s.jsxs)("div",{className:"results-tile-card__media",children:[Wt||mr(L)?(0,s.jsxs)("div",{className:"results-tile-card__badges",children:[mr(L)?(0,s.jsx)(fd,{meta:V.get(L.linked_group_id)}):(0,s.jsx)("span",{}),Wt?(0,s.jsx)("span",{style:{padding:"6px 10px",borderRadius:999,background:"#fef3c7",color:"#92400e",fontSize:12,fontWeight:700,lineHeight:1},children:"Partially matched"}):null]}):null,(0,s.jsx)("img",{className:"fill-img results-tile-card__image",src:Qa(Je?.description||L.description_original,Je?.product_id,Je?.pdp_photo_url),alt:""})]}),(0,s.jsxs)("div",{className:"results-tile-card__body",children:[Je?(0,s.jsx)(s.Fragment,{children:(0,s.jsx)("div",{className:"results-tile-card__heading",children:(0,s.jsx)("div",{className:"results-tile-card__title",children:Je.description})})}):(0,s.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line item."}),(0,s.jsx)("div",{className:"results-tile-card__match",children:Je?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-tile-card__match-label",children:Wt?"\u21B3 partially matched from":"\u21B3 matched from"}),(0,s.jsx)("div",{className:"results-tile-card__match-name",children:Pr(L,w)}),mr(L)?(0,s.jsx)("div",{className:"results-row-meta",children:zn(L)}):null]}):(0,s.jsx)("span",{className:"results-empty-hint",children:"No matched product selected."})})]}),(0,s.jsx)("span",{className:"results-tile-card__hover-prompt","aria-hidden":"true",children:"Click to view options"})]}),(0,s.jsxs)("div",{className:"results-tile-card__actions",children:[f&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ei(L.line_id),children:"Review"}),(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[L.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[L.line_id]?n(L.line_id):r(Mi(_))},disabled:!Je,"aria-label":a[L.line_id]?f?"Remove from selection":`Remove from ${d}`:f?"Add to selection":`Add to ${d}`,children:a[L.line_id]?"\u2713 Added":f?"+ Add":`Add to ${d}`})]})]},L.line_id)})})}):null,Pd]})]}):(0,s.jsxs)(s.Fragment,{children:[I&&(0,s.jsx)("div",{className:"results-table__hover-overlay",style:I,"aria-hidden":"true",children:"Click to view options"}),(0,s.jsx)("div",{className:"bom-table-wrap",children:(0,s.jsxs)("table",{className:"bom-table results-table","aria-label":"Matched line items",children:[(0,s.jsxs)("colgroup",{children:[(0,s.jsx)("col",{className:"col-item"}),(0,s.jsx)("col",{style:{width:"220px"}}),(0,s.jsx)("col",{style:{width:"100px"}}),ue==="simple"&&(0,s.jsx)("col",{style:{width:"110px"}})]}),(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"bom-col-header",children:[(0,s.jsx)("th",{style:{textAlign:"left"},children:"Description"}),(0,s.jsx)("th",{style:{textAlign:"center"},children:"Product Matched"}),(0,s.jsx)("th",{style:{textAlign:"center"},children:"Price"}),ue==="simple"&&(0,s.jsx)("th",{style:{textAlign:"center"},children:f?"Selection":b?"Quote":"Basket"})]})}),(0,s.jsxs)("tbody",{children:[Ea.length===0&&(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:ue==="simple"?4:3,className:"results-empty-hint",style:{padding:"16px 8px"},children:"No line items match the current search/filter."})}),hc.map(_=>{let{item:L,result:ve,decision:gt,best:Je}=_;return(0,s.jsxs)("tr",{className:"bom-row results-table__review-row",onClick:()=>Ei(L.line_id),onMouseEnter:Wt=>{me.current=Wt.currentTarget,Qn()},onMouseLeave:()=>{me.current=null,ce(null)},children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{className:"bom-component-name",children:Pr(L,w)}),mr(L)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,s.jsx)(fd,{meta:V.get(L.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:zn(L)})]}):null]}),(0,s.jsx)("td",{children:Je?(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"results-match-cell-text",title:Je.description,children:Je.description}),ue==="detailed"&>?.technical_classification&&(0,s.jsxs)("div",{className:"results-row-meta",children:[o_(gt.technical_classification),gt.approval_required?" - approval required":""]})]}):(0,s.jsx)("span",{className:"results-empty-hint"})}),(0,s.jsx)("td",{style:{textAlign:"center"},children:Je?.price!=null?Tn(Je.price,Je.price_basis):"-"}),ue==="simple"&&(0,s.jsx)("td",{style:{textAlign:"center"},children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[L.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,style:{width:84,justifyContent:"center"},onClick:Wt=>{Wt.stopPropagation(),a[L.line_id]?n(L.line_id):r(Mi(_))},"aria-label":a[L.line_id]?f?"Remove from selection":`Remove from ${d}`:f?"Add to selection":`Add to ${d}`,children:a[L.line_id]?"\u2713 Added":f?"+ Add":`Add to ${d}`})})]},L.line_id)})]})]})}),Pd]}),!J&&hr>1&&(0,s.jsxs)("div",{className:"results-pagination",children:[(0,s.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(Ft-1)*el+1,"\u2013",Math.min(Ft*el,Ea.length)," of ",Ea.length]}),(0,s.jsxs)("div",{className:"results-pagination-controls",children:[(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ge(Ft-1),disabled:Ft===1,children:"Previous"}),(0,s.jsxs)("span",{className:"results-pagination-page",children:["Page ",Ft," of ",hr]}),(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ge(Ft+1),disabled:Ft===hr,children:"Next"})]})]}),(E.itemCount!=null||E.headingCount!=null||E.skippedCount!=null)&&(0,s.jsxs)("div",{className:"results-summary",style:{marginTop:16},children:[E.itemCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:E.itemCount})," items parsed"]}),E.headingCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:E.headingCount})," headings"]}),E.skippedCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:E.skippedCount})," rows skipped"]})]}),(0,s.jsxs)("div",{className:"disclaimer-box",children:[(0,s.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,s.jsx)("p",{className:"disclaimer-text",children:"These matches are generated automatically and should be reviewed before purchase."})]}),!J&&(0,s.jsxs)("div",{className:"btn-row results-actions",children:[(0,s.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:(wc>0,"0 1 30%"),gap:10,justifyContent:"center"},onClick:()=>A(!0),"aria-label":"Start over",children:[(0,s.jsx)(dd,{}),(0,s.jsx)("span",{children:"Start Over"})]}),wc>0&&(0,s.jsxs)("button",{className:"cta-btn",style:{flex:"0 1 70%"},onClick:i,"aria-label":f?"View selection":b?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[f?"View Selection":b?"View Quote":"View Basket"," (",wc,")"]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Ht,{})})]})]})]})]}),Rw&&(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop review-gate-modal-backdrop",role:"dialog","aria-modal":"true","aria-labelledby":"review-gate-title",children:(0,s.jsxs)("section",{className:"quick-order-workflow-modal review-gate-modal",children:[(0,s.jsxs)("div",{className:"review-gate-modal__header",children:[(0,s.jsx)("h2",{id:"review-gate-title",children:"Choose products for these items"}),(0,s.jsx)("p",{children:"We couldn\u2019t find a clear match for these items, so we need your help. Select an option from the suggestions, search the catalogue, or leave the item out."})]}),(0,s.jsx)("div",{className:"review-gate-list",children:Ir.map(_=>{let L=ke.has(_.item.line_id),ve=ft(_);return(0,s.jsx)("div",{className:`review-gate-item${L?" is-reviewed":""}`,children:(0,s.jsxs)("button",{type:"button",className:"review-gate-item__review",onClick:()=>{ee(!0),Ei(_.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Pr(_.item,w)}),(0,s.jsx)("span",{children:_.decision?.reason||(ve?"A close alternative is available but needs confirmation.":"No product has been selected for this item yet.")})]}),(0,s.jsx)("span",{className:"review-gate-item__action",children:L?"Choice made":"Choose a product"})]})},_.item.line_id)})}),(0,s.jsx)("button",{type:"button",className:"review-gate-skip",onClick:Ow,children:"Skip all"}),ll.length>0?(0,s.jsxs)("div",{className:"review-gate-skipped",children:[(0,s.jsx)("strong",{children:"Skipped"}),ll.map(_=>(0,s.jsxs)("button",{type:"button",className:"review-gate-item is-skipped",onClick:()=>{O(L=>{let ve=new Set(L);return ve.delete(_.item.line_id),ve}),ee(!0),Ei(_.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Pr(_.item,w)}),(0,s.jsx)("span",{children:`Not added to your ${d}.`})]}),(0,s.jsx)("span",{className:"review-gate-item__action",children:"Choose a product"})]},_.item.line_id))]}):null]})}),x&&(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop start-over-modal",role:"dialog","aria-modal":"true","aria-labelledby":"start-over-modal-title",children:(0,s.jsxs)("div",{className:"modal-card start-over-modal__card",children:[(0,s.jsx)("h2",{id:"start-over-modal-title",className:"modal-title",children:"Start over?"}),(0,s.jsxs)("p",{className:"modal-body",children:["This will clear the current results and ",b?"quote":"basket"," and take you back to the start."]}),(0,s.jsxs)("div",{className:"modal-actions",children:[(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-secondary",onClick:()=>A(!1),children:"Cancel"}),(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-danger",onClick:()=>{A(!1),t()},autoFocus:!0,children:"Start Over"})]})]})})]})}var xt=Y(Ke());var q=Y(ae()),b_=.2,tl=10,ow="Enter a valid email address so we can send your quote.",v_=(e,t)=>{let a=`${t.requestedAmount} ${xa(t.requestedUnit,t.requestedAmount)}`,r=`${t.requiredSellUnits} ${xa(t.sellUnit,t.requiredSellUnits??0)}`,n=e.unitConversions?.find(i=>i.requestUom===t.requestedUnit);return n&&n.quantityPerSaleUnit<1?`${a} requested \u2192 order ${r} (${Math.round(1/n.quantityPerSaleUnit)} ${xa(t.sellUnit,2)} per ${xa(t.requestedUnit,1)})`:e.coverageQty&&/^m per /i.test(e.coverageUom??"")?`${a} requested \u2192 order ${r} (${e.coverageQty} ${e.coverageUom})`:`${a} requested \u2192 order ${r}`},w_=e=>["box","pack"].includes(e.requestedUnit)?"Pack size needed to calculate the order quantity.":`This product is sold by ${xa(e.sellUnit,1)}.`;function y_(){return(0,q.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,q.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,q.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),(0,q.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,q.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function al(){return(0,q.jsx)("svg",{width:"8",height:"5",viewBox:"0 0 8 5",fill:"none",children:(0,q.jsx)("path",{d:"M1 4L4 1L7 4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function rl({cart:e,onUpdateQty:t,onUpdateSellUnits:a,onResolveConversions:r,onRemove:n,onBack:i,onStartNewQuote:o,internal:l=!1}){let c=(0,xt.useId)(),p=!l&&Qs()==="QZA6-MRA4",f=Object.values(e),[b,d]=(0,xt.useState)(""),[h,w]=(0,xt.useState)(!1),[E,D]=(0,xt.useState)(!1),m=Cn(),[u,g]=(0,xt.useState)(""),[v,N]=(0,xt.useState)({}),[R,T]=(0,xt.useState)({}),[z,G]=(0,xt.useState)(1),[K,xe]=(0,xt.useState)({}),[Ee,Ge]=(0,xt.useState)(!1),[Qe,Ie]=(0,xt.useState)("0"),ue=(0,xt.useRef)(new Set);(0,xt.useEffect)(()=>{if(!r)return;for(let A of Object.values(e))Ut(A).requiredSellUnits!=null&&ue.current.delete(A.lineId);let x=Object.values(e).filter(A=>A.productId!=="-"&&Ut(A).requiredSellUnits==null&&!ue.current.has(A.lineId));x.length!==0&&(x.forEach(A=>ue.current.add(A.lineId)),fetch(Lt("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({lines:x.map(A=>({line_id:A.lineId,product_id:A.productId,requested_description:A.requestedDescription??A.description,requested_qty:A.qty,requested_uom:A.unit||null,linked_context:A.linkedContext??[],selected_description:A.description,selected_uoi:A.uoi,selected_uoi_count:A.uoiCount,selected_conversion:{sales_uom_normalised:A.salesUomNormalised,conversion_type:A.conversionType,sales_unit_size:A.salesUnitSize,sales_unit_size_uom:A.salesUnitSizeUom,coverage_qty:A.coverageQty,coverage_uom:A.coverageUom}}))})}).then(A=>A.ok?Kt(A):null).then(A=>{let I={};for(let ce of A?.data?.items??A?.items??[]){let me=ce?.conversion;if(!me||typeof ce?.line_id!="string")continue;let ke=e[ce.line_id];I[ce.line_id]={conversionType:me.conversion_type,requestUomsSupported:me.request_uoms_supported,salesUomNormalised:me.sales_uom_normalised,salesUnitSize:me.sales_unit_size,salesUnitSizeUom:me.sales_unit_size_uom,coverageQty:me.coverage_qty,coverageUom:me.coverage_uom,roundingRule:me.rounding_rule,conversionConfidence:me.conversion_confidence,conversionNotes:me.conversion_notes,...ke?.qty===0&&Number.isFinite(me.suggested_order_qty)&&me.suggested_order_qty>0?{qty:me.suggested_order_qty,unit:me.suggested_order_uom||ke.unit}:{}}}Object.keys(I).length>0&&r(I)}).catch(A=>console.error("Catalogue conversion resolution failed",A)))},[e,r]);function Q(x){N(A=>{let I={...A};return delete I[x],I})}function se(x,A){let I=parseFloat(A);!isNaN(I)&&I>=0&&t(x,I),Q(x)}function Ne(x,A,I){t(x,Math.max(0,A+I)),Q(x)}function lt(x){T(A=>{let I={...A};return delete I[x],I})}function Ye(x,A){let I=parseFloat(A);!isNaN(I)&&I>=0&&a(x,I),lt(x)}function ge(x,A,I){a(x,Math.max(0,A+I)),lt(x)}async function We(){let x=b.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(x)){g(ow);return}g(""),D(!0);try{let A=await fetch(Lt("/api/quote-requests"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({email:x,items:he.map(({item:I,pricing:ce})=>{let me=ce.requiredSellUnits??ce.requestedAmount,ke=ce.requiredSellUnits!=null?ce.sellUnit:ce.requestedUnit;return{product_id:I.productId,description:I.description,quantity:me,unit:xa(ke,me),unit_price:ce.requiredSellUnits!=null?ce.unitPrice:null,line_total:ce.lineTotal}})})});if(!A.ok){let I=await Kt(A);console.error("Quote request failed",A.status,I?.message),g(A.status===429?"You've sent a few requests already. Please try again in a few minutes.":"Your request couldn't be sent. Please try again, or contact us if it keeps happening.");return}m("quote_requested",{items:he.length,total:Math.round(Be*100)/100}),w(!0),window.scrollTo(0,0)}catch{g("Your request couldn't be sent. Check your connection and try again.")}finally{D(!1)}}let he=f.map(x=>({item:x,pricing:Ut(x,{wasteFactorEnabled:Ee,wasteFactorOverride:Math.max(0,Number.parseFloat(Qe)||0)/100})})),W=Zs(f,{wasteFactorEnabled:Ee,wasteFactorOverride:Math.max(0,Number.parseFloat(Qe)||0)/100}),Re=W*b_,Be=W+Re,ye=(0,xt.useRef)({items:he.length,total:Math.round(Be*100)/100});(0,xt.useEffect)(()=>{m("basket_viewed",ye.current)},[m]);let et=Math.max(1,Math.ceil(he.length/tl)),Ze=Math.min(z,et),M=he.slice((Ze-1)*tl,Ze*tl);return h?(0,q.jsx)("div",{className:"wizard-step entry-stage",children:(0,q.jsxs)("div",{className:"quote-request-sent",role:"status",children:[(0,q.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,q.jsx)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,q.jsx)("polyline",{points:"5 12.5 10 17.5 19 7"})})}),(0,q.jsx)("h1",{children:"Quote requested"}),(0,q.jsxs)("p",{children:["You're all done. We'll email your sharper price to ",(0,q.jsx)("strong",{children:b.trim()}),", usually within one working day."]}),(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,q.jsx)("span",{children:"Start a new quote"})}),(0,q.jsx)("p",{className:"quote-request-sent-note",children:"Nothing is charged until you approve the quote."})]})}):(0,q.jsx)("div",{className:`wizard-step entry-stage${p?" basket-layout--qza6-mra4":""}`,children:(0,q.jsxs)("div",{className:`quick-order-card${l?"":" quick-order-card--customer"}`,children:[(0,q.jsxs)("div",{className:`quick-order-hero${l?"":" quick-order-hero--customer"}`,children:[l&&(0,q.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,q.jsxs)("div",{className:"basket-hero-copy",children:[p&&(0,q.jsxs)("button",{type:"button",className:"cta-btn cta-btn-secondary basket-hero-back",onClick:i,children:[(0,q.jsx)(Zr,{}),(0,q.jsx)("span",{children:"Back to results"})]}),(0,q.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,q.jsx)("h1",{children:l?"Your Selection":p?"Request a quote":"Your Basket"}),l&&(0,q.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,q.jsx)("strong",{children:f.length})," ",f.length===1?"item":"items"]})]}),(0,q.jsx)("p",{children:l?"Review the items you've added before exporting them for review.":p?"Check your items & quantities below, and we'll do our best to beat list prices.":"Review your quantities and order summary before you buy."})]})]}),(0,q.jsx)("div",{className:"quick-order-panel",style:{paddingTop:16},children:f.length===0?(0,q.jsxs)("div",{className:"quick-order-history-empty",children:[(0,q.jsx)("div",{className:"basket-empty-icon","aria-hidden":"true",children:l?"\u{1F4CB}":"\u{1F9FA}"}),(0,q.jsx)("p",{children:l?"Your selection is empty.":p?"Your quote request is empty.":"Your basket is empty."}),(0,q.jsx)("p",{className:"basket-empty-hint",children:p?"Go back to your results and add items for your quote.":"Go back to your results and add quoted items."}),(0,q.jsx)("div",{className:"btn-row",style:{marginTop:20,justifyContent:"center"},children:(0,q.jsx)("button",{className:"cta-btn",style:{width:"auto",maxWidth:280},onClick:i,"aria-label":"Back to results",children:(0,q.jsx)("span",{children:"Back to Results"})})})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)("div",{className:"basket-layout",children:[(0,q.jsxs)("div",{className:"basket-main",children:[(0,q.jsx)("div",{className:"basket-list","aria-label":l?"Selection items":p?"Quote request items":"Basket items",children:M.map(({item:x,pricing:A})=>{let I=v[x.lineId]??String(A.requestedAmount),ce=A.requestedUnit===A.sellUnit||A.costingMode==="review",me=A.requiredSellUnits==null||A.requestedAmount!==A.requiredSellUnits||A.requestedUnit!==A.sellUnit;return(0,q.jsxs)("article",{className:"basket-card",children:[(0,q.jsxs)("div",{className:"basket-card-top",children:[(0,q.jsx)("img",{className:"basket-card-thumb",src:Qa(x.description,x.productId,x.pdpPhotoUrl),alt:"",width:48,height:48}),(0,q.jsxs)("div",{className:"basket-card-info",children:[(0,q.jsx)("div",{className:"bom-component-name",children:x.description}),me&&A.costingMode!=="review"&&(0,q.jsxs)("button",{type:"button",className:"basket-calc-toggle",onClick:()=>xe(ke=>({...ke,[x.lineId]:!ke[x.lineId]})),"aria-expanded":!!K[x.lineId],children:["How we calculated this",(0,q.jsx)("span",{className:`basket-calc-toggle-chevron${K[x.lineId]?" basket-calc-toggle-chevron--open":""}`,children:(0,q.jsx)(al,{})})]})]}),(0,q.jsx)("div",{className:"basket-card-actions",children:(0,q.jsx)("button",{type:"button",className:"mf-remove-small-btn basket-card-remove",onClick:()=>n(x.lineId),"aria-label":`Remove ${x.description}`,children:(0,q.jsx)(y_,{})})})]}),l&&(0,q.jsxs)("div",{className:"results-detail-block basket-internal-detail",children:[(0,q.jsxs)("dl",{className:"results-detail-grid",children:[(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Conversion type"}),(0,q.jsx)("dd",{children:x.conversionType??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Conversion confidence"}),(0,q.jsx)("dd",{children:x.conversionConfidence??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Sales unit"}),(0,q.jsx)("dd",{children:x.salesUnitSize!=null?(0,q.jsxs)(q.Fragment,{children:[x.salesUnitSize," ",ka(x.salesUnitSizeUom,x.salesUnitSize)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Coverage"}),(0,q.jsx)("dd",{children:x.coverageQty!=null?(0,q.jsxs)(q.Fragment,{children:[x.coverageQty," ",ka(x.coverageUom,x.coverageQty)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Waste factor"}),(0,q.jsx)("dd",{children:x.wasteFactorDefault??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Rounding rule"}),(0,q.jsx)("dd",{children:x.roundingRule??"-"})]})]}),x.conversionNotes&&(0,q.jsx)("p",{className:"results-rerank-note",children:x.conversionNotes})]}),A.costingMode==="review"?(0,q.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,q.jsx)("strong",{children:"Quantity needs confirmation."})," ",w_(A)]}):me&&K[x.lineId]?(0,q.jsx)("p",{className:"basket-calc-text",children:v_(x,A)}):null,(0,q.jsxs)("div",{className:"basket-card-stats",children:[(0,q.jsxs)("div",{className:"basket-stat",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Requested qty"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsxs)("div",{className:"basket-qty-field",children:[(0,q.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:I,disabled:ce,onChange:ke=>N(k=>({...k,[x.lineId]:ke.target.value})),onBlur:ke=>se(x.lineId,ke.target.value),onKeyDown:ke=>{ke.key==="Enter"&&ke.target.blur()},"aria-label":`${x.description} requested quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",disabled:ce,onClick:()=>Ne(x.lineId,parseFloat(I)||0,1),"aria-label":`Increase ${x.description} quantity`,children:(0,q.jsx)(al,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",disabled:ce,onClick:()=>Ne(x.lineId,parseFloat(I)||0,-1),"aria-label":`Decrease ${x.description} quantity`,children:(0,q.jsx)(al,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:ka(A.requestedUnit,parseFloat(I)||0)})]})]}),(0,q.jsxs)("div",{className:"basket-stat basket-stat--right",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Order qty"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsxs)("div",{className:"basket-qty-field",children:[(0,q.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:R[x.lineId]??String(A.requiredSellUnits??""),onChange:ke=>T(k=>({...k,[x.lineId]:ke.target.value})),onBlur:ke=>Ye(x.lineId,ke.target.value),onKeyDown:ke=>{ke.key==="Enter"&&ke.target.blur()},"aria-label":`${x.description} order quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",onClick:()=>ge(x.lineId,parseFloat(R[x.lineId]??String(A.requiredSellUnits??"0"))||0,1),"aria-label":`Increase ${x.description} order quantity`,children:(0,q.jsx)(al,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",onClick:()=>ge(x.lineId,parseFloat(R[x.lineId]??String(A.requiredSellUnits??"0"))||0,-1),"aria-label":`Decrease ${x.description} order quantity`,children:(0,q.jsx)(al,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:ka(A.sellUnit,parseFloat(R[x.lineId]??String(A.requiredSellUnits??"0"))||0)})]})]}),(0,q.jsxs)("div",{className:"basket-stat basket-stat--total",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Total"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsx)("strong",{children:A.lineTotal!=null?st(A.lineTotal):"-"}),A.lineTotal!=null&&(0,q.jsx)("span",{className:"basket-metric-unit",children:"ex. VAT"})]})]})]})]},x.lineId)})}),et>1&&(0,q.jsxs)("div",{className:"results-pagination",children:[(0,q.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(Ze-1)*tl+1,"\u2013",Math.min(Ze*tl,he.length)," of ",he.length]}),(0,q.jsxs)("div",{className:"results-pagination-controls",children:[(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>G(Ze-1),disabled:Ze===1,children:"Previous"}),(0,q.jsxs)("span",{className:"results-pagination-page",children:["Page ",Ze," of ",et]}),(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>G(Ze+1),disabled:Ze===et,children:"Next"})]})]})]}),(0,q.jsxs)("aside",{className:"basket-sidebar",children:[(0,q.jsx)("div",{className:"basket-sidebar-title",children:p?"Quote request summary":"Order summary"}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:p?"List price (ex. VAT)":"Subtotal (ex. VAT)"}),(0,q.jsx)("span",{children:st(W)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:"VAT (20%)"}),(0,q.jsx)("span",{children:st(Re)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row basket-sidebar-row--total",children:[(0,q.jsx)("span",{children:p?"List price (inc. VAT)":"Total"}),(0,q.jsx)("span",{children:st(Be)})]}),!p&&(0,q.jsx)("div",{className:"basket-summary-waste",children:(0,q.jsxs)("div",{className:"basket-waste-control",children:[(0,q.jsxs)("label",{className:"basket-global-waste",children:[(0,q.jsx)("input",{type:"checkbox",checked:Ee,onChange:x=>Ge(x.target.checked)}),(0,q.jsx)("span",{children:"Add waste factor"})]}),(0,q.jsxs)("label",{className:"basket-global-waste-percent",children:[(0,q.jsx)("input",{type:"number",inputMode:"decimal",min:"0",step:"0.1",value:Qe,onChange:x=>Ie(x.target.value),disabled:!Ee,"aria-label":"Waste factor percent"}),(0,q.jsx)("span",{children:"%"})]})]})}),(0,q.jsx)("label",{htmlFor:`${c}-basket-reference`,className:"basket-sidebar-label",children:p?"Enter email for your sharper quote":"Your reference (optional)"}),(0,q.jsx)("input",{id:`${c}-basket-reference`,type:p?"email":"text",className:"basket-sidebar-input",value:b,onChange:x=>{d(x.target.value),p&&g("")},placeholder:p?"you@example.com":"PO number or job reference","aria-invalid":p&&u===ow,"aria-describedby":p&&u?`${c}-basket-reference-error`:void 0}),p&&u&&(0,q.jsx)("p",{id:`${c}-basket-reference-error`,className:"basket-quote-request-error",role:"alert",children:u}),p?(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:()=>{We()},disabled:E,"aria-busy":E,children:(0,q.jsx)("span",{children:E?"Sending\u2026":"Request our best quote"})}):(0,q.jsx)("button",{className:"cta-btn",onClick:()=>{m("downloaded",{type:"basket",items:f.length}),tw(f)},"aria-label":l?"Download selection":"Download basket",children:(0,q.jsx)("span",{children:l?"Download Quote":"Buy Now"})}),(0,q.jsxs)("p",{className:"basket-sidebar-disclaimer",children:[(0,q.jsx)("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),p?"This is a quote request, not an order. We'll confirm our best price, availability and delivery before you approve.":"Prices and availability are estimates and should be confirmed before procurement."]})]})]}),(0,q.jsx)("div",{className:"btn-row results-actions",children:(0,q.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",gap:10,justifyContent:"center"},onClick:i,"aria-label":"Back to results",children:[(0,q.jsx)(Zr,{}),(0,q.jsx)("span",{children:"Back to results"})]})})]})})]})})}var zt=Y(Ke()),lw=Y(ae());function __(e,t){let a={...e,[t.lineId]:t};for(let[r,n]of Object.entries(a)){if(!n.linkedContext)continue;let i=n.linkedContext.find(l=>l.role==="anchor"&&l.line_id&&a[l.line_id]),o=i?.line_id?a[i.line_id]:void 0;if(!(!i||!o||i.product_id===o.productId&&i.description===o.description)){if(n.conversionType!=="basket_line_unit"){a[r]={...n,linkedContext:n.linkedContext.map(l=>l.line_id===i.line_id?{...l,product_id:o.productId,measurements_mm:o.measurementsMm??[],description:o.description}:l)};continue}a[r]={...n,qty:0,sellUnitsOverride:null,linkedContext:n.linkedContext.map(l=>l.line_id===i.line_id?{...l,product_id:o.productId,measurements_mm:o.measurementsMm??[],description:o.description}:l),conversionType:null,requestUomsSupported:null,salesUomNormalised:null,salesUnitSize:null,salesUnitSizeUom:null,coverageQty:null,coverageUom:null,roundingRule:null,conversionConfidence:null,conversionNotes:null}}}return a}var vd=(0,zt.createContext)(null);function Js({children:e,onOpenBasket:t}){let[a,r]=(0,zt.useState)({}),n=(0,zt.useCallback)(d=>{r(h=>__(h,d))},[]),i=(0,zt.useCallback)(d=>{r(h=>{let w={...h};for(let E of d)w[E.lineId]=E;return w})},[]),o=(0,zt.useCallback)(d=>{r(h=>{let w={...h};return delete w[d],w})},[]),l=(0,zt.useCallback)((d,h)=>{r(w=>w[d]?{...w,[d]:{...w[d],qty:h,sellUnitsOverride:null}}:w)},[]),c=(0,zt.useCallback)((d,h)=>{r(w=>w[d]?{...w,[d]:{...w[d],sellUnitsOverride:h}}:w)},[]),p=(0,zt.useCallback)(d=>{r(h=>{let w=!1,E={...h};for(let[D,m]of Object.entries(d))E[D]&&(E[D]={...E[D],...m},w=!0);return w?E:h})},[]),f=(0,zt.useCallback)(()=>r({}),[]),b=(0,zt.useMemo)(()=>({cart:a,count:Object.keys(a).length,addToCart:n,addManyToCart:i,removeFromCart:o,updateCartQty:l,updateCartSellUnits:c,updateCartConversions:p,clearCart:f,openBasket:t??(()=>{})}),[a,n,i,o,l,c,p,f,t]);return(0,lw.jsx)(vd.Provider,{value:b,children:e})}function An(){let e=(0,zt.useContext)(vd);if(!e)throw new Error("useCart must be used inside a <CartProvider>");return e}function Fs(){return(0,zt.useContext)(vd)}var Na=Y(ae()),wd="metron-quick-quote";function Is(e){return(0,Na.jsx)(Js,{children:(0,Na.jsx)(x_,{...e})})}function x_({fullPage:e=!1,hideHeader:t=!1,internal:a=!1}){let[r,n]=(0,He.useState)("entry"),[i,o]=(0,He.useState)(null),[l,c]=(0,He.useState)(""),p=(0,He.useRef)(null),[f,b]=(0,He.useState)(0),[d,h]=(0,He.useState)(null),[w,E]=(0,He.useState)(!1),{cart:D,addToCart:m,addManyToCart:u,removeFromCart:g,updateCartQty:v,updateCartSellUnits:N,updateCartConversions:R,clearCart:T}=An(),[z,G]=(0,He.useState)(!1),K=(0,He.useRef)(new Map),xe=(0,He.useRef)(null),Ee=Gs("quick-quote",xe);(0,He.useEffect)(()=>{Ee("viewed")},[Ee]),(0,He.useEffect)(()=>{for(let W of Object.values(D))Ut(W).requiredSellUnits!=null&&K.current.delete(W.lineId);let he=Object.values(D).filter(W=>{if(W.productId==="-"||Ut(W).requiredSellUnits!=null)return!1;let Re=`${W.productId}|${W.qty}|${W.unit}`;return K.current.get(W.lineId)===Re?!1:(K.current.set(W.lineId,Re),!0)});he.length!==0&&fetch(Lt("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({lines:he.map(W=>({line_id:W.lineId,product_id:W.productId,requested_description:W.requestedDescription??W.description,requested_qty:W.qty,requested_uom:W.unit||null,selected_description:W.description,selected_uoi:W.uoi,selected_uoi_count:W.uoiCount,linked_context:W.linkedContext??[],selected_conversion:{sales_uom_normalised:W.salesUomNormalised,conversion_type:W.conversionType,sales_unit_size:W.salesUnitSize,sales_unit_size_uom:W.salesUnitSizeUom,coverage_qty:W.coverageQty,coverage_uom:W.coverageUom}}))})}).then(W=>W.ok?Kt(W):null).then(W=>{let Re={};for(let Be of W?.data?.items??W?.items??[]){let ye=Be?.conversion;if(!ye||typeof Be?.line_id!="string")continue;let et=D[Be.line_id];Re[Be.line_id]={conversionType:ye.conversion_type,requestUomsSupported:ye.request_uoms_supported,salesUomNormalised:ye.sales_uom_normalised,salesUnitSize:ye.sales_unit_size,salesUnitSizeUom:ye.sales_unit_size_uom,coverageQty:ye.coverage_qty,coverageUom:ye.coverage_uom,roundingRule:ye.rounding_rule,conversionConfidence:ye.conversion_confidence,conversionNotes:ye.conversion_notes,...et?.qty===0&&Number.isFinite(ye.suggested_order_qty)&&ye.suggested_order_qty>0?{qty:ye.suggested_order_qty,unit:ye.suggested_order_uom||et.unit}:{}}}Object.keys(Re).length>0&&R(Re)}).catch(W=>console.error("Catalogue conversion resolution failed",W))},[D,R]);let[Ge,Qe]=(0,He.useState)(!1);(0,He.useEffect)(()=>{let he=window.location.hash,W=null;try{W=JSON.parse(window.sessionStorage.getItem(wd)??"null")}catch{}if(W?.scheduleResult)o("schedule"),h(W.scheduleResult),E(W.reviewGateComplete),G(W.cartSeeded),u(Object.values(W.cart)),he==="#quote-request"?n("basket"):he==="#matched-products"&&n("results");else if(he==="#matched-products"||he==="#quote-request"){let Re=new URL(window.location.href);Re.hash="",window.history.replaceState(window.history.state,"",Re)}Qe(!0)},[]),(0,He.useEffect)(()=>{if(Ge)try{d?window.sessionStorage.setItem(wd,JSON.stringify({scheduleResult:d,reviewGateComplete:w,cartSeeded:z,cart:D})):window.sessionStorage.removeItem(wd)}catch{}},[Ge,d,w,z,D]);let Ie=(0,He.useCallback)(he=>{if(typeof window>"u")return;let W=new URL(window.location.href);W.hash=he==="basket"?"quote-request":"matched-products";let Re=he==="results"&&(window.location.hash==="#matched-products"||window.location.hash==="#quote-request");window.history[Re?"replaceState":"pushState"]({boqQuoteStage:he},"",W)},[]),ue=(0,He.useRef)(!1);(0,He.useEffect)(()=>{let he=W=>{ue.current=!1;let Re=window.location.hash;n(Re==="#quote-request"?"basket":Re==="#matched-products"&&d?"results":"entry");let Be=W.state,ye=window.location.href;setTimeout(()=>{Be?.turbo||window.location.href!==ye||window.history.state?.turbo&&window.history.replaceState(Be,"",ye)})};return window.addEventListener("popstate",he),()=>window.removeEventListener("popstate",he)},[d]);let Q=(0,He.useCallback)(()=>{Ie("basket"),n("basket")},[Ie]),se=(0,He.useCallback)(()=>{if(window.location.hash==="#quote-request"){if(ue.current)return;ue.current=!0,window.history.back();return}n(d?"results":"entry")},[d]),Ne=(0,He.useRef)(r);(0,He.useEffect)(()=>{Ne.current!==r&&(Ne.current=r,window.scrollTo(0,0))},[r]);let lt=()=>{n("entry"),o(null),c(""),b(0),h(null),E(!1),T(),G(!1)},Ye=(0,He.useCallback)(async(he,W,Re=!0)=>{c(""),b(0);let Be=0,ye=()=>{Be=Math.min(Be+1,3),b(Be)};try{let{jobId:et}=await ev(he,W,Re),{promise:Ze,cancel:M}=av(()=>tv(et),5e3,ye,"schedule");p.current=M;let x=await Ze;if(x.status==="failed"||!x.result)throw new Error(x.error||"Failed to process schedule");let A=x.result.lineItems.length,I=x.result.results.filter(ce=>ce.candidates.length>0).length;Ee("results_shown",{lines:A,matched:I,unmatched:A-I}),E(!1),h(x.result),Ie("results"),n("results")}catch(et){Ee("error",{stage:"matching"}),c(et?.message||"Failed to process schedule"),n("entry")}finally{p.current?.(),p.current=null}},[Ie,Ee]),ge=(0,He.useCallback)(async(he,W,Re=!0)=>{let Be=he.trim();if(!Be)return;o("schedule");let ye=new File([Be],"pasted-schedule.txt",{type:"text/plain"});await Ye(ye,W,Re)},[Ye]),We=(0,He.useCallback)(async he=>{o("schedule"),await Ye(he)},[Ye]);return(0,Na.jsx)(Zo.Provider,{value:Ee,children:(0,Na.jsx)("div",{ref:xe,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${!e&&r==="processing"?" app-wrapper--loading":""}`,style:pr().theme,children:(0,Na.jsxs)("main",{className:"main-content",children:[l&&(0,Na.jsxs)("div",{className:"error-box",role:"alert",children:[(0,Na.jsx)("strong",{children:"Error:"})," ",l]}),r==="entry"&&(0,Na.jsx)(ud,{onPasteSchedule:ge,onUploadSchedule:We,onEntryModeChange:o}),r==="results"&&i==="schedule"&&d&&(0,Na.jsx)(bd,{scheduleResult:d,onStartOver:lt,cart:D,onAddToCart:m,onRemoveFromCart:g,onGoToBasket:Q,cartSeeded:z,onCartSeeded:()=>G(!0),reviewGateComplete:w,onReviewGateComplete:()=>E(!0),internal:a}),r==="basket"&&(0,Na.jsx)(rl,{cart:D,onUpdateQty:v,onUpdateSellUnits:N,onRemove:g,onBack:se,onStartNewQuote:lt,internal:a})]})})})}var Va=Y(Ke());var ki=Y(Ke()),te=Y(ae()),sw=[{id:"ogee",label:"Ogee",blurb:"Traditional curved profile"},{id:"torus",label:"Torus",blurb:"Soft rounded detail"},{id:"ovolo",label:"Ovolo",blurb:"Traditional rounded profile"},{id:"pencil-round",label:"Pencil round",blurb:"Simple softened edge"},{id:"square-edge",label:"Square edge",blurb:"Clean contemporary edge"}],Ws=e=>Number.parseFloat(e)||0,cw=(e,t)=>Ws(e)*(t==="m"?1:.3048),yd=(e,t)=>Ws(e.quantity)*(2*cw(e.height,t)+cw(e.width,t)),k_=()=>({quantity:"1",width:"",height:""});function N_({profile:e}){return(0,te.jsxs)("svg",{className:"architrave-calculator__profile-diagram",viewBox:"0 0 112 76","aria-hidden":"true",children:[(0,te.jsx)("path",{d:{ogee:"M18 62 V38 C18 28 28 22 40 22 H78 C88 22 94 28 94 38 V62",torus:"M18 62 V40 C18 27 30 20 42 20 C54 20 58 30 66 30 C74 30 78 20 90 20 C102 20 94 34 94 40 V62",ovolo:"M18 62 V38 C18 28 30 20 42 20 H70 C82 20 94 28 94 38 V62","pencil-round":"M18 62 V38 C18 28 28 20 40 20 H72 C84 20 94 28 94 38 V62","square-edge":"M18 62 V20 H94 V62"}[e]}),(0,te.jsx)("line",{x1:"12",y1:"66",x2:"100",y2:"66"})]})}function _d({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,ki.useState)("m"),[i,o]=(0,ki.useState)({quantity:"1",width:"0.76",height:"1.98"}),[l,c]=(0,ki.useState)({quantity:"0",width:"1.52",height:"1.98"}),[p,f]=(0,ki.useState)([]),[b,d]=(0,ki.useState)("ogee"),[h,w]=(0,ki.useState)("2.4"),E=(N,R,T)=>{N(z=>({...z,[R]:T}))},D=yd(i,r)+yd(l,r)+p.reduce((N,R)=>N+yd(R,r),0),m=Ws(h)>0?Math.ceil(D/Ws(h)):0,u=sw.find(N=>N.id===b)?.label??"",g=[{key:`architrave-${b}`,label:`Architrave (${u})`,qty:D,unit:"m",query:`${u} architrave`,category:"architrave"}],v=(N,R,T,z)=>(0,te.jsxs)("div",{className:"architrave-calculator__opening-row",children:[(0,te.jsx)("span",{children:N}),(0,te.jsx)("input",{"aria-label":`${N} quantity`,type:"number",min:"0",step:"1",value:R.quantity,onChange:G=>T("quantity",G.target.value)}),(0,te.jsx)("input",{"aria-label":`${N} width`,type:"number",min:"0",step:"0.01",value:R.width,onChange:G=>T("width",G.target.value)}),(0,te.jsx)("input",{"aria-label":`${N} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:G=>T("height",G.target.value)}),z?(0,te.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:z,children:"Remove"}):null]});return(0,te.jsx)(te.Fragment,{children:(0,te.jsxs)("div",{className:"truss-estimator",children:[(0,te.jsxs)("div",{className:"quick-order-hero",children:[(0,te.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,te.jsx)("h1",{children:"Architrave Calculator"}),(0,te.jsx)("p",{children:"Estimate architrave lengths and board quantities for door openings."})]}),(0,te.jsxs)("div",{className:"truss-estimator__card architrave-calculator",children:[(0,te.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure your openings"}),(0,te.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter each door or window opening. Mitred corners are allowed for, and board lengths are worked out from the net run."}),(0,te.jsxs)("div",{className:"architrave-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Door openings"}),(0,te.jsx)("p",{className:"architrave-calculator__hint",children:"Each opening is calculated as two side pieces plus one head piece."}),(0,te.jsxs)("div",{className:"architrave-calculator__unit-row",children:[(0,te.jsx)("span",{children:"Units"}),(0,te.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,te.jsx)("button",{type:"button",className:r==="m"?"is-selected":"",onClick:()=>n("m"),children:"Metres"}),(0,te.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>n("ft"),children:"Feet"})]})]}),(0,te.jsxs)("div",{className:"architrave-calculator__dimensions-header",children:[(0,te.jsx)("span",{children:"Opening"}),(0,te.jsx)("span",{children:"Qty"}),(0,te.jsxs)("span",{children:["Width (",r,")"]}),(0,te.jsxs)("span",{children:["Height (",r,")"]}),(0,te.jsx)("span",{})]}),v("Single doors",i,(N,R)=>E(o,N,R)),v("Double doors",l,(N,R)=>E(c,N,R)),p.map((N,R)=>v(`Alternative door ${R+1}`,N,(T,z)=>f(G=>G.map((K,xe)=>xe===R?{...K,[T]:z}:K)),()=>f(T=>T.filter((z,G)=>G!==R)))),(0,te.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>f(N=>[...N,k_()]),children:"+ Add alternative-sized door"})]}),(0,te.jsxs)("div",{className:"architrave-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Standard profile"}),(0,te.jsx)("p",{className:"architrave-calculator__hint",children:"Choose the profile you plan to use. Length calculations are the same for each profile."}),(0,te.jsx)("div",{className:"architrave-calculator__profiles",children:sw.map(N=>(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${b===N.id?" is-selected":""}`,onClick:()=>d(N.id),children:[(0,te.jsx)(N_,{profile:N.id}),(0,te.jsx)("div",{className:"truss-estimator__option-title",children:N.label}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:N.blurb})]},N.id))})]}),(0,te.jsxs)("div",{className:"architrave-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,te.jsx)("div",{className:"architrave-calculator__options",children:(0,te.jsxs)("label",{className:"truss-estimator__field",children:[(0,te.jsx)("span",{children:"Board length (m)"}),(0,te.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,te.jsx)("p",{className:"architrave-calculator__hint",children:"Waste allows for mitred corners, cuts and damaged lengths."})]}),(0,te.jsxs)("div",{className:"architrave-calculator__totals",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,te.jsxs)("div",{className:"architrave-calculator__result-grid",children:[(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Architrave needed"}),(0,te.jsxs)("strong",{children:[D.toFixed(2)," m"]})]}),(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Board lengths"}),(0,te.jsx)("strong",{children:m})]})]})]}),(0,te.jsxs)("div",{className:"architrave-calculator__actions",children:[(0,te.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,te.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(g),disabled:D<=0,children:a})]})]})]})})}var Ni=Y(Ke()),le=Y(ae()),uw=60,pw=10,S_=.02,C_=.012,q_=.01,Rn=e=>Number.parseFloat(e)||0,E_=(e,t=2)=>e.toFixed(t);function xd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Ni.useState)("brick"),[i,o]=(0,Ni.useState)("engineering-red"),[l,c]=(0,Ni.useState)("metric"),[p,f]=(0,Ni.useState)(""),[b,d]=(0,Ni.useState)(""),[h,w]=(0,Ni.useState)(!0),E=l==="metric"?Rn(p)*Rn(b):Rn(p)*Rn(b)*.092903,m=E*(r==="brick"?uw:pw),u=Math.ceil(m),g=E*(r==="brick"?S_:C_),v=Math.ceil(g/q_),N=l==="metric"?E:E*10.7639,R=[{key:r==="brick"?`brick-${i}`:"block",label:r==="brick"?{common:"Common concrete bricks","engineering-red":"Red engineering bricks","engineering-blue":"Blue engineering bricks"}[i]:"Blocks",qty:u,unit:"each",query:r==="brick"?"facing brick":"concrete block",category:"masonry"},...h?[{key:"mortar",label:"Blue Circle Quality Assured Mortar Mix 20kg",qty:v,unit:"bag",query:"ready mixed mortar",category:"mortar"}]:[]],T=z=>{if(z===l)return;let G=z==="imperial"?3.28084:.3048;f((Rn(p)*G).toFixed(2)),d((Rn(b)*G).toFixed(2)),c(z)};return(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"truss-estimator",children:[(0,le.jsxs)("div",{className:"quick-order-hero",children:[(0,le.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,le.jsx)("h1",{children:"Brick & Block Calculator"}),(0,le.jsx)("p",{children:"Estimate masonry units, sand and cement for a wall."})]}),(0,le.jsxs)("div",{className:"truss-estimator__card brick-calculator",children:[(0,le.jsx)("h2",{className:"truss-estimator__step-title",children:"Wall area and masonry type"}),(0,le.jsx)("p",{className:"truss-estimator__step-sub",children:"Pick brick or block and enter the wall dimensions for unit counts plus ready-mixed mortar."}),(0,le.jsxs)("div",{className:"brick-calculator__section",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Masonry type"}),(0,le.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["brick","Brick"],["block","Block"]].map(([z,G])=>(0,le.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===z?" is-selected":""}`,onClick:()=>n(z),children:[(0,le.jsx)("div",{className:"truss-estimator__option-title",children:G}),(0,le.jsxs)("div",{className:"truss-estimator__option-copy",children:["Approx. ",z==="brick"?uw:pw," per m\xB2"]})]},z))})]}),r==="brick"&&(0,le.jsxs)("div",{className:"brick-calculator__section",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Brick type"}),(0,le.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:[["common","Common concrete","General-purpose grey concrete brick"],["engineering-red","Engineering red","Class B perforated, 65mm"],["engineering-blue","Engineering blue","Class B solid, 65mm"]].map(([z,G,K])=>(0,le.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i===z?" is-selected":""}`,onClick:()=>o(z),children:[(0,le.jsx)("div",{className:"truss-estimator__option-title",children:G}),(0,le.jsx)("div",{className:"truss-estimator__option-copy",children:K})]},z))})]}),(0,le.jsxs)("div",{className:"brick-calculator__section",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,le.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,le.jsx)("button",{type:"button",className:l==="metric"?"is-selected":"",onClick:()=>T("metric"),children:"Metric"}),(0,le.jsx)("button",{type:"button",className:l==="imperial"?"is-selected":"",onClick:()=>T("imperial"),children:"Imperial"})]}),(0,le.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsxs)("span",{children:["Height (",l==="metric"?"m":"ft",")"]}),(0,le.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:z=>f(z.target.value)})]}),(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsxs)("span",{children:["Width (",l==="metric"?"m":"ft",")"]}),(0,le.jsx)("input",{type:"number",min:"0",step:"0.01",value:b,onChange:z=>d(z.target.value)})]})]})]}),(0,le.jsx)("div",{className:"brick-calculator__options",children:(0,le.jsxs)("label",{className:"brick-calculator__checkbox",children:[(0,le.jsx)("input",{type:"checkbox",checked:h,onChange:z=>w(z.target.checked)}),(0,le.jsx)("span",{children:"Include ready-mixed mortar"})]})}),(0,le.jsxs)("div",{className:"brick-calculator__totals",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,le.jsxs)("div",{className:"brick-calculator__result-grid",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{children:"Wall area"}),(0,le.jsxs)("strong",{children:[E_(N)," ",l==="metric"?"m\xB2":"ft\xB2"]})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{children:r==="brick"?"Bricks":"Blocks"}),(0,le.jsx)("strong",{children:u.toLocaleString("en-GB")})]}),h?(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{children:"Ready-mixed mortar"}),(0,le.jsxs)("strong",{children:[v," x 20kg bags"]})]}):null]}),(0,le.jsx)("p",{className:"brick-calculator__note",children:"Estimate based on standard nominal sizes and 10mm joints. Mortar bags are approximate; confirm the required mortar specification before ordering."})]}),(0,le.jsxs)("div",{className:"brick-calculator__actions",children:[(0,le.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,le.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(R),disabled:E<=0,children:a})]})]})]})})}var fr=Y(Ke());var dw=new Map;function M_(e){return{product_id:e.product_id,description:e.description,source_list:e.source_list??null,price:e.price??null,list_price:e.list_price,discount:e.discount,price_basis:e.price_basis??null,uoi_count:e.uoi_count??null,uoi:e.uoi??null,pdp_photo_url:e.pdp_photo_url??null,conversion:e.conversion,measurements_mm:e.measurements_mm??e.attrs?.measurements_mm??[],scores:{dimension:0,grade:0,brand:0,fuzzy:0,bm25:0,overall:0},method:"estimator_catalogue_search"}}async function Jr(e,t,a=12,r){let n=`${e}||${t??""}||${a}||${r??""}`,i=dw.get(n);if(i)return i;let o=new URLSearchParams({q:e,limit:String(a)});t&&o.set("category",t),r&&o.set("account",r);let l=await fetch(Lt(`/api/catalogue/search?${o.toString()}`),{headers:wi()}),c=await Kt(l);if(!l.ok)throw new Error(c?.error||c?.message||"Could not reach the product catalogue");let p=Array.isArray(c?.items)?c.items.map(M_):[];return dw.set(n,p),p}async function mw(e,t){return await Promise.all(e.map(async r=>{try{return{requirement:r,candidates:await Jr(r.query,r.category,void 0,t)}}catch{return{requirement:r,candidates:[]}}}))}async function fw(){let e=await fetch(Lt("/api/catalogue"),{headers:wi()});if(!e.ok)return{itemCount:0,uploadedAt:null};let t=await Kt(e);return{itemCount:Number(t?.itemCount)||0,uploadedAt:t?.uploadedAt??null}}var $=Y(ae()),T_=1.54,z_=1440,A_=25,kd=800,R_=1500,Nd=e=>Number.parseFloat(e)||0,Un={mot:{label:"MOT Type 1",blurb:"Sub-base for patios and driveways",density:1.7,productId:"6001007"},"sharp-sand":{label:"Sharp sand",blurb:"Bedding and general groundwork",density:1.6,productId:"6001012"},gravel:{label:"20mm gravel",blurb:"Drainage and landscaping",density:1.6,productId:"6001004"}};function Sd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let r=Fs(),[n,i]=(0,fr.useState)("m"),[o,l]=(0,fr.useState)(""),[c,p]=(0,fr.useState)(""),[f,b]=(0,fr.useState)(""),[d,h]=(0,fr.useState)("concrete"),[w,E]=(0,fr.useState)("mot"),[D,m]=(0,fr.useState)(!1),[u,g]=(0,fr.useState)(null),v=n==="m"?1:.3048,N=Nd(o)*v*Nd(c)*v*Nd(f)*(n==="m"?.01:.0254),R=Un[w],T=N*T_/7,z=T*z_,G=T*2,K=T*4,xe=Math.ceil(z/A_),Ee=Math.ceil(G*Un["sharp-sand"].density*1e3/kd),Ge=Math.ceil(K*Un.gravel.density*1e3/kd),Qe=Math.ceil(N*R.density*1e3/kd),Ie=d==="concrete"?[{key:"cement",label:"Blue Circle General Purpose Grey Cement 25kg",qty:xe,productId:"6003004"},{key:"sharp-sand",label:"Sharp Sand Bulk Bag (800kg)",qty:Ee,productId:"6001012"},{key:"gravel",label:"20mm Non Decorative Pea Shingle/Gravel Bulk Bag (800kg)",qty:Ge,productId:"6001004"}]:[{key:w,label:`${R.label} Bulk Bag (800kg)`,qty:Qe,productId:R.productId}],ue=()=>{if(t){t(Ie.map(se=>({key:se.key,label:se.label,qty:se.qty,unit:"each",query:se.productId})));return}Q()},Q=async()=>{let se=Date.now();m(!0),g(null);try{let Ne=await Promise.all(Ie.map(async Ye=>{let ge=(await Jr(Ye.productId)).find(We=>We.product_id===Ye.productId);if(!ge)throw new Error(`${Ye.label} is no longer available in this catalogue.`);return Kr(ge,{lineId:`concrete-aggregate:${Ye.key}`,description:Ye.label,unit:"bag",qty:Ye.qty})})),lt=R_-(Date.now()-se);lt>0&&await new Promise(Ye=>window.setTimeout(Ye,lt)),r?.clearCart(),r?.addManyToCart(Ne),r?.openBasket()}catch(Ne){g(Ne instanceof Error?Ne.message:"Could not add the products to your basket.")}finally{m(!1)}};return D?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)("div",{className:"truss-estimator",children:[(0,$.jsxs)("div",{className:"quick-order-hero",children:[(0,$.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,$.jsx)("h1",{children:"Your Materials"}),(0,$.jsx)("p",{children:"Calculating quantities from the Concrete & Aggregate Calculator."})]}),(0,$.jsx)("div",{className:"truss-estimator__card",children:(0,$.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,$.jsx)(dr,{}),(0,$.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})}):(0,$.jsx)($.Fragment,{children:(0,$.jsxs)("div",{className:"truss-estimator",children:[(0,$.jsxs)("div",{className:"quick-order-hero",children:[(0,$.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,$.jsx)("h1",{children:"Concrete & Aggregate Calculator"}),(0,$.jsx)("p",{children:"Calculate fixed site-mix concrete ingredients or aggregate bulk bags."})]}),(0,$.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,$.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose what you need"}),(0,$.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter the area and depth. The calculator adds the fixed Materials Market products directly to your basket."}),(0,$.jsxs)("div",{className:"materials-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Material type"}),(0,$.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,$.jsxs)("button",{type:"button",className:`truss-estimator__option-card${d==="concrete"?" is-selected":""}`,onClick:()=>h("concrete"),children:[(0,$.jsx)("div",{className:"truss-estimator__option-title",children:"Site-mixed concrete"}),(0,$.jsx)("div",{className:"truss-estimator__option-copy",children:"Cement, sharp sand and 20mm aggregate"})]}),(0,$.jsxs)("button",{type:"button",className:`truss-estimator__option-card${d==="aggregate"?" is-selected":""}`,onClick:()=>h("aggregate"),children:[(0,$.jsx)("div",{className:"truss-estimator__option-title",children:"Aggregates"}),(0,$.jsx)("div",{className:"truss-estimator__option-copy",children:"MOT Type 1, sharp sand or 20mm gravel"})]})]})]}),d==="aggregate"&&(0,$.jsxs)("div",{className:"materials-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Aggregate type"}),(0,$.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.keys(Un).map(se=>(0,$.jsxs)("button",{type:"button",className:`truss-estimator__option-card${w===se?" is-selected":""}`,onClick:()=>E(se),children:[(0,$.jsx)("div",{className:"truss-estimator__option-title",children:Un[se].label}),(0,$.jsx)("div",{className:"truss-estimator__option-copy",children:Un[se].blurb})]},se))})]}),(0,$.jsxs)("div",{className:"materials-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and depth"}),(0,$.jsxs)("div",{className:"materials-calculator__unit-row",children:[(0,$.jsx)("span",{children:"Units"}),(0,$.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,$.jsx)("button",{type:"button",className:n==="m"?"is-selected":"",onClick:()=>i("m"),children:"Metric"}),(0,$.jsx)("button",{type:"button",className:n==="ft"?"is-selected":"",onClick:()=>i("ft"),children:"Imperial"})]})]}),(0,$.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsxs)("span",{children:["Length (",n,")"]}),(0,$.jsx)("input",{type:"number",min:"0",step:"0.01",value:o,onChange:se=>l(se.target.value)})]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsxs)("span",{children:["Width (",n,")"]}),(0,$.jsx)("input",{type:"number",min:"0",step:"0.01",value:c,onChange:se=>p(se.target.value)})]})]}),(0,$.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,$.jsxs)("span",{children:["Depth (",n==="m"?"cm":"inches",")"]}),(0,$.jsx)("input",{type:"number",min:"0",step:"0.1",value:f,onChange:se=>b(se.target.value)})]})]}),(0,$.jsxs)("div",{className:"materials-calculator__totals",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Materials required"}),(0,$.jsx)("div",{className:"materials-calculator__result-grid",children:d==="concrete"?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Cement"}),(0,$.jsxs)("strong",{children:[z.toFixed(0)," kg"]})]}),(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Sharp sand"}),(0,$.jsxs)("strong",{children:[G.toFixed(2)," m\xB3"]})]}),(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"20mm aggregate"}),(0,$.jsxs)("strong",{children:[K.toFixed(2)," m\xB3"]})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:R.label}),(0,$.jsxs)("strong",{children:[N.toFixed(2)," m\xB3"]})]}),(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Approx. weight"}),(0,$.jsxs)("strong",{children:[(N*R.density).toFixed(2)," t"]})]}),(0,$.jsx)("div",{})]})}),(0,$.jsx)("p",{className:"materials-calculator__note",children:d==="concrete"?"Based on a 1:2:4 mix. Confirm the mix design for structural work.":"Figures are estimates. Confirm the specification and supplier quantities before ordering."})]}),u&&(0,$.jsx)("p",{className:"results-empty-hint estimator-products__error",children:u}),(0,$.jsxs)("div",{className:"materials-calculator__actions",children:[(0,$.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,$.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:ue,disabled:N<=0||D,children:D?"Adding products\u2026":a})]})]})]})})}var Ya=Y(Ke());var U=Y(ae()),Dn=12,Bn=8,ec=.56,gw=.21,Sa={ranges:{meridian:{label:"Standard grooved timber",blurb:"32 \xD7 125mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.125},summit:{label:"Wide grooved timber",blurb:"32 \xD7 150mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.15}},boardGapM:.006,wastage:{straight:.05,diagonal:.15},pictureFrame:{extraWastage:.08},joist:{lengthM:2.4,spacingOptions:[{id:"300",label:"300mm centres (heavy duty)",spacingM:.3},{id:"400",label:"400mm centres (standard)",spacingM:.4},{id:"450",label:"450mm centres (light use)",spacingM:.45}]}},Si=["range","grid","pictureFrame","substructure"],U_={range:null,colour:null,deckSizeMode:"quick",quickLengthM:"",quickWidthM:"",points:[],isOutlineClosed:!1,wallSegments:new Set,drawMode:"outline",drawError:"",pictureFrame:null,direction:null,deckHeightMode:"standard",deckHeightCm:"",joistSpacing:null,supportType:null,contact:{name:"",email:""}},tc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),ac=(e,t,a)=>a.x>=Math.min(e.x,t.x)&&a.x<=Math.max(e.x,t.x)&&a.y>=Math.min(e.y,t.y)&&a.y<=Math.max(e.y,t.y),D_=(e,t,a,r)=>{let n=tc(e,t,a),i=tc(e,t,r),o=tc(a,r,e),l=tc(a,r,t);return n===0&&ac(e,t,a)||i===0&&ac(e,t,r)||o===0&&ac(a,r,e)||l===0&&ac(a,r,t)?!0:n>0!=i>0&&o>0!=l>0},Cd=(e,t)=>{let a=t?e.length:e.length-1;for(let r=0;r<a;r+=1){let n=e[(r+1)%e.length];for(let i=r+1;i<a;i+=1)if(!(i===r+1||t&&r===0&&i===a-1)&&D_(e[r],n,e[i],e[(i+1)%e.length]))return!0}return!1};function qd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Ya.useState)(0),[i,o]=(0,Ya.useState)(U_),[l,c]=(0,Ya.useState)(1),[p,f]=(0,Ya.useState)({x:0,y:0}),[b,d]=(0,Ya.useState)(null),h=(0,Ya.useRef)(null),w=(0,Ya.useRef)(null),E=(0,Ya.useRef)(null),D=Si[r],m=i.range?Sa.ranges[i.range]:null,u=Dn/l,g=Bn/l,v=(Dn-u)/2,N=(Bn-g)/2,R=Math.max(-Dn,Math.min(Dn*2-u,v+p.x)),T=Math.max(-Bn,Math.min(Bn*2-g,N+p.y)),z=Number.parseFloat(i.quickLengthM),G=Number.parseFloat(i.quickWidthM),K=z>0&&G>0,xe=M=>Math.abs(M.reduce((x,A,I)=>{let ce=M[(I+1)%M.length];return x+A.x*ce.y-ce.x*A.y},0))/2,Ee=(M,x)=>Math.hypot(x.x-M.x,x.y-M.y),Ge=i.isOutlineClosed?xe(i.points):0,Qe=i.isOutlineClosed?i.points.reduce((M,x,A)=>M+Ee(x,i.points[(A+1)%i.points.length]),0):0,Ie=i.isOutlineClosed?i.points.reduce((M,x,A)=>M+(i.wallSegments.has(A)?0:Ee(x,i.points[(A+1)%i.points.length])),0):0,ue=i.points.reduce((M,x)=>({x:M.x+x.x/i.points.length,y:M.y+x.y/i.points.length}),{x:0,y:0}),Q=i.points.length>1?(()=>{let M=i.points[0],x=i.points[1],A=Ee(M,x),I=A?-(x.y-M.y)/A:0,ce=A?(x.x-M.x)/A:0,me=(M.x+x.x)/2,ke=(M.y+x.y)/2,k=I*(me-ue.x)+ce*(ke-ue.y)>=0?1:-1;return{x:me+I*ec*k,y:ke+ce*ec*k}})():null,Ne=(()=>{let M=i.range?Sa.ranges[i.range]:Sa.ranges.meridian,x=i.deckSizeMode==="quick"?z*G:Ge,A=i.deckSizeMode==="quick"?2*(z+G):Ie,I=i.direction==="diagonal"?Sa.wastage.diagonal:Sa.wastage.straight,ce=i.pictureFrame==="yes"?Sa.pictureFrame.extraWastage:0,ke=x/(M.boardWidthM+Sa.boardGapM)/M.boardLengthM,k=Math.ceil(ke*(1+I+ce)),j=Math.ceil(x*30*(1+I+ce)/200),O=Sa.joist.spacingOptions.find(C=>C.id===i.joistSpacing)??Sa.joist.spacingOptions[1],ne=x/O.spacingM,ee=Math.ceil(ne/Sa.joist.lengthM);return{range:M,area:x,boardCount:k,screwBoxes:j,joistLengthsNeeded:ee,spacing:O}})(),lt=Ne?[{key:`boards-${i.range??"meridian"}`,label:`Deck boards (${Ne.range.label})`,qty:Ne.boardCount,unit:"each",query:"timber decking board",category:"decking",calculatorWasteIncluded:!0},{key:"joists",label:"Treated C24 joists",qty:Ne.joistLengthsNeeded,unit:"each",query:"treated joist",category:"timber",calculatorWasteIncluded:!0},{key:"screws",label:"Green decking screws (200/box)",qty:Ne.screwBoxes,unit:"box",query:"green decking screws",category:"fixings",calculatorWasteIncluded:!0}]:[],Ye=()=>D==="range"?!!i.range:D==="grid"?i.deckSizeMode==="quick"?K:i.isOutlineClosed&&Ge>0:D==="pictureFrame"?!!i.pictureFrame&&!!i.direction:D==="substructure"?!!i.joistSpacing:!0,ge=r===Si.length-1?a:"Next",We=(M,x,A=!1)=>{let I=E.current?.getBoundingClientRect();if(!I)return null;let ce=A?1:.25;return{x:Math.round(Math.max(R,Math.min(R+u,R+(M-I.left)/I.width*u))/ce)*ce,y:Math.round(Math.max(T,Math.min(T+g,T+(x-I.top)/I.height*g))/ce)*ce}},he=M=>{if(i.isOutlineClosed){let A=M.target;if(A!==M.currentTarget&&!A.classList.contains("deck-outline__grid"))return;w.current={startX:M.clientX,startY:M.clientY,startViewX:R,startViewY:T},M.currentTarget.setPointerCapture(M.pointerId);return}if(i.drawMode!=="outline")return;let x=We(M.clientX,M.clientY,!0);x&&(d(null),o(A=>{let I=[...A.points,x];return Cd(I,!1)?{...A,drawError:"Edges cannot cross. Choose another corner."}:{...A,points:I,drawError:""}}))},W=(M,x)=>{if(!i.isOutlineClosed){M.stopPropagation(),x===0&&i.points.length>=3&&o(A=>({...A,isOutlineClosed:!0,drawMode:"edges"}));return}M.stopPropagation(),h.current=x,M.currentTarget.setPointerCapture(M.pointerId)},Re=M=>{if(w.current){let I=E.current?.getBoundingClientRect();if(!I)return;let ce=w.current,me=ce.startViewX-(M.clientX-ce.startX)/I.width*u,ke=ce.startViewY-(M.clientY-ce.startY)/I.height*g;f({x:me-v,y:ke-N});return}!i.isOutlineClosed&&i.drawMode==="outline"&&d(We(M.clientX,M.clientY,!0));let x=h.current;if(x===null)return;let A=We(M.clientX,M.clientY);A&&o(I=>{let ce=I.points.map((me,ke)=>ke===x?A:me);return Cd(ce,!0)?{...I,drawError:"Edges cannot cross. Move the corner to a different position."}:{...I,points:ce,drawError:""}})},Be=M=>{w.current=null,h.current=null,M.currentTarget.hasPointerCapture(M.pointerId)&&M.currentTarget.releasePointerCapture(M.pointerId)},ye=M=>{o(x=>{let A=new Set(x.wallSegments);return A.has(M)?A.delete(M):A.add(M),{...x,wallSegments:A}})},et=()=>{r===0?e():n(M=>M-1)},Ze=()=>{Ye()&&(r===Si.length-1?t?.(lt):n(M=>M+1))};return(0,U.jsx)(U.Fragment,{children:(0,U.jsxs)("div",{className:"truss-estimator",children:[(0,U.jsxs)("div",{className:"quick-order-hero",children:[(0,U.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,U.jsx)("h1",{children:"Decking Calculator"}),(0,U.jsx)("p",{children:"Estimate timber boards, joists and screws for your deck."})]}),(0,U.jsxs)("div",{className:"truss-estimator__card",children:[(0,U.jsxs)("div",{className:"truss-estimator__body",children:[D==="range"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your timber decking"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Both options are fixed, orderable pressure-treated timber boards."}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Sa.ranges).map(([M,x])=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.range===M?" is-selected":""}`,onClick:()=>o(A=>({...A,range:M})),children:[(0,U.jsx)("div",{className:"truss-estimator__option-title",children:x.label}),(0,U.jsx)("div",{className:"truss-estimator__option-copy",children:x.blurb}),(0,U.jsxs)("div",{className:"truss-estimator__option-copy",children:[x.boardLengthM,"m boards"]})]},M))})]}):null,D==="grid"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Tell us your deck size"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Start with a quick rectangle estimate, or draw an irregular deck for a more precise result."}),(0,U.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,U.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.deckSizeMode==="quick"?" is-selected":""}`,onClick:()=>o(M=>({...M,deckSizeMode:"quick"})),children:"Quick estimate"}),(0,U.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.deckSizeMode==="draw"?" is-selected":""}`,onClick:()=>o(M=>({...M,deckSizeMode:"draw",drawMode:"outline"})),children:"Draw your space"})]}),i.deckSizeMode==="quick"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,U.jsxs)("label",{className:"truss-estimator__field",children:[(0,U.jsx)("span",{children:"Length (m)"}),(0,U.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:i.quickLengthM,onChange:M=>o(x=>({...x,quickLengthM:M.target.value}))})]}),(0,U.jsxs)("label",{className:"truss-estimator__field",children:[(0,U.jsx)("span",{children:"Width (m)"}),(0,U.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:i.quickWidthM,onChange:M=>o(x=>({...x,quickWidthM:M.target.value}))})]})]}),(0,U.jsx)("div",{className:"truss-estimator__grid-hint",children:"For L-shaped decks, cut-outs, or sides against a wall, use Draw your space."}),K?(0,U.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,U.jsxs)("div",{children:[(z*G).toFixed(2)," m\xB2 deck"]}),(0,U.jsxs)("div",{children:[(2*(z+G)).toFixed(2)," m perimeter"]})]}):null]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Draw your deck"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Click to add corners, then close the outline. Drag any handle to refine it."}),(0,U.jsxs)("div",{className:"deck-outline__toolbar",children:[i.isOutlineClosed?(0,U.jsxs)("div",{className:"deck-outline__summary",children:[(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Deck area"}),(0,U.jsxs)("strong",{children:[Ge.toFixed(2)," m\xB2"]})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Perimeter"}),(0,U.jsxs)("strong",{children:[Qe.toFixed(2)," m"]})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Wall edges"}),(0,U.jsx)("strong",{children:i.wallSegments.size>0?i.wallSegments.size:"None"})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Visible edge"}),(0,U.jsxs)("strong",{children:[Ie.toFixed(2)," m"]})]})]}):null,(0,U.jsxs)("div",{className:"deck-outline__actions",children:[(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(M=>({...M,points:M.points.slice(0,-1)})),disabled:i.points.length===0||i.isOutlineClosed,children:"Undo"}),(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{d(null),o(M=>({...M,points:[],isOutlineClosed:!1,wallSegments:new Set,drawMode:"outline",drawError:""}))},disabled:i.points.length===0,children:"Clear"}),(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(M=>({...M,points:[{x:2,y:2},{x:8,y:2},{x:8,y:5},{x:2,y:5}],isOutlineClosed:!0,wallSegments:new Set,drawMode:"edges",drawError:""})),children:"Start with rectangle"})]})]}),(0,U.jsx)("div",{className:"deck-editor-layout",children:(0,U.jsxs)("div",{className:"deck-editor-layout__canvas-column",children:[(0,U.jsxs)("div",{className:"deck-outline",children:[(0,U.jsxs)("svg",{ref:E,className:`deck-outline__canvas${i.isOutlineClosed?" is-pan-mode":""}`,viewBox:`${R} ${T} ${u} ${g}`,preserveAspectRatio:"none","aria-label":"Deck outline drawing area",onPointerDown:he,onPointerMove:Re,onPointerUp:Be,onPointerLeave:()=>{d(null),w.current||(h.current=null)},children:[(0,U.jsx)("defs",{children:(0,U.jsx)("pattern",{id:"deck-outline-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,U.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,U.jsx)("rect",{x:-Dn,y:-Bn,width:Dn*3,height:Bn*3,className:"deck-outline__grid",fill:"url(#deck-outline-grid)"}),i.points.length>1?(0,U.jsx)("polyline",{className:"deck-outline__preview",points:i.points.map(M=>`${M.x},${M.y}`).join(" ")}):null,i.isOutlineClosed?(0,U.jsx)("polygon",{className:"deck-outline__shape",points:i.points.map(M=>`${M.x},${M.y}`).join(" "),stroke:"none"}):null,i.points.length>1?i.points.slice(0,i.isOutlineClosed?void 0:-1).map((M,x)=>{let A=i.points[i.isOutlineClosed?(x+1)%i.points.length:x+1],I=Ee(M,A),ce=I?-(A.y-M.y)/I:0,me=I?(A.x-M.x)/I:0,ke=(M.x+A.x)/2,k=(M.y+A.y)/2,j=ce*(ke-ue.x)+me*(k-ue.y)>=0?1:-1,O=ke+ce*ec*j,ne=k+me*ec*j;return(0,U.jsxs)("g",{children:[(0,U.jsx)("line",{className:"deck-outline__edge-hit",x1:M.x,y1:M.y,x2:A.x,y2:A.y,onClick:i.isOutlineClosed?()=>ye(x):void 0}),(0,U.jsx)("line",{className:`deck-outline__edge${i.wallSegments.has(x)?" is-wall":""}`,x1:M.x,y1:M.y,x2:A.x,y2:A.y,pointerEvents:"none"}),(0,U.jsxs)("text",{className:`deck-outline__edge-label${i.wallSegments.has(x)?" is-wall":""}`,x:O,y:ne,textAnchor:"middle",dominantBaseline:"central",fontSize:gw/l,children:[I.toFixed(2)," m"]})]},`segment-${x}`)}):null,!i.isOutlineClosed&&i.points.length>0&&b?(()=>{let M=i.points[i.points.length-1],x=Ee(M,b);if(!x)return null;let A=-(b.y-M.y)/x,I=(b.x-M.x)/x,ce=(M.x+b.x)/2,me=(M.y+b.y)/2;return(0,U.jsxs)("g",{className:"deck-outline__live-measurement",children:[(0,U.jsx)("line",{x1:M.x,y1:M.y,x2:b.x,y2:b.y}),(0,U.jsxs)("text",{x:ce+A*.34,y:me+I*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:gw/l,children:[x.toFixed(2)," m"]})]})})():null,i.points.map((M,x)=>(0,U.jsx)("circle",{className:"deck-outline__point",cx:M.x,cy:M.y,r:"0.13",onPointerDown:A=>W(A,x)},`point-${x}`))]}),(0,U.jsxs)("div",{className:"deck-outline__zoom","aria-label":"Zoom controls",children:[(0,U.jsx)("button",{type:"button",onClick:()=>c(M=>Math.max(.5,M-.25)),disabled:l===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,U.jsxs)("span",{children:[Math.round(l*100),"%"]}),(0,U.jsx)("button",{type:"button",onClick:()=>c(M=>Math.min(1,M+.25)),disabled:l===1,"aria-label":"Zoom in",children:"+"})]}),i.isOutlineClosed&&i.wallSegments.size===0&&Q?(0,U.jsx)("div",{className:"deck-outline__edge-prompt",role:"status",style:{left:`${(Q.x-R)/u*100}%`,top:`${(Q.y-T)/g*100}%`},children:"Tap an edge to mark it as a wall, or leave it as a visible edge."}):null,!i.isOutlineClosed&&i.points.length>=3?(0,U.jsx)("button",{type:"button",className:"deck-outline__close",onClick:()=>o(M=>Cd(M.points,!0)?{...M,drawError:"Edges cannot cross. Adjust the outline before finishing."}:{...M,isOutlineClosed:!0,drawMode:"edges",drawError:""}),children:"Finish outline"}):null]}),(0,U.jsxs)("div",{className:"deck-outline__supporting",children:[(0,U.jsx)("div",{className:"truss-estimator__grid-hint",children:i.isOutlineClosed?"Drag a corner handle to refine the outline.":"Add at least three corners, then click Finish outline."}),i.drawError?(0,U.jsx)("div",{className:"deck-outline__error",role:"alert",children:i.drawError}):null]})]})})]})]}):null,D==="pictureFrame"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Picture frame border?"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"A picture frame border runs boards around the perimeter for a finished look and uses extra material."}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"no",label:"No border",img:"/decking/boards/no-border.webp"},{id:"yes",label:"Picture frame",img:"/decking/boards/picture-frame.webp"}].map(M=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.pictureFrame===M.id?" is-selected":""}`,onClick:()=>o(x=>({...x,pictureFrame:M.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:Pt(M.img),alt:""}),(0,U.jsx)("span",{children:M.label})]},M.id))}),(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Board direction"}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"straight",label:"Straight",img:"/decking/boards/straight.webp"},{id:"diagonal",label:"Diagonal",img:"/decking/boards/diagonal.webp"}].map(M=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.direction===M.id?" is-selected":""}`,onClick:()=>o(x=>({...x,direction:M.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:Pt(M.img),alt:""}),(0,U.jsx)("span",{children:M.label})]},M.id))})]})]}):null,D==="substructure"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Substructure"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the joist spacing. Posts, footings and ground preparation vary by site, so are not included."}),(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Joist spacing"}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Sa.joist.spacingOptions.map(M=>(0,U.jsx)("button",{type:"button",className:`truss-estimator__option-card${i.joistSpacing===M.id?" is-selected":""}`,onClick:()=>o(x=>({...x,joistSpacing:M.id})),children:(0,U.jsx)("div",{className:"truss-estimator__option-title",children:M.label})},M.id))})]}):null]}),(0,U.jsxs)("div",{className:"truss-estimator__nav",children:[(0,U.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:et,children:"Back"}),(0,U.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:Ze,disabled:!Ye(),children:[(0,U.jsx)("span",{children:ge}),(0,U.jsx)("span",{className:"arrow",children:(0,U.jsx)(Ht,{})})]})]})]})]})})}var qa=Y(Ke());var H=Y(ae()),hw=12,bw=30,On=12,Ln=8,vw=.56,Ca={ranges:{boundary:{label:"Horizontal lap",blurb:"Traditional pressure-treated timber panels.",panelWidthM:1.83},skyline:{label:"Feather edge",blurb:"Heavier timber panels for a more solid boundary.",panelWidthM:1.83}},heights:["0.9","1.2","1.5","1.8"],gate:{single:{label:"Single lap gate",widthDefault:.9}},mounting:{concrete:{label:"Concrete posts",blurb:"Slotted concrete posts with matching panels."},postcrete:{label:"Postcrete bags",blurb:"Fast-set post-mix bags in a dug hole.",bagsPerPost:2}}},Ci=["range","height","gate","posts"],B_={range:null,colour:null,grid:new Set,excludedEdges:new Set,gridMode:"draw",boundaryMode:"quick",quickLengthM:"",boundaryPoints:[],boundaryClosed:!1,excludedBoundaryEdges:new Set,height:null,gravelBoard:null,gateType:null,gateWidthM:"",mountingType:null,contact:{name:"",email:""}},rc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),ic=(e,t,a)=>a.x>=Math.min(e.x,t.x)&&a.x<=Math.max(e.x,t.x)&&a.y>=Math.min(e.y,t.y)&&a.y<=Math.max(e.y,t.y),O_=(e,t,a,r)=>{let n=rc(e,t,a),i=rc(e,t,r),o=rc(a,r,e),l=rc(a,r,t);return n===0&&ic(e,t,a)||i===0&&ic(e,t,r)||o===0&&ic(a,r,e)||l===0&&ic(a,r,t)?!0:n>0!=i>0&&o>0!=l>0},nc=(e,t)=>{let a=t?e.length:e.length-1;for(let r=0;r<a;r+=1)for(let n=r+1;n<a;n+=1)if(!(n===r+1||t&&r===0&&n===a-1)&&O_(e[r],e[(r+1)%e.length],e[n],e[(n+1)%e.length]))return!0;return!1};function Ed({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,qa.useState)(0),[i,o]=(0,qa.useState)(B_),l=(0,qa.useRef)(null),c=(0,qa.useRef)(null),[p,f]=(0,qa.useState)(1),[b,d]=(0,qa.useState)({x:0,y:0}),[h,w]=(0,qa.useState)(null),E=(0,qa.useRef)(null),D=(0,qa.useRef)(null),m=(0,qa.useRef)(null),u=Ci[r],g=i.range?Ca.ranges[i.range]:null,v=On/p,N=Ln/p,R=(On-v)/2,T=(Ln-N)/2,z=Math.max(-On,Math.min(On*2-v,R+b.x)),G=Math.max(-Ln,Math.min(Ln*2-N,T+b.y)),K=i.boundaryPoints.reduce((k,j)=>({x:k.x+j.x/Math.max(1,i.boundaryPoints.length),y:k.y+j.y/Math.max(1,i.boundaryPoints.length)}),{x:0,y:0}),xe=k=>{let j=new Set,O=[];return k.forEach(ne=>{let[ee,C]=ne.split(",").map(Number),V=[{key:`H,${ee},${C}`,type:"H",x:ee,y:C},{key:`H,${ee},${C+1}`,type:"H",x:ee,y:C+1},{key:`V,${ee},${C}`,type:"V",x:ee,y:C},{key:`V,${ee+1},${C}`,type:"V",x:ee+1,y:C}],X=[!k.has(`${ee},${C-1}`),!k.has(`${ee},${C+1}`),!k.has(`${ee-1},${C}`),!k.has(`${ee+1},${C}`)];V.forEach((pe,Se)=>{X[Se]&&!j.has(pe.key)&&(j.add(pe.key),O.push(pe))})}),O},Ee=(k,j)=>xe(k).filter(O=>!j.has(O.key)),Ge=(k,j)=>Ee(k,j).length,Qe=(k,j)=>{let O={};Ee(k,j).forEach(ee=>{var C,V,X,pe;ee.type==="H"?((O[C=`${ee.x},${ee.y}`]||(O[C]=[])).push("H"),(O[V=`${ee.x+1},${ee.y}`]||(O[V]=[])).push("H")):((O[X=`${ee.x},${ee.y}`]||(O[X]=[])).push("V"),(O[pe=`${ee.x},${ee.y+1}`]||(O[pe]=[])).push("V"))});let ne=0;return Object.values(O).forEach(ee=>{(ee.length===1||ee.length===2&&ee[0]!==ee[1]||ee.length>=3)&&(ne+=1)}),ne},ue=(()=>{let k=i.range?Ca.ranges[i.range]:Ca.ranges.boundary,j=i.height??"1.8",O=i.boundaryMode==="quick"?Math.max(0,Number.parseFloat(i.quickLengthM)||0):i.boundaryClosed?i.boundaryPoints.slice(0,-1).reduce((hr,Ft,It)=>hr+(i.excludedBoundaryEdges.has(It)?0:Math.hypot(i.boundaryPoints[It+1].x-Ft.x,i.boundaryPoints[It+1].y-Ft.y)),0):0,ne=i.gateType&&i.gateType!=="none"?Number.parseFloat(i.gateWidthM)||Ca.gate[i.gateType].widthDefault:0,ee=Math.max(0,O-ne),C=ee>0?Math.ceil(ee/k.panelWidthM):0,V=i.boundaryPoints.length>2&&i.boundaryPoints[0].x===i.boundaryPoints[i.boundaryPoints.length-1].x&&i.boundaryPoints[0].y===i.boundaryPoints[i.boundaryPoints.length-1].y,X=i.boundaryMode==="quick"?ee>0?2:0:i.boundaryClosed?i.boundaryPoints.slice(0,V?-1:void 0).reduce((hr,Ft,It)=>{let Xd=It>0&&!i.excludedBoundaryEdges.has(It-1),$d=It<i.boundaryPoints.length-1&&!i.excludedBoundaryEdges.has(It);return hr+(Xd||$d?1:0)},0):0,pe=ee>0?Math.ceil(ee/k.panelWidthM)+1:0,Se=Math.max(0,pe-X),ft=i.mountingType?Ca.mounting[i.mountingType]:Ca.mounting.concrete,Ve=i.gateType&&i.gateType!=="none"?2:0,Fr=Se+X+Ve,Ir=i.mountingType==="postcrete"?Fr*Ca.mounting.postcrete.bagsPerPost:0,ll=i.gravelBoard==="yes"?C:0;return{range:k,height:j,totalEdgeM:O,fencedLengthM:ee,gateWidthM:ne,panelsCount:C,cornerPostCount:X,intermediatePostCount:Se,gatePostCount:Ve,totalPostCount:Fr,bagsCount:Ir,gravelCount:ll,capCount:Fr,mounting:ft}})(),Q=i.gateType&&i.gateType!=="none"?Ca.gate[i.gateType].label:null,se=Number(ue.height)<=1.2?"6":"8",Ne=ue?[{key:`panels-${i.range??"boundary"}-${ue.height}`,label:`${ue.range.label} panels (${ue.height}m)`,qty:ue.panelsCount,unit:"each",query:"fence panel",category:"fencing"},...i.mountingType==="concrete"?[{key:`concrete-intermediate-${se}`,label:"Intermediate concrete posts",qty:ue.intermediatePostCount,unit:"each",query:"concrete fence post",category:"fencing"},{key:`concrete-end-${se}`,label:"End and corner concrete posts",qty:ue.cornerPostCount+ue.gatePostCount,unit:"each",query:"concrete end post",category:"fencing"}]:[{key:`timber-post-${se}`,label:"Timber fence posts",qty:ue.totalPostCount,unit:"each",query:"timber fence post",category:"fencing"},{key:"postcrete",label:"Postcrete",qty:ue.bagsCount,unit:"bag",query:"postcrete",category:"cement"}],...Q?[{key:"gate",label:Q,qty:1,unit:"each",query:"lap gate",category:"fencing"}]:[],...ue.gravelCount>0?[{key:"gravel-boards",label:"Concrete gravel boards",qty:ue.gravelCount,unit:"each",query:"gravel board",category:"fencing"}]:[]]:[],lt=()=>{if(u==="range"){let k=i.boundaryMode==="quick"?(Number.parseFloat(i.quickLengthM)||0)>0:i.boundaryClosed&&i.boundaryPoints.length>=2;return!!i.range&&k}return u==="height"?!!i.height&&!!i.gravelBoard:u==="gate"?!!i.gateType&&(i.gateType==="none"||i.gateWidthM.trim()!==""):u==="posts"?!!i.mountingType:!0},Ye=r===Ci.length-1?a:"Next",ge=k=>{o(j=>{let O=k(new Set(j.grid)),ne=new Set([...j.excludedEdges].filter(ee=>xe(O).some(C=>C.key===ee)));return{...j,grid:O,excludedEdges:ne}})},We=(k,j,O)=>{ge(ne=>{let ee=`${k},${j}`;return O?ne.add(ee):ne.delete(ee),ne})},he=(k,j,O,ne,ee)=>{let C=k,V=j,X=Math.abs(O-k),pe=k<O?1:-1,Se=-Math.abs(ne-j),ft=j<ne?1:-1,Ve=X+Se;for(;We(C,V,ee),!(C===O&&V===ne);){let Fr=2*Ve;Fr>=Se&&(Ve+=Se,C+=pe),Fr<=X&&(Ve+=X,V+=ft)}},W=(k,j)=>{let O=c.current?.getBoundingClientRect();if(!O)return null;let ne=Math.floor((k-O.left)/bw),ee=Math.floor((j-O.top)/bw);return ne<0||ee<0||ne>=hw||ee>=hw?null:{x:ne,y:ee}},Re=k=>{if(i.gridMode!=="draw")return;let j=W(k.clientX,k.clientY);if(!j)return;k.preventDefault();let O=`${j.x},${j.y}`,ne=!i.grid.has(O);l.current={active:!0,paintValue:ne,lastX:j.x,lastY:j.y},k.currentTarget.setPointerCapture(k.pointerId),We(j.x,j.y,ne)},Be=k=>{let j=l.current;if(!j?.active)return;let O=W(k.clientX,k.clientY);O&&(O.x===j.lastX&&O.y===j.lastY||(he(j.lastX,j.lastY,O.x,O.y,j.paintValue),l.current={...j,lastX:O.x,lastY:O.y}))},ye=k=>{l.current?.active&&(l.current=null,k.currentTarget.releasePointerCapture(k.pointerId))},et=(k,j,O=!1)=>{let ne=m.current?.getBoundingClientRect();if(!ne)return null;let ee=O?1:.25;return{x:Math.round(Math.max(z,Math.min(z+v,z+(k-ne.left)/ne.width*v))/ee)*ee,y:Math.round(Math.max(G,Math.min(G+N,G+(j-ne.top)/ne.height*N))/ee)*ee}},Ze=k=>{if(i.boundaryClosed){let O=k.target;if(O!==k.currentTarget&&!O.classList.contains("fence-boundary__grid"))return;D.current={startX:k.clientX,startY:k.clientY,startViewX:z,startViewY:G},k.currentTarget.setPointerCapture(k.pointerId);return}let j=et(k.clientX,k.clientY,!0);j&&(w(null),o(O=>{let ne=[...O.boundaryPoints,j];return nc(ne,!1)?{...O}:{...O,boundaryPoints:ne}}))},M=(k,j)=>{if(k.stopPropagation(),!i.boundaryClosed){if(j!==0||i.boundaryPoints.length<3)return;o(O=>nc(O.boundaryPoints,!0)?O:{...O,boundaryPoints:[...O.boundaryPoints,O.boundaryPoints[0]],boundaryClosed:!0});return}E.current=j,k.currentTarget.setPointerCapture(k.pointerId)},x=k=>{if(D.current){let O=m.current?.getBoundingClientRect();if(!O)return;let ne=D.current,ee=ne.startViewX-(k.clientX-ne.startX)/O.width*v,C=ne.startViewY-(k.clientY-ne.startY)/O.height*N;d({x:ee-R,y:C-T});return}if(i.boundaryClosed||w(et(k.clientX,k.clientY,!0)),E.current===null)return;let j=et(k.clientX,k.clientY);j&&o(O=>{let ne=O.boundaryPoints.length>2&&O.boundaryPoints[0].x===O.boundaryPoints[O.boundaryPoints.length-1].x&&O.boundaryPoints[0].y===O.boundaryPoints[O.boundaryPoints.length-1].y,ee=O.boundaryPoints.map((C,V)=>{let X=V===E.current,pe=ne&&E.current===0&&V===O.boundaryPoints.length-1;return X||pe?j:C});return nc(ee,!1)?O:{...O,boundaryPoints:ee}})},A=k=>{D.current=null,E.current=null,k.currentTarget.hasPointerCapture(k.pointerId)&&k.currentTarget.releasePointerCapture(k.pointerId)},I=k=>{o(j=>{let O=new Set(j.excludedBoundaryEdges);return O.has(k)?O.delete(k):O.add(k),{...j,excludedBoundaryEdges:O}})},ce=()=>{r===0?e():n(k=>k-1)},me=()=>{lt()&&(r===Ci.length-1?t?.(Ne):n(k=>k+1))},ke=xe(i.grid);return(0,H.jsx)(H.Fragment,{children:(0,H.jsxs)("div",{className:"truss-estimator",children:[(0,H.jsxs)("div",{className:"quick-order-hero",children:[(0,H.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,H.jsx)("h1",{children:"Fencing Calculator"}),(0,H.jsx)("p",{children:"Estimate panels, posts and cost for your fence line in a few steps."})]}),(0,H.jsxs)("div",{className:"truss-estimator__card",children:[(0,H.jsxs)("div",{className:"truss-estimator__body",children:[u==="range"?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ci.length]}),(0,H.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your fence panels"}),(0,H.jsx)("p",{className:"truss-estimator__step-sub",children:"The calculator uses fixed, orderable timber panels from the catalogue."}),(0,H.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Ca.ranges).map(([k,j])=>(0,H.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.range===k?" is-selected":""}`,onClick:()=>o(O=>({...O,range:k})),children:[(0,H.jsx)("div",{className:"truss-estimator__option-title",children:j.label}),(0,H.jsx)("div",{className:"truss-estimator__option-copy",children:j.blurb})]},k))})]}):null,u==="range"?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)("div",{className:"truss-estimator__section-heading",children:"Measure your fence line"}),(0,H.jsx)("p",{className:"truss-estimator__step-sub",children:"Use a quick total, or draw the boundary to mark existing edges that do not need new fencing."}),(0,H.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,H.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.boundaryMode==="quick"?" is-selected":""}`,onClick:()=>o(k=>({...k,boundaryMode:"quick"})),children:"Quick estimate"}),(0,H.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.boundaryMode==="draw"?" is-selected":""}`,onClick:()=>o(k=>({...k,boundaryMode:"draw"})),children:"Draw your boundary"})]}),i.boundaryMode==="quick"?(0,H.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact fence-boundary__quick-field",children:[(0,H.jsx)("span",{children:"Total fence length (m)"}),(0,H.jsx)("input",{type:"number",min:"0",step:"0.1",value:i.quickLengthM,onChange:k=>o(j=>({...j,quickLengthM:k.target.value}))})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)("div",{className:"fence-boundary__toolbar",children:(0,H.jsxs)("div",{className:"fence-boundary__actions",children:[(0,H.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(k=>({...k,boundaryPoints:k.boundaryPoints.slice(0,-1),boundaryClosed:!1,excludedBoundaryEdges:new Set})),disabled:i.boundaryPoints.length===0||i.boundaryClosed,children:"Undo"}),(0,H.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{d({x:0,y:0}),w(null),o(k=>({...k,boundaryPoints:[],boundaryClosed:!1,excludedBoundaryEdges:new Set}))},disabled:i.boundaryPoints.length===0,children:"Clear"}),(0,H.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(k=>({...k,boundaryPoints:[{x:2,y:2},{x:8,y:2},{x:8,y:5},{x:2,y:5},{x:2,y:2}],boundaryClosed:!0,excludedBoundaryEdges:new Set})),children:"Start with rectangle"})]})}),(0,H.jsxs)("div",{className:"fence-boundary",children:[(0,H.jsxs)("svg",{ref:m,className:`fence-boundary__canvas${i.boundaryClosed?" is-pan-mode":""}`,viewBox:`${z} ${G} ${v} ${N}`,preserveAspectRatio:"none","aria-label":"Fence boundary drawing area",onPointerDown:Ze,onPointerMove:x,onPointerUp:A,onPointerLeave:()=>{w(null),D.current||(E.current=null)},children:[(0,H.jsx)("defs",{children:(0,H.jsx)("pattern",{id:"fence-boundary-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,H.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,H.jsx)("rect",{x:-On,y:-Ln,width:On*3,height:Ln*3,className:"fence-boundary__grid",fill:"url(#fence-boundary-grid)"}),i.boundaryPoints.length>1?(0,H.jsx)("polyline",{className:"fence-boundary__preview",points:i.boundaryPoints.map(k=>`${k.x},${k.y}`).join(" ")}):null,i.boundaryPoints.length>1?i.boundaryPoints.slice(0,-1).map((k,j)=>{let O=i.boundaryPoints[j+1],ne=Math.hypot(O.x-k.x,O.y-k.y),ee=ne?-(O.y-k.y)/ne:0,C=ne?(O.x-k.x)/ne:0,V=(k.x+O.x)/2,X=(k.y+O.y)/2,pe=ee*(V-K.x)+C*(X-K.y)>=0?1:-1,Se=V+ee*vw*pe,ft=X+C*vw*pe;return(0,H.jsxs)("g",{children:[(0,H.jsx)("line",{className:"fence-boundary__edge-hit",x1:k.x,y1:k.y,x2:O.x,y2:O.y,onClick:i.boundaryClosed?()=>I(j):void 0}),(0,H.jsx)("line",{className:`fence-boundary__edge${i.excludedBoundaryEdges.has(j)?" is-excluded":""}`,x1:k.x,y1:k.y,x2:O.x,y2:O.y,pointerEvents:"none"}),(0,H.jsxs)("text",{className:`fence-boundary__edge-label${i.excludedBoundaryEdges.has(j)?" is-excluded":""}`,x:Se,y:ft,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[ne.toFixed(2)," m"]})]},`fence-edge-${j}`)}):null,!i.boundaryClosed&&i.boundaryPoints.length>0&&h?(()=>{let k=i.boundaryPoints[i.boundaryPoints.length-1],j=Math.hypot(h.x-k.x,h.y-k.y);if(!j)return null;let O=-(h.y-k.y)/j,ne=(h.x-k.x)/j,ee=(k.x+h.x)/2,C=(k.y+h.y)/2;return(0,H.jsxs)("g",{className:"fence-boundary__live-measurement",children:[(0,H.jsx)("line",{x1:k.x,y1:k.y,x2:h.x,y2:h.y}),(0,H.jsxs)("text",{x:ee+O*.34,y:C+ne*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[j.toFixed(2)," m"]})]})})():null,i.boundaryPoints.map((k,j)=>j>0&&j===i.boundaryPoints.length-1&&k.x===i.boundaryPoints[0]?.x&&k.y===i.boundaryPoints[0]?.y?null:(0,H.jsx)("circle",{className:`fence-boundary__point${!i.boundaryClosed&&j===0&&i.boundaryPoints.length>=3?" is-close-target":""}`,cx:k.x,cy:k.y,r:"0.13",onPointerDown:O=>M(O,j)},`fence-point-${j}`))]}),(0,H.jsxs)("div",{className:"fence-boundary__zoom","aria-label":"Zoom controls",children:[(0,H.jsx)("button",{type:"button",onClick:()=>f(k=>Math.max(.5,k-.25)),disabled:p===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,H.jsxs)("span",{children:[Math.round(p*100),"%"]}),(0,H.jsx)("button",{type:"button",onClick:()=>f(k=>Math.min(1,k+.25)),disabled:p===1,"aria-label":"Zoom in",children:"+"})]}),!i.boundaryClosed&&i.boundaryPoints.length>=2?(0,H.jsx)("button",{type:"button",className:"fence-boundary__close",onClick:()=>o(k=>nc(k.boundaryPoints,!1)?k:{...k,boundaryClosed:!0}),children:"Finish fence line"}):null]}),(0,H.jsx)("div",{className:"truss-estimator__grid-hint",children:i.boundaryClosed?"Drag the blank canvas to pan. Tap an edge to exclude it from the new fence.":"Click to add points, then finish the fence line. The displayed distances update as you draw."})]}),(0,H.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,H.jsx)("div",{children:i.boundaryMode==="quick"?`${(Number.parseFloat(i.quickLengthM)||0).toFixed(2)} m fence line`:`${ue.totalEdgeM.toFixed(2)} m fence line`}),i.boundaryMode==="draw"&&i.boundaryClosed?(0,H.jsxs)("div",{children:[ue.cornerPostCount," corner/end posts"]}):null]})]}):null,null,u==="height"?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ci.length]}),(0,H.jsx)("h2",{className:"truss-estimator__step-title",children:"Fence height"}),(0,H.jsx)("p",{className:"truss-estimator__step-sub",children:"Select the nearest available panel height."}),(0,H.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:Ca.heights.map(k=>(0,H.jsx)("button",{type:"button",className:`truss-estimator__visual-card${i.height===k?" is-selected":""}`,onClick:()=>o(j=>({...j,height:k})),children:(0,H.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--tall",src:Pt(`/fencing/height/${k}.webp`),alt:""})},k))}),(0,H.jsx)("div",{className:"truss-estimator__section-heading",children:"Gravel board?"}),(0,H.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"no",label:"No gravel board",img:"/fencing/no-gravel-board.webp"},{id:"yes",label:"Add gravel board",img:"/fencing/gravel-board.webp"}].map(k=>(0,H.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.gravelBoard===k.id?" is-selected":""}`,onClick:()=>o(j=>({...j,gravelBoard:k.id})),children:[(0,H.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Pt(k.img),alt:""}),(0,H.jsx)("span",{children:k.label})]},k.id))})]}):null,u==="gate"?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ci.length]}),(0,H.jsx)("h2",{className:"truss-estimator__step-title",children:"Do you need a gate?"}),(0,H.jsx)("p",{className:"truss-estimator__step-sub",children:"A gate opening replaces part of the panel run and adds a gate kit with heavy-duty posts."}),(0,H.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"none",label:"No gate",img:"/fencing/gates/no-gate.webp"},{id:"single",label:"Single gate",img:"/fencing/gates/single-gate.webp"}].map(k=>(0,H.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${i.gateType===k.id?" is-selected":""}`,onClick:()=>o(j=>({...j,gateType:k.id,gateWidthM:k.id==="none"?"":String(Ca.gate[k.id].widthDefault)})),children:[(0,H.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Pt(k.img),alt:""}),(0,H.jsx)("span",{children:k.label})]},k.id))}),i.gateType&&i.gateType!=="none"?(0,H.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,H.jsx)("span",{children:"Gate width (m)"}),(0,H.jsx)("input",{type:"text",inputMode:"decimal",value:i.gateWidthM,onChange:k=>o(j=>({...j,gateWidthM:k.target.value}))})]}):null]}):null,u==="posts"?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ci.length]}),(0,H.jsx)("h2",{className:"truss-estimator__step-title",children:"Posts and fixing type"}),(0,H.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose how the posts will be set."}),(0,H.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Ca.mounting).map(([k,j])=>(0,H.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.mountingType===k?" is-selected":""}`,onClick:()=>o(O=>({...O,mountingType:k})),children:[(0,H.jsx)("div",{className:"truss-estimator__option-title",children:j.label}),(0,H.jsx)("div",{className:"truss-estimator__option-copy",children:j.blurb})]},k))})]}):null]}),(0,H.jsxs)("div",{className:"truss-estimator__nav",children:[(0,H.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:ce,children:"Back"}),(0,H.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:me,disabled:!lt(),children:[(0,H.jsx)("span",{children:Ye}),(0,H.jsx)("span",{className:"arrow",children:(0,H.jsx)(Ht,{})})]})]})]})]})})}var oc=Y(Ke()),we=Y(ae()),ww={floor:{label:"Floor",product:"Knauf Acoustic Roll",thickness:"100mm",coverage:12.36,salesUnit:"roll"},wall:{label:"Cavity wall",product:"Celotex CW4100",thickness:"100mm",coverage:3.24,salesUnit:"pack"},roof:{label:"Pitched roof",product:"Kingspan K107",thickness:"100mm",coverage:8.64,salesUnit:"pack"},loft:{label:"Loft",product:"Knauf Loft Roll 44",thickness:"100mm",coverage:13.89,salesUnit:"roll"}};function Md({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,oc.useState)("floor"),[i,o]=(0,oc.useState)(""),[l,c]=(0,oc.useState)(""),p=Number.parseFloat(i)*Number.parseFloat(l)||0,f=ww[r],b=Math.ceil(p/f.coverage),d=[{key:`insulation-${r}`,label:`${f.product} ${f.thickness}`,qty:b,unit:f.salesUnit,query:f.product,category:"insulation"}],h=Object.entries(ww);return(0,we.jsx)(we.Fragment,{children:(0,we.jsxs)("div",{className:"truss-estimator",children:[(0,we.jsxs)("div",{className:"quick-order-hero",children:[(0,we.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,we.jsx)("h1",{children:"Insulation Calculator"}),(0,we.jsx)("p",{children:"Estimate insulation coverage and pack quantities for floors, walls, roofs and lofts."})]}),(0,we.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,we.jsx)("h2",{className:"truss-estimator__step-title",children:"Where and what you are insulating"}),(0,we.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the application and product, and enter the area, for coverage and pack quantities."}),(0,we.jsxs)("div",{className:"materials-calculator__section",children:[(0,we.jsx)("div",{className:"truss-estimator__section-heading",children:"Application"}),(0,we.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:h.map(([w,E])=>(0,we.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===w?" is-selected":""}`,onClick:()=>n(w),children:[(0,we.jsx)("div",{className:"truss-estimator__option-title",children:E.label}),(0,we.jsxs)("div",{className:"truss-estimator__option-copy",children:[E.product,", ",E.thickness]})]},w))})]}),(0,we.jsxs)("div",{className:"materials-calculator__section",children:[(0,we.jsx)("div",{className:"truss-estimator__section-heading",children:"Area"}),(0,we.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,we.jsxs)("label",{className:"truss-estimator__field",children:[(0,we.jsx)("span",{children:"Length (m)"}),(0,we.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:w=>o(w.target.value)})]}),(0,we.jsxs)("label",{className:"truss-estimator__field",children:[(0,we.jsx)("span",{children:"Width (m)"}),(0,we.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:w=>c(w.target.value)})]})]})]}),(0,we.jsxs)("div",{className:"materials-calculator__totals",children:[(0,we.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,we.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,we.jsxs)("div",{children:[(0,we.jsx)("span",{children:"Insulated area"}),(0,we.jsxs)("strong",{children:[p.toFixed(2)," m\xB2"]})]}),(0,we.jsxs)("div",{children:[(0,we.jsx)("span",{children:f.product}),(0,we.jsxs)("strong",{children:[b," packs"]})]})]}),(0,we.jsx)("p",{className:"materials-calculator__note",children:"This is a simple product choice, not thermal or Building Regulations advice. Confirm the specification before ordering."})]}),(0,we.jsxs)("div",{className:"materials-calculator__actions",children:[(0,we.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,we.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(d),disabled:p<=0,children:a})]})]})]})})}var Hn=Y(Ke()),Z=Y(ae()),L_=10,H_=1.9*.762,j_=1.9*1.524,lc=()=>({height:"",width:""}),sc=e=>Number.parseFloat(e)||0,yw=({height:e,width:t})=>sc(e)*sc(t);function Td({onBack:e}){let[t,a]=(0,Hn.useState)([lc()]),[r,n]=(0,Hn.useState)([lc()]),[i,o]=(0,Hn.useState)("0"),[l,c]=(0,Hn.useState)("0"),[p,f]=(0,Hn.useState)(1),b=t.reduce((m,u)=>m+yw(u),0),d=r.reduce((m,u)=>m+yw(u),0),h=sc(i)*H_+sc(l)*j_,w=Math.max(0,b-d-h),E=w*p/L_,D=(m,u,g,v)=>{m(N=>N.map((R,T)=>T===u?{...R,[g]:v}:R))};return(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsxs)("div",{className:"truss-estimator",children:[(0,Z.jsxs)("div",{className:"quick-order-hero",children:[(0,Z.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Z.jsx)("h1",{children:"Paint Calculator"}),(0,Z.jsx)("p",{children:"Estimate how much paint you need for your walls, including multiple coats and excluded areas."})]}),(0,Z.jsxs)("div",{className:"truss-estimator__card paint-calculator",children:[(0,Z.jsx)("h2",{className:"truss-estimator__step-title",children:"Walls, exclusions and coats"}),(0,Z.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter each wall, subtract windows and doors, and choose your number of coats. Quantities assume a coverage of 10 m\xB2 per litre."}),(0,Z.jsxs)("div",{className:"paint-calculator__section",children:[(0,Z.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,Z.jsx)("p",{className:"paint-calculator__hint",children:"Enter the height and width of each wall you want to paint."}),(0,Z.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,Z.jsx)("span",{}),(0,Z.jsx)("span",{children:"Height (m)"}),(0,Z.jsx)("span",{children:"Width (m)"}),(0,Z.jsx)("span",{})]}),t.map((m,u)=>(0,Z.jsxs)("div",{className:"paint-calculator__row",children:[(0,Z.jsxs)("span",{className:"paint-calculator__row-label",children:["Wall ",u+1]}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,Z.jsx)("input",{"aria-label":`Wall ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:m.height,onChange:g=>D(a,u,"height",g.target.value)})]}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,Z.jsx)("input",{"aria-label":`Wall ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:m.width,onChange:g=>D(a,u,"width",g.target.value)})]}),t.length>1?(0,Z.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>a(g=>g.filter((v,N)=>N!==u)),children:"Remove"}):null]},`wall-${u}`)),(0,Z.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>a(m=>[...m,lc()]),children:"+ Add another wall"})]}),(0,Z.jsxs)("div",{className:"paint-calculator__section",children:[(0,Z.jsx)("div",{className:"truss-estimator__section-heading",children:"Areas to exclude"}),(0,Z.jsx)("p",{className:"paint-calculator__hint",children:"Add windows, sockets, skirting boards or other areas that will not be painted."}),(0,Z.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,Z.jsx)("span",{}),(0,Z.jsx)("span",{children:"Height (m)"}),(0,Z.jsx)("span",{children:"Width (m)"}),(0,Z.jsx)("span",{})]}),r.map((m,u)=>(0,Z.jsxs)("div",{className:"paint-calculator__row",children:[(0,Z.jsxs)("span",{className:"paint-calculator__row-label",children:["Area ",u+1]}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,Z.jsx)("input",{"aria-label":`Area ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:m.height,onChange:g=>D(n,u,"height",g.target.value)})]}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,Z.jsx)("input",{"aria-label":`Area ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:m.width,onChange:g=>D(n,u,"width",g.target.value)})]}),r.length>1?(0,Z.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>n(g=>g.filter((v,N)=>N!==u)),children:"Remove"}):null]},`excluded-${u}`)),(0,Z.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>n(m=>[...m,lc()]),children:"+ Add another area"})]}),(0,Z.jsxs)("div",{className:"paint-calculator__section",children:[(0,Z.jsx)("div",{className:"truss-estimator__section-heading",children:"Doors and coats"}),(0,Z.jsx)("p",{className:"paint-calculator__hint",children:"Enter the number of standard single and double doors to leave unpainted. Door sizes are estimated automatically."}),(0,Z.jsxs)("div",{className:"truss-estimator__field-grid paint-calculator__small-fields",children:[(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{children:"Doors"}),(0,Z.jsx)("input",{type:"number",min:"0",step:"1",value:i,onChange:m=>o(m.target.value)})]}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{children:"Double doors"}),(0,Z.jsx)("input",{type:"number",min:"0",step:"1",value:l,onChange:m=>c(m.target.value)})]})]}),(0,Z.jsxs)("div",{className:"paint-calculator__coat-field",children:[(0,Z.jsx)("p",{className:"paint-calculator__hint",children:"Most walls need 2 coats for an even finish. Use 3 coats when changing colour significantly or covering a darker wall."}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{children:"Number of coats"}),(0,Z.jsxs)("select",{value:p,onChange:m=>f(Number(m.target.value)),children:[(0,Z.jsx)("option",{value:"1",children:"1 coat"}),(0,Z.jsx)("option",{value:"2",children:"2 coats"}),(0,Z.jsx)("option",{value:"3",children:"3 coats"})]})]})]})]}),(0,Z.jsxs)("div",{className:"paint-calculator__totals",children:[(0,Z.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,Z.jsxs)("div",{className:"paint-calculator__result-grid",children:[(0,Z.jsxs)("div",{children:[(0,Z.jsx)("span",{children:"Paintable area"}),(0,Z.jsxs)("strong",{children:[w.toFixed(2)," m\xB2"]})]}),(0,Z.jsxs)("div",{children:[(0,Z.jsx)("span",{children:"Coverage"}),(0,Z.jsxs)("strong",{children:[p," ",p===1?"coat":"coats"]})]}),(0,Z.jsxs)("div",{children:[(0,Z.jsx)("span",{children:"Paint required"}),(0,Z.jsxs)("strong",{children:[E.toFixed(1)," litres"]})]})]}),(0,Z.jsx)("p",{className:"paint-calculator__note",children:"Based on paint coverage of 10 m\xB2 per litre. Decorative paint is not currently stocked in this catalogue, so this remains an estimate only."})]}),(0,Z.jsxs)("div",{className:"paint-calculator__actions",children:[(0,Z.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,Z.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",disabled:!0,children:"Paint products unavailable"})]})]})]})})}var gr=Y(Ke()),re=Y(ae()),cc=e=>Number.parseFloat(e)||0,zd={paving:[{id:"council",label:"Council paving slab (600 \xD7 600mm)"},{id:"raj",label:"Raj blend sandstone (600 \xD7 600mm)"}],block:[{id:"brindle",label:"Brindle block paving (60mm)"},{id:"charcoal",label:"Charcoal block paving (60mm)"}],gravel:[{id:"pea",label:"20mm pea shingle"}]};function Ad({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,gr.useState)("paving"),[i,o]=(0,gr.useState)("council"),[l,c]=(0,gr.useState)(""),[p,f]=(0,gr.useState)(""),[b,d]=(0,gr.useState)("100"),[h,w]=(0,gr.useState)("50"),[E,D]=(0,gr.useState)(!0),[m,u]=(0,gr.useState)(!0),g=cc(l)*cc(p),v=g,N=g*(cc(b)/1e3),R=g*.04,T=g*(cc(h)/1e3),z=Math.ceil(v/.36),G=Math.ceil(v/.1),K=Math.ceil(N*1700/800),xe=Math.ceil(R*1600/800),Ee=Math.ceil(T*1600/800),Ge=r==="paving"?{qty:z,unit:"each"}:r==="block"?{qty:v,unit:"m2"}:{qty:Ee,unit:"bag"},Qe={paving:"paving slab",block:"block paver",gravel:"decorative gravel"}[r],Ie=[{key:`surface-${i}`,label:zd[r].find(Q=>Q.id===i)?.label??"Surface material",qty:Ge.qty,unit:Ge.unit,query:Qe,category:"landscaping"},...E?[{key:"sub-base",label:"MOT Type 1 sub-base",qty:K,unit:"bag",query:"MOT Type 1 sub base",category:"aggregate"}]:[],...m?[{key:"bedding",label:"Sharp sand bedding",qty:xe,unit:"bag",query:"sharp sand",category:"aggregate"}]:[]];return(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{className:"truss-estimator",children:[(0,re.jsxs)("div",{className:"quick-order-hero",children:[(0,re.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,re.jsx)("h1",{children:"Paving & Driveway Calculator"}),(0,re.jsx)("p",{children:"Estimate paving, block paving, sub-base and bedding materials for outdoor areas."})]}),(0,re.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,re.jsx)("h2",{className:"truss-estimator__step-title",children:"Surface and ground build-up"}),(0,re.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the surface material and enter the area. Sub-base and bedding sand are estimated alongside the surface units."}),(0,re.jsxs)("div",{className:"materials-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Surface material"}),(0,re.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:[["paving","Paving slabs","For patios and paths"],["block","Block paving","For driveways and paths"],["gravel","Decorative gravel","For paths and landscaping"]].map(([Q,se,Ne])=>(0,re.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===Q?" is-selected":""}`,onClick:()=>{n(Q),o(zd[Q][0].id)},children:[(0,re.jsx)("div",{className:"truss-estimator__option-title",children:se}),(0,re.jsx)("div",{className:"truss-estimator__option-copy",children:Ne})]},Q))}),(0,re.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,re.jsx)("span",{children:"Finish"}),(0,re.jsx)("select",{value:i,onChange:Q=>o(Q.target.value),children:zd[r].map(Q=>(0,re.jsx)("option",{value:Q.id,children:Q.label},Q.id))})]})]}),(0,re.jsxs)("div",{className:"materials-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and groundwork"}),(0,re.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,re.jsxs)("label",{className:"truss-estimator__field",children:[(0,re.jsx)("span",{children:"Length (m)"}),(0,re.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:Q=>c(Q.target.value)})]}),(0,re.jsxs)("label",{className:"truss-estimator__field",children:[(0,re.jsx)("span",{children:"Width (m)"}),(0,re.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:Q=>f(Q.target.value)})]})]}),r==="gravel"&&(0,re.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,re.jsx)("span",{children:"Gravel depth (mm)"}),(0,re.jsx)("input",{type:"number",min:"0",step:"10",value:h,onChange:Q=>w(Q.target.value)})]}),E&&(0,re.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,re.jsx)("span",{children:"Sub-base depth (mm)"}),(0,re.jsx)("input",{type:"number",min:"0",step:"10",value:b,onChange:Q=>d(Q.target.value)})]}),(0,re.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,re.jsx)("input",{type:"checkbox",checked:E,onChange:Q=>D(Q.target.checked)}),(0,re.jsx)("span",{children:"Include MOT Type 1 sub-base"})]}),(0,re.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,re.jsx)("input",{type:"checkbox",checked:m,onChange:Q=>u(Q.target.checked)}),(0,re.jsx)("span",{children:"Include sharp sand bedding"})]})]}),(0,re.jsxs)("div",{className:"materials-calculator__totals",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,re.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Surface area"}),(0,re.jsxs)("strong",{children:[g.toFixed(2)," m\xB2"]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:r==="paving"?"Paving slabs":r==="block"?"Block paving":"Gravel"}),(0,re.jsx)("strong",{children:r==="paving"?`${z} slabs`:r==="block"?`${v.toFixed(2)} m\xB2`:`${Ee} bulk bags`})]}),E&&(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"MOT Type 1"}),(0,re.jsxs)("strong",{children:[K," bulk bags"]})]}),m&&(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Sharp sand"}),(0,re.jsxs)("strong",{children:[xe," bulk bags"]})]})]}),(0,re.jsx)("p",{className:"materials-calculator__note",children:"Slab and block quantities use typical sizes. Confirm pack coverage and laying pattern before ordering."})]}),(0,re.jsxs)("div",{className:"materials-calculator__actions",children:[(0,re.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,re.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(Ie),disabled:g<=0,children:a})]})]})]})})}var il=Y(Ke()),ie=Y(ae()),G_=2.88,_w=[{id:"standard",label:"Standard wallboard",blurb:"General internal walls and ceilings"},{id:"moisture",label:"Moisture resistant",blurb:"Kitchens, bathrooms and utility rooms"},{id:"fire",label:"Fire resistant",blurb:"Where fire-rated lining is required"},{id:"sound",label:"Sound resistant",blurb:"Improved acoustic performance"}],xw=()=>({length:"",height:""}),Rd=e=>Number.parseFloat(e)||0;function Ud({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,il.useState)([xw()]),[i,o]=(0,il.useState)(""),[l,c]=(0,il.useState)("standard"),[p,f]=(0,il.useState)("screws"),b=r.reduce((R,T)=>R+Rd(T.length)*Rd(T.height),0),d=Math.max(0,b-Rd(i)),h=Math.ceil(d/G_),w=Math.ceil(d*12),E=Math.ceil(w/1e3),D=Math.ceil(d*1.2),m=Math.ceil(D/90),u=Math.ceil(d/3.5),g=_w.find(R=>R.id===l)?.label??"Standard",v=[{key:"board",label:`${g} plasterboard`,qty:h,unit:"sheet",query:`${g} plasterboard`,category:"plasterboard"},...p==="screws"?[{key:"screws",label:"Drywall screws",qty:E,unit:"box",query:"drywall screws",category:"fixings"}]:[{key:"adhesive",label:"Board adhesive",qty:u,unit:"bag",query:"drywall board adhesive",category:"plasterboard"}],{key:"tape",label:"Joint tape",qty:m,unit:"roll",query:"plasterboard joint tape",category:"plasterboard"}],N=(R,T,z)=>{n(G=>G.map((K,xe)=>xe===R?{...K,[T]:z}:K))};return(0,ie.jsx)(ie.Fragment,{children:(0,ie.jsxs)("div",{className:"truss-estimator",children:[(0,ie.jsxs)("div",{className:"quick-order-hero",children:[(0,ie.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ie.jsx)("h1",{children:"Plasterboard & Drylining Calculator"}),(0,ie.jsx)("p",{children:"Estimate boards, fixings and jointing materials for walls and ceilings."})]}),(0,ie.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,ie.jsx)("h2",{className:"truss-estimator__step-title",children:"Boards, fixings and jointing"}),(0,ie.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter the surfaces you are lining and the board specification. Screws, tape and adhesive are estimated with the boards."}),(0,ie.jsxs)("div",{className:"materials-calculator__section",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Board type"}),(0,ie.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:_w.map(R=>(0,ie.jsxs)("button",{type:"button",className:`truss-estimator__option-card${l===R.id?" is-selected":""}`,onClick:()=>c(R.id),children:[(0,ie.jsx)("div",{className:"truss-estimator__option-title",children:R.label}),(0,ie.jsx)("div",{className:"truss-estimator__option-copy",children:R.blurb})]},R.id))})]}),(0,ie.jsxs)("div",{className:"materials-calculator__section",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Fixing method"}),(0,ie.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["screws","Drywall screws","For timber or metal framing"],["adhesive","Board adhesive","For masonry dot-and-dab"]].map(([R,T,z])=>(0,ie.jsxs)("button",{type:"button",className:`truss-estimator__option-card${p===R?" is-selected":""}`,onClick:()=>f(R),children:[(0,ie.jsx)("div",{className:"truss-estimator__option-title",children:T}),(0,ie.jsx)("div",{className:"truss-estimator__option-copy",children:z})]},R))})]}),(0,ie.jsxs)("div",{className:"materials-calculator__section",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall and ceiling areas"}),(0,ie.jsx)("p",{className:"materials-calculator__hint",children:"Add each surface separately so different wall sizes are easy to measure."}),(0,ie.jsxs)("div",{className:"materials-calculator__dimensions-header",children:[(0,ie.jsx)("span",{children:"Surface"}),(0,ie.jsx)("span",{children:"Length (m)"}),(0,ie.jsx)("span",{children:"Height (m)"}),(0,ie.jsx)("span",{})]}),r.map((R,T)=>(0,ie.jsxs)("div",{className:"materials-calculator__surface-row",children:[(0,ie.jsxs)("span",{children:["Surface ",T+1]}),(0,ie.jsx)("input",{"aria-label":`Surface ${T+1} length`,type:"number",min:"0",step:"0.01",value:R.length,onChange:z=>N(T,"length",z.target.value)}),(0,ie.jsx)("input",{"aria-label":`Surface ${T+1} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:z=>N(T,"height",z.target.value)}),r.length>1?(0,ie.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>n(z=>z.filter((G,K)=>K!==T)),children:"Remove"}):null]},`surface-${T}`)),(0,ie.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>n(R=>[...R,xw()]),children:"+ Add another surface"}),(0,ie.jsxs)("label",{className:"truss-estimator__field materials-calculator__openings",children:[(0,ie.jsxs)("span",{children:["Openings to deduct (m\xB2) ",(0,ie.jsx)("small",{children:"optional"})]}),(0,ie.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:R=>o(R.target.value)})]})]}),(0,ie.jsxs)("div",{className:"materials-calculator__totals",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ie.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:"Board area"}),(0,ie.jsxs)("strong",{children:[d.toFixed(2)," m\xB2"]})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:"2.4 x 1.2 m boards"}),(0,ie.jsx)("strong",{children:h})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:p==="screws"?"Drywall screws":"Board adhesive"}),(0,ie.jsx)("strong",{children:p==="screws"?`${w} (${E} boxes)`:`${u} bags`})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:"Joint tape"}),(0,ie.jsxs)("strong",{children:[D," m (",m," rolls)"]})]})]}),(0,ie.jsx)("p",{className:"materials-calculator__note",children:"Figures are estimates. Confirm board specification, fixing patterns and fire or acoustic requirements before ordering."})]}),(0,ie.jsxs)("div",{className:"materials-calculator__actions",children:[(0,ie.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ie.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(v),disabled:d<=0,children:a})]})]})]})})}var nl=Y(Ke());var y=Y(ae()),At={ranges:{standard:{label:"Standard Fink",blurb:"Classic W-shaped truss for standard pitched roofs."},attic:{label:"Attic",blurb:"Room-in-roof truss with usable attic space and clear span."},mono:{label:"Mono-pitch",blurb:"Single-slope truss for lean-to roofs and outbuildings."}},pitches:["15","20","22.5","25","30","35","40","45","50","55"],pitchMultipliers:{15:.95,20:.98,"22.5":1,25:1.02,30:1.05,35:1.1,40:1.18,45:1.27,50:1.38,55:1.52},overhang:{thresholdMM:300,surchargePerTruss:3.5},centresOptions:["400","600"],treatment:{treated:{label:"Treated (tanalised)",surchargePct:.08},untreated:{label:"Untreated",surchargePct:0}},estimate:{design:250,delivery:250,bracingPerMetre:6.5,girderMultiplier:1.8,ranges:{standard:{supplyAt8m:53.33,installPerTruss:30},attic:{supplyAt8m:128.35,installPerTruss:55},mono:{supplyAt8m:60,installPerTruss:38}}}},uc=["range","pitchAndDimensions","quantityAndGirders","bracing"],Q_={range:null,pitch:null,spanMM:"",overhangMM:"",roofLengthM:"",centres:null,girderCount:0,bracing:null,treatment:null,contact:{name:"",email:""}};function Y_({degrees:e}){let a=e*Math.PI/180,n=82-Math.min(58,38*Math.tan(a));return(0,y.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,y.jsx)("line",{x1:"6",y1:"82",x2:"94",y2:"82",stroke:"var(--border)",strokeWidth:"2"}),(0,y.jsx)("polygon",{points:`12,82 88,82 50,${n}`,fill:"var(--accent-light)",stroke:"var(--accent)",strokeWidth:"3",strokeLinejoin:"round"})]})}function V_({type:e}){let t="#b3835a",a="#5c3b22",r="#d9b48f",n="#d3d8de",i="#7c8494",o=(f,b,d,h,w=8,E)=>{let D=d-f,m=h-b,u=Math.hypot(D,m)||1,g=-m/u,v=D/u,N=w*.2;return(0,y.jsxs)("g",{children:[(0,y.jsx)("line",{x1:f,y1:b,x2:d,y2:h,stroke:a,strokeWidth:w+3,strokeLinecap:"square"}),(0,y.jsx)("line",{x1:f,y1:b,x2:d,y2:h,stroke:t,strokeWidth:w,strokeLinecap:"square"}),(0,y.jsx)("line",{x1:f-g*N,y1:b-v*N,x2:d-g*N,y2:h-v*N,stroke:r,strokeWidth:Math.max(1.5,w*.24),strokeLinecap:"round",opacity:"0.9"})]},E)},l=(f,b,d)=>(0,y.jsxs)("g",{children:[(0,y.jsx)("rect",{x:f-7.5,y:b-5.5,width:"15",height:"11",rx:"2",fill:n,stroke:i,strokeWidth:"1"}),(0,y.jsx)("circle",{cx:f-4,cy:b-2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:f+4,cy:b-2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:f-4,cy:b+2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:f+4,cy:b+2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:f,cy:b,r:"1",fill:i})]},d),c=(f,b)=>(0,y.jsx)("rect",{x:f-9,y:"110",width:"18",height:"10",fill:a},b),p=(0,y.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"});return e==="attic"?(0,y.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[p,c(26,"wl"),c(174,"wr"),o(26,112,100,26,8,"b1"),o(174,112,100,26,8,"b2"),o(26,112,174,112,8,"b3"),o(58,112,58,70,6,"b4"),o(142,112,142,70,6,"b5"),o(58,70,142,70,7,"b6"),(0,y.jsx)("rect",{x:"90",y:"82",width:"20",height:"24",fill:"#cfe3f2",stroke:a,strokeWidth:"2"}),(0,y.jsx)("line",{x1:"100",y1:"82",x2:"100",y2:"106",stroke:a,strokeWidth:"1.5"}),l(26,112,"p1"),l(174,112,"p2"),l(100,26,"p3"),l(58,112,"p4"),l(58,70,"p5"),l(142,112,"p6"),l(142,70,"p7")]}):e==="mono"?(0,y.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[p,c(26,"wl"),c(174,"wr"),o(26,112,174,26,8,"b1"),o(174,26,174,112,8,"b2"),o(26,112,174,112,8,"b3"),o(90,112,90,75,5,"b4"),o(90,75,132,112,5,"b5"),l(26,112,"p1"),l(174,26,"p2"),l(174,112,"p3"),l(90,112,"p4"),l(90,75,"p5"),l(132,112,"p6")]}):(0,y.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[p,c(26,"wl"),c(174,"wr"),o(26,112,100,34,8,"b1"),o(174,112,100,34,8,"b2"),o(26,112,174,112,8,"b3"),o(63,112,100,34,5,"b4"),o(137,112,100,34,5,"b5"),o(63,112,54,83,5,"b6"),o(137,112,146,83,5,"b7"),(0,y.jsx)("rect",{x:"96",y:"108",width:"8",height:"8",fill:a}),l(26,112,"p1"),l(174,112,"p2"),l(100,34,"p3"),l(63,112,"p4"),l(137,112,"p5"),l(54,83,"p6"),l(146,83,"p7")]})}function X_({enabled:e}){return(0,y.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[(0,y.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"}),(0,y.jsx)("rect",{x:"17",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,y.jsx)("rect",{x:"165",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,y.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,y.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,y.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,y.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,y.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,y.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),e?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("line",{x1:"45",y1:"112",x2:"140",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"}),(0,y.jsx)("line",{x1:"155",y1:"112",x2:"60",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"})]}):null,(0,y.jsx)("rect",{x:"18.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,y.jsx)("rect",{x:"166.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,y.jsx)("rect",{x:"92.5",y:"28.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"})]})}function kw({treated:e}){let t=e?"#5a7a4a":"var(--accent)";return(0,y.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,y.jsx)("rect",{x:"10",y:"22",width:"80",height:"14",rx:"2",fill:t}),(0,y.jsx)("rect",{x:"10",y:"43",width:"80",height:"14",rx:"2",fill:e?"#8faf7a":"var(--accent-light)"}),(0,y.jsx)("rect",{x:"10",y:"64",width:"80",height:"14",rx:"2",fill:t})]})}function Dd({onBack:e}){let[t,a]=(0,nl.useState)(0),[r,n]=(0,nl.useState)(Q_),[i,o]=(0,nl.useState)(!1),[l,c]=(0,nl.useState)(!1),p=()=>{let m=Number.parseFloat(r.roofLengthM)||0,u=Number.parseFloat(r.centres??"");return m<=0||!u?0:Math.ceil(m*1e3/u)+1},b=(()=>{let m=r.range?At.ranges[r.range]:At.ranges.standard,u=r.pitch??"22.5",g=At.pitchMultipliers[u],v=(Number.parseFloat(r.spanMM)||0)/1e3,R=(Number.parseFloat(r.overhangMM)||0)>At.overhang.thresholdMM,T=p(),z=T+r.girderCount,G=Number.parseFloat(r.roofLengthM)||0,K=r.treatment?At.treatment[r.treatment]:At.treatment.untreated,xe=At.estimate.ranges[r.range??"standard"],Ee=xe.supplyAt8m*Math.max(.7,v/8)*g*(1+K.surchargePct)+(R?At.overhang.surchargePerTruss:0),Ge=T*Ee,Qe=r.girderCount*Ee*At.estimate.girderMultiplier,Ie=r.bracing==="yes"?G*At.estimate.bracingPerMetre:0,ue=Ge+Qe+Ie+At.estimate.delivery,Q=At.estimate.design+T*xe.installPerTruss+r.girderCount*40,se=ue+Q,Ne=se*.2;return{range:m,count:T,girderCount:r.girderCount,overhangApplies:R,overhangUnits:z,roofLengthM:G,treatment:K,trussSupply:Ge,bracingMaterials:Ie,delivery:At.estimate.delivery,labour:Q,subtotal:se,vat:Ne,total:se+Ne}})(),d=()=>{let m=uc[t];return m==="range"?!!r.range:m==="pitchAndDimensions"?!!r.pitch&&r.spanMM.trim()!==""&&r.overhangMM.trim()!=="":m==="quantityAndGirders"?r.roofLengthM.trim()!==""&&!!r.centres:m==="bracing"?!!r.bracing&&!!r.treatment:!0},h=t===uc.length-1?"View truss request":"Next",w=()=>{i?o(!1):t===0?e():a(m=>m-1)},E=()=>{d()&&(t===uc.length-1?(c(!1),o(!0)):a(m=>m+1))},D=()=>{let m=uc[t];return m==="range"?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Step 1 of 4"}),(0,y.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your truss range"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"Pricing shown is placeholder. Swap in your real engineering and pricing catalogue."}),(0,y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--range",children:Object.entries(At.ranges).map(([u,g])=>(0,y.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r.range===u?" is-selected":""}`,onClick:()=>n(v=>({...v,range:u})),children:[(0,y.jsx)(V_,{type:u}),(0,y.jsxs)("div",{className:"truss-estimator__option-info",children:[(0,y.jsx)("div",{className:"truss-estimator__option-title",children:g.label}),(0,y.jsx)("div",{className:"truss-estimator__option-copy",children:g.blurb})]})]},u))})]}):m==="pitchAndDimensions"?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Step 2 of 4"}),(0,y.jsx)("h2",{className:"truss-estimator__step-title",children:"Span, overhang and roof pitch"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"Span is wall-to-wall, overhang is the eaves tail beyond the wall line. Steeper pitches use more timber per truss."}),(0,y.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,y.jsxs)("label",{className:"truss-estimator__field",children:[(0,y.jsx)("span",{children:"Span (mm)"}),(0,y.jsx)("input",{type:"text",inputMode:"numeric",value:r.spanMM,onChange:u=>n(g=>({...g,spanMM:u.target.value}))})]}),(0,y.jsxs)("label",{className:"truss-estimator__field",children:[(0,y.jsx)("span",{children:"Overhang (mm)"}),(0,y.jsx)("input",{type:"text",inputMode:"numeric",value:r.overhangMM,onChange:u=>n(g=>({...g,overhangMM:u.target.value}))}),(0,y.jsxs)("small",{children:["Overhangs beyond ",At.overhang.thresholdMM,"mm add a small surcharge per truss."]})]})]}),(0,y.jsx)("div",{className:"truss-estimator__section-heading",children:"Roof pitch"}),(0,y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:At.pitches.map(u=>(0,y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${r.pitch===u?" is-selected":""}`,onClick:()=>n(g=>({...g,pitch:u})),children:[(0,y.jsx)(Y_,{degrees:Number.parseFloat(u)}),(0,y.jsxs)("span",{children:[u,"\xB0"]})]},u))})]}):m==="quantityAndGirders"?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Step 3 of 4"}),(0,y.jsx)("h2",{className:"truss-estimator__step-title",children:"Roof length"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"Trusses are based on designs at 400mm or 600mm centres wherever possible."}),(0,y.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,y.jsx)("span",{children:"Roof length (m)"}),(0,y.jsx)("input",{type:"text",inputMode:"decimal",value:r.roofLengthM,onChange:u=>n(g=>({...g,roofLengthM:u.target.value}))})]}),(0,y.jsx)("div",{className:"truss-estimator__section-heading",children:"Truss centres"}),(0,y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--centres",children:At.centresOptions.map(u=>(0,y.jsx)("button",{type:"button",className:`truss-estimator__option-card truss-estimator__option-card--compact${r.centres===u?" is-selected":""}`,onClick:()=>n(g=>({...g,centres:u})),children:(0,y.jsxs)("div",{className:"truss-estimator__option-title",children:[u,"mm centres"]})},u))}),(0,y.jsxs)("div",{className:"truss-estimator__stat",children:[p()," trusses estimated"]}),(0,y.jsx)("div",{className:"truss-estimator__section-heading",children:"Girder trusses"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"Heavy-duty girder trusses carry point loads over large openings. Set 0 if you do not need any."}),(0,y.jsxs)("div",{className:"truss-estimator__stepper",children:[(0,y.jsx)("button",{type:"button",onClick:()=>n(u=>({...u,girderCount:Math.max(0,u.girderCount-1)})),children:"\u2212"}),(0,y.jsx)("span",{children:r.girderCount}),(0,y.jsx)("button",{type:"button",onClick:()=>n(u=>({...u,girderCount:Math.min(3,u.girderCount+1)})),children:"+"})]})]}):m==="bracing"?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Step 4 of 4"}),(0,y.jsx)("h2",{className:"truss-estimator__step-title",children:"Bracing pack?"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"A timber bracing pack stabilises the roof structure once trusses are erected."}),(0,y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"no",label:"No bracing pack"},{id:"yes",label:"Add bracing pack"}].map(u=>(0,y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.bracing===u.id?" is-selected":""}`,onClick:()=>n(g=>({...g,bracing:u.id})),children:[(0,y.jsx)(X_,{enabled:u.id==="yes"}),(0,y.jsx)("span",{children:u.label})]},u.id))}),(0,y.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber treatment"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"Tanalised timber protects against rot in exposed or damp locations."}),(0,y.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.treatment==="untreated"?" is-selected":""}`,onClick:()=>n(u=>({...u,treatment:"untreated"})),children:[(0,y.jsx)(kw,{treated:!1}),(0,y.jsx)("span",{children:"Untreated"})]}),(0,y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.treatment==="treated"?" is-selected":""}`,onClick:()=>n(u=>({...u,treatment:"treated"})),children:[(0,y.jsx)(kw,{treated:!0}),(0,y.jsx)("span",{children:"Treated (+8% cost)"}),(0,y.jsx)("small",{children:"Applies to trusses, girders and overhang"})]})]})]}):null};return i?(0,y.jsx)(y.Fragment,{children:(0,y.jsxs)("div",{className:"truss-estimator",children:[(0,y.jsxs)("div",{className:"quick-order-hero",children:[(0,y.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,y.jsx)("h1",{children:"Your truss estimate"}),(0,y.jsx)("p",{children:"A provisional quantity and specification based on the dimensions you entered."})]}),(0,y.jsxs)("div",{className:"truss-estimator__card truss-request",style:{minHeight:0},children:[(0,y.jsxs)("div",{className:"truss-request__heading",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Estimated requirement"}),(0,y.jsxs)("h2",{children:[b.range.label," roof trusses"]})]}),(0,y.jsxs)("strong",{children:[b.count,(0,y.jsx)("span",{children:"trusses"})]})]}),(0,y.jsxs)("div",{className:"truss-request__grid",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Span"}),(0,y.jsxs)("strong",{children:[r.spanMM," mm"]})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Roof length"}),(0,y.jsxs)("strong",{children:[r.roofLengthM," m"]})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Pitch"}),(0,y.jsxs)("strong",{children:[r.pitch,"\xB0"]})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Centres"}),(0,y.jsxs)("strong",{children:[r.centres," mm"]})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Overhang"}),(0,y.jsxs)("strong",{children:[r.overhangMM," mm"]})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Treatment"}),(0,y.jsx)("strong",{children:b.treatment.label})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Girder trusses"}),(0,y.jsx)("strong",{children:b.girderCount||"None"})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Bracing pack"}),(0,y.jsx)("strong",{children:r.bracing==="yes"?"Included":"Not included"})]})]}),(0,y.jsxs)("div",{className:"truss-request__price",children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Indicative cost estimate"}),(0,y.jsxs)("div",{className:"truss-request__price-grid",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Truss supply allowance"}),(0,y.jsx)("strong",{children:st(b.trussSupply)})]}),b.bracingMaterials>0&&(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Bracing materials allowance"}),(0,y.jsx)("strong",{children:st(b.bracingMaterials)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Delivery allowance"}),(0,y.jsx)("strong",{children:st(b.delivery)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Design and installation labour"}),(0,y.jsx)("strong",{children:st(b.labour)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Subtotal (ex. VAT)"}),(0,y.jsx)("strong",{children:st(b.subtotal)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"VAT (20%)"}),(0,y.jsx)("strong",{children:st(b.vat)})]}),(0,y.jsxs)("div",{className:"truss-request__price-total",children:[(0,y.jsx)("span",{children:"Estimated total"}),(0,y.jsx)("strong",{children:st(b.total)})]})]}),(0,y.jsx)("p",{children:"Trusses are not listed as fixed products in this catalogue, so supply, delivery and labour are benchmark allowances. Confirm the engineered design and final quote before ordering."})]}),(0,y.jsxs)("div",{className:"truss-request__notice",children:[(0,y.jsx)("strong",{children:"Before ordering"}),(0,y.jsx)("span",{children:"Roof trusses must be designed and signed off for the building. Confirm loading, bearings, wind bracing and final drawings with the truss manufacturer."})]}),(0,y.jsxs)("div",{className:"truss-estimator__nav",children:[(0,y.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:w,children:"Back to calculator"}),(0,y.jsx)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",justifyContent:"center",marginTop:0},onClick:()=>c(!0),children:"Request order"})]}),l&&(0,y.jsx)("p",{className:"truss-request__demo",children:"Demo only \u2014 no order has been sent."})]})]})}):(0,y.jsx)(y.Fragment,{children:(0,y.jsxs)("div",{className:"truss-estimator",children:[(0,y.jsxs)("div",{className:"quick-order-hero",children:[(0,y.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,y.jsx)("h1",{children:"Roof Truss Calculator"}),(0,y.jsx)("p",{children:"Estimate trusses, girders and cost for your roof in a few steps."})]}),(0,y.jsxs)("div",{className:"truss-estimator__card",children:[(0,y.jsx)("div",{className:"truss-estimator__body",children:D()}),(0,y.jsxs)("div",{className:"truss-estimator__nav",children:[(0,y.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:w,children:"Back"}),(0,y.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:E,disabled:!d(),children:[(0,y.jsx)("span",{children:h}),(0,y.jsx)("span",{className:"arrow",children:(0,y.jsx)(Ht,{})})]})]})]})]})})}var qi=Y(Ke()),F=Y(ae()),Cw=e=>Number.parseFloat(e)||0,pc=(e,t)=>Cw(e)*(t==="m"?1:.3048),Nw=()=>({length:"",width:""}),Sw=[{id:"chamfered",label:"Chamfered",blurb:"Clean angled edge"},{id:"ogee",label:"Ogee",blurb:"Traditional curved profile"},{id:"pencil-round",label:"Pencil round",blurb:"Simple softened edge"},{id:"torus",label:"Torus",blurb:"Soft rounded detail"}];function $_({profile:e}){return(0,F.jsxs)("svg",{className:"skirting-calculator__profile-diagram",viewBox:"0 0 120 84","aria-hidden":"true",children:[(0,F.jsx)("path",{d:{chamfered:"M16 70V43L43 16H104V70Z",ogee:"M16 70V47C16 36 27 31 40 31C40 21 50 16 63 16H104V70Z","pencil-round":"M16 70V37C16 25 25 16 37 16H104V70Z",torus:"M16 70V49C16 39 25 34 36 34C36 22 47 16 61 16H104V70Z"}[e]}),(0,F.jsx)("line",{x1:"12",y1:"70",x2:"108",y2:"70"})]})}function Bd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,qi.useState)("total"),[i,o]=(0,qi.useState)("m"),[l,c]=(0,qi.useState)(""),[p,f]=(0,qi.useState)([Nw()]),[b,d]=(0,qi.useState)(""),[h,w]=(0,qi.useState)("chamfered"),E="4.2",D=r==="total"?pc(l,i):p.reduce((N,R)=>N+2*(pc(R.length,i)+pc(R.width,i)),0),m=Math.max(0,D-pc(b,i)),u=Math.ceil(m/Cw(E)),g=[{key:`skirting-${h}`,label:`${Sw.find(N=>N.id===h)?.label} skirting board`,qty:m,unit:"m",query:"skirting board",category:"skirting"}],v=(N,R,T)=>{f(z=>z.map((G,K)=>K===N?{...G,[R]:T}:G))};return(0,F.jsx)(F.Fragment,{children:(0,F.jsxs)("div",{className:"truss-estimator",children:[(0,F.jsxs)("div",{className:"quick-order-hero",children:[(0,F.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,F.jsx)("h1",{children:"Skirting Board Calculator"}),(0,F.jsx)("p",{children:"Work out how many skirting board lengths you need for one room or a whole project."})]}),(0,F.jsxs)("div",{className:"truss-estimator__card skirting-calculator",children:[(0,F.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure by room or total length"}),(0,F.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter a single total or work room by room. The run is converted straight into board lengths."}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"How would you like to measure?"}),(0,F.jsxs)("div",{className:"brick-calculator__unit-toggle skirting-calculator__mode-toggle",role:"group","aria-label":"Calculation method",children:[(0,F.jsx)("button",{type:"button",className:r==="total"?"is-selected":"",onClick:()=>n("total"),children:"Total length"}),(0,F.jsx)("button",{type:"button",className:r==="rooms"?"is-selected":"",onClick:()=>n("rooms"),children:"Room by room"})]})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Measurements"}),(0,F.jsxs)("div",{className:"skirting-calculator__unit-row",children:[(0,F.jsx)("span",{children:"Units"}),(0,F.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,F.jsx)("button",{type:"button",className:i==="m"?"is-selected":"",onClick:()=>o("m"),children:"Metres"}),(0,F.jsx)("button",{type:"button",className:i==="ft"?"is-selected":"",onClick:()=>o("ft"),children:"Feet"})]})]}),r==="total"?(0,F.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,F.jsxs)("span",{children:["Total skirting length (",i,")"]}),(0,F.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:N=>c(N.target.value)})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)("div",{className:"skirting-calculator__dimensions-header",children:[(0,F.jsx)("span",{children:"Room"}),(0,F.jsxs)("span",{children:["Length (",i,")"]}),(0,F.jsxs)("span",{children:["Width (",i,")"]}),(0,F.jsx)("span",{})]}),p.map((N,R)=>(0,F.jsxs)("div",{className:"skirting-calculator__room-row",children:[(0,F.jsxs)("span",{className:"skirting-calculator__room-label",children:["Room ",R+1]}),(0,F.jsx)("input",{"aria-label":`Room ${R+1} length in ${i}`,type:"number",min:"0",step:"0.01",value:N.length,onChange:T=>v(R,"length",T.target.value)}),(0,F.jsx)("input",{"aria-label":`Room ${R+1} width in ${i}`,type:"number",min:"0",step:"0.01",value:N.width,onChange:T=>v(R,"width",T.target.value)}),p.length>1?(0,F.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>f(T=>T.filter((z,G)=>G!==R)),children:"Remove"}):null]},`room-${R}`)),(0,F.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>f(N=>[...N,Nw()]),children:"+ Add another room"})]}),(0,F.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,F.jsxs)("span",{children:["Openings and doorways to deduct (",i,") ",(0,F.jsx)("small",{children:"optional"})]}),(0,F.jsx)("input",{type:"number",min:"0",step:"0.01",value:b,onChange:N=>d(N.target.value)})]})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Profile"}),(0,F.jsx)("p",{className:"skirting-calculator__hint",children:"Choose the finish you want for the fixed 4.2m white-primed MDF boards."}),(0,F.jsx)("div",{className:"architrave-calculator__profiles",children:Sw.map(N=>(0,F.jsxs)("button",{type:"button",className:`truss-estimator__option-card${h===N.id?" is-selected":""}`,onClick:()=>w(N.id),children:[(0,F.jsx)($_,{profile:N.id}),(0,F.jsx)("div",{className:"truss-estimator__option-title",children:N.label}),(0,F.jsx)("div",{className:"truss-estimator__option-copy",children:N.blurb})]},N.id))})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,F.jsx)("div",{className:"truss-estimator__field-grid skirting-calculator__options-grid",children:(0,F.jsxs)("label",{className:"truss-estimator__field",children:[(0,F.jsx)("span",{children:"Board length"}),(0,F.jsx)("input",{value:"4.20 m",disabled:!0})]})}),(0,F.jsx)("p",{className:"skirting-calculator__hint",children:"Longer boards can reduce the number of joins, while 10% waste allows for cuts, corners and mistakes."})]}),(0,F.jsxs)("div",{className:"skirting-calculator__totals",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,F.jsxs)("div",{className:"skirting-calculator__result-grid",children:[(0,F.jsxs)("div",{children:[(0,F.jsx)("span",{children:"Net skirting"}),(0,F.jsxs)("strong",{children:[m.toFixed(2)," m"]})]}),(0,F.jsxs)("div",{children:[(0,F.jsx)("span",{children:"Board lengths"}),(0,F.jsx)("strong",{children:u})]})]}),(0,F.jsx)("p",{className:"skirting-calculator__note",children:"Corners and joins vary by room layout. Measure each wall where possible for the most accurate result."})]}),(0,F.jsxs)("div",{className:"skirting-calculator__actions",children:[(0,F.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,F.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(g),disabled:m<=0,children:a})]})]})]})})}var jn=Y(Ke()),oe=Y(ae()),ol=e=>Number.parseFloat(e)||0;function Od({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,jn.useState)("studs"),[i,o]=(0,jn.useState)(""),[l,c]=(0,jn.useState)(""),[p,f]=(0,jn.useState)("600"),[b,d]=(0,jn.useState)("2.4"),h=i&&l&&p?Math.ceil(ol(l)/(ol(p)/1e3))+1:0,w=h*ol(i),E=ol(b)>0?Math.ceil(w/ol(b)):0,D=[{key:r,label:{studs:"Stud timber",joists:"Joist timber",battens:"Batten timber"}[r],qty:w,unit:"m",query:{studs:"cls studwork timber",joists:"timber joist",battens:"roofing batten"}[r],category:"timber"}],m={studs:["Stud wall","Vertical studs along a wall length"],joists:["Joists","Parallel joists across a floor or deck"],battens:["Battens","Regularly spaced battens for lining or cladding"]},g={studs:{member:"Wall height",overall:"Wall length",help:"Studs repeat across the wall length.",count:"Studs"},joists:{member:"Joist span",overall:"Overall width",help:"Joists repeat across the overall floor or deck width.",count:"Joists"},battens:{member:"Batten length",overall:"Overall width",help:"Battens repeat across the overall lining or cladding width.",count:"Battens"}}[r];return(0,oe.jsx)(oe.Fragment,{children:(0,oe.jsxs)("div",{className:"truss-estimator",children:[(0,oe.jsxs)("div",{className:"quick-order-hero",children:[(0,oe.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,oe.jsx)("h1",{children:"Timber Calculator"}),(0,oe.jsx)("p",{children:"Estimate studs, joists or battens from a run length, width and spacing."})]}),(0,oe.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,oe.jsx)("h2",{className:"truss-estimator__step-title",children:"Member size and spacing"}),(0,oe.jsxs)("p",{className:"truss-estimator__step-sub",children:[g.help," Enter the member length and centres to estimate the number of pieces and stock lengths."]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber use"}),(0,oe.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:Object.keys(m).map(v=>(0,oe.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===v?" is-selected":""}`,onClick:()=>n(v),children:[(0,oe.jsx)("div",{className:"truss-estimator__option-title",children:m[v][0]}),(0,oe.jsx)("div",{className:"truss-estimator__option-copy",children:m[v][1]})]},v))})]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Dimensions and spacing"}),(0,oe.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsxs)("span",{children:[g.member," (m)"]}),(0,oe.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:v=>o(v.target.value)})]}),(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsxs)("span",{children:[g.overall," (m)"]}),(0,oe.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:v=>c(v.target.value)})]})]}),(0,oe.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsx)("span",{children:"Centres (mm)"}),(0,oe.jsxs)("select",{value:p,onChange:v=>f(v.target.value),children:[(0,oe.jsx)("option",{value:"300",children:"300 mm"}),(0,oe.jsx)("option",{value:"400",children:"400 mm"}),(0,oe.jsx)("option",{value:"450",children:"450 mm"}),(0,oe.jsx)("option",{value:"600",children:"600 mm"})]})]}),(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsx)("span",{children:"Stock length (m)"}),(0,oe.jsxs)("select",{value:b,onChange:v=>d(v.target.value),children:[(0,oe.jsx)("option",{value:"2.4",children:"2.40 m"}),(0,oe.jsx)("option",{value:"3.6",children:"3.60 m"}),(0,oe.jsx)("option",{value:"4.8",children:"4.80 m"})]})]})]})]}),(0,oe.jsxs)("div",{className:"materials-calculator__totals",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,oe.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:g.count}),(0,oe.jsx)("strong",{children:h})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:"Linear metres"}),(0,oe.jsxs)("strong",{children:[w.toFixed(2)," m"]})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsxs)("span",{children:[b," m lengths"]}),(0,oe.jsx)("strong",{children:E})]})]}),(0,oe.jsx)("p",{className:"materials-calculator__note",children:"Spacing is measured centre-to-centre. Add extra timber for plates, noggins, trimming and openings where required."})]}),(0,oe.jsxs)("div",{className:"materials-calculator__actions",children:[(0,oe.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,oe.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(D),disabled:w<=0,children:a})]})]})]})})}var Ld=[{id:"truss",title:"Roof Truss Calculator",desc:"Estimate trusses, girders and roof structure costs.",imageUrl:"/tool-images/truss.webp",Component:Dd},{id:"fencing",title:"Fencing Calculator",desc:"Estimate fence panels, posts, gravel boards and fixings.",imageUrl:"/tool-images/fencing.webp",Component:Ed},{id:"decking",title:"Decking Calculator",desc:"Estimate boards, substructure and fixing quantities.",imageUrl:"/tool-images/decking.webp",Component:qd},{id:"brick-block",title:"Brick & Block Calculator",desc:"Estimate masonry units and ready-mixed mortar for a wall.",imageUrl:"/tool-images/brick-block.webp",Component:xd},{id:"paint",title:"Paint Calculator",desc:"Estimate paint for walls, doors and multiple coats.",imageUrl:"/tool-images/paint.webp",Component:Td},{id:"skirting",title:"Skirting Board Calculator",desc:"Estimate skirting lengths for rooms and wall runs.",imageUrl:"/tool-images/skirting.webp",Component:Bd},{id:"architrave",title:"Architrave Calculator",desc:"Estimate architrave lengths for door and window openings.",imageUrl:"/tool-images/architrave.webp",Component:_d},{id:"concrete-aggregate",title:"Concrete & Aggregate Calculator",desc:"Estimate concrete, MOT, sand and gravel quantities.",imageUrl:"/tool-images/concrete-aggregate.webp",Component:Sd},{id:"plasterboard",title:"Plasterboard Calculator",desc:"Estimate plasterboard sheets, screws, tape and adhesive.",imageUrl:"/tool-images/plasterboard.webp",Component:Ud},{id:"insulation",title:"Insulation Calculator",desc:"Estimate insulation packs for floors, walls, roofs and lofts.",imageUrl:"/tool-images/insulation.webp",Component:Md},{id:"timber",title:"Timber Calculator",desc:"Estimate studs, joists and battens from spacing and lengths.",imageUrl:"/tool-images/timber.webp",Component:Od},{id:"paving",title:"Paving & Driveway Calculator",desc:"Estimate paving, block paving, MOT and sharp sand.",imageUrl:"/tool-images/paving.webp",Component:Ad}];var mc=Y(Ke());var je=Y(Ke());var S=Y(ae()),Z_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}],Hd={wasteFactorEnabled:!0},K_=3e3,qw=null;function dc(e,t){let a=Fo(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function P_(e){return e&&e.length>0?e.join(" x "):"-"}function jd({toolId:e,requirements:t,ready:a,onBack:r,onTotalChange:n}){let i=Fs(),o=`${e}~${t.map(C=>`${C.key}|${C.query}|${C.category??""}|${C.qty}`).join("~")}`,l=o!==qw,[c,p]=(0,je.useState)(null),[f,b]=(0,je.useState)([]),[d,h]=(0,je.useState)(l),[w,E]=(0,je.useState)(null),[D,m]=(0,je.useState)("tile"),[u,g]=(0,je.useState)(null),[v,N]=(0,je.useState)(""),[R,T]=(0,je.useState)(null),[z,G]=(0,je.useState)(""),[K,xe]=(0,je.useState)([]),[Ee,Ge]=(0,je.useState)(new Set),[Qe,Ie]=(0,je.useState)(null),[ue,Q]=(0,je.useState)(""),[se,Ne]=(0,je.useState)([]),lt=(0,je.useRef)(null),Ye=(0,je.useRef)(!1),ge=C=>`${e}:${C}`,We=C=>Kr(C.chosen,{lineId:ge(C.requirement.key),description:C.requirement.label,unit:C.requirement.unit,qty:C.requirement.qty}),he=(0,je.useMemo)(()=>t.map(C=>`${C.key}|${C.query}|${C.category??""}`).join("~"),[t]);(0,je.useEffect)(()=>{let C=!1;return fw().then(V=>{C||p(V.itemCount>0)}).catch(()=>{C||p(!1)}),()=>{C=!0}},[]),(0,je.useEffect)(()=>{if(!a||!c)return;let C=!1,V;l&&h(!0),E(null);let X=Date.now();return(async()=>{let pe=null;try{pe=(await mw(t)).map(({requirement:ft,candidates:Ve})=>({requirement:ft,candidates:Ve,chosen:Ve[0]??null}))}catch(Se){C||E(Se instanceof Error?Se.message:"Could not load products")}if(!C){if(qw=o,l){let Se=K_-(Date.now()-X);Se>0&&await new Promise(ft=>{V=window.setTimeout(ft,Se)})}C||(pe&&(b(pe),!Ye.current&&i&&(Ye.current=!0,i.addManyToCart(pe.filter(Se=>Se.chosen).map(We)))),h(!1))}})(),()=>{C=!0,window.clearTimeout(V)}},[a,c,he]),(0,je.useEffect)(()=>{if(!R)return;let C=z.trim();if(!C){xe([]);return}let V=!1,X=window.setTimeout(()=>{Jr(C).then(pe=>{V||xe(pe)}).catch(()=>{V||xe([])})},250);return()=>{V=!0,window.clearTimeout(X)}},[R,z]),(0,je.useEffect)(()=>{if(!Qe)return;let C=ue.trim();if(!C){Ne([]);return}let V=!1,X=window.setTimeout(()=>{Jr(C).then(pe=>{V||Ne(pe)}).catch(()=>{V||Ne([])})},250);return()=>{V=!0,window.clearTimeout(X)}},[Qe,ue]);let W=(0,je.useMemo)(()=>{let C=v.trim().toLowerCase(),V=C?f.filter(X=>X.requirement.label.toLowerCase().includes(C)||(X.chosen?.description??"").toLowerCase().includes(C)||(X.chosen?.product_id??"").toLowerCase().includes(C)):f;return u?[...V].sort((X,pe)=>{let Se=X.requirement.label.localeCompare(pe.requirement.label);return u==="asc"?Se:-Se}):V},[f,v,u]),Re=W.filter(C=>C.chosen),Be=W.filter(C=>!C.chosen),ye=f.filter(C=>C.chosen),et=ye.filter(C=>C.chosen?.price==null).length,Ze=ye.reduce((C,V)=>C+(Ut(We(V),Hd).lineTotal??0),0);if((0,je.useEffect)(()=>{n?.(Ze)},[Ze,n]),!a||c===!1)return null;let M=i?ye.filter(C=>i.cart[ge(C.requirement.key)]).length:0,x=Qe?f.find(C=>C.requirement.key===Qe)??null:null,I=ue.trim()?se:x?.candidates??[],ce=C=>{let V=R===C.requirement.key;T(V?null:C.requirement.key),G(V?"":C.requirement.query)},me=(C,V)=>{let X=f.find(pe=>pe.requirement.key===C);b(pe=>pe.map(Se=>Se.requirement.key===C?{...Se,chosen:V}:Se)),i&&X&&i.cart[ge(C)]&&i.addToCart(We({...X,chosen:V})),T(null),G("")},ke=C=>{b(V=>V.map(X=>X.requirement.key===C?{...X,chosen:null}:X)),i?.cart[ge(C)]&&i.removeFromCart(ge(C))},k=C=>{Ie(C.requirement.key),Q(""),Ne([])},j=()=>{Ie(null),Q(""),Ne([])},O=C=>{if(!i)return;let V=ge(C.requirement.key);i.cart[V]?i.removeFromCart(V):i.addToCart(We(C))},ne=C=>{Ge(V=>{let X=new Set(V);return X.has(C)?X.delete(C):X.add(C),X})},ee=C=>{let V=K.length>0?K:C.candidates;return(0,S.jsxs)("div",{className:"estimator-products__picker",children:[(0,S.jsx)("input",{type:"text",className:"results-search-input",value:z,autoFocus:!0,placeholder:"Search products in catalogue...",onChange:X=>G(X.target.value),"aria-label":`Search a product for ${C.requirement.label}`}),(0,S.jsxs)("div",{className:"estimator-products__options",children:[V.map(X=>(0,S.jsxs)("button",{type:"button",className:`estimator-products__option${X.product_id===C.chosen?.product_id?" is-selected":""}`,onClick:()=>me(C.requirement.key,X),children:[(0,S.jsx)("span",{children:X.description}),(0,S.jsxs)("span",{className:"results-row-meta",children:[X.product_id,X.price!=null&&` \xB7 ${st(X.price)}`]})]},X.product_id)),V.length===0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No matching products."})]})]})};return(0,S.jsxs)("section",{className:"estimator-products results-tile-section","aria-label":"Matched products",children:[!d&&(0,S.jsxs)("div",{className:"estimator-products__head",children:[(0,S.jsxs)("div",{className:"results-tile-section__head",children:[(0,S.jsx)("h3",{children:"Matched Products"}),(0,S.jsx)("p",{children:"Products matched to your estimate, check before adding to your basket."})]}),!x&&(0,S.jsxs)("div",{className:"results-summary estimator-products__toolbar",children:[et>0&&(0,S.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,S.jsx)("strong",{children:et})," need pricing"]}),(0,S.jsxs)("div",{className:"estimator-products__controls",children:[(0,S.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:v,onChange:C=>N(C.target.value),"aria-label":"Search matched products"}),(0,S.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,S.jsx)("button",{type:"button",className:`results-view-toggle__btn${D==="tile"?" is-active":""}`,"aria-pressed":D==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>m("tile"),children:(0,S.jsxs)("svg",{width:"18",height:"12",viewBox:"0 0 15 10",fill:"currentColor",children:[(0,S.jsx)("rect",{x:"0.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"5.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"10.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"0.5",y:"5.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"5.5",y:"5.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"10.5",y:"5.5",width:"4",height:"4"})]})}),(0,S.jsx)("button",{type:"button",className:`results-view-toggle__btn${D==="list"?" is-active":""}`,"aria-pressed":D==="list","aria-label":"List view",title:"List view",onClick:()=>m("list"),children:(0,S.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,S.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,S.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,S.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),(0,S.jsxs)("details",{ref:lt,style:{position:"relative"},children:[(0,S.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort materials",style:{fontSize:16},children:"\u21C5"}),(0,S.jsx)("div",{className:"sort-menu-panel",children:Z_.map(C=>{let V=u===C.dir;return(0,S.jsxs)("button",{type:"button",className:`sort-menu-item${V?" is-active":""}`,onClick:()=>{g(V?null:C.dir),lt.current?.removeAttribute("open")},children:[(0,S.jsx)("span",{className:"sort-menu-item__check",children:V?"\u2713":""}),C.label]},C.dir)})})]})]})]})]}),x&&(0,S.jsxs)("div",{className:"results-review-page",children:[(0,S.jsxs)("div",{className:"results-review-page__top",children:[(0,S.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:j,children:[(0,S.jsx)(Zr,{}),"Back to results"]}),(0,S.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,S.jsx)("div",{className:"results-review-searchbar",children:(0,S.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:ue,onChange:C=>Q(C.target.value),"aria-label":`Search a product for ${x.requirement.label}`})}),x.chosen&&(0,S.jsx)("div",{className:"results-candidate-actions",children:(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ke(x.requirement.key),children:"Clear selected product"})})]})]}),(0,S.jsxs)("div",{className:"results-review-page__hero",children:[(0,S.jsx)("div",{className:"results-review-page__image-wrap",children:(0,S.jsx)("img",{className:"fill-img results-review-page__image",src:Qa(x.chosen?.description||x.requirement.label,x.chosen?.product_id,x.chosen?.pdp_photo_url),alt:""})}),(0,S.jsxs)("div",{className:"results-review-page__summary",children:[(0,S.jsx)("h2",{children:x.requirement.label}),(0,S.jsxs)("p",{className:"results-review-page__meta",children:[_i(x.requirement.qty)," ",ka(x.requirement.unit,x.requirement.qty)]}),x.chosen?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("div",{className:"results-review-page__product",children:x.chosen.description}),(0,S.jsxs)("div",{className:"results-row-meta",children:[x.chosen.product_id,x.chosen.price!=null?` \xB7 ${dc(x.chosen.price,x.chosen.price_basis)}`:""]})]}):(0,S.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line."}),(0,S.jsx)("div",{className:"results-review-page__actions",children:(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${i?.cart[ge(x.requirement.key)]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>O(x),disabled:!x.chosen||!i,children:i?.cart[ge(x.requirement.key)]?"\u2713 Added":"+ Add to basket"})})]})]}),I.length===0?(0,S.jsx)("p",{className:"results-empty-hint",children:"No matching products."}):(0,S.jsxs)("table",{className:"score-breakdown-table",children:[(0,S.jsx)("thead",{children:(0,S.jsxs)("tr",{children:[(0,S.jsx)("th",{children:"Product"}),(0,S.jsx)("th",{children:"Dims (mm)"}),(0,S.jsx)("th",{children:"Price"}),(0,S.jsx)("th",{"aria-label":"Actions"})]})}),(0,S.jsx)("tbody",{children:I.map(C=>{let V=C.product_id===x.chosen?.product_id;return(0,S.jsxs)("tr",{className:V?"score-breakdown-row--best":"",children:[(0,S.jsxs)("td",{children:[(0,S.jsx)("div",{children:C.description}),(0,S.jsx)("div",{className:"results-row-meta",children:C.product_id})]}),(0,S.jsx)("td",{children:(0,S.jsx)("span",{className:"unit-badge",children:P_(C.measurements_mm)})}),(0,S.jsx)("td",{children:C.price!=null?dc(C.price,C.price_basis):"-"}),(0,S.jsx)("td",{children:(0,S.jsxs)("label",{className:"switch-toggle",title:V?"Currently selected":"Use this candidate",children:[(0,S.jsx)("input",{type:"checkbox",checked:V,onChange:()=>{V?ke(x.requirement.key):me(x.requirement.key,C)},"aria-label":V?`${C.description} selected`:`Use ${C.description}`}),(0,S.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},C.product_id)})})]})]}),!x&&d&&(0,S.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{padding:"32px 24px"},children:[(0,S.jsx)(dr,{}),(0,S.jsx)("p",{className:"banter-message is-visible",style:{fontSize:15,minHeight:0},children:"Matching your materials against the catalogue\u2026"})]}),!x&&w&&(0,S.jsx)("p",{className:"results-empty-hint estimator-products__error",children:w}),!x&&!d&&!w&&W.length===0&&f.length>0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No materials match the current search."}),!x&&!d&&!w&&D==="tile"&&Re.length>0&&(0,S.jsx)("div",{className:"results-tile-grid",children:Re.map(C=>{let{requirement:V,chosen:X}=C,pe=X?Ut(We(C),Hd):null,Se=i?!!i.cart[ge(V.key)]:!1;return(0,S.jsxs)("article",{className:"results-tile-card",children:[(0,S.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>k(C),"aria-label":`Review match for ${V.label}`,children:[(0,S.jsx)("div",{className:"results-tile-card__media",children:(0,S.jsx)("img",{className:"fill-img results-tile-card__image",src:Qa(X?.description||V.label,X?.product_id,X?.pdp_photo_url),alt:""})}),(0,S.jsxs)("div",{className:"results-tile-card__body",children:[X?(0,S.jsxs)("div",{className:"results-tile-card__heading",children:[(0,S.jsx)("div",{className:"results-tile-card__title",children:X.description}),(0,S.jsxs)("div",{className:"results-tile-card__match-meta",children:[(0,S.jsx)("span",{children:X.product_id}),X.price!=null?(0,S.jsx)("span",{children:dc(X.price,X.price_basis)}):null]})]}):(0,S.jsx)("div",{className:"results-empty-hint",children:"No product matched for this line."}),(0,S.jsxs)("div",{className:"results-tile-card__match",children:[(0,S.jsx)("div",{className:"results-tile-card__match-label",children:"\u21B3 calculated as"}),(0,S.jsx)("div",{className:"results-tile-card__match-name",children:V.label}),(0,S.jsxs)("div",{className:"results-tile-card__meta",children:[_i(V.qty)," ",ka(V.unit,V.qty)]}),pe?.requiredSellUnits!=null?(0,S.jsxs)("div",{className:"results-tile-card__meta estimator-products__order",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${st(pe.lineTotal)}`:""]}):X?(0,S.jsx)("div",{className:"results-row-meta",children:"Quantity needs review"}):null]})]})]}),(0,S.jsxs)("div",{className:"results-tile-card__actions",children:[(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>k(C),children:"Review"}),(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${Se?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>O(C),disabled:!X||!i,children:Se?"\u2713 Added":"+ Add"})]})]},V.key)})}),!x&&!d&&!w&&D==="list"&&Re.length>0&&(0,S.jsx)("div",{className:"bom-table-wrap",children:(0,S.jsxs)("table",{className:"bom-table results-table","aria-label":"Matched materials",children:[(0,S.jsxs)("colgroup",{children:[(0,S.jsx)("col",{style:{width:"56px"}}),(0,S.jsx)("col",{className:"col-item"}),(0,S.jsx)("col",{style:{width:"90px"}}),(0,S.jsx)("col",{style:{width:"80px"}}),(0,S.jsx)("col",{style:{width:"220px"}}),(0,S.jsx)("col",{style:{width:"110px"}})]}),(0,S.jsx)("thead",{children:(0,S.jsxs)("tr",{className:"bom-col-header",children:[(0,S.jsx)("th",{"aria-label":"Expand"}),(0,S.jsx)("th",{style:{textAlign:"left"},children:"Description"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Qty"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Unit"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Product Matched"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Basket"})]})}),(0,S.jsx)("tbody",{children:Re.map(C=>{let{requirement:V,chosen:X}=C,pe=X?Ut(We(C),Hd):null,Se=i?!!i.cart[ge(V.key)]:!1,ft=Ee.has(V.key);return(0,S.jsxs)(je.Fragment,{children:[(0,S.jsxs)("tr",{className:"bom-row",children:[(0,S.jsx)("td",{className:"bom-actions",style:{textAlign:"center",paddingLeft:0,paddingRight:0},children:(0,S.jsx)("button",{type:"button",className:"link-btn",onClick:()=>ne(V.key),"aria-expanded":ft,"aria-label":ft?"Collapse product options":"Expand product options",children:ft?"\u25BE":"\u25B8"})}),(0,S.jsxs)("td",{style:{paddingLeft:0},children:[(0,S.jsx)("div",{className:"bom-component-name",children:V.label}),pe?.requiredSellUnits!=null&&(0,S.jsxs)("div",{className:"results-row-meta",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${st(pe.lineTotal)}`:""]})]}),(0,S.jsx)("td",{className:"bom-qty col-order",style:{textAlign:"center"},children:_i(V.qty)}),(0,S.jsx)("td",{style:{textAlign:"center"},children:ka(V.unit,V.qty)}),(0,S.jsx)("td",{style:{textAlign:"center"},children:X?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("div",{className:"bom-component-name",children:X.description}),(0,S.jsxs)("div",{className:"results-row-meta",children:[X.product_id,X.price!=null&&` \xB7 ${dc(X.price,X.price_basis)}`]})]}):(0,S.jsx)("span",{className:"results-empty-hint",children:"No match"})}),(0,S.jsx)("td",{style:{textAlign:"center"},children:(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${Se?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>O(C),disabled:!X||!i,children:Se?"\u2713 Added":"+ Add"})})]}),ft&&(0,S.jsx)("tr",{children:(0,S.jsx)("td",{colSpan:6,style:{paddingLeft:0,paddingRight:0},children:R===V.key?ee(C):(0,S.jsxs)("div",{className:"estimator-products__picker",children:[(0,S.jsxs)("div",{className:"estimator-products__options",children:[C.candidates.map(Ve=>(0,S.jsxs)("button",{type:"button",className:`estimator-products__option${Ve.product_id===X?.product_id?" is-selected":""}`,onClick:()=>me(V.key,Ve),children:[(0,S.jsx)("span",{children:Ve.description}),(0,S.jsxs)("span",{className:"results-row-meta",children:[Ve.product_id,Ve.price!=null&&` \xB7 ${st(Ve.price)}`]})]},Ve.product_id)),C.candidates.length===0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No candidates found."})]}),(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ce(C),children:"Search the catalogue"})]})})})]},V.key)})})]})}),!x&&!d&&!w&&Be.length>0&&(0,S.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,S.jsxs)("div",{className:"results-tile-section__head",children:[(0,S.jsx)("h3",{children:"Require Matching"}),(0,S.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,S.jsx)("div",{className:"results-unmatched-list",children:Be.map(C=>(0,S.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>k(C),children:[(0,S.jsxs)("span",{className:"results-unmatched-card__main",children:[(0,S.jsx)("span",{className:"results-unmatched-card__title",children:C.requirement.label}),(0,S.jsxs)("span",{className:"results-row-meta",children:[_i(C.requirement.qty)," ",ka(C.requirement.unit,C.requirement.qty)]})]}),(0,S.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},C.requirement.key))})]}),!d&&!w&&f.length>0&&(0,S.jsxs)("div",{className:"disclaimer-box",style:{alignItems:"center"},children:[(0,S.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,S.jsx)("p",{className:"disclaimer-text",children:"These matches are generated automatically and should be reviewed before procurement, especially any items flagged as medium or low confidence."})]}),!x&&!d&&!w&&(r||M>0)&&(0,S.jsxs)("div",{className:"btn-row estimator-products__footer",children:[r&&(0,S.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:r,children:"Back"}),M>0&&i&&(0,S.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:r?"0 1 70%":1,marginTop:0},onClick:i.openBasket,children:[(0,S.jsxs)("span",{children:["View Basket (",M,")"]}),(0,S.jsx)("span",{className:"arrow",children:(0,S.jsx)(Ht,{})})]})]})]})}var jt=Y(ae());function Gd({toolId:e,toolTitle:t,requirements:a,onBack:r}){let[n,i]=(0,mc.useState)(0),o=(0,mc.useCallback)(l=>i(l),[]);return(0,jt.jsx)(jt.Fragment,{children:(0,jt.jsxs)("div",{className:"truss-estimator",children:[(0,jt.jsxs)("div",{className:"quick-order-hero",children:[(0,jt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,jt.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,jt.jsx)("h1",{children:"Your Materials"}),n>0&&(0,jt.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,jt.jsx)("strong",{children:st(n)})," Est. total"]})]}),(0,jt.jsxs)("p",{children:["Quantities from the ",t,", matched against your merchant\u2019s catalogue."]})]}),(0,jt.jsx)("div",{className:"truss-estimator__card",style:{minHeight:0},children:(0,jt.jsx)(jd,{toolId:e,requirements:a,ready:!0,onBack:r,onTotalChange:o})})]})})}var J_=(e,t)=>{let a=t.key,r={"brick-block":{"brick-common":"5001444","brick-engineering-red":"5002008","brick-engineering-blue":"5001439",block:"5003187",mortar:"6003088"},skirting:{"skirting-chamfered":"4006057","skirting-ogee":"4006045","skirting-pencil-round":"4006048","skirting-torus":"4006042"},architrave:{"architrave-ogee":"4006060","architrave-ovolo":"4006063","architrave-pencil-round":"4006061","architrave-square-edge":"4006062","architrave-torus":"4006059"},plasterboard:{board:"2001035",screws:"2006040",tape:"2007043",adhesive:"2004023"},insulation:{"insulation-floor":"3002110","insulation-wall":"3002012","insulation-roof":"3004047","insulation-loft":"3003046"},timber:{studs:"4001168",joists:"4001201",battens:"4001053"},fencing:{"panels-boundary-0.9":"4001268","panels-boundary-1.2":"4001269","panels-boundary-1.5":"4001270","panels-boundary-1.8":"4001271","panels-skyline-0.9":"4001264","panels-skyline-1.2":"4001265","panels-skyline-1.5":"4001266","panels-skyline-1.8":"4001267","concrete-intermediate-6":"4001290","concrete-intermediate-8":"4001291","concrete-end-6":"4001294","concrete-end-8":"4001295","timber-post-6":"4001242","timber-post-8":"4001243",postcrete:"6003008",gate:"4001630","gravel-boards":"4001284"},decking:{"boards-meridian":"4001251","boards-summit":"4001360",joists:"4001201",screws:"1001103"},paving:{"surface-council":"7003121","surface-raj":"7003003","surface-brindle":"4001621","surface-charcoal":"4001622","surface-pea":"6001004","sub-base":"6001007",bedding:"6001012"}};return e==="plasterboard"?{standard:"2001035",moisture:"2002039",fire:"2002087",sound:"2002044"}[t.label.split(" ")[0].toLowerCase()]??r[e]?.[a]??null:r[e]?.[a]??null};function Ew(e,t){if(e==="paint"||e==="concrete-aggregate")return null;let a=t.map(r=>{let n=J_(e,r);return n?{key:r.key,productId:n,qty:r.qty,unit:r.unit}:null});return a.every(Boolean)?a:null}var Qd=Y(Ke());var Jt=Y(ae()),F_=1500;function Mw(e){let{addManyToCart:t,clearCart:a,openBasket:r}=An(),[n,i]=(0,Qd.useState)(!1),[o,l]=(0,Qd.useState)(null);return{adding:n,basketError:o,addToBasket:async(p,f)=>{let b=Date.now();i(!0),l(null);try{let d=await Promise.all(p.filter(w=>w.qty>0).map(async w=>{let E=(await Jr(w.productId)).find(D=>D.product_id===w.productId);if(!E)throw new Error("A selected product is no longer available in this catalogue.");return Kr(E,{lineId:`${e}:${w.key}`,description:E.description,unit:w.unit??"each",qty:w.qty,calculatorWasteIncluded:f})})),h=F_-(Date.now()-b);h>0&&await new Promise(w=>window.setTimeout(w,h)),a(),t(d),r()}catch(d){l(d instanceof Error?d.message:"Could not add the products to your basket.")}finally{i(!1)}}}}function Tw({toolTitle:e}){return(0,Jt.jsx)(Jt.Fragment,{children:(0,Jt.jsxs)("div",{className:"truss-estimator",children:[(0,Jt.jsxs)("div",{className:"quick-order-hero",children:[(0,Jt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Jt.jsx)("h1",{children:"Your Materials"}),(0,Jt.jsxs)("p",{children:["Calculating quantities from the ",e,"."]})]}),(0,Jt.jsx)("div",{className:"truss-estimator__card",children:(0,Jt.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,Jt.jsx)(dr,{}),(0,Jt.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})})}var Ae=Y(ae());function fc(e){let[t,a]=(0,Va.useState)(!1);return(0,Ae.jsx)(Js,{onOpenBasket:()=>a(!0),children:(0,Ae.jsx)(I_,{...e,showBasket:t,onShowBasket:a})})}function I_({fullPage:e=!1,hideHeader:t=!1,internal:a=!1,showBasket:r,onShowBasket:n}){let[i,o]=(0,Va.useState)(null),[l,c]=(0,Va.useState)(null),p=Ld.find(z=>z.id===i),{cart:f,updateCartQty:b,updateCartSellUnits:d,updateCartConversions:h,removeFromCart:w,clearCart:E}=An(),{adding:D,basketError:m,addToBasket:u}=Mw(p?.title??"calculator"),g=(0,Va.useRef)(null),v=Gs("estimating-tools",g);(0,Va.useEffect)(()=>{v("viewed")},[v]);let N=r?"basket":D?"adding":l?"review":i??"list",R=(0,Va.useRef)(N);(0,Va.useEffect)(()=>{R.current!==N&&(R.current=N,window.scrollTo(0,0))},[N]);let T=z=>{if(!p)return;v("estimate_completed",{calculator:p.id,lines:z.length});let G=Ew(p.id,z);G?u(G,z[0]?.calculatorWasteIncluded??!1):c(z)};return(0,Ae.jsx)(Zo.Provider,{value:v,children:(0,Ae.jsx)("div",{ref:g,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}`,style:pr().theme,children:(0,Ae.jsx)("main",{className:"main-content",children:r?(0,Ae.jsx)(rl,{cart:f,onUpdateQty:b,onUpdateSellUnits:d,onResolveConversions:h,onRemove:w,onBack:()=>n(!1),onStartNewQuote:()=>{E(),o(null),c(null),n(!1)},internal:a}):D&&p?(0,Ae.jsx)(Tw,{toolTitle:p.title}):p?(0,Ae.jsxs)(Ae.Fragment,{children:[(0,Ae.jsx)("div",{hidden:l!==null,children:(0,Ae.jsx)(p.Component,{onBack:()=>o(null),onReview:T})}),m&&(0,Ae.jsx)("p",{className:"results-empty-hint estimator-products__error",children:m}),l!==null&&(0,Ae.jsx)(Gd,{toolId:p.id,toolTitle:p.title,requirements:l,onBack:()=>c(null)})]}):(0,Ae.jsx)(Ae.Fragment,{children:(0,Ae.jsxs)("div",{className:"quick-order-card",children:[(0,Ae.jsxs)("div",{className:"quick-order-hero",children:[(0,Ae.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,Ae.jsx)("h1",{children:"Estimating Tools"}),(0,Ae.jsx)("p",{children:"Trade-specific calculators for trusses, fencing, decking, masonry and painting. Dial in your specs and get an instant material estimate."})]}),(0,Ae.jsxs)("div",{className:"quick-order-alt",children:[(0,Ae.jsx)("div",{className:"quick-order-alt-title",children:"Choose a Calculator"}),(0,Ae.jsx)("div",{className:"estimator-tools-grid",children:Ld.map(z=>(0,Ae.jsxs)("button",{type:"button",className:"estimator-tool-card",onClick:()=>{v("calculator_selected",{calculator:z.id}),o(z.id),c(null)},children:[(0,Ae.jsx)("span",{className:"estimator-tool-card__image-wrap",children:(0,Ae.jsx)("img",{className:"fill-img estimator-tool-card__image",src:Pt(z.imageUrl),alt:""})}),(0,Ae.jsxs)("span",{className:"estimator-tool-card__content",children:[(0,Ae.jsx)("span",{className:"estimator-tool-card__title",children:z.title}),(0,Ae.jsx)("span",{className:"estimator-tool-card__desc",children:z.desc})]})]},z.id))})]})]})})})})})}var gc=Y(ae());function Yd({config:e,children:t}){return Kb(e),(0,gc.jsx)(gc.Fragment,{children:t})}var Vd=Y(ae()),W_="https://api.metronlabs.ai",ex=["client","api-key","api-url","theme","hide-header","analytics"],tx=["all","events-only","none"];function Aw(e,t){var a;customElements.get(e)||customElements.define(e,(a=class extends HTMLElement{constructor(){super();this.root=null;this.attachShadow({mode:"open"})}connectedCallback(){if(this.dataset.version="0.1.35",!this.root){let n=document.createElement("div"),i=document.createElement("style");i.textContent=`:host { display: block; }
|
|
6798
|
+
`)}function Kr(e,t){return{lineId:t.lineId,description:e?.description||t.description||"(no description)",requestedDescription:t.description,productId:e?.product_id??"-",price:e?.price??null,priceBasis:e?.price_basis??null,unit:t.unit,uoi:e?.uoi??t.unit,uoiCount:e?.uoi_count??null,saleUnit:e?.conversion?.sale_unit??null,saleUnitQuantity:e?.conversion?.sale_unit_quantity??null,unitConversions:e?.conversion?.unit_conversions?.map(a=>({requestUom:a.request_uom,quantityPerSaleUnit:a.quantity_per_sale_unit,evidence:a.evidence,confidence:a.confidence})),pdpPhotoUrl:e?.pdp_photo_url??null,measurementsMm:e?.measurements_mm??[],conversionType:e?.conversion?.conversion_type??null,requestUomsSupported:e?.conversion?.request_uoms_supported??null,salesUomNormalised:e?.conversion?.sales_uom_normalised??null,salesUnitSize:e?.conversion?.sales_unit_size??null,salesUnitSizeUom:e?.conversion?.sales_unit_size_uom??null,coverageQty:e?.conversion?.coverage_qty??null,coverageUom:e?.conversion?.coverage_uom??null,itemsPerPallet:e?.conversion?.items_per_pallet??null,itemsPerPack:e?.conversion?.items_per_pack??null,itemsPerBox:e?.conversion?.items_per_box??null,itemsPerM2:e?.conversion?.items_per_m2??null,wasteFactorDefault:e?.conversion?.waste_factor_default??null,roundingRule:e?.conversion?.rounding_rule??null,derivedCoverageM2:e?.conversion?.derived_coverage_m2??null,derivedLengthM:e?.conversion?.derived_length_m??null,quoteQtyFormulaType:e?.conversion?.quote_qty_formula_type??null,conversionConfidence:e?.conversion?.conversion_confidence??null,conversionNotes:e?.conversion?.conversion_notes??null,calculatorWasteIncluded:t.calculatorWasteIncluded,qty:t.qty,linkedContext:t.linkedContext}}var Iv=e=>(e??"").trim().toLowerCase(),J1={sqm:"m2","sq m":"m2","m\xB2":"m2",cbm:"m3","cu m":"m3",lm:"m","lin m":"m",metre:"m",meter:"m",each:"each",ea:"each",nr:"each",no:"each",item:"each",unit:"each",units:"each",pc:"each",pcs:"each",board:"sheet",bags:"bag",length:"length",lengths:"length",pallet:"pallet",pallets:"pallet"},Zv=new Set(["sheet","length","box","bag","pack","roll","set","tub","each"]),Kv=new Set(["box","bag","pack","pallet","roll","set","tub"]),Pv=(e,t)=>t==="ml"?e:["l","litre","litres"].includes(t)?e*1e3:null,Jv=(e,t)=>t==="g"?e:["kg","kilogram","kilograms"].includes(t)?e*1e3:["t","tonne","tonnes"].includes(t)?e*1e6:null,xi=e=>{let t=Iv(e);return J1[t]??t},pt=(e,t)=>{let a=xi(e),r=xi(t);return a.length>0&&a===r},F1=(e,t)=>{let a=Iv(t);return a?a.includes("round_up_1000")?Math.ceil(e):a.includes("allow_decimal")?Math.round(e*1e3)/1e3:a.includes("round_up")?Math.ceil(e):e:e},I1=e=>(e??"").split(",").map(t=>xi(t)).filter(Boolean),W1=(e,t)=>{let a=I1(e.requestUomsSupported);return!!(a.length===0||a.includes(t)||pt(t,"pallet")&&e.itemsPerPallet!=null&&e.itemsPerPallet>0||pt(t,"pack")&&e.itemsPerPack!=null&&e.itemsPerPack>0||pt(t,"box")&&e.itemsPerBox!=null&&e.itemsPerBox>0)},Fv=(e,t)=>pt(t,"pallet")?e.itemsPerPallet??null:pt(t,"pack")?e.itemsPerPack??null:pt(t,"box")?e.itemsPerBox??null:null,e_=(e,t,a)=>{if(!pt(t,"m2"))return null;let r=e.description.match(/(\d+(?:[.,]\d+)?)\s*(m2|m²|sqm|sq\.?\s*m)\s*(?:\/|per)\s*([a-z]+)/i);if(!r||!pt(r[3],a))return null;let n=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(n)&&n>0?n:null};function Zs(e,t){return e.reduce((a,r)=>a+(Ut(r,t).lineTotal??0),0)}function Ut(e,t){let a=e.qty,r=xi(e.saleUnit??e.salesUnitSizeUom??e.uoi??e.salesUomNormalised)||"-",n=xi(e.unit)||(a>0&&Zv.has(r)?r:"-"),i=e.saleUnitQuantity??e.salesUnitSize??e.uoiCount??1,o=t?.wasteFactorEnabled===!1?0:t?.wasteFactorOverride??e.wasteFactorOverride??e.wasteFactorDefault??0,l=e.sellUnitsOverride!=null&&Number.isFinite(e.sellUnitsOverride)&&e.sellUnitsOverride>0,c=l?e.sellUnitsOverride??null:null,p=v=>({requestedAmount:a,requestedUnit:n,salesUnitSize:e.salesUnitSize??e.uoiCount??null,sellUnit:r,calculatedSellUnits:null,requiredSellUnits:c,unitPrice:e.price,lineTotal:e.price!=null&&c!=null?e.price*c:null,calculation:c!=null?`${v} Manually set to ${c} ${r}.`:v,costingMode:"review"});if(!W1(e,n))return p("Requested unit is not supported by this catalogue conversion.");let f=null,b="review",d=e.roundingRule,h=`Quantity review required, initial request needed ${a} ${n}.`,w=1+o,E=e_(e,n,r),D=e.unitConversions?.find(v=>pt(v.requestUom,n));if(!!e.saleUnit&&(pt(n,r)||!!D||pt(n,"each")&&!Kv.has(r)))if(pt(n,r))f=a*w/i,b="direct",h=`${a} ${n}${o>0?` x ${w}`:""}`;else if(D){f=a*w/D.quantityPerSaleUnit,b="derived";let v=1/D.quantityPerSaleUnit,N=Math.round(v);h=pt(r,"each")&&D.quantityPerSaleUnit<1&&Math.abs(v-N)<1e-9?`${a} ${n}${o>0?` x ${w}`:""} x ${N} per ${n}`:`${a} ${n}${o>0?` x ${w}`:""} / ${D.quantityPerSaleUnit} ${n} per ${r}`}else pt(n,"each")&&!Kv.has(r)&&(f=a*w/i,b="derived",h=`${a} ${r}${o>0?` x ${w}`:""}`);else if(pt(n,r)&&i>0)f=a*w/i,b="direct",h=o>0?`${a} ${n} x ${w} / ${i} ${r} per sell unit`:`${a} ${n} / ${i} ${r} per sell unit`;else if(pt(n,"each")&&i>0&&Zv.has(r))f=a*w/i,b="derived",h=o>0?`${a} each x ${w} / ${i} each per ${r}`:`${a} each / ${i} each per ${r}`;else if(Fv(e,n)!=null&&i>0){let v=Fv(e,n)??0;f=a*v*w/i,b="derived";let N=`${a} ${n} x ${v} each${o>0?` x ${w}`:""}`;h=i===1&&pt(r,"each")?N:`${N} / ${i} each per ${r}`}else if(E!=null)f=a*w/E,b="derived",d??(d="round_up_each"),h=`${a} m2 x ${w} / ${E} m2 per ${r} (from product description)`;else if(e.conversionType==="basket_line_unit")i>0&&(f=a*w/i,b="derived",h=`${a} ${n}${o>0?` x ${w}`:""} / ${i} ${n} per ${r}`);else{if(e.conversionType==="count_only")return p(`Quantity review required, initial request needed ${a} ${n}.`);if(["area_from_dims","explicit_coverage_area","roll_area"].includes(e.conversionType??"")){let v=e.coverageQty??e.derivedCoverageM2??null;pt(n,"m2")&&v!=null&&v>0&&(f=a*w/v,b="derived",h=`${a} m2 x ${w} / ${v} m2 per ${r}`)}else if(e.conversionType==="count_per_area"){let v=e.coverageQty??null;pt(n,"m2")&&v!=null&&v>0?(f=a/v,b="derived",h=`${a} m2 / ${v} m2 per sell unit`):pt(n,"m2")&&e.itemsPerM2!=null&&e.itemsPerM2>0&&i>0&&(f=a*e.itemsPerM2*w/i,b="derived",h=`${a} m2 x ${e.itemsPerM2} ${r}/m2 x ${w} / ${i}`)}else if(e.conversionType==="length_from_dims"){let v=e.coverageQty??e.derivedLengthM??null;pt(n,"m")&&v!=null&&v>0&&(f=a*w/v,b="derived",h=`${a} m x ${w} / ${v} m per ${r}`)}else if(e.conversionType==="volume_from_description"){let v=Pv(a,n),N=Pv(e.coverageQty??0,xi(e.coverageUom));v!=null&&N!=null&&N>0&&(f=v*w/N,b="derived",h=`${a} ${n} x ${w} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="weight_from_description"){let v=Jv(a,n),N=Jv(e.coverageQty??0,xi(e.coverageUom));v!=null&&N!=null&&N>0&&(f=v*w/N,b="derived",h=`${a} ${n} x ${w} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="same_unit_volume"){let v=e.coverageQty??null;pt(n,"m3")&&v!=null&&v>0&&(f=a/v,b="derived",h=`${a} m3 / ${v} m3 per ${r}`)}}if(f==null||!Number.isFinite(f)||f<0)return p(`Quantity review required, initial request needed ${a} ${n}.`);let u=F1(f,d),g=l?e.sellUnitsOverride??null:u;return{requestedAmount:a,requestedUnit:n,salesUnitSize:i,sellUnit:r,calculatedSellUnits:u,requiredSellUnits:g,unitPrice:e.price,lineTotal:e.price!=null&&g!=null?e.price*g:null,calculation:l?`${h} = ${u} ${r} (manually set to ${g})`:`${h} = ${g} ${r}`,costingMode:b}}var Wv=()=>import("./xlsx-K4MOA2QM.js"),Wo=["Source Line ID","Split Line ID","Description","Section","Qty","Unit","Procurement intent","Procurement aliases","Build-up type","Layer count","Total thickness (mm)","Installation clues","System clues","Component requirements","Technical classification","Include in quote","Approval required","Approval type","Missing information","Adjudicator confidence","Decision reason","Selected candidate ID","Selected candidate description","Price basis","Price","Line total","Confidence","Status"],t_=Wo.indexOf("Line total");function a_(e){return e.unmatchable?"Not matched (labour/plant/referential)":e.decision?.include_in_quote===!0&&e.decision.approval_required===!0?"Approval required":e.decision?.include_in_quote===!0?"Quoted":e.decision?.technical_classification==="no_suitable_candidate"?"No suitable candidate":(e.best,"No match")}async function ew(e){let t=await Wv(),a=t.utils.book_new(),r=new Date().toISOString().slice(0,10),n=[Wo],i=0;for(let c of e){let{item:p,best:f,qty:b,band:d,unmatchable:h,decision:w}=c,E=[p.section,p.subsection,p.subheading].filter(Boolean).join(" / "),D=!h&&f?.price!=null?f.price*b:null;D!=null&&(i+=D),n.push([p.source_line_id,p.line_id,p.description_original||"(no description)",E,b,p.unit,p.procurement_intent||"-",p.procurement_aliases.join(", "),p.build_up_type,p.layer_count,p.total_required_thickness_mm,p.installation_clues.join(", "),p.system_clues.join(", "),p.component_requirements.join(", "),w?.technical_classification??"",w?.include_in_quote==null?"":w.include_in_quote?"yes":"no",w?.approval_required==null?"":w.approval_required?"yes":"no",w?.approval_type??"",w?.missing_information.join(", ")??"",w?.confidence??"",w?.reason??"",h?"-":f?.product_id??w?.selected_candidate_id??"-",h?"-":f?.description??"-",h?"-":f?.price_basis??"-",h?null:f?.price??null,D,h?"-":d,a_(c)])}n.push(Array(Wo.length).fill(null));let o=Array(Wo.length).fill(null);o[0]="Estimated total",o[t_]=i,n.push(o),n.push(["DISCLAIMER: These matches are generated automatically and should be reviewed before procurement, especially any items flagged as medium or low confidence.",...Array(Wo.length-1).fill(null)]);let l=t.utils.aoa_to_sheet(n);l["!cols"]=[{wch:12},{wch:12},{wch:44},{wch:24},{wch:8},{wch:8},{wch:28},{wch:28},{wch:16},{wch:10},{wch:12},{wch:24},{wch:24},{wch:24},{wch:22},{wch:14},{wch:14},{wch:18},{wch:24},{wch:16},{wch:48},{wch:16},{wch:40},{wch:10},{wch:10},{wch:12},{wch:11},{wch:26}],t.utils.book_append_sheet(a,l,"Schedule match"),t.writeFile(a,`schedule-quote-${r}.xlsx`)}var Io=["Product ID","Description","Costing mode","Required amount","Req unit","Sell unit size","Sell unit","Required sell units","Unit price","Line total"];async function tw(e,t){let a=await Wv(),r=a.utils.book_new(),n=new Date().toISOString().slice(0,10),i=t?[["Account",t.name+" ("+t.id+")"],[],Io]:[Io],o=0;for(let p of e){let f=Ut(p),b=f.lineTotal;b!=null&&(o+=b),i.push([p.productId,p.description,f.costingMode,f.requestedAmount,xa(f.requestedUnit),f.salesUnitSize,xa(f.sellUnit),f.requiredSellUnits,f.unitPrice,b])}i.push(Array(Io.length).fill(null));let l=Array(Io.length).fill(null);l[0]="Estimated total",l[Io.length-1]=o,i.push(l);let c=a.utils.aoa_to_sheet(i);c["!cols"]=[{wch:14},{wch:48},{wch:12},{wch:14},{wch:10},{wch:14},{wch:10},{wch:16},{wch:12},{wch:14}],a.utils.book_append_sheet(r,c,"Basket"),a.writeFile(r,t?`basket-${t.id}-${n}.xlsx`:`basket-${n}.xlsx`)}var s=Y(ae()),gd="__none__",el=24,r_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}];function nw(e){return e==null?"low":e>=.7?"high":e>=.5?"medium":"low"}var i_=e=>e.attrs.supply_nature==="labour_only"||e.attrs.supply_nature==="plant"||e.flags.includes("referential");function n_(e,t){if(t!==gd){if(t)return e?.candidates.find(a=>a.product_id===t);if(e?.decision?.selected_candidate_id!=null)return e.candidates.find(a=>a.product_id===e.decision.selected_candidate_id)}}function aw(e){return{product_id:e.productId,description:e.description,source_list:null,price:e.price,price_basis:e.priceBasis,uoi_count:e.uoiCount??null,uoi:e.uoi,pdp_photo_url:e.pdpPhotoUrl??null,measurements_mm:e.measurementsMm??[],conversion:{sale_unit:e.saleUnit,sale_unit_quantity:e.saleUnitQuantity,unit_conversions:e.unitConversions?.map(t=>({request_uom:t.requestUom,quantity_per_sale_unit:t.quantityPerSaleUnit,evidence:t.evidence,confidence:t.confidence})),sales_uom_normalised:e.salesUomNormalised,conversion_type:e.conversionType,request_uoms_supported:e.requestUomsSupported,sales_unit_size:e.salesUnitSize,sales_unit_size_uom:e.salesUnitSizeUom,coverage_qty:e.coverageQty,coverage_uom:e.coverageUom,items_per_pallet:e.itemsPerPallet,items_per_pack:e.itemsPerPack,items_per_box:e.itemsPerBox,items_per_m2:e.itemsPerM2,waste_factor_default:e.wasteFactorDefault,rounding_rule:e.roundingRule,derived_coverage_m2:e.derivedCoverageM2,derived_length_m:e.derivedLengthM,quote_qty_formula_type:e.quoteQtyFormulaType,conversion_confidence:e.conversionConfidence,conversion_notes:e.conversionNotes},scores:{dimension:0,grade:0,brand:0,fuzzy:0,bm25:0,overall:0},method:"manual_cart_selection"}}function o_(e){return e?e.replace(/_/g," "):"not stated"}function l_({band:e}){return(0,s.jsx)("span",{className:`status-dot status-dot--${e}`,title:e,children:(0,s.jsx)("span",{className:"status-dot__mark"})})}function Tn(e,t){if(e==null)return"-";let a=Fo(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function hd(e){return e&&e.length>0?e.join(" x "):"-"}function s_(e){return e==null?"-":Number.isInteger(e/1e3)?`${e/1e3}m`:`${(e/1e3).toFixed(1)}m`}function Mn(e){let t=(e??[]).map(a=>a.trim()).filter(Boolean);return t.length>0?t.join(", "):"-"}function Pr(e,t){let a=typeof e.description_original=="string"?e.description_original.trim():"";return(typeof e.customer_display_label=="string"?e.customer_display_label.trim():"")||a||"(no description)"}var rw=[{background:"#fff7ed",borderColor:"#fdba74",color:"#9a3412"},{background:"#eff6ff",borderColor:"#93c5fd",color:"#1d4ed8"},{background:"#ecfeff",borderColor:"#67e8f9",color:"#0f766e"},{background:"#f0fdf4",borderColor:"#86efac",color:"#166534"},{background:"#fdf4ff",borderColor:"#f0abfc",color:"#a21caf"}];function c_(e){let t=new Map;return[...new Set(e.filter(mr).map(r=>r.linked_group_id))].forEach((r,n)=>{let i=n%26;t.set(r,{token:String.fromCharCode(65+i),bubbleStyle:rw[n%rw.length]})}),t}function mr(e){return!1}function zn(e){if(!e.linked_group_id)return null;let t=e.linked_group_label||"Linked group",a=e.linked_group_role==="anchor"?"anchor":e.linked_group_role==="dependent"?"dependent":"member",r=e.linked_group_shared_width_mm!=null?`, ${e.linked_group_shared_width_mm}mm family`:"";return`${t} (${a}${r})`}function fd({meta:e}){return e?(0,s.jsx)("span",{className:"results-linked-pill",style:e.bubbleStyle,children:`Link ${e.token}`}):null}function u_(e,t,a){let r=t?.rerank?.recommendedCandidateIds??[];if(r.length===0){let o=e.slice(0,5),l=o.some(c=>c.product_id===a)?void 0:e.find(c=>c.product_id===a);return l?[...o,l]:o}let n=new Map(e.map(o=>[o.product_id,o])),i=r.map(o=>n.get(o)).filter(o=>o!=null);if(a&&!i.some(o=>o.product_id===a)){let o=n.get(a);o&&i.unshift(o)}return[...new Map(i.map(o=>[o.product_id,o])).values()].slice(0,5)}function Ks(e){let t=e?.rerank?.recommendedCandidateIds??[];if(t.length===0||!e)return[];let a=new Map(e.candidates.map(r=>[r.product_id,r]));return t.map(r=>a.get(r)).filter(r=>r!=null)}function Ps(e){if(e>=6e4){let t=Math.floor(e/6e4),a=Math.round(e%6e4/1e3);return a===60?`${t+1}m`:`${t}m ${a}s`}return e>=1e3?`${(e/1e3).toFixed(e>=1e4?0:1)}s`:`${e}ms`}function p_({processStages:e,llmCalls:t,totalDurationMs:a,llmDurationMs:r,llmCallCount:n}){let i=[...t].sort((l,c)=>c.durationMs-l.durationMs).slice(0,12),o=Math.max(0,t.length-i.length);return(0,s.jsxs)("div",{className:"results-detail-block",style:{marginBottom:18},children:[(0,s.jsx)("h3",{style:{margin:"0 0 12px"},children:"Pipeline timings"}),(0,s.jsxs)("div",{className:"results-summary",style:{marginBottom:12},children:[(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:Ps(a)})," total"]}),(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:n})," LLM calls"]}),(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:Ps(r)})," LLM time"]})]}),(0,s.jsxs)("table",{className:"score-breakdown-table",style:{marginBottom:14},children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Process stage"}),(0,s.jsx)("th",{children:"Duration"})]})}),(0,s.jsx)("tbody",{children:e.map((l,c)=>(0,s.jsxs)("tr",{children:[(0,s.jsx)("td",{children:l.label}),(0,s.jsx)("td",{children:Ps(l.durationMs)})]},`${l.key}-${c}`))})]}),t.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("h4",{style:{margin:"0 0 10px"},children:"LLM calls"}),(0,s.jsxs)("table",{className:"score-breakdown-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Call"}),(0,s.jsx)("th",{children:"Duration"})]})}),(0,s.jsx)("tbody",{children:i.map((l,c)=>(0,s.jsxs)("tr",{children:[(0,s.jsx)("td",{children:l.label}),(0,s.jsx)("td",{children:Ps(l.durationMs)})]},`${l.key}-${c}`))})]}),o>0&&(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Showing slowest ",i.length," of ",t.length," LLM calls."]})]})]})}function d_({queries:e}){return e.length===0?null:(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Retrieval by procurement query"}),e.map((t,a)=>(0,s.jsxs)("div",{style:{marginBottom:16},children:[(0,s.jsxs)("div",{className:"results-row-meta",style:{marginBottom:6},children:["Query: ",(0,s.jsx)("strong",{children:t.query})]}),t.candidates.length===0?(0,s.jsx)("p",{className:"results-empty-hint",children:"No candidates returned for this query."}):(0,s.jsxs)("table",{className:"score-breakdown-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Product"}),(0,s.jsx)("th",{children:"Dims (mm)"}),(0,s.jsx)("th",{children:"Unit"}),(0,s.jsx)("th",{children:"bm25"})]})}),(0,s.jsx)("tbody",{children:t.candidates.slice(0,5).map((r,n)=>(0,s.jsxs)("tr",{children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{children:r.description}),(0,s.jsx)("div",{className:"results-row-meta",children:r.product_id})]}),(0,s.jsx)("td",{children:hd(r.measurements_mm)}),(0,s.jsx)("td",{children:Fo(r.price_basis)||"-"}),(0,s.jsx)("td",{children:r.bm25.toFixed(2)})]},`${r.product_id}-${n}`))})]})]},`${t.query}-${a}`))]})}function iw({item:e,result:t}){let a=t?.retrieval_debug.map(n=>n.query).filter(Boolean)??[],r=[["Procurement intent",e.procurement_intent||"-"],["Procurement aliases",Mn(e.procurement_aliases)],["Retrieval queries",Mn(a)],["Category",e.attrs.category||"-"],["Fine category",e.attrs.category_fine||"-"],["Brand",e.attrs.brand||"-"],["Material",e.attrs.material||"-"],["Grade / standard",e.attrs.grade_standard||"-"],["Treatment",e.attrs.treatment||"-"],["Supply nature",e.attrs.supply_nature||"-"],["Measurements (mm)",hd(e.attrs.measurements_mm)],["Stock length",s_(e.attrs.stock_length_mm)],["Matching mode",e.matching_mode||"-"],["Build-up type",e.build_up_type||"-"],["Layer count",e.layer_count!=null?String(e.layer_count):"-"],["Required thickness (mm)",e.total_required_thickness_mm!=null?String(e.total_required_thickness_mm):"-"],["Allowed layer thicknesses (mm)",e.acceptable_layer_thicknesses_mm.length>0?e.acceptable_layer_thicknesses_mm.join(", "):"-"],["Installation clues",Mn(e.installation_clues)],["System clues",Mn(e.system_clues)],["Component requirements",Mn(e.component_requirements)],["Linked group",zn(e)||"-"],["Flags",Mn(e.flags)]];return(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Search context"}),(0,s.jsx)("dl",{className:"results-detail-grid",children:r.map(([n,i])=>(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:n}),(0,s.jsx)("dd",{children:i})]},n))})]})}function m_({item:e}){let t=e.decomposition_debug;return t?(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Decomposition"}),(0,s.jsxs)("dl",{className:"results-detail-grid",children:[(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:"Attempted"}),(0,s.jsx)("dd",{children:t.attempted?"yes":"no"})]}),(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:"Applied"}),(0,s.jsx)("dd",{children:t.applied?"yes":"no"})]}),(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned items"}),(0,s.jsx)("dd",{children:t.returned_item_count??"-"})]}),(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:"Reason"}),(0,s.jsx)("dd",{children:t.reason||"-"})]}),(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned intents"}),(0,s.jsx)("dd",{children:t.items.length>0?t.items.map(a=>`${a.intent}${a.inherits_quantity?" (inherits qty)":""}`).join(", "):"-"})]})]})]}):null}function f_({result:e}){let t=e?.adjudication_debug;if(!t)return null;let a=[["Dependent rerank applied",t.dependent_rerank_applied?"yes":"no"],["Linked parent selected product",t.linked_parent_selected_candidate_description||t.linked_parent_selected_candidate_id||"-"],["Dimension reason overridden",t.dimension_reason_overridden?"yes":"no"]];return(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Adjudication context"}),(0,s.jsx)("dl",{className:"results-detail-grid",children:a.map(([r,n])=>(0,s.jsxs)(_e.Fragment,{children:[(0,s.jsx)("dt",{children:r}),(0,s.jsx)("dd",{children:n})]},r))}),t.rerank_line_item_input?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("h5",{style:{margin:"12px 0 8px"},children:"Rerank input"}),(0,s.jsx)("pre",{className:"results-pre",children:JSON.stringify(t.rerank_line_item_input,null,2)})]}):null]})}function g_({item:e,decision:t,result:a,showRetrievalDebug:r,reviewOnly:n=!1,linkedGroupMeta:i}){if(!t)return null;let o=t.technical_classification==="no_suitable_candidate"?"Exact match not found:":`AI review (${t.confidence??"confidence not stated"}):`;return n?t.reason?(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,s.jsx)("strong",{children:o}),"\xA0",t.reason]}),mr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",i?`Link ${i.token} - `:"",zn(e)]}):null]}):null:!t.reason&&!r?(0,s.jsx)(iw,{item:e,result:a}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(iw,{item:e,result:a}),r&&(0,s.jsx)(m_,{item:e}),r&&(0,s.jsx)(f_,{result:a}),t.reason&&(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,s.jsx)("strong",{children:o}),"\xA0",t.reason]}),mr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",i?`Link ${i.token} - `:"",zn(e)]}):null]}),r&&(0,s.jsx)(d_,{queries:a?.retrieval_debug??[]})]})}function h_({item:e,candidates:t,result:a,decision:r,unmatchable:n,selectedProductId:i,detailMode:o,onPick:l,onClear:c,showAll:p=!1,internal:f=!1,debugEnabled:b=!1,forceReviewNote:d=!1,linkedGroupMeta:h}){let w=f||o==="detailed",E=b&&o==="detailed",D=w||d?(0,s.jsx)(g_,{item:e,decision:r,result:a,showRetrievalDebug:E,reviewOnly:d&&!w,linkedGroupMeta:h}):null;if(n)return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsx)("p",{className:"results-empty-hint",children:"Classified as labour/plant or referencing another line item - skipped by design."})]});if(t.length===0)return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsx)("p",{className:"results-empty-hint",children:"No candidates were returned for this line item."})]});let m=p||f||o==="detailed"?t:u_(t,a,i);return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsxs)("table",{className:"score-breakdown-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Product"}),(0,s.jsx)("th",{children:"Dims (mm)"}),(0,s.jsx)("th",{children:"Price"}),E&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("th",{children:"dimension"}),(0,s.jsx)("th",{children:"grade"}),(0,s.jsx)("th",{children:"brand"}),(0,s.jsx)("th",{children:"fuzzy"}),(0,s.jsx)("th",{children:"bm25"}),(0,s.jsx)("th",{children:"overall"})]}),(0,s.jsx)("th",{"aria-label":"Actions"})]})}),(0,s.jsx)("tbody",{children:m.map((u,g)=>{let v=u.product_id===i;return(0,s.jsxs)("tr",{className:v?"score-breakdown-row--best":"",children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{children:u.description}),(0,s.jsx)("div",{className:"results-row-meta",children:u.product_id})]}),(0,s.jsx)("td",{children:(0,s.jsx)("span",{className:"unit-badge",children:hd(u.measurements_mm??u.debug?.candidate.measurements_mm)})}),(0,s.jsx)("td",{children:Tn(u.price,u.price_basis)}),E&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("td",{children:(u.scores?.dimension??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.grade??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.brand??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.fuzzy??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.bm25??0).toFixed(2)}),(0,s.jsx)("td",{children:(0,s.jsxs)("div",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[(0,s.jsx)(l_,{band:nw(u.scores?.overall)}),(0,s.jsx)("span",{className:"results-overall-cell",children:(u.scores?.overall??0).toFixed(2)})]})})]}),(0,s.jsx)("td",{children:(0,s.jsxs)("label",{className:"switch-toggle",title:v?"Currently selected":"Use this candidate",children:[(0,s.jsx)("input",{type:"checkbox",checked:v,onChange:()=>{v?c?.():l(u)},"aria-label":v?`${u.description} selected`:`Use ${u.description}`}),(0,s.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},`${u.product_id}-${g}`)})})]})]})}function bd({scheduleResult:e,onStartOver:t,cart:a,onAddToCart:r,onRemoveFromCart:n,onGoToBasket:i,cartSeeded:o,onCartSeeded:l,reviewGateComplete:c,onReviewGateComplete:p,internal:f=!1}){let b=!f&&Qs()==="QZA6-MRA4",d=b?"quote":"basket",{results:h,lineItems:w,parseReport:E,timings:D}=e,[m,u]=(0,_e.useState)({}),g=Cn(),[v,N]=(0,_e.useState)({}),[R,T]=(0,_e.useState)({}),[z,G]=(0,_e.useState)(""),[K,xe]=(0,_e.useState)(null),[Ee,Ge]=(0,_e.useState)(1),[Qe,Ie]=(0,_e.useState)(!1);(0,_e.useEffect)(()=>{Ie(new URLSearchParams(window.location.search).get("debug")==="1")},[]);let[ue,Q]=(0,_e.useState)("simple"),[se,Ne]=(0,_e.useState)(f?"list":"tile"),[lt,Ye]=(0,_e.useState)(!1),[ge,We]=(0,_e.useState)(null),[he,W]=(0,_e.useState)(""),[ze,Be]=(0,_e.useState)([]),[ve,et]=(0,_e.useState)(!1),[Ze,M]=(0,_e.useState)(null),[x,A]=(0,_e.useState)(!1),[I,ce]=(0,_e.useState)(null),me=(0,_e.useRef)(null),[ke,k]=(0,_e.useState)(new Set),[j,O]=(0,_e.useState)(new Set),[ne,ee]=(0,_e.useState)(!1);(0,_e.useEffect)(()=>{Ge(1)},[z,K,se]);let C=new Map(h.map(_=>[_.line_id,_])),V=c_(w),X=w.map(_=>{let L=C.get(_.line_id),we=L?.decision,gt=i_(_),Je=m[_.line_id],Wt=n_(L,Je),zi=a[_.line_id],jw=Je===gd?void 0:v[_.line_id]??(zi&&zi.productId!==Wt?.product_id?aw(zi):Wt),tm=gt?void 0:jw,Gw=_.qty??0;return{item:_,result:L,decision:we,unmatchable:gt,best:tm,qty:Gw,band:nw(tm?.scores?.overall)}}),pe=Zs(Object.values(a),{wasteFactorEnabled:!1,wasteFactorOverride:0}),Se=0;for(let _ of X){if(_.unmatchable||_.decision?.include_in_quote!==!0||!_.best)continue;let L=a[_.item.line_id];(!L||Ut(L).lineTotal==null)&&(Se+=1)}Se>0&&(pe=null);let ft=_=>!_.unmatchable&&!_.best&&_.decision?.technical_classification!=="no_suitable_candidate"&&Ks(_.result).length>0,Ve=_=>_.best??Ks(_.result)[0],Ir=X.filter(_=>!_.unmatchable&&!_.best).filter(_=>!j.has(_.item.line_id)),ll=X.filter(_=>j.has(_.item.line_id)),Ea=X;if(z.trim()){let _=z.trim().toLowerCase();Ea=Ea.filter(L=>L.item.description_original?.toLowerCase().includes(_)||Ve(L)?.description?.toLowerCase().includes(_))}if(K){let _=K==="asc"?1:-1;Ea=[...Ea].sort((L,we)=>_*(L.item.description_original||"").localeCompare(we.item.description_original||""))}let hr=Math.max(1,Math.ceil(Ea.length/el)),Ft=Math.min(Ee,hr),It=Ea.slice((Ft-1)*el,Ft*el),Xd=It.filter(_=>!_.unmatchable&&_.best),$d=It.filter(_=>ft(_)),hc=It.filter(_=>!_.unmatchable&&(_.best||ft(_))),Zd=It.filter(_=>_.unmatchable||!_.best&&!ft(_)),J=ge?X.find(_=>_.item.line_id===ge)??null:null,Rw=!f&&!c&&!J&&Ir.length>0,Gn=(0,_e.useRef)(null),Qn=()=>{let _=me.current;if(!_)return;let{top:L,left:we,width:gt,height:Je}=_.getBoundingClientRect(),zi=_.querySelector(".bom-toolbar-btn")?.closest("td")?.getBoundingClientRect().left;ce({top:L,left:we,width:zi?zi-we:gt,height:Je})};(0,_e.useEffect)(()=>(window.addEventListener("scroll",Qn,!0),window.addEventListener("resize",Qn),()=>{window.removeEventListener("scroll",Qn,!0),window.removeEventListener("resize",Qn)})),(0,_e.useEffect)(()=>{let _=L=>{Gn.current&&!L.composedPath().includes(Gn.current)&&Gn.current.removeAttribute("open")};return document.addEventListener("click",_),()=>document.removeEventListener("click",_)},[]);let Ei=_=>{We(_),W("")},Uw=()=>{if(!ge)return;let _=a[ge];if(_){u(L=>({...L,[ge]:_.productId})),N(L=>({...L,[ge]:aw(_)}));return}u(L=>{let we={...L};return delete we[ge],we}),N(L=>{let we={...L};return delete we[ge],we})},br=(_=!1)=>{let L=ge?a[ge]:void 0;!_&&L&&J?.best&&L.productId!==J.best.product_id&&!window.confirm("You have selected a new product. Leave without updating it?")||(_||Uw(),We(null),ee(!1))},Dw=_=>{if(k(L=>new Set(L).add(_)),Ir.some(L=>L.item.line_id!==_)){br(!0);return}p(),br(!0)},Bw=_=>{if(bc(_),O(L=>new Set(L).add(_)),Ir.some(L=>L.item.line_id!==_)){br(!0);return}p(),br(!0)},Ow=()=>{O(_=>new Set([..._,...Ir.map(L=>L.item.line_id)])),p()},Kd=()=>{J?.best&&(Jd(J.item.line_id,J.best),r(Mi(J)),ne?Dw(J.item.line_id):br(!0))},Pd=Zd.length>0?(0,s.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,s.jsxs)("div",{className:"results-tile-section__head",children:[(0,s.jsx)("h3",{children:"Require Matching"}),(0,s.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,s.jsx)("div",{className:"results-unmatched-list",children:Zd.map(_=>{let{item:L,qty:we}=_;return(0,s.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>Ei(L.line_id),children:[(0,s.jsx)("span",{className:"results-unmatched-card__main",children:(0,s.jsx)("span",{className:"results-unmatched-card__title",children:Pr(L,w)})}),(0,s.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},L.line_id)})})]}):null,bc=_=>{u(L=>({...L,[_]:gd})),N(L=>({...L,[_]:void 0})),T(L=>({...L,[_]:void 0})),n(_)},vc=(_,L)=>{u(we=>({...we,[_]:L.product_id})),N(we=>({...we,[_]:L}))},Jd=(_,L)=>{L.method==="catalogue_search"&&T(we=>({...we,[_]:L}))};function ix(){g("downloaded",{type:"schedule",lines:X.length}),ew(X.map(({item:_,best:L,qty:we,band:gt,unmatchable:Je,decision:Wt})=>({item:_,best:L,qty:we,band:gt,unmatchable:Je,decision:Wt})))}function Mi(_){let L=_.best??Ks(_.result)[0];return Kr(L,{lineId:_.item.line_id,description:_.item.description_original,unit:_.item.unit,qty:_.qty,linkedContext:_.item.linked_group_role==="dependent"&&_.item.linked_group_id?w.filter(we=>we.linked_group_id===_.item.linked_group_id&&we.linked_group_role==="anchor").slice(0,1).map(we=>{let gt=a[we.line_id];return{line_id:we.line_id,product_id:gt?.productId??null,measurements_mm:gt?.measurementsMm??we.attrs.measurements_mm,description:gt?.description??we.description_original,qty:we.qty,unit:we.unit,role:"anchor"}}):void 0})}(0,_e.useEffect)(()=>{if(!o){for(let _ of X)!_.unmatchable&&_.best&&r(Mi(_));l()}},[o]),(0,_e.useEffect)(()=>{for(let _ of X)!a[_.item.line_id]&&!_.unmatchable&&_.best&&r(Mi(_))},[e]),(0,_e.useEffect)(()=>{if(!ge){Be([]),M(null),et(!1);return}let _=he.trim();if(!_){Be([]),M(null),et(!1);return}let L=!1,we=window.setTimeout(async()=>{try{et(!0),M(null);let gt=await fetch(Lt(`/api/catalogue/search?q=${encodeURIComponent(_)}`),{headers:wi()}),Je=await Kt(gt);if(!gt.ok)throw new Error(Je?.error||Je?.message||"Failed to search catalogue");L||Be(Array.isArray(Je?.items)?Je.items:[])}catch(gt){L||(Be([]),M(gt?.message||"Failed to search catalogue"))}finally{L||et(!1)}},250);return()=>{L=!0,window.clearTimeout(we)}},[he,ge]);let wc=Object.keys(a).length,Ma=he.trim(),Fd=Ks(J?.result),sl=J?.decision?.technical_classification==="no_suitable_candidate"||!!J&&!J.best,Id=J?.decision?.technical_classification!=null,Wd=J?.decision?.reason??(sl?"No catalogue candidate found. Refine the request or search the catalogue.":null),Lw=ze.map(_=>({product_id:_.product_id,description:_.description,source_list:_.source_list,price:_.price,price_basis:_.price_basis,uoi_count:_.uoi_count??null,uoi:_.uoi,pdp_photo_url:_.pdp_photo_url??null,conversion:_.conversion,measurements_mm:_.measurements_mm??[],scores:{dimension:0,grade:0,brand:0,fuzzy:0,bm25:0,overall:0},method:"catalogue_search"})),Yn=Ma?Lw:Fd,Ti=J?R[J.item.line_id]:void 0,Vn=!Ma&&Ti&&!Yn.some(_=>_.product_id===Ti.product_id)?[...Yn,Ti]:Yn,em=(()=>{let _=Vn.slice(0,Ma?12:3);return Ma||!Ti||_.some(L=>L.product_id===Ti.product_id)?_:[..._,Ti]})(),cl=!!J?.best&&a[J.item.line_id]?.productId===J.best.product_id,Hw=!!J?.best&&!!a[J.item.line_id]&&!cl;return(0,s.jsxs)("div",{className:"wizard-step entry-stage",children:[(0,s.jsxs)("div",{className:`quick-order-card${f?"":" quick-order-card--customer"}`,children:[(0,s.jsx)("div",{className:`quick-order-hero${f?"":" quick-order-hero--customer"}`,children:f?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,s.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,s.jsx)("h1",{children:"Your Results"}),(0,s.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,s.jsx)("strong",{children:pe==null?"Calculating\u2026":st(pe)})," Est. total"]})]}),(0,s.jsx)("p",{children:"Each line item from your schedule matched against your catalogue, ranked by confidence."})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{children:"Review your matched products"}),(0,s.jsxs)("p",{children:["Check you're happy with these items, then click ",b?"View Quote":"View Basket"," to continue."]})]}),(0,s.jsxs)("button",{type:"button",className:"results-total-action",onClick:i,"aria-label":b?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:b?"View Quote":"View Basket"}),(0,s.jsx)("strong",{children:pe==null?"Calculating\u2026":st(pe)})]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Ht,{})})]})]})}),(0,s.jsxs)("div",{className:"quick-order-panel",style:{paddingTop:16},children:[Qe&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:12},children:(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn","aria-pressed":lt,onClick:()=>Ye(_=>!_),children:lt?"Hide timings":"Show timings"})}),Qe&<&&(0,s.jsx)(p_,{...D}),!b&&(0,s.jsx)("div",{className:"results-toolbar-row",children:!J&&(0,s.jsxs)("div",{className:"results-summary",style:{marginBottom:0},children:[Se>0&&(0,s.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,s.jsx)("strong",{children:Se})," need pricing"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:z,onChange:_=>G(_.target.value),"aria-label":"Search line items"}),!f&&(0,s.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,s.jsx)("button",{type:"button",className:`results-view-toggle__btn${se==="tile"?" is-active":""}`,"aria-pressed":se==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>Ne("tile"),children:(0,s.jsxs)("svg",{width:"18",height:"12",viewBox:"0 0 15 10",fill:"currentColor",children:[(0,s.jsx)("rect",{x:"0.5",y:"0.5",width:"4",height:"4"}),(0,s.jsx)("rect",{x:"5.5",y:"0.5",width:"4",height:"4"}),(0,s.jsx)("rect",{x:"10.5",y:"0.5",width:"4",height:"4"}),(0,s.jsx)("rect",{x:"0.5",y:"5.5",width:"4",height:"4"}),(0,s.jsx)("rect",{x:"5.5",y:"5.5",width:"4",height:"4"}),(0,s.jsx)("rect",{x:"10.5",y:"5.5",width:"4",height:"4"})]})}),(0,s.jsx)("button",{type:"button",className:`results-view-toggle__btn${se==="list"?" is-active":""}`,"aria-pressed":se==="list","aria-label":"List view",title:"List view",onClick:()=>Ne("list"),children:(0,s.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,s.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,s.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,s.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),Qe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Q(_=>_==="simple"?"detailed":"simple"),children:ue==="detailed"?"Hide detailed view":"Show detailed view"}),(0,s.jsxs)("details",{ref:Gn,style:{position:"relative"},children:[(0,s.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort line items",style:{fontSize:16},children:"\u21C5"}),(0,s.jsx)("div",{className:"sort-menu-panel",children:r_.map(_=>{let L=K===_.dir;return(0,s.jsxs)("button",{type:"button",className:`sort-menu-item${L?" is-active":""}`,onClick:()=>{xe(L?null:_.dir),Gn.current?.removeAttribute("open")},children:[(0,s.jsx)("span",{className:"sort-menu-item__check",children:L?"\u2713":""}),_.label]},_.dir)})})]})]})]})}),se==="tile"||J?(0,s.jsxs)(s.Fragment,{children:[J?(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop",role:"dialog","aria-modal":"true","aria-label":"Product options",onClick:()=>br(),children:(0,s.jsxs)("section",{className:"quick-order-workflow-modal results-review-modal",onClick:_=>_.stopPropagation(),children:[(0,s.jsx)("button",{type:"button",className:"quick-order-workflow-close results-review-modal__close",onClick:()=>br(),"aria-label":"Close product options",children:(0,s.jsx)(Ko,{})}),(0,s.jsx)("div",{className:"results-review-page",children:f?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"results-review-page__top",children:[(0,s.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:()=>br(),children:[(0,s.jsx)(Zr,{}),"Back to results"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[Qe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Q(_=>_==="simple"?"detailed":"simple"),children:ue==="detailed"?"Hide detailed info":"Show detailed info"}),(0,s.jsx)("div",{className:"results-review-searchbar",children:(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:he,onChange:_=>W(_.target.value),"aria-label":"Search database candidates"})}),(0,s.jsx)("div",{className:"results-candidate-actions",children:(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>bc(J.item.line_id),children:"Clear selected product"})})]})]}),(0,s.jsxs)("div",{className:"results-review-page__hero",children:[(0,s.jsx)("div",{className:"results-review-page__image-wrap",children:(0,s.jsx)("img",{className:"fill-img results-review-page__image",src:Qa(Ve(J)?.description||J.item.description_original,Ve(J)?.product_id,Ve(J)?.pdp_photo_url),alt:""})}),(0,s.jsxs)("div",{className:"results-review-page__summary",children:[(0,s.jsx)("h2",{children:Pr(J.item,w)}),(0,s.jsxs)("p",{className:"results-review-page__meta",children:[_i(J.qty)," ",ka(J.item.unit,J.qty)]}),J.best?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:J.best.description}),J.best.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Tn(J.best.price,J.best.price_basis)}):null]}):Ve(J)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:Ve(J)?.description}),Ve(J)?.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Tn(Ve(J)?.price??null,Ve(J)?.price_basis??null)}):null,(0,s.jsx)("div",{className:"results-row-meta",children:"Best reviewed alternative - not yet selected"})]}):(0,s.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line item."}),mr(J.item)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[(0,s.jsx)(fd,{meta:V.get(J.item.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:zn(J.item)})]}):null,(0,s.jsx)("div",{className:"results-review-page__actions",children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[J.item.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[J.item.line_id]?n(J.item.line_id):(J.best&&Jd(J.item.line_id,J.best),r(Mi(J)))},disabled:!J.best,"aria-label":a[J.item.line_id]?f?"Remove from selection":`Remove from ${d}`:f?"Add to selection":`Add to ${d}`,children:a[J.item.line_id]?"\u2713 Added":f?"+ Add to selection":`Add to ${d}`})})]})]}),ve?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,!ve&&Ze?(0,s.jsx)("div",{className:"results-empty-card",children:Ze}):null,!ve&&!Ze&&Ma&&Yn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No candidate products match this database search."}):!ve&&!Ze?(0,s.jsx)(h_,{item:J.item,candidates:Yn,result:J.result,decision:J.decision,unmatchable:J.unmatchable,selectedProductId:J.best?.product_id??null,detailMode:ue,linkedGroupMeta:mr(J.item)?V.get(J.item.linked_group_id):void 0,onPick:_=>vc(J.item.line_id,_),onClear:()=>bc(J.item.line_id),showAll:f||Qe||Ma.length>0,internal:f,debugEnabled:Qe,forceReviewNote:!0}):null]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("section",{className:"customer-review-request",children:[(0,s.jsx)("span",{className:"customer-review-eyebrow",children:"Original request"}),(0,s.jsx)("strong",{children:Pr(J.item,w)||"Original request"})]}),Wd?(0,s.jsxs)("section",{className:"customer-review-ai",children:[(0,s.jsx)("strong",{children:sl?"Exact match not found:":"AI review:"})," ",Wd]}):null,(0,s.jsxs)("section",{className:"customer-review-options",children:[(0,s.jsx)("div",{className:"customer-review-options__head",children:(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:sl?"We couldn't find a suitable product":Id?"Choose a product":"We couldn't review this item"}),(0,s.jsx)("p",{children:sl?Fd.length>0?"These AI-reviewed alternatives may be useful, but need approval.":"Search the catalogue to choose an alternative.":Id?`Select the option you want to add to your ${d}.`:"Search the catalogue to choose a product."})]})}),!Ma&&Vn.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:em.map(_=>{let L=_.product_id===J.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${L?" is-selected":""}`,onClick:()=>vc(J.item.line_id,_),"aria-pressed":L,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Qa(_.description,_.product_id,_.pdp_photo_url),alt:"",width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:_.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:_.price!=null?`\xA3${Tn(_.price,_.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:L?"Selected":"Choose"})]},_.product_id)})}):null,Vn.length>0&&(0,s.jsx)("div",{className:"customer-review-divider",children:(0,s.jsx)("span",{children:"or"})}),(0,s.jsxs)("label",{className:"customer-review-search",children:[(0,s.jsx)("span",{children:"Search our full catalogue"}),(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products...",value:he,onChange:_=>W(_.target.value),"aria-label":"Search catalogue"})]}),Ma&&ve?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,Ma&&!ve&&Ze?(0,s.jsx)("div",{className:"results-empty-card",children:Ze}):null,Ma&&!ve&&!Ze&&Vn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No products match this search."}):null,Ma&&!ve&&!Ze&&Vn.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:em.map(_=>{let L=_.product_id===J.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${L?" is-selected":""}`,onClick:()=>vc(J.item.line_id,_),"aria-pressed":L,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Qa(_.description,_.product_id,_.pdp_photo_url),alt:"",width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:_.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:_.price!=null?`\xA3${Tn(_.price,_.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:L?"Selected":"Choose"})]},_.product_id)})}):null]}),J.best?Hw?(0,s.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,s.jsx)("button",{type:"button",className:"cta-btn customer-review-add",onClick:()=>{Kd()},children:(0,s.jsx)("span",{children:"Update product"})}),(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-add",onClick:()=>n(J.item.line_id),children:(0,s.jsx)("span",{children:`Remove from ${d}`})})]}):(0,s.jsx)("button",{type:"button",className:`cta-btn customer-review-add${cl?" cta-btn-secondary":""}`,onClick:()=>{cl?n(J.item.line_id):Kd()},children:(0,s.jsx)("span",{children:cl?`Remove from ${d}`:`Add selected product to ${d}`})}):null,ne?(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-skip",onClick:()=>Bw(J.item.line_id),children:"Skip this item"}):null]})})]})}):null,(0,s.jsxs)("div",{className:"results-tile-layout",children:[Ea.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No line items match the current search/filter."}):null,hc.length>0?(0,s.jsx)("section",{className:"results-tile-section","aria-label":"Matched and review items",children:(0,s.jsx)("div",{className:"results-tile-grid",children:hc.map(_=>{let{item:L,best:we,qty:gt}=_,Je=Ve(_),Wt=!we&&ft(_);return(0,s.jsxs)("article",{className:"results-tile-card",children:[(0,s.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>Ei(L.line_id),"aria-label":`Review match for ${Pr(L,w)||"item"}`,children:[(0,s.jsxs)("div",{className:"results-tile-card__media",children:[Wt||mr(L)?(0,s.jsxs)("div",{className:"results-tile-card__badges",children:[mr(L)?(0,s.jsx)(fd,{meta:V.get(L.linked_group_id)}):(0,s.jsx)("span",{}),Wt?(0,s.jsx)("span",{style:{padding:"6px 10px",borderRadius:999,background:"#fef3c7",color:"#92400e",fontSize:12,fontWeight:700,lineHeight:1},children:"Partially matched"}):null]}):null,(0,s.jsx)("img",{className:"fill-img results-tile-card__image",src:Qa(Je?.description||L.description_original,Je?.product_id,Je?.pdp_photo_url),alt:""})]}),(0,s.jsxs)("div",{className:"results-tile-card__body",children:[Je?(0,s.jsx)(s.Fragment,{children:(0,s.jsx)("div",{className:"results-tile-card__heading",children:(0,s.jsx)("div",{className:"results-tile-card__title",children:Je.description})})}):(0,s.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line item."}),(0,s.jsx)("div",{className:"results-tile-card__match",children:Je?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-tile-card__match-label",children:Wt?"\u21B3 partially matched from":"\u21B3 matched from"}),(0,s.jsx)("div",{className:"results-tile-card__match-name",children:Pr(L,w)}),mr(L)?(0,s.jsx)("div",{className:"results-row-meta",children:zn(L)}):null]}):(0,s.jsx)("span",{className:"results-empty-hint",children:"No matched product selected."})})]}),(0,s.jsx)("span",{className:"results-tile-card__hover-prompt","aria-hidden":"true",children:"Click to view options"})]}),(0,s.jsxs)("div",{className:"results-tile-card__actions",children:[f&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ei(L.line_id),children:"Review"}),(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[L.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[L.line_id]?n(L.line_id):r(Mi(_))},disabled:!Je,"aria-label":a[L.line_id]?f?"Remove from selection":`Remove from ${d}`:f?"Add to selection":`Add to ${d}`,children:a[L.line_id]?"\u2713 Added":f?"+ Add":`Add to ${d}`})]})]},L.line_id)})})}):null,Pd]})]}):(0,s.jsxs)(s.Fragment,{children:[I&&(0,s.jsx)("div",{className:"results-table__hover-overlay",style:I,"aria-hidden":"true",children:"Click to view options"}),(0,s.jsx)("div",{className:"bom-table-wrap",children:(0,s.jsxs)("table",{className:"bom-table results-table","aria-label":"Matched line items",children:[(0,s.jsxs)("colgroup",{children:[(0,s.jsx)("col",{className:"col-item"}),(0,s.jsx)("col",{style:{width:"220px"}}),(0,s.jsx)("col",{style:{width:"100px"}}),ue==="simple"&&(0,s.jsx)("col",{style:{width:"110px"}})]}),(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{className:"bom-col-header",children:[(0,s.jsx)("th",{style:{textAlign:"left"},children:"Description"}),(0,s.jsx)("th",{style:{textAlign:"center"},children:"Product Matched"}),(0,s.jsx)("th",{style:{textAlign:"center"},children:"Price"}),ue==="simple"&&(0,s.jsx)("th",{style:{textAlign:"center"},children:f?"Selection":b?"Quote":"Basket"})]})}),(0,s.jsxs)("tbody",{children:[Ea.length===0&&(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:ue==="simple"?4:3,className:"results-empty-hint",style:{padding:"16px 8px"},children:"No line items match the current search/filter."})}),hc.map(_=>{let{item:L,result:we,decision:gt,best:Je}=_;return(0,s.jsxs)("tr",{className:"bom-row results-table__review-row",onClick:()=>Ei(L.line_id),onMouseEnter:Wt=>{me.current=Wt.currentTarget,Qn()},onMouseLeave:()=>{me.current=null,ce(null)},children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{className:"bom-component-name",children:Pr(L,w)}),mr(L)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,s.jsx)(fd,{meta:V.get(L.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:zn(L)})]}):null]}),(0,s.jsx)("td",{children:Je?(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"results-match-cell-text",title:Je.description,children:Je.description}),ue==="detailed"&>?.technical_classification&&(0,s.jsxs)("div",{className:"results-row-meta",children:[o_(gt.technical_classification),gt.approval_required?" - approval required":""]})]}):(0,s.jsx)("span",{className:"results-empty-hint"})}),(0,s.jsx)("td",{style:{textAlign:"center"},children:Je?.price!=null?Tn(Je.price,Je.price_basis):"-"}),ue==="simple"&&(0,s.jsx)("td",{style:{textAlign:"center"},children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[L.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,style:{width:84,justifyContent:"center"},onClick:Wt=>{Wt.stopPropagation(),a[L.line_id]?n(L.line_id):r(Mi(_))},"aria-label":a[L.line_id]?f?"Remove from selection":`Remove from ${d}`:f?"Add to selection":`Add to ${d}`,children:a[L.line_id]?"\u2713 Added":f?"+ Add":`Add to ${d}`})})]},L.line_id)})]})]})}),Pd]}),!J&&hr>1&&(0,s.jsxs)("div",{className:"results-pagination",children:[(0,s.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(Ft-1)*el+1,"\u2013",Math.min(Ft*el,Ea.length)," of ",Ea.length]}),(0,s.jsxs)("div",{className:"results-pagination-controls",children:[(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ge(Ft-1),disabled:Ft===1,children:"Previous"}),(0,s.jsxs)("span",{className:"results-pagination-page",children:["Page ",Ft," of ",hr]}),(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ge(Ft+1),disabled:Ft===hr,children:"Next"})]})]}),(E.itemCount!=null||E.headingCount!=null||E.skippedCount!=null)&&(0,s.jsxs)("div",{className:"results-summary",style:{marginTop:16},children:[E.itemCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:E.itemCount})," items parsed"]}),E.headingCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:E.headingCount})," headings"]}),E.skippedCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:E.skippedCount})," rows skipped"]})]}),(0,s.jsxs)("div",{className:"disclaimer-box",children:[(0,s.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,s.jsx)("p",{className:"disclaimer-text",children:"These matches are generated automatically and should be reviewed before purchase."})]}),!J&&(0,s.jsxs)("div",{className:"btn-row results-actions",children:[(0,s.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:(wc>0,"0 1 30%"),gap:10,justifyContent:"center"},onClick:()=>A(!0),"aria-label":"Start over",children:[(0,s.jsx)(dd,{}),(0,s.jsx)("span",{children:"Start Over"})]}),wc>0&&(0,s.jsxs)("button",{className:"cta-btn",style:{flex:"0 1 70%"},onClick:i,"aria-label":f?"View selection":b?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[f?"View Selection":b?"View Quote":"View Basket"," (",wc,")"]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Ht,{})})]})]})]})]}),Rw&&(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop review-gate-modal-backdrop",role:"dialog","aria-modal":"true","aria-labelledby":"review-gate-title",children:(0,s.jsxs)("section",{className:"quick-order-workflow-modal review-gate-modal",children:[(0,s.jsxs)("div",{className:"review-gate-modal__header",children:[(0,s.jsx)("h2",{id:"review-gate-title",children:"Choose products for these items"}),(0,s.jsx)("p",{children:"We couldn\u2019t find a clear match for these items, so we need your help. Select an option from the suggestions, search the catalogue, or leave the item out."})]}),(0,s.jsx)("div",{className:"review-gate-list",children:Ir.map(_=>{let L=ke.has(_.item.line_id),we=ft(_);return(0,s.jsx)("div",{className:`review-gate-item${L?" is-reviewed":""}`,children:(0,s.jsxs)("button",{type:"button",className:"review-gate-item__review",onClick:()=>{ee(!0),Ei(_.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Pr(_.item,w)}),(0,s.jsx)("span",{children:_.decision?.reason||(we?"A close alternative is available but needs confirmation.":"No product has been selected for this item yet.")})]}),(0,s.jsx)("span",{className:"review-gate-item__action",children:L?"Choice made":"Choose a product"})]})},_.item.line_id)})}),(0,s.jsx)("button",{type:"button",className:"review-gate-skip",onClick:Ow,children:"Skip all"}),ll.length>0?(0,s.jsxs)("div",{className:"review-gate-skipped",children:[(0,s.jsx)("strong",{children:"Skipped"}),ll.map(_=>(0,s.jsxs)("button",{type:"button",className:"review-gate-item is-skipped",onClick:()=>{O(L=>{let we=new Set(L);return we.delete(_.item.line_id),we}),ee(!0),Ei(_.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Pr(_.item,w)}),(0,s.jsx)("span",{children:`Not added to your ${d}.`})]}),(0,s.jsx)("span",{className:"review-gate-item__action",children:"Choose a product"})]},_.item.line_id))]}):null]})}),x&&(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop start-over-modal",role:"dialog","aria-modal":"true","aria-labelledby":"start-over-modal-title",children:(0,s.jsxs)("div",{className:"modal-card start-over-modal__card",children:[(0,s.jsx)("h2",{id:"start-over-modal-title",className:"modal-title",children:"Start over?"}),(0,s.jsxs)("p",{className:"modal-body",children:["This will clear the current results and ",b?"quote":"basket"," and take you back to the start."]}),(0,s.jsxs)("div",{className:"modal-actions",children:[(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-secondary",onClick:()=>A(!1),children:"Cancel"}),(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-danger",onClick:()=>{A(!1),t()},autoFocus:!0,children:"Start Over"})]})]})})]})}var xt=Y(Ke());var q=Y(ae()),b_=.2,tl=10,ow="Enter a valid email address so we can send your quote.",v_=(e,t)=>{let a=`${t.requestedAmount} ${xa(t.requestedUnit,t.requestedAmount)}`,r=`${t.requiredSellUnits} ${xa(t.sellUnit,t.requiredSellUnits??0)}`,n=e.unitConversions?.find(i=>i.requestUom===t.requestedUnit);return n&&n.quantityPerSaleUnit<1?`${a} requested \u2192 order ${r} (${Math.round(1/n.quantityPerSaleUnit)} ${xa(t.sellUnit,2)} per ${xa(t.requestedUnit,1)})`:e.coverageQty&&/^m per /i.test(e.coverageUom??"")?`${a} requested \u2192 order ${r} (${e.coverageQty} ${e.coverageUom})`:`${a} requested \u2192 order ${r}`},w_=e=>["box","pack"].includes(e.requestedUnit)?"Pack size needed to calculate the order quantity.":`This product is sold by ${xa(e.sellUnit,1)}.`;function y_(){return(0,q.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,q.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,q.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),(0,q.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,q.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function al(){return(0,q.jsx)("svg",{width:"8",height:"5",viewBox:"0 0 8 5",fill:"none",children:(0,q.jsx)("path",{d:"M1 4L4 1L7 4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function rl({cart:e,onUpdateQty:t,onUpdateSellUnits:a,onResolveConversions:r,onRemove:n,onBack:i,onStartNewQuote:o,internal:l=!1}){let c=(0,xt.useId)(),p=!l&&Qs()==="QZA6-MRA4",f=Object.values(e),[b,d]=(0,xt.useState)(""),[h,w]=(0,xt.useState)(!1),[E,D]=(0,xt.useState)(!1),m=Cn(),[u,g]=(0,xt.useState)(""),[v,N]=(0,xt.useState)({}),[R,T]=(0,xt.useState)({}),[z,G]=(0,xt.useState)(1),[K,xe]=(0,xt.useState)({}),[Ee,Ge]=(0,xt.useState)(!1),[Qe,Ie]=(0,xt.useState)("0"),ue=(0,xt.useRef)(new Set);(0,xt.useEffect)(()=>{if(!r)return;for(let A of Object.values(e))Ut(A).requiredSellUnits!=null&&ue.current.delete(A.lineId);let x=Object.values(e).filter(A=>A.productId!=="-"&&Ut(A).requiredSellUnits==null&&!ue.current.has(A.lineId));x.length!==0&&(x.forEach(A=>ue.current.add(A.lineId)),fetch(Lt("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({lines:x.map(A=>({line_id:A.lineId,product_id:A.productId,requested_description:A.requestedDescription??A.description,requested_qty:A.qty,requested_uom:A.unit||null,linked_context:A.linkedContext??[],selected_description:A.description,selected_uoi:A.uoi,selected_uoi_count:A.uoiCount,selected_conversion:{sales_uom_normalised:A.salesUomNormalised,conversion_type:A.conversionType,sales_unit_size:A.salesUnitSize,sales_unit_size_uom:A.salesUnitSizeUom,coverage_qty:A.coverageQty,coverage_uom:A.coverageUom}}))})}).then(A=>A.ok?Kt(A):null).then(A=>{let I={};for(let ce of A?.data?.items??A?.items??[]){let me=ce?.conversion;if(!me||typeof ce?.line_id!="string")continue;let ke=e[ce.line_id];I[ce.line_id]={conversionType:me.conversion_type,requestUomsSupported:me.request_uoms_supported,salesUomNormalised:me.sales_uom_normalised,salesUnitSize:me.sales_unit_size,salesUnitSizeUom:me.sales_unit_size_uom,coverageQty:me.coverage_qty,coverageUom:me.coverage_uom,roundingRule:me.rounding_rule,conversionConfidence:me.conversion_confidence,conversionNotes:me.conversion_notes,...ke?.qty===0&&Number.isFinite(me.suggested_order_qty)&&me.suggested_order_qty>0?{qty:me.suggested_order_qty,unit:me.suggested_order_uom||ke.unit}:{}}}Object.keys(I).length>0&&r(I)}).catch(A=>console.error("Catalogue conversion resolution failed",A)))},[e,r]);function Q(x){N(A=>{let I={...A};return delete I[x],I})}function se(x,A){let I=parseFloat(A);!isNaN(I)&&I>=0&&t(x,I),Q(x)}function Ne(x,A,I){t(x,Math.max(0,A+I)),Q(x)}function lt(x){T(A=>{let I={...A};return delete I[x],I})}function Ye(x,A){let I=parseFloat(A);!isNaN(I)&&I>=0&&a(x,I),lt(x)}function ge(x,A,I){a(x,Math.max(0,A+I)),lt(x)}async function We(){let x=b.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(x)){g(ow);return}g(""),D(!0);try{let A=await fetch(Lt("/api/quote-requests"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({email:x,items:he.map(({item:I,pricing:ce})=>{let me=ce.requiredSellUnits??ce.requestedAmount,ke=ce.requiredSellUnits!=null?ce.sellUnit:ce.requestedUnit;return{product_id:I.productId,description:I.description,quantity:me,unit:xa(ke,me),unit_price:ce.requiredSellUnits!=null?ce.unitPrice:null,line_total:ce.lineTotal}})})});if(!A.ok){let I=await Kt(A);console.error("Quote request failed",A.status,I?.message),g(A.status===429?"You've sent a few requests already. Please try again in a few minutes.":"Your request couldn't be sent. Please try again, or contact us if it keeps happening.");return}m("quote_requested",{items:he.length,total:Math.round(Be*100)/100}),w(!0),window.scrollTo(0,0)}catch{g("Your request couldn't be sent. Check your connection and try again.")}finally{D(!1)}}let he=f.map(x=>({item:x,pricing:Ut(x,{wasteFactorEnabled:Ee,wasteFactorOverride:Math.max(0,Number.parseFloat(Qe)||0)/100})})),W=Zs(f,{wasteFactorEnabled:Ee,wasteFactorOverride:Math.max(0,Number.parseFloat(Qe)||0)/100}),ze=W*b_,Be=W+ze,ve=(0,xt.useRef)({items:he.length,total:Math.round(Be*100)/100});(0,xt.useEffect)(()=>{m("basket_viewed",ve.current)},[m]);let et=Math.max(1,Math.ceil(he.length/tl)),Ze=Math.min(z,et),M=he.slice((Ze-1)*tl,Ze*tl);return h?(0,q.jsx)("div",{className:"wizard-step entry-stage",children:(0,q.jsxs)("div",{className:"quote-request-sent",role:"status",children:[(0,q.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,q.jsx)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,q.jsx)("polyline",{points:"5 12.5 10 17.5 19 7"})})}),(0,q.jsx)("h1",{children:"Quote requested"}),(0,q.jsxs)("p",{children:["You're all done. We'll email your sharper price to ",(0,q.jsx)("strong",{children:b.trim()}),", usually within one working day."]}),(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,q.jsx)("span",{children:"Start a new quote"})}),(0,q.jsx)("p",{className:"quote-request-sent-note",children:"Nothing is charged until you approve the quote."})]})}):(0,q.jsx)("div",{className:`wizard-step entry-stage${p?" basket-layout--qza6-mra4":""}`,children:(0,q.jsxs)("div",{className:`quick-order-card${l?"":" quick-order-card--customer"}`,children:[(0,q.jsxs)("div",{className:`quick-order-hero${l?"":" quick-order-hero--customer"}`,children:[l&&(0,q.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,q.jsxs)("div",{className:"basket-hero-copy",children:[p&&(0,q.jsxs)("button",{type:"button",className:"cta-btn cta-btn-secondary basket-hero-back",onClick:i,children:[(0,q.jsx)(Zr,{}),(0,q.jsx)("span",{children:"Back to results"})]}),(0,q.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,q.jsx)("h1",{children:l?"Your Selection":p?"Request a quote":"Your Basket"}),l&&(0,q.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,q.jsx)("strong",{children:f.length})," ",f.length===1?"item":"items"]})]}),(0,q.jsx)("p",{children:l?"Review the items you've added before exporting them for review.":p?"Check your items & quantities below, and we'll do our best to beat list prices.":"Review your quantities and order summary before you buy."})]})]}),(0,q.jsx)("div",{className:"quick-order-panel",style:{paddingTop:16},children:f.length===0?(0,q.jsxs)("div",{className:"quick-order-history-empty",children:[(0,q.jsx)("div",{className:"basket-empty-icon","aria-hidden":"true",children:l?"\u{1F4CB}":"\u{1F9FA}"}),(0,q.jsx)("p",{children:l?"Your selection is empty.":p?"Your quote request is empty.":"Your basket is empty."}),(0,q.jsx)("p",{className:"basket-empty-hint",children:p?"Go back to your results and add items for your quote.":"Go back to your results and add quoted items."}),(0,q.jsx)("div",{className:"btn-row",style:{marginTop:20,justifyContent:"center"},children:(0,q.jsx)("button",{className:"cta-btn",style:{width:"auto",maxWidth:280},onClick:i,"aria-label":"Back to results",children:(0,q.jsx)("span",{children:"Back to Results"})})})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)("div",{className:"basket-layout",children:[(0,q.jsxs)("div",{className:"basket-main",children:[(0,q.jsx)("div",{className:"basket-list","aria-label":l?"Selection items":p?"Quote request items":"Basket items",children:M.map(({item:x,pricing:A})=>{let I=v[x.lineId]??String(A.requestedAmount),ce=A.requestedUnit===A.sellUnit||A.costingMode==="review",me=A.requiredSellUnits==null||A.requestedAmount!==A.requiredSellUnits||A.requestedUnit!==A.sellUnit;return(0,q.jsxs)("article",{className:"basket-card",children:[(0,q.jsxs)("div",{className:"basket-card-top",children:[(0,q.jsx)("img",{className:"basket-card-thumb",src:Qa(x.description,x.productId,x.pdpPhotoUrl),alt:"",width:48,height:48}),(0,q.jsxs)("div",{className:"basket-card-info",children:[(0,q.jsx)("div",{className:"bom-component-name",children:x.description}),me&&A.costingMode!=="review"&&(0,q.jsxs)("button",{type:"button",className:"basket-calc-toggle",onClick:()=>xe(ke=>({...ke,[x.lineId]:!ke[x.lineId]})),"aria-expanded":!!K[x.lineId],children:["How we calculated this",(0,q.jsx)("span",{className:`basket-calc-toggle-chevron${K[x.lineId]?" basket-calc-toggle-chevron--open":""}`,children:(0,q.jsx)(al,{})})]})]}),(0,q.jsx)("div",{className:"basket-card-actions",children:(0,q.jsx)("button",{type:"button",className:"mf-remove-small-btn basket-card-remove",onClick:()=>n(x.lineId),"aria-label":`Remove ${x.description}`,children:(0,q.jsx)(y_,{})})})]}),l&&(0,q.jsxs)("div",{className:"results-detail-block basket-internal-detail",children:[(0,q.jsxs)("dl",{className:"results-detail-grid",children:[(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Conversion type"}),(0,q.jsx)("dd",{children:x.conversionType??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Conversion confidence"}),(0,q.jsx)("dd",{children:x.conversionConfidence??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Sales unit"}),(0,q.jsx)("dd",{children:x.salesUnitSize!=null?(0,q.jsxs)(q.Fragment,{children:[x.salesUnitSize," ",ka(x.salesUnitSizeUom,x.salesUnitSize)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Coverage"}),(0,q.jsx)("dd",{children:x.coverageQty!=null?(0,q.jsxs)(q.Fragment,{children:[x.coverageQty," ",ka(x.coverageUom,x.coverageQty)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Waste factor"}),(0,q.jsx)("dd",{children:x.wasteFactorDefault??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Rounding rule"}),(0,q.jsx)("dd",{children:x.roundingRule??"-"})]})]}),x.conversionNotes&&(0,q.jsx)("p",{className:"results-rerank-note",children:x.conversionNotes})]}),A.costingMode==="review"?(0,q.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,q.jsx)("strong",{children:"Quantity needs confirmation."})," ",w_(A)]}):me&&K[x.lineId]?(0,q.jsx)("p",{className:"basket-calc-text",children:v_(x,A)}):null,(0,q.jsxs)("div",{className:"basket-card-stats",children:[(0,q.jsxs)("div",{className:"basket-stat",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Requested qty"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsxs)("div",{className:"basket-qty-field",children:[(0,q.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:I,disabled:ce,onChange:ke=>N(k=>({...k,[x.lineId]:ke.target.value})),onBlur:ke=>se(x.lineId,ke.target.value),onKeyDown:ke=>{ke.key==="Enter"&&ke.target.blur()},"aria-label":`${x.description} requested quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",disabled:ce,onClick:()=>Ne(x.lineId,parseFloat(I)||0,1),"aria-label":`Increase ${x.description} quantity`,children:(0,q.jsx)(al,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",disabled:ce,onClick:()=>Ne(x.lineId,parseFloat(I)||0,-1),"aria-label":`Decrease ${x.description} quantity`,children:(0,q.jsx)(al,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:ka(A.requestedUnit,parseFloat(I)||0)})]})]}),(0,q.jsxs)("div",{className:"basket-stat basket-stat--right",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Order qty"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsxs)("div",{className:"basket-qty-field",children:[(0,q.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:R[x.lineId]??String(A.requiredSellUnits??""),onChange:ke=>T(k=>({...k,[x.lineId]:ke.target.value})),onBlur:ke=>Ye(x.lineId,ke.target.value),onKeyDown:ke=>{ke.key==="Enter"&&ke.target.blur()},"aria-label":`${x.description} order quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",onClick:()=>ge(x.lineId,parseFloat(R[x.lineId]??String(A.requiredSellUnits??"0"))||0,1),"aria-label":`Increase ${x.description} order quantity`,children:(0,q.jsx)(al,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",onClick:()=>ge(x.lineId,parseFloat(R[x.lineId]??String(A.requiredSellUnits??"0"))||0,-1),"aria-label":`Decrease ${x.description} order quantity`,children:(0,q.jsx)(al,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:ka(A.sellUnit,parseFloat(R[x.lineId]??String(A.requiredSellUnits??"0"))||0)})]})]}),(0,q.jsxs)("div",{className:"basket-stat basket-stat--total",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Total"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsx)("strong",{children:A.lineTotal!=null?st(A.lineTotal):"-"}),A.lineTotal!=null&&(0,q.jsx)("span",{className:"basket-metric-unit",children:"ex. VAT"})]})]})]})]},x.lineId)})}),et>1&&(0,q.jsxs)("div",{className:"results-pagination",children:[(0,q.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(Ze-1)*tl+1,"\u2013",Math.min(Ze*tl,he.length)," of ",he.length]}),(0,q.jsxs)("div",{className:"results-pagination-controls",children:[(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>G(Ze-1),disabled:Ze===1,children:"Previous"}),(0,q.jsxs)("span",{className:"results-pagination-page",children:["Page ",Ze," of ",et]}),(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>G(Ze+1),disabled:Ze===et,children:"Next"})]})]})]}),(0,q.jsxs)("aside",{className:"basket-sidebar",children:[(0,q.jsx)("div",{className:"basket-sidebar-title",children:p?"Quote request summary":"Order summary"}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:p?"List price (ex. VAT)":"Subtotal (ex. VAT)"}),(0,q.jsx)("span",{children:st(W)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:"VAT (20%)"}),(0,q.jsx)("span",{children:st(ze)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row basket-sidebar-row--total",children:[(0,q.jsx)("span",{children:p?"List price (inc. VAT)":"Total"}),(0,q.jsx)("span",{children:st(Be)})]}),!p&&(0,q.jsx)("div",{className:"basket-summary-waste",children:(0,q.jsxs)("div",{className:"basket-waste-control",children:[(0,q.jsxs)("label",{className:"basket-global-waste",children:[(0,q.jsx)("input",{type:"checkbox",checked:Ee,onChange:x=>Ge(x.target.checked)}),(0,q.jsx)("span",{children:"Add waste factor"})]}),(0,q.jsxs)("label",{className:"basket-global-waste-percent",children:[(0,q.jsx)("input",{type:"number",inputMode:"decimal",min:"0",step:"0.1",value:Qe,onChange:x=>Ie(x.target.value),disabled:!Ee,"aria-label":"Waste factor percent"}),(0,q.jsx)("span",{children:"%"})]})]})}),(0,q.jsx)("label",{htmlFor:`${c}-basket-reference`,className:"basket-sidebar-label",children:p?"Enter email for your sharper quote":"Your reference (optional)"}),(0,q.jsx)("input",{id:`${c}-basket-reference`,type:p?"email":"text",className:"basket-sidebar-input",value:b,onChange:x=>{d(x.target.value),p&&g("")},placeholder:p?"you@example.com":"PO number or job reference","aria-invalid":p&&u===ow,"aria-describedby":p&&u?`${c}-basket-reference-error`:void 0}),p&&u&&(0,q.jsx)("p",{id:`${c}-basket-reference-error`,className:"basket-quote-request-error",role:"alert",children:u}),p?(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:()=>{We()},disabled:E,"aria-busy":E,children:(0,q.jsx)("span",{children:E?"Sending\u2026":"Request our best quote"})}):(0,q.jsx)("button",{className:"cta-btn",onClick:()=>{m("downloaded",{type:"basket",items:f.length}),tw(f)},"aria-label":l?"Download selection":"Download basket",children:(0,q.jsx)("span",{children:l?"Download Quote":"Buy Now"})}),(0,q.jsxs)("p",{className:"basket-sidebar-disclaimer",children:[(0,q.jsx)("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),p?"This is a quote request, not an order. We'll confirm our best price, availability and delivery before you approve.":"Prices and availability are estimates and should be confirmed before procurement."]})]})]}),(0,q.jsx)("div",{className:"btn-row results-actions",children:(0,q.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",gap:10,justifyContent:"center"},onClick:i,"aria-label":"Back to results",children:[(0,q.jsx)(Zr,{}),(0,q.jsx)("span",{children:"Back to results"})]})})]})})]})})}var zt=Y(Ke()),lw=Y(ae());function __(e,t){let a={...e,[t.lineId]:t};for(let[r,n]of Object.entries(a)){if(!n.linkedContext)continue;let i=n.linkedContext.find(l=>l.role==="anchor"&&l.line_id&&a[l.line_id]),o=i?.line_id?a[i.line_id]:void 0;if(!(!i||!o||i.product_id===o.productId&&i.description===o.description)){if(n.conversionType!=="basket_line_unit"){a[r]={...n,linkedContext:n.linkedContext.map(l=>l.line_id===i.line_id?{...l,product_id:o.productId,measurements_mm:o.measurementsMm??[],description:o.description}:l)};continue}a[r]={...n,qty:0,sellUnitsOverride:null,linkedContext:n.linkedContext.map(l=>l.line_id===i.line_id?{...l,product_id:o.productId,measurements_mm:o.measurementsMm??[],description:o.description}:l),conversionType:null,requestUomsSupported:null,salesUomNormalised:null,salesUnitSize:null,salesUnitSizeUom:null,coverageQty:null,coverageUom:null,roundingRule:null,conversionConfidence:null,conversionNotes:null}}}return a}var vd=(0,zt.createContext)(null);function Js({children:e,onOpenBasket:t}){let[a,r]=(0,zt.useState)({}),n=(0,zt.useCallback)(d=>{r(h=>__(h,d))},[]),i=(0,zt.useCallback)(d=>{r(h=>{let w={...h};for(let E of d)w[E.lineId]=E;return w})},[]),o=(0,zt.useCallback)(d=>{r(h=>{let w={...h};return delete w[d],w})},[]),l=(0,zt.useCallback)((d,h)=>{r(w=>w[d]?{...w,[d]:{...w[d],qty:h,sellUnitsOverride:null}}:w)},[]),c=(0,zt.useCallback)((d,h)=>{r(w=>w[d]?{...w,[d]:{...w[d],sellUnitsOverride:h}}:w)},[]),p=(0,zt.useCallback)(d=>{r(h=>{let w=!1,E={...h};for(let[D,m]of Object.entries(d))E[D]&&(E[D]={...E[D],...m},w=!0);return w?E:h})},[]),f=(0,zt.useCallback)(()=>r({}),[]),b=(0,zt.useMemo)(()=>({cart:a,count:Object.keys(a).length,addToCart:n,addManyToCart:i,removeFromCart:o,updateCartQty:l,updateCartSellUnits:c,updateCartConversions:p,clearCart:f,openBasket:t??(()=>{})}),[a,n,i,o,l,c,p,f,t]);return(0,lw.jsx)(vd.Provider,{value:b,children:e})}function An(){let e=(0,zt.useContext)(vd);if(!e)throw new Error("useCart must be used inside a <CartProvider>");return e}function Fs(){return(0,zt.useContext)(vd)}var Na=Y(ae()),wd="metron-quick-quote";function Is(e){return(0,Na.jsx)(Js,{children:(0,Na.jsx)(x_,{...e})})}function x_({fullPage:e=!1,hideHeader:t=!1,internal:a=!1}){let[r,n]=(0,He.useState)("entry"),[i,o]=(0,He.useState)(null),[l,c]=(0,He.useState)(""),p=(0,He.useRef)(null),[f,b]=(0,He.useState)(0),[d,h]=(0,He.useState)(null),[w,E]=(0,He.useState)(!1),{cart:D,addToCart:m,addManyToCart:u,removeFromCart:g,updateCartQty:v,updateCartSellUnits:N,updateCartConversions:R,clearCart:T}=An(),[z,G]=(0,He.useState)(!1),K=(0,He.useRef)(new Map),xe=(0,He.useRef)(null),Ee=Gs("quick-quote",xe);(0,He.useEffect)(()=>{Ee("viewed")},[Ee]),(0,He.useEffect)(()=>{for(let W of Object.values(D))Ut(W).requiredSellUnits!=null&&K.current.delete(W.lineId);let he=Object.values(D).filter(W=>{if(W.productId==="-"||Ut(W).requiredSellUnits!=null)return!1;let ze=`${W.productId}|${W.qty}|${W.unit}`;return K.current.get(W.lineId)===ze?!1:(K.current.set(W.lineId,ze),!0)});he.length!==0&&fetch(Lt("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({lines:he.map(W=>({line_id:W.lineId,product_id:W.productId,requested_description:W.requestedDescription??W.description,requested_qty:W.qty,requested_uom:W.unit||null,selected_description:W.description,selected_uoi:W.uoi,selected_uoi_count:W.uoiCount,linked_context:W.linkedContext??[],selected_conversion:{sales_uom_normalised:W.salesUomNormalised,conversion_type:W.conversionType,sales_unit_size:W.salesUnitSize,sales_unit_size_uom:W.salesUnitSizeUom,coverage_qty:W.coverageQty,coverage_uom:W.coverageUom}}))})}).then(W=>W.ok?Kt(W):null).then(W=>{let ze={};for(let Be of W?.data?.items??W?.items??[]){let ve=Be?.conversion;if(!ve||typeof Be?.line_id!="string")continue;let et=D[Be.line_id];ze[Be.line_id]={conversionType:ve.conversion_type,requestUomsSupported:ve.request_uoms_supported,salesUomNormalised:ve.sales_uom_normalised,salesUnitSize:ve.sales_unit_size,salesUnitSizeUom:ve.sales_unit_size_uom,coverageQty:ve.coverage_qty,coverageUom:ve.coverage_uom,roundingRule:ve.rounding_rule,conversionConfidence:ve.conversion_confidence,conversionNotes:ve.conversion_notes,...et?.qty===0&&Number.isFinite(ve.suggested_order_qty)&&ve.suggested_order_qty>0?{qty:ve.suggested_order_qty,unit:ve.suggested_order_uom||et.unit}:{}}}Object.keys(ze).length>0&&R(ze)}).catch(W=>console.error("Catalogue conversion resolution failed",W))},[D,R]);let[Ge,Qe]=(0,He.useState)(!1);(0,He.useEffect)(()=>{let he=window.location.hash,W=null;try{W=JSON.parse(window.sessionStorage.getItem(wd)??"null")}catch{}if(W?.scheduleResult)o("schedule"),h(W.scheduleResult),E(W.reviewGateComplete),G(W.cartSeeded),u(Object.values(W.cart)),he==="#quote-request"?n("basket"):he==="#matched-products"&&n("results");else if(he==="#matched-products"||he==="#quote-request"){let ze=new URL(window.location.href);ze.hash="",window.history.replaceState(window.history.state,"",ze)}Qe(!0)},[]),(0,He.useEffect)(()=>{if(Ge)try{d?window.sessionStorage.setItem(wd,JSON.stringify({scheduleResult:d,reviewGateComplete:w,cartSeeded:z,cart:D})):window.sessionStorage.removeItem(wd)}catch{}},[Ge,d,w,z,D]);let Ie=(0,He.useCallback)(he=>{if(typeof window>"u")return;let W=new URL(window.location.href);W.hash=he==="basket"?"quote-request":"matched-products";let ze=he==="results"&&(window.location.hash==="#matched-products"||window.location.hash==="#quote-request");window.history[ze?"replaceState":"pushState"]({boqQuoteStage:he},"",W)},[]),ue=(0,He.useRef)(!1);(0,He.useEffect)(()=>{let he=W=>{ue.current=!1;let ze=window.location.hash;n(ze==="#quote-request"?"basket":ze==="#matched-products"&&d?"results":"entry");let Be=W.state,ve=window.location.href;setTimeout(()=>{if(window.location.href===ve){if(ze==="#quote-request"||ze==="#matched-products"){window.history.replaceState({boqQuoteStage:ze==="#quote-request"?"basket":"results"},"",ve);return}!Be?.turbo&&window.history.state?.turbo&&window.history.replaceState(Be,"",ve)}})};return window.addEventListener("popstate",he),()=>window.removeEventListener("popstate",he)},[d]);let Q=(0,He.useCallback)(()=>{Ie("basket"),n("basket")},[Ie]),se=(0,He.useCallback)(()=>{if(window.location.hash==="#quote-request"){if(ue.current)return;ue.current=!0,window.history.back();return}n(d?"results":"entry")},[d]),Ne=(0,He.useRef)(r);(0,He.useEffect)(()=>{Ne.current!==r&&(Ne.current=r,window.scrollTo(0,0))},[r]);let lt=()=>{n("entry"),o(null),c(""),b(0),h(null),E(!1),T(),G(!1)},Ye=(0,He.useCallback)(async(he,W,ze=!0)=>{c(""),b(0);let Be=0,ve=()=>{Be=Math.min(Be+1,3),b(Be)};try{let{jobId:et}=await ev(he,W,ze),{promise:Ze,cancel:M}=av(()=>tv(et),5e3,ve,"schedule");p.current=M;let x=await Ze;if(x.status==="failed"||!x.result)throw new Error(x.error||"Failed to process schedule");let A=x.result.lineItems.length,I=x.result.results.filter(ce=>ce.candidates.length>0).length;Ee("results_shown",{lines:A,matched:I,unmatched:A-I}),E(!1),h(x.result),Ie("results"),n("results")}catch(et){Ee("error",{stage:"matching"}),c(et?.message||"Failed to process schedule"),n("entry")}finally{p.current?.(),p.current=null}},[Ie,Ee]),ge=(0,He.useCallback)(async(he,W,ze=!0)=>{let Be=he.trim();if(!Be)return;o("schedule");let ve=new File([Be],"pasted-schedule.txt",{type:"text/plain"});await Ye(ve,W,ze)},[Ye]),We=(0,He.useCallback)(async he=>{o("schedule"),await Ye(he)},[Ye]);return(0,Na.jsx)(Zo.Provider,{value:Ee,children:(0,Na.jsx)("div",{ref:xe,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${!e&&r==="processing"?" app-wrapper--loading":""}`,style:pr().theme,children:(0,Na.jsxs)("main",{className:"main-content",children:[l&&(0,Na.jsxs)("div",{className:"error-box",role:"alert",children:[(0,Na.jsx)("strong",{children:"Error:"})," ",l]}),r==="entry"&&(0,Na.jsx)(ud,{onPasteSchedule:ge,onUploadSchedule:We,onEntryModeChange:o}),r==="results"&&i==="schedule"&&d&&(0,Na.jsx)(bd,{scheduleResult:d,onStartOver:lt,cart:D,onAddToCart:m,onRemoveFromCart:g,onGoToBasket:Q,cartSeeded:z,onCartSeeded:()=>G(!0),reviewGateComplete:w,onReviewGateComplete:()=>E(!0),internal:a}),r==="basket"&&(0,Na.jsx)(rl,{cart:D,onUpdateQty:v,onUpdateSellUnits:N,onRemove:g,onBack:se,onStartNewQuote:lt,internal:a})]})})})}var Va=Y(Ke());var ki=Y(Ke()),te=Y(ae()),sw=[{id:"ogee",label:"Ogee",blurb:"Traditional curved profile"},{id:"torus",label:"Torus",blurb:"Soft rounded detail"},{id:"ovolo",label:"Ovolo",blurb:"Traditional rounded profile"},{id:"pencil-round",label:"Pencil round",blurb:"Simple softened edge"},{id:"square-edge",label:"Square edge",blurb:"Clean contemporary edge"}],Ws=e=>Number.parseFloat(e)||0,cw=(e,t)=>Ws(e)*(t==="m"?1:.3048),yd=(e,t)=>Ws(e.quantity)*(2*cw(e.height,t)+cw(e.width,t)),k_=()=>({quantity:"1",width:"",height:""});function N_({profile:e}){return(0,te.jsxs)("svg",{className:"architrave-calculator__profile-diagram",viewBox:"0 0 112 76","aria-hidden":"true",children:[(0,te.jsx)("path",{d:{ogee:"M18 62 V38 C18 28 28 22 40 22 H78 C88 22 94 28 94 38 V62",torus:"M18 62 V40 C18 27 30 20 42 20 C54 20 58 30 66 30 C74 30 78 20 90 20 C102 20 94 34 94 40 V62",ovolo:"M18 62 V38 C18 28 30 20 42 20 H70 C82 20 94 28 94 38 V62","pencil-round":"M18 62 V38 C18 28 28 20 40 20 H72 C84 20 94 28 94 38 V62","square-edge":"M18 62 V20 H94 V62"}[e]}),(0,te.jsx)("line",{x1:"12",y1:"66",x2:"100",y2:"66"})]})}function _d({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,ki.useState)("m"),[i,o]=(0,ki.useState)({quantity:"1",width:"0.76",height:"1.98"}),[l,c]=(0,ki.useState)({quantity:"0",width:"1.52",height:"1.98"}),[p,f]=(0,ki.useState)([]),[b,d]=(0,ki.useState)("ogee"),[h,w]=(0,ki.useState)("2.4"),E=(N,R,T)=>{N(z=>({...z,[R]:T}))},D=yd(i,r)+yd(l,r)+p.reduce((N,R)=>N+yd(R,r),0),m=Ws(h)>0?Math.ceil(D/Ws(h)):0,u=sw.find(N=>N.id===b)?.label??"",g=[{key:`architrave-${b}`,label:`Architrave (${u})`,qty:D,unit:"m",query:`${u} architrave`,category:"architrave"}],v=(N,R,T,z)=>(0,te.jsxs)("div",{className:"architrave-calculator__opening-row",children:[(0,te.jsx)("span",{children:N}),(0,te.jsx)("input",{"aria-label":`${N} quantity`,type:"number",min:"0",step:"1",value:R.quantity,onChange:G=>T("quantity",G.target.value)}),(0,te.jsx)("input",{"aria-label":`${N} width`,type:"number",min:"0",step:"0.01",value:R.width,onChange:G=>T("width",G.target.value)}),(0,te.jsx)("input",{"aria-label":`${N} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:G=>T("height",G.target.value)}),z?(0,te.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:z,children:"Remove"}):null]});return(0,te.jsx)(te.Fragment,{children:(0,te.jsxs)("div",{className:"truss-estimator",children:[(0,te.jsxs)("div",{className:"quick-order-hero",children:[(0,te.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,te.jsx)("h1",{children:"Architrave Calculator"}),(0,te.jsx)("p",{children:"Estimate architrave lengths and board quantities for door openings."})]}),(0,te.jsxs)("div",{className:"truss-estimator__card architrave-calculator",children:[(0,te.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure your openings"}),(0,te.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter each door or window opening. Mitred corners are allowed for, and board lengths are worked out from the net run."}),(0,te.jsxs)("div",{className:"architrave-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Door openings"}),(0,te.jsx)("p",{className:"architrave-calculator__hint",children:"Each opening is calculated as two side pieces plus one head piece."}),(0,te.jsxs)("div",{className:"architrave-calculator__unit-row",children:[(0,te.jsx)("span",{children:"Units"}),(0,te.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,te.jsx)("button",{type:"button",className:r==="m"?"is-selected":"",onClick:()=>n("m"),children:"Metres"}),(0,te.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>n("ft"),children:"Feet"})]})]}),(0,te.jsxs)("div",{className:"architrave-calculator__dimensions-header",children:[(0,te.jsx)("span",{children:"Opening"}),(0,te.jsx)("span",{children:"Qty"}),(0,te.jsxs)("span",{children:["Width (",r,")"]}),(0,te.jsxs)("span",{children:["Height (",r,")"]}),(0,te.jsx)("span",{})]}),v("Single doors",i,(N,R)=>E(o,N,R)),v("Double doors",l,(N,R)=>E(c,N,R)),p.map((N,R)=>v(`Alternative door ${R+1}`,N,(T,z)=>f(G=>G.map((K,xe)=>xe===R?{...K,[T]:z}:K)),()=>f(T=>T.filter((z,G)=>G!==R)))),(0,te.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>f(N=>[...N,k_()]),children:"+ Add alternative-sized door"})]}),(0,te.jsxs)("div",{className:"architrave-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Standard profile"}),(0,te.jsx)("p",{className:"architrave-calculator__hint",children:"Choose the profile you plan to use. Length calculations are the same for each profile."}),(0,te.jsx)("div",{className:"architrave-calculator__profiles",children:sw.map(N=>(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${b===N.id?" is-selected":""}`,onClick:()=>d(N.id),children:[(0,te.jsx)(N_,{profile:N.id}),(0,te.jsx)("div",{className:"truss-estimator__option-title",children:N.label}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:N.blurb})]},N.id))})]}),(0,te.jsxs)("div",{className:"architrave-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,te.jsx)("div",{className:"architrave-calculator__options",children:(0,te.jsxs)("label",{className:"truss-estimator__field",children:[(0,te.jsx)("span",{children:"Board length (m)"}),(0,te.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,te.jsx)("p",{className:"architrave-calculator__hint",children:"Waste allows for mitred corners, cuts and damaged lengths."})]}),(0,te.jsxs)("div",{className:"architrave-calculator__totals",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,te.jsxs)("div",{className:"architrave-calculator__result-grid",children:[(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Architrave needed"}),(0,te.jsxs)("strong",{children:[D.toFixed(2)," m"]})]}),(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Board lengths"}),(0,te.jsx)("strong",{children:m})]})]})]}),(0,te.jsxs)("div",{className:"architrave-calculator__actions",children:[(0,te.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,te.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(g),disabled:D<=0,children:a})]})]})]})})}var Ni=Y(Ke()),le=Y(ae()),uw=60,pw=10,S_=.02,C_=.012,q_=.01,Rn=e=>Number.parseFloat(e)||0,E_=(e,t=2)=>e.toFixed(t);function xd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Ni.useState)("brick"),[i,o]=(0,Ni.useState)("engineering-red"),[l,c]=(0,Ni.useState)("metric"),[p,f]=(0,Ni.useState)(""),[b,d]=(0,Ni.useState)(""),[h,w]=(0,Ni.useState)(!0),E=l==="metric"?Rn(p)*Rn(b):Rn(p)*Rn(b)*.092903,m=E*(r==="brick"?uw:pw),u=Math.ceil(m),g=E*(r==="brick"?S_:C_),v=Math.ceil(g/q_),N=l==="metric"?E:E*10.7639,R=[{key:r==="brick"?`brick-${i}`:"block",label:r==="brick"?{common:"Common concrete bricks","engineering-red":"Red engineering bricks","engineering-blue":"Blue engineering bricks"}[i]:"Blocks",qty:u,unit:"each",query:r==="brick"?"facing brick":"concrete block",category:"masonry"},...h?[{key:"mortar",label:"Blue Circle Quality Assured Mortar Mix 20kg",qty:v,unit:"bag",query:"ready mixed mortar",category:"mortar"}]:[]],T=z=>{if(z===l)return;let G=z==="imperial"?3.28084:.3048;f((Rn(p)*G).toFixed(2)),d((Rn(b)*G).toFixed(2)),c(z)};return(0,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"truss-estimator",children:[(0,le.jsxs)("div",{className:"quick-order-hero",children:[(0,le.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,le.jsx)("h1",{children:"Brick & Block Calculator"}),(0,le.jsx)("p",{children:"Estimate masonry units, sand and cement for a wall."})]}),(0,le.jsxs)("div",{className:"truss-estimator__card brick-calculator",children:[(0,le.jsx)("h2",{className:"truss-estimator__step-title",children:"Wall area and masonry type"}),(0,le.jsx)("p",{className:"truss-estimator__step-sub",children:"Pick brick or block and enter the wall dimensions for unit counts plus ready-mixed mortar."}),(0,le.jsxs)("div",{className:"brick-calculator__section",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Masonry type"}),(0,le.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["brick","Brick"],["block","Block"]].map(([z,G])=>(0,le.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===z?" is-selected":""}`,onClick:()=>n(z),children:[(0,le.jsx)("div",{className:"truss-estimator__option-title",children:G}),(0,le.jsxs)("div",{className:"truss-estimator__option-copy",children:["Approx. ",z==="brick"?uw:pw," per m\xB2"]})]},z))})]}),r==="brick"&&(0,le.jsxs)("div",{className:"brick-calculator__section",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Brick type"}),(0,le.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:[["common","Common concrete","General-purpose grey concrete brick"],["engineering-red","Engineering red","Class B perforated, 65mm"],["engineering-blue","Engineering blue","Class B solid, 65mm"]].map(([z,G,K])=>(0,le.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i===z?" is-selected":""}`,onClick:()=>o(z),children:[(0,le.jsx)("div",{className:"truss-estimator__option-title",children:G}),(0,le.jsx)("div",{className:"truss-estimator__option-copy",children:K})]},z))})]}),(0,le.jsxs)("div",{className:"brick-calculator__section",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,le.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,le.jsx)("button",{type:"button",className:l==="metric"?"is-selected":"",onClick:()=>T("metric"),children:"Metric"}),(0,le.jsx)("button",{type:"button",className:l==="imperial"?"is-selected":"",onClick:()=>T("imperial"),children:"Imperial"})]}),(0,le.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsxs)("span",{children:["Height (",l==="metric"?"m":"ft",")"]}),(0,le.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:z=>f(z.target.value)})]}),(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsxs)("span",{children:["Width (",l==="metric"?"m":"ft",")"]}),(0,le.jsx)("input",{type:"number",min:"0",step:"0.01",value:b,onChange:z=>d(z.target.value)})]})]})]}),(0,le.jsx)("div",{className:"brick-calculator__options",children:(0,le.jsxs)("label",{className:"brick-calculator__checkbox",children:[(0,le.jsx)("input",{type:"checkbox",checked:h,onChange:z=>w(z.target.checked)}),(0,le.jsx)("span",{children:"Include ready-mixed mortar"})]})}),(0,le.jsxs)("div",{className:"brick-calculator__totals",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,le.jsxs)("div",{className:"brick-calculator__result-grid",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{children:"Wall area"}),(0,le.jsxs)("strong",{children:[E_(N)," ",l==="metric"?"m\xB2":"ft\xB2"]})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{children:r==="brick"?"Bricks":"Blocks"}),(0,le.jsx)("strong",{children:u.toLocaleString("en-GB")})]}),h?(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{children:"Ready-mixed mortar"}),(0,le.jsxs)("strong",{children:[v," x 20kg bags"]})]}):null]}),(0,le.jsx)("p",{className:"brick-calculator__note",children:"Estimate based on standard nominal sizes and 10mm joints. Mortar bags are approximate; confirm the required mortar specification before ordering."})]}),(0,le.jsxs)("div",{className:"brick-calculator__actions",children:[(0,le.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,le.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(R),disabled:E<=0,children:a})]})]})]})})}var fr=Y(Ke());var dw=new Map;function M_(e){return{product_id:e.product_id,description:e.description,source_list:e.source_list??null,price:e.price??null,list_price:e.list_price,discount:e.discount,price_basis:e.price_basis??null,uoi_count:e.uoi_count??null,uoi:e.uoi??null,pdp_photo_url:e.pdp_photo_url??null,conversion:e.conversion,measurements_mm:e.measurements_mm??e.attrs?.measurements_mm??[],scores:{dimension:0,grade:0,brand:0,fuzzy:0,bm25:0,overall:0},method:"estimator_catalogue_search"}}async function Jr(e,t,a=12,r){let n=`${e}||${t??""}||${a}||${r??""}`,i=dw.get(n);if(i)return i;let o=new URLSearchParams({q:e,limit:String(a)});t&&o.set("category",t),r&&o.set("account",r);let l=await fetch(Lt(`/api/catalogue/search?${o.toString()}`),{headers:wi()}),c=await Kt(l);if(!l.ok)throw new Error(c?.error||c?.message||"Could not reach the product catalogue");let p=Array.isArray(c?.items)?c.items.map(M_):[];return dw.set(n,p),p}async function mw(e,t){return await Promise.all(e.map(async r=>{try{return{requirement:r,candidates:await Jr(r.query,r.category,void 0,t)}}catch{return{requirement:r,candidates:[]}}}))}async function fw(){let e=await fetch(Lt("/api/catalogue"),{headers:wi()});if(!e.ok)return{itemCount:0,uploadedAt:null};let t=await Kt(e);return{itemCount:Number(t?.itemCount)||0,uploadedAt:t?.uploadedAt??null}}var $=Y(ae()),T_=1.54,z_=1440,A_=25,kd=800,R_=1500,Nd=e=>Number.parseFloat(e)||0,Un={mot:{label:"MOT Type 1",blurb:"Sub-base for patios and driveways",density:1.7,productId:"6001007"},"sharp-sand":{label:"Sharp sand",blurb:"Bedding and general groundwork",density:1.6,productId:"6001012"},gravel:{label:"20mm gravel",blurb:"Drainage and landscaping",density:1.6,productId:"6001004"}};function Sd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let r=Fs(),[n,i]=(0,fr.useState)("m"),[o,l]=(0,fr.useState)(""),[c,p]=(0,fr.useState)(""),[f,b]=(0,fr.useState)(""),[d,h]=(0,fr.useState)("concrete"),[w,E]=(0,fr.useState)("mot"),[D,m]=(0,fr.useState)(!1),[u,g]=(0,fr.useState)(null),v=n==="m"?1:.3048,N=Nd(o)*v*Nd(c)*v*Nd(f)*(n==="m"?.01:.0254),R=Un[w],T=N*T_/7,z=T*z_,G=T*2,K=T*4,xe=Math.ceil(z/A_),Ee=Math.ceil(G*Un["sharp-sand"].density*1e3/kd),Ge=Math.ceil(K*Un.gravel.density*1e3/kd),Qe=Math.ceil(N*R.density*1e3/kd),Ie=d==="concrete"?[{key:"cement",label:"Blue Circle General Purpose Grey Cement 25kg",qty:xe,productId:"6003004"},{key:"sharp-sand",label:"Sharp Sand Bulk Bag (800kg)",qty:Ee,productId:"6001012"},{key:"gravel",label:"20mm Non Decorative Pea Shingle/Gravel Bulk Bag (800kg)",qty:Ge,productId:"6001004"}]:[{key:w,label:`${R.label} Bulk Bag (800kg)`,qty:Qe,productId:R.productId}],ue=()=>{if(t){t(Ie.map(se=>({key:se.key,label:se.label,qty:se.qty,unit:"each",query:se.productId})));return}Q()},Q=async()=>{let se=Date.now();m(!0),g(null);try{let Ne=await Promise.all(Ie.map(async Ye=>{let ge=(await Jr(Ye.productId)).find(We=>We.product_id===Ye.productId);if(!ge)throw new Error(`${Ye.label} is no longer available in this catalogue.`);return Kr(ge,{lineId:`concrete-aggregate:${Ye.key}`,description:Ye.label,unit:"bag",qty:Ye.qty})})),lt=R_-(Date.now()-se);lt>0&&await new Promise(Ye=>window.setTimeout(Ye,lt)),r?.clearCart(),r?.addManyToCart(Ne),r?.openBasket()}catch(Ne){g(Ne instanceof Error?Ne.message:"Could not add the products to your basket.")}finally{m(!1)}};return D?(0,$.jsx)($.Fragment,{children:(0,$.jsxs)("div",{className:"truss-estimator",children:[(0,$.jsxs)("div",{className:"quick-order-hero",children:[(0,$.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,$.jsx)("h1",{children:"Your Materials"}),(0,$.jsx)("p",{children:"Calculating quantities from the Concrete & Aggregate Calculator."})]}),(0,$.jsx)("div",{className:"truss-estimator__card",children:(0,$.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,$.jsx)(dr,{}),(0,$.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})}):(0,$.jsx)($.Fragment,{children:(0,$.jsxs)("div",{className:"truss-estimator",children:[(0,$.jsxs)("div",{className:"quick-order-hero",children:[(0,$.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,$.jsx)("h1",{children:"Concrete & Aggregate Calculator"}),(0,$.jsx)("p",{children:"Calculate fixed site-mix concrete ingredients or aggregate bulk bags."})]}),(0,$.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,$.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose what you need"}),(0,$.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter the area and depth. The calculator adds the fixed Materials Market products directly to your basket."}),(0,$.jsxs)("div",{className:"materials-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Material type"}),(0,$.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,$.jsxs)("button",{type:"button",className:`truss-estimator__option-card${d==="concrete"?" is-selected":""}`,onClick:()=>h("concrete"),children:[(0,$.jsx)("div",{className:"truss-estimator__option-title",children:"Site-mixed concrete"}),(0,$.jsx)("div",{className:"truss-estimator__option-copy",children:"Cement, sharp sand and 20mm aggregate"})]}),(0,$.jsxs)("button",{type:"button",className:`truss-estimator__option-card${d==="aggregate"?" is-selected":""}`,onClick:()=>h("aggregate"),children:[(0,$.jsx)("div",{className:"truss-estimator__option-title",children:"Aggregates"}),(0,$.jsx)("div",{className:"truss-estimator__option-copy",children:"MOT Type 1, sharp sand or 20mm gravel"})]})]})]}),d==="aggregate"&&(0,$.jsxs)("div",{className:"materials-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Aggregate type"}),(0,$.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.keys(Un).map(se=>(0,$.jsxs)("button",{type:"button",className:`truss-estimator__option-card${w===se?" is-selected":""}`,onClick:()=>E(se),children:[(0,$.jsx)("div",{className:"truss-estimator__option-title",children:Un[se].label}),(0,$.jsx)("div",{className:"truss-estimator__option-copy",children:Un[se].blurb})]},se))})]}),(0,$.jsxs)("div",{className:"materials-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and depth"}),(0,$.jsxs)("div",{className:"materials-calculator__unit-row",children:[(0,$.jsx)("span",{children:"Units"}),(0,$.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,$.jsx)("button",{type:"button",className:n==="m"?"is-selected":"",onClick:()=>i("m"),children:"Metric"}),(0,$.jsx)("button",{type:"button",className:n==="ft"?"is-selected":"",onClick:()=>i("ft"),children:"Imperial"})]})]}),(0,$.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsxs)("span",{children:["Length (",n,")"]}),(0,$.jsx)("input",{type:"number",min:"0",step:"0.01",value:o,onChange:se=>l(se.target.value)})]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsxs)("span",{children:["Width (",n,")"]}),(0,$.jsx)("input",{type:"number",min:"0",step:"0.01",value:c,onChange:se=>p(se.target.value)})]})]}),(0,$.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,$.jsxs)("span",{children:["Depth (",n==="m"?"cm":"inches",")"]}),(0,$.jsx)("input",{type:"number",min:"0",step:"0.1",value:f,onChange:se=>b(se.target.value)})]})]}),(0,$.jsxs)("div",{className:"materials-calculator__totals",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Materials required"}),(0,$.jsx)("div",{className:"materials-calculator__result-grid",children:d==="concrete"?(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Cement"}),(0,$.jsxs)("strong",{children:[z.toFixed(0)," kg"]})]}),(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Sharp sand"}),(0,$.jsxs)("strong",{children:[G.toFixed(2)," m\xB3"]})]}),(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"20mm aggregate"}),(0,$.jsxs)("strong",{children:[K.toFixed(2)," m\xB3"]})]})]}):(0,$.jsxs)($.Fragment,{children:[(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:R.label}),(0,$.jsxs)("strong",{children:[N.toFixed(2)," m\xB3"]})]}),(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Approx. weight"}),(0,$.jsxs)("strong",{children:[(N*R.density).toFixed(2)," t"]})]}),(0,$.jsx)("div",{})]})}),(0,$.jsx)("p",{className:"materials-calculator__note",children:d==="concrete"?"Based on a 1:2:4 mix. Confirm the mix design for structural work.":"Figures are estimates. Confirm the specification and supplier quantities before ordering."})]}),u&&(0,$.jsx)("p",{className:"results-empty-hint estimator-products__error",children:u}),(0,$.jsxs)("div",{className:"materials-calculator__actions",children:[(0,$.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,$.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:ue,disabled:N<=0||D,children:D?"Adding products\u2026":a})]})]})]})})}var Ya=Y(Ke());var U=Y(ae()),Dn=12,Bn=8,ec=.56,gw=.21,Sa={ranges:{meridian:{label:"Standard grooved timber",blurb:"32 \xD7 125mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.125},summit:{label:"Wide grooved timber",blurb:"32 \xD7 150mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.15}},boardGapM:.006,wastage:{straight:.05,diagonal:.15},pictureFrame:{extraWastage:.08},joist:{lengthM:2.4,spacingOptions:[{id:"300",label:"300mm centres (heavy duty)",spacingM:.3},{id:"400",label:"400mm centres (standard)",spacingM:.4},{id:"450",label:"450mm centres (light use)",spacingM:.45}]}},Si=["range","grid","pictureFrame","substructure"],U_={range:null,colour:null,deckSizeMode:"quick",quickLengthM:"",quickWidthM:"",points:[],isOutlineClosed:!1,wallSegments:new Set,drawMode:"outline",drawError:"",pictureFrame:null,direction:null,deckHeightMode:"standard",deckHeightCm:"",joistSpacing:null,supportType:null,contact:{name:"",email:""}},tc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),ac=(e,t,a)=>a.x>=Math.min(e.x,t.x)&&a.x<=Math.max(e.x,t.x)&&a.y>=Math.min(e.y,t.y)&&a.y<=Math.max(e.y,t.y),D_=(e,t,a,r)=>{let n=tc(e,t,a),i=tc(e,t,r),o=tc(a,r,e),l=tc(a,r,t);return n===0&&ac(e,t,a)||i===0&&ac(e,t,r)||o===0&&ac(a,r,e)||l===0&&ac(a,r,t)?!0:n>0!=i>0&&o>0!=l>0},Cd=(e,t)=>{let a=t?e.length:e.length-1;for(let r=0;r<a;r+=1){let n=e[(r+1)%e.length];for(let i=r+1;i<a;i+=1)if(!(i===r+1||t&&r===0&&i===a-1)&&D_(e[r],n,e[i],e[(i+1)%e.length]))return!0}return!1};function qd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Ya.useState)(0),[i,o]=(0,Ya.useState)(U_),[l,c]=(0,Ya.useState)(1),[p,f]=(0,Ya.useState)({x:0,y:0}),[b,d]=(0,Ya.useState)(null),h=(0,Ya.useRef)(null),w=(0,Ya.useRef)(null),E=(0,Ya.useRef)(null),D=Si[r],m=i.range?Sa.ranges[i.range]:null,u=Dn/l,g=Bn/l,v=(Dn-u)/2,N=(Bn-g)/2,R=Math.max(-Dn,Math.min(Dn*2-u,v+p.x)),T=Math.max(-Bn,Math.min(Bn*2-g,N+p.y)),z=Number.parseFloat(i.quickLengthM),G=Number.parseFloat(i.quickWidthM),K=z>0&&G>0,xe=M=>Math.abs(M.reduce((x,A,I)=>{let ce=M[(I+1)%M.length];return x+A.x*ce.y-ce.x*A.y},0))/2,Ee=(M,x)=>Math.hypot(x.x-M.x,x.y-M.y),Ge=i.isOutlineClosed?xe(i.points):0,Qe=i.isOutlineClosed?i.points.reduce((M,x,A)=>M+Ee(x,i.points[(A+1)%i.points.length]),0):0,Ie=i.isOutlineClosed?i.points.reduce((M,x,A)=>M+(i.wallSegments.has(A)?0:Ee(x,i.points[(A+1)%i.points.length])),0):0,ue=i.points.reduce((M,x)=>({x:M.x+x.x/i.points.length,y:M.y+x.y/i.points.length}),{x:0,y:0}),Q=i.points.length>1?(()=>{let M=i.points[0],x=i.points[1],A=Ee(M,x),I=A?-(x.y-M.y)/A:0,ce=A?(x.x-M.x)/A:0,me=(M.x+x.x)/2,ke=(M.y+x.y)/2,k=I*(me-ue.x)+ce*(ke-ue.y)>=0?1:-1;return{x:me+I*ec*k,y:ke+ce*ec*k}})():null,Ne=(()=>{let M=i.range?Sa.ranges[i.range]:Sa.ranges.meridian,x=i.deckSizeMode==="quick"?z*G:Ge,A=i.deckSizeMode==="quick"?2*(z+G):Ie,I=i.direction==="diagonal"?Sa.wastage.diagonal:Sa.wastage.straight,ce=i.pictureFrame==="yes"?Sa.pictureFrame.extraWastage:0,ke=x/(M.boardWidthM+Sa.boardGapM)/M.boardLengthM,k=Math.ceil(ke*(1+I+ce)),j=Math.ceil(x*30*(1+I+ce)/200),O=Sa.joist.spacingOptions.find(C=>C.id===i.joistSpacing)??Sa.joist.spacingOptions[1],ne=x/O.spacingM,ee=Math.ceil(ne/Sa.joist.lengthM);return{range:M,area:x,boardCount:k,screwBoxes:j,joistLengthsNeeded:ee,spacing:O}})(),lt=Ne?[{key:`boards-${i.range??"meridian"}`,label:`Deck boards (${Ne.range.label})`,qty:Ne.boardCount,unit:"each",query:"timber decking board",category:"decking",calculatorWasteIncluded:!0},{key:"joists",label:"Treated C24 joists",qty:Ne.joistLengthsNeeded,unit:"each",query:"treated joist",category:"timber",calculatorWasteIncluded:!0},{key:"screws",label:"Green decking screws (200/box)",qty:Ne.screwBoxes,unit:"box",query:"green decking screws",category:"fixings",calculatorWasteIncluded:!0}]:[],Ye=()=>D==="range"?!!i.range:D==="grid"?i.deckSizeMode==="quick"?K:i.isOutlineClosed&&Ge>0:D==="pictureFrame"?!!i.pictureFrame&&!!i.direction:D==="substructure"?!!i.joistSpacing:!0,ge=r===Si.length-1?a:"Next",We=(M,x,A=!1)=>{let I=E.current?.getBoundingClientRect();if(!I)return null;let ce=A?1:.25;return{x:Math.round(Math.max(R,Math.min(R+u,R+(M-I.left)/I.width*u))/ce)*ce,y:Math.round(Math.max(T,Math.min(T+g,T+(x-I.top)/I.height*g))/ce)*ce}},he=M=>{if(i.isOutlineClosed){let A=M.target;if(A!==M.currentTarget&&!A.classList.contains("deck-outline__grid"))return;w.current={startX:M.clientX,startY:M.clientY,startViewX:R,startViewY:T},M.currentTarget.setPointerCapture(M.pointerId);return}if(i.drawMode!=="outline")return;let x=We(M.clientX,M.clientY,!0);x&&(d(null),o(A=>{let I=[...A.points,x];return Cd(I,!1)?{...A,drawError:"Edges cannot cross. Choose another corner."}:{...A,points:I,drawError:""}}))},W=(M,x)=>{if(!i.isOutlineClosed){M.stopPropagation(),x===0&&i.points.length>=3&&o(A=>({...A,isOutlineClosed:!0,drawMode:"edges"}));return}M.stopPropagation(),h.current=x,M.currentTarget.setPointerCapture(M.pointerId)},ze=M=>{if(w.current){let I=E.current?.getBoundingClientRect();if(!I)return;let ce=w.current,me=ce.startViewX-(M.clientX-ce.startX)/I.width*u,ke=ce.startViewY-(M.clientY-ce.startY)/I.height*g;f({x:me-v,y:ke-N});return}!i.isOutlineClosed&&i.drawMode==="outline"&&d(We(M.clientX,M.clientY,!0));let x=h.current;if(x===null)return;let A=We(M.clientX,M.clientY);A&&o(I=>{let ce=I.points.map((me,ke)=>ke===x?A:me);return Cd(ce,!0)?{...I,drawError:"Edges cannot cross. Move the corner to a different position."}:{...I,points:ce,drawError:""}})},Be=M=>{w.current=null,h.current=null,M.currentTarget.hasPointerCapture(M.pointerId)&&M.currentTarget.releasePointerCapture(M.pointerId)},ve=M=>{o(x=>{let A=new Set(x.wallSegments);return A.has(M)?A.delete(M):A.add(M),{...x,wallSegments:A}})},et=()=>{r===0?e():n(M=>M-1)},Ze=()=>{Ye()&&(r===Si.length-1?t?.(lt):n(M=>M+1))};return(0,U.jsx)(U.Fragment,{children:(0,U.jsxs)("div",{className:"truss-estimator",children:[(0,U.jsxs)("div",{className:"quick-order-hero",children:[(0,U.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,U.jsx)("h1",{children:"Decking Calculator"}),(0,U.jsx)("p",{children:"Estimate timber boards, joists and screws for your deck."})]}),(0,U.jsxs)("div",{className:"truss-estimator__card",children:[(0,U.jsxs)("div",{className:"truss-estimator__body",children:[D==="range"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your timber decking"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Both options are fixed, orderable pressure-treated timber boards."}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Sa.ranges).map(([M,x])=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.range===M?" is-selected":""}`,onClick:()=>o(A=>({...A,range:M})),children:[(0,U.jsx)("div",{className:"truss-estimator__option-title",children:x.label}),(0,U.jsx)("div",{className:"truss-estimator__option-copy",children:x.blurb}),(0,U.jsxs)("div",{className:"truss-estimator__option-copy",children:[x.boardLengthM,"m boards"]})]},M))})]}):null,D==="grid"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Tell us your deck size"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Start with a quick rectangle estimate, or draw an irregular deck for a more precise result."}),(0,U.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,U.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.deckSizeMode==="quick"?" is-selected":""}`,onClick:()=>o(M=>({...M,deckSizeMode:"quick"})),children:"Quick estimate"}),(0,U.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.deckSizeMode==="draw"?" is-selected":""}`,onClick:()=>o(M=>({...M,deckSizeMode:"draw",drawMode:"outline"})),children:"Draw your space"})]}),i.deckSizeMode==="quick"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,U.jsxs)("label",{className:"truss-estimator__field",children:[(0,U.jsx)("span",{children:"Length (m)"}),(0,U.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:i.quickLengthM,onChange:M=>o(x=>({...x,quickLengthM:M.target.value}))})]}),(0,U.jsxs)("label",{className:"truss-estimator__field",children:[(0,U.jsx)("span",{children:"Width (m)"}),(0,U.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:i.quickWidthM,onChange:M=>o(x=>({...x,quickWidthM:M.target.value}))})]})]}),(0,U.jsx)("div",{className:"truss-estimator__grid-hint",children:"For L-shaped decks, cut-outs, or sides against a wall, use Draw your space."}),K?(0,U.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,U.jsxs)("div",{children:[(z*G).toFixed(2)," m\xB2 deck"]}),(0,U.jsxs)("div",{children:[(2*(z+G)).toFixed(2)," m perimeter"]})]}):null]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Draw your deck"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Click to add corners, then close the outline. Drag any handle to refine it."}),(0,U.jsxs)("div",{className:"deck-outline__toolbar",children:[i.isOutlineClosed?(0,U.jsxs)("div",{className:"deck-outline__summary",children:[(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Deck area"}),(0,U.jsxs)("strong",{children:[Ge.toFixed(2)," m\xB2"]})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Perimeter"}),(0,U.jsxs)("strong",{children:[Qe.toFixed(2)," m"]})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Wall edges"}),(0,U.jsx)("strong",{children:i.wallSegments.size>0?i.wallSegments.size:"None"})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Visible edge"}),(0,U.jsxs)("strong",{children:[Ie.toFixed(2)," m"]})]})]}):null,(0,U.jsxs)("div",{className:"deck-outline__actions",children:[(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(M=>({...M,points:M.points.slice(0,-1)})),disabled:i.points.length===0||i.isOutlineClosed,children:"Undo"}),(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{d(null),o(M=>({...M,points:[],isOutlineClosed:!1,wallSegments:new Set,drawMode:"outline",drawError:""}))},disabled:i.points.length===0,children:"Clear"}),(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(M=>({...M,points:[{x:2,y:2},{x:8,y:2},{x:8,y:5},{x:2,y:5}],isOutlineClosed:!0,wallSegments:new Set,drawMode:"edges",drawError:""})),children:"Start with rectangle"})]})]}),(0,U.jsx)("div",{className:"deck-editor-layout",children:(0,U.jsxs)("div",{className:"deck-editor-layout__canvas-column",children:[(0,U.jsxs)("div",{className:"deck-outline",children:[(0,U.jsxs)("svg",{ref:E,className:`deck-outline__canvas${i.isOutlineClosed?" is-pan-mode":""}`,viewBox:`${R} ${T} ${u} ${g}`,preserveAspectRatio:"none","aria-label":"Deck outline drawing area",onPointerDown:he,onPointerMove:ze,onPointerUp:Be,onPointerLeave:()=>{d(null),w.current||(h.current=null)},children:[(0,U.jsx)("defs",{children:(0,U.jsx)("pattern",{id:"deck-outline-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,U.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,U.jsx)("rect",{x:-Dn,y:-Bn,width:Dn*3,height:Bn*3,className:"deck-outline__grid",fill:"url(#deck-outline-grid)"}),i.points.length>1?(0,U.jsx)("polyline",{className:"deck-outline__preview",points:i.points.map(M=>`${M.x},${M.y}`).join(" ")}):null,i.isOutlineClosed?(0,U.jsx)("polygon",{className:"deck-outline__shape",points:i.points.map(M=>`${M.x},${M.y}`).join(" "),stroke:"none"}):null,i.points.length>1?i.points.slice(0,i.isOutlineClosed?void 0:-1).map((M,x)=>{let A=i.points[i.isOutlineClosed?(x+1)%i.points.length:x+1],I=Ee(M,A),ce=I?-(A.y-M.y)/I:0,me=I?(A.x-M.x)/I:0,ke=(M.x+A.x)/2,k=(M.y+A.y)/2,j=ce*(ke-ue.x)+me*(k-ue.y)>=0?1:-1,O=ke+ce*ec*j,ne=k+me*ec*j;return(0,U.jsxs)("g",{children:[(0,U.jsx)("line",{className:"deck-outline__edge-hit",x1:M.x,y1:M.y,x2:A.x,y2:A.y,onClick:i.isOutlineClosed?()=>ve(x):void 0}),(0,U.jsx)("line",{className:`deck-outline__edge${i.wallSegments.has(x)?" is-wall":""}`,x1:M.x,y1:M.y,x2:A.x,y2:A.y,pointerEvents:"none"}),(0,U.jsxs)("text",{className:`deck-outline__edge-label${i.wallSegments.has(x)?" is-wall":""}`,x:O,y:ne,textAnchor:"middle",dominantBaseline:"central",fontSize:gw/l,children:[I.toFixed(2)," m"]})]},`segment-${x}`)}):null,!i.isOutlineClosed&&i.points.length>0&&b?(()=>{let M=i.points[i.points.length-1],x=Ee(M,b);if(!x)return null;let A=-(b.y-M.y)/x,I=(b.x-M.x)/x,ce=(M.x+b.x)/2,me=(M.y+b.y)/2;return(0,U.jsxs)("g",{className:"deck-outline__live-measurement",children:[(0,U.jsx)("line",{x1:M.x,y1:M.y,x2:b.x,y2:b.y}),(0,U.jsxs)("text",{x:ce+A*.34,y:me+I*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:gw/l,children:[x.toFixed(2)," m"]})]})})():null,i.points.map((M,x)=>(0,U.jsx)("circle",{className:"deck-outline__point",cx:M.x,cy:M.y,r:"0.13",onPointerDown:A=>W(A,x)},`point-${x}`))]}),(0,U.jsxs)("div",{className:"deck-outline__zoom","aria-label":"Zoom controls",children:[(0,U.jsx)("button",{type:"button",onClick:()=>c(M=>Math.max(.5,M-.25)),disabled:l===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,U.jsxs)("span",{children:[Math.round(l*100),"%"]}),(0,U.jsx)("button",{type:"button",onClick:()=>c(M=>Math.min(1,M+.25)),disabled:l===1,"aria-label":"Zoom in",children:"+"})]}),i.isOutlineClosed&&i.wallSegments.size===0&&Q?(0,U.jsx)("div",{className:"deck-outline__edge-prompt",role:"status",style:{left:`${(Q.x-R)/u*100}%`,top:`${(Q.y-T)/g*100}%`},children:"Tap an edge to mark it as a wall, or leave it as a visible edge."}):null,!i.isOutlineClosed&&i.points.length>=3?(0,U.jsx)("button",{type:"button",className:"deck-outline__close",onClick:()=>o(M=>Cd(M.points,!0)?{...M,drawError:"Edges cannot cross. Adjust the outline before finishing."}:{...M,isOutlineClosed:!0,drawMode:"edges",drawError:""}),children:"Finish outline"}):null]}),(0,U.jsxs)("div",{className:"deck-outline__supporting",children:[(0,U.jsx)("div",{className:"truss-estimator__grid-hint",children:i.isOutlineClosed?"Drag a corner handle to refine the outline.":"Add at least three corners, then click Finish outline."}),i.drawError?(0,U.jsx)("div",{className:"deck-outline__error",role:"alert",children:i.drawError}):null]})]})})]})]}):null,D==="pictureFrame"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Picture frame border?"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"A picture frame border runs boards around the perimeter for a finished look and uses extra material."}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"no",label:"No border",img:"/decking/boards/no-border.webp"},{id:"yes",label:"Picture frame",img:"/decking/boards/picture-frame.webp"}].map(M=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.pictureFrame===M.id?" is-selected":""}`,onClick:()=>o(x=>({...x,pictureFrame:M.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:Pt(M.img),alt:""}),(0,U.jsx)("span",{children:M.label})]},M.id))}),(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Board direction"}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"straight",label:"Straight",img:"/decking/boards/straight.webp"},{id:"diagonal",label:"Diagonal",img:"/decking/boards/diagonal.webp"}].map(M=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.direction===M.id?" is-selected":""}`,onClick:()=>o(x=>({...x,direction:M.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:Pt(M.img),alt:""}),(0,U.jsx)("span",{children:M.label})]},M.id))})]})]}):null,D==="substructure"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Substructure"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the joist spacing. Posts, footings and ground preparation vary by site, so are not included."}),(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Joist spacing"}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Sa.joist.spacingOptions.map(M=>(0,U.jsx)("button",{type:"button",className:`truss-estimator__option-card${i.joistSpacing===M.id?" is-selected":""}`,onClick:()=>o(x=>({...x,joistSpacing:M.id})),children:(0,U.jsx)("div",{className:"truss-estimator__option-title",children:M.label})},M.id))})]}):null]}),(0,U.jsxs)("div",{className:"truss-estimator__nav",children:[(0,U.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:et,children:"Back"}),(0,U.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:Ze,disabled:!Ye(),children:[(0,U.jsx)("span",{children:ge}),(0,U.jsx)("span",{className:"arrow",children:(0,U.jsx)(Ht,{})})]})]})]})]})})}var qa=Y(Ke());var H=Y(ae()),hw=12,bw=30,On=12,Ln=8,vw=.56,Ca={ranges:{boundary:{label:"Horizontal lap",blurb:"Traditional pressure-treated timber panels.",panelWidthM:1.83},skyline:{label:"Feather edge",blurb:"Heavier timber panels for a more solid boundary.",panelWidthM:1.83}},heights:["0.9","1.2","1.5","1.8"],gate:{single:{label:"Single lap gate",widthDefault:.9}},mounting:{concrete:{label:"Concrete posts",blurb:"Slotted concrete posts with matching panels."},postcrete:{label:"Postcrete bags",blurb:"Fast-set post-mix bags in a dug hole.",bagsPerPost:2}}},Ci=["range","height","gate","posts"],B_={range:null,colour:null,grid:new Set,excludedEdges:new Set,gridMode:"draw",boundaryMode:"quick",quickLengthM:"",boundaryPoints:[],boundaryClosed:!1,excludedBoundaryEdges:new Set,height:null,gravelBoard:null,gateType:null,gateWidthM:"",mountingType:null,contact:{name:"",email:""}},rc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),ic=(e,t,a)=>a.x>=Math.min(e.x,t.x)&&a.x<=Math.max(e.x,t.x)&&a.y>=Math.min(e.y,t.y)&&a.y<=Math.max(e.y,t.y),O_=(e,t,a,r)=>{let n=rc(e,t,a),i=rc(e,t,r),o=rc(a,r,e),l=rc(a,r,t);return n===0&&ic(e,t,a)||i===0&&ic(e,t,r)||o===0&&ic(a,r,e)||l===0&&ic(a,r,t)?!0:n>0!=i>0&&o>0!=l>0},nc=(e,t)=>{let a=t?e.length:e.length-1;for(let r=0;r<a;r+=1)for(let n=r+1;n<a;n+=1)if(!(n===r+1||t&&r===0&&n===a-1)&&O_(e[r],e[(r+1)%e.length],e[n],e[(n+1)%e.length]))return!0;return!1};function Ed({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,qa.useState)(0),[i,o]=(0,qa.useState)(B_),l=(0,qa.useRef)(null),c=(0,qa.useRef)(null),[p,f]=(0,qa.useState)(1),[b,d]=(0,qa.useState)({x:0,y:0}),[h,w]=(0,qa.useState)(null),E=(0,qa.useRef)(null),D=(0,qa.useRef)(null),m=(0,qa.useRef)(null),u=Ci[r],g=i.range?Ca.ranges[i.range]:null,v=On/p,N=Ln/p,R=(On-v)/2,T=(Ln-N)/2,z=Math.max(-On,Math.min(On*2-v,R+b.x)),G=Math.max(-Ln,Math.min(Ln*2-N,T+b.y)),K=i.boundaryPoints.reduce((k,j)=>({x:k.x+j.x/Math.max(1,i.boundaryPoints.length),y:k.y+j.y/Math.max(1,i.boundaryPoints.length)}),{x:0,y:0}),xe=k=>{let j=new Set,O=[];return k.forEach(ne=>{let[ee,C]=ne.split(",").map(Number),V=[{key:`H,${ee},${C}`,type:"H",x:ee,y:C},{key:`H,${ee},${C+1}`,type:"H",x:ee,y:C+1},{key:`V,${ee},${C}`,type:"V",x:ee,y:C},{key:`V,${ee+1},${C}`,type:"V",x:ee+1,y:C}],X=[!k.has(`${ee},${C-1}`),!k.has(`${ee},${C+1}`),!k.has(`${ee-1},${C}`),!k.has(`${ee+1},${C}`)];V.forEach((pe,Se)=>{X[Se]&&!j.has(pe.key)&&(j.add(pe.key),O.push(pe))})}),O},Ee=(k,j)=>xe(k).filter(O=>!j.has(O.key)),Ge=(k,j)=>Ee(k,j).length,Qe=(k,j)=>{let O={};Ee(k,j).forEach(ee=>{var C,V,X,pe;ee.type==="H"?((O[C=`${ee.x},${ee.y}`]||(O[C]=[])).push("H"),(O[V=`${ee.x+1},${ee.y}`]||(O[V]=[])).push("H")):((O[X=`${ee.x},${ee.y}`]||(O[X]=[])).push("V"),(O[pe=`${ee.x},${ee.y+1}`]||(O[pe]=[])).push("V"))});let ne=0;return Object.values(O).forEach(ee=>{(ee.length===1||ee.length===2&&ee[0]!==ee[1]||ee.length>=3)&&(ne+=1)}),ne},ue=(()=>{let k=i.range?Ca.ranges[i.range]:Ca.ranges.boundary,j=i.height??"1.8",O=i.boundaryMode==="quick"?Math.max(0,Number.parseFloat(i.quickLengthM)||0):i.boundaryClosed?i.boundaryPoints.slice(0,-1).reduce((hr,Ft,It)=>hr+(i.excludedBoundaryEdges.has(It)?0:Math.hypot(i.boundaryPoints[It+1].x-Ft.x,i.boundaryPoints[It+1].y-Ft.y)),0):0,ne=i.gateType&&i.gateType!=="none"?Number.parseFloat(i.gateWidthM)||Ca.gate[i.gateType].widthDefault:0,ee=Math.max(0,O-ne),C=ee>0?Math.ceil(ee/k.panelWidthM):0,V=i.boundaryPoints.length>2&&i.boundaryPoints[0].x===i.boundaryPoints[i.boundaryPoints.length-1].x&&i.boundaryPoints[0].y===i.boundaryPoints[i.boundaryPoints.length-1].y,X=i.boundaryMode==="quick"?ee>0?2:0:i.boundaryClosed?i.boundaryPoints.slice(0,V?-1:void 0).reduce((hr,Ft,It)=>{let Xd=It>0&&!i.excludedBoundaryEdges.has(It-1),$d=It<i.boundaryPoints.length-1&&!i.excludedBoundaryEdges.has(It);return hr+(Xd||$d?1:0)},0):0,pe=ee>0?Math.ceil(ee/k.panelWidthM)+1:0,Se=Math.max(0,pe-X),ft=i.mountingType?Ca.mounting[i.mountingType]:Ca.mounting.concrete,Ve=i.gateType&&i.gateType!=="none"?2:0,Fr=Se+X+Ve,Ir=i.mountingType==="postcrete"?Fr*Ca.mounting.postcrete.bagsPerPost:0,ll=i.gravelBoard==="yes"?C:0;return{range:k,height:j,totalEdgeM:O,fencedLengthM:ee,gateWidthM:ne,panelsCount:C,cornerPostCount:X,intermediatePostCount:Se,gatePostCount:Ve,totalPostCount:Fr,bagsCount:Ir,gravelCount:ll,capCount:Fr,mounting:ft}})(),Q=i.gateType&&i.gateType!=="none"?Ca.gate[i.gateType].label:null,se=Number(ue.height)<=1.2?"6":"8",Ne=ue?[{key:`panels-${i.range??"boundary"}-${ue.height}`,label:`${ue.range.label} panels (${ue.height}m)`,qty:ue.panelsCount,unit:"each",query:"fence panel",category:"fencing"},...i.mountingType==="concrete"?[{key:`concrete-intermediate-${se}`,label:"Intermediate concrete posts",qty:ue.intermediatePostCount,unit:"each",query:"concrete fence post",category:"fencing"},{key:`concrete-end-${se}`,label:"End and corner concrete posts",qty:ue.cornerPostCount+ue.gatePostCount,unit:"each",query:"concrete end post",category:"fencing"}]:[{key:`timber-post-${se}`,label:"Timber fence posts",qty:ue.totalPostCount,unit:"each",query:"timber fence post",category:"fencing"},{key:"postcrete",label:"Postcrete",qty:ue.bagsCount,unit:"bag",query:"postcrete",category:"cement"}],...Q?[{key:"gate",label:Q,qty:1,unit:"each",query:"lap gate",category:"fencing"}]:[],...ue.gravelCount>0?[{key:"gravel-boards",label:"Concrete gravel boards",qty:ue.gravelCount,unit:"each",query:"gravel board",category:"fencing"}]:[]]:[],lt=()=>{if(u==="range"){let k=i.boundaryMode==="quick"?(Number.parseFloat(i.quickLengthM)||0)>0:i.boundaryClosed&&i.boundaryPoints.length>=2;return!!i.range&&k}return u==="height"?!!i.height&&!!i.gravelBoard:u==="gate"?!!i.gateType&&(i.gateType==="none"||i.gateWidthM.trim()!==""):u==="posts"?!!i.mountingType:!0},Ye=r===Ci.length-1?a:"Next",ge=k=>{o(j=>{let O=k(new Set(j.grid)),ne=new Set([...j.excludedEdges].filter(ee=>xe(O).some(C=>C.key===ee)));return{...j,grid:O,excludedEdges:ne}})},We=(k,j,O)=>{ge(ne=>{let ee=`${k},${j}`;return O?ne.add(ee):ne.delete(ee),ne})},he=(k,j,O,ne,ee)=>{let C=k,V=j,X=Math.abs(O-k),pe=k<O?1:-1,Se=-Math.abs(ne-j),ft=j<ne?1:-1,Ve=X+Se;for(;We(C,V,ee),!(C===O&&V===ne);){let Fr=2*Ve;Fr>=Se&&(Ve+=Se,C+=pe),Fr<=X&&(Ve+=X,V+=ft)}},W=(k,j)=>{let O=c.current?.getBoundingClientRect();if(!O)return null;let ne=Math.floor((k-O.left)/bw),ee=Math.floor((j-O.top)/bw);return ne<0||ee<0||ne>=hw||ee>=hw?null:{x:ne,y:ee}},ze=k=>{if(i.gridMode!=="draw")return;let j=W(k.clientX,k.clientY);if(!j)return;k.preventDefault();let O=`${j.x},${j.y}`,ne=!i.grid.has(O);l.current={active:!0,paintValue:ne,lastX:j.x,lastY:j.y},k.currentTarget.setPointerCapture(k.pointerId),We(j.x,j.y,ne)},Be=k=>{let j=l.current;if(!j?.active)return;let O=W(k.clientX,k.clientY);O&&(O.x===j.lastX&&O.y===j.lastY||(he(j.lastX,j.lastY,O.x,O.y,j.paintValue),l.current={...j,lastX:O.x,lastY:O.y}))},ve=k=>{l.current?.active&&(l.current=null,k.currentTarget.releasePointerCapture(k.pointerId))},et=(k,j,O=!1)=>{let ne=m.current?.getBoundingClientRect();if(!ne)return null;let ee=O?1:.25;return{x:Math.round(Math.max(z,Math.min(z+v,z+(k-ne.left)/ne.width*v))/ee)*ee,y:Math.round(Math.max(G,Math.min(G+N,G+(j-ne.top)/ne.height*N))/ee)*ee}},Ze=k=>{if(i.boundaryClosed){let O=k.target;if(O!==k.currentTarget&&!O.classList.contains("fence-boundary__grid"))return;D.current={startX:k.clientX,startY:k.clientY,startViewX:z,startViewY:G},k.currentTarget.setPointerCapture(k.pointerId);return}let j=et(k.clientX,k.clientY,!0);j&&(w(null),o(O=>{let ne=[...O.boundaryPoints,j];return nc(ne,!1)?{...O}:{...O,boundaryPoints:ne}}))},M=(k,j)=>{if(k.stopPropagation(),!i.boundaryClosed){if(j!==0||i.boundaryPoints.length<3)return;o(O=>nc(O.boundaryPoints,!0)?O:{...O,boundaryPoints:[...O.boundaryPoints,O.boundaryPoints[0]],boundaryClosed:!0});return}E.current=j,k.currentTarget.setPointerCapture(k.pointerId)},x=k=>{if(D.current){let O=m.current?.getBoundingClientRect();if(!O)return;let ne=D.current,ee=ne.startViewX-(k.clientX-ne.startX)/O.width*v,C=ne.startViewY-(k.clientY-ne.startY)/O.height*N;d({x:ee-R,y:C-T});return}if(i.boundaryClosed||w(et(k.clientX,k.clientY,!0)),E.current===null)return;let j=et(k.clientX,k.clientY);j&&o(O=>{let ne=O.boundaryPoints.length>2&&O.boundaryPoints[0].x===O.boundaryPoints[O.boundaryPoints.length-1].x&&O.boundaryPoints[0].y===O.boundaryPoints[O.boundaryPoints.length-1].y,ee=O.boundaryPoints.map((C,V)=>{let X=V===E.current,pe=ne&&E.current===0&&V===O.boundaryPoints.length-1;return X||pe?j:C});return nc(ee,!1)?O:{...O,boundaryPoints:ee}})},A=k=>{D.current=null,E.current=null,k.currentTarget.hasPointerCapture(k.pointerId)&&k.currentTarget.releasePointerCapture(k.pointerId)},I=k=>{o(j=>{let O=new Set(j.excludedBoundaryEdges);return O.has(k)?O.delete(k):O.add(k),{...j,excludedBoundaryEdges:O}})},ce=()=>{r===0?e():n(k=>k-1)},me=()=>{lt()&&(r===Ci.length-1?t?.(Ne):n(k=>k+1))},ke=xe(i.grid);return(0,H.jsx)(H.Fragment,{children:(0,H.jsxs)("div",{className:"truss-estimator",children:[(0,H.jsxs)("div",{className:"quick-order-hero",children:[(0,H.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,H.jsx)("h1",{children:"Fencing Calculator"}),(0,H.jsx)("p",{children:"Estimate panels, posts and cost for your fence line in a few steps."})]}),(0,H.jsxs)("div",{className:"truss-estimator__card",children:[(0,H.jsxs)("div",{className:"truss-estimator__body",children:[u==="range"?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ci.length]}),(0,H.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your fence panels"}),(0,H.jsx)("p",{className:"truss-estimator__step-sub",children:"The calculator uses fixed, orderable timber panels from the catalogue."}),(0,H.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Ca.ranges).map(([k,j])=>(0,H.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.range===k?" is-selected":""}`,onClick:()=>o(O=>({...O,range:k})),children:[(0,H.jsx)("div",{className:"truss-estimator__option-title",children:j.label}),(0,H.jsx)("div",{className:"truss-estimator__option-copy",children:j.blurb})]},k))})]}):null,u==="range"?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)("div",{className:"truss-estimator__section-heading",children:"Measure your fence line"}),(0,H.jsx)("p",{className:"truss-estimator__step-sub",children:"Use a quick total, or draw the boundary to mark existing edges that do not need new fencing."}),(0,H.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,H.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.boundaryMode==="quick"?" is-selected":""}`,onClick:()=>o(k=>({...k,boundaryMode:"quick"})),children:"Quick estimate"}),(0,H.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.boundaryMode==="draw"?" is-selected":""}`,onClick:()=>o(k=>({...k,boundaryMode:"draw"})),children:"Draw your boundary"})]}),i.boundaryMode==="quick"?(0,H.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact fence-boundary__quick-field",children:[(0,H.jsx)("span",{children:"Total fence length (m)"}),(0,H.jsx)("input",{type:"number",min:"0",step:"0.1",value:i.quickLengthM,onChange:k=>o(j=>({...j,quickLengthM:k.target.value}))})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)("div",{className:"fence-boundary__toolbar",children:(0,H.jsxs)("div",{className:"fence-boundary__actions",children:[(0,H.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(k=>({...k,boundaryPoints:k.boundaryPoints.slice(0,-1),boundaryClosed:!1,excludedBoundaryEdges:new Set})),disabled:i.boundaryPoints.length===0||i.boundaryClosed,children:"Undo"}),(0,H.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{d({x:0,y:0}),w(null),o(k=>({...k,boundaryPoints:[],boundaryClosed:!1,excludedBoundaryEdges:new Set}))},disabled:i.boundaryPoints.length===0,children:"Clear"}),(0,H.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(k=>({...k,boundaryPoints:[{x:2,y:2},{x:8,y:2},{x:8,y:5},{x:2,y:5},{x:2,y:2}],boundaryClosed:!0,excludedBoundaryEdges:new Set})),children:"Start with rectangle"})]})}),(0,H.jsxs)("div",{className:"fence-boundary",children:[(0,H.jsxs)("svg",{ref:m,className:`fence-boundary__canvas${i.boundaryClosed?" is-pan-mode":""}`,viewBox:`${z} ${G} ${v} ${N}`,preserveAspectRatio:"none","aria-label":"Fence boundary drawing area",onPointerDown:Ze,onPointerMove:x,onPointerUp:A,onPointerLeave:()=>{w(null),D.current||(E.current=null)},children:[(0,H.jsx)("defs",{children:(0,H.jsx)("pattern",{id:"fence-boundary-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,H.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,H.jsx)("rect",{x:-On,y:-Ln,width:On*3,height:Ln*3,className:"fence-boundary__grid",fill:"url(#fence-boundary-grid)"}),i.boundaryPoints.length>1?(0,H.jsx)("polyline",{className:"fence-boundary__preview",points:i.boundaryPoints.map(k=>`${k.x},${k.y}`).join(" ")}):null,i.boundaryPoints.length>1?i.boundaryPoints.slice(0,-1).map((k,j)=>{let O=i.boundaryPoints[j+1],ne=Math.hypot(O.x-k.x,O.y-k.y),ee=ne?-(O.y-k.y)/ne:0,C=ne?(O.x-k.x)/ne:0,V=(k.x+O.x)/2,X=(k.y+O.y)/2,pe=ee*(V-K.x)+C*(X-K.y)>=0?1:-1,Se=V+ee*vw*pe,ft=X+C*vw*pe;return(0,H.jsxs)("g",{children:[(0,H.jsx)("line",{className:"fence-boundary__edge-hit",x1:k.x,y1:k.y,x2:O.x,y2:O.y,onClick:i.boundaryClosed?()=>I(j):void 0}),(0,H.jsx)("line",{className:`fence-boundary__edge${i.excludedBoundaryEdges.has(j)?" is-excluded":""}`,x1:k.x,y1:k.y,x2:O.x,y2:O.y,pointerEvents:"none"}),(0,H.jsxs)("text",{className:`fence-boundary__edge-label${i.excludedBoundaryEdges.has(j)?" is-excluded":""}`,x:Se,y:ft,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[ne.toFixed(2)," m"]})]},`fence-edge-${j}`)}):null,!i.boundaryClosed&&i.boundaryPoints.length>0&&h?(()=>{let k=i.boundaryPoints[i.boundaryPoints.length-1],j=Math.hypot(h.x-k.x,h.y-k.y);if(!j)return null;let O=-(h.y-k.y)/j,ne=(h.x-k.x)/j,ee=(k.x+h.x)/2,C=(k.y+h.y)/2;return(0,H.jsxs)("g",{className:"fence-boundary__live-measurement",children:[(0,H.jsx)("line",{x1:k.x,y1:k.y,x2:h.x,y2:h.y}),(0,H.jsxs)("text",{x:ee+O*.34,y:C+ne*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[j.toFixed(2)," m"]})]})})():null,i.boundaryPoints.map((k,j)=>j>0&&j===i.boundaryPoints.length-1&&k.x===i.boundaryPoints[0]?.x&&k.y===i.boundaryPoints[0]?.y?null:(0,H.jsx)("circle",{className:`fence-boundary__point${!i.boundaryClosed&&j===0&&i.boundaryPoints.length>=3?" is-close-target":""}`,cx:k.x,cy:k.y,r:"0.13",onPointerDown:O=>M(O,j)},`fence-point-${j}`))]}),(0,H.jsxs)("div",{className:"fence-boundary__zoom","aria-label":"Zoom controls",children:[(0,H.jsx)("button",{type:"button",onClick:()=>f(k=>Math.max(.5,k-.25)),disabled:p===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,H.jsxs)("span",{children:[Math.round(p*100),"%"]}),(0,H.jsx)("button",{type:"button",onClick:()=>f(k=>Math.min(1,k+.25)),disabled:p===1,"aria-label":"Zoom in",children:"+"})]}),!i.boundaryClosed&&i.boundaryPoints.length>=2?(0,H.jsx)("button",{type:"button",className:"fence-boundary__close",onClick:()=>o(k=>nc(k.boundaryPoints,!1)?k:{...k,boundaryClosed:!0}),children:"Finish fence line"}):null]}),(0,H.jsx)("div",{className:"truss-estimator__grid-hint",children:i.boundaryClosed?"Drag the blank canvas to pan. Tap an edge to exclude it from the new fence.":"Click to add points, then finish the fence line. The displayed distances update as you draw."})]}),(0,H.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,H.jsx)("div",{children:i.boundaryMode==="quick"?`${(Number.parseFloat(i.quickLengthM)||0).toFixed(2)} m fence line`:`${ue.totalEdgeM.toFixed(2)} m fence line`}),i.boundaryMode==="draw"&&i.boundaryClosed?(0,H.jsxs)("div",{children:[ue.cornerPostCount," corner/end posts"]}):null]})]}):null,null,u==="height"?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ci.length]}),(0,H.jsx)("h2",{className:"truss-estimator__step-title",children:"Fence height"}),(0,H.jsx)("p",{className:"truss-estimator__step-sub",children:"Select the nearest available panel height."}),(0,H.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:Ca.heights.map(k=>(0,H.jsx)("button",{type:"button",className:`truss-estimator__visual-card${i.height===k?" is-selected":""}`,onClick:()=>o(j=>({...j,height:k})),children:(0,H.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--tall",src:Pt(`/fencing/height/${k}.webp`),alt:""})},k))}),(0,H.jsx)("div",{className:"truss-estimator__section-heading",children:"Gravel board?"}),(0,H.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"no",label:"No gravel board",img:"/fencing/no-gravel-board.webp"},{id:"yes",label:"Add gravel board",img:"/fencing/gravel-board.webp"}].map(k=>(0,H.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.gravelBoard===k.id?" is-selected":""}`,onClick:()=>o(j=>({...j,gravelBoard:k.id})),children:[(0,H.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Pt(k.img),alt:""}),(0,H.jsx)("span",{children:k.label})]},k.id))})]}):null,u==="gate"?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ci.length]}),(0,H.jsx)("h2",{className:"truss-estimator__step-title",children:"Do you need a gate?"}),(0,H.jsx)("p",{className:"truss-estimator__step-sub",children:"A gate opening replaces part of the panel run and adds a gate kit with heavy-duty posts."}),(0,H.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"none",label:"No gate",img:"/fencing/gates/no-gate.webp"},{id:"single",label:"Single gate",img:"/fencing/gates/single-gate.webp"}].map(k=>(0,H.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${i.gateType===k.id?" is-selected":""}`,onClick:()=>o(j=>({...j,gateType:k.id,gateWidthM:k.id==="none"?"":String(Ca.gate[k.id].widthDefault)})),children:[(0,H.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Pt(k.img),alt:""}),(0,H.jsx)("span",{children:k.label})]},k.id))}),i.gateType&&i.gateType!=="none"?(0,H.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,H.jsx)("span",{children:"Gate width (m)"}),(0,H.jsx)("input",{type:"text",inputMode:"decimal",value:i.gateWidthM,onChange:k=>o(j=>({...j,gateWidthM:k.target.value}))})]}):null]}):null,u==="posts"?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ci.length]}),(0,H.jsx)("h2",{className:"truss-estimator__step-title",children:"Posts and fixing type"}),(0,H.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose how the posts will be set."}),(0,H.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Ca.mounting).map(([k,j])=>(0,H.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.mountingType===k?" is-selected":""}`,onClick:()=>o(O=>({...O,mountingType:k})),children:[(0,H.jsx)("div",{className:"truss-estimator__option-title",children:j.label}),(0,H.jsx)("div",{className:"truss-estimator__option-copy",children:j.blurb})]},k))})]}):null]}),(0,H.jsxs)("div",{className:"truss-estimator__nav",children:[(0,H.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:ce,children:"Back"}),(0,H.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:me,disabled:!lt(),children:[(0,H.jsx)("span",{children:Ye}),(0,H.jsx)("span",{className:"arrow",children:(0,H.jsx)(Ht,{})})]})]})]})]})})}var oc=Y(Ke()),ye=Y(ae()),ww={floor:{label:"Floor",product:"Knauf Acoustic Roll",thickness:"100mm",coverage:12.36,salesUnit:"roll"},wall:{label:"Cavity wall",product:"Celotex CW4100",thickness:"100mm",coverage:3.24,salesUnit:"pack"},roof:{label:"Pitched roof",product:"Kingspan K107",thickness:"100mm",coverage:8.64,salesUnit:"pack"},loft:{label:"Loft",product:"Knauf Loft Roll 44",thickness:"100mm",coverage:13.89,salesUnit:"roll"}};function Md({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,oc.useState)("floor"),[i,o]=(0,oc.useState)(""),[l,c]=(0,oc.useState)(""),p=Number.parseFloat(i)*Number.parseFloat(l)||0,f=ww[r],b=Math.ceil(p/f.coverage),d=[{key:`insulation-${r}`,label:`${f.product} ${f.thickness}`,qty:b,unit:f.salesUnit,query:f.product,category:"insulation"}],h=Object.entries(ww);return(0,ye.jsx)(ye.Fragment,{children:(0,ye.jsxs)("div",{className:"truss-estimator",children:[(0,ye.jsxs)("div",{className:"quick-order-hero",children:[(0,ye.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ye.jsx)("h1",{children:"Insulation Calculator"}),(0,ye.jsx)("p",{children:"Estimate insulation coverage and pack quantities for floors, walls, roofs and lofts."})]}),(0,ye.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,ye.jsx)("h2",{className:"truss-estimator__step-title",children:"Where and what you are insulating"}),(0,ye.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the application and product, and enter the area, for coverage and pack quantities."}),(0,ye.jsxs)("div",{className:"materials-calculator__section",children:[(0,ye.jsx)("div",{className:"truss-estimator__section-heading",children:"Application"}),(0,ye.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:h.map(([w,E])=>(0,ye.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===w?" is-selected":""}`,onClick:()=>n(w),children:[(0,ye.jsx)("div",{className:"truss-estimator__option-title",children:E.label}),(0,ye.jsxs)("div",{className:"truss-estimator__option-copy",children:[E.product,", ",E.thickness]})]},w))})]}),(0,ye.jsxs)("div",{className:"materials-calculator__section",children:[(0,ye.jsx)("div",{className:"truss-estimator__section-heading",children:"Area"}),(0,ye.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ye.jsxs)("label",{className:"truss-estimator__field",children:[(0,ye.jsx)("span",{children:"Length (m)"}),(0,ye.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:w=>o(w.target.value)})]}),(0,ye.jsxs)("label",{className:"truss-estimator__field",children:[(0,ye.jsx)("span",{children:"Width (m)"}),(0,ye.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:w=>c(w.target.value)})]})]})]}),(0,ye.jsxs)("div",{className:"materials-calculator__totals",children:[(0,ye.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ye.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,ye.jsxs)("div",{children:[(0,ye.jsx)("span",{children:"Insulated area"}),(0,ye.jsxs)("strong",{children:[p.toFixed(2)," m\xB2"]})]}),(0,ye.jsxs)("div",{children:[(0,ye.jsx)("span",{children:f.product}),(0,ye.jsxs)("strong",{children:[b," packs"]})]})]}),(0,ye.jsx)("p",{className:"materials-calculator__note",children:"This is a simple product choice, not thermal or Building Regulations advice. Confirm the specification before ordering."})]}),(0,ye.jsxs)("div",{className:"materials-calculator__actions",children:[(0,ye.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ye.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(d),disabled:p<=0,children:a})]})]})]})})}var Hn=Y(Ke()),Z=Y(ae()),L_=10,H_=1.9*.762,j_=1.9*1.524,lc=()=>({height:"",width:""}),sc=e=>Number.parseFloat(e)||0,yw=({height:e,width:t})=>sc(e)*sc(t);function Td({onBack:e}){let[t,a]=(0,Hn.useState)([lc()]),[r,n]=(0,Hn.useState)([lc()]),[i,o]=(0,Hn.useState)("0"),[l,c]=(0,Hn.useState)("0"),[p,f]=(0,Hn.useState)(1),b=t.reduce((m,u)=>m+yw(u),0),d=r.reduce((m,u)=>m+yw(u),0),h=sc(i)*H_+sc(l)*j_,w=Math.max(0,b-d-h),E=w*p/L_,D=(m,u,g,v)=>{m(N=>N.map((R,T)=>T===u?{...R,[g]:v}:R))};return(0,Z.jsx)(Z.Fragment,{children:(0,Z.jsxs)("div",{className:"truss-estimator",children:[(0,Z.jsxs)("div",{className:"quick-order-hero",children:[(0,Z.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Z.jsx)("h1",{children:"Paint Calculator"}),(0,Z.jsx)("p",{children:"Estimate how much paint you need for your walls, including multiple coats and excluded areas."})]}),(0,Z.jsxs)("div",{className:"truss-estimator__card paint-calculator",children:[(0,Z.jsx)("h2",{className:"truss-estimator__step-title",children:"Walls, exclusions and coats"}),(0,Z.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter each wall, subtract windows and doors, and choose your number of coats. Quantities assume a coverage of 10 m\xB2 per litre."}),(0,Z.jsxs)("div",{className:"paint-calculator__section",children:[(0,Z.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,Z.jsx)("p",{className:"paint-calculator__hint",children:"Enter the height and width of each wall you want to paint."}),(0,Z.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,Z.jsx)("span",{}),(0,Z.jsx)("span",{children:"Height (m)"}),(0,Z.jsx)("span",{children:"Width (m)"}),(0,Z.jsx)("span",{})]}),t.map((m,u)=>(0,Z.jsxs)("div",{className:"paint-calculator__row",children:[(0,Z.jsxs)("span",{className:"paint-calculator__row-label",children:["Wall ",u+1]}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,Z.jsx)("input",{"aria-label":`Wall ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:m.height,onChange:g=>D(a,u,"height",g.target.value)})]}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,Z.jsx)("input",{"aria-label":`Wall ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:m.width,onChange:g=>D(a,u,"width",g.target.value)})]}),t.length>1?(0,Z.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>a(g=>g.filter((v,N)=>N!==u)),children:"Remove"}):null]},`wall-${u}`)),(0,Z.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>a(m=>[...m,lc()]),children:"+ Add another wall"})]}),(0,Z.jsxs)("div",{className:"paint-calculator__section",children:[(0,Z.jsx)("div",{className:"truss-estimator__section-heading",children:"Areas to exclude"}),(0,Z.jsx)("p",{className:"paint-calculator__hint",children:"Add windows, sockets, skirting boards or other areas that will not be painted."}),(0,Z.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,Z.jsx)("span",{}),(0,Z.jsx)("span",{children:"Height (m)"}),(0,Z.jsx)("span",{children:"Width (m)"}),(0,Z.jsx)("span",{})]}),r.map((m,u)=>(0,Z.jsxs)("div",{className:"paint-calculator__row",children:[(0,Z.jsxs)("span",{className:"paint-calculator__row-label",children:["Area ",u+1]}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,Z.jsx)("input",{"aria-label":`Area ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:m.height,onChange:g=>D(n,u,"height",g.target.value)})]}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,Z.jsx)("input",{"aria-label":`Area ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:m.width,onChange:g=>D(n,u,"width",g.target.value)})]}),r.length>1?(0,Z.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>n(g=>g.filter((v,N)=>N!==u)),children:"Remove"}):null]},`excluded-${u}`)),(0,Z.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>n(m=>[...m,lc()]),children:"+ Add another area"})]}),(0,Z.jsxs)("div",{className:"paint-calculator__section",children:[(0,Z.jsx)("div",{className:"truss-estimator__section-heading",children:"Doors and coats"}),(0,Z.jsx)("p",{className:"paint-calculator__hint",children:"Enter the number of standard single and double doors to leave unpainted. Door sizes are estimated automatically."}),(0,Z.jsxs)("div",{className:"truss-estimator__field-grid paint-calculator__small-fields",children:[(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{children:"Doors"}),(0,Z.jsx)("input",{type:"number",min:"0",step:"1",value:i,onChange:m=>o(m.target.value)})]}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{children:"Double doors"}),(0,Z.jsx)("input",{type:"number",min:"0",step:"1",value:l,onChange:m=>c(m.target.value)})]})]}),(0,Z.jsxs)("div",{className:"paint-calculator__coat-field",children:[(0,Z.jsx)("p",{className:"paint-calculator__hint",children:"Most walls need 2 coats for an even finish. Use 3 coats when changing colour significantly or covering a darker wall."}),(0,Z.jsxs)("label",{className:"truss-estimator__field",children:[(0,Z.jsx)("span",{children:"Number of coats"}),(0,Z.jsxs)("select",{value:p,onChange:m=>f(Number(m.target.value)),children:[(0,Z.jsx)("option",{value:"1",children:"1 coat"}),(0,Z.jsx)("option",{value:"2",children:"2 coats"}),(0,Z.jsx)("option",{value:"3",children:"3 coats"})]})]})]})]}),(0,Z.jsxs)("div",{className:"paint-calculator__totals",children:[(0,Z.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,Z.jsxs)("div",{className:"paint-calculator__result-grid",children:[(0,Z.jsxs)("div",{children:[(0,Z.jsx)("span",{children:"Paintable area"}),(0,Z.jsxs)("strong",{children:[w.toFixed(2)," m\xB2"]})]}),(0,Z.jsxs)("div",{children:[(0,Z.jsx)("span",{children:"Coverage"}),(0,Z.jsxs)("strong",{children:[p," ",p===1?"coat":"coats"]})]}),(0,Z.jsxs)("div",{children:[(0,Z.jsx)("span",{children:"Paint required"}),(0,Z.jsxs)("strong",{children:[E.toFixed(1)," litres"]})]})]}),(0,Z.jsx)("p",{className:"paint-calculator__note",children:"Based on paint coverage of 10 m\xB2 per litre. Decorative paint is not currently stocked in this catalogue, so this remains an estimate only."})]}),(0,Z.jsxs)("div",{className:"paint-calculator__actions",children:[(0,Z.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,Z.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",disabled:!0,children:"Paint products unavailable"})]})]})]})})}var gr=Y(Ke()),re=Y(ae()),cc=e=>Number.parseFloat(e)||0,zd={paving:[{id:"council",label:"Council paving slab (600 \xD7 600mm)"},{id:"raj",label:"Raj blend sandstone (600 \xD7 600mm)"}],block:[{id:"brindle",label:"Brindle block paving (60mm)"},{id:"charcoal",label:"Charcoal block paving (60mm)"}],gravel:[{id:"pea",label:"20mm pea shingle"}]};function Ad({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,gr.useState)("paving"),[i,o]=(0,gr.useState)("council"),[l,c]=(0,gr.useState)(""),[p,f]=(0,gr.useState)(""),[b,d]=(0,gr.useState)("100"),[h,w]=(0,gr.useState)("50"),[E,D]=(0,gr.useState)(!0),[m,u]=(0,gr.useState)(!0),g=cc(l)*cc(p),v=g,N=g*(cc(b)/1e3),R=g*.04,T=g*(cc(h)/1e3),z=Math.ceil(v/.36),G=Math.ceil(v/.1),K=Math.ceil(N*1700/800),xe=Math.ceil(R*1600/800),Ee=Math.ceil(T*1600/800),Ge=r==="paving"?{qty:z,unit:"each"}:r==="block"?{qty:v,unit:"m2"}:{qty:Ee,unit:"bag"},Qe={paving:"paving slab",block:"block paver",gravel:"decorative gravel"}[r],Ie=[{key:`surface-${i}`,label:zd[r].find(Q=>Q.id===i)?.label??"Surface material",qty:Ge.qty,unit:Ge.unit,query:Qe,category:"landscaping"},...E?[{key:"sub-base",label:"MOT Type 1 sub-base",qty:K,unit:"bag",query:"MOT Type 1 sub base",category:"aggregate"}]:[],...m?[{key:"bedding",label:"Sharp sand bedding",qty:xe,unit:"bag",query:"sharp sand",category:"aggregate"}]:[]];return(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{className:"truss-estimator",children:[(0,re.jsxs)("div",{className:"quick-order-hero",children:[(0,re.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,re.jsx)("h1",{children:"Paving & Driveway Calculator"}),(0,re.jsx)("p",{children:"Estimate paving, block paving, sub-base and bedding materials for outdoor areas."})]}),(0,re.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,re.jsx)("h2",{className:"truss-estimator__step-title",children:"Surface and ground build-up"}),(0,re.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the surface material and enter the area. Sub-base and bedding sand are estimated alongside the surface units."}),(0,re.jsxs)("div",{className:"materials-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Surface material"}),(0,re.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:[["paving","Paving slabs","For patios and paths"],["block","Block paving","For driveways and paths"],["gravel","Decorative gravel","For paths and landscaping"]].map(([Q,se,Ne])=>(0,re.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===Q?" is-selected":""}`,onClick:()=>{n(Q),o(zd[Q][0].id)},children:[(0,re.jsx)("div",{className:"truss-estimator__option-title",children:se}),(0,re.jsx)("div",{className:"truss-estimator__option-copy",children:Ne})]},Q))}),(0,re.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,re.jsx)("span",{children:"Finish"}),(0,re.jsx)("select",{value:i,onChange:Q=>o(Q.target.value),children:zd[r].map(Q=>(0,re.jsx)("option",{value:Q.id,children:Q.label},Q.id))})]})]}),(0,re.jsxs)("div",{className:"materials-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and groundwork"}),(0,re.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,re.jsxs)("label",{className:"truss-estimator__field",children:[(0,re.jsx)("span",{children:"Length (m)"}),(0,re.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:Q=>c(Q.target.value)})]}),(0,re.jsxs)("label",{className:"truss-estimator__field",children:[(0,re.jsx)("span",{children:"Width (m)"}),(0,re.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:Q=>f(Q.target.value)})]})]}),r==="gravel"&&(0,re.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,re.jsx)("span",{children:"Gravel depth (mm)"}),(0,re.jsx)("input",{type:"number",min:"0",step:"10",value:h,onChange:Q=>w(Q.target.value)})]}),E&&(0,re.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,re.jsx)("span",{children:"Sub-base depth (mm)"}),(0,re.jsx)("input",{type:"number",min:"0",step:"10",value:b,onChange:Q=>d(Q.target.value)})]}),(0,re.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,re.jsx)("input",{type:"checkbox",checked:E,onChange:Q=>D(Q.target.checked)}),(0,re.jsx)("span",{children:"Include MOT Type 1 sub-base"})]}),(0,re.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,re.jsx)("input",{type:"checkbox",checked:m,onChange:Q=>u(Q.target.checked)}),(0,re.jsx)("span",{children:"Include sharp sand bedding"})]})]}),(0,re.jsxs)("div",{className:"materials-calculator__totals",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,re.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Surface area"}),(0,re.jsxs)("strong",{children:[g.toFixed(2)," m\xB2"]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:r==="paving"?"Paving slabs":r==="block"?"Block paving":"Gravel"}),(0,re.jsx)("strong",{children:r==="paving"?`${z} slabs`:r==="block"?`${v.toFixed(2)} m\xB2`:`${Ee} bulk bags`})]}),E&&(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"MOT Type 1"}),(0,re.jsxs)("strong",{children:[K," bulk bags"]})]}),m&&(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Sharp sand"}),(0,re.jsxs)("strong",{children:[xe," bulk bags"]})]})]}),(0,re.jsx)("p",{className:"materials-calculator__note",children:"Slab and block quantities use typical sizes. Confirm pack coverage and laying pattern before ordering."})]}),(0,re.jsxs)("div",{className:"materials-calculator__actions",children:[(0,re.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,re.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(Ie),disabled:g<=0,children:a})]})]})]})})}var il=Y(Ke()),ie=Y(ae()),G_=2.88,_w=[{id:"standard",label:"Standard wallboard",blurb:"General internal walls and ceilings"},{id:"moisture",label:"Moisture resistant",blurb:"Kitchens, bathrooms and utility rooms"},{id:"fire",label:"Fire resistant",blurb:"Where fire-rated lining is required"},{id:"sound",label:"Sound resistant",blurb:"Improved acoustic performance"}],xw=()=>({length:"",height:""}),Rd=e=>Number.parseFloat(e)||0;function Ud({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,il.useState)([xw()]),[i,o]=(0,il.useState)(""),[l,c]=(0,il.useState)("standard"),[p,f]=(0,il.useState)("screws"),b=r.reduce((R,T)=>R+Rd(T.length)*Rd(T.height),0),d=Math.max(0,b-Rd(i)),h=Math.ceil(d/G_),w=Math.ceil(d*12),E=Math.ceil(w/1e3),D=Math.ceil(d*1.2),m=Math.ceil(D/90),u=Math.ceil(d/3.5),g=_w.find(R=>R.id===l)?.label??"Standard",v=[{key:"board",label:`${g} plasterboard`,qty:h,unit:"sheet",query:`${g} plasterboard`,category:"plasterboard"},...p==="screws"?[{key:"screws",label:"Drywall screws",qty:E,unit:"box",query:"drywall screws",category:"fixings"}]:[{key:"adhesive",label:"Board adhesive",qty:u,unit:"bag",query:"drywall board adhesive",category:"plasterboard"}],{key:"tape",label:"Joint tape",qty:m,unit:"roll",query:"plasterboard joint tape",category:"plasterboard"}],N=(R,T,z)=>{n(G=>G.map((K,xe)=>xe===R?{...K,[T]:z}:K))};return(0,ie.jsx)(ie.Fragment,{children:(0,ie.jsxs)("div",{className:"truss-estimator",children:[(0,ie.jsxs)("div",{className:"quick-order-hero",children:[(0,ie.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ie.jsx)("h1",{children:"Plasterboard & Drylining Calculator"}),(0,ie.jsx)("p",{children:"Estimate boards, fixings and jointing materials for walls and ceilings."})]}),(0,ie.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,ie.jsx)("h2",{className:"truss-estimator__step-title",children:"Boards, fixings and jointing"}),(0,ie.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter the surfaces you are lining and the board specification. Screws, tape and adhesive are estimated with the boards."}),(0,ie.jsxs)("div",{className:"materials-calculator__section",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Board type"}),(0,ie.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:_w.map(R=>(0,ie.jsxs)("button",{type:"button",className:`truss-estimator__option-card${l===R.id?" is-selected":""}`,onClick:()=>c(R.id),children:[(0,ie.jsx)("div",{className:"truss-estimator__option-title",children:R.label}),(0,ie.jsx)("div",{className:"truss-estimator__option-copy",children:R.blurb})]},R.id))})]}),(0,ie.jsxs)("div",{className:"materials-calculator__section",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Fixing method"}),(0,ie.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["screws","Drywall screws","For timber or metal framing"],["adhesive","Board adhesive","For masonry dot-and-dab"]].map(([R,T,z])=>(0,ie.jsxs)("button",{type:"button",className:`truss-estimator__option-card${p===R?" is-selected":""}`,onClick:()=>f(R),children:[(0,ie.jsx)("div",{className:"truss-estimator__option-title",children:T}),(0,ie.jsx)("div",{className:"truss-estimator__option-copy",children:z})]},R))})]}),(0,ie.jsxs)("div",{className:"materials-calculator__section",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall and ceiling areas"}),(0,ie.jsx)("p",{className:"materials-calculator__hint",children:"Add each surface separately so different wall sizes are easy to measure."}),(0,ie.jsxs)("div",{className:"materials-calculator__dimensions-header",children:[(0,ie.jsx)("span",{children:"Surface"}),(0,ie.jsx)("span",{children:"Length (m)"}),(0,ie.jsx)("span",{children:"Height (m)"}),(0,ie.jsx)("span",{})]}),r.map((R,T)=>(0,ie.jsxs)("div",{className:"materials-calculator__surface-row",children:[(0,ie.jsxs)("span",{children:["Surface ",T+1]}),(0,ie.jsx)("input",{"aria-label":`Surface ${T+1} length`,type:"number",min:"0",step:"0.01",value:R.length,onChange:z=>N(T,"length",z.target.value)}),(0,ie.jsx)("input",{"aria-label":`Surface ${T+1} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:z=>N(T,"height",z.target.value)}),r.length>1?(0,ie.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>n(z=>z.filter((G,K)=>K!==T)),children:"Remove"}):null]},`surface-${T}`)),(0,ie.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>n(R=>[...R,xw()]),children:"+ Add another surface"}),(0,ie.jsxs)("label",{className:"truss-estimator__field materials-calculator__openings",children:[(0,ie.jsxs)("span",{children:["Openings to deduct (m\xB2) ",(0,ie.jsx)("small",{children:"optional"})]}),(0,ie.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:R=>o(R.target.value)})]})]}),(0,ie.jsxs)("div",{className:"materials-calculator__totals",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ie.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:"Board area"}),(0,ie.jsxs)("strong",{children:[d.toFixed(2)," m\xB2"]})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:"2.4 x 1.2 m boards"}),(0,ie.jsx)("strong",{children:h})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:p==="screws"?"Drywall screws":"Board adhesive"}),(0,ie.jsx)("strong",{children:p==="screws"?`${w} (${E} boxes)`:`${u} bags`})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:"Joint tape"}),(0,ie.jsxs)("strong",{children:[D," m (",m," rolls)"]})]})]}),(0,ie.jsx)("p",{className:"materials-calculator__note",children:"Figures are estimates. Confirm board specification, fixing patterns and fire or acoustic requirements before ordering."})]}),(0,ie.jsxs)("div",{className:"materials-calculator__actions",children:[(0,ie.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ie.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(v),disabled:d<=0,children:a})]})]})]})})}var nl=Y(Ke());var y=Y(ae()),At={ranges:{standard:{label:"Standard Fink",blurb:"Classic W-shaped truss for standard pitched roofs."},attic:{label:"Attic",blurb:"Room-in-roof truss with usable attic space and clear span."},mono:{label:"Mono-pitch",blurb:"Single-slope truss for lean-to roofs and outbuildings."}},pitches:["15","20","22.5","25","30","35","40","45","50","55"],pitchMultipliers:{15:.95,20:.98,"22.5":1,25:1.02,30:1.05,35:1.1,40:1.18,45:1.27,50:1.38,55:1.52},overhang:{thresholdMM:300,surchargePerTruss:3.5},centresOptions:["400","600"],treatment:{treated:{label:"Treated (tanalised)",surchargePct:.08},untreated:{label:"Untreated",surchargePct:0}},estimate:{design:250,delivery:250,bracingPerMetre:6.5,girderMultiplier:1.8,ranges:{standard:{supplyAt8m:53.33,installPerTruss:30},attic:{supplyAt8m:128.35,installPerTruss:55},mono:{supplyAt8m:60,installPerTruss:38}}}},uc=["range","pitchAndDimensions","quantityAndGirders","bracing"],Q_={range:null,pitch:null,spanMM:"",overhangMM:"",roofLengthM:"",centres:null,girderCount:0,bracing:null,treatment:null,contact:{name:"",email:""}};function Y_({degrees:e}){let a=e*Math.PI/180,n=82-Math.min(58,38*Math.tan(a));return(0,y.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,y.jsx)("line",{x1:"6",y1:"82",x2:"94",y2:"82",stroke:"var(--border)",strokeWidth:"2"}),(0,y.jsx)("polygon",{points:`12,82 88,82 50,${n}`,fill:"var(--accent-light)",stroke:"var(--accent)",strokeWidth:"3",strokeLinejoin:"round"})]})}function V_({type:e}){let t="#b3835a",a="#5c3b22",r="#d9b48f",n="#d3d8de",i="#7c8494",o=(f,b,d,h,w=8,E)=>{let D=d-f,m=h-b,u=Math.hypot(D,m)||1,g=-m/u,v=D/u,N=w*.2;return(0,y.jsxs)("g",{children:[(0,y.jsx)("line",{x1:f,y1:b,x2:d,y2:h,stroke:a,strokeWidth:w+3,strokeLinecap:"square"}),(0,y.jsx)("line",{x1:f,y1:b,x2:d,y2:h,stroke:t,strokeWidth:w,strokeLinecap:"square"}),(0,y.jsx)("line",{x1:f-g*N,y1:b-v*N,x2:d-g*N,y2:h-v*N,stroke:r,strokeWidth:Math.max(1.5,w*.24),strokeLinecap:"round",opacity:"0.9"})]},E)},l=(f,b,d)=>(0,y.jsxs)("g",{children:[(0,y.jsx)("rect",{x:f-7.5,y:b-5.5,width:"15",height:"11",rx:"2",fill:n,stroke:i,strokeWidth:"1"}),(0,y.jsx)("circle",{cx:f-4,cy:b-2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:f+4,cy:b-2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:f-4,cy:b+2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:f+4,cy:b+2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:f,cy:b,r:"1",fill:i})]},d),c=(f,b)=>(0,y.jsx)("rect",{x:f-9,y:"110",width:"18",height:"10",fill:a},b),p=(0,y.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"});return e==="attic"?(0,y.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[p,c(26,"wl"),c(174,"wr"),o(26,112,100,26,8,"b1"),o(174,112,100,26,8,"b2"),o(26,112,174,112,8,"b3"),o(58,112,58,70,6,"b4"),o(142,112,142,70,6,"b5"),o(58,70,142,70,7,"b6"),(0,y.jsx)("rect",{x:"90",y:"82",width:"20",height:"24",fill:"#cfe3f2",stroke:a,strokeWidth:"2"}),(0,y.jsx)("line",{x1:"100",y1:"82",x2:"100",y2:"106",stroke:a,strokeWidth:"1.5"}),l(26,112,"p1"),l(174,112,"p2"),l(100,26,"p3"),l(58,112,"p4"),l(58,70,"p5"),l(142,112,"p6"),l(142,70,"p7")]}):e==="mono"?(0,y.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[p,c(26,"wl"),c(174,"wr"),o(26,112,174,26,8,"b1"),o(174,26,174,112,8,"b2"),o(26,112,174,112,8,"b3"),o(90,112,90,75,5,"b4"),o(90,75,132,112,5,"b5"),l(26,112,"p1"),l(174,26,"p2"),l(174,112,"p3"),l(90,112,"p4"),l(90,75,"p5"),l(132,112,"p6")]}):(0,y.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[p,c(26,"wl"),c(174,"wr"),o(26,112,100,34,8,"b1"),o(174,112,100,34,8,"b2"),o(26,112,174,112,8,"b3"),o(63,112,100,34,5,"b4"),o(137,112,100,34,5,"b5"),o(63,112,54,83,5,"b6"),o(137,112,146,83,5,"b7"),(0,y.jsx)("rect",{x:"96",y:"108",width:"8",height:"8",fill:a}),l(26,112,"p1"),l(174,112,"p2"),l(100,34,"p3"),l(63,112,"p4"),l(137,112,"p5"),l(54,83,"p6"),l(146,83,"p7")]})}function X_({enabled:e}){return(0,y.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[(0,y.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"}),(0,y.jsx)("rect",{x:"17",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,y.jsx)("rect",{x:"165",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,y.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,y.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,y.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,y.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,y.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,y.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),e?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("line",{x1:"45",y1:"112",x2:"140",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"}),(0,y.jsx)("line",{x1:"155",y1:"112",x2:"60",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"})]}):null,(0,y.jsx)("rect",{x:"18.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,y.jsx)("rect",{x:"166.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,y.jsx)("rect",{x:"92.5",y:"28.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"})]})}function kw({treated:e}){let t=e?"#5a7a4a":"var(--accent)";return(0,y.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,y.jsx)("rect",{x:"10",y:"22",width:"80",height:"14",rx:"2",fill:t}),(0,y.jsx)("rect",{x:"10",y:"43",width:"80",height:"14",rx:"2",fill:e?"#8faf7a":"var(--accent-light)"}),(0,y.jsx)("rect",{x:"10",y:"64",width:"80",height:"14",rx:"2",fill:t})]})}function Dd({onBack:e}){let[t,a]=(0,nl.useState)(0),[r,n]=(0,nl.useState)(Q_),[i,o]=(0,nl.useState)(!1),[l,c]=(0,nl.useState)(!1),p=()=>{let m=Number.parseFloat(r.roofLengthM)||0,u=Number.parseFloat(r.centres??"");return m<=0||!u?0:Math.ceil(m*1e3/u)+1},b=(()=>{let m=r.range?At.ranges[r.range]:At.ranges.standard,u=r.pitch??"22.5",g=At.pitchMultipliers[u],v=(Number.parseFloat(r.spanMM)||0)/1e3,R=(Number.parseFloat(r.overhangMM)||0)>At.overhang.thresholdMM,T=p(),z=T+r.girderCount,G=Number.parseFloat(r.roofLengthM)||0,K=r.treatment?At.treatment[r.treatment]:At.treatment.untreated,xe=At.estimate.ranges[r.range??"standard"],Ee=xe.supplyAt8m*Math.max(.7,v/8)*g*(1+K.surchargePct)+(R?At.overhang.surchargePerTruss:0),Ge=T*Ee,Qe=r.girderCount*Ee*At.estimate.girderMultiplier,Ie=r.bracing==="yes"?G*At.estimate.bracingPerMetre:0,ue=Ge+Qe+Ie+At.estimate.delivery,Q=At.estimate.design+T*xe.installPerTruss+r.girderCount*40,se=ue+Q,Ne=se*.2;return{range:m,count:T,girderCount:r.girderCount,overhangApplies:R,overhangUnits:z,roofLengthM:G,treatment:K,trussSupply:Ge,bracingMaterials:Ie,delivery:At.estimate.delivery,labour:Q,subtotal:se,vat:Ne,total:se+Ne}})(),d=()=>{let m=uc[t];return m==="range"?!!r.range:m==="pitchAndDimensions"?!!r.pitch&&r.spanMM.trim()!==""&&r.overhangMM.trim()!=="":m==="quantityAndGirders"?r.roofLengthM.trim()!==""&&!!r.centres:m==="bracing"?!!r.bracing&&!!r.treatment:!0},h=t===uc.length-1?"View truss request":"Next",w=()=>{i?o(!1):t===0?e():a(m=>m-1)},E=()=>{d()&&(t===uc.length-1?(c(!1),o(!0)):a(m=>m+1))},D=()=>{let m=uc[t];return m==="range"?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Step 1 of 4"}),(0,y.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your truss range"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"Pricing shown is placeholder. Swap in your real engineering and pricing catalogue."}),(0,y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--range",children:Object.entries(At.ranges).map(([u,g])=>(0,y.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r.range===u?" is-selected":""}`,onClick:()=>n(v=>({...v,range:u})),children:[(0,y.jsx)(V_,{type:u}),(0,y.jsxs)("div",{className:"truss-estimator__option-info",children:[(0,y.jsx)("div",{className:"truss-estimator__option-title",children:g.label}),(0,y.jsx)("div",{className:"truss-estimator__option-copy",children:g.blurb})]})]},u))})]}):m==="pitchAndDimensions"?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Step 2 of 4"}),(0,y.jsx)("h2",{className:"truss-estimator__step-title",children:"Span, overhang and roof pitch"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"Span is wall-to-wall, overhang is the eaves tail beyond the wall line. Steeper pitches use more timber per truss."}),(0,y.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,y.jsxs)("label",{className:"truss-estimator__field",children:[(0,y.jsx)("span",{children:"Span (mm)"}),(0,y.jsx)("input",{type:"text",inputMode:"numeric",value:r.spanMM,onChange:u=>n(g=>({...g,spanMM:u.target.value}))})]}),(0,y.jsxs)("label",{className:"truss-estimator__field",children:[(0,y.jsx)("span",{children:"Overhang (mm)"}),(0,y.jsx)("input",{type:"text",inputMode:"numeric",value:r.overhangMM,onChange:u=>n(g=>({...g,overhangMM:u.target.value}))}),(0,y.jsxs)("small",{children:["Overhangs beyond ",At.overhang.thresholdMM,"mm add a small surcharge per truss."]})]})]}),(0,y.jsx)("div",{className:"truss-estimator__section-heading",children:"Roof pitch"}),(0,y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:At.pitches.map(u=>(0,y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${r.pitch===u?" is-selected":""}`,onClick:()=>n(g=>({...g,pitch:u})),children:[(0,y.jsx)(Y_,{degrees:Number.parseFloat(u)}),(0,y.jsxs)("span",{children:[u,"\xB0"]})]},u))})]}):m==="quantityAndGirders"?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Step 3 of 4"}),(0,y.jsx)("h2",{className:"truss-estimator__step-title",children:"Roof length"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"Trusses are based on designs at 400mm or 600mm centres wherever possible."}),(0,y.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,y.jsx)("span",{children:"Roof length (m)"}),(0,y.jsx)("input",{type:"text",inputMode:"decimal",value:r.roofLengthM,onChange:u=>n(g=>({...g,roofLengthM:u.target.value}))})]}),(0,y.jsx)("div",{className:"truss-estimator__section-heading",children:"Truss centres"}),(0,y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--centres",children:At.centresOptions.map(u=>(0,y.jsx)("button",{type:"button",className:`truss-estimator__option-card truss-estimator__option-card--compact${r.centres===u?" is-selected":""}`,onClick:()=>n(g=>({...g,centres:u})),children:(0,y.jsxs)("div",{className:"truss-estimator__option-title",children:[u,"mm centres"]})},u))}),(0,y.jsxs)("div",{className:"truss-estimator__stat",children:[p()," trusses estimated"]}),(0,y.jsx)("div",{className:"truss-estimator__section-heading",children:"Girder trusses"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"Heavy-duty girder trusses carry point loads over large openings. Set 0 if you do not need any."}),(0,y.jsxs)("div",{className:"truss-estimator__stepper",children:[(0,y.jsx)("button",{type:"button",onClick:()=>n(u=>({...u,girderCount:Math.max(0,u.girderCount-1)})),children:"\u2212"}),(0,y.jsx)("span",{children:r.girderCount}),(0,y.jsx)("button",{type:"button",onClick:()=>n(u=>({...u,girderCount:Math.min(3,u.girderCount+1)})),children:"+"})]})]}):m==="bracing"?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Step 4 of 4"}),(0,y.jsx)("h2",{className:"truss-estimator__step-title",children:"Bracing pack?"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"A timber bracing pack stabilises the roof structure once trusses are erected."}),(0,y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"no",label:"No bracing pack"},{id:"yes",label:"Add bracing pack"}].map(u=>(0,y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.bracing===u.id?" is-selected":""}`,onClick:()=>n(g=>({...g,bracing:u.id})),children:[(0,y.jsx)(X_,{enabled:u.id==="yes"}),(0,y.jsx)("span",{children:u.label})]},u.id))}),(0,y.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber treatment"}),(0,y.jsx)("p",{className:"truss-estimator__step-sub",children:"Tanalised timber protects against rot in exposed or damp locations."}),(0,y.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.treatment==="untreated"?" is-selected":""}`,onClick:()=>n(u=>({...u,treatment:"untreated"})),children:[(0,y.jsx)(kw,{treated:!1}),(0,y.jsx)("span",{children:"Untreated"})]}),(0,y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.treatment==="treated"?" is-selected":""}`,onClick:()=>n(u=>({...u,treatment:"treated"})),children:[(0,y.jsx)(kw,{treated:!0}),(0,y.jsx)("span",{children:"Treated (+8% cost)"}),(0,y.jsx)("small",{children:"Applies to trusses, girders and overhang"})]})]})]}):null};return i?(0,y.jsx)(y.Fragment,{children:(0,y.jsxs)("div",{className:"truss-estimator",children:[(0,y.jsxs)("div",{className:"quick-order-hero",children:[(0,y.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,y.jsx)("h1",{children:"Your truss estimate"}),(0,y.jsx)("p",{children:"A provisional quantity and specification based on the dimensions you entered."})]}),(0,y.jsxs)("div",{className:"truss-estimator__card truss-request",style:{minHeight:0},children:[(0,y.jsxs)("div",{className:"truss-request__heading",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Estimated requirement"}),(0,y.jsxs)("h2",{children:[b.range.label," roof trusses"]})]}),(0,y.jsxs)("strong",{children:[b.count,(0,y.jsx)("span",{children:"trusses"})]})]}),(0,y.jsxs)("div",{className:"truss-request__grid",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Span"}),(0,y.jsxs)("strong",{children:[r.spanMM," mm"]})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Roof length"}),(0,y.jsxs)("strong",{children:[r.roofLengthM," m"]})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Pitch"}),(0,y.jsxs)("strong",{children:[r.pitch,"\xB0"]})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Centres"}),(0,y.jsxs)("strong",{children:[r.centres," mm"]})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Overhang"}),(0,y.jsxs)("strong",{children:[r.overhangMM," mm"]})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Treatment"}),(0,y.jsx)("strong",{children:b.treatment.label})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Girder trusses"}),(0,y.jsx)("strong",{children:b.girderCount||"None"})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Bracing pack"}),(0,y.jsx)("strong",{children:r.bracing==="yes"?"Included":"Not included"})]})]}),(0,y.jsxs)("div",{className:"truss-request__price",children:[(0,y.jsx)("div",{className:"truss-estimator__step-label",children:"Indicative cost estimate"}),(0,y.jsxs)("div",{className:"truss-request__price-grid",children:[(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Truss supply allowance"}),(0,y.jsx)("strong",{children:st(b.trussSupply)})]}),b.bracingMaterials>0&&(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Bracing materials allowance"}),(0,y.jsx)("strong",{children:st(b.bracingMaterials)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Delivery allowance"}),(0,y.jsx)("strong",{children:st(b.delivery)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Design and installation labour"}),(0,y.jsx)("strong",{children:st(b.labour)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Subtotal (ex. VAT)"}),(0,y.jsx)("strong",{children:st(b.subtotal)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"VAT (20%)"}),(0,y.jsx)("strong",{children:st(b.vat)})]}),(0,y.jsxs)("div",{className:"truss-request__price-total",children:[(0,y.jsx)("span",{children:"Estimated total"}),(0,y.jsx)("strong",{children:st(b.total)})]})]}),(0,y.jsx)("p",{children:"Trusses are not listed as fixed products in this catalogue, so supply, delivery and labour are benchmark allowances. Confirm the engineered design and final quote before ordering."})]}),(0,y.jsxs)("div",{className:"truss-request__notice",children:[(0,y.jsx)("strong",{children:"Before ordering"}),(0,y.jsx)("span",{children:"Roof trusses must be designed and signed off for the building. Confirm loading, bearings, wind bracing and final drawings with the truss manufacturer."})]}),(0,y.jsxs)("div",{className:"truss-estimator__nav",children:[(0,y.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:w,children:"Back to calculator"}),(0,y.jsx)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",justifyContent:"center",marginTop:0},onClick:()=>c(!0),children:"Request order"})]}),l&&(0,y.jsx)("p",{className:"truss-request__demo",children:"Demo only \u2014 no order has been sent."})]})]})}):(0,y.jsx)(y.Fragment,{children:(0,y.jsxs)("div",{className:"truss-estimator",children:[(0,y.jsxs)("div",{className:"quick-order-hero",children:[(0,y.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,y.jsx)("h1",{children:"Roof Truss Calculator"}),(0,y.jsx)("p",{children:"Estimate trusses, girders and cost for your roof in a few steps."})]}),(0,y.jsxs)("div",{className:"truss-estimator__card",children:[(0,y.jsx)("div",{className:"truss-estimator__body",children:D()}),(0,y.jsxs)("div",{className:"truss-estimator__nav",children:[(0,y.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:w,children:"Back"}),(0,y.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:E,disabled:!d(),children:[(0,y.jsx)("span",{children:h}),(0,y.jsx)("span",{className:"arrow",children:(0,y.jsx)(Ht,{})})]})]})]})]})})}var qi=Y(Ke()),F=Y(ae()),Cw=e=>Number.parseFloat(e)||0,pc=(e,t)=>Cw(e)*(t==="m"?1:.3048),Nw=()=>({length:"",width:""}),Sw=[{id:"chamfered",label:"Chamfered",blurb:"Clean angled edge"},{id:"ogee",label:"Ogee",blurb:"Traditional curved profile"},{id:"pencil-round",label:"Pencil round",blurb:"Simple softened edge"},{id:"torus",label:"Torus",blurb:"Soft rounded detail"}];function $_({profile:e}){return(0,F.jsxs)("svg",{className:"skirting-calculator__profile-diagram",viewBox:"0 0 120 84","aria-hidden":"true",children:[(0,F.jsx)("path",{d:{chamfered:"M16 70V43L43 16H104V70Z",ogee:"M16 70V47C16 36 27 31 40 31C40 21 50 16 63 16H104V70Z","pencil-round":"M16 70V37C16 25 25 16 37 16H104V70Z",torus:"M16 70V49C16 39 25 34 36 34C36 22 47 16 61 16H104V70Z"}[e]}),(0,F.jsx)("line",{x1:"12",y1:"70",x2:"108",y2:"70"})]})}function Bd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,qi.useState)("total"),[i,o]=(0,qi.useState)("m"),[l,c]=(0,qi.useState)(""),[p,f]=(0,qi.useState)([Nw()]),[b,d]=(0,qi.useState)(""),[h,w]=(0,qi.useState)("chamfered"),E="4.2",D=r==="total"?pc(l,i):p.reduce((N,R)=>N+2*(pc(R.length,i)+pc(R.width,i)),0),m=Math.max(0,D-pc(b,i)),u=Math.ceil(m/Cw(E)),g=[{key:`skirting-${h}`,label:`${Sw.find(N=>N.id===h)?.label} skirting board`,qty:m,unit:"m",query:"skirting board",category:"skirting"}],v=(N,R,T)=>{f(z=>z.map((G,K)=>K===N?{...G,[R]:T}:G))};return(0,F.jsx)(F.Fragment,{children:(0,F.jsxs)("div",{className:"truss-estimator",children:[(0,F.jsxs)("div",{className:"quick-order-hero",children:[(0,F.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,F.jsx)("h1",{children:"Skirting Board Calculator"}),(0,F.jsx)("p",{children:"Work out how many skirting board lengths you need for one room or a whole project."})]}),(0,F.jsxs)("div",{className:"truss-estimator__card skirting-calculator",children:[(0,F.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure by room or total length"}),(0,F.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter a single total or work room by room. The run is converted straight into board lengths."}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"How would you like to measure?"}),(0,F.jsxs)("div",{className:"brick-calculator__unit-toggle skirting-calculator__mode-toggle",role:"group","aria-label":"Calculation method",children:[(0,F.jsx)("button",{type:"button",className:r==="total"?"is-selected":"",onClick:()=>n("total"),children:"Total length"}),(0,F.jsx)("button",{type:"button",className:r==="rooms"?"is-selected":"",onClick:()=>n("rooms"),children:"Room by room"})]})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Measurements"}),(0,F.jsxs)("div",{className:"skirting-calculator__unit-row",children:[(0,F.jsx)("span",{children:"Units"}),(0,F.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,F.jsx)("button",{type:"button",className:i==="m"?"is-selected":"",onClick:()=>o("m"),children:"Metres"}),(0,F.jsx)("button",{type:"button",className:i==="ft"?"is-selected":"",onClick:()=>o("ft"),children:"Feet"})]})]}),r==="total"?(0,F.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,F.jsxs)("span",{children:["Total skirting length (",i,")"]}),(0,F.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:N=>c(N.target.value)})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)("div",{className:"skirting-calculator__dimensions-header",children:[(0,F.jsx)("span",{children:"Room"}),(0,F.jsxs)("span",{children:["Length (",i,")"]}),(0,F.jsxs)("span",{children:["Width (",i,")"]}),(0,F.jsx)("span",{})]}),p.map((N,R)=>(0,F.jsxs)("div",{className:"skirting-calculator__room-row",children:[(0,F.jsxs)("span",{className:"skirting-calculator__room-label",children:["Room ",R+1]}),(0,F.jsx)("input",{"aria-label":`Room ${R+1} length in ${i}`,type:"number",min:"0",step:"0.01",value:N.length,onChange:T=>v(R,"length",T.target.value)}),(0,F.jsx)("input",{"aria-label":`Room ${R+1} width in ${i}`,type:"number",min:"0",step:"0.01",value:N.width,onChange:T=>v(R,"width",T.target.value)}),p.length>1?(0,F.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>f(T=>T.filter((z,G)=>G!==R)),children:"Remove"}):null]},`room-${R}`)),(0,F.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>f(N=>[...N,Nw()]),children:"+ Add another room"})]}),(0,F.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,F.jsxs)("span",{children:["Openings and doorways to deduct (",i,") ",(0,F.jsx)("small",{children:"optional"})]}),(0,F.jsx)("input",{type:"number",min:"0",step:"0.01",value:b,onChange:N=>d(N.target.value)})]})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Profile"}),(0,F.jsx)("p",{className:"skirting-calculator__hint",children:"Choose the finish you want for the fixed 4.2m white-primed MDF boards."}),(0,F.jsx)("div",{className:"architrave-calculator__profiles",children:Sw.map(N=>(0,F.jsxs)("button",{type:"button",className:`truss-estimator__option-card${h===N.id?" is-selected":""}`,onClick:()=>w(N.id),children:[(0,F.jsx)($_,{profile:N.id}),(0,F.jsx)("div",{className:"truss-estimator__option-title",children:N.label}),(0,F.jsx)("div",{className:"truss-estimator__option-copy",children:N.blurb})]},N.id))})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,F.jsx)("div",{className:"truss-estimator__field-grid skirting-calculator__options-grid",children:(0,F.jsxs)("label",{className:"truss-estimator__field",children:[(0,F.jsx)("span",{children:"Board length"}),(0,F.jsx)("input",{value:"4.20 m",disabled:!0})]})}),(0,F.jsx)("p",{className:"skirting-calculator__hint",children:"Longer boards can reduce the number of joins, while 10% waste allows for cuts, corners and mistakes."})]}),(0,F.jsxs)("div",{className:"skirting-calculator__totals",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,F.jsxs)("div",{className:"skirting-calculator__result-grid",children:[(0,F.jsxs)("div",{children:[(0,F.jsx)("span",{children:"Net skirting"}),(0,F.jsxs)("strong",{children:[m.toFixed(2)," m"]})]}),(0,F.jsxs)("div",{children:[(0,F.jsx)("span",{children:"Board lengths"}),(0,F.jsx)("strong",{children:u})]})]}),(0,F.jsx)("p",{className:"skirting-calculator__note",children:"Corners and joins vary by room layout. Measure each wall where possible for the most accurate result."})]}),(0,F.jsxs)("div",{className:"skirting-calculator__actions",children:[(0,F.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,F.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(g),disabled:m<=0,children:a})]})]})]})})}var jn=Y(Ke()),oe=Y(ae()),ol=e=>Number.parseFloat(e)||0;function Od({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,jn.useState)("studs"),[i,o]=(0,jn.useState)(""),[l,c]=(0,jn.useState)(""),[p,f]=(0,jn.useState)("600"),[b,d]=(0,jn.useState)("2.4"),h=i&&l&&p?Math.ceil(ol(l)/(ol(p)/1e3))+1:0,w=h*ol(i),E=ol(b)>0?Math.ceil(w/ol(b)):0,D=[{key:r,label:{studs:"Stud timber",joists:"Joist timber",battens:"Batten timber"}[r],qty:w,unit:"m",query:{studs:"cls studwork timber",joists:"timber joist",battens:"roofing batten"}[r],category:"timber"}],m={studs:["Stud wall","Vertical studs along a wall length"],joists:["Joists","Parallel joists across a floor or deck"],battens:["Battens","Regularly spaced battens for lining or cladding"]},g={studs:{member:"Wall height",overall:"Wall length",help:"Studs repeat across the wall length.",count:"Studs"},joists:{member:"Joist span",overall:"Overall width",help:"Joists repeat across the overall floor or deck width.",count:"Joists"},battens:{member:"Batten length",overall:"Overall width",help:"Battens repeat across the overall lining or cladding width.",count:"Battens"}}[r];return(0,oe.jsx)(oe.Fragment,{children:(0,oe.jsxs)("div",{className:"truss-estimator",children:[(0,oe.jsxs)("div",{className:"quick-order-hero",children:[(0,oe.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,oe.jsx)("h1",{children:"Timber Calculator"}),(0,oe.jsx)("p",{children:"Estimate studs, joists or battens from a run length, width and spacing."})]}),(0,oe.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,oe.jsx)("h2",{className:"truss-estimator__step-title",children:"Member size and spacing"}),(0,oe.jsxs)("p",{className:"truss-estimator__step-sub",children:[g.help," Enter the member length and centres to estimate the number of pieces and stock lengths."]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber use"}),(0,oe.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:Object.keys(m).map(v=>(0,oe.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===v?" is-selected":""}`,onClick:()=>n(v),children:[(0,oe.jsx)("div",{className:"truss-estimator__option-title",children:m[v][0]}),(0,oe.jsx)("div",{className:"truss-estimator__option-copy",children:m[v][1]})]},v))})]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Dimensions and spacing"}),(0,oe.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsxs)("span",{children:[g.member," (m)"]}),(0,oe.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:v=>o(v.target.value)})]}),(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsxs)("span",{children:[g.overall," (m)"]}),(0,oe.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:v=>c(v.target.value)})]})]}),(0,oe.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsx)("span",{children:"Centres (mm)"}),(0,oe.jsxs)("select",{value:p,onChange:v=>f(v.target.value),children:[(0,oe.jsx)("option",{value:"300",children:"300 mm"}),(0,oe.jsx)("option",{value:"400",children:"400 mm"}),(0,oe.jsx)("option",{value:"450",children:"450 mm"}),(0,oe.jsx)("option",{value:"600",children:"600 mm"})]})]}),(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsx)("span",{children:"Stock length (m)"}),(0,oe.jsxs)("select",{value:b,onChange:v=>d(v.target.value),children:[(0,oe.jsx)("option",{value:"2.4",children:"2.40 m"}),(0,oe.jsx)("option",{value:"3.6",children:"3.60 m"}),(0,oe.jsx)("option",{value:"4.8",children:"4.80 m"})]})]})]})]}),(0,oe.jsxs)("div",{className:"materials-calculator__totals",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,oe.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:g.count}),(0,oe.jsx)("strong",{children:h})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:"Linear metres"}),(0,oe.jsxs)("strong",{children:[w.toFixed(2)," m"]})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsxs)("span",{children:[b," m lengths"]}),(0,oe.jsx)("strong",{children:E})]})]}),(0,oe.jsx)("p",{className:"materials-calculator__note",children:"Spacing is measured centre-to-centre. Add extra timber for plates, noggins, trimming and openings where required."})]}),(0,oe.jsxs)("div",{className:"materials-calculator__actions",children:[(0,oe.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,oe.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(D),disabled:w<=0,children:a})]})]})]})})}var Ld=[{id:"truss",title:"Roof Truss Calculator",desc:"Estimate trusses, girders and roof structure costs.",imageUrl:"/tool-images/truss.webp",Component:Dd},{id:"fencing",title:"Fencing Calculator",desc:"Estimate fence panels, posts, gravel boards and fixings.",imageUrl:"/tool-images/fencing.webp",Component:Ed},{id:"decking",title:"Decking Calculator",desc:"Estimate boards, substructure and fixing quantities.",imageUrl:"/tool-images/decking.webp",Component:qd},{id:"brick-block",title:"Brick & Block Calculator",desc:"Estimate masonry units and ready-mixed mortar for a wall.",imageUrl:"/tool-images/brick-block.webp",Component:xd},{id:"paint",title:"Paint Calculator",desc:"Estimate paint for walls, doors and multiple coats.",imageUrl:"/tool-images/paint.webp",Component:Td},{id:"skirting",title:"Skirting Board Calculator",desc:"Estimate skirting lengths for rooms and wall runs.",imageUrl:"/tool-images/skirting.webp",Component:Bd},{id:"architrave",title:"Architrave Calculator",desc:"Estimate architrave lengths for door and window openings.",imageUrl:"/tool-images/architrave.webp",Component:_d},{id:"concrete-aggregate",title:"Concrete & Aggregate Calculator",desc:"Estimate concrete, MOT, sand and gravel quantities.",imageUrl:"/tool-images/concrete-aggregate.webp",Component:Sd},{id:"plasterboard",title:"Plasterboard Calculator",desc:"Estimate plasterboard sheets, screws, tape and adhesive.",imageUrl:"/tool-images/plasterboard.webp",Component:Ud},{id:"insulation",title:"Insulation Calculator",desc:"Estimate insulation packs for floors, walls, roofs and lofts.",imageUrl:"/tool-images/insulation.webp",Component:Md},{id:"timber",title:"Timber Calculator",desc:"Estimate studs, joists and battens from spacing and lengths.",imageUrl:"/tool-images/timber.webp",Component:Od},{id:"paving",title:"Paving & Driveway Calculator",desc:"Estimate paving, block paving, MOT and sharp sand.",imageUrl:"/tool-images/paving.webp",Component:Ad}];var mc=Y(Ke());var je=Y(Ke());var S=Y(ae()),Z_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}],Hd={wasteFactorEnabled:!0},K_=3e3,qw=null;function dc(e,t){let a=Fo(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function P_(e){return e&&e.length>0?e.join(" x "):"-"}function jd({toolId:e,requirements:t,ready:a,onBack:r,onTotalChange:n}){let i=Fs(),o=`${e}~${t.map(C=>`${C.key}|${C.query}|${C.category??""}|${C.qty}`).join("~")}`,l=o!==qw,[c,p]=(0,je.useState)(null),[f,b]=(0,je.useState)([]),[d,h]=(0,je.useState)(l),[w,E]=(0,je.useState)(null),[D,m]=(0,je.useState)("tile"),[u,g]=(0,je.useState)(null),[v,N]=(0,je.useState)(""),[R,T]=(0,je.useState)(null),[z,G]=(0,je.useState)(""),[K,xe]=(0,je.useState)([]),[Ee,Ge]=(0,je.useState)(new Set),[Qe,Ie]=(0,je.useState)(null),[ue,Q]=(0,je.useState)(""),[se,Ne]=(0,je.useState)([]),lt=(0,je.useRef)(null),Ye=(0,je.useRef)(!1),ge=C=>`${e}:${C}`,We=C=>Kr(C.chosen,{lineId:ge(C.requirement.key),description:C.requirement.label,unit:C.requirement.unit,qty:C.requirement.qty}),he=(0,je.useMemo)(()=>t.map(C=>`${C.key}|${C.query}|${C.category??""}`).join("~"),[t]);(0,je.useEffect)(()=>{let C=!1;return fw().then(V=>{C||p(V.itemCount>0)}).catch(()=>{C||p(!1)}),()=>{C=!0}},[]),(0,je.useEffect)(()=>{if(!a||!c)return;let C=!1,V;l&&h(!0),E(null);let X=Date.now();return(async()=>{let pe=null;try{pe=(await mw(t)).map(({requirement:ft,candidates:Ve})=>({requirement:ft,candidates:Ve,chosen:Ve[0]??null}))}catch(Se){C||E(Se instanceof Error?Se.message:"Could not load products")}if(!C){if(qw=o,l){let Se=K_-(Date.now()-X);Se>0&&await new Promise(ft=>{V=window.setTimeout(ft,Se)})}C||(pe&&(b(pe),!Ye.current&&i&&(Ye.current=!0,i.addManyToCart(pe.filter(Se=>Se.chosen).map(We)))),h(!1))}})(),()=>{C=!0,window.clearTimeout(V)}},[a,c,he]),(0,je.useEffect)(()=>{if(!R)return;let C=z.trim();if(!C){xe([]);return}let V=!1,X=window.setTimeout(()=>{Jr(C).then(pe=>{V||xe(pe)}).catch(()=>{V||xe([])})},250);return()=>{V=!0,window.clearTimeout(X)}},[R,z]),(0,je.useEffect)(()=>{if(!Qe)return;let C=ue.trim();if(!C){Ne([]);return}let V=!1,X=window.setTimeout(()=>{Jr(C).then(pe=>{V||Ne(pe)}).catch(()=>{V||Ne([])})},250);return()=>{V=!0,window.clearTimeout(X)}},[Qe,ue]);let W=(0,je.useMemo)(()=>{let C=v.trim().toLowerCase(),V=C?f.filter(X=>X.requirement.label.toLowerCase().includes(C)||(X.chosen?.description??"").toLowerCase().includes(C)||(X.chosen?.product_id??"").toLowerCase().includes(C)):f;return u?[...V].sort((X,pe)=>{let Se=X.requirement.label.localeCompare(pe.requirement.label);return u==="asc"?Se:-Se}):V},[f,v,u]),ze=W.filter(C=>C.chosen),Be=W.filter(C=>!C.chosen),ve=f.filter(C=>C.chosen),et=ve.filter(C=>C.chosen?.price==null).length,Ze=ve.reduce((C,V)=>C+(Ut(We(V),Hd).lineTotal??0),0);if((0,je.useEffect)(()=>{n?.(Ze)},[Ze,n]),!a||c===!1)return null;let M=i?ve.filter(C=>i.cart[ge(C.requirement.key)]).length:0,x=Qe?f.find(C=>C.requirement.key===Qe)??null:null,I=ue.trim()?se:x?.candidates??[],ce=C=>{let V=R===C.requirement.key;T(V?null:C.requirement.key),G(V?"":C.requirement.query)},me=(C,V)=>{let X=f.find(pe=>pe.requirement.key===C);b(pe=>pe.map(Se=>Se.requirement.key===C?{...Se,chosen:V}:Se)),i&&X&&i.cart[ge(C)]&&i.addToCart(We({...X,chosen:V})),T(null),G("")},ke=C=>{b(V=>V.map(X=>X.requirement.key===C?{...X,chosen:null}:X)),i?.cart[ge(C)]&&i.removeFromCart(ge(C))},k=C=>{Ie(C.requirement.key),Q(""),Ne([])},j=()=>{Ie(null),Q(""),Ne([])},O=C=>{if(!i)return;let V=ge(C.requirement.key);i.cart[V]?i.removeFromCart(V):i.addToCart(We(C))},ne=C=>{Ge(V=>{let X=new Set(V);return X.has(C)?X.delete(C):X.add(C),X})},ee=C=>{let V=K.length>0?K:C.candidates;return(0,S.jsxs)("div",{className:"estimator-products__picker",children:[(0,S.jsx)("input",{type:"text",className:"results-search-input",value:z,autoFocus:!0,placeholder:"Search products in catalogue...",onChange:X=>G(X.target.value),"aria-label":`Search a product for ${C.requirement.label}`}),(0,S.jsxs)("div",{className:"estimator-products__options",children:[V.map(X=>(0,S.jsxs)("button",{type:"button",className:`estimator-products__option${X.product_id===C.chosen?.product_id?" is-selected":""}`,onClick:()=>me(C.requirement.key,X),children:[(0,S.jsx)("span",{children:X.description}),(0,S.jsxs)("span",{className:"results-row-meta",children:[X.product_id,X.price!=null&&` \xB7 ${st(X.price)}`]})]},X.product_id)),V.length===0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No matching products."})]})]})};return(0,S.jsxs)("section",{className:"estimator-products results-tile-section","aria-label":"Matched products",children:[!d&&(0,S.jsxs)("div",{className:"estimator-products__head",children:[(0,S.jsxs)("div",{className:"results-tile-section__head",children:[(0,S.jsx)("h3",{children:"Matched Products"}),(0,S.jsx)("p",{children:"Products matched to your estimate, check before adding to your basket."})]}),!x&&(0,S.jsxs)("div",{className:"results-summary estimator-products__toolbar",children:[et>0&&(0,S.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,S.jsx)("strong",{children:et})," need pricing"]}),(0,S.jsxs)("div",{className:"estimator-products__controls",children:[(0,S.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:v,onChange:C=>N(C.target.value),"aria-label":"Search matched products"}),(0,S.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,S.jsx)("button",{type:"button",className:`results-view-toggle__btn${D==="tile"?" is-active":""}`,"aria-pressed":D==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>m("tile"),children:(0,S.jsxs)("svg",{width:"18",height:"12",viewBox:"0 0 15 10",fill:"currentColor",children:[(0,S.jsx)("rect",{x:"0.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"5.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"10.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"0.5",y:"5.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"5.5",y:"5.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"10.5",y:"5.5",width:"4",height:"4"})]})}),(0,S.jsx)("button",{type:"button",className:`results-view-toggle__btn${D==="list"?" is-active":""}`,"aria-pressed":D==="list","aria-label":"List view",title:"List view",onClick:()=>m("list"),children:(0,S.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,S.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,S.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,S.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),(0,S.jsxs)("details",{ref:lt,style:{position:"relative"},children:[(0,S.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort materials",style:{fontSize:16},children:"\u21C5"}),(0,S.jsx)("div",{className:"sort-menu-panel",children:Z_.map(C=>{let V=u===C.dir;return(0,S.jsxs)("button",{type:"button",className:`sort-menu-item${V?" is-active":""}`,onClick:()=>{g(V?null:C.dir),lt.current?.removeAttribute("open")},children:[(0,S.jsx)("span",{className:"sort-menu-item__check",children:V?"\u2713":""}),C.label]},C.dir)})})]})]})]})]}),x&&(0,S.jsxs)("div",{className:"results-review-page",children:[(0,S.jsxs)("div",{className:"results-review-page__top",children:[(0,S.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:j,children:[(0,S.jsx)(Zr,{}),"Back to results"]}),(0,S.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,S.jsx)("div",{className:"results-review-searchbar",children:(0,S.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:ue,onChange:C=>Q(C.target.value),"aria-label":`Search a product for ${x.requirement.label}`})}),x.chosen&&(0,S.jsx)("div",{className:"results-candidate-actions",children:(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ke(x.requirement.key),children:"Clear selected product"})})]})]}),(0,S.jsxs)("div",{className:"results-review-page__hero",children:[(0,S.jsx)("div",{className:"results-review-page__image-wrap",children:(0,S.jsx)("img",{className:"fill-img results-review-page__image",src:Qa(x.chosen?.description||x.requirement.label,x.chosen?.product_id,x.chosen?.pdp_photo_url),alt:""})}),(0,S.jsxs)("div",{className:"results-review-page__summary",children:[(0,S.jsx)("h2",{children:x.requirement.label}),(0,S.jsxs)("p",{className:"results-review-page__meta",children:[_i(x.requirement.qty)," ",ka(x.requirement.unit,x.requirement.qty)]}),x.chosen?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("div",{className:"results-review-page__product",children:x.chosen.description}),(0,S.jsxs)("div",{className:"results-row-meta",children:[x.chosen.product_id,x.chosen.price!=null?` \xB7 ${dc(x.chosen.price,x.chosen.price_basis)}`:""]})]}):(0,S.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line."}),(0,S.jsx)("div",{className:"results-review-page__actions",children:(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${i?.cart[ge(x.requirement.key)]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>O(x),disabled:!x.chosen||!i,children:i?.cart[ge(x.requirement.key)]?"\u2713 Added":"+ Add to basket"})})]})]}),I.length===0?(0,S.jsx)("p",{className:"results-empty-hint",children:"No matching products."}):(0,S.jsxs)("table",{className:"score-breakdown-table",children:[(0,S.jsx)("thead",{children:(0,S.jsxs)("tr",{children:[(0,S.jsx)("th",{children:"Product"}),(0,S.jsx)("th",{children:"Dims (mm)"}),(0,S.jsx)("th",{children:"Price"}),(0,S.jsx)("th",{"aria-label":"Actions"})]})}),(0,S.jsx)("tbody",{children:I.map(C=>{let V=C.product_id===x.chosen?.product_id;return(0,S.jsxs)("tr",{className:V?"score-breakdown-row--best":"",children:[(0,S.jsxs)("td",{children:[(0,S.jsx)("div",{children:C.description}),(0,S.jsx)("div",{className:"results-row-meta",children:C.product_id})]}),(0,S.jsx)("td",{children:(0,S.jsx)("span",{className:"unit-badge",children:P_(C.measurements_mm)})}),(0,S.jsx)("td",{children:C.price!=null?dc(C.price,C.price_basis):"-"}),(0,S.jsx)("td",{children:(0,S.jsxs)("label",{className:"switch-toggle",title:V?"Currently selected":"Use this candidate",children:[(0,S.jsx)("input",{type:"checkbox",checked:V,onChange:()=>{V?ke(x.requirement.key):me(x.requirement.key,C)},"aria-label":V?`${C.description} selected`:`Use ${C.description}`}),(0,S.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},C.product_id)})})]})]}),!x&&d&&(0,S.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{padding:"32px 24px"},children:[(0,S.jsx)(dr,{}),(0,S.jsx)("p",{className:"banter-message is-visible",style:{fontSize:15,minHeight:0},children:"Matching your materials against the catalogue\u2026"})]}),!x&&w&&(0,S.jsx)("p",{className:"results-empty-hint estimator-products__error",children:w}),!x&&!d&&!w&&W.length===0&&f.length>0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No materials match the current search."}),!x&&!d&&!w&&D==="tile"&&ze.length>0&&(0,S.jsx)("div",{className:"results-tile-grid",children:ze.map(C=>{let{requirement:V,chosen:X}=C,pe=X?Ut(We(C),Hd):null,Se=i?!!i.cart[ge(V.key)]:!1;return(0,S.jsxs)("article",{className:"results-tile-card",children:[(0,S.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>k(C),"aria-label":`Review match for ${V.label}`,children:[(0,S.jsx)("div",{className:"results-tile-card__media",children:(0,S.jsx)("img",{className:"fill-img results-tile-card__image",src:Qa(X?.description||V.label,X?.product_id,X?.pdp_photo_url),alt:""})}),(0,S.jsxs)("div",{className:"results-tile-card__body",children:[X?(0,S.jsxs)("div",{className:"results-tile-card__heading",children:[(0,S.jsx)("div",{className:"results-tile-card__title",children:X.description}),(0,S.jsxs)("div",{className:"results-tile-card__match-meta",children:[(0,S.jsx)("span",{children:X.product_id}),X.price!=null?(0,S.jsx)("span",{children:dc(X.price,X.price_basis)}):null]})]}):(0,S.jsx)("div",{className:"results-empty-hint",children:"No product matched for this line."}),(0,S.jsxs)("div",{className:"results-tile-card__match",children:[(0,S.jsx)("div",{className:"results-tile-card__match-label",children:"\u21B3 calculated as"}),(0,S.jsx)("div",{className:"results-tile-card__match-name",children:V.label}),(0,S.jsxs)("div",{className:"results-tile-card__meta",children:[_i(V.qty)," ",ka(V.unit,V.qty)]}),pe?.requiredSellUnits!=null?(0,S.jsxs)("div",{className:"results-tile-card__meta estimator-products__order",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${st(pe.lineTotal)}`:""]}):X?(0,S.jsx)("div",{className:"results-row-meta",children:"Quantity needs review"}):null]})]})]}),(0,S.jsxs)("div",{className:"results-tile-card__actions",children:[(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>k(C),children:"Review"}),(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${Se?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>O(C),disabled:!X||!i,children:Se?"\u2713 Added":"+ Add"})]})]},V.key)})}),!x&&!d&&!w&&D==="list"&&ze.length>0&&(0,S.jsx)("div",{className:"bom-table-wrap",children:(0,S.jsxs)("table",{className:"bom-table results-table","aria-label":"Matched materials",children:[(0,S.jsxs)("colgroup",{children:[(0,S.jsx)("col",{style:{width:"56px"}}),(0,S.jsx)("col",{className:"col-item"}),(0,S.jsx)("col",{style:{width:"90px"}}),(0,S.jsx)("col",{style:{width:"80px"}}),(0,S.jsx)("col",{style:{width:"220px"}}),(0,S.jsx)("col",{style:{width:"110px"}})]}),(0,S.jsx)("thead",{children:(0,S.jsxs)("tr",{className:"bom-col-header",children:[(0,S.jsx)("th",{"aria-label":"Expand"}),(0,S.jsx)("th",{style:{textAlign:"left"},children:"Description"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Qty"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Unit"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Product Matched"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Basket"})]})}),(0,S.jsx)("tbody",{children:ze.map(C=>{let{requirement:V,chosen:X}=C,pe=X?Ut(We(C),Hd):null,Se=i?!!i.cart[ge(V.key)]:!1,ft=Ee.has(V.key);return(0,S.jsxs)(je.Fragment,{children:[(0,S.jsxs)("tr",{className:"bom-row",children:[(0,S.jsx)("td",{className:"bom-actions",style:{textAlign:"center",paddingLeft:0,paddingRight:0},children:(0,S.jsx)("button",{type:"button",className:"link-btn",onClick:()=>ne(V.key),"aria-expanded":ft,"aria-label":ft?"Collapse product options":"Expand product options",children:ft?"\u25BE":"\u25B8"})}),(0,S.jsxs)("td",{style:{paddingLeft:0},children:[(0,S.jsx)("div",{className:"bom-component-name",children:V.label}),pe?.requiredSellUnits!=null&&(0,S.jsxs)("div",{className:"results-row-meta",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${st(pe.lineTotal)}`:""]})]}),(0,S.jsx)("td",{className:"bom-qty col-order",style:{textAlign:"center"},children:_i(V.qty)}),(0,S.jsx)("td",{style:{textAlign:"center"},children:ka(V.unit,V.qty)}),(0,S.jsx)("td",{style:{textAlign:"center"},children:X?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("div",{className:"bom-component-name",children:X.description}),(0,S.jsxs)("div",{className:"results-row-meta",children:[X.product_id,X.price!=null&&` \xB7 ${dc(X.price,X.price_basis)}`]})]}):(0,S.jsx)("span",{className:"results-empty-hint",children:"No match"})}),(0,S.jsx)("td",{style:{textAlign:"center"},children:(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${Se?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>O(C),disabled:!X||!i,children:Se?"\u2713 Added":"+ Add"})})]}),ft&&(0,S.jsx)("tr",{children:(0,S.jsx)("td",{colSpan:6,style:{paddingLeft:0,paddingRight:0},children:R===V.key?ee(C):(0,S.jsxs)("div",{className:"estimator-products__picker",children:[(0,S.jsxs)("div",{className:"estimator-products__options",children:[C.candidates.map(Ve=>(0,S.jsxs)("button",{type:"button",className:`estimator-products__option${Ve.product_id===X?.product_id?" is-selected":""}`,onClick:()=>me(V.key,Ve),children:[(0,S.jsx)("span",{children:Ve.description}),(0,S.jsxs)("span",{className:"results-row-meta",children:[Ve.product_id,Ve.price!=null&&` \xB7 ${st(Ve.price)}`]})]},Ve.product_id)),C.candidates.length===0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No candidates found."})]}),(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ce(C),children:"Search the catalogue"})]})})})]},V.key)})})]})}),!x&&!d&&!w&&Be.length>0&&(0,S.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,S.jsxs)("div",{className:"results-tile-section__head",children:[(0,S.jsx)("h3",{children:"Require Matching"}),(0,S.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,S.jsx)("div",{className:"results-unmatched-list",children:Be.map(C=>(0,S.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>k(C),children:[(0,S.jsxs)("span",{className:"results-unmatched-card__main",children:[(0,S.jsx)("span",{className:"results-unmatched-card__title",children:C.requirement.label}),(0,S.jsxs)("span",{className:"results-row-meta",children:[_i(C.requirement.qty)," ",ka(C.requirement.unit,C.requirement.qty)]})]}),(0,S.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},C.requirement.key))})]}),!d&&!w&&f.length>0&&(0,S.jsxs)("div",{className:"disclaimer-box",style:{alignItems:"center"},children:[(0,S.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,S.jsx)("p",{className:"disclaimer-text",children:"These matches are generated automatically and should be reviewed before procurement, especially any items flagged as medium or low confidence."})]}),!x&&!d&&!w&&(r||M>0)&&(0,S.jsxs)("div",{className:"btn-row estimator-products__footer",children:[r&&(0,S.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:r,children:"Back"}),M>0&&i&&(0,S.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:r?"0 1 70%":1,marginTop:0},onClick:i.openBasket,children:[(0,S.jsxs)("span",{children:["View Basket (",M,")"]}),(0,S.jsx)("span",{className:"arrow",children:(0,S.jsx)(Ht,{})})]})]})]})}var jt=Y(ae());function Gd({toolId:e,toolTitle:t,requirements:a,onBack:r}){let[n,i]=(0,mc.useState)(0),o=(0,mc.useCallback)(l=>i(l),[]);return(0,jt.jsx)(jt.Fragment,{children:(0,jt.jsxs)("div",{className:"truss-estimator",children:[(0,jt.jsxs)("div",{className:"quick-order-hero",children:[(0,jt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,jt.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,jt.jsx)("h1",{children:"Your Materials"}),n>0&&(0,jt.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,jt.jsx)("strong",{children:st(n)})," Est. total"]})]}),(0,jt.jsxs)("p",{children:["Quantities from the ",t,", matched against your merchant\u2019s catalogue."]})]}),(0,jt.jsx)("div",{className:"truss-estimator__card",style:{minHeight:0},children:(0,jt.jsx)(jd,{toolId:e,requirements:a,ready:!0,onBack:r,onTotalChange:o})})]})})}var J_=(e,t)=>{let a=t.key,r={"brick-block":{"brick-common":"5001444","brick-engineering-red":"5002008","brick-engineering-blue":"5001439",block:"5003187",mortar:"6003088"},skirting:{"skirting-chamfered":"4006057","skirting-ogee":"4006045","skirting-pencil-round":"4006048","skirting-torus":"4006042"},architrave:{"architrave-ogee":"4006060","architrave-ovolo":"4006063","architrave-pencil-round":"4006061","architrave-square-edge":"4006062","architrave-torus":"4006059"},plasterboard:{board:"2001035",screws:"2006040",tape:"2007043",adhesive:"2004023"},insulation:{"insulation-floor":"3002110","insulation-wall":"3002012","insulation-roof":"3004047","insulation-loft":"3003046"},timber:{studs:"4001168",joists:"4001201",battens:"4001053"},fencing:{"panels-boundary-0.9":"4001268","panels-boundary-1.2":"4001269","panels-boundary-1.5":"4001270","panels-boundary-1.8":"4001271","panels-skyline-0.9":"4001264","panels-skyline-1.2":"4001265","panels-skyline-1.5":"4001266","panels-skyline-1.8":"4001267","concrete-intermediate-6":"4001290","concrete-intermediate-8":"4001291","concrete-end-6":"4001294","concrete-end-8":"4001295","timber-post-6":"4001242","timber-post-8":"4001243",postcrete:"6003008",gate:"4001630","gravel-boards":"4001284"},decking:{"boards-meridian":"4001251","boards-summit":"4001360",joists:"4001201",screws:"1001103"},paving:{"surface-council":"7003121","surface-raj":"7003003","surface-brindle":"4001621","surface-charcoal":"4001622","surface-pea":"6001004","sub-base":"6001007",bedding:"6001012"}};return e==="plasterboard"?{standard:"2001035",moisture:"2002039",fire:"2002087",sound:"2002044"}[t.label.split(" ")[0].toLowerCase()]??r[e]?.[a]??null:r[e]?.[a]??null};function Ew(e,t){if(e==="paint"||e==="concrete-aggregate")return null;let a=t.map(r=>{let n=J_(e,r);return n?{key:r.key,productId:n,qty:r.qty,unit:r.unit}:null});return a.every(Boolean)?a:null}var Qd=Y(Ke());var Jt=Y(ae()),F_=1500;function Mw(e){let{addManyToCart:t,clearCart:a,openBasket:r}=An(),[n,i]=(0,Qd.useState)(!1),[o,l]=(0,Qd.useState)(null);return{adding:n,basketError:o,addToBasket:async(p,f)=>{let b=Date.now();i(!0),l(null);try{let d=await Promise.all(p.filter(w=>w.qty>0).map(async w=>{let E=(await Jr(w.productId)).find(D=>D.product_id===w.productId);if(!E)throw new Error("A selected product is no longer available in this catalogue.");return Kr(E,{lineId:`${e}:${w.key}`,description:E.description,unit:w.unit??"each",qty:w.qty,calculatorWasteIncluded:f})})),h=F_-(Date.now()-b);h>0&&await new Promise(w=>window.setTimeout(w,h)),a(),t(d),r()}catch(d){l(d instanceof Error?d.message:"Could not add the products to your basket.")}finally{i(!1)}}}}function Tw({toolTitle:e}){return(0,Jt.jsx)(Jt.Fragment,{children:(0,Jt.jsxs)("div",{className:"truss-estimator",children:[(0,Jt.jsxs)("div",{className:"quick-order-hero",children:[(0,Jt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Jt.jsx)("h1",{children:"Your Materials"}),(0,Jt.jsxs)("p",{children:["Calculating quantities from the ",e,"."]})]}),(0,Jt.jsx)("div",{className:"truss-estimator__card",children:(0,Jt.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,Jt.jsx)(dr,{}),(0,Jt.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})})}var Re=Y(ae());function fc(e){let[t,a]=(0,Va.useState)(!1);return(0,Re.jsx)(Js,{onOpenBasket:()=>a(!0),children:(0,Re.jsx)(I_,{...e,showBasket:t,onShowBasket:a})})}function I_({fullPage:e=!1,hideHeader:t=!1,internal:a=!1,showBasket:r,onShowBasket:n}){let[i,o]=(0,Va.useState)(null),[l,c]=(0,Va.useState)(null),p=Ld.find(z=>z.id===i),{cart:f,updateCartQty:b,updateCartSellUnits:d,updateCartConversions:h,removeFromCart:w,clearCart:E}=An(),{adding:D,basketError:m,addToBasket:u}=Mw(p?.title??"calculator"),g=(0,Va.useRef)(null),v=Gs("estimating-tools",g);(0,Va.useEffect)(()=>{v("viewed")},[v]);let N=r?"basket":D?"adding":l?"review":i??"list",R=(0,Va.useRef)(N);(0,Va.useEffect)(()=>{R.current!==N&&(R.current=N,window.scrollTo(0,0))},[N]);let T=z=>{if(!p)return;v("estimate_completed",{calculator:p.id,lines:z.length});let G=Ew(p.id,z);G?u(G,z[0]?.calculatorWasteIncluded??!1):c(z)};return(0,Re.jsx)(Zo.Provider,{value:v,children:(0,Re.jsx)("div",{ref:g,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}`,style:pr().theme,children:(0,Re.jsx)("main",{className:"main-content",children:r?(0,Re.jsx)(rl,{cart:f,onUpdateQty:b,onUpdateSellUnits:d,onResolveConversions:h,onRemove:w,onBack:()=>n(!1),onStartNewQuote:()=>{E(),o(null),c(null),n(!1)},internal:a}):D&&p?(0,Re.jsx)(Tw,{toolTitle:p.title}):p?(0,Re.jsxs)(Re.Fragment,{children:[(0,Re.jsx)("div",{hidden:l!==null,children:(0,Re.jsx)(p.Component,{onBack:()=>o(null),onReview:T})}),m&&(0,Re.jsx)("p",{className:"results-empty-hint estimator-products__error",children:m}),l!==null&&(0,Re.jsx)(Gd,{toolId:p.id,toolTitle:p.title,requirements:l,onBack:()=>c(null)})]}):(0,Re.jsx)(Re.Fragment,{children:(0,Re.jsxs)("div",{className:"quick-order-card",children:[(0,Re.jsxs)("div",{className:"quick-order-hero",children:[(0,Re.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,Re.jsx)("h1",{children:"Estimating Tools"}),(0,Re.jsx)("p",{children:"Trade-specific calculators for trusses, fencing, decking, masonry and painting. Dial in your specs and get an instant material estimate."})]}),(0,Re.jsxs)("div",{className:"quick-order-alt",children:[(0,Re.jsx)("div",{className:"quick-order-alt-title",children:"Choose a Calculator"}),(0,Re.jsx)("div",{className:"estimator-tools-grid",children:Ld.map(z=>(0,Re.jsxs)("button",{type:"button",className:"estimator-tool-card",onClick:()=>{v("calculator_selected",{calculator:z.id}),o(z.id),c(null)},children:[(0,Re.jsx)("span",{className:"estimator-tool-card__image-wrap",children:(0,Re.jsx)("img",{className:"fill-img estimator-tool-card__image",src:Pt(z.imageUrl),alt:""})}),(0,Re.jsxs)("span",{className:"estimator-tool-card__content",children:[(0,Re.jsx)("span",{className:"estimator-tool-card__title",children:z.title}),(0,Re.jsx)("span",{className:"estimator-tool-card__desc",children:z.desc})]})]},z.id))})]})]})})})})})}var gc=Y(ae());function Yd({config:e,children:t}){return Kb(e),(0,gc.jsx)(gc.Fragment,{children:t})}var Vd=Y(ae()),W_="https://api.metronlabs.ai",ex=["client","api-key","api-url","theme","hide-header","analytics"],tx=["all","events-only","none"];function Aw(e,t){var a;customElements.get(e)||customElements.define(e,(a=class extends HTMLElement{constructor(){super();this.root=null;this.attachShadow({mode:"open"})}connectedCallback(){if(this.dataset.version="0.1.37",this.id||(this.id=e),this.setAttribute("data-turbo-permanent",""),this.setAttribute("data-turbolinks-permanent",""),!this.root){let n=document.createElement("div"),i=document.createElement("style");i.textContent=`:host { display: block; }
|
|
6799
6799
|
:host > div { all: initial; display: block; }
|
|
6800
6800
|
${Zb}`,this.shadowRoot.replaceChildren(i,n),this.root=(0,zw.createRoot)(n)}this.renderWidget()}disconnectedCallback(){queueMicrotask(()=>{this.isConnected||!this.root||(this.root.unmount(),this.root=null)})}attributeChangedCallback(){this.root&&this.renderWidget()}renderWidget(){let n=this.getAttribute("client")??void 0,i=this.getAttribute("api-key")??void 0;(!n||!i)&&console.error(`<${e}> needs client and api-key attributes.`);let o={apiBaseUrl:this.getAttribute("api-url")||W_,client:n,apiKey:i,theme:rx(e,this.getAttribute("theme")),analytics:ax(this.getAttribute("analytics"))};this.root.render((0,Vd.jsx)(Yd,{config:o,children:(0,Vd.jsx)(t,{hideHeader:this.hasAttribute("hide-header")})}))}},a.observedAttributes=ex,a))}function ax(e){return tx.find(t=>t===e)??"all"}function rx(e,t){if(t)try{return JSON.parse(t)}catch{console.error(`<${e}> theme attribute isn't valid JSON; using the default colours.`);return}}Aw("metron-labs-quick-quote",Is);Aw("metron-labs-estimating-tools",fc);
|
|
6801
6801
|
/*! Bundled license information:
|