@metron-labs/quote-react 0.1.76 → 0.1.77
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/embed/quote.js +1 -1
- package/dist/util/pricing.js +3 -1
- package/package.json +1 -1
package/dist/embed/quote.js
CHANGED
|
@@ -6971,7 +6971,7 @@ Error generating stack: `+r.message+`
|
|
|
6971
6971
|
`).map(t=>t.trim()).filter(Boolean);function dv(e){let t=k_(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 mv(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=$(Ve());var ec=$(Ve()),Ws=$(ee()),C_=[4,5,4],_d=4e3;function vn(){let[e,t]=(0,ec.useState)(0);(0,ec.useEffect)(()=>{let r=setInterval(()=>t(n=>n+1),_d);return()=>clearInterval(r)},[]);let a=0;return(0,Ws.jsx)("div",{className:"brick-wall","aria-hidden":!0,children:C_.map((r,n)=>(0,Ws.jsx)("div",{className:"brick-wall__course",children:Array.from({length:r},(i,o)=>(0,Ws.jsx)("span",{className:`brick-wall__brick${r===5&&(o===0||o===4)?" brick-wall__brick--half":""}`,style:{"--i":a++}},o))},n))},e)}var al=$(ee()),tc=["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 bv(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 wv(){let e=(0,$r.useRef)(0),t=(0,$r.useRef)(bv(tc.map((o,l)=>l))),[a,r]=(0,$r.useState)(tc[t.current[0]]),[n,i]=(0,$r.useState)(!0);return(0,$r.useEffect)(()=>{let o=setInterval(()=>{i(!1),window.setTimeout(()=>{e.current++,e.current>=t.current.length&&(t.current=bv(tc.map((l,c)=>c)),e.current=0),r(tc[t.current[e.current]]),i(!0)},600)},_d);return()=>clearInterval(o)},[]),(0,al.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",children:[(0,al.jsx)(vn,{}),(0,al.jsx)("p",{className:`banter-message${n?" is-visible":""}`,children:a})]})}var ac=$(Ve());function rl(e,t){let a=(0,ac.useRef)(t);a.current=t,(0,ac.useEffect)(()=>{if(!e)return;let r=n=>{n.key!=="Escape"||n.defaultPrevented||n.isComposing||(n.preventDefault(),a.current())};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[e])}var xd={"#quote-entry":"entry","#matched-products":"results","#quote-request":"basket"},vv=!1,nc="",kd=!1,yv=()=>window.navigation,rc=-1;function q_(){if(kd)return-1;let e=yv()?.currentEntry?.index;return e==null||rc<0||e===rc?0:e<rc?-1:1}function E_(e){let t=new URL(nc||window.location.href),a=new URL(window.location.href);if(nc=a.href,t.pathname!==a.pathname||t.search!==a.search||!(t.hash in xd)&&!(a.hash in xd))return;let r=t.href===a.href?q_():0;if(r){e.stopImmediatePropagation(),window.history.go(r);return}kd=!1;let n=e.state;Object.defineProperty(e,"state",{value:null}),setTimeout(()=>{if(window.location.href!==a.href)return;let i=xd[a.hash],o=i&&n?.turbo?{boqQuoteStage:i}:n;JSON.stringify(window.history.state)!==JSON.stringify(o)&&window.history.replaceState(o,"",a.href)})}function _v(){vv||typeof window>"u"||(vv=!0,nc=window.location.href,window.addEventListener("popstate",E_,{capture:!0}),yv()?.addEventListener("currententrychange",e=>{rc=e.from?.index??-1}))}function Ri(e,t,a){window.history[e](t,"",a),nc=window.location.href}function ic(){kd=!0,window.history.back()}var Sd=$(ee());function Qt(){return(0,Sd.jsx)("svg",{className:"forward-arrow",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,Sd.jsx)("path",{d:"M3 8H13M13 8L9 4M13 8L9 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}var Nd=$(ee());function nl(){return(0,Nd.jsx)("svg",{className:"close-icon",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",children:(0,Nd.jsx)("path",{d:"M3.5 3.5L12.5 12.5M12.5 3.5L3.5 12.5",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round"})})}var F=$(ee()),M_=[...Ti.schedule,...Ti.photo].join(","),T_={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."}]},Ai="#quote-entry",oc="metron-quick-quote-entry";function Cd({onPasteSchedule:e,onUploadSchedule:t,onEntryModeChange:a,draft:r,onSubmitDraft:n,onCancelMatch:i}){let o=(0,Nt.useRef)(null),l=Ei(),c=(0,Nt.useRef)(0),p=(0,Nt.useRef)(0),[m,f]=(0,Nt.useState)(()=>r&&typeof window<"u"&&window.location.hash===Ai?r.tab:null),[d,g]=(0,Nt.useState)(r?.text??""),[w,A]=(0,Nt.useState)(r?.file??null),[L,h]=(0,Nt.useState)(""),[u,b]=(0,Nt.useState)(!1),[v,_]=(0,Nt.useState)(!1),[C,R]=(0,Nt.useState)(null),T=d.split(`
|
|
6972
6972
|
`).filter(P=>P.trim()).length,D=dv(d),V=m==="paste"?!!d:!!w;(0,Nt.useEffect)(()=>{if(!w||!zi(w)){R(null);return}let P=URL.createObjectURL(w);return R(P),()=>URL.revokeObjectURL(P)},[w]);let oe=(0,Nt.useRef)(m??r?.tab??null);m&&(oe.current=m),(0,Nt.useEffect)(()=>{if(r||window.location.hash!==Ai)return;let P=null;try{P=JSON.parse(window.sessionStorage.getItem(oc)??"null")}catch{}if(!P?.tab){let pe=new URL(window.location.href);pe.hash="",Ri("replaceState",window.history.state,pe);return}oe.current=P.tab,f(P.tab),g(P.text??"")},[]),(0,Nt.useEffect)(()=>{if(m)try{window.sessionStorage.setItem(oc,JSON.stringify({tab:m,text:d}))}catch{}},[m,d]),(0,Nt.useEffect)(()=>{let P=()=>{if(window.location.hash===Ai)return f(oe.current);f(null),p.current++,b(!1),i?.()};return window.addEventListener("popstate",P),()=>window.removeEventListener("popstate",P)},[]);let _e=P=>{l("method_selected",{method:P}),f(P),h(""),a(null);let pe=window.location.hash;if(pe===Ai)return;let Re=new URL(window.location.href);Re.hash=Ai,Ri(pe==="#matched-products"||pe==="#quote-request"?"replaceState":"pushState",{boqQuoteStage:"entry"},Re)},Te=()=>{f(null),a(null),window.location.hash===Ai&&ic()};rl(!!m&&!u,Te);let Oe=P=>{if(!P?.length)return;if(P.length>1)return h("Please choose one file at a time.");let pe=P[0],Re=yd(pe,zi(pe)?1/0:void 0);if(Re)return h(Re);h(""),A(pe)},xe=async P=>{m==="paste"&&A(null),m==="upload"&&g(""),m&&n?.({tab:m,text:m==="paste"?d:"",file:m==="upload"?w:null});let pe=++p.current;h(""),b(!0);try{await P()}catch(Re){pe===p.current&&h(Re?.message||"Failed to process your list")}finally{pe===p.current&&b(!1)}},X=()=>{if(w)return l("list_submitted",{method:zi(w)?"photo":"upload"}),xe(async()=>{if(!zi(w))return t(w);let P;try{P=await mv(w);let pe=yd(P);if(pe)throw new Error(pe)}catch(pe){throw l("error",{stage:"photo"}),pe}await t(P)})},J=P=>P.dataTransfer.types.includes("Files"),ze=P=>{J(P)&&(P.preventDefault(),c.current+=1,_(!0))},Ee=P=>{J(P)&&(c.current-=1,c.current<=0&&(c.current=0,_(!1)))},wt=P=>{J(P)&&(P.preventDefault(),c.current=0,_(!1),Oe(P.dataTransfer.files),_e("upload"))};return(0,F.jsxs)("div",{className:"wizard-step entry-stage",onDragEnter:ze,onDragOver:P=>J(P)&&P.preventDefault(),onDragLeave:Ee,onDrop:wt,children:[v&&(0,F.jsx)("div",{className:"entry-drop-overlay","aria-hidden":"true",children:"Drop your file to upload"}),(0,F.jsxs)("div",{className:"quick-order-card",children:[(0,F.jsxs)("div",{className:"quick-order-alt",children:[(0,F.jsxs)("div",{className:"quick-order-entry-copy",children:[(0,F.jsx)("div",{className:"quick-order-alt-title",children:"How would you like to get started?"}),(0,F.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,F.jsxs)("div",{className:"entry-options entry-options--workflow entry-options--two",children:[(0,F.jsxs)("button",{type:"button",className:`entry-option-card entry-option-card--paste${m==="paste"?" entry-option-card--active":""}`,onClick:()=>_e("paste"),children:[(0,F.jsxs)("span",{className:"entry-option-content",children:[(0,F.jsx)("span",{className:"entry-option-title",children:"Type or paste a list"}),(0,F.jsx)("span",{className:"entry-option-desc",children:"Enter your materials and quantities"})]}),(0,F.jsx)("span",{className:"entry-option-media entry-option-media--paste","aria-hidden":"true",children:(0,F.jsx)("img",{className:"fill-img",src:It("/quick-order/paste-list.webp"),alt:""})})]}),(0,F.jsxs)("button",{type:"button",className:`entry-option-card entry-option-card--upload${m==="upload"?" entry-option-card--active":""}`,onClick:()=>_e("upload"),children:[(0,F.jsxs)("span",{className:"entry-option-content",children:[(0,F.jsx)("span",{className:"entry-option-title",children:"Upload a file"}),(0,F.jsx)("span",{className:"entry-option-desc",children:"A photo, spreadsheet, Word document or PDF"})]}),(0,F.jsx)("span",{className:"entry-option-media entry-option-media--upload","aria-hidden":"true",children:(0,F.jsx)("img",{className:"fill-img",src:It("/quick-order/photo-list.webp"),alt:""})})]})]})]}),m&&(0,F.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop",role:"dialog","aria-modal":"true","aria-labelledby":"quick-order-workflow-title",onClick:()=>!V&&Te(),children:(0,F.jsxs)("section",{className:`quick-order-workflow-modal${u?" quick-order-workflow-modal--matching":""}`,onClick:P=>P.stopPropagation(),children:[(0,F.jsxs)("header",{className:"quick-order-workflow-modal-header",children:[(0,F.jsx)("h2",{id:"quick-order-workflow-title",children:m==="paste"?"Type or paste a list":"Upload a file"}),(0,F.jsx)("button",{type:"button",className:"quick-order-workflow-close",onClick:Te,"aria-label":"Close",children:(0,F.jsx)(nl,{})})]}),(0,F.jsxs)("div",{className:"quick-order-panel",children:[(0,F.jsxs)("div",{className:"quick-order-body","aria-hidden":u,children:[(0,F.jsx)("div",{className:"quick-order-body-main",children:m==="paste"?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)("textarea",{className:"paste-textarea",placeholder:`Paste your line items here, one per line, e.g.
|
|
6973
6973
|
insulated plasterboard 50mm
|
|
6974
|
-
C24 timber 4.8m`,value:d,onChange:P=>g(P.target.value),"aria-label":"Paste schedule line items"}),(D||L)&&(0,F.jsxs)("div",{className:"error-box",role:"alert",children:[(0,F.jsx)("strong",{children:"Error:"})," ",D||L]}),(0,F.jsxs)("div",{className:"quick-order-hint",children:[(0,F.jsx)("strong",{children:"Tip:"}),'\xA0Paste one line per item. Include a count, e.g. "x10", to help us find the right stock and pricing.']}),(0,F.jsx)("div",{className:"quick-order-actions",children:(0,F.jsxs)("button",{type:"button",className:"cta-btn",disabled:!T||!!D,onClick:()=>{l("list_submitted",{method:"paste",lines:T}),xe(()=>e(d))},"aria-label":"Match pasted lines",children:[(0,F.jsx)("span",{children:"Match line items"}),(0,F.jsx)("span",{className:"arrow",children:(0,F.jsx)(Qt,{})})]})})]}):(0,F.jsxs)(F.Fragment,{children:[L&&(0,F.jsxs)("div",{className:"error-box",role:"alert",children:[(0,F.jsx)("strong",{children:"Error:"})," ",L]}),(0,F.jsxs)("div",{className:`upload-zone${w?" has-file":""}`,onClick:()=>o.current?.click(),onDragOver:P=>P.preventDefault(),onDrop:wt,role:"button",tabIndex:0,onKeyDown:P=>(P.key==="Enter"||P.key===" ")&&o.current?.click(),"aria-label":"Upload zone: click or drag a list or image file here",children:[C?(0,F.jsx)("img",{src:C,alt:w?.name??"Selected photo",className:"upload-zone-photo-preview"}):(0,F.jsx)("div",{className:"upload-zone-icon",children:(0,F.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,F.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,F.jsx)("polyline",{points:"14,2 14,8 20,8"}),(0,F.jsx)("polyline",{points:"9,15 11,17 15,13"})]})}),w?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)("div",{className:"upload-zone-subtext",children:w.name}),(0,F.jsx)("button",{type:"button",className:"link-btn link-btn--underline",onClick:P=>{P.stopPropagation(),A(null),h(""),o.current&&(o.current.value="")},children:"Remove"})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)("div",{className:"upload-zone-text",children:"Drop a photo, spreadsheet, Word document or PDF"}),(0,F.jsx)("div",{className:"upload-zone-subtext",children:"or click to choose a file"})]}),(0,F.jsx)("input",{ref:o,type:"file",accept:M_,className:"visually-hidden",onChange:P=>Oe(P.target.files),tabIndex:-1,"aria-hidden":"true"})]}),(0,F.jsx)("div",{className:"quick-order-actions",children:(0,F.jsxs)("button",{type:"button",className:"cta-btn",disabled:!w,onClick:()=>{X()},"aria-label":"Match uploaded items",children:[(0,F.jsx)("span",{children:"Match items"}),(0,F.jsx)("span",{className:"arrow",children:(0,F.jsx)(Qt,{})})]})})]})}),(0,F.jsx)("aside",{className:"quick-order-sidebar",children:T_[m].map((P,pe)=>(0,F.jsxs)("div",{className:"quick-order-step quick-order-step--rail",children:[(0,F.jsx)("span",{className:"quick-order-step-dot",children:pe+1}),(0,F.jsxs)("div",{children:[(0,F.jsx)("div",{className:"quick-order-step-title",children:P.title}),(0,F.jsx)("div",{className:"quick-order-step-desc",children:P.desc})]})]},P.title))})]}),u&&(0,F.jsx)("div",{className:"quick-order-matching-overlay",children:(0,F.jsx)(wv,{})})]})]})})]})]})}var zt=$(Ve()),kv=$(ee());function Ui(e){return JSON.stringify([e.productId,e.qty,e.unit,e.linkedContext??[]])}function z_(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 qd=(0,zt.createContext)(null);function lc({children:e,onOpenBasket:t}){let[a,r]=(0,zt.useState)({}),n=(0,zt.useCallback)(d=>{r(g=>z_(g,d))},[]),i=(0,zt.useCallback)(d=>{r(g=>{let w={...g};for(let A of d)w[A.lineId]=A;return w})},[]),o=(0,zt.useCallback)(d=>{r(g=>{let w={...g};return delete w[d],w})},[]),l=(0,zt.useCallback)((d,g)=>{r(w=>w[d]?{...w,[d]:{...w[d],qty:g,sellUnitsOverride:null}}:w)},[]),c=(0,zt.useCallback)((d,g)=>{r(w=>w[d]?{...w,[d]:{...w[d],sellUnitsOverride:g}}:w)},[]),p=(0,zt.useCallback)(d=>{r(g=>{let w=!1,A={...g};for(let[L,h]of Object.entries(d))A[L]&&(A[L]={...A[L],...h},w=!0);return w?A:g})},[]),m=(0,zt.useCallback)(()=>r({}),[]),f=(0,zt.useMemo)(()=>({cart:a,count:Object.keys(a).length,addToCart:n,addManyToCart:i,removeFromCart:o,updateCartQty:l,updateCartSellUnits:c,updateCartConversions:p,clearCart:m,openBasket:t??(()=>{})}),[a,n,i,o,l,c,p,m,t]);return(0,kv.jsx)(qd.Provider,{value:f,children:e})}function Di(){let e=(0,zt.useContext)(qd);if(!e)throw new Error("useCart must be used inside a <CartProvider>");return e}function xv(){return(0,zt.useContext)(qd)}var mt=$(Ve());function yn(e){return e===0?"-":Number.isInteger(e)?e.toString():e<1?e.toFixed(2):e.toFixed(1)}function ot(e){return`\xA3${e.toLocaleString("en-GB",{minimumFractionDigits:2,maximumFractionDigits:2})}`}var qv=e=>(e??"").trim().toLowerCase(),R_={sqm:"m2","sq m":"m2","m\xB2":"m2",cbm:"m3","cu m":"m3","m\xB3":"m3",lm:"m","lin m":"m","linear metre":"m","linear metres":"m","linear meter":"m","linear meters":"m",metre:"m",metres:"m",meter:"m",meters:"m",litre:"l",litres:"l",liter:"l",liters:"l",ltr:"l",ltrs:"l",rolls:"roll",coils:"coil",each:"each",ea:"each",nr:"each",no:"each",item:"each",unit:"each",units:"each",pc:"each",pcs:"each",piece:"each",pieces:"each",board:"sheet",bags:"bag",length:"length",lengths:"length",pallet:"pallet",pallets:"pallet"},Ed=new Set(["sheet","length","box","bag","pack","roll","set","tub","each"]),Md=new Set(["box","bag","pack","pallet","roll","set","tub"]),A_=new Set(["roll","coil"]),Td=(e,t)=>t==="ml"?e:["l","litre","litres"].includes(t)?e*1e3:null,zd=(e,t)=>t==="g"?e:["kg","kilogram","kilograms"].includes(t)?e*1e3:["t","tonne","tonnes"].includes(t)?e*1e6:null,Ta=e=>{let t=qv(e);return R_[t]??t},Sv=e=>{let t=Ta(e);return t==="ml"?{dimension:"volume",toBase:1}:t==="l"?{dimension:"volume",toBase:1e3}:t==="m3"?{dimension:"volume",toBase:1e6}:t==="g"?{dimension:"mass",toBase:1}:t==="kg"?{dimension:"mass",toBase:1e3}:t==="t"||t==="tonne"||t==="tonnes"?{dimension:"mass",toBase:1e6}:t==="mm"?{dimension:"length",toBase:.001}:t==="cm"?{dimension:"length",toBase:.01}:t==="m"?{dimension:"length",toBase:1}:t==="ft"?{dimension:"length",toBase:.3048}:t==="in"||t==="inch"||t==="inches"?{dimension:"length",toBase:.0254}:null},Ad=(e,t,a)=>{if(tt(t,a))return e;let r=Sv(t),n=Sv(a);return r&&n&&r.dimension===n.dimension?e*r.toBase/n.toBase:null},tt=(e,t)=>{let a=Ta(e),r=Ta(t);return a.length>0&&a===r},Rd=(e,t)=>{let a=qv(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},U_=e=>(e??"").split(",").map(t=>Ta(t)).filter(Boolean),D_=(e,t)=>{let a=U_(e.requestUomsSupported);return!!(a.length===0||a.includes(t)||e.unitConversions?.some(r=>Ad(1,t,r.requestUom)!=null)||tt(t,"pallet")&&e.itemsPerPallet!=null&&e.itemsPerPallet>0||tt(t,"pack")&&e.itemsPerPack!=null&&e.itemsPerPack>0||tt(t,"box")&&e.itemsPerBox!=null&&e.itemsPerBox>0)},Nv=(e,t)=>tt(t,"pallet")?e.itemsPerPallet??null:tt(t,"pack")?e.itemsPerPack??null:tt(t,"box")?e.itemsPerBox??null:null,Cv=(e,t)=>{let a=t==="volume"?/(\d+(?:[.,]\d+)?)\s*(ml|l|ltr|ltrs|litres?|liters?)\b/i:/(\d+(?:[.,]\d+)?)\s*(kg|kgs|tonnes?)\b/i,r=e.description.match(a);if(!r)return null;let n=Number.parseFloat(r[1].replace(",","."));if(!Number.isFinite(n)||n<=0)return null;let i=r[2].toLowerCase();return t==="volume"?{ml:i==="ml"?n:n*1e3}:{g:i.startsWith("tonne")?n*1e6:n*1e3}},O_=["volume_from_description","same_unit_volume"],B_=["weight_from_description","mass_from_pack","same_unit_mass"],L_=(e,t,a)=>{if(!tt(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||!tt(r[3],a))return null;let n=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(n)&&n>0?n:null},Ev=(e,t)=>t.costingMode==="review"&&!(e.conversionConfidence==="llm_basket_line"&&e.sellUnitsOverride!=null&&!e.conversionNotes?.trim());function sc(e,t){let a=e.map(r=>Ft(r,t).lineTotal);return a.some(r=>r==null)?null:a.reduce((r,n)=>r+(n??0),0)}function Ft(e,t){let a=H_(e,t);return a.sellUnit==="bag"&&a.requestedUnit!=="bag"&&/\bbulk bag\b/i.test(e.description)?{...a,sellUnit:"bulk bag"}:a}function H_(e,t){let a=e.qty,r=Ta(e.saleUnit??e.salesUnitSizeUom??e.uoi??e.salesUomNormalised)||"-",n=e.unitConversions?.find(X=>tt(X.requestUom,"each"))?.quantityPerSaleUnit,i=!Ta(e.unit)&&Md.has(r)&&n!=null&&n>1&&a>=n,o=Ta(e.unit)||(i?"each":a>0&&Ed.has(r)?r:"-"),l=e.saleUnitQuantity??e.salesUnitSize??e.uoiCount??1,c=t?.wasteFactorEnabled===!1?0:t?.wasteFactorOverride??e.wasteFactorOverride??e.wasteFactorDefault??0,p=e.sellUnitsOverride!=null&&Number.isFinite(e.sellUnitsOverride)&&e.sellUnitsOverride>0,m=p?Ed.has(r)?Math.ceil(e.sellUnitsOverride):e.sellUnitsOverride:null,f=X=>({requestedAmount:a,requestedUnit:o,salesUnitSize:e.salesUnitSize??e.uoiCount??null,sellUnit:r,calculatedSellUnits:null,requiredSellUnits:m,unitPrice:e.price,lineTotal:e.price!=null&&m!=null?e.price*m:null,calculation:m!=null?`${X} Order quantity set to ${m} ${r}.`:X,costingMode:"review"});if(!Number.isFinite(a)||a<=0)return f("Quantity needs confirmation.");let d=Td(a,o),g=zd(a,o),w=tt(o,r)?null:d!=null&&!O_.includes(e.conversionType??"")?Cv(e,"volume"):g!=null&&!B_.includes(e.conversionType??"")?Cv(e,"weight"):null,A=w?.ml!=null?d:g,L=w?.ml??w?.g??null;if(A!=null&&L!=null){let X=Ta(e.uoi)||r,J=w?.ml!=null?`${L/1e3} l`:`${L/1e3} kg`,ze=p?m:Math.ceil(A*(1+c)/L-1e-9);return{requestedAmount:a,requestedUnit:o,salesUnitSize:1,sellUnit:X,calculatedSellUnits:ze,requiredSellUnits:ze,unitPrice:e.price,lineTotal:e.price!=null?e.price*ze:null,calculation:`${a} ${o}${c>0?` x ${1+c}`:""} / ${J} per ${X} (from product description) = ${ze} ${X}`,costingMode:"derived"}}if(o==="sales_unit"){let X=Ta(e.uoi)||r,J=p?m:Rd(a*(1+c),e.roundingRule??"round_up_each");return{requestedAmount:a,requestedUnit:X,salesUnitSize:1,sellUnit:X,calculatedSellUnits:J,requiredSellUnits:J,unitPrice:e.price,lineTotal:e.price!=null?e.price*J:null,calculation:`${a} ${X}${c>0?` x ${1+c}`:""} = ${J} ${X}`,costingMode:"direct"}}let h=A_.has(o),u=/\b(?:pack|box)\s+of\s+(\d+)\s+(?:rolls?|coils?)\b|\b(\d+)\s+(?:rolls?|coils?)\s+(?:per|in each)\s+(?:pack|box)\b/i.test(e.description),b=r==="pack"?e.itemsPerPack:null,v=(e.derivedLengthM??0)>0||(e.derivedCoverageM2??0)>0||/^(?:m2|m²|sqm|m)\s*(?:per|\/)/i.test(e.coverageUom??"");if(h&&["each","pack"].includes(r)&&l===1&&!(b!=null&&b>1)&&!u&&v){let X=p?m:Rd(a*(1+c),e.roundingRule??"round_up_each");return{requestedAmount:a,requestedUnit:o,salesUnitSize:l,sellUnit:r,calculatedSellUnits:X,requiredSellUnits:X,unitPrice:e.price,lineTotal:e.price!=null?e.price*X:null,calculation:`${a} ${o}${c>0?` x ${1+c}`:""} = ${X} ${r} (one product per sale unit)`,costingMode:"derived"}}if(!D_(e,o))return f("Requested unit is not supported by this catalogue conversion.");let _=null,C="review",R=e.roundingRule,T=`Quantity review required, initial request needed ${a} ${o}.`,D=1+c,V=L_(e,o,r),oe=e.unitConversions?.find(X=>Ad(1,o,X.requestUom)!=null),_e=oe?Ad(a,o,oe.requestUom):null;if(!!e.saleUnit&&(tt(o,r)||!!oe||tt(o,"each")&&!Md.has(r)))if(tt(o,r))_=a*D/l,C="direct",T=`${a} ${o}${c>0?` x ${D}`:""}`;else if(oe&&_e!=null){_=_e*D/oe.quantityPerSaleUnit,C="derived";let X=1/oe.quantityPerSaleUnit,J=Math.round(X),ze=tt(r,"each")&&oe.quantityPerSaleUnit<1&&Math.abs(X-J)<1e-9,Ee=tt(o,oe.requestUom)?`${a} ${o}`:`${a} ${o} (${_e} ${oe.requestUom})`;T=ze?`${a} ${o}${c>0?` x ${D}`:""} x ${J} per ${o}`:`${Ee}${c>0?` x ${D}`:""} / ${oe.quantityPerSaleUnit} ${oe.requestUom} per ${r}`}else tt(o,"each")&&!Md.has(r)&&(_=a*D/l,C="derived",T=`${a} ${r}${c>0?` x ${D}`:""}`);else if(tt(o,r)&&l>0)_=a*D/l,C="direct",T=c>0?`${a} ${o} x ${D} / ${l} ${r} per sell unit`:`${a} ${o} / ${l} ${r} per sell unit`;else if(tt(o,"each")&&l>0&&Ed.has(r))_=a*D/l,C="derived",T=c>0?`${a} each x ${D} / ${l} each per ${r}`:`${a} each / ${l} each per ${r}`;else if(Nv(e,o)!=null&&l>0){let X=Nv(e,o)??0;_=a*X*D/l,C="derived";let J=`${a} ${o} x ${X} each${c>0?` x ${D}`:""}`;T=l===1&&tt(r,"each")?J:`${J} / ${l} each per ${r}`}else if(V!=null)_=a*D/V,C="derived",R??(R="round_up_each"),T=`${a} m2 x ${D} / ${V} m2 per ${r} (from product description)`;else if(e.conversionType==="basket_line_unit")l>0&&(_=a*D/l,C="derived",T=`${a} ${o}${c>0?` x ${D}`:""} / ${l} ${o} per ${r}`);else{if(e.conversionType==="count_only")return f(`Quantity review required, initial request needed ${a} ${o}.`);if(["area_from_dims","explicit_coverage_area","roll_area"].includes(e.conversionType??"")){let X=e.coverageQty??e.derivedCoverageM2??null;tt(o,"m2")&&X!=null&&X>0&&(_=a*D/X,C="derived",T=`${a} m2 x ${D} / ${X} m2 per ${r}`)}else if(e.conversionType==="count_per_area"){let X=e.coverageQty??null;tt(o,"m2")&&X!=null&&X>0?(_=a/X,C="derived",T=`${a} m2 / ${X} m2 per sell unit`):tt(o,"m2")&&e.itemsPerM2!=null&&e.itemsPerM2>0&&l>0&&(_=a*e.itemsPerM2*D/l,C="derived",T=`${a} m2 x ${e.itemsPerM2} ${r}/m2 x ${D} / ${l}`)}else if(e.conversionType==="length_from_dims"){let X=e.coverageQty??e.derivedLengthM??null;tt(o,"m")&&X!=null&&X>0&&(_=a*D/X,C="derived",T=`${a} m x ${D} / ${X} m per ${r}`)}else if(e.conversionType==="volume_from_description"){let X=Td(a,o),J=Td(e.coverageQty??0,Ta(e.coverageUom));X!=null&&J!=null&&J>0&&(_=X*D/J,C="derived",T=`${a} ${o} x ${D} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="weight_from_description"||e.conversionType==="mass_from_pack"){let X=Ta((e.coverageUom??"").split(" ")[0]),J=zd(a,o),ze=zd(e.coverageQty??0,X);J!=null&&ze!=null&&ze>0&&(_=J*D/ze,C="derived",T=`${a} ${o} x ${D} / ${e.coverageQty} ${X} per ${r}`)}else if(e.conversionType==="same_unit_volume"){let X=e.coverageQty??null;tt(o,"m3")&&X!=null&&X>0&&(_=a/X,C="derived",T=`${a} m3 / ${X} m3 per ${r}`)}}if(_==null||!Number.isFinite(_)||_<0)return f(`Quantity review required, initial request needed ${a} ${o}.`);let Oe=Rd(_,R),xe=p?m:Oe;return{requestedAmount:a,requestedUnit:o,salesUnitSize:l,sellUnit:r,calculatedSellUnits:Oe,requiredSellUnits:xe,unitPrice:e.price,lineTotal:e.price!=null&&xe!=null?e.price*xe:null,calculation:p?`${T} = ${Oe} ${r} (manually set to ${xe})`:`${T} = ${xe} ${r}`,costingMode:C}}var il=$(ee());function Ud({unit:e}){return(0,il.jsx)(il.Fragment,{children:e.split(/([²³])/).map((t,a)=>t==="\xB2"||t==="\xB3"?(0,il.jsx)("span",{className:"unit-sup",children:t},a):t)})}var Mv=$(ee());function Q_(e,t){return t===1||/^(m\d*|mm|cm|ml|kg|g)$/i.test(e)?e:/(s|x|z|ch|sh)$/i.test(e)?`${e}es`:/[^aeiou]y$/i.test(e)?`${e.slice(0,-1)}ies`:`${e}s`}function Wt(e,t){let a=(e??"").trim();if(!a||a==="-")return"";let r=/^each$/i.test(a)?"unit":/^l$/i.test(a)?"litre":a;return t!=null?Q_(r,t):r}function xa(e,t){let a=Wt(e,t);return a?(0,Mv.jsx)(Ud,{unit:a}):null}function ol(e){let t=(e??"").trim();if(!t)return"";let a=t.match(/^per\s+(.+)$/i);if(!a)return t;let r=Wt(a[1]);return r?`per ${r}`:""}var Tv=()=>import("./xlsx-K4MOA2QM.js"),sl=["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","Review required","Decision reason","Selected candidate ID","Selected candidate description","Price basis","Price","Line total","Confidence","Status"],G_=sl.indexOf("Line total");function j_(e){return e.unmatchable?"Not matched (labour/plant/referential)":e.best?"Selected":"Needs review"}async function zv(e){let t=await Tv(),a=t.utils.book_new(),r=new Date().toISOString().slice(0,10),n=[sl],i=0;for(let c of e){let{item:p,best:m,qty:f,band:d,unmatchable:g,decision:w}=c,A=[p.section,p.subsection,p.subheading].filter(Boolean).join(" / "),L=!g&&m?.price!=null?m.price*f:null;L!=null&&(i+=L),n.push([p.source_line_id,p.line_id,p.description_original||"(no description)",A,f,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(", "),m?"no":"yes",w?.reason??"",g?"-":m?.product_id??w?.selected_candidate_id??"-",g?"-":m?.description??"-",g?"-":m?.price_basis??"-",g?null:m?.price??null,L,g?"-":d,j_(c)])}n.push(Array(sl.length).fill(null));let o=Array(sl.length).fill(null);o[0]="Estimated total",o[G_]=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(sl.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 ll=["Product ID","Description","Costing mode","Required amount","Req unit","Sell unit size","Sell unit","Required sell units","Unit price","Line total"];async function Rv(e,t){let a=await Tv(),r=a.utils.book_new(),n=new Date().toISOString().slice(0,10),i=t?[["Account",t.name+" ("+t.id+")"],[],ll]:[ll],o=0;for(let p of e){let m=Ft(p),f=m.lineTotal;f!=null&&(o+=f),i.push([p.productId,p.description,m.costingMode,m.requestedAmount,Wt(m.requestedUnit),m.salesUnitSize,Wt(m.sellUnit),m.requiredSellUnits,m.unitPrice,f])}i.push(Array(ll.length).fill(null));let l=Array(ll.length).fill(null);l[0]="Estimated total",l[ll.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 Dd=$(ee());function Vr(){return(0,Dd.jsx)("svg",{className:"back-arrow",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,Dd.jsx)("path",{d:"M13 8H3M3 8L7 4M3 8L7 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}var Od=$(ee());function _n(){return(0,Od.jsx)("svg",{width:"8",height:"5",viewBox:"0 0 8 5",fill:"none",children:(0,Od.jsx)("path",{d:"M1 4L4 1L7 4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}var xn=$(ee());function Bd(){return(0,xn.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,xn.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,xn.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,xn.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,xn.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}var ja=$(ee());function Ld(e){return(0,ja.jsxs)("svg",{viewBox:"0 0 640 420",preserveAspectRatio:"xMidYMid slice",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",...e,children:[(0,ja.jsx)("rect",{width:"640",height:"420",fill:"#fbf1cf"}),(0,ja.jsx)("rect",{x:"88",y:"78",width:"432",height:"264",rx:"16",fill:"#f0c43f"}),(0,ja.jsx)("rect",{x:"120",y:"110",width:"368",height:"200",rx:"10",fill:"#ffd95e"}),(0,ja.jsxs)("g",{stroke:"#e2b12e",strokeWidth:"8",opacity:"0.75",children:[(0,ja.jsx)("line",{x1:"140",y1:"140",x2:"468",y2:"140"}),(0,ja.jsx)("line",{x1:"140",y1:"190",x2:"468",y2:"190"}),(0,ja.jsx)("line",{x1:"140",y1:"240",x2:"468",y2:"240"})]})]})}var Xr=$(ee());function Hd(e){return(0,Xr.jsxs)("svg",{viewBox:"0 0 640 420",preserveAspectRatio:"xMidYMid slice",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",...e,children:[(0,Xr.jsx)("rect",{width:"640",height:"420",fill:"#edf1f5"}),(0,Xr.jsx)("rect",{x:"132",y:"108",width:"376",height:"204",rx:"18",fill:"#d5dde6"}),(0,Xr.jsx)("rect",{x:"168",y:"144",width:"304",height:"24",rx:"12",fill:"#9aa6b2"}),(0,Xr.jsx)("rect",{x:"168",y:"188",width:"250",height:"24",rx:"12",fill:"#aab5c0"}),(0,Xr.jsx)("rect",{x:"168",y:"232",width:"220",height:"24",rx:"12",fill:"#aab5c0"})]})}var Qd=$(ee()),Y_=[{match:["building sand"],path:"/schedule-products/building-sand.webp"},{match:["drywall screw"],path:"/schedule-products/drywall-screws.webp"},{match:["scrim"],path:"/schedule-products/scrim-tape.webp"},{match:["loft insulation","loft roll"],path:"/schedule-products/loft-insulation-roll.webp"},{match:["wall tie"],path:"/schedule-products/wall-ties.webp"},{match:["red multi","multi stock","brick"],path:"/schedule-products/red-multi-stock-bricks.webp"}];function za({description:e,photoUrl:t,className:a,width:r,height:n}){let i=(e||"").toLowerCase(),o=Y_.find(p=>p.match.some(m=>i.includes(m))),l=t||o&&It(o.path);if(l)return(0,Qd.jsx)("img",{className:a,src:l,alt:"",width:r,height:n});let c=i.includes("insulation")?Ld:Hd;return(0,Qd.jsx)(c,{className:a,width:r,height:n})}var M=$(ee()),Av=.2,cl=10,Uv="Enter a valid email address so we can send your quote.",$_=(e,t)=>{let a=`${t.requestedAmount} ${Wt(t.requestedUnit,t.requestedAmount)}`,r=`${t.requiredSellUnits} ${Wt(t.sellUnit,t.requiredSellUnits??0)}`,n=e.unitConversions?.find(o=>o.requestUom===t.requestedUnit);if(n&&n.quantityPerSaleUnit<1){let o=Math.round(1/n.quantityPerSaleUnit),l=Math.abs(o*n.quantityPerSaleUnit-1)<1e-9?`${o} ${Wt(t.sellUnit,o)} per ${Wt(t.requestedUnit,1)}`:`${n.quantityPerSaleUnit} ${Wt(t.requestedUnit,n.quantityPerSaleUnit)} per ${Wt(t.sellUnit,1)}`;return`${a} requested \u2192 order ${r} (${l})`}let i=t.sellUnit==="bulk bag"?e.description.match(/(\d+(?:\.\d+)?)\s*kg\b/i):null;return i?`${a} requested \u2192 order ${r} (${i[1]} kg each)`:e.coverageQty&&/^m per /i.test(e.coverageUom??"")?`${a} requested \u2192 order ${r} (${e.coverageQty} ${e.coverageUom})`:`${a} requested \u2192 order ${r}`},V_=e=>["box","pack"].includes(e.requestedUnit)?"Pack size needed to calculate the order quantity.":`This product is sold by the ${Wt(e.sellUnit,1)}.`;function ul({cart:e,onUpdateQty:t,onUpdateSellUnits:a,onResolveConversions:r,onRemove:n,onBack:i,onStartNewQuote:o,onQuoteRequested:l,internal:c=!1}){let p=(0,mt.useId)(),m=Ei(),f=!c&&Is()==="QZA6-MRA4",d=!c,g=Object.values(e),w=(0,mt.useRef)(new Map),[A,L]=(0,mt.useState)(""),[h,u]=(0,mt.useState)(!1),[b,v]=(0,mt.useState)(!1),[_,C]=(0,mt.useState)(""),[R,T]=(0,mt.useState)({}),[D,V]=(0,mt.useState)({}),[oe,_e]=(0,mt.useState)(1),[Te,Oe]=(0,mt.useState)({}),[xe,X]=(0,mt.useState)(!1),[J,ze]=(0,mt.useState)("0"),[Ee,wt]=(0,mt.useState)({});(0,mt.useEffect)(()=>{if(!r)return;for(let U of Object.values(e))Ft(U).requiredSellUnits!=null&&w.current.delete(U.lineId);let x=Object.values(e).filter(U=>{if(U.productId==="-"||Ft(U).requiredSellUnits!=null)return!1;let Z=Ui(U);return w.current.get(U.lineId)===Z?!1:(w.current.set(U.lineId,Z),!0)});if(x.length===0)return;let E=new Map(x.map(U=>[U.lineId,Ui(U)]));wt(U=>({...U,...Object.fromEntries(E)})),fetch(Ma("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Mi()},body:JSON.stringify({lines:x.map(U=>({line_id:U.lineId,product_id:U.productId,requested_description:U.requestedDescription??U.description,requested_qty:U.qty,requested_uom:U.unit||null,linked_context:U.linkedContext??[],selected_description:U.description,selected_uoi:U.uoi,selected_uoi_count:U.uoiCount,selected_conversion:{sales_uom_normalised:U.salesUomNormalised,conversion_type:U.conversionType,sales_unit_size:U.salesUnitSize,sales_unit_size_uom:U.salesUnitSizeUom,coverage_qty:U.coverageQty,coverage_uom:U.coverageUom}}))})}).then(U=>U.ok?Ga(U):null).then(U=>{let Z={},N=new Map(x.map(G=>[G.lineId,Ui(G)]));for(let G of U?.data?.items??U?.items??[]){let Y=G?.conversion;!Y||typeof G?.line_id!="string"||w.current.get(G.line_id)!==N.get(G.line_id)||(Z[G.line_id]={conversionConfidence:Y.conversion_confidence,conversionNotes:Y.conversion_notes,...Number.isFinite(Y.suggested_order_qty)&&Y.suggested_order_qty>0?{sellUnitsOverride:Y.suggested_order_qty}:{}})}Object.keys(Z).length>0&&r(Z)}).catch(U=>console.error("Catalogue conversion resolution failed",U)).finally(()=>{wt(U=>{let Z={...U};for(let[N,G]of E)Z[N]===G&&delete Z[N];return Z})})},[e,r]);function P(x){T(E=>{let U={...E};return delete U[x],U})}function pe(x,E){let U=parseFloat(E);!isNaN(U)&&U>=0&&t(x,Math.min(U,1e5)),P(x)}function Re(x,E,U){t(x,Math.min(1e5,Math.max(0,E+U))),P(x)}function Ot(x){V(E=>{let U={...E};return delete U[x],U})}function jt(x,E){let U=parseFloat(E);!isNaN(U)&&U>=0&&a(x,Math.min(U,1e5)),Ot(x)}function qe(x,E,U){a(x,Math.min(1e5,Math.max(0,E+U))),Ot(x)}async function ke(){if(Be.some(({pricing:E})=>E.lineTotal==null)){C(f?"Confirm the highlighted quantities before requesting a quote.":"Confirm the highlighted quantities before sending your basket.");return}let x=A.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(x)){C(Uv);return}C(""),v(!0);try{let E=await fetch(Ma("/api/quote-requests"),{method:"POST",headers:{"Content-Type":"application/json",...Mi()},body:JSON.stringify({email:x,items:Be.map(({item:U,pricing:Z})=>{let N=Z.requiredSellUnits??Z.requestedAmount,G=Z.requiredSellUnits!=null?Z.sellUnit:Z.requestedUnit;return{product_id:U.productId,description:U.description,quantity:N,unit:Wt(G,N),unit_price:Z.requiredSellUnits!=null?Z.unitPrice:null,line_total:Z.lineTotal}})})});if(!E.ok){let U=await Ga(E);console.error("Quote request failed",E.status,U?.message),C(E.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}z!=null&&m("quote_requested",{items:Be.length,total:Math.round(z*100)/100}),u(!0),l?.(),window.scrollTo(0,0)}catch{C("Your request couldn't be sent. Check your connection and try again.")}finally{v(!1)}}let Be=g.map(x=>({item:x,pricing:Ft(x,{wasteFactorEnabled:xe,wasteFactorOverride:Math.max(0,Number.parseFloat(J)||0)/100})})),Ye=sc(g,{wasteFactorEnabled:xe,wasteFactorOverride:Math.max(0,Number.parseFloat(J)||0)/100}),vt=Ye==null?null:Ye*Av,z=Ye==null?null:Ye*(1+Av),H=Be.filter(({pricing:x})=>x.lineTotal==null).length,le=Object.keys(Ee).length,de=!!r&&g.some(x=>{if(x.productId==="-"||Ft(x).requiredSellUnits!=null)return!1;let E=Ui(x);return w.current.get(x.lineId)!==E||Ee[x.lineId]===E}),me=(0,mt.useRef)({items:Be.length,...z==null?{}:{total:Math.round(z*100)/100}});(0,mt.useEffect)(()=>{m("basket_viewed",me.current)},[m]);let $e=Math.max(1,Math.ceil(Be.length/cl)),Le=Math.min(oe,$e),k=Be.slice((Le-1)*cl,Le*cl);return h?(0,M.jsx)("div",{className:"wizard-step entry-stage",children:(0,M.jsxs)("div",{className:"quote-request-sent",role:"status",children:[(0,M.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,M.jsx)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,M.jsx)("polyline",{points:"5 12.5 10 17.5 19 7"})})}),(0,M.jsx)("h1",{children:f?"Quote requested":"Basket sent"}),f?(0,M.jsxs)("p",{children:["You're all done. We'll email your sharper price to ",(0,M.jsx)("strong",{children:A.trim()}),", usually within one working day."]}):(0,M.jsxs)("p",{children:["You're all done. We'll email ",(0,M.jsx)("strong",{children:A.trim()})," to confirm prices, availability and delivery, usually within one working day."]}),(0,M.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,M.jsx)("span",{children:f?"Start a new quote":"Start a new basket"})}),(0,M.jsx)("p",{className:"quote-request-sent-note",children:f?"Nothing is charged until you approve the quote.":"Nothing is charged until you approve the order."})]})}):!c&&g.length===0?(0,M.jsx)("div",{className:"wizard-step entry-stage",children:(0,M.jsxs)("div",{className:"quote-request-sent",children:[(0,M.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,M.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,M.jsx)("path",{d:"M3 9h18l-2 11H5z"}),(0,M.jsx)("path",{d:"M8 9l4-6 4 6"})]})}),(0,M.jsx)("h1",{children:f?"Your quote request is empty":"Your basket is empty"}),(0,M.jsx)("p",{children:f?"Start again with your list to build your quote.":"Start again with your list to fill your basket."}),(0,M.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,M.jsx)("span",{children:"Back to start"})})]})}):(0,M.jsx)("div",{className:`wizard-step entry-stage${f?" basket-layout--qza6-mra4":""}`,children:(0,M.jsxs)("div",{className:`quick-order-card${c?"":" quick-order-card--customer"}`,children:[(0,M.jsxs)("div",{className:`quick-order-hero${c?"":" quick-order-hero--customer"}`,children:[c&&(0,M.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,M.jsxs)("div",{className:"basket-hero-copy",children:[f&&(0,M.jsxs)("button",{type:"button",className:"cta-btn cta-btn-secondary basket-hero-back",onClick:i,children:[(0,M.jsx)(Vr,{}),(0,M.jsx)("span",{children:"Back to results"})]}),(0,M.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,M.jsx)("h1",{children:c?"Your Selection":f?"Request a quote":"Your Basket"}),c&&(0,M.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,M.jsx)("strong",{children:g.length})," ",g.length===1?"item":"items"]})]}),(0,M.jsx)("p",{children:c?"Review the items you've added before exporting them for review.":f?"Check your items and quantities below, and we'll do our best to beat list prices.":"Review your quantities and order summary, then send us your basket."})]})]}),(0,M.jsx)("div",{className:"quick-order-panel",style:{paddingTop:16},children:de?(0,M.jsxs)("div",{className:"basket-resolving",role:"status","aria-label":"Calculating order quantities",children:[(0,M.jsx)("span",{className:"basket-resolving-wheel","aria-hidden":"true"}),(0,M.jsx)("span",{children:"Calculating your quantities\u2026"})]}):g.length===0?(0,M.jsxs)("div",{className:"quick-order-history-empty",children:[(0,M.jsx)("div",{className:"basket-empty-icon","aria-hidden":"true",children:"\u{1F4CB}"}),(0,M.jsx)("p",{children:"Your selection is empty."}),(0,M.jsx)("p",{className:"basket-empty-hint",children:"Go back to your results and add quoted items."}),(0,M.jsx)("div",{className:"btn-row",style:{marginTop:20,justifyContent:"center"},children:(0,M.jsx)("button",{className:"cta-btn",style:{width:"auto",maxWidth:280},onClick:i,"aria-label":"Back to results",children:(0,M.jsx)("span",{children:"Back to Results"})})})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)("div",{className:"basket-layout",children:[(0,M.jsxs)("div",{className:"basket-main",children:[(0,M.jsx)("div",{className:"basket-list","aria-label":c?"Selection items":f?"Quote request items":"Basket items",children:k.map(({item:x,pricing:E})=>{let U=R[x.lineId]??String(E.requestedAmount),Z=Ev(x,E),N=E.requestedUnit===E.sellUnit||Z,G=E.requiredSellUnits==null||E.requestedAmount!==E.requiredSellUnits||E.requestedUnit!==E.sellUnit;return(0,M.jsxs)("article",{className:"basket-card",children:[(0,M.jsxs)("div",{className:"basket-card-top",children:[(0,M.jsx)(za,{className:"basket-card-thumb",description:x.description,photoUrl:x.pdpPhotoUrl,width:48,height:48}),(0,M.jsxs)("div",{className:"basket-card-info",children:[(0,M.jsx)("div",{className:"bom-component-name",children:x.description}),G&&E.costingMode!=="review"&&(0,M.jsxs)("button",{type:"button",className:"basket-calc-toggle",onClick:()=>Oe(Y=>({...Y,[x.lineId]:!Y[x.lineId]})),"aria-expanded":!!Te[x.lineId],children:["How we calculated this",(0,M.jsx)("span",{className:`basket-calc-toggle-chevron${Te[x.lineId]?" basket-calc-toggle-chevron--open":""}`,children:(0,M.jsx)(_n,{})})]})]}),(0,M.jsx)("div",{className:"basket-card-actions",children:(0,M.jsx)("button",{type:"button",className:"mf-remove-small-btn basket-card-remove",onClick:()=>n(x.lineId),"aria-label":`Remove ${x.description}`,children:(0,M.jsx)(Bd,{})})})]}),c&&(0,M.jsxs)("div",{className:"results-detail-block basket-internal-detail",children:[(0,M.jsxs)("dl",{className:"results-detail-grid",children:[(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Conversion type"}),(0,M.jsx)("dd",{children:x.conversionType??"-"})]}),(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Conversion confidence"}),(0,M.jsx)("dd",{children:x.conversionConfidence??"-"})]}),(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Sales unit"}),(0,M.jsx)("dd",{children:x.salesUnitSize!=null?(0,M.jsxs)(M.Fragment,{children:[x.salesUnitSize," ",xa(x.salesUnitSizeUom,x.salesUnitSize)]}):"-"})]}),(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Coverage"}),(0,M.jsx)("dd",{children:x.coverageQty!=null?(0,M.jsxs)(M.Fragment,{children:[x.coverageQty," ",xa(x.coverageUom,x.coverageQty)]}):"-"})]}),(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Waste factor"}),(0,M.jsx)("dd",{children:x.wasteFactorDefault??"-"})]}),(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Rounding rule"}),(0,M.jsx)("dd",{children:x.roundingRule??"-"})]})]}),x.conversionNotes&&(0,M.jsx)("p",{className:"results-rerank-note",children:x.conversionNotes})]}),Z?(0,M.jsx)("p",{className:"basket-calc-text basket-calc-text--review",children:Ee[x.lineId]===Ui(x)?(0,M.jsx)("strong",{children:"Calculating order quantity\u2026"}):x.conversionNotes?.trim()?x.conversionNotes.trim():(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)("strong",{children:"Quantity needs confirmation."})," ",V_(E)]})}):G&&Te[x.lineId]?(0,M.jsx)("p",{className:"basket-calc-text",children:$_(x,E)}):null,(0,M.jsxs)("div",{className:"basket-card-stats",children:[(0,M.jsxs)("div",{className:"basket-stat",children:[(0,M.jsx)("span",{className:"basket-stat-label",children:"Requested qty"}),(0,M.jsxs)("div",{className:"basket-stat-value",children:[(0,M.jsxs)("div",{className:"basket-qty-field",children:[(0,M.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:U,disabled:N,onChange:Y=>T(ce=>({...ce,[x.lineId]:Y.target.value})),onBlur:Y=>pe(x.lineId,Y.target.value),onKeyDown:Y=>{Y.key==="Enter"&&Y.target.blur()},"aria-label":`${x.description} requested quantity`}),(0,M.jsxs)("div",{className:"basket-qty-arrows",children:[(0,M.jsx)("button",{type:"button",className:"basket-qty-arrow",disabled:N,onClick:()=>Re(x.lineId,parseFloat(U)||0,1),"aria-label":`Increase ${x.description} quantity`,children:(0,M.jsx)(_n,{})}),(0,M.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",disabled:N,onClick:()=>Re(x.lineId,parseFloat(U)||0,-1),"aria-label":`Decrease ${x.description} quantity`,children:(0,M.jsx)(_n,{})})]})]}),(0,M.jsx)("span",{className:"basket-metric-unit",children:xa(E.requestedUnit,parseFloat(U)||0)})]})]}),(0,M.jsxs)("div",{className:"basket-stat basket-stat--right",children:[(0,M.jsx)("span",{className:"basket-stat-label",children:"Order qty"}),(0,M.jsxs)("div",{className:"basket-stat-value",children:[(0,M.jsxs)("div",{className:"basket-qty-field",children:[(0,M.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:D[x.lineId]??String(E.requiredSellUnits??""),onChange:Y=>V(ce=>({...ce,[x.lineId]:Y.target.value})),onBlur:Y=>jt(x.lineId,Y.target.value),onKeyDown:Y=>{Y.key==="Enter"&&Y.target.blur()},"aria-label":`${x.description} order quantity`}),(0,M.jsxs)("div",{className:"basket-qty-arrows",children:[(0,M.jsx)("button",{type:"button",className:"basket-qty-arrow",onClick:()=>qe(x.lineId,parseFloat(D[x.lineId]??String(E.requiredSellUnits??"0"))||0,1),"aria-label":`Increase ${x.description} order quantity`,children:(0,M.jsx)(_n,{})}),(0,M.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",onClick:()=>qe(x.lineId,parseFloat(D[x.lineId]??String(E.requiredSellUnits??"0"))||0,-1),"aria-label":`Decrease ${x.description} order quantity`,children:(0,M.jsx)(_n,{})})]})]}),(0,M.jsx)("span",{className:"basket-metric-unit",children:xa(E.sellUnit,parseFloat(D[x.lineId]??String(E.requiredSellUnits??"0"))||0)})]})]}),(0,M.jsxs)("div",{className:"basket-stat basket-stat--total",children:[(0,M.jsx)("span",{className:"basket-stat-label",children:"Total"}),(0,M.jsxs)("div",{className:"basket-stat-value",children:[(0,M.jsx)("strong",{children:E.lineTotal!=null?ot(E.lineTotal):"-"}),E.lineTotal!=null&&(0,M.jsx)("span",{className:"basket-metric-unit",children:"ex. VAT"})]})]})]})]},x.lineId)})}),$e>1&&(0,M.jsxs)("div",{className:"results-pagination",children:[(0,M.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(Le-1)*cl+1,"\u2013",Math.min(Le*cl,Be.length)," of ",Be.length]}),(0,M.jsxs)("div",{className:"results-pagination-controls",children:[(0,M.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>_e(Le-1),disabled:Le===1,children:"Previous"}),(0,M.jsxs)("span",{className:"results-pagination-page",children:["Page ",Le," of ",$e]}),(0,M.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>_e(Le+1),disabled:Le===$e,children:"Next"})]})]})]}),(0,M.jsxs)("aside",{className:"basket-sidebar",children:[(0,M.jsx)("div",{className:"basket-sidebar-title",children:f?"Quote request summary":"Order summary"}),(0,M.jsxs)("div",{className:"basket-sidebar-row",children:[(0,M.jsx)("span",{children:f?"List price (ex. VAT)":"Subtotal (ex. VAT)"}),(0,M.jsx)("span",{children:Ye==null?"To confirm":ot(Ye)})]}),(0,M.jsxs)("div",{className:"basket-sidebar-row",children:[(0,M.jsx)("span",{children:"VAT (20%)"}),(0,M.jsx)("span",{children:vt==null?"To confirm":ot(vt)})]}),(0,M.jsxs)("div",{className:"basket-sidebar-row basket-sidebar-row--total",children:[(0,M.jsx)("span",{children:f?"List price (inc.\xA0VAT)":"Total"}),(0,M.jsx)("span",{children:z==null?"To confirm":ot(z)})]}),!f&&(0,M.jsx)("div",{className:"basket-summary-waste",children:(0,M.jsxs)("div",{className:"basket-waste-control",children:[(0,M.jsxs)("label",{className:"basket-global-waste",children:[(0,M.jsx)("input",{type:"checkbox",checked:xe,onChange:x=>X(x.target.checked)}),(0,M.jsx)("span",{children:"Add waste factor"})]}),(0,M.jsxs)("label",{className:"basket-global-waste-percent",children:[(0,M.jsx)("input",{type:"number",inputMode:"decimal",min:"0",step:"0.1",value:J,onChange:x=>ze(x.target.value),disabled:!xe,"aria-label":"Waste factor percent"}),(0,M.jsx)("span",{children:"%"})]})]})}),(0,M.jsx)("label",{htmlFor:`${p}-basket-reference`,className:"basket-sidebar-label",children:f?"Enter email for your sharper quote":d?"Your email":"Your reference (optional)"}),(0,M.jsx)("input",{id:`${p}-basket-reference`,type:d?"email":"text",className:"basket-sidebar-input",value:A,onChange:x=>{L(x.target.value),d&&C("")},placeholder:d?"you@example.com":"PO number or job reference","aria-invalid":d&&_===Uv,"aria-describedby":d&&_?`${p}-basket-reference-error`:void 0}),d&&_&&(0,M.jsx)("p",{id:`${p}-basket-reference-error`,className:"basket-quote-request-error",role:"alert",children:_}),d?(0,M.jsx)("button",{type:"button",className:"cta-btn",onClick:()=>{ke()},disabled:b||H>0||le>0,"aria-busy":b,children:(0,M.jsx)("span",{children:b?"Sending\u2026":f?"Request our best quote":"Send basket"})}):(0,M.jsx)("button",{className:"cta-btn",onClick:()=>{m("downloaded",{type:"basket",items:g.length}),Rv(g)},"aria-label":"Download selection",children:(0,M.jsx)("span",{children:"Download Quote"})}),(0,M.jsxs)("p",{className:"basket-sidebar-disclaimer",children:[(0,M.jsx)("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),f?"This is a quote request, not an order. We'll confirm our best price, availability and delivery before you approve.":d?"Sending your basket isn't an order. We'll confirm prices, availability and delivery before you approve.":"Prices and availability are estimates and should be confirmed before procurement."]})]})]}),(0,M.jsx)("div",{className:"btn-row results-actions",children:(0,M.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,M.jsx)(Vr,{}),(0,M.jsx)("span",{children:"Back to results"})]})})]})})]})})}var ye=$(Ve());function Oi(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 kn=$(ee());function jd(){return(0,kn.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,kn.jsx)("path",{d:"M3 12a9 9 0 0 1 15.36-6.36L21 8"}),(0,kn.jsx)("path",{d:"M21 3v5h-5"}),(0,kn.jsx)("path",{d:"M21 12a9 9 0 0 1-15.36 6.36L3 16"}),(0,kn.jsx)("path",{d:"M3 21v-5h5"})]})}var s=$(ee()),Vd="__none__",pl=24,X_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}];function Lv(e){return e==null?"low":e>=.7?"high":e>=.5?"medium":"low"}var Z_=e=>e.attrs.supply_nature==="labour_only"||e.attrs.supply_nature==="plant"||e.flags.includes("referential");function P_(e,t){if(t!==Vd){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 Dv(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 K_({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 Li(e,t){if(e==null)return"-";let a=ol(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function Xd(e){return e&&e.length>0?e.join(" x "):"-"}function J_(e){return e==null?"-":Number.isInteger(e/1e3)?`${e/1e3}m`:`${(e/1e3).toFixed(1)}m`}function Bi(e){let t=(e??[]).map(a=>a.trim()).filter(Boolean);return t.length>0?t.join(", "):"-"}function Zr(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)"}function I_(e,t){return t>0||e==null?null:ot(e)}var Ov=[{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 F_(e){let t=new Map;return[...new Set(e.filter(Pr).map(r=>r.linked_group_id))].forEach((r,n)=>{let i=n%26;t.set(r,{token:String.fromCharCode(65+i),bubbleStyle:Ov[n%Ov.length]})}),t}function Pr(e){return!1}function Hi(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 Yd({meta:e}){return e?(0,s.jsx)("span",{className:"results-linked-pill",style:e.bubbleStyle,children:`Link ${e.token}`}):null}function W_(e,t,a){let r=t?.rerank?.recommendedCandidateIds??[],n=new Map(e.map(c=>[c.product_id,c])),i=r.length>0?r.map(c=>n.get(c)).filter(c=>c!=null):e.slice(0,6),o=a?n.get(a):void 0,l=o?[o,...i.filter(({product_id:c})=>c!==o.product_id)]:i;return[...new Map(l.map(c=>[c.product_id,c])).values()].slice(0,6)}function $d(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 cc(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 ex({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:cc(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:cc(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:cc(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:cc(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 tx({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:Xd(r.measurements_mm)}),(0,s.jsx)("td",{children:ol(r.price_basis)||"-"}),(0,s.jsx)("td",{children:r.bm25.toFixed(2)})]},`${r.product_id}-${n}`))})]})]},`${t.query}-${a}`))]})}function Bv({item:e,result:t}){let a=t?.retrieval_debug.map(n=>n.query).filter(Boolean)??[],r=[["Procurement intent",e.procurement_intent||"-"],["Procurement aliases",Bi(e.procurement_aliases)],["Retrieval queries",Bi(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)",Xd(e.attrs.measurements_mm)],["Stock length",J_(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",Bi(e.installation_clues)],["System clues",Bi(e.system_clues)],["Component requirements",Bi(e.component_requirements)],["Linked group",Hi(e)||"-"],["Flags",Bi(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)(ye.Fragment,{children:[(0,s.jsx)("dt",{children:n}),(0,s.jsx)("dd",{children:i})]},n))})]})}function ax({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)(ye.Fragment,{children:[(0,s.jsx)("dt",{children:"Attempted"}),(0,s.jsx)("dd",{children:t.attempted?"yes":"no"})]}),(0,s.jsxs)(ye.Fragment,{children:[(0,s.jsx)("dt",{children:"Applied"}),(0,s.jsx)("dd",{children:t.applied?"yes":"no"})]}),(0,s.jsxs)(ye.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned items"}),(0,s.jsx)("dd",{children:t.returned_item_count??"-"})]}),(0,s.jsxs)(ye.Fragment,{children:[(0,s.jsx)("dt",{children:"Reason"}),(0,s.jsx)("dd",{children:t.reason||"-"})]}),(0,s.jsxs)(ye.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 rx({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||"-"]];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)(ye.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 nx({item:e,decision:t,selectedProductId:a,result:r,showRetrievalDebug:n,reviewOnly:i=!1,linkedGroupMeta:o}){if(!t)return null;let l=a==null?"Needs review:":"Selected:";return i?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:l}),"\xA0",t.reason]}),Pr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",o?`Link ${o.token} - `:"",Hi(e)]}):null]}):null:!t.reason&&!n?(0,s.jsx)(Bv,{item:e,result:r}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Bv,{item:e,result:r}),n&&(0,s.jsx)(ax,{item:e}),n&&(0,s.jsx)(rx,{result:r}),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:l}),"\xA0",t.reason]}),Pr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",o?`Link ${o.token} - `:"",Hi(e)]}):null]}),n&&(0,s.jsx)(tx,{queries:r?.retrieval_debug??[]})]})}function ix({item:e,candidates:t,result:a,decision:r,unmatchable:n,selectedProductId:i,detailMode:o,onPick:l,onClear:c,showAll:p=!1,internal:m=!1,debugEnabled:f=!1,forceReviewNote:d=!1,linkedGroupMeta:g}){let w=m||o==="detailed",A=f&&o==="detailed",L=w||d?(0,s.jsx)(nx,{item:e,decision:r,selectedProductId:i,result:a,showRetrievalDebug:A,reviewOnly:d&&!w,linkedGroupMeta:g}):null;if(n)return(0,s.jsxs)(s.Fragment,{children:[L,(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:[L,(0,s.jsx)("p",{className:"results-empty-hint",children:"No candidates were returned for this line item."})]});let h=p||m||o==="detailed"?t:W_(t,a,i);return(0,s.jsxs)(s.Fragment,{children:[L,(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"}),A&&(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:h.map((u,b)=>{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:Xd(u.measurements_mm??u.debug?.candidate.measurements_mm)})}),(0,s.jsx)("td",{children:Li(u.price,u.price_basis)}),A&&(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)(K_,{band:Lv(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}-${b}`)})})]})]})}function Zd({scheduleResult:e,onStartOver:t,cart:a,onAddToCart:r,onRemoveFromCart:n,onGoToBasket:i,cartSeeded:o,onCartSeeded:l,reviewGateComplete:c,onReviewGateComplete:p,internal:m=!1}){let f=!m&&Is()==="QZA6-MRA4",d=f?"quote":"basket",{results:g,lineItems:w,parseReport:A,timings:L}=e,[h,u]=(0,ye.useState)({}),b=Ei(),[v,_]=(0,ye.useState)({}),[C,R]=(0,ye.useState)({}),[T,D]=(0,ye.useState)(""),[V,oe]=(0,ye.useState)(null),[_e,Te]=(0,ye.useState)(1),Oe=Dt().debug===!0,[xe,X]=(0,ye.useState)("simple"),[J,ze]=(0,ye.useState)(m?"list":"tile"),[Ee,wt]=(0,ye.useState)(!1),[P,pe]=(0,ye.useState)(null),[Re,Ot]=(0,ye.useState)(""),[jt,qe]=(0,ye.useState)([]),[ke,Be]=(0,ye.useState)(!1),[Ye,vt]=(0,ye.useState)(null),[z,H]=(0,ye.useState)(!1),[le,de]=(0,ye.useState)(null),me=(0,ye.useRef)(null),[$e,Le]=(0,ye.useState)(new Set),[k,x]=(0,ye.useState)(new Set),[E,U]=(0,ye.useState)(!1);(0,ye.useEffect)(()=>{Te(1)},[T,V,J]);let Z=new Map(g.map(S=>[S.line_id,S])),N=F_(w),G=w.map(S=>{let Q=Z.get(S.line_id),ge=Q?.decision,ht=Z_(S),Je=h[S.line_id],Za=P_(Q,Je),Un=a[S.line_id],x0=Je===Vd?void 0:v[S.line_id]??(Un&&Un.productId!==Za?.product_id?Dv(Un):Za),Mm=ht?void 0:x0,k0=S.qty??0;return{item:S,result:Q,decision:ge,unmatchable:ht,best:Mm,qty:k0,band:Lv(Mm?.scores?.overall)}}),ce=G.some(S=>!S.unmatchable&&!S.best&&!k.has(S.item.line_id))?null:sc(Object.values(a),{wasteFactorEnabled:!1,wasteFactorOverride:0}),Se=0;for(let S of G){if(S.unmatchable||!S.best)continue;let Q=a[S.item.line_id];(!Q||Ft(Q).lineTotal==null)&&(Se+=1)}Se>0&&(ce=null);let yt=I_(ce,Se),ft=S=>!S.unmatchable&&!S.best&&$d(S.result).length>0,At=S=>S.best??$d(S.result)[0],Jr=G.filter(S=>!S.unmatchable&&!S.best).filter(S=>!k.has(S.item.line_id)),Ec=G.filter(S=>k.has(S.item.line_id)),Yt=G;if(T.trim()){let S=T.trim().toLowerCase();Yt=Yt.filter(Q=>Q.item.description_original?.toLowerCase().includes(S)||At(Q)?.description?.toLowerCase().includes(S))}if(V){let S=V==="asc"?1:-1;Yt=[...Yt].sort((Q,ge)=>S*(Q.item.description_original||"").localeCompare(ge.item.description_original||""))}let hr=Math.max(1,Math.ceil(Yt.length/pl)),_t=Math.min(_e,hr),Zi=Yt.slice((_t-1)*pl,_t*pl),_m=Zi.filter(S=>!S.unmatchable&&S.best),Mc=Zi.filter(S=>!S.unmatchable&&S.best),xm=Zi.filter(S=>S.unmatchable||!S.best),I=P?G.find(S=>S.item.line_id===P)??null:null,h0=!m&&!c&&!I&&Jr.length>0,Pi=(0,ye.useRef)(null),Ki=()=>{let S=me.current;if(!S)return;let{top:Q,left:ge,width:ht,height:Je}=S.getBoundingClientRect(),Un=S.querySelector(".bom-toolbar-btn")?.closest("td")?.getBoundingClientRect().left;de({top:Q,left:ge,width:Un?Un-ge:ht,height:Je})};(0,ye.useEffect)(()=>(window.addEventListener("scroll",Ki,!0),window.addEventListener("resize",Ki),()=>{window.removeEventListener("scroll",Ki,!0),window.removeEventListener("resize",Ki)})),(0,ye.useEffect)(()=>{let S=Q=>{Pi.current&&!Q.composedPath().includes(Pi.current)&&Pi.current.removeAttribute("open")};return document.addEventListener("click",S),()=>document.removeEventListener("click",S)},[]);let Rn=S=>{pe(S),Ot("")},g0=()=>{if(!P)return;let S=a[P];if(S){u(Q=>({...Q,[P]:S.productId})),_(Q=>({...Q,[P]:Dv(S)}));return}u(Q=>{let ge={...Q};return delete ge[P],ge}),_(Q=>{let ge={...Q};return delete ge[P],ge})},Xa=(S=!1)=>{let Q=P?a[P]:void 0;!S&&Q&&I?.best&&Q.productId!==I.best.product_id&&!window.confirm("You have selected a new product. Leave without updating it?")||(S||g0(),pe(null),U(!1))};rl(z,()=>H(!1)),rl(!!I&&!z,()=>Xa());let b0=S=>{if(Le(Q=>new Set(Q).add(S)),Jr.some(Q=>Q.item.line_id!==S)){Xa(!0);return}p(),Xa(!0)},w0=S=>{if(Tc(S),x(Q=>new Set(Q).add(S)),Jr.some(Q=>Q.item.line_id!==S)){Xa(!0);return}p(),Xa(!0)},v0=()=>{x(S=>new Set([...S,...Jr.map(Q=>Q.item.line_id)])),p()},km=()=>{I?.best&&(Nm(I.item.line_id,I.best),r(Ji(I)),E?b0(I.item.line_id):Xa(!0))},Sm=xm.length>0?(0,s.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items needing review",children:[(0,s.jsxs)("div",{className:"results-tile-section__head",children:[(0,s.jsx)("h3",{children:"Needs review"}),(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:xm.map(S=>{let{item:Q,qty:ge}=S;return(0,s.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>Rn(Q.line_id),children:[(0,s.jsx)("span",{className:"results-unmatched-card__main",children:(0,s.jsx)("span",{className:"results-unmatched-card__title",children:Zr(Q,w)})}),(0,s.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},Q.line_id)})})]}):null,Tc=S=>{u(Q=>({...Q,[S]:Vd})),_(Q=>({...Q,[S]:void 0})),R(Q=>({...Q,[S]:void 0})),n(S)},zc=(S,Q)=>{u(ge=>({...ge,[S]:Q.product_id})),_(ge=>({...ge,[S]:Q}))},Nm=(S,Q)=>{Q.method==="catalogue_search"&&R(ge=>({...ge,[S]:Q}))};function $x(){b("downloaded",{type:"schedule",lines:G.length}),zv(G.map(({item:S,best:Q,qty:ge,band:ht,unmatchable:Je,decision:Za})=>({item:S,best:Q,qty:ge,band:ht,unmatchable:Je,decision:Za})))}function Ji(S){let Q=S.best;if(!Q)throw new Error("Cannot add a line item without a selected product.");return Oi(Q,{lineId:S.item.line_id,description:S.item.description_original,unit:S.item.unit,qty:S.qty,linkedContext:S.item.linked_group_role==="dependent"&&S.item.linked_group_id?w.filter(ge=>ge.linked_group_id===S.item.linked_group_id&&ge.linked_group_role==="anchor").slice(0,1).map(ge=>{let ht=a[ge.line_id];return{line_id:ge.line_id,product_id:ht?.productId??null,measurements_mm:ht?.measurementsMm??ge.attrs.measurements_mm,description:ht?.description??ge.description_original,qty:ge.qty,unit:ge.unit,role:"anchor"}}):void 0})}(0,ye.useEffect)(()=>{if(!o){for(let S of G)!S.unmatchable&&S.best&&r(Ji(S));l()}},[o]),(0,ye.useEffect)(()=>{if(!P){qe([]),vt(null),Be(!1);return}let S=Re.trim();if(!S){qe([]),vt(null),Be(!1);return}let Q=!1,ge=window.setTimeout(async()=>{try{Be(!0),vt(null);let ht=await fetch(Ma(`/api/catalogue/search?q=${encodeURIComponent(S)}`),{headers:wn()}),Je=await Ga(ht);if(!ht.ok)throw new Error(Je?.error||Je?.message||"Failed to search catalogue");Q||qe(Array.isArray(Je?.items)?Je.items:[])}catch(ht){Q||(qe([]),vt(ht?.message||"Failed to search catalogue"))}finally{Q||Be(!1)}},250);return()=>{Q=!0,window.clearTimeout(ge)}},[Re,P]);let Rc=Object.keys(a).length,Na=Re.trim(),Ac=$d(I?.result),bl=!!I&&!I.best&&(I.result?.candidates.length===0||I.result?.rerank?.selectedCandidateId===null),Cm=I?.result?.rerank!=null,qm=I?.decision?.reason??(bl?"No catalogue candidate found. Refine the request or search the catalogue.":null),y0=jt.map(S=>({product_id:S.product_id,description:S.description,source_list:S.source_list,price:S.price,price_basis:S.price_basis,uoi_count:S.uoi_count??null,uoi:S.uoi,pdp_photo_url:S.pdp_photo_url??null,conversion:S.conversion,measurements_mm:S.measurements_mm??[],scores:{dimension:0,grade:0,brand:0,fuzzy:0,bm25:0,overall:0},method:"catalogue_search"})),Ii=Na?y0:Ac,An=I?C[I.item.line_id]:void 0,Fi=!Na&&An&&!Ii.some(S=>S.product_id===An.product_id)?[...Ii,An]:Ii,Em=(()=>{let S=Fi.slice(0,Na?12:6);return Na||!An||S.some(Q=>Q.product_id===An.product_id)?S:[...S,An]})(),wl=!!I?.best&&a[I.item.line_id]?.productId===I.best.product_id,_0=!!I?.best&&!!a[I.item.line_id]&&!wl;return(0,s.jsxs)("div",{className:"wizard-step entry-stage",children:[(0,s.jsxs)("div",{className:`quick-order-card${m?"":" quick-order-card--customer"}`,children:[(0,s.jsx)("div",{className:`quick-order-hero${m?"":" quick-order-hero--customer"}`,children:m?(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:yt??"Review quantities"})," 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 ",f?"View Quote":"View Basket"," to continue."]})]}),(0,s.jsxs)("button",{type:"button",className:"results-total-action",onClick:i,disabled:Rc===0,"aria-label":f?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:f?"View Quote":"View Basket"}),yt!=null&&(0,s.jsx)("strong",{children:yt})]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Qt,{})})]})]})}),(0,s.jsxs)("div",{className:"quick-order-panel",style:{paddingTop:16},children:[Oe&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:12},children:(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn","aria-pressed":Ee,onClick:()=>wt(S=>!S),children:Ee?"Hide timings":"Show timings"})}),Oe&&Ee&&(0,s.jsx)(ex,{...L}),!f&&(0,s.jsx)("div",{className:"results-toolbar-row",children:!I&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:0},children:(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:T,onChange:S=>D(S.target.value),"aria-label":"Search line items"}),!m&&(0,s.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,s.jsx)("button",{type:"button",className:`results-view-toggle__btn${J==="tile"?" is-active":""}`,"aria-pressed":J==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>ze("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${J==="list"?" is-active":""}`,"aria-pressed":J==="list","aria-label":"List view",title:"List view",onClick:()=>ze("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"})]})})]}),Oe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>X(S=>S==="simple"?"detailed":"simple"),children:xe==="detailed"?"Hide detailed view":"Show detailed view"}),(0,s.jsxs)("details",{ref:Pi,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:X_.map(S=>{let Q=V===S.dir;return(0,s.jsxs)("button",{type:"button",className:`sort-menu-item${Q?" is-active":""}`,onClick:()=>{oe(Q?null:S.dir),Pi.current?.removeAttribute("open")},children:[(0,s.jsx)("span",{className:"sort-menu-item__check",children:Q?"\u2713":""}),S.label]},S.dir)})})]})]})})}),J==="tile"||I?(0,s.jsxs)(s.Fragment,{children:[I?(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop",role:"dialog","aria-modal":"true","aria-label":"Product options",onClick:()=>Xa(),children:(0,s.jsxs)("section",{className:"quick-order-workflow-modal results-review-modal",onClick:S=>S.stopPropagation(),children:[(0,s.jsx)("button",{type:"button",className:"quick-order-workflow-close results-review-modal__close",onClick:()=>Xa(),"aria-label":"Close product options",children:(0,s.jsx)(nl,{})}),(0,s.jsx)("div",{className:"results-review-page",children:m?(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:()=>Xa(),children:[(0,s.jsx)(Vr,{}),"Back to results"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[Oe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>X(S=>S==="simple"?"detailed":"simple"),children:xe==="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:Re,onChange:S=>Ot(S.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:()=>Tc(I.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)(za,{className:"fill-img results-review-page__image",description:At(I)?.description||I.item.description_original,photoUrl:At(I)?.pdp_photo_url})}),(0,s.jsxs)("div",{className:"results-review-page__summary",children:[(0,s.jsx)("h2",{children:Zr(I.item,w)}),(0,s.jsxs)("p",{className:"results-review-page__meta",children:[yn(I.qty)," ",xa(I.item.unit,I.qty)]}),I.best?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:I.best.description}),I.best.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Li(I.best.price,I.best.price_basis)}):null]}):At(I)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:At(I)?.description}),At(I)?.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Li(At(I)?.price??null,At(I)?.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."}),Pr(I.item)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[(0,s.jsx)(Yd,{meta:N.get(I.item.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:Hi(I.item)})]}):null,(0,s.jsx)("div",{className:"results-review-page__actions",children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[I.item.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[I.item.line_id]?n(I.item.line_id):(I.best&&Nm(I.item.line_id,I.best),r(Ji(I)))},disabled:!I.best,"aria-label":a[I.item.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[I.item.line_id]?"\u2713 Added":m?"+ Add to selection":`Add to ${d}`})})]})]}),ke?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,!ke&&Ye?(0,s.jsx)("div",{className:"results-empty-card",children:Ye}):null,!ke&&!Ye&&Na&&Ii.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No candidate products match this database search."}):!ke&&!Ye?(0,s.jsx)(ix,{item:I.item,candidates:Ii,result:I.result,decision:I.decision,unmatchable:I.unmatchable,selectedProductId:I.best?.product_id??null,detailMode:xe,linkedGroupMeta:Pr(I.item)?N.get(I.item.linked_group_id):void 0,onPick:S=>zc(I.item.line_id,S),onClear:()=>Tc(I.item.line_id),showAll:m||Oe||Na.length>0,internal:m,debugEnabled:Oe,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:Zr(I.item,w)||"Original request"})]}),qm?(0,s.jsxs)("section",{className:"customer-review-ai",children:[(0,s.jsx)("strong",{children:bl?"No automatic match:":"AI review:"})," ",qm]}):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:bl?Ac.length>0?"Choose a product":"No suitable product found":Cm?"Choose a product":"We couldn't review this item"}),(0,s.jsx)("p",{children:bl?Ac.length>0?"No product was selected automatically. Review these related options before adding one.":"Search the catalogue to choose an alternative.":Cm?`Select the option you want to add to your ${d}.`:"Search the catalogue to choose a product."})]})}),!Na&&Fi.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:Em.map(S=>{let Q=S.product_id===I.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${Q?" is-selected":""}`,onClick:()=>zc(I.item.line_id,S),"aria-pressed":Q,children:[(0,s.jsx)(za,{className:"customer-review-option__image",description:S.description,photoUrl:S.pdp_photo_url,width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:S.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:S.price!=null?`\xA3${Li(S.price,S.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:Q?"Selected":"Choose"})]},S.product_id)})}):null,Fi.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:Re,onChange:S=>Ot(S.target.value),"aria-label":"Search catalogue"})]}),Na&&ke?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,Na&&!ke&&Ye?(0,s.jsx)("div",{className:"results-empty-card",children:Ye}):null,Na&&!ke&&!Ye&&Fi.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No products match this search."}):null,Na&&!ke&&!Ye&&Fi.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:Em.map(S=>{let Q=S.product_id===I.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${Q?" is-selected":""}`,onClick:()=>zc(I.item.line_id,S),"aria-pressed":Q,children:[(0,s.jsx)(za,{className:"customer-review-option__image",description:S.description,photoUrl:S.pdp_photo_url,width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:S.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:S.price!=null?`\xA3${Li(S.price,S.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:Q?"Selected":"Choose"})]},S.product_id)})}):null]}),I.best?_0?(0,s.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,s.jsx)("button",{type:"button",className:"cta-btn customer-review-add",onClick:()=>{km()},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(I.item.line_id),children:(0,s.jsx)("span",{children:`Remove from ${d}`})})]}):(0,s.jsx)("button",{type:"button",className:`cta-btn customer-review-add${wl?" cta-btn-secondary":""}`,onClick:()=>{wl?n(I.item.line_id):km()},children:(0,s.jsx)("span",{children:wl?`Remove from ${d}`:`Add selected product to ${d}`})}):null,E?(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-skip",onClick:()=>w0(I.item.line_id),children:"Skip this item"}):null]})})]})}):null,(0,s.jsxs)("div",{className:"results-tile-layout",children:[Yt.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No line items match the current search/filter."}):null,Mc.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:Mc.map(S=>{let{item:Q,best:ge,qty:ht}=S,Je=At(S);return(0,s.jsxs)("article",{className:"results-tile-card",children:[(0,s.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>Rn(Q.line_id),"aria-label":`Review match for ${Zr(Q,w)||"item"}`,children:[(0,s.jsxs)("div",{className:"results-tile-card__media",children:[Pr(Q)?(0,s.jsx)("div",{className:"results-tile-card__badges",children:(0,s.jsx)(Yd,{meta:N.get(Q.linked_group_id)})}):null,(0,s.jsx)(za,{className:"fill-img results-tile-card__image",description:Je?.description||Q.description_original,photoUrl:Je?.pdp_photo_url})]}),(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:"\u21B3 matched from"}),(0,s.jsx)("div",{className:"results-tile-card__match-name",children:Zr(Q,w)}),Pr(Q)?(0,s.jsx)("div",{className:"results-row-meta",children:Hi(Q)}):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:[m&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Rn(Q.line_id),children:"Review"}),(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[Q.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[Q.line_id]?n(Q.line_id):r(Ji(S))},disabled:!ge,"aria-label":a[Q.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[Q.line_id]?"\u2713 Added":m?"+ Add":`Add to ${d}`})]})]},Q.line_id)})})}):null,Sm]})]}):(0,s.jsxs)(s.Fragment,{children:[le&&(0,s.jsx)("div",{className:"results-table__hover-overlay",style:le,"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"}}),xe==="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"}),xe==="simple"&&(0,s.jsx)("th",{style:{textAlign:"center"},children:m?"Selection":f?"Quote":"Basket"})]})}),(0,s.jsxs)("tbody",{children:[Yt.length===0&&(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:xe==="simple"?4:3,className:"results-empty-hint",style:{padding:"16px 8px"},children:"No line items match the current search/filter."})}),Mc.map(S=>{let{item:Q,result:ge,decision:ht,best:Je}=S;return(0,s.jsxs)("tr",{className:"bom-row results-table__review-row",onClick:()=>Rn(Q.line_id),onMouseEnter:Za=>{me.current=Za.currentTarget,Ki()},onMouseLeave:()=>{me.current=null,de(null)},children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{className:"bom-component-name",children:Zr(Q,w)}),Pr(Q)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,s.jsx)(Yd,{meta:N.get(Q.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:Hi(Q)})]}):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}),xe==="detailed"&&ht&&(0,s.jsx)("div",{className:"results-row-meta",children:ht.selected_candidate_id===Je.product_id?"Automatically selected":"Selected"})]}):(0,s.jsx)("span",{className:"results-empty-hint"})}),(0,s.jsx)("td",{style:{textAlign:"center"},children:Je?.price!=null?Li(Je.price,Je.price_basis):"-"}),xe==="simple"&&(0,s.jsx)("td",{style:{textAlign:"center"},children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[Q.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,style:{width:84,justifyContent:"center"},onClick:Za=>{Za.stopPropagation(),a[Q.line_id]?n(Q.line_id):r(Ji(S))},"aria-label":a[Q.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[Q.line_id]?"\u2713 Added":m?"+ Add":`Add to ${d}`})})]},Q.line_id)})]})]})}),Sm]}),!I&&hr>1&&(0,s.jsxs)("div",{className:"results-pagination",children:[(0,s.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(_t-1)*pl+1,"\u2013",Math.min(_t*pl,Yt.length)," of ",Yt.length]}),(0,s.jsxs)("div",{className:"results-pagination-controls",children:[(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Te(_t-1),disabled:_t===1,children:"Previous"}),(0,s.jsxs)("span",{className:"results-pagination-page",children:["Page ",_t," of ",hr]}),(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Te(_t+1),disabled:_t===hr,children:"Next"})]})]}),(A.itemCount!=null||A.headingCount!=null||A.skippedCount!=null)&&(0,s.jsxs)("div",{className:"results-summary",style:{marginTop:16},children:[A.itemCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:A.itemCount})," items parsed"]}),A.headingCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:A.headingCount})," headings"]}),A.skippedCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:A.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."})]}),!I&&(0,s.jsxs)("div",{className:"btn-row results-actions",children:[(0,s.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",gap:10,justifyContent:"center"},onClick:()=>H(!0),"aria-label":"Start over",children:[(0,s.jsx)(jd,{}),(0,s.jsx)("span",{children:"Start Over"})]}),(0,s.jsxs)("button",{className:"cta-btn",style:{flex:"0 1 70%"},onClick:i,disabled:Rc===0,"aria-label":m?"View selection":f?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[m?"View Selection":f?"View Quote":"View Basket"," (",Rc,")"]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Qt,{})})]})]})]})]}),h0&&(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:Jr.map(S=>{let Q=$e.has(S.item.line_id),ge=ft(S);return(0,s.jsx)("div",{className:`review-gate-item${Q?" is-reviewed":""}`,children:(0,s.jsxs)("button",{type:"button",className:"review-gate-item__review",onClick:()=>{U(!0),Rn(S.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Zr(S.item,w)}),(0,s.jsx)("span",{children:S.decision?.reason||(ge?"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:Q?"Choice made":"Choose a product"})]})},S.item.line_id)})}),(0,s.jsx)("button",{type:"button",className:"review-gate-skip",onClick:v0,children:"Skip all"}),Ec.length>0?(0,s.jsxs)("div",{className:"review-gate-skipped",children:[(0,s.jsx)("strong",{children:"Skipped"}),Ec.map(S=>(0,s.jsxs)("button",{type:"button",className:"review-gate-item is-skipped",onClick:()=>{x(Q=>{let ge=new Set(Q);return ge.delete(S.item.line_id),ge}),U(!0),Rn(S.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Zr(S.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"})]},S.item.line_id))]}):null]})}),z&&(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 ",f?"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:()=>H(!1),children:"Cancel"}),(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-danger",onClick:()=>{H(!1),t()},autoFocus:!0,children:"Start Over"})]})]})})]})}var Ya=$(ee()),Pd="metron-quick-quote",ox=1440*60*1e3;function uc(e){return(0,Ya.jsx)(lc,{children:(0,Ya.jsx)(lx,{...e})})}function lx({fullPage:e=!1,hideHeader:t=!1,internal:a=!1}){let[r,n]=(0,Ge.useState)("entry"),[i,o]=(0,Ge.useState)(null),l=(0,Ge.useRef)(null),c=(0,Ge.useRef)(0),[p,m]=(0,Ge.useState)(0),[f,d]=(0,Ge.useState)(null),[g,w]=(0,Ge.useState)(!1),{cart:A,addToCart:L,addManyToCart:h,removeFromCart:u,updateCartQty:b,updateCartSellUnits:v,updateCartConversions:_,clearCart:C}=Di(),[R,T]=(0,Ge.useState)(!1),[D,V]=(0,Ge.useState)(null),oe=()=>{V(null);try{window.sessionStorage.removeItem(oc)}catch{}},_e=(0,Ge.useRef)(null),Te=Js("quick-quote",_e);(0,Ge.useEffect)(()=>{Te("viewed")},[Te]);let[Oe,xe]=(0,Ge.useState)(!1);(0,Ge.useEffect)(()=>{_v();let qe=window.location.hash,ke=null;try{ke=JSON.parse(window.sessionStorage.getItem(Pd)??"null")}catch{}if(ke&&!(Date.now()-(ke.savedAt??0)<ox)&&(ke=null),ke?.scheduleResult)o("schedule"),d(ke.scheduleResult),w(ke.reviewGateComplete),T(ke.cartSeeded),h(Object.values(ke.cart)),qe==="#quote-request"?n("basket"):qe==="#matched-products"&&n("results");else if(qe==="#matched-products"||qe==="#quote-request"){let Be=new URL(window.location.href);Be.hash="",Ri("replaceState",window.history.state,Be)}xe(!0)},[]),(0,Ge.useEffect)(()=>{if(Oe)try{f?window.sessionStorage.setItem(Pd,JSON.stringify({savedAt:Date.now(),scheduleResult:f,reviewGateComplete:g,cartSeeded:R,cart:A})):window.sessionStorage.removeItem(Pd)}catch{}},[Oe,f,g,R,A]);let X=(0,Ge.useCallback)(qe=>{if(typeof window>"u")return;let ke=new URL(window.location.href);ke.hash=qe==="basket"?"quote-request":"matched-products";let Be=qe==="results"&&(window.location.hash==="#matched-products"||window.location.hash==="#quote-request");Ri(Be?"replaceState":"pushState",{boqQuoteStage:qe},ke)},[]),J=(0,Ge.useRef)(!1);(0,Ge.useEffect)(()=>{let qe=()=>{J.current=!1;let ke=window.location.hash;ke==="#quote-request"?n("basket"):ke==="#matched-products"&&f?(o("schedule"),n("results")):n("entry")};return window.addEventListener("popstate",qe),()=>window.removeEventListener("popstate",qe)},[f]);let ze=(0,Ge.useCallback)(()=>{X("basket"),n("basket")},[X]),Ee=(0,Ge.useCallback)(()=>{if(window.location.hash==="#quote-request"){if(J.current)return;J.current=!0,ic();return}n(f?"results":"entry")},[f]),wt=(0,Ge.useRef)(r);(0,Ge.useEffect)(()=>{wt.current!==r&&(wt.current=r,window.scrollTo(0,0))},[r]);let P=()=>{n("entry"),o(null),m(0),d(null),w(!1),C(),T(!1),oe()},pe=(0,Ge.useCallback)(async(qe,ke,Be=!0)=>{let Ye=++c.current;m(0);let vt=0,z=()=>{vt=Math.min(vt+1,3),m(vt)};try{let{jobId:H}=await Ew(qe,ke,Be);if(Ye!==c.current)return;let{promise:le,cancel:de}=Tw(()=>Mw(H),5e3,z,"schedule");l.current=de;let me=await le;if(me.status==="failed"||!me.result)throw new Error(me.error||"Failed to process schedule");let $e=me.result.lineItems.length,Le=me.result.results.filter(k=>k.candidates.length>0).length;Te("results_shown",{lines:$e,matched:Le,unmatched:$e-Le}),C(),T(!1),w(!1),d(me.result),X("results"),n("results")}catch(H){if(Ye!==c.current)return;throw Te("error",{stage:"matching"}),H}finally{Ye===c.current&&(l.current?.(),l.current=null)}},[X,Te,C]),Re=(0,Ge.useCallback)(()=>{c.current++,l.current?.(),l.current=null},[]),Ot=(0,Ge.useCallback)(async(qe,ke,Be=!0)=>{if(!qe.trim())return;o("schedule");let Ye=new File([qe],"pasted-schedule.txt",{type:"text/plain"});await pe(Ye,ke,Be)},[pe]),jt=(0,Ge.useCallback)(async qe=>{o("schedule"),await pe(qe)},[pe]);return(0,Ya.jsx)(tl.Provider,{value:Te,children:(0,Ya.jsx)("div",{ref:_e,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${!e&&r==="processing"?" app-wrapper--loading":""}`,style:Dt().theme,children:(0,Ya.jsxs)("main",{className:"main-content",children:[r==="entry"&&(0,Ya.jsx)(Cd,{onPasteSchedule:Ot,onUploadSchedule:jt,onEntryModeChange:o,draft:D,onSubmitDraft:V,onCancelMatch:Re}),r==="results"&&i==="schedule"&&f&&(0,Ya.jsx)(Zd,{scheduleResult:f,onStartOver:P,cart:A,onAddToCart:L,onRemoveFromCart:u,onGoToBasket:ze,cartSeeded:R,onCartSeeded:()=>T(!0),reviewGateComplete:g,onReviewGateComplete:()=>w(!0),internal:a}),r==="basket"&&(0,Ya.jsx)(ul,{cart:A,onUpdateQty:b,onUpdateSellUnits:v,onResolveConversions:_,onRemove:u,onBack:Ee,onStartNewQuote:P,onQuoteRequested:()=>{d(null),w(!1),T(!1),C(),oe()},internal:a})]})})})}var Va=$(Ve());var Nn=$(Ve());var Hv={"NZ4Y-ZMSQ":{"brick-block":{"brick-common":"105499","brick-engineering-red":"1654","brick-engineering-blue":"1723",block:"501","mortar-cement":"1762 cement","mortar-sand":"564 building sand"},skirting:{"skirting-chamfered":"1525","skirting-ogee":"135 primed mdf ogee","skirting-pencil-round":"892","skirting-torus":"1941"},architrave:{"architrave-ogee":"134 primed mdf ogee","architrave-pencil-round":"1896","architrave-square-edge":"118 primed mdf square","architrave-torus":"1531"},plasterboard:{standard:"1647",moisture:"11 moisture plasterboard",fire:"14 fire plasterboard",sound:"1769",screws:"131160",tape:"1766",adhesive:"108439"},paint:{"paint-emulsion":"157217"},"concrete-aggregate":{cement:"1762 cement","sharp-sand":"563",gravel:"571",mot:"569"},insulation:{"insulation-floor":"152187","insulation-ground":"442","insulation-wall":"147","insulation-roof":"442","insulation-loft":"152180"},timber:{studs:"1213",joists:"208",battens:"1729"},fencing:{"panels-boundary-0.9":"66 lap fence panel","panels-boundary-1.2":"1450","panels-boundary-1.5":"1449","panels-boundary-1.8":"1448","panels-skyline-1.8":"1475","concrete-intermediate-8":"40197","concrete-end-8":"40198","timber-post-6":"141411","timber-post-8":"1709",postcrete:"12142","gate-boundary":"1984","gate-skyline":"40002","gravel-boards":"40200"},decking:{"boards-summit":"24322",joists:"208",screws:"131079"},paving:{"surface-council":"1669","surface-raj":"12363","surface-brindle":"304","surface-charcoal":"296","surface-pea":"431","sub-base":"569",bedding:"563"}}};function dl(e,t){let a=Hv[Dt().client??""]?.[e];if(!a)return null;let r=e==="plasterboard"&&t.key==="board"?t.label.split(" ")[0].toLowerCase():t.key;return a[r]??null}function Sn(e,t){let a=Hv[Dt().client??""]?.[e];return!a||t in a}function Qv(e,t){let a=t.map(r=>{let n=dl(e,r);return n?{key:r.key,productId:n.split(" ")[0],search:n,qty:r.qty,unit:r.unit}:null});return a.length>0&&a.every(Boolean)?a:null}var ae=$(ee()),Gv=[{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"}],pc=e=>Number.parseFloat(e)||0,jv=(e,t)=>pc(e)*(t==="m"?1:.3048),Kd=(e,t)=>pc(e.quantity)*(2*jv(e.height,t)+jv(e.width,t)),sx=()=>({quantity:"1",width:"",height:""});function cx({profile:e}){return(0,ae.jsxs)("svg",{className:"architrave-calculator__profile-diagram",viewBox:"0 0 112 76","aria-hidden":"true",children:[(0,ae.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,ae.jsx)("line",{x1:"12",y1:"66",x2:"100",y2:"66"})]})}function Jd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Nn.useState)("m"),[i,o]=(0,Nn.useState)({quantity:"1",width:"0.76",height:"1.98"}),[l,c]=(0,Nn.useState)({quantity:"0",width:"1.52",height:"1.98"}),[p,m]=(0,Nn.useState)([]),[f,d]=(0,Nn.useState)("ogee"),[g,w]=(0,Nn.useState)("2.4"),A=(_,C,R)=>{_(T=>({...T,[C]:R}))},L=Kd(i,r)+Kd(l,r)+p.reduce((_,C)=>_+Kd(C,r),0),h=pc(g)>0?Math.ceil(L/pc(g)):0,u=Gv.find(_=>_.id===f)?.label??"",b=[{key:`architrave-${f}`,label:`Architrave (${u})`,qty:L,unit:"m",query:`${u} architrave`,category:"architrave"}],v=(_,C,R,T)=>(0,ae.jsxs)("div",{className:"architrave-calculator__opening-row",children:[(0,ae.jsx)("span",{children:_}),(0,ae.jsx)("input",{"aria-label":`${_} quantity`,type:"number",min:"0",step:"1",value:C.quantity,onChange:D=>R("quantity",D.target.value)}),(0,ae.jsx)("input",{"aria-label":`${_} width`,type:"number",min:"0",step:"0.01",value:C.width,onChange:D=>R("width",D.target.value)}),(0,ae.jsx)("input",{"aria-label":`${_} height`,type:"number",min:"0",step:"0.01",value:C.height,onChange:D=>R("height",D.target.value)}),T?(0,ae.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:T,children:"Remove"}):null]});return(0,ae.jsx)(ae.Fragment,{children:(0,ae.jsxs)("div",{className:"truss-estimator",children:[(0,ae.jsxs)("div",{className:"quick-order-hero",children:[(0,ae.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ae.jsx)("h1",{children:"Architrave Calculator"}),(0,ae.jsx)("p",{children:"Estimate architrave lengths and board quantities for door openings."})]}),(0,ae.jsxs)("div",{className:"truss-estimator__card architrave-calculator",children:[(0,ae.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure your openings"}),(0,ae.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,ae.jsxs)("div",{className:"architrave-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Door openings"}),(0,ae.jsx)("p",{className:"architrave-calculator__hint",children:"Each opening is calculated as two side pieces plus one head piece."}),(0,ae.jsxs)("div",{className:"architrave-calculator__unit-row",children:[(0,ae.jsx)("span",{children:"Units"}),(0,ae.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,ae.jsx)("button",{type:"button",className:r==="m"?"is-selected":"",onClick:()=>n("m"),children:"Metres"}),(0,ae.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>n("ft"),children:"Feet"})]})]}),(0,ae.jsxs)("div",{className:"architrave-calculator__dimensions-header",children:[(0,ae.jsx)("span",{children:"Opening"}),(0,ae.jsx)("span",{children:"Qty"}),(0,ae.jsxs)("span",{children:["Width (",r,")"]}),(0,ae.jsxs)("span",{children:["Height (",r,")"]}),(0,ae.jsx)("span",{})]}),v("Single doors",i,(_,C)=>A(o,_,C)),v("Double doors",l,(_,C)=>A(c,_,C)),p.map((_,C)=>v(`Alternative door ${C+1}`,_,(R,T)=>m(D=>D.map((V,oe)=>oe===C?{...V,[R]:T}:V)),()=>m(R=>R.filter((T,D)=>D!==C)))),(0,ae.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>m(_=>[..._,sx()]),children:"+ Add alternative-sized door"})]}),(0,ae.jsxs)("div",{className:"architrave-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Standard profile"}),(0,ae.jsx)("p",{className:"architrave-calculator__hint",children:"Choose the profile you plan to use. Length calculations are the same for each profile."}),(0,ae.jsx)("div",{className:"architrave-calculator__profiles",children:Gv.filter(_=>Sn("architrave",`architrave-${_.id}`)).map(_=>(0,ae.jsxs)("button",{type:"button",className:`truss-estimator__option-card${f===_.id?" is-selected":""}`,onClick:()=>d(_.id),children:[(0,ae.jsx)(cx,{profile:_.id}),(0,ae.jsx)("div",{className:"truss-estimator__option-title",children:_.label}),(0,ae.jsx)("div",{className:"truss-estimator__option-copy",children:_.blurb})]},_.id))})]}),(0,ae.jsxs)("div",{className:"architrave-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,ae.jsx)("div",{className:"architrave-calculator__options",children:(0,ae.jsxs)("label",{className:"truss-estimator__field",children:[(0,ae.jsx)("span",{children:"Board length (m)"}),(0,ae.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,ae.jsx)("p",{className:"architrave-calculator__hint",children:"Waste allows for mitred corners, cuts and damaged lengths."})]}),(0,ae.jsxs)("div",{className:"architrave-calculator__totals",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ae.jsxs)("div",{className:"architrave-calculator__result-grid",children:[(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Architrave needed"}),(0,ae.jsxs)("strong",{children:[L.toFixed(2)," m"]})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Board lengths"}),(0,ae.jsx)("strong",{children:h})]})]})]}),(0,ae.jsxs)("div",{className:"architrave-calculator__actions",children:[(0,ae.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ae.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(b),disabled:L<=0,children:a})]})]})]})})}var Cn=$(Ve()),ne=$(ee()),Yv=60,$v=10,ux=.02,px=.012,Vv=1,Xv=4,dx=1.33,mx=1440,fx=1600,Qi=e=>Number.parseFloat(e)||0,hx=(e,t=2)=>e.toFixed(t);function Id({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Cn.useState)("brick"),[i,o]=(0,Cn.useState)("engineering-red"),[l,c]=(0,Cn.useState)("metric"),[p,m]=(0,Cn.useState)(""),[f,d]=(0,Cn.useState)(""),[g,w]=(0,Cn.useState)(!0),A=l==="metric"?Qi(p)*Qi(f):Qi(p)*Qi(f)*.092903,h=A*(r==="brick"?Yv:$v),u=Math.ceil(h),v=A*(r==="brick"?ux:px)*dx/(Vv+Xv),_=Math.ceil(v*Vv*mx),C=Math.ceil(v*Xv*fx),R=l==="metric"?A:A*10.7639,T=[{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"},...g?[{key:"mortar-cement",label:"General purpose cement",qty:_,unit:"kg",query:"general purpose cement",category:"cement"},{key:"mortar-sand",label:"Building sand",qty:C,unit:"kg",query:"building sand",category:"aggregate"}]:[]],D=V=>{if(V===l)return;let oe=V==="imperial"?3.28084:.3048;m((Qi(p)*oe).toFixed(2)),d((Qi(f)*oe).toFixed(2)),c(V)};return(0,ne.jsx)(ne.Fragment,{children:(0,ne.jsxs)("div",{className:"truss-estimator",children:[(0,ne.jsxs)("div",{className:"quick-order-hero",children:[(0,ne.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ne.jsx)("h1",{children:"Brick and Block Calculator"}),(0,ne.jsx)("p",{children:"Estimate masonry units, sand and cement for a wall."})]}),(0,ne.jsxs)("div",{className:"truss-estimator__card brick-calculator",children:[(0,ne.jsx)("h2",{className:"truss-estimator__step-title",children:"Wall area and masonry type"}),(0,ne.jsx)("p",{className:"truss-estimator__step-sub",children:"Pick brick or block and enter the wall dimensions for unit counts plus the cement and sand for the mortar."}),(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Masonry type"}),(0,ne.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["brick","Brick"],["block","Block"]].map(([V,oe])=>(0,ne.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===V?" is-selected":""}`,onClick:()=>n(V),children:[(0,ne.jsx)("div",{className:"truss-estimator__option-title",children:oe}),(0,ne.jsxs)("div",{className:"truss-estimator__option-copy",children:["Approx. ",V==="brick"?Yv:$v," per m\xB2"]})]},V))})]}),r==="brick"&&(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Brick type"}),(0,ne.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(([V,oe,_e])=>(0,ne.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i===V?" is-selected":""}`,onClick:()=>o(V),children:[(0,ne.jsx)("div",{className:"truss-estimator__option-title",children:oe}),(0,ne.jsx)("div",{className:"truss-estimator__option-copy",children:_e})]},V))})]}),(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,ne.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,ne.jsx)("button",{type:"button",className:l==="metric"?"is-selected":"",onClick:()=>D("metric"),children:"Metric"}),(0,ne.jsx)("button",{type:"button",className:l==="imperial"?"is-selected":"",onClick:()=>D("imperial"),children:"Imperial"})]}),(0,ne.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsxs)("span",{children:["Height (",l==="metric"?"m":"ft",")"]}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:V=>m(V.target.value)})]}),(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsxs)("span",{children:["Width (",l==="metric"?"m":"ft",")"]}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:f,onChange:V=>d(V.target.value)})]})]})]}),(0,ne.jsx)("div",{className:"brick-calculator__options",children:(0,ne.jsxs)("label",{className:"brick-calculator__checkbox",children:[(0,ne.jsx)("input",{type:"checkbox",checked:g,onChange:V=>w(V.target.checked)}),(0,ne.jsx)("span",{children:"Include mortar (cement and building sand, mixed 1:4)"})]})}),(0,ne.jsxs)("div",{className:"brick-calculator__totals",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ne.jsxs)("div",{className:"brick-calculator__result-grid",children:[(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Wall area"}),(0,ne.jsxs)("strong",{children:[hx(R)," ",l==="metric"?"m\xB2":"ft\xB2"]})]}),(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:r==="brick"?"Bricks":"Blocks"}),(0,ne.jsx)("strong",{children:u.toLocaleString("en-GB")})]}),g?(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Cement"}),(0,ne.jsxs)("strong",{children:[_," kg"]})]}),(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Building sand"}),(0,ne.jsxs)("strong",{children:[C," kg"]})]})]}):null]}),(0,ne.jsx)("p",{className:"brick-calculator__note",children:"Estimate based on standard nominal sizes and 10mm joints. Mortar is a general purpose 1:4 cement and sand mix; quantities are approximate, so confirm the specification before ordering."})]}),(0,ne.jsxs)("div",{className:"brick-calculator__actions",children:[(0,ne.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ne.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(T),disabled:A<=0,children:a})]})]})]})})}var qn=$(Ve()),te=$(ee()),gx=1.54,bx=1440,Fd=e=>Number.parseFloat(e)||0,Kr={mot:{label:"MOT Type 1",blurb:"Sub-base for patios and driveways",density:1.7,query:"MOT type 1"},"sharp-sand":{label:"Sharp sand",blurb:"Bedding and general groundwork",density:1.6,query:"sharp sand"},gravel:{label:"20mm gravel",blurb:"Drainage and landscaping",density:1.6,query:"20mm gravel"}};function Wd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,qn.useState)("m"),[i,o]=(0,qn.useState)(""),[l,c]=(0,qn.useState)(""),[p,m]=(0,qn.useState)(""),[f,d]=(0,qn.useState)("concrete"),[g,w]=(0,qn.useState)("mot"),A=r==="m"?1:.3048,L=Fd(i)*A*Fd(l)*A*Fd(p)*(r==="m"?.01:.0254),h=Kr[g],u=L*gx/7,b=u*bx,v=u*2,_=u*4,C=(T,D)=>Math.ceil(T*D*1e3),R=f==="concrete"?[{key:"cement",label:"General purpose cement",qty:Math.ceil(b),unit:"kg",query:"general purpose cement"},{key:"sharp-sand",label:"Sharp sand",qty:C(v,Kr["sharp-sand"].density),unit:"kg",query:Kr["sharp-sand"].query},{key:"gravel",label:"20mm gravel",qty:C(_,Kr.gravel.density),unit:"kg",query:Kr.gravel.query}]:[{key:g,label:h.label,qty:C(L,h.density),unit:"kg",query:h.query}];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:"Concrete and Aggregate Calculator"}),(0,te.jsx)("p",{children:"Calculate fixed site-mix concrete ingredients or aggregate bulk bags."})]}),(0,te.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,te.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose what you need"}),(0,te.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter the area and depth. The calculator works out the materials and adds them to your basket."}),(0,te.jsxs)("div",{className:"materials-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Material type"}),(0,te.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${f==="concrete"?" is-selected":""}`,onClick:()=>d("concrete"),children:[(0,te.jsx)("div",{className:"truss-estimator__option-title",children:"Site-mixed concrete"}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:"Cement, sharp sand and 20mm aggregate"})]}),(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${f==="aggregate"?" is-selected":""}`,onClick:()=>d("aggregate"),children:[(0,te.jsx)("div",{className:"truss-estimator__option-title",children:"Aggregates"}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:"MOT Type 1, sharp sand or 20mm gravel"})]})]})]}),f==="aggregate"&&(0,te.jsxs)("div",{className:"materials-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Aggregate type"}),(0,te.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.keys(Kr).map(T=>(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g===T?" is-selected":""}`,onClick:()=>w(T),children:[(0,te.jsx)("div",{className:"truss-estimator__option-title",children:Kr[T].label}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:Kr[T].blurb})]},T))})]}),(0,te.jsxs)("div",{className:"materials-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and depth"}),(0,te.jsxs)("div",{className:"materials-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:"Metric"}),(0,te.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>n("ft"),children:"Imperial"})]})]}),(0,te.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,te.jsxs)("label",{className:"truss-estimator__field",children:[(0,te.jsxs)("span",{children:["Length (",r,")"]}),(0,te.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:T=>o(T.target.value)})]}),(0,te.jsxs)("label",{className:"truss-estimator__field",children:[(0,te.jsxs)("span",{children:["Width (",r,")"]}),(0,te.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:T=>c(T.target.value)})]})]}),(0,te.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,te.jsxs)("span",{children:["Depth (",r==="m"?"cm":"inches",")"]}),(0,te.jsx)("input",{type:"number",min:"0",step:"0.1",value:p,onChange:T=>m(T.target.value)})]})]}),(0,te.jsxs)("div",{className:"materials-calculator__totals",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Materials required"}),(0,te.jsx)("div",{className:"materials-calculator__result-grid",children:f==="concrete"?(0,te.jsxs)(te.Fragment,{children:[(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Cement"}),(0,te.jsxs)("strong",{children:[b.toFixed(0)," kg"]})]}),(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Sharp sand"}),(0,te.jsxs)("strong",{children:[v.toFixed(2)," m\xB3"]})]}),(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"20mm aggregate"}),(0,te.jsxs)("strong",{children:[_.toFixed(2)," m\xB3"]})]})]}):(0,te.jsxs)(te.Fragment,{children:[(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:h.label}),(0,te.jsxs)("strong",{children:[L.toFixed(2)," m\xB3"]})]}),(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Approx. weight"}),(0,te.jsxs)("strong",{children:[(L*h.density).toFixed(2)," t"]})]}),(0,te.jsx)("div",{})]})}),(0,te.jsx)("p",{className:"materials-calculator__note",children:f==="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."})]}),(0,te.jsxs)("div",{className:"materials-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?.(R),disabled:L<=0,children:a})]})]})]})})}var $a=$(Ve());var O=$(ee()),Gi=12,ji=8,dc=.56,Zv=.21,Ra={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:{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}]}},En=["range","grid","pictureFrame","substructure"],wx={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:""}},mc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),fc=(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),vx=(e,t,a,r)=>{let n=mc(e,t,a),i=mc(e,t,r),o=mc(a,r,e),l=mc(a,r,t);return n===0&&fc(e,t,a)||i===0&&fc(e,t,r)||o===0&&fc(a,r,e)||l===0&&fc(a,r,t)?!0:n>0!=i>0&&o>0!=l>0},em=(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)&&vx(e[r],n,e[i],e[(i+1)%e.length]))return!0}return!1};function tm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,$a.useState)(0),[i,o]=(0,$a.useState)(wx),[l,c]=(0,$a.useState)(1),[p,m]=(0,$a.useState)({x:0,y:0}),[f,d]=(0,$a.useState)(null),g=(0,$a.useRef)(null),w=(0,$a.useRef)(null),A=(0,$a.useRef)(null),L=En[r],h=i.range?Ra.ranges[i.range]:null,u=Gi/l,b=ji/l,v=(Gi-u)/2,_=(ji-b)/2,C=Math.max(-Gi,Math.min(Gi*2-u,v+p.x)),R=Math.max(-ji,Math.min(ji*2-b,_+p.y)),T=Number.parseFloat(i.quickLengthM),D=Number.parseFloat(i.quickWidthM),V=T>0&&D>0,oe=z=>Math.abs(z.reduce((H,le,de)=>{let me=z[(de+1)%z.length];return H+le.x*me.y-me.x*le.y},0))/2,_e=(z,H)=>Math.hypot(H.x-z.x,H.y-z.y),Te=i.isOutlineClosed?oe(i.points):0,Oe=i.isOutlineClosed?i.points.reduce((z,H,le)=>z+_e(H,i.points[(le+1)%i.points.length]),0):0,xe=i.isOutlineClosed?i.points.reduce((z,H,le)=>z+(i.wallSegments.has(le)?0:_e(H,i.points[(le+1)%i.points.length])),0):0,X=i.points.reduce((z,H)=>({x:z.x+H.x/i.points.length,y:z.y+H.y/i.points.length}),{x:0,y:0}),J=i.points.length>1?(()=>{let z=i.points[0],H=i.points[1],le=_e(z,H),de=le?-(H.y-z.y)/le:0,me=le?(H.x-z.x)/le:0,$e=(z.x+H.x)/2,Le=(z.y+H.y)/2,k=de*($e-X.x)+me*(Le-X.y)>=0?1:-1;return{x:$e+de*dc*k,y:Le+me*dc*k}})():null,Ee=(()=>{let z=i.range?Ra.ranges[i.range]:Ra.ranges.meridian,H=i.deckSizeMode==="quick"?T*D:Te,le=i.deckSizeMode==="quick"?2*(T+D):xe,de=i.direction==="diagonal"?Ra.wastage.diagonal:Ra.wastage.straight,me=i.pictureFrame==="yes"?Ra.pictureFrame.extraWastage:0,Le=H/(z.boardWidthM+Ra.boardGapM)/z.boardLengthM,k=Math.ceil(Le*(1+de+me)),x=Math.ceil(H*30*(1+de+me)/200),E=Ra.joist.spacingOptions.find(N=>N.id===i.joistSpacing)??Ra.joist.spacingOptions[1],U=H/E.spacingM,Z=Math.ceil(U);return{range:z,area:H,boardCount:k,screwBoxes:x,joistMetres:Z,spacing:E}})(),wt=Ee?[{key:`boards-${i.range??"meridian"}`,label:`Deck boards (${Ee.range.label})`,qty:Math.round(Ee.boardCount*Ee.range.boardLengthM*100)/100,unit:"m",query:"timber decking board",category:"decking",calculatorWasteIncluded:!0},{key:"joists",label:"Treated C24 joists",qty:Ee.joistMetres,unit:"m",query:"treated joist",category:"timber",calculatorWasteIncluded:!0},{key:"screws",label:"Green decking screws (200/box)",qty:Ee.screwBoxes,unit:"box",query:"green decking screws",category:"fixings",calculatorWasteIncluded:!0}]:[],P=()=>L==="range"?!!i.range:L==="grid"?i.deckSizeMode==="quick"?V:i.isOutlineClosed&&Te>0:L==="pictureFrame"?!!i.pictureFrame&&!!i.direction:L==="substructure"?!!i.joistSpacing:!0,pe=r===En.length-1?a:"Next",Re=(z,H,le=!1)=>{let de=A.current?.getBoundingClientRect();if(!de)return null;let me=le?1:.25;return{x:Math.round(Math.max(C,Math.min(C+u,C+(z-de.left)/de.width*u))/me)*me,y:Math.round(Math.max(R,Math.min(R+b,R+(H-de.top)/de.height*b))/me)*me}},Ot=z=>{if(i.isOutlineClosed){let le=z.target;if(le!==z.currentTarget&&!le.classList.contains("deck-outline__grid"))return;w.current={startX:z.clientX,startY:z.clientY,startViewX:C,startViewY:R},z.currentTarget.setPointerCapture(z.pointerId);return}if(i.drawMode!=="outline")return;let H=Re(z.clientX,z.clientY,!0);H&&(d(null),o(le=>{let de=[...le.points,H];return em(de,!1)?{...le,drawError:"Edges cannot cross. Choose another corner."}:{...le,points:de,drawError:""}}))},jt=(z,H)=>{if(!i.isOutlineClosed){z.stopPropagation(),H===0&&i.points.length>=3&&o(le=>({...le,isOutlineClosed:!0,drawMode:"edges"}));return}z.stopPropagation(),g.current=H,z.currentTarget.setPointerCapture(z.pointerId)},qe=z=>{if(w.current){let de=A.current?.getBoundingClientRect();if(!de)return;let me=w.current,$e=me.startViewX-(z.clientX-me.startX)/de.width*u,Le=me.startViewY-(z.clientY-me.startY)/de.height*b;m({x:$e-v,y:Le-_});return}!i.isOutlineClosed&&i.drawMode==="outline"&&d(Re(z.clientX,z.clientY,!0));let H=g.current;if(H===null)return;let le=Re(z.clientX,z.clientY);le&&o(de=>{let me=de.points.map(($e,Le)=>Le===H?le:$e);return em(me,!0)?{...de,drawError:"Edges cannot cross. Move the corner to a different position."}:{...de,points:me,drawError:""}})},ke=z=>{w.current=null,g.current=null,z.currentTarget.hasPointerCapture(z.pointerId)&&z.currentTarget.releasePointerCapture(z.pointerId)},Be=z=>{o(H=>{let le=new Set(H.wallSegments);return le.has(z)?le.delete(z):le.add(z),{...H,wallSegments:le}})},Ye=()=>{r===0?e():n(z=>z-1)},vt=()=>{P()&&(r===En.length-1?t?.(wt):n(z=>z+1))};return(0,O.jsx)(O.Fragment,{children:(0,O.jsxs)("div",{className:"truss-estimator",children:[(0,O.jsxs)("div",{className:"quick-order-hero",children:[(0,O.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,O.jsx)("h1",{children:"Decking Calculator"}),(0,O.jsx)("p",{children:"Estimate timber boards, joists and screws for your deck."})]}),(0,O.jsxs)("div",{className:"truss-estimator__card",children:[(0,O.jsxs)("div",{className:"truss-estimator__body",children:[L==="range"?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",En.length]}),(0,O.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your timber decking"}),(0,O.jsx)("p",{className:"truss-estimator__step-sub",children:"Both options are fixed, orderable pressure-treated timber boards."}),(0,O.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Ra.ranges).filter(([z])=>Sn("decking",`boards-${z}`)).map(([z,H])=>(0,O.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.range===z?" is-selected":""}`,onClick:()=>o(le=>({...le,range:z})),children:[(0,O.jsx)("div",{className:"truss-estimator__option-title",children:H.label}),(0,O.jsx)("div",{className:"truss-estimator__option-copy",children:H.blurb}),(0,O.jsxs)("div",{className:"truss-estimator__option-copy",children:[H.boardLengthM,"m boards"]})]},z))})]}):null,L==="grid"?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",En.length]}),(0,O.jsx)("h2",{className:"truss-estimator__step-title",children:"Tell us your deck size"}),(0,O.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,O.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,O.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.deckSizeMode==="quick"?" is-selected":""}`,onClick:()=>o(z=>({...z,deckSizeMode:"quick"})),children:"Quick estimate"}),(0,O.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.deckSizeMode==="draw"?" is-selected":""}`,onClick:()=>o(z=>({...z,deckSizeMode:"draw",drawMode:"outline"})),children:"Draw your space"})]}),i.deckSizeMode==="quick"?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,O.jsxs)("label",{className:"truss-estimator__field",children:[(0,O.jsx)("span",{children:"Length (m)"}),(0,O.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:i.quickLengthM,onChange:z=>o(H=>({...H,quickLengthM:z.target.value}))})]}),(0,O.jsxs)("label",{className:"truss-estimator__field",children:[(0,O.jsx)("span",{children:"Width (m)"}),(0,O.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:i.quickWidthM,onChange:z=>o(H=>({...H,quickWidthM:z.target.value}))})]})]}),(0,O.jsx)("div",{className:"truss-estimator__grid-hint",children:"For L-shaped decks, cut-outs, or sides against a wall, use Draw your space."}),V?(0,O.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,O.jsxs)("div",{children:[(T*D).toFixed(2)," m\xB2 deck"]}),(0,O.jsxs)("div",{children:[(2*(T+D)).toFixed(2)," m perimeter"]})]}):null]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)("div",{className:"truss-estimator__section-heading",children:"Draw your deck"}),(0,O.jsx)("p",{className:"truss-estimator__step-sub",children:"Click to add corners, then close the outline. Drag any handle to refine it."}),(0,O.jsxs)("div",{className:"deck-outline__toolbar",children:[i.isOutlineClosed?(0,O.jsxs)("div",{className:"deck-outline__summary",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)("span",{children:"Deck area"}),(0,O.jsxs)("strong",{children:[Te.toFixed(2)," m\xB2"]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)("span",{children:"Perimeter"}),(0,O.jsxs)("strong",{children:[Oe.toFixed(2)," m"]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)("span",{children:"Wall edges"}),(0,O.jsx)("strong",{children:i.wallSegments.size>0?i.wallSegments.size:"None"})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)("span",{children:"Visible edge"}),(0,O.jsxs)("strong",{children:[xe.toFixed(2)," m"]})]})]}):null,(0,O.jsxs)("div",{className:"deck-outline__actions",children:[(0,O.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(z=>({...z,points:z.points.slice(0,-1)})),disabled:i.points.length===0||i.isOutlineClosed,children:"Undo"}),(0,O.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{d(null),o(z=>({...z,points:[],isOutlineClosed:!1,wallSegments:new Set,drawMode:"outline",drawError:""}))},disabled:i.points.length===0,children:"Clear"}),(0,O.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(z=>({...z,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,O.jsx)("div",{className:"deck-editor-layout",children:(0,O.jsxs)("div",{className:"deck-editor-layout__canvas-column",children:[(0,O.jsxs)("div",{className:"deck-outline",children:[(0,O.jsxs)("svg",{ref:A,className:`deck-outline__canvas${i.isOutlineClosed?" is-pan-mode":""}`,viewBox:`${C} ${R} ${u} ${b}`,preserveAspectRatio:"none","aria-label":"Deck outline drawing area",onPointerDown:Ot,onPointerMove:qe,onPointerUp:ke,onPointerLeave:()=>{d(null),w.current||(g.current=null)},children:[(0,O.jsx)("defs",{children:(0,O.jsx)("pattern",{id:"deck-outline-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,O.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,O.jsx)("rect",{x:-Gi,y:-ji,width:Gi*3,height:ji*3,className:"deck-outline__grid",fill:"url(#deck-outline-grid)"}),i.points.length>1?(0,O.jsx)("polyline",{className:"deck-outline__preview",points:i.points.map(z=>`${z.x},${z.y}`).join(" ")}):null,i.isOutlineClosed?(0,O.jsx)("polygon",{className:"deck-outline__shape",points:i.points.map(z=>`${z.x},${z.y}`).join(" "),stroke:"none"}):null,i.points.length>1?i.points.slice(0,i.isOutlineClosed?void 0:-1).map((z,H)=>{let le=i.points[i.isOutlineClosed?(H+1)%i.points.length:H+1],de=_e(z,le),me=de?-(le.y-z.y)/de:0,$e=de?(le.x-z.x)/de:0,Le=(z.x+le.x)/2,k=(z.y+le.y)/2,x=me*(Le-X.x)+$e*(k-X.y)>=0?1:-1,E=Le+me*dc*x,U=k+$e*dc*x;return(0,O.jsxs)("g",{children:[(0,O.jsx)("line",{className:"deck-outline__edge-hit",x1:z.x,y1:z.y,x2:le.x,y2:le.y,onClick:i.isOutlineClosed?()=>Be(H):void 0}),(0,O.jsx)("line",{className:`deck-outline__edge${i.wallSegments.has(H)?" is-wall":""}`,x1:z.x,y1:z.y,x2:le.x,y2:le.y,pointerEvents:"none"}),(0,O.jsxs)("text",{className:`deck-outline__edge-label${i.wallSegments.has(H)?" is-wall":""}`,x:E,y:U,textAnchor:"middle",dominantBaseline:"central",fontSize:Zv/l,children:[de.toFixed(2)," m"]})]},`segment-${H}`)}):null,!i.isOutlineClosed&&i.points.length>0&&f?(()=>{let z=i.points[i.points.length-1],H=_e(z,f);if(!H)return null;let le=-(f.y-z.y)/H,de=(f.x-z.x)/H,me=(z.x+f.x)/2,$e=(z.y+f.y)/2;return(0,O.jsxs)("g",{className:"deck-outline__live-measurement",children:[(0,O.jsx)("line",{x1:z.x,y1:z.y,x2:f.x,y2:f.y}),(0,O.jsxs)("text",{x:me+le*.34,y:$e+de*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:Zv/l,children:[H.toFixed(2)," m"]})]})})():null,i.points.map((z,H)=>(0,O.jsx)("circle",{className:"deck-outline__point",cx:z.x,cy:z.y,r:"0.13",onPointerDown:le=>jt(le,H)},`point-${H}`))]}),(0,O.jsxs)("div",{className:"deck-outline__zoom","aria-label":"Zoom controls",children:[(0,O.jsx)("button",{type:"button",onClick:()=>c(z=>Math.max(.5,z-.25)),disabled:l===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,O.jsxs)("span",{children:[Math.round(l*100),"%"]}),(0,O.jsx)("button",{type:"button",onClick:()=>c(z=>Math.min(1,z+.25)),disabled:l===1,"aria-label":"Zoom in",children:"+"})]}),i.isOutlineClosed&&i.wallSegments.size===0&&J?(0,O.jsx)("div",{className:"deck-outline__edge-prompt",role:"status",style:{left:`${(J.x-C)/u*100}%`,top:`${(J.y-R)/b*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,O.jsx)("button",{type:"button",className:"deck-outline__close",onClick:()=>o(z=>em(z.points,!0)?{...z,drawError:"Edges cannot cross. Adjust the outline before finishing."}:{...z,isOutlineClosed:!0,drawMode:"edges",drawError:""}),children:"Finish outline"}):null]}),(0,O.jsxs)("div",{className:"deck-outline__supporting",children:[(0,O.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,O.jsx)("div",{className:"deck-outline__error",role:"alert",children:i.drawError}):null]})]})})]})]}):null,L==="pictureFrame"?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",En.length]}),(0,O.jsx)("h2",{className:"truss-estimator__step-title",children:"Picture frame border?"}),(0,O.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,O.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(z=>(0,O.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.pictureFrame===z.id?" is-selected":""}`,onClick:()=>o(H=>({...H,pictureFrame:z.id})),children:[(0,O.jsx)("img",{className:"truss-estimator__visual-card-img",src:It(z.img),alt:""}),(0,O.jsx)("span",{children:z.label})]},z.id))}),(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)("div",{className:"truss-estimator__section-heading",children:"Board direction"}),(0,O.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(z=>(0,O.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.direction===z.id?" is-selected":""}`,onClick:()=>o(H=>({...H,direction:z.id})),children:[(0,O.jsx)("img",{className:"truss-estimator__visual-card-img",src:It(z.img),alt:""}),(0,O.jsx)("span",{children:z.label})]},z.id))})]})]}):null,L==="substructure"?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",En.length]}),(0,O.jsx)("h2",{className:"truss-estimator__step-title",children:"Substructure"}),(0,O.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,O.jsx)("div",{className:"truss-estimator__section-heading",children:"Joist spacing"}),(0,O.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Ra.joist.spacingOptions.map(z=>(0,O.jsx)("button",{type:"button",className:`truss-estimator__option-card${i.joistSpacing===z.id?" is-selected":""}`,onClick:()=>o(H=>({...H,joistSpacing:z.id})),children:(0,O.jsx)("div",{className:"truss-estimator__option-title",children:z.label})},z.id))})]}):null]}),(0,O.jsxs)("div",{className:"truss-estimator__nav",children:[(0,O.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:Ye,children:"Back"}),(0,O.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:vt,disabled:!P(),children:[(0,O.jsx)("span",{children:pe}),(0,O.jsx)("span",{className:"arrow",children:(0,O.jsx)(Qt,{})})]})]})]})]})})}var Sa=$(Ve());var j=$(ee()),Pv=12,Kv=30,Yi=12,$i=8,Jv=.56,ka={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 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}}},Mn=["range","height","gate","posts"],am=e=>Number(e)<=1.2?"6":"8",Iv=(e,t)=>Sn("fencing",`panels-${e??"boundary"}-${t}`),Fv=(e,t)=>!t||Sn("fencing",e==="concrete"?`concrete-intermediate-${am(t)}`:`timber-post-${am(t)}`),yx={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:""}},hc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),gc=(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),_x=(e,t,a,r)=>{let n=hc(e,t,a),i=hc(e,t,r),o=hc(a,r,e),l=hc(a,r,t);return n===0&&gc(e,t,a)||i===0&&gc(e,t,r)||o===0&&gc(a,r,e)||l===0&&gc(a,r,t)?!0:n>0!=i>0&&o>0!=l>0},bc=(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)&&_x(e[r],e[(r+1)%e.length],e[n],e[(n+1)%e.length]))return!0;return!1};function rm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Sa.useState)(0),[i,o]=(0,Sa.useState)(yx),l=(0,Sa.useRef)(null),c=(0,Sa.useRef)(null),[p,m]=(0,Sa.useState)(1),[f,d]=(0,Sa.useState)({x:0,y:0}),[g,w]=(0,Sa.useState)(null),A=(0,Sa.useRef)(null),L=(0,Sa.useRef)(null),h=(0,Sa.useRef)(null),u=Mn[r],b=i.range?ka.ranges[i.range]:null,v=Yi/p,_=$i/p,C=(Yi-v)/2,R=($i-_)/2,T=Math.max(-Yi,Math.min(Yi*2-v,C+f.x)),D=Math.max(-$i,Math.min($i*2-_,R+f.y)),V=i.boundaryPoints.reduce((k,x)=>({x:k.x+x.x/Math.max(1,i.boundaryPoints.length),y:k.y+x.y/Math.max(1,i.boundaryPoints.length)}),{x:0,y:0}),oe=k=>{let x=new Set,E=[];return k.forEach(U=>{let[Z,N]=U.split(",").map(Number),G=[{key:`H,${Z},${N}`,type:"H",x:Z,y:N},{key:`H,${Z},${N+1}`,type:"H",x:Z,y:N+1},{key:`V,${Z},${N}`,type:"V",x:Z,y:N},{key:`V,${Z+1},${N}`,type:"V",x:Z+1,y:N}],Y=[!k.has(`${Z},${N-1}`),!k.has(`${Z},${N+1}`),!k.has(`${Z-1},${N}`),!k.has(`${Z+1},${N}`)];G.forEach((ce,Se)=>{Y[Se]&&!x.has(ce.key)&&(x.add(ce.key),E.push(ce))})}),E},_e=(k,x)=>oe(k).filter(E=>!x.has(E.key)),Te=(k,x)=>_e(k,x).length,Oe=(k,x)=>{let E={};_e(k,x).forEach(Z=>{var N,G,Y,ce;Z.type==="H"?((E[N=`${Z.x},${Z.y}`]||(E[N]=[])).push("H"),(E[G=`${Z.x+1},${Z.y}`]||(E[G]=[])).push("H")):((E[Y=`${Z.x},${Z.y}`]||(E[Y]=[])).push("V"),(E[ce=`${Z.x},${Z.y+1}`]||(E[ce]=[])).push("V"))});let U=0;return Object.values(E).forEach(Z=>{(Z.length===1||Z.length===2&&Z[0]!==Z[1]||Z.length>=3)&&(U+=1)}),U},X=(()=>{let k=i.range?ka.ranges[i.range]:ka.ranges.boundary,x=i.height??"1.8",E=i.boundaryMode==="quick"?Math.max(0,Number.parseFloat(i.quickLengthM)||0):i.boundaryClosed?i.boundaryPoints.slice(0,-1).reduce((Yt,hr,_t)=>Yt+(i.excludedBoundaryEdges.has(_t)?0:Math.hypot(i.boundaryPoints[_t+1].x-hr.x,i.boundaryPoints[_t+1].y-hr.y)),0):0,U=i.gateType&&i.gateType!=="none"?Number.parseFloat(i.gateWidthM)||ka.gate[i.gateType].widthDefault:0,Z=Math.max(0,E-U),N=Z>0?Math.ceil(Z/k.panelWidthM):0,G=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,Y=i.boundaryMode==="quick"?Z>0?2:0:i.boundaryClosed?i.boundaryPoints.slice(0,G?-1:void 0).reduce((Yt,hr,_t)=>{let Zi=_t>0&&!i.excludedBoundaryEdges.has(_t-1),_m=_t<i.boundaryPoints.length-1&&!i.excludedBoundaryEdges.has(_t);return Yt+(Zi||_m?1:0)},0):0,ce=Z>0?Math.ceil(Z/k.panelWidthM)+1:0,Se=Math.max(0,ce-Y),yt=i.mountingType?ka.mounting[i.mountingType]:ka.mounting.concrete,ft=i.gateType&&i.gateType!=="none"?2:0,At=Se+Y+ft,ym=i.mountingType==="postcrete"?At*ka.mounting.postcrete.bagsPerPost:0,Jr=i.gravelBoard==="yes"?N:0;return{range:k,height:x,totalEdgeM:E,fencedLengthM:Z,gateWidthM:U,panelsCount:N,cornerPostCount:Y,intermediatePostCount:Se,gatePostCount:ft,totalPostCount:At,bagsCount:ym,gravelCount:Jr,capCount:At,mounting:yt}})(),J=i.gateType&&i.gateType!=="none"?ka.gate[i.gateType].label:null,ze=am(X.height),Ee=X?[{key:`panels-${i.range??"boundary"}-${X.height}`,label:`${X.range.label} panels (${X.height}m)`,qty:X.panelsCount,unit:"each",query:"fence panel",category:"fencing"},...i.mountingType==="concrete"?[{key:`concrete-intermediate-${ze}`,label:"Intermediate concrete posts",qty:X.intermediatePostCount,unit:"each",query:"concrete fence post",category:"fencing"},{key:`concrete-end-${ze}`,label:"End and corner concrete posts",qty:X.cornerPostCount+X.gatePostCount,unit:"each",query:"concrete end post",category:"fencing"}]:[{key:`timber-post-${ze}`,label:"Timber fence posts",qty:X.totalPostCount,unit:"each",query:"timber fence post",category:"fencing"},{key:"postcrete",label:"Postcrete",qty:X.bagsCount,unit:"bag",query:"postcrete",category:"cement"}],...J?[{key:`gate-${i.range??"boundary"}`,label:i.range==="skyline"?"Single feather edge gate":"Single lap gate",qty:1,unit:"each",query:i.range==="skyline"?"feather edge gate":"lap gate",category:"fencing"}]:[],...X.gravelCount>0?[{key:"gravel-boards",label:"Concrete gravel boards",qty:X.gravelCount,unit:"each",query:"gravel board",category:"fencing"}]:[]]:[],wt=()=>{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},P=r===Mn.length-1?a:"Next",pe=k=>{o(x=>{let E=k(new Set(x.grid)),U=new Set([...x.excludedEdges].filter(Z=>oe(E).some(N=>N.key===Z)));return{...x,grid:E,excludedEdges:U}})},Re=(k,x,E)=>{pe(U=>{let Z=`${k},${x}`;return E?U.add(Z):U.delete(Z),U})},Ot=(k,x,E,U,Z)=>{let N=k,G=x,Y=Math.abs(E-k),ce=k<E?1:-1,Se=-Math.abs(U-x),yt=x<U?1:-1,ft=Y+Se;for(;Re(N,G,Z),!(N===E&&G===U);){let At=2*ft;At>=Se&&(ft+=Se,N+=ce),At<=Y&&(ft+=Y,G+=yt)}},jt=(k,x)=>{let E=c.current?.getBoundingClientRect();if(!E)return null;let U=Math.floor((k-E.left)/Kv),Z=Math.floor((x-E.top)/Kv);return U<0||Z<0||U>=Pv||Z>=Pv?null:{x:U,y:Z}},qe=k=>{if(i.gridMode!=="draw")return;let x=jt(k.clientX,k.clientY);if(!x)return;k.preventDefault();let E=`${x.x},${x.y}`,U=!i.grid.has(E);l.current={active:!0,paintValue:U,lastX:x.x,lastY:x.y},k.currentTarget.setPointerCapture(k.pointerId),Re(x.x,x.y,U)},ke=k=>{let x=l.current;if(!x?.active)return;let E=jt(k.clientX,k.clientY);E&&(E.x===x.lastX&&E.y===x.lastY||(Ot(x.lastX,x.lastY,E.x,E.y,x.paintValue),l.current={...x,lastX:E.x,lastY:E.y}))},Be=k=>{l.current?.active&&(l.current=null,k.currentTarget.releasePointerCapture(k.pointerId))},Ye=(k,x,E=!1)=>{let U=h.current?.getBoundingClientRect();if(!U)return null;let Z=E?1:.25;return{x:Math.round(Math.max(T,Math.min(T+v,T+(k-U.left)/U.width*v))/Z)*Z,y:Math.round(Math.max(D,Math.min(D+_,D+(x-U.top)/U.height*_))/Z)*Z}},vt=k=>{if(i.boundaryClosed){let E=k.target;if(E!==k.currentTarget&&!E.classList.contains("fence-boundary__grid"))return;L.current={startX:k.clientX,startY:k.clientY,startViewX:T,startViewY:D},k.currentTarget.setPointerCapture(k.pointerId);return}let x=Ye(k.clientX,k.clientY,!0);x&&(w(null),o(E=>{let U=[...E.boundaryPoints,x];return bc(U,!1)?{...E}:{...E,boundaryPoints:U}}))},z=(k,x)=>{if(k.stopPropagation(),!i.boundaryClosed){if(x!==0||i.boundaryPoints.length<3)return;o(E=>bc(E.boundaryPoints,!0)?E:{...E,boundaryPoints:[...E.boundaryPoints,E.boundaryPoints[0]],boundaryClosed:!0});return}A.current=x,k.currentTarget.setPointerCapture(k.pointerId)},H=k=>{if(L.current){let E=h.current?.getBoundingClientRect();if(!E)return;let U=L.current,Z=U.startViewX-(k.clientX-U.startX)/E.width*v,N=U.startViewY-(k.clientY-U.startY)/E.height*_;d({x:Z-C,y:N-R});return}if(i.boundaryClosed||w(Ye(k.clientX,k.clientY,!0)),A.current===null)return;let x=Ye(k.clientX,k.clientY);x&&o(E=>{let U=E.boundaryPoints.length>2&&E.boundaryPoints[0].x===E.boundaryPoints[E.boundaryPoints.length-1].x&&E.boundaryPoints[0].y===E.boundaryPoints[E.boundaryPoints.length-1].y,Z=E.boundaryPoints.map((N,G)=>{let Y=G===A.current,ce=U&&A.current===0&&G===E.boundaryPoints.length-1;return Y||ce?x:N});return bc(Z,!1)?E:{...E,boundaryPoints:Z}})},le=k=>{L.current=null,A.current=null,k.currentTarget.hasPointerCapture(k.pointerId)&&k.currentTarget.releasePointerCapture(k.pointerId)},de=k=>{o(x=>{let E=new Set(x.excludedBoundaryEdges);return E.has(k)?E.delete(k):E.add(k),{...x,excludedBoundaryEdges:E}})},me=()=>{r===0?e():n(k=>k-1)},$e=()=>{wt()&&(r===Mn.length-1?t?.(Ee):n(k=>k+1))},Le=oe(i.grid);return(0,j.jsx)(j.Fragment,{children:(0,j.jsxs)("div",{className:"truss-estimator",children:[(0,j.jsxs)("div",{className:"quick-order-hero",children:[(0,j.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,j.jsx)("h1",{children:"Fencing Calculator"}),(0,j.jsx)("p",{children:"Estimate panels, posts and cost for your fence line in a few steps."})]}),(0,j.jsxs)("div",{className:"truss-estimator__card",children:[(0,j.jsxs)("div",{className:"truss-estimator__body",children:[u==="range"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Mn.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your fence panels"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"The calculator uses fixed, orderable timber panels from the catalogue."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(ka.ranges).map(([k,x])=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.range===k?" is-selected":""}`,onClick:()=>o(E=>({...E,range:k,height:E.height&&Iv(k,E.height)?E.height:null})),children:[(0,j.jsx)("div",{className:"truss-estimator__option-title",children:x.label}),(0,j.jsx)("div",{className:"truss-estimator__option-copy",children:x.blurb})]},k))})]}):null,u==="range"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("div",{className:"truss-estimator__section-heading",children:"Measure your fence line"}),(0,j.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,j.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,j.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.boundaryMode==="quick"?" is-selected":""}`,onClick:()=>o(k=>({...k,boundaryMode:"quick"})),children:"Quick estimate"}),(0,j.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,j.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact fence-boundary__quick-field",children:[(0,j.jsx)("span",{children:"Total fence length (m)"}),(0,j.jsx)("input",{type:"number",min:"0",step:"0.1",value:i.quickLengthM,onChange:k=>o(x=>({...x,quickLengthM:k.target.value}))})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("div",{className:"fence-boundary__toolbar",children:(0,j.jsxs)("div",{className:"fence-boundary__actions",children:[(0,j.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,j.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,j.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,j.jsxs)("div",{className:"fence-boundary",children:[(0,j.jsxs)("svg",{ref:h,className:`fence-boundary__canvas${i.boundaryClosed?" is-pan-mode":""}`,viewBox:`${T} ${D} ${v} ${_}`,preserveAspectRatio:"none","aria-label":"Fence boundary drawing area",onPointerDown:vt,onPointerMove:H,onPointerUp:le,onPointerLeave:()=>{w(null),L.current||(A.current=null)},children:[(0,j.jsx)("defs",{children:(0,j.jsx)("pattern",{id:"fence-boundary-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,j.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,j.jsx)("rect",{x:-Yi,y:-$i,width:Yi*3,height:$i*3,className:"fence-boundary__grid",fill:"url(#fence-boundary-grid)"}),i.boundaryPoints.length>1?(0,j.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,x)=>{let E=i.boundaryPoints[x+1],U=Math.hypot(E.x-k.x,E.y-k.y),Z=U?-(E.y-k.y)/U:0,N=U?(E.x-k.x)/U:0,G=(k.x+E.x)/2,Y=(k.y+E.y)/2,ce=Z*(G-V.x)+N*(Y-V.y)>=0?1:-1,Se=G+Z*Jv*ce,yt=Y+N*Jv*ce;return(0,j.jsxs)("g",{children:[(0,j.jsx)("line",{className:"fence-boundary__edge-hit",x1:k.x,y1:k.y,x2:E.x,y2:E.y,onClick:i.boundaryClosed?()=>de(x):void 0}),(0,j.jsx)("line",{className:`fence-boundary__edge${i.excludedBoundaryEdges.has(x)?" is-excluded":""}`,x1:k.x,y1:k.y,x2:E.x,y2:E.y,pointerEvents:"none"}),(0,j.jsxs)("text",{className:`fence-boundary__edge-label${i.excludedBoundaryEdges.has(x)?" is-excluded":""}`,x:Se,y:yt,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[U.toFixed(2)," m"]})]},`fence-edge-${x}`)}):null,!i.boundaryClosed&&i.boundaryPoints.length>0&&g?(()=>{let k=i.boundaryPoints[i.boundaryPoints.length-1],x=Math.hypot(g.x-k.x,g.y-k.y);if(!x)return null;let E=-(g.y-k.y)/x,U=(g.x-k.x)/x,Z=(k.x+g.x)/2,N=(k.y+g.y)/2;return(0,j.jsxs)("g",{className:"fence-boundary__live-measurement",children:[(0,j.jsx)("line",{x1:k.x,y1:k.y,x2:g.x,y2:g.y}),(0,j.jsxs)("text",{x:Z+E*.34,y:N+U*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[x.toFixed(2)," m"]})]})})():null,i.boundaryPoints.map((k,x)=>x>0&&x===i.boundaryPoints.length-1&&k.x===i.boundaryPoints[0]?.x&&k.y===i.boundaryPoints[0]?.y?null:(0,j.jsx)("circle",{className:`fence-boundary__point${!i.boundaryClosed&&x===0&&i.boundaryPoints.length>=3?" is-close-target":""}`,cx:k.x,cy:k.y,r:"0.13",onPointerDown:E=>z(E,x)},`fence-point-${x}`))]}),(0,j.jsxs)("div",{className:"fence-boundary__zoom","aria-label":"Zoom controls",children:[(0,j.jsx)("button",{type:"button",onClick:()=>m(k=>Math.max(.5,k-.25)),disabled:p===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,j.jsxs)("span",{children:[Math.round(p*100),"%"]}),(0,j.jsx)("button",{type:"button",onClick:()=>m(k=>Math.min(1,k+.25)),disabled:p===1,"aria-label":"Zoom in",children:"+"})]}),!i.boundaryClosed&&i.boundaryPoints.length>=2?(0,j.jsx)("button",{type:"button",className:"fence-boundary__close",onClick:()=>o(k=>bc(k.boundaryPoints,!1)?k:{...k,boundaryClosed:!0}),children:"Finish fence line"}):null]}),(0,j.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,j.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,j.jsx)("div",{children:i.boundaryMode==="quick"?`${(Number.parseFloat(i.quickLengthM)||0).toFixed(2)} m fence line`:`${X.totalEdgeM.toFixed(2)} m fence line`}),i.boundaryMode==="draw"&&i.boundaryClosed?(0,j.jsxs)("div",{children:[X.cornerPostCount," corner/end posts"]}):null]})]}):null,null,u==="height"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Mn.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Fence height"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"Select the nearest available panel height."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:ka.heights.filter(k=>Iv(i.range,k)).map(k=>(0,j.jsx)("button",{type:"button",className:`truss-estimator__visual-card${i.height===k?" is-selected":""}`,onClick:()=>o(x=>({...x,height:k,mountingType:x.mountingType&&Fv(x.mountingType,k)?x.mountingType:null})),children:(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--tall",src:It(`/fencing/height/${k}.webp`),alt:""})},k))}),(0,j.jsx)("div",{className:"truss-estimator__section-heading",children:"Gravel board?"}),(0,j.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,j.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.gravelBoard===k.id?" is-selected":""}`,onClick:()=>o(x=>({...x,gravelBoard:k.id})),children:[(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:It(k.img),alt:""}),(0,j.jsx)("span",{children:k.label})]},k.id))})]}):null,u==="gate"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Mn.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Do you need a gate?"}),(0,j.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,j.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,j.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${i.gateType===k.id?" is-selected":""}`,onClick:()=>o(x=>({...x,gateType:k.id,gateWidthM:k.id==="none"?"":String(ka.gate[k.id].widthDefault)})),children:[(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:It(k.img),alt:""}),(0,j.jsx)("span",{children:k.label})]},k.id))}),i.gateType&&i.gateType!=="none"?(0,j.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,j.jsx)("span",{children:"Gate width (m)"}),(0,j.jsx)("input",{type:"text",inputMode:"decimal",value:i.gateWidthM,onChange:k=>o(x=>({...x,gateWidthM:k.target.value}))})]}):null]}):null,u==="posts"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Mn.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Posts and fixing type"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose how the posts will be set."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(ka.mounting).filter(([k])=>Fv(k,i.height)).map(([k,x])=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.mountingType===k?" is-selected":""}`,onClick:()=>o(E=>({...E,mountingType:k})),children:[(0,j.jsx)("div",{className:"truss-estimator__option-title",children:x.label}),(0,j.jsx)("div",{className:"truss-estimator__option-copy",children:x.blurb})]},k))})]}):null]}),(0,j.jsxs)("div",{className:"truss-estimator__nav",children:[(0,j.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:me,children:"Back"}),(0,j.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:$e,disabled:!wt(),children:[(0,j.jsx)("span",{children:P}),(0,j.jsx)("span",{className:"arrow",children:(0,j.jsx)(Qt,{})})]})]})]})]})})}var wc=$(Ve()),be=$(ee()),Wv={floor:{label:"Floor between rooms",product:"Knauf Acoustic Roll",thickness:"100mm",coverage:12.36},ground:{label:"Ground floor",product:"Rigid PIR insulation board",thickness:"100mm",coverage:2.88},wall:{label:"Cavity wall",product:"Celotex CW4100",thickness:"100mm",coverage:3.24},roof:{label:"Pitched roof",product:"Kingspan K107",thickness:"100mm",coverage:8.64},loft:{label:"Loft",product:"Knauf Loft Roll 44",thickness:"100mm",coverage:13.89}};function nm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,wc.useState)("floor"),[i,o]=(0,wc.useState)(""),[l,c]=(0,wc.useState)(""),p=Number.parseFloat(i)*Number.parseFloat(l)||0,m=Wv[r],f=Math.ceil(p/m.coverage),d=[{key:`insulation-${r}`,label:`${m.product} ${m.thickness}`,qty:Math.round(p*100)/100,unit:"m2",query:m.product,category:"insulation"}],g=Object.entries(Wv);return(0,be.jsx)(be.Fragment,{children:(0,be.jsxs)("div",{className:"truss-estimator",children:[(0,be.jsxs)("div",{className:"quick-order-hero",children:[(0,be.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,be.jsx)("h1",{children:"Insulation Calculator"}),(0,be.jsx)("p",{children:"Estimate insulation coverage and pack quantities for floors, walls, roofs and lofts."})]}),(0,be.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,be.jsx)("h2",{className:"truss-estimator__step-title",children:"Where and what you are insulating"}),(0,be.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the application and product, and enter the area, for coverage and pack quantities."}),(0,be.jsxs)("div",{className:"materials-calculator__section",children:[(0,be.jsx)("div",{className:"truss-estimator__section-heading",children:"Application"}),(0,be.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:g.map(([w,A])=>(0,be.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===w?" is-selected":""}`,onClick:()=>n(w),children:[(0,be.jsx)("div",{className:"truss-estimator__option-title",children:A.label}),(0,be.jsxs)("div",{className:"truss-estimator__option-copy",children:[A.product,", ",A.thickness]})]},w))})]}),(0,be.jsxs)("div",{className:"materials-calculator__section",children:[(0,be.jsx)("div",{className:"truss-estimator__section-heading",children:"Area"}),(0,be.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,be.jsxs)("label",{className:"truss-estimator__field",children:[(0,be.jsx)("span",{children:"Length (m)"}),(0,be.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:w=>o(w.target.value)})]}),(0,be.jsxs)("label",{className:"truss-estimator__field",children:[(0,be.jsx)("span",{children:"Width (m)"}),(0,be.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:w=>c(w.target.value)})]})]})]}),(0,be.jsxs)("div",{className:"materials-calculator__totals",children:[(0,be.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,be.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,be.jsxs)("div",{children:[(0,be.jsx)("span",{children:"Insulated area"}),(0,be.jsxs)("strong",{children:[p.toFixed(2)," m\xB2"]})]}),(0,be.jsxs)("div",{children:[(0,be.jsx)("span",{children:m.product}),(0,be.jsxs)("strong",{children:[f," packs"]})]})]}),(0,be.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,be.jsxs)("div",{className:"materials-calculator__actions",children:[(0,be.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,be.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(d),disabled:p<=0,children:a})]})]})]})})}var Vi=$(Ve());var K=$(ee()),xx=10,kx=1.9*.762,Sx=1.9*1.524,vc=()=>({height:"",width:""}),yc=e=>Number.parseFloat(e)||0,e0=({height:e,width:t})=>yc(e)*yc(t);function im({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Vi.useState)([vc()]),[i,o]=(0,Vi.useState)([vc()]),[l,c]=(0,Vi.useState)("0"),[p,m]=(0,Vi.useState)("0"),[f,d]=(0,Vi.useState)(1),g=r.reduce((_,C)=>_+e0(C),0),w=i.reduce((_,C)=>_+e0(C),0),A=yc(l)*kx+yc(p)*Sx,L=Math.max(0,g-w-A),h=L*f/xx,u={key:"paint-emulsion",label:"Matt emulsion, brilliant white",qty:Math.round(h*10)/10,unit:"litres",query:"matt emulsion brilliant white"},b=dl("paint",u)!=null,v=(_,C,R,T)=>{_(D=>D.map((V,oe)=>oe===C?{...V,[R]:T}:V))};return(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)("div",{className:"truss-estimator",children:[(0,K.jsxs)("div",{className:"quick-order-hero",children:[(0,K.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,K.jsx)("h1",{children:"Paint Calculator"}),(0,K.jsx)("p",{children:"Estimate how much paint you need for your walls, including multiple coats and excluded areas."})]}),(0,K.jsxs)("div",{className:"truss-estimator__card paint-calculator",children:[(0,K.jsx)("h2",{className:"truss-estimator__step-title",children:"Walls, exclusions and coats"}),(0,K.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,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Enter the height and width of each wall you want to paint."}),(0,K.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,K.jsx)("span",{}),(0,K.jsx)("span",{children:"Height (m)"}),(0,K.jsx)("span",{children:"Width (m)"}),(0,K.jsx)("span",{})]}),r.map((_,C)=>(0,K.jsxs)("div",{className:"paint-calculator__row",children:[(0,K.jsxs)("span",{className:"paint-calculator__row-label",children:["Wall ",C+1]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,K.jsx)("input",{"aria-label":`Wall ${C+1} height in metres`,type:"number",min:"0",step:"0.01",value:_.height,onChange:R=>v(n,C,"height",R.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,K.jsx)("input",{"aria-label":`Wall ${C+1} width in metres`,type:"number",min:"0",step:"0.01",value:_.width,onChange:R=>v(n,C,"width",R.target.value)})]}),r.length>1?(0,K.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>n(R=>R.filter((T,D)=>D!==C)),children:"Remove"}):null]},`wall-${C}`)),(0,K.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>n(_=>[..._,vc()]),children:"+ Add another wall"})]}),(0,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Areas to exclude"}),(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Add windows, sockets, skirting boards or other areas that will not be painted."}),(0,K.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,K.jsx)("span",{}),(0,K.jsx)("span",{children:"Height (m)"}),(0,K.jsx)("span",{children:"Width (m)"}),(0,K.jsx)("span",{})]}),i.map((_,C)=>(0,K.jsxs)("div",{className:"paint-calculator__row",children:[(0,K.jsxs)("span",{className:"paint-calculator__row-label",children:["Area ",C+1]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,K.jsx)("input",{"aria-label":`Area ${C+1} height in metres`,type:"number",min:"0",step:"0.01",value:_.height,onChange:R=>v(o,C,"height",R.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,K.jsx)("input",{"aria-label":`Area ${C+1} width in metres`,type:"number",min:"0",step:"0.01",value:_.width,onChange:R=>v(o,C,"width",R.target.value)})]}),i.length>1?(0,K.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>o(R=>R.filter((T,D)=>D!==C)),children:"Remove"}):null]},`excluded-${C}`)),(0,K.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>o(_=>[..._,vc()]),children:"+ Add another area"})]}),(0,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Doors and coats"}),(0,K.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,K.jsxs)("div",{className:"truss-estimator__field-grid paint-calculator__small-fields",children:[(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Doors"}),(0,K.jsx)("input",{type:"number",min:"0",step:"1",value:l,onChange:_=>c(_.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Double doors"}),(0,K.jsx)("input",{type:"number",min:"0",step:"1",value:p,onChange:_=>m(_.target.value)})]})]}),(0,K.jsxs)("div",{className:"paint-calculator__coat-field",children:[(0,K.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,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Number of coats"}),(0,K.jsxs)("select",{value:f,onChange:_=>d(Number(_.target.value)),children:[(0,K.jsx)("option",{value:"1",children:"1 coat"}),(0,K.jsx)("option",{value:"2",children:"2 coats"}),(0,K.jsx)("option",{value:"3",children:"3 coats"})]})]})]})]}),(0,K.jsxs)("div",{className:"paint-calculator__totals",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,K.jsxs)("div",{className:"paint-calculator__result-grid",children:[(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Paintable area"}),(0,K.jsxs)("strong",{children:[L.toFixed(2)," m\xB2"]})]}),(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Coverage"}),(0,K.jsxs)("strong",{children:[f," ",f===1?"coat":"coats"]})]}),(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Paint required"}),(0,K.jsxs)("strong",{children:[h.toFixed(1)," litres"]})]})]}),(0,K.jsx)("p",{className:"paint-calculator__note",children:b?"Based on paint coverage of 10 m\xB2 per litre. Ordered as brilliant white matt emulsion, rounded up to whole tins.":"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,K.jsxs)("div",{className:"paint-calculator__actions",children:[(0,K.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),b?(0,K.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.([u]),disabled:h<=0,children:a}):(0,K.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",disabled:!0,children:"Paint products unavailable"})]})]})]})})}var fr=$(Ve()),re=$(ee()),_c=e=>Number.parseFloat(e)||0,om={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 lm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,fr.useState)("paving"),[i,o]=(0,fr.useState)("council"),[l,c]=(0,fr.useState)(""),[p,m]=(0,fr.useState)(""),[f,d]=(0,fr.useState)("100"),[g,w]=(0,fr.useState)("50"),[A,L]=(0,fr.useState)(!0),[h,u]=(0,fr.useState)(!0),b=_c(l)*_c(p),v=b,_=b*(_c(f)/1e3),C=b*.04,R=b*(_c(g)/1e3),T=Math.ceil(v/.36),D=Math.ceil(v/.1),V=Math.ceil(_*1700/800),oe=Math.ceil(C*1600/800),_e=Math.ceil(R*1600/800),Te=r==="paving"?{qty:T,unit:"each"}:r==="block"?{qty:v,unit:"m2"}:{qty:_e,unit:"bag"},Oe={paving:"paving slab",block:"block paver",gravel:"decorative gravel"}[r],xe=[{key:`surface-${i}`,label:om[r].find(J=>J.id===i)?.label??"Surface material",qty:Te.qty,unit:Te.unit,query:Oe,category:"landscaping"},...A?[{key:"sub-base",label:"MOT Type 1 sub-base",qty:V,unit:"bag",query:"MOT Type 1 sub base",category:"aggregate"}]:[],...h?[{key:"bedding",label:"Sharp sand bedding",qty:oe,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 and 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(([J,ze,Ee])=>(0,re.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===J?" is-selected":""}`,onClick:()=>{n(J),o(om[J][0].id)},children:[(0,re.jsx)("div",{className:"truss-estimator__option-title",children:ze}),(0,re.jsx)("div",{className:"truss-estimator__option-copy",children:Ee})]},J))}),(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:J=>o(J.target.value),children:om[r].map(J=>(0,re.jsx)("option",{value:J.id,children:J.label},J.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:J=>c(J.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:J=>m(J.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:g,onChange:J=>w(J.target.value)})]}),A&&(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:f,onChange:J=>d(J.target.value)})]}),(0,re.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,re.jsx)("input",{type:"checkbox",checked:A,onChange:J=>L(J.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:h,onChange:J=>u(J.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:[b.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"?`${T} slabs`:r==="block"?`${v.toFixed(2)} m\xB2`:`${_e} bulk bags`})]}),A&&(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"MOT Type 1"}),(0,re.jsxs)("strong",{children:[V," bulk bags"]})]}),h&&(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Sharp sand"}),(0,re.jsxs)("strong",{children:[oe," 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?.(xe),disabled:b<=0,children:a})]})]})]})})}var ml=$(Ve()),ie=$(ee()),Nx=2.88,t0=[{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"}],a0=()=>({length:"",height:""}),sm=e=>Number.parseFloat(e)||0;function cm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,ml.useState)([a0()]),[i,o]=(0,ml.useState)(""),[l,c]=(0,ml.useState)("standard"),[p,m]=(0,ml.useState)("screws"),f=r.reduce((C,R)=>C+sm(R.length)*sm(R.height),0),d=Math.max(0,f-sm(i)),g=Math.ceil(d/Nx),w=Math.ceil(d*12),A=Math.ceil(w/1e3),L=Math.ceil(d*1.2),h=Math.ceil(L/90),u=Math.ceil(d/3.5),b=t0.find(C=>C.id===l)?.label??"Standard",v=[{key:"board",label:`${b} plasterboard`,qty:g,unit:"sheet",query:`${b} plasterboard`,category:"plasterboard"},...p==="screws"?[{key:"screws",label:"Drywall screws",qty:A,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:h,unit:"roll",query:"plasterboard joint tape",category:"plasterboard"}],_=(C,R,T)=>{n(D=>D.map((V,oe)=>oe===C?{...V,[R]:T}:V))};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 and 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:t0.map(C=>(0,ie.jsxs)("button",{type:"button",className:`truss-estimator__option-card${l===C.id?" is-selected":""}`,onClick:()=>c(C.id),children:[(0,ie.jsx)("div",{className:"truss-estimator__option-title",children:C.label}),(0,ie.jsx)("div",{className:"truss-estimator__option-copy",children:C.blurb})]},C.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(([C,R,T])=>(0,ie.jsxs)("button",{type:"button",className:`truss-estimator__option-card${p===C?" is-selected":""}`,onClick:()=>m(C),children:[(0,ie.jsx)("div",{className:"truss-estimator__option-title",children:R}),(0,ie.jsx)("div",{className:"truss-estimator__option-copy",children:T})]},C))})]}),(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((C,R)=>(0,ie.jsxs)("div",{className:"materials-calculator__surface-row",children:[(0,ie.jsxs)("span",{children:["Surface ",R+1]}),(0,ie.jsx)("input",{"aria-label":`Surface ${R+1} length`,type:"number",min:"0",step:"0.01",value:C.length,onChange:T=>_(R,"length",T.target.value)}),(0,ie.jsx)("input",{"aria-label":`Surface ${R+1} height`,type:"number",min:"0",step:"0.01",value:C.height,onChange:T=>_(R,"height",T.target.value)}),r.length>1?(0,ie.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>n(T=>T.filter((D,V)=>V!==R)),children:"Remove"}):null]},`surface-${R}`)),(0,ie.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>n(C=>[...C,a0()]),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:C=>o(C.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:g})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:p==="screws"?"Drywall screws":"Board adhesive"}),(0,ie.jsx)("strong",{children:p==="screws"?`${w} (${A} boxes)`:`${u} bags`})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:"Joint tape"}),(0,ie.jsxs)("strong",{children:[L," m (",h," 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 fl=$(Ve());var y=$(ee()),Rt={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}}}},xc=["range","pitchAndDimensions","quantityAndGirders","bracing"],Cx={range:null,pitch:null,spanMM:"",overhangMM:"",roofLengthM:"",centres:null,girderCount:0,bracing:null,treatment:null,contact:{name:"",email:""}};function qx({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 Ex({type:e}){let t="#b3835a",a="#5c3b22",r="#d9b48f",n="#d3d8de",i="#7c8494",o=(m,f,d,g,w=8,A)=>{let L=d-m,h=g-f,u=Math.hypot(L,h)||1,b=-h/u,v=L/u,_=w*.2;return(0,y.jsxs)("g",{children:[(0,y.jsx)("line",{x1:m,y1:f,x2:d,y2:g,stroke:a,strokeWidth:w+3,strokeLinecap:"square"}),(0,y.jsx)("line",{x1:m,y1:f,x2:d,y2:g,stroke:t,strokeWidth:w,strokeLinecap:"square"}),(0,y.jsx)("line",{x1:m-b*_,y1:f-v*_,x2:d-b*_,y2:g-v*_,stroke:r,strokeWidth:Math.max(1.5,w*.24),strokeLinecap:"round",opacity:"0.9"})]},A)},l=(m,f,d)=>(0,y.jsxs)("g",{children:[(0,y.jsx)("rect",{x:m-7.5,y:f-5.5,width:"15",height:"11",rx:"2",fill:n,stroke:i,strokeWidth:"1"}),(0,y.jsx)("circle",{cx:m-4,cy:f-2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:m+4,cy:f-2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:m-4,cy:f+2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:m+4,cy:f+2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:m,cy:f,r:"1",fill:i})]},d),c=(m,f)=>(0,y.jsx)("rect",{x:m-9,y:"110",width:"18",height:"10",fill:a},f),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 Mx({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 r0({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 um({onBack:e}){let[t,a]=(0,fl.useState)(0),[r,n]=(0,fl.useState)(Cx),[i,o]=(0,fl.useState)(!1),[l,c]=(0,fl.useState)(!1),p=()=>{let h=Number.parseFloat(r.roofLengthM)||0,u=Number.parseFloat(r.centres??"");return h<=0||!u?0:Math.ceil(h*1e3/u)+1},f=(()=>{let h=r.range?Rt.ranges[r.range]:Rt.ranges.standard,u=r.pitch??"22.5",b=Rt.pitchMultipliers[u],v=(Number.parseFloat(r.spanMM)||0)/1e3,C=(Number.parseFloat(r.overhangMM)||0)>Rt.overhang.thresholdMM,R=p(),T=R+r.girderCount,D=Number.parseFloat(r.roofLengthM)||0,V=r.treatment?Rt.treatment[r.treatment]:Rt.treatment.untreated,oe=Rt.estimate.ranges[r.range??"standard"],_e=oe.supplyAt8m*Math.max(.7,v/8)*b*(1+V.surchargePct)+(C?Rt.overhang.surchargePerTruss:0),Te=R*_e,Oe=r.girderCount*_e*Rt.estimate.girderMultiplier,xe=r.bracing==="yes"?D*Rt.estimate.bracingPerMetre:0,X=Te+Oe+xe+Rt.estimate.delivery,J=Rt.estimate.design+R*oe.installPerTruss+r.girderCount*40,ze=X+J,Ee=ze*.2;return{range:h,count:R,girderCount:r.girderCount,overhangApplies:C,overhangUnits:T,roofLengthM:D,treatment:V,trussSupply:Te,bracingMaterials:xe,delivery:Rt.estimate.delivery,labour:J,subtotal:ze,vat:Ee,total:ze+Ee}})(),d=()=>{let h=xc[t];return h==="range"?!!r.range:h==="pitchAndDimensions"?!!r.pitch&&r.spanMM.trim()!==""&&r.overhangMM.trim()!=="":h==="quantityAndGirders"?r.roofLengthM.trim()!==""&&!!r.centres:h==="bracing"?!!r.bracing&&!!r.treatment:!0},g=t===xc.length-1?"View truss request":"Next",w=()=>{i?o(!1):t===0?e():a(h=>h-1)},A=()=>{d()&&(t===xc.length-1?(c(!1),o(!0)):a(h=>h+1))},L=()=>{let h=xc[t];return h==="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(Rt.ranges).map(([u,b])=>(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)(Ex,{type:u}),(0,y.jsxs)("div",{className:"truss-estimator__option-info",children:[(0,y.jsx)("div",{className:"truss-estimator__option-title",children:b.label}),(0,y.jsx)("div",{className:"truss-estimator__option-copy",children:b.blurb})]})]},u))})]}):h==="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(b=>({...b,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(b=>({...b,overhangMM:u.target.value}))}),(0,y.jsxs)("small",{children:["Overhangs beyond ",Rt.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:Rt.pitches.map(u=>(0,y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${r.pitch===u?" is-selected":""}`,onClick:()=>n(b=>({...b,pitch:u})),children:[(0,y.jsx)(qx,{degrees:Number.parseFloat(u)}),(0,y.jsxs)("span",{children:[u,"\xB0"]})]},u))})]}):h==="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(b=>({...b,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:Rt.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(b=>({...b,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:"+"})]})]}):h==="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(b=>({...b,bracing:u.id})),children:[(0,y.jsx)(Mx,{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)(r0,{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)(r0,{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:[f.range.label," roof trusses"]})]}),(0,y.jsxs)("strong",{children:[f.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:f.treatment.label})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Girder trusses"}),(0,y.jsx)("strong",{children:f.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:ot(f.trussSupply)})]}),f.bracingMaterials>0&&(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Bracing materials allowance"}),(0,y.jsx)("strong",{children:ot(f.bracingMaterials)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Delivery allowance"}),(0,y.jsx)("strong",{children:ot(f.delivery)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Design and installation labour"}),(0,y.jsx)("strong",{children:ot(f.labour)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Subtotal (ex. VAT)"}),(0,y.jsx)("strong",{children:ot(f.subtotal)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"VAT (20%)"}),(0,y.jsx)("strong",{children:ot(f.vat)})]}),(0,y.jsxs)("div",{className:"truss-request__price-total",children:[(0,y.jsx)("span",{children:"Estimated total"}),(0,y.jsx)("strong",{children:ot(f.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:L()}),(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:A,disabled:!d(),children:[(0,y.jsx)("span",{children:g}),(0,y.jsx)("span",{className:"arrow",children:(0,y.jsx)(Qt,{})})]})]})]})]})})}var Tn=$(Ve()),W=$(ee()),o0=e=>Number.parseFloat(e)||0,kc=(e,t)=>o0(e)*(t==="m"?1:.3048),n0=()=>({length:"",width:""}),i0=[{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 Tx({profile:e}){return(0,W.jsxs)("svg",{className:"skirting-calculator__profile-diagram",viewBox:"0 0 120 84","aria-hidden":"true",children:[(0,W.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,W.jsx)("line",{x1:"12",y1:"70",x2:"108",y2:"70"})]})}function pm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Tn.useState)("total"),[i,o]=(0,Tn.useState)("m"),[l,c]=(0,Tn.useState)(""),[p,m]=(0,Tn.useState)([n0()]),[f,d]=(0,Tn.useState)(""),[g,w]=(0,Tn.useState)("chamfered"),A="4.4",L=r==="total"?kc(l,i):p.reduce((_,C)=>_+2*(kc(C.length,i)+kc(C.width,i)),0),h=Math.max(0,L-kc(f,i)),u=Math.ceil(h/o0(A)),b=[{key:`skirting-${g}`,label:`${i0.find(_=>_.id===g)?.label} skirting board`,qty:h,unit:"m",query:"skirting board",category:"skirting"}],v=(_,C,R)=>{m(T=>T.map((D,V)=>V===_?{...D,[C]:R}:D))};return(0,W.jsx)(W.Fragment,{children:(0,W.jsxs)("div",{className:"truss-estimator",children:[(0,W.jsxs)("div",{className:"quick-order-hero",children:[(0,W.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,W.jsx)("h1",{children:"Skirting Board Calculator"}),(0,W.jsx)("p",{children:"Work out how many skirting board lengths you need for one room or a whole project."})]}),(0,W.jsxs)("div",{className:"truss-estimator__card skirting-calculator",children:[(0,W.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure by room or total length"}),(0,W.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,W.jsxs)("div",{className:"skirting-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"How would you like to measure?"}),(0,W.jsxs)("div",{className:"brick-calculator__unit-toggle skirting-calculator__mode-toggle",role:"group","aria-label":"Calculation method",children:[(0,W.jsx)("button",{type:"button",className:r==="total"?"is-selected":"",onClick:()=>n("total"),children:"Total length"}),(0,W.jsx)("button",{type:"button",className:r==="rooms"?"is-selected":"",onClick:()=>n("rooms"),children:"Room by room"})]})]}),(0,W.jsxs)("div",{className:"skirting-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Measurements"}),(0,W.jsxs)("div",{className:"skirting-calculator__unit-row",children:[(0,W.jsx)("span",{children:"Units"}),(0,W.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,W.jsx)("button",{type:"button",className:i==="m"?"is-selected":"",onClick:()=>o("m"),children:"Metres"}),(0,W.jsx)("button",{type:"button",className:i==="ft"?"is-selected":"",onClick:()=>o("ft"),children:"Feet"})]})]}),r==="total"?(0,W.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,W.jsxs)("span",{children:["Total skirting length (",i,")"]}),(0,W.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:_=>c(_.target.value)})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)("div",{className:"skirting-calculator__dimensions-header",children:[(0,W.jsx)("span",{children:"Room"}),(0,W.jsxs)("span",{children:["Length (",i,")"]}),(0,W.jsxs)("span",{children:["Width (",i,")"]}),(0,W.jsx)("span",{})]}),p.map((_,C)=>(0,W.jsxs)("div",{className:"skirting-calculator__room-row",children:[(0,W.jsxs)("span",{className:"skirting-calculator__room-label",children:["Room ",C+1]}),(0,W.jsx)("input",{"aria-label":`Room ${C+1} length in ${i}`,type:"number",min:"0",step:"0.01",value:_.length,onChange:R=>v(C,"length",R.target.value)}),(0,W.jsx)("input",{"aria-label":`Room ${C+1} width in ${i}`,type:"number",min:"0",step:"0.01",value:_.width,onChange:R=>v(C,"width",R.target.value)}),p.length>1?(0,W.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>m(R=>R.filter((T,D)=>D!==C)),children:"Remove"}):null]},`room-${C}`)),(0,W.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>m(_=>[..._,n0()]),children:"+ Add another room"})]}),(0,W.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,W.jsxs)("span",{children:["Openings and doorways to deduct (",i,") ",(0,W.jsx)("small",{children:"optional"})]}),(0,W.jsx)("input",{type:"number",min:"0",step:"0.01",value:f,onChange:_=>d(_.target.value)})]})]}),(0,W.jsxs)("div",{className:"skirting-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Profile"}),(0,W.jsx)("p",{className:"skirting-calculator__hint",children:"Choose the finish you want for the fixed 4.4m white-primed MDF boards."}),(0,W.jsx)("div",{className:"architrave-calculator__profiles",children:i0.map(_=>(0,W.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g===_.id?" is-selected":""}`,onClick:()=>w(_.id),children:[(0,W.jsx)(Tx,{profile:_.id}),(0,W.jsx)("div",{className:"truss-estimator__option-title",children:_.label}),(0,W.jsx)("div",{className:"truss-estimator__option-copy",children:_.blurb})]},_.id))})]}),(0,W.jsxs)("div",{className:"skirting-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,W.jsx)("div",{className:"truss-estimator__field-grid skirting-calculator__options-grid",children:(0,W.jsxs)("label",{className:"truss-estimator__field",children:[(0,W.jsx)("span",{children:"Board length"}),(0,W.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,W.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,W.jsxs)("div",{className:"skirting-calculator__totals",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,W.jsxs)("div",{className:"skirting-calculator__result-grid",children:[(0,W.jsxs)("div",{children:[(0,W.jsx)("span",{children:"Net skirting"}),(0,W.jsxs)("strong",{children:[h.toFixed(2)," m"]})]}),(0,W.jsxs)("div",{children:[(0,W.jsx)("span",{children:"Board lengths"}),(0,W.jsx)("strong",{children:u})]})]}),(0,W.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,W.jsxs)("div",{className:"skirting-calculator__actions",children:[(0,W.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,W.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(b),disabled:h<=0,children:a})]})]})]})})}var Xi=$(Ve()),se=$(ee()),hl=e=>Number.parseFloat(e)||0;function dm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Xi.useState)("studs"),[i,o]=(0,Xi.useState)(""),[l,c]=(0,Xi.useState)(""),[p,m]=(0,Xi.useState)("600"),[f,d]=(0,Xi.useState)("2.4"),g=i&&l&&p?Math.ceil(hl(l)/(hl(p)/1e3))+1:0,w=g*hl(i),A=hl(f)>0?Math.ceil(w/hl(f)):0,L=[{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"}],h={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"]},b={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,se.jsx)(se.Fragment,{children:(0,se.jsxs)("div",{className:"truss-estimator",children:[(0,se.jsxs)("div",{className:"quick-order-hero",children:[(0,se.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,se.jsx)("h1",{children:"Timber Calculator"}),(0,se.jsx)("p",{children:"Estimate studs, joists or battens from a run length, width and spacing."})]}),(0,se.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,se.jsx)("h2",{className:"truss-estimator__step-title",children:"Member size and spacing"}),(0,se.jsxs)("p",{className:"truss-estimator__step-sub",children:[b.help," Enter the member length and centres to estimate the number of pieces and stock lengths."]}),(0,se.jsxs)("div",{className:"materials-calculator__section",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber use"}),(0,se.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:Object.keys(h).map(v=>(0,se.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===v?" is-selected":""}`,onClick:()=>n(v),children:[(0,se.jsx)("div",{className:"truss-estimator__option-title",children:h[v][0]}),(0,se.jsx)("div",{className:"truss-estimator__option-copy",children:h[v][1]})]},v))})]}),(0,se.jsxs)("div",{className:"materials-calculator__section",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Dimensions and spacing"}),(0,se.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsxs)("span",{children:[b.member," (m)"]}),(0,se.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:v=>o(v.target.value)})]}),(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsxs)("span",{children:[b.overall," (m)"]}),(0,se.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:v=>c(v.target.value)})]})]}),(0,se.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsx)("span",{children:"Centres (mm)"}),(0,se.jsxs)("select",{value:p,onChange:v=>m(v.target.value),children:[(0,se.jsx)("option",{value:"300",children:"300 mm"}),(0,se.jsx)("option",{value:"400",children:"400 mm"}),(0,se.jsx)("option",{value:"450",children:"450 mm"}),(0,se.jsx)("option",{value:"600",children:"600 mm"})]})]}),(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsx)("span",{children:"Stock length (m)"}),(0,se.jsxs)("select",{value:f,onChange:v=>d(v.target.value),children:[(0,se.jsx)("option",{value:"2.4",children:"2.40 m"}),(0,se.jsx)("option",{value:"3.6",children:"3.60 m"}),(0,se.jsx)("option",{value:"4.8",children:"4.80 m"})]})]})]})]}),(0,se.jsxs)("div",{className:"materials-calculator__totals",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,se.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,se.jsxs)("div",{children:[(0,se.jsx)("span",{children:b.count}),(0,se.jsx)("strong",{children:g})]}),(0,se.jsxs)("div",{children:[(0,se.jsx)("span",{children:"Linear metres"}),(0,se.jsxs)("strong",{children:[w.toFixed(2)," m"]})]}),(0,se.jsxs)("div",{children:[(0,se.jsxs)("span",{children:[f," m lengths"]}),(0,se.jsx)("strong",{children:A})]})]}),(0,se.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,se.jsxs)("div",{className:"materials-calculator__actions",children:[(0,se.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,se.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(L),disabled:w<=0,children:a})]})]})]})})}var mm=[{id:"truss",title:"Roof Truss Calculator",desc:"Estimate trusses, girders and roof structure costs.",imageUrl:"/tool-images/truss.webp",Component:um},{id:"fencing",title:"Fencing Calculator",desc:"Estimate fence panels, posts, gravel boards and fixings.",imageUrl:"/tool-images/fencing.webp",Component:rm},{id:"decking",title:"Decking Calculator",desc:"Estimate boards, substructure and fixing quantities.",imageUrl:"/tool-images/decking.webp",Component:tm},{id:"brick-block",title:"Brick and Block Calculator",desc:"Estimate masonry units and ready-mixed mortar for a wall.",imageUrl:"/tool-images/brick-block.webp",Component:Id},{id:"paint",title:"Paint Calculator",desc:"Estimate paint for walls, doors and multiple coats.",imageUrl:"/tool-images/paint.webp",Component:im},{id:"skirting",title:"Skirting Board Calculator",desc:"Estimate skirting lengths for rooms and wall runs.",imageUrl:"/tool-images/skirting.webp",Component:pm},{id:"architrave",title:"Architrave Calculator",desc:"Estimate architrave lengths for door and window openings.",imageUrl:"/tool-images/architrave.webp",Component:Jd},{id:"concrete-aggregate",title:"Concrete and Aggregate Calculator",desc:"Estimate concrete, MOT, sand and gravel quantities.",imageUrl:"/tool-images/concrete-aggregate.webp",Component:Wd},{id:"plasterboard",title:"Plasterboard Calculator",desc:"Estimate plasterboard sheets, screws, tape and adhesive.",imageUrl:"/tool-images/plasterboard.webp",Component:cm},{id:"insulation",title:"Insulation Calculator",desc:"Estimate insulation packs for floors, walls, roofs and lofts.",imageUrl:"/tool-images/insulation.webp",Component:nm},{id:"timber",title:"Timber Calculator",desc:"Estimate studs, joists and battens from spacing and lengths.",imageUrl:"/tool-images/timber.webp",Component:dm},{id:"paving",title:"Paving and Driveway Calculator",desc:"Estimate paving, block paving, MOT and sharp sand.",imageUrl:"/tool-images/paving.webp",Component:lm}];var fm=$(Ve());var zx=new Set(["bag","box","roll","pack"]),Rx=new Set(["each","bag","box","roll","pack","tub"]);function gl(e,t){let r=(t?.conversion?.request_uoms_supported??"").split(",").map(o=>o.trim().toLowerCase()).includes("sales_unit");if(e==="each"){let o=(t?.uoi_count??1)===1&&(t?.conversion?.sales_unit_size??1)===1;return r&&o?"sales_unit":e}if(!zx.has(e))return e;if(r)return"sales_unit";let n=t?.uoi;return n!=null&&Rx.has(n.toLowerCase())&&(t?.uoi_count??1)===1?n:e}var l0=new Map;function Ax(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 zn(e,t,a=12,r){let n=`${Dt().client??""}||${e}||${t??""}||${a}||${r??""}`,i=l0.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(Ma(`/api/catalogue/search?${o.toString()}`),{headers:wn()}),c=await Ga(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(Ax):[];return l0.set(n,p),p}async function s0(e,t,a){return await Promise.all(e.map(async n=>{try{let i=a?dl(a,n):null,[o,l]=await Promise.all([i?zn(i,void 0,void 0,t).then(p=>p.find(m=>m.product_id===i.split(" ")[0]),()=>{}):void 0,zn(n.query,n.category,void 0,t)]),c=o?[o,...l.filter(p=>p.product_id!==o.product_id)]:l;return{requirement:n,candidates:c}}catch{return{requirement:n,candidates:[]}}}))}async function c0(){let e=await fetch(Ma("/api/catalogue"),{headers:wn()});if(!e.ok)return{itemCount:0,uploadedAt:null};let t=await Ga(e);return{itemCount:Number(t?.itemCount)||0,uploadedAt:t?.uploadedAt??null}}var ea=$(ee()),Ux=1500;function u0(e){let{addManyToCart:t,clearCart:a,openBasket:r}=Di(),[n,i]=(0,fm.useState)(!1),[o,l]=(0,fm.useState)(null);return{adding:n,basketError:o,addToBasket:async(p,m)=>{let f=Date.now();i(!0),l(null);try{let d=await Promise.all(p.filter(w=>w.qty>0).map(async w=>{let A=(await zn(w.search)).find(L=>L.product_id===w.productId);if(!A)throw new Error("A selected product is no longer available in this catalogue.");return Oi(A,{lineId:`${e}:${w.key}`,description:A.description,unit:gl(w.unit??"each",A),qty:w.qty,calculatorWasteIncluded:m})})),g=Ux-(Date.now()-f);g>0&&await new Promise(w=>window.setTimeout(w,g)),a(),t(d),r()}catch(d){l(d instanceof Error?d.message:"Could not add the products to your basket.")}finally{i(!1)}}}}function p0({toolTitle:e}){return(0,ea.jsx)(ea.Fragment,{children:(0,ea.jsxs)("div",{className:"truss-estimator",children:[(0,ea.jsxs)("div",{className:"quick-order-hero",children:[(0,ea.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ea.jsx)("h1",{children:"Your Materials"}),(0,ea.jsxs)("p",{children:["Calculating quantities from the ",e,"."]})]}),(0,ea.jsx)("div",{className:"truss-estimator__card",children:(0,ea.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,ea.jsx)(vn,{}),(0,ea.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})})}var Nc=$(Ve());var je=$(Ve());var q=$(ee()),Dx=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}],hm={wasteFactorEnabled:!0},Ox=3e3,d0=null;function Sc(e,t){let a=ol(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function Bx(e){return e&&e.length>0?e.join(" x "):"-"}function gm({toolId:e,requirements:t,ready:a,onBack:r,onTotalChange:n}){let i=xv(),o=`${e}~${t.map(N=>`${N.key}|${N.query}|${N.category??""}|${N.qty}`).join("~")}`,l=o!==d0,[c,p]=(0,je.useState)(null),[m,f]=(0,je.useState)([]),[d,g]=(0,je.useState)(l),[w,A]=(0,je.useState)(null),[L,h]=(0,je.useState)("tile"),[u,b]=(0,je.useState)(null),[v,_]=(0,je.useState)(""),[C,R]=(0,je.useState)(null),[T,D]=(0,je.useState)(""),[V,oe]=(0,je.useState)([]),[_e,Te]=(0,je.useState)(new Set),[Oe,xe]=(0,je.useState)(null),[X,J]=(0,je.useState)(""),[ze,Ee]=(0,je.useState)([]),wt=(0,je.useRef)(null),P=(0,je.useRef)(!1),pe=N=>`${e}:${N}`,Re=N=>Oi(N.chosen,{lineId:pe(N.requirement.key),description:N.requirement.label,unit:gl(N.requirement.unit,N.chosen),qty:N.requirement.qty}),Ot=(0,je.useMemo)(()=>t.map(N=>`${N.key}|${N.query}|${N.category??""}`).join("~"),[t]);(0,je.useEffect)(()=>{let N=!1;return c0().then(G=>{N||p(G.itemCount>0)}).catch(()=>{N||p(!1)}),()=>{N=!0}},[]),(0,je.useEffect)(()=>{if(!a||!c)return;let N=!1,G;l&&g(!0),A(null);let Y=Date.now();return(async()=>{let ce=null;try{ce=(await s0(t,void 0,e)).map(({requirement:yt,candidates:ft})=>({requirement:yt,candidates:ft,chosen:ft[0]??null}))}catch(Se){N||A(Se instanceof Error?Se.message:"Could not load products")}if(!N){if(d0=o,l){let Se=Ox-(Date.now()-Y);Se>0&&await new Promise(yt=>{G=window.setTimeout(yt,Se)})}N||(ce&&(f(ce),!P.current&&i&&(P.current=!0,i.addManyToCart(ce.filter(Se=>Se.chosen).map(Re)))),g(!1))}})(),()=>{N=!0,window.clearTimeout(G)}},[a,c,Ot]),(0,je.useEffect)(()=>{if(!C)return;let N=T.trim();if(!N){oe([]);return}let G=!1,Y=window.setTimeout(()=>{zn(N).then(ce=>{G||oe(ce)}).catch(()=>{G||oe([])})},250);return()=>{G=!0,window.clearTimeout(Y)}},[C,T]),(0,je.useEffect)(()=>{if(!Oe)return;let N=X.trim();if(!N){Ee([]);return}let G=!1,Y=window.setTimeout(()=>{zn(N).then(ce=>{G||Ee(ce)}).catch(()=>{G||Ee([])})},250);return()=>{G=!0,window.clearTimeout(Y)}},[Oe,X]);let jt=(0,je.useMemo)(()=>{let N=v.trim().toLowerCase(),G=N?m.filter(Y=>Y.requirement.label.toLowerCase().includes(N)||(Y.chosen?.description??"").toLowerCase().includes(N)||(Y.chosen?.product_id??"").toLowerCase().includes(N)):m;return u?[...G].sort((Y,ce)=>{let Se=Y.requirement.label.localeCompare(ce.requirement.label);return u==="asc"?Se:-Se}):G},[m,v,u]),qe=jt.filter(N=>N.chosen),ke=jt.filter(N=>!N.chosen),Be=m.filter(N=>N.chosen),Ye=Be.filter(N=>N.chosen?.price==null).length,vt=Be.reduce((N,G)=>N+(Ft(Re(G),hm).lineTotal??0),0);if((0,je.useEffect)(()=>{n?.(vt)},[vt,n]),!a||c===!1)return null;let z=i?Be.filter(N=>i.cart[pe(N.requirement.key)]).length:0,H=Oe?m.find(N=>N.requirement.key===Oe)??null:null,de=X.trim()?ze:H?.candidates??[],me=N=>{let G=C===N.requirement.key;R(G?null:N.requirement.key),D(G?"":N.requirement.query)},$e=(N,G)=>{let Y=m.find(ce=>ce.requirement.key===N);f(ce=>ce.map(Se=>Se.requirement.key===N?{...Se,chosen:G}:Se)),i&&Y&&i.cart[pe(N)]&&i.addToCart(Re({...Y,chosen:G})),R(null),D("")},Le=N=>{f(G=>G.map(Y=>Y.requirement.key===N?{...Y,chosen:null}:Y)),i?.cart[pe(N)]&&i.removeFromCart(pe(N))},k=N=>{xe(N.requirement.key),J(""),Ee([])},x=()=>{xe(null),J(""),Ee([])},E=N=>{if(!i)return;let G=pe(N.requirement.key);i.cart[G]?i.removeFromCart(G):i.addToCart(Re(N))},U=N=>{Te(G=>{let Y=new Set(G);return Y.has(N)?Y.delete(N):Y.add(N),Y})},Z=N=>{let G=V.length>0?V:N.candidates;return(0,q.jsxs)("div",{className:"estimator-products__picker",children:[(0,q.jsx)("input",{type:"text",className:"results-search-input",value:T,autoFocus:!0,placeholder:"Search products in catalogue...",onChange:Y=>D(Y.target.value),"aria-label":`Search a product for ${N.requirement.label}`}),(0,q.jsxs)("div",{className:"estimator-products__options",children:[G.map(Y=>(0,q.jsxs)("button",{type:"button",className:`estimator-products__option${Y.product_id===N.chosen?.product_id?" is-selected":""}`,onClick:()=>$e(N.requirement.key,Y),children:[(0,q.jsx)("span",{children:Y.description}),(0,q.jsxs)("span",{className:"results-row-meta",children:[Y.product_id,Y.price!=null&&` \xB7 ${ot(Y.price)}`]})]},Y.product_id)),G.length===0&&(0,q.jsx)("p",{className:"results-empty-hint",children:"No matching products."})]})]})};return(0,q.jsxs)("section",{className:"estimator-products results-tile-section","aria-label":"Matched products",children:[!d&&(0,q.jsxs)("div",{className:"estimator-products__head",children:[(0,q.jsxs)("div",{className:"results-tile-section__head",children:[(0,q.jsx)("h3",{children:"Matched Products"}),(0,q.jsx)("p",{children:"Products matched to your estimate, check before adding to your basket."})]}),!H&&(0,q.jsx)("div",{className:"results-summary estimator-products__toolbar",children:(0,q.jsxs)("div",{className:"estimator-products__controls",children:[(0,q.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:v,onChange:N=>_(N.target.value),"aria-label":"Search matched products"}),(0,q.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,q.jsx)("button",{type:"button",className:`results-view-toggle__btn${L==="tile"?" is-active":""}`,"aria-pressed":L==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>h("tile"),children:(0,q.jsxs)("svg",{width:"18",height:"12",viewBox:"0 0 15 10",fill:"currentColor",children:[(0,q.jsx)("rect",{x:"0.5",y:"0.5",width:"4",height:"4"}),(0,q.jsx)("rect",{x:"5.5",y:"0.5",width:"4",height:"4"}),(0,q.jsx)("rect",{x:"10.5",y:"0.5",width:"4",height:"4"}),(0,q.jsx)("rect",{x:"0.5",y:"5.5",width:"4",height:"4"}),(0,q.jsx)("rect",{x:"5.5",y:"5.5",width:"4",height:"4"}),(0,q.jsx)("rect",{x:"10.5",y:"5.5",width:"4",height:"4"})]})}),(0,q.jsx)("button",{type:"button",className:`results-view-toggle__btn${L==="list"?" is-active":""}`,"aria-pressed":L==="list","aria-label":"List view",title:"List view",onClick:()=>h("list"),children:(0,q.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,q.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,q.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,q.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),(0,q.jsxs)("details",{ref:wt,style:{position:"relative"},children:[(0,q.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort materials",style:{fontSize:16},children:"\u21C5"}),(0,q.jsx)("div",{className:"sort-menu-panel",children:Dx.map(N=>{let G=u===N.dir;return(0,q.jsxs)("button",{type:"button",className:`sort-menu-item${G?" is-active":""}`,onClick:()=>{b(G?null:N.dir),wt.current?.removeAttribute("open")},children:[(0,q.jsx)("span",{className:"sort-menu-item__check",children:G?"\u2713":""}),N.label]},N.dir)})})]})]})})]}),H&&(0,q.jsxs)("div",{className:"results-review-page",children:[(0,q.jsxs)("div",{className:"results-review-page__top",children:[(0,q.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:x,children:[(0,q.jsx)(Vr,{}),"Back to results"]}),(0,q.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,q.jsx)("div",{className:"results-review-searchbar",children:(0,q.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:X,onChange:N=>J(N.target.value),"aria-label":`Search a product for ${H.requirement.label}`})}),H.chosen&&(0,q.jsx)("div",{className:"results-candidate-actions",children:(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Le(H.requirement.key),children:"Clear selected product"})})]})]}),(0,q.jsxs)("div",{className:"results-review-page__hero",children:[(0,q.jsx)("div",{className:"results-review-page__image-wrap",children:(0,q.jsx)(za,{className:"fill-img results-review-page__image",description:H.chosen?.description||H.requirement.label,photoUrl:H.chosen?.pdp_photo_url})}),(0,q.jsxs)("div",{className:"results-review-page__summary",children:[(0,q.jsx)("h2",{children:H.requirement.label}),(0,q.jsxs)("p",{className:"results-review-page__meta",children:[yn(H.requirement.qty)," ",xa(H.requirement.unit,H.requirement.qty)]}),H.chosen?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)("div",{className:"results-review-page__product",children:H.chosen.description}),(0,q.jsxs)("div",{className:"results-row-meta",children:[H.chosen.product_id,H.chosen.price!=null?` \xB7 ${Sc(H.chosen.price,H.chosen.price_basis)}`:""]})]}):(0,q.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line."}),(0,q.jsx)("div",{className:"results-review-page__actions",children:(0,q.jsx)("button",{type:"button",className:`bom-toolbar-btn${i?.cart[pe(H.requirement.key)]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(H),disabled:!H.chosen||!i,children:i?.cart[pe(H.requirement.key)]?"\u2713 Added":"+ Add to basket"})})]})]}),de.length===0?(0,q.jsx)("p",{className:"results-empty-hint",children:"No matching products."}):(0,q.jsxs)("table",{className:"score-breakdown-table",children:[(0,q.jsx)("thead",{children:(0,q.jsxs)("tr",{children:[(0,q.jsx)("th",{children:"Product"}),(0,q.jsx)("th",{children:"Dims (mm)"}),(0,q.jsx)("th",{children:"Price"}),(0,q.jsx)("th",{"aria-label":"Actions"})]})}),(0,q.jsx)("tbody",{children:de.map(N=>{let G=N.product_id===H.chosen?.product_id;return(0,q.jsxs)("tr",{className:G?"score-breakdown-row--best":"",children:[(0,q.jsxs)("td",{children:[(0,q.jsx)("div",{children:N.description}),(0,q.jsx)("div",{className:"results-row-meta",children:N.product_id})]}),(0,q.jsx)("td",{children:(0,q.jsx)("span",{className:"unit-badge",children:Bx(N.measurements_mm)})}),(0,q.jsx)("td",{children:N.price!=null?Sc(N.price,N.price_basis):"-"}),(0,q.jsx)("td",{children:(0,q.jsxs)("label",{className:"switch-toggle",title:G?"Currently selected":"Use this candidate",children:[(0,q.jsx)("input",{type:"checkbox",checked:G,onChange:()=>{G?Le(H.requirement.key):$e(H.requirement.key,N)},"aria-label":G?`${N.description} selected`:`Use ${N.description}`}),(0,q.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},N.product_id)})})]})]}),!H&&d&&(0,q.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{padding:"32px 24px"},children:[(0,q.jsx)(vn,{}),(0,q.jsx)("p",{className:"banter-message is-visible",style:{fontSize:15,minHeight:0},children:"Matching your materials against the catalogue\u2026"})]}),!H&&w&&(0,q.jsx)("p",{className:"results-empty-hint estimator-products__error",children:w}),!H&&!d&&!w&&jt.length===0&&m.length>0&&(0,q.jsx)("p",{className:"results-empty-hint",children:"No materials match the current search."}),!H&&!d&&!w&&L==="tile"&&qe.length>0&&(0,q.jsx)("div",{className:"results-tile-grid",children:qe.map(N=>{let{requirement:G,chosen:Y}=N,ce=Y?Ft(Re(N),hm):null,Se=i?!!i.cart[pe(G.key)]:!1;return(0,q.jsxs)("article",{className:"results-tile-card",children:[(0,q.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>k(N),"aria-label":`Review match for ${G.label}`,children:[(0,q.jsx)("div",{className:"results-tile-card__media",children:(0,q.jsx)(za,{className:"fill-img results-tile-card__image",description:Y?.description||G.label,photoUrl:Y?.pdp_photo_url})}),(0,q.jsxs)("div",{className:"results-tile-card__body",children:[Y?(0,q.jsxs)("div",{className:"results-tile-card__heading",children:[(0,q.jsx)("div",{className:"results-tile-card__title",children:Y.description}),(0,q.jsxs)("div",{className:"results-tile-card__match-meta",children:[(0,q.jsx)("span",{children:Y.product_id}),Y.price!=null?(0,q.jsx)("span",{children:Sc(Y.price,Y.price_basis)}):null]})]}):(0,q.jsx)("div",{className:"results-empty-hint",children:"No product matched for this line."}),(0,q.jsxs)("div",{className:"results-tile-card__match",children:[(0,q.jsx)("div",{className:"results-tile-card__match-label",children:"\u21B3 calculated as"}),(0,q.jsx)("div",{className:"results-tile-card__match-name",children:G.label}),(0,q.jsxs)("div",{className:"results-tile-card__meta",children:[yn(G.qty)," ",xa(G.unit,G.qty)]}),ce?.requiredSellUnits!=null?(0,q.jsxs)("div",{className:"results-tile-card__meta estimator-products__order",children:["Order ",ce.requiredSellUnits," ",ce.sellUnit,ce.lineTotal!=null?` \xB7 ${ot(ce.lineTotal)}`:""]}):Y?(0,q.jsx)("div",{className:"results-row-meta",children:"Quantity needs review"}):null]})]})]}),(0,q.jsxs)("div",{className:"results-tile-card__actions",children:[(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>k(N),children:"Review"}),(0,q.jsx)("button",{type:"button",className:`bom-toolbar-btn${Se?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(N),disabled:!Y||!i,children:Se?"\u2713 Added":"+ Add"})]})]},G.key)})}),!H&&!d&&!w&&L==="list"&&qe.length>0&&(0,q.jsx)("div",{className:"bom-table-wrap",children:(0,q.jsxs)("table",{className:"bom-table results-table","aria-label":"Matched materials",children:[(0,q.jsxs)("colgroup",{children:[(0,q.jsx)("col",{style:{width:"56px"}}),(0,q.jsx)("col",{className:"col-item"}),(0,q.jsx)("col",{style:{width:"90px"}}),(0,q.jsx)("col",{style:{width:"80px"}}),(0,q.jsx)("col",{style:{width:"220px"}}),(0,q.jsx)("col",{style:{width:"110px"}})]}),(0,q.jsx)("thead",{children:(0,q.jsxs)("tr",{className:"bom-col-header",children:[(0,q.jsx)("th",{"aria-label":"Expand"}),(0,q.jsx)("th",{style:{textAlign:"left"},children:"Description"}),(0,q.jsx)("th",{style:{textAlign:"center"},children:"Qty"}),(0,q.jsx)("th",{style:{textAlign:"center"},children:"Unit"}),(0,q.jsx)("th",{style:{textAlign:"center"},children:"Product Matched"}),(0,q.jsx)("th",{style:{textAlign:"center"},children:"Basket"})]})}),(0,q.jsx)("tbody",{children:qe.map(N=>{let{requirement:G,chosen:Y}=N,ce=Y?Ft(Re(N),hm):null,Se=i?!!i.cart[pe(G.key)]:!1,yt=_e.has(G.key);return(0,q.jsxs)(je.Fragment,{children:[(0,q.jsxs)("tr",{className:"bom-row",children:[(0,q.jsx)("td",{className:"bom-actions",style:{textAlign:"center",paddingLeft:0,paddingRight:0},children:(0,q.jsx)("button",{type:"button",className:"link-btn",onClick:()=>U(G.key),"aria-expanded":yt,"aria-label":yt?"Collapse product options":"Expand product options",children:yt?"\u25BE":"\u25B8"})}),(0,q.jsxs)("td",{style:{paddingLeft:0},children:[(0,q.jsx)("div",{className:"bom-component-name",children:G.label}),ce?.requiredSellUnits!=null&&(0,q.jsxs)("div",{className:"results-row-meta",children:["Order ",ce.requiredSellUnits," ",ce.sellUnit,ce.lineTotal!=null?` \xB7 ${ot(ce.lineTotal)}`:""]})]}),(0,q.jsx)("td",{className:"bom-qty col-order",style:{textAlign:"center"},children:yn(G.qty)}),(0,q.jsx)("td",{style:{textAlign:"center"},children:xa(G.unit,G.qty)}),(0,q.jsx)("td",{style:{textAlign:"center"},children:Y?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)("div",{className:"bom-component-name",children:Y.description}),(0,q.jsxs)("div",{className:"results-row-meta",children:[Y.product_id,Y.price!=null&&` \xB7 ${Sc(Y.price,Y.price_basis)}`]})]}):(0,q.jsx)("span",{className:"results-empty-hint",children:"No match"})}),(0,q.jsx)("td",{style:{textAlign:"center"},children:(0,q.jsx)("button",{type:"button",className:`bom-toolbar-btn${Se?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(N),disabled:!Y||!i,children:Se?"\u2713 Added":"+ Add"})})]}),yt&&(0,q.jsx)("tr",{children:(0,q.jsx)("td",{colSpan:6,style:{paddingLeft:0,paddingRight:0},children:C===G.key?Z(N):(0,q.jsxs)("div",{className:"estimator-products__picker",children:[(0,q.jsxs)("div",{className:"estimator-products__options",children:[N.candidates.map(ft=>(0,q.jsxs)("button",{type:"button",className:`estimator-products__option${ft.product_id===Y?.product_id?" is-selected":""}`,onClick:()=>$e(G.key,ft),children:[(0,q.jsx)("span",{children:ft.description}),(0,q.jsxs)("span",{className:"results-row-meta",children:[ft.product_id,ft.price!=null&&` \xB7 ${ot(ft.price)}`]})]},ft.product_id)),N.candidates.length===0&&(0,q.jsx)("p",{className:"results-empty-hint",children:"No candidates found."})]}),(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>me(N),children:"Search the catalogue"})]})})})]},G.key)})})]})}),!H&&!d&&!w&&ke.length>0&&(0,q.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,q.jsxs)("div",{className:"results-tile-section__head",children:[(0,q.jsx)("h3",{children:"Require Matching"}),(0,q.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,q.jsx)("div",{className:"results-unmatched-list",children:ke.map(N=>(0,q.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>k(N),children:[(0,q.jsxs)("span",{className:"results-unmatched-card__main",children:[(0,q.jsx)("span",{className:"results-unmatched-card__title",children:N.requirement.label}),(0,q.jsxs)("span",{className:"results-row-meta",children:[yn(N.requirement.qty)," ",xa(N.requirement.unit,N.requirement.qty)]})]}),(0,q.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},N.requirement.key))})]}),!d&&!w&&m.length>0&&(0,q.jsxs)("div",{className:"disclaimer-box",style:{alignItems:"center"},children:[(0,q.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,q.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."})]}),!H&&!d&&!w&&(r||z>0)&&(0,q.jsxs)("div",{className:"btn-row estimator-products__footer",children:[r&&(0,q.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:r,children:"Back"}),z>0&&i&&(0,q.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:r?"0 1 70%":1,marginTop:0},onClick:i.openBasket,children:[(0,q.jsxs)("span",{children:["View Basket (",z,")"]}),(0,q.jsx)("span",{className:"arrow",children:(0,q.jsx)(Qt,{})})]})]})]})}var Gt=$(ee());function bm({toolId:e,toolTitle:t,requirements:a,onBack:r}){let[n,i]=(0,Nc.useState)(0),o=(0,Nc.useCallback)(l=>i(l),[]);return(0,Gt.jsx)(Gt.Fragment,{children:(0,Gt.jsxs)("div",{className:"truss-estimator",children:[(0,Gt.jsxs)("div",{className:"quick-order-hero",children:[(0,Gt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Gt.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,Gt.jsx)("h1",{children:"Your Materials"}),n>0&&(0,Gt.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,Gt.jsx)("strong",{children:ot(n)})," Est. total"]})]}),(0,Gt.jsxs)("p",{children:["Quantities from the ",t,", matched against your merchant\u2019s catalogue."]})]}),(0,Gt.jsx)("div",{className:"truss-estimator__card",style:{minHeight:0},children:(0,Gt.jsx)(gm,{toolId:e,requirements:a,ready:!0,onBack:r,onTotalChange:o})})]})})}var Ae=$(ee());function Cc(e){let[t,a]=(0,Va.useState)(!1);return(0,Ae.jsx)(lc,{onOpenBasket:()=>a(!0),children:(0,Ae.jsx)(Lx,{...e,showBasket:t,onShowBasket:a})})}function Lx({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=mm.find(T=>T.id===i),{cart:m,updateCartQty:f,updateCartSellUnits:d,updateCartConversions:g,removeFromCart:w,clearCart:A}=Di(),{adding:L,basketError:h,addToBasket:u}=u0(p?.title??"calculator"),b=(0,Va.useRef)(null),v=Js("estimating-tools",b);(0,Va.useEffect)(()=>{v("viewed")},[v]);let _=r?"basket":L?"adding":l?"review":i??"list",C=(0,Va.useRef)(_);(0,Va.useEffect)(()=>{C.current!==_&&(C.current=_,window.scrollTo(0,0))},[_]);let R=T=>{if(!p)return;v("estimate_completed",{calculator:p.id,lines:T.length});let D=Qv(p.id,T);D?u(D,T[0]?.calculatorWasteIncluded??!1):c(T)};return(0,Ae.jsx)(tl.Provider,{value:v,children:(0,Ae.jsx)("div",{ref:b,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${a?"":" estimating-tools--customer"}`,style:Dt().theme,children:(0,Ae.jsx)("main",{className:"main-content",children:r?(0,Ae.jsx)(ul,{cart:m,onUpdateQty:f,onUpdateSellUnits:d,onResolveConversions:g,onRemove:w,onBack:()=>n(!1),onStartNewQuote:()=>{A(),o(null),c(null),n(!1)},internal:a}):L&&p?(0,Ae.jsx)(p0,{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:R})}),h&&(0,Ae.jsx)("p",{className:"results-empty-hint estimator-products__error",children:h}),l!==null&&(0,Ae.jsx)(bm,{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:mm.map(T=>(0,Ae.jsxs)("button",{type:"button",className:"estimator-tool-card",onClick:()=>{v("calculator_selected",{calculator:T.id}),o(T.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:It(T.imageUrl),alt:""})}),(0,Ae.jsxs)("span",{className:"estimator-tool-card__content",children:[(0,Ae.jsx)("span",{className:"estimator-tool-card__title",children:T.title}),(0,Ae.jsx)("span",{className:"estimator-tool-card__desc",children:T.desc})]})]},T.id))})]})]})})})})})}var qc=$(ee());function wm({config:e,children:t}){return xw(e),(0,qc.jsx)(qc.Fragment,{children:t})}var vm=$(ee()),Hx="https://api.metronlabs.ai",Qx=["client","api-key","api-url","theme","hide-header","analytics"],Gx=["all","events-only","none"];function f0(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.76",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; }
|
|
6974
|
+
C24 timber 4.8m`,value:d,onChange:P=>g(P.target.value),"aria-label":"Paste schedule line items"}),(D||L)&&(0,F.jsxs)("div",{className:"error-box",role:"alert",children:[(0,F.jsx)("strong",{children:"Error:"})," ",D||L]}),(0,F.jsxs)("div",{className:"quick-order-hint",children:[(0,F.jsx)("strong",{children:"Tip:"}),'\xA0Paste one line per item. Include a count, e.g. "x10", to help us find the right stock and pricing.']}),(0,F.jsx)("div",{className:"quick-order-actions",children:(0,F.jsxs)("button",{type:"button",className:"cta-btn",disabled:!T||!!D,onClick:()=>{l("list_submitted",{method:"paste",lines:T}),xe(()=>e(d))},"aria-label":"Match pasted lines",children:[(0,F.jsx)("span",{children:"Match line items"}),(0,F.jsx)("span",{className:"arrow",children:(0,F.jsx)(Qt,{})})]})})]}):(0,F.jsxs)(F.Fragment,{children:[L&&(0,F.jsxs)("div",{className:"error-box",role:"alert",children:[(0,F.jsx)("strong",{children:"Error:"})," ",L]}),(0,F.jsxs)("div",{className:`upload-zone${w?" has-file":""}`,onClick:()=>o.current?.click(),onDragOver:P=>P.preventDefault(),onDrop:wt,role:"button",tabIndex:0,onKeyDown:P=>(P.key==="Enter"||P.key===" ")&&o.current?.click(),"aria-label":"Upload zone: click or drag a list or image file here",children:[C?(0,F.jsx)("img",{src:C,alt:w?.name??"Selected photo",className:"upload-zone-photo-preview"}):(0,F.jsx)("div",{className:"upload-zone-icon",children:(0,F.jsxs)("svg",{viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,F.jsx)("path",{d:"M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"}),(0,F.jsx)("polyline",{points:"14,2 14,8 20,8"}),(0,F.jsx)("polyline",{points:"9,15 11,17 15,13"})]})}),w?(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)("div",{className:"upload-zone-subtext",children:w.name}),(0,F.jsx)("button",{type:"button",className:"link-btn link-btn--underline",onClick:P=>{P.stopPropagation(),A(null),h(""),o.current&&(o.current.value="")},children:"Remove"})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsx)("div",{className:"upload-zone-text",children:"Drop a photo, spreadsheet, Word document or PDF"}),(0,F.jsx)("div",{className:"upload-zone-subtext",children:"or click to choose a file"})]}),(0,F.jsx)("input",{ref:o,type:"file",accept:M_,className:"visually-hidden",onChange:P=>Oe(P.target.files),tabIndex:-1,"aria-hidden":"true"})]}),(0,F.jsx)("div",{className:"quick-order-actions",children:(0,F.jsxs)("button",{type:"button",className:"cta-btn",disabled:!w,onClick:()=>{X()},"aria-label":"Match uploaded items",children:[(0,F.jsx)("span",{children:"Match items"}),(0,F.jsx)("span",{className:"arrow",children:(0,F.jsx)(Qt,{})})]})})]})}),(0,F.jsx)("aside",{className:"quick-order-sidebar",children:T_[m].map((P,pe)=>(0,F.jsxs)("div",{className:"quick-order-step quick-order-step--rail",children:[(0,F.jsx)("span",{className:"quick-order-step-dot",children:pe+1}),(0,F.jsxs)("div",{children:[(0,F.jsx)("div",{className:"quick-order-step-title",children:P.title}),(0,F.jsx)("div",{className:"quick-order-step-desc",children:P.desc})]})]},P.title))})]}),u&&(0,F.jsx)("div",{className:"quick-order-matching-overlay",children:(0,F.jsx)(wv,{})})]})]})})]})]})}var zt=$(Ve()),kv=$(ee());function Ui(e){return JSON.stringify([e.productId,e.qty,e.unit,e.linkedContext??[]])}function z_(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 qd=(0,zt.createContext)(null);function lc({children:e,onOpenBasket:t}){let[a,r]=(0,zt.useState)({}),n=(0,zt.useCallback)(d=>{r(g=>z_(g,d))},[]),i=(0,zt.useCallback)(d=>{r(g=>{let w={...g};for(let A of d)w[A.lineId]=A;return w})},[]),o=(0,zt.useCallback)(d=>{r(g=>{let w={...g};return delete w[d],w})},[]),l=(0,zt.useCallback)((d,g)=>{r(w=>w[d]?{...w,[d]:{...w[d],qty:g,sellUnitsOverride:null}}:w)},[]),c=(0,zt.useCallback)((d,g)=>{r(w=>w[d]?{...w,[d]:{...w[d],sellUnitsOverride:g}}:w)},[]),p=(0,zt.useCallback)(d=>{r(g=>{let w=!1,A={...g};for(let[L,h]of Object.entries(d))A[L]&&(A[L]={...A[L],...h},w=!0);return w?A:g})},[]),m=(0,zt.useCallback)(()=>r({}),[]),f=(0,zt.useMemo)(()=>({cart:a,count:Object.keys(a).length,addToCart:n,addManyToCart:i,removeFromCart:o,updateCartQty:l,updateCartSellUnits:c,updateCartConversions:p,clearCart:m,openBasket:t??(()=>{})}),[a,n,i,o,l,c,p,m,t]);return(0,kv.jsx)(qd.Provider,{value:f,children:e})}function Di(){let e=(0,zt.useContext)(qd);if(!e)throw new Error("useCart must be used inside a <CartProvider>");return e}function xv(){return(0,zt.useContext)(qd)}var mt=$(Ve());function yn(e){return e===0?"-":Number.isInteger(e)?e.toString():e<1?e.toFixed(2):e.toFixed(1)}function ot(e){return`\xA3${e.toLocaleString("en-GB",{minimumFractionDigits:2,maximumFractionDigits:2})}`}var qv=e=>(e??"").trim().toLowerCase(),R_={sqm:"m2","sq m":"m2","m\xB2":"m2",cbm:"m3","cu m":"m3","m\xB3":"m3",lm:"m","lin m":"m","linear metre":"m","linear metres":"m","linear meter":"m","linear meters":"m",metre:"m",metres:"m",meter:"m",meters:"m",litre:"l",litres:"l",liter:"l",liters:"l",ltr:"l",ltrs:"l",rolls:"roll",coils:"coil",each:"each",ea:"each",nr:"each",no:"each",item:"each",unit:"each",units:"each",pc:"each",pcs:"each",piece:"each",pieces:"each",board:"sheet",bags:"bag",length:"length",lengths:"length",pallet:"pallet",pallets:"pallet"},Ed=new Set(["sheet","length","box","bag","pack","roll","set","tub","each"]),Md=new Set(["box","bag","pack","pallet","roll","set","tub"]),A_=new Set(["roll","coil"]),Td=(e,t)=>t==="ml"?e:["l","litre","litres"].includes(t)?e*1e3:null,zd=(e,t)=>t==="g"?e:["kg","kilogram","kilograms"].includes(t)?e*1e3:["t","tonne","tonnes"].includes(t)?e*1e6:null,Ta=e=>{let t=qv(e);return R_[t]??t},Sv=e=>{let t=Ta(e);return t==="ml"?{dimension:"volume",toBase:1}:t==="l"?{dimension:"volume",toBase:1e3}:t==="m3"?{dimension:"volume",toBase:1e6}:t==="g"?{dimension:"mass",toBase:1}:t==="kg"?{dimension:"mass",toBase:1e3}:t==="t"||t==="tonne"||t==="tonnes"?{dimension:"mass",toBase:1e6}:t==="mm"?{dimension:"length",toBase:.001}:t==="cm"?{dimension:"length",toBase:.01}:t==="m"?{dimension:"length",toBase:1}:t==="ft"?{dimension:"length",toBase:.3048}:t==="in"||t==="inch"||t==="inches"?{dimension:"length",toBase:.0254}:null},Ad=(e,t,a)=>{if(tt(t,a))return e;let r=Sv(t),n=Sv(a);return r&&n&&r.dimension===n.dimension?e*r.toBase/n.toBase:null},tt=(e,t)=>{let a=Ta(e),r=Ta(t);return a.length>0&&a===r},Rd=(e,t)=>{let a=qv(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},U_=e=>(e??"").split(",").map(t=>Ta(t)).filter(Boolean),D_=(e,t)=>{let a=U_(e.requestUomsSupported);return!!(a.length===0||a.includes(t)||e.unitConversions?.some(r=>Ad(1,t,r.requestUom)!=null)||tt(t,"pallet")&&e.itemsPerPallet!=null&&e.itemsPerPallet>0||tt(t,"pack")&&e.itemsPerPack!=null&&e.itemsPerPack>0||tt(t,"box")&&e.itemsPerBox!=null&&e.itemsPerBox>0)},Nv=(e,t)=>tt(t,"pallet")?e.itemsPerPallet??null:tt(t,"pack")?e.itemsPerPack??null:tt(t,"box")?e.itemsPerBox??null:null,Cv=(e,t)=>{let a=t==="volume"?/(\d+(?:[.,]\d+)?)\s*(ml|l|ltr|ltrs|litres?|liters?)\b/i:/(\d+(?:[.,]\d+)?)\s*(kg|kgs|tonnes?)\b/i,r=e.description.match(a);if(!r)return null;let n=Number.parseFloat(r[1].replace(",","."));if(!Number.isFinite(n)||n<=0)return null;let i=r[2].toLowerCase();return t==="volume"?{ml:i==="ml"?n:n*1e3}:{g:i.startsWith("tonne")?n*1e6:n*1e3}},O_=["volume_from_description","same_unit_volume"],B_=["weight_from_description","mass_from_pack","same_unit_mass"],L_=(e,t,a)=>{if(!tt(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||!tt(r[3],a))return null;let n=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(n)&&n>0?n:null},Ev=(e,t)=>t.costingMode==="review"&&!(["llm_basket_line","rule_based_pallet_quantity"].includes(e.conversionConfidence??"")&&e.sellUnitsOverride!=null&&!e.conversionNotes?.trim());function sc(e,t){let a=e.map(r=>Ft(r,t).lineTotal);return a.some(r=>r==null)?null:a.reduce((r,n)=>r+(n??0),0)}function Ft(e,t){let a=H_(e,t);return a.sellUnit==="bag"&&a.requestedUnit!=="bag"&&/\bbulk bag\b/i.test(e.description)?{...a,sellUnit:"bulk bag"}:a}function H_(e,t){let a=e.qty,r=Ta(e.saleUnit??e.salesUnitSizeUom??e.uoi??e.salesUomNormalised)||"-",n=e.unitConversions?.find(X=>tt(X.requestUom,"each"))?.quantityPerSaleUnit,i=!Ta(e.unit)&&Md.has(r)&&n!=null&&n>1&&a>=n,o=Ta(e.unit)||(i?"each":a>0&&Ed.has(r)?r:"-"),l=e.saleUnitQuantity??e.salesUnitSize??e.uoiCount??1,c=t?.wasteFactorEnabled===!1?0:t?.wasteFactorOverride??e.wasteFactorOverride??e.wasteFactorDefault??0,p=e.sellUnitsOverride!=null&&Number.isFinite(e.sellUnitsOverride)&&e.sellUnitsOverride>0,m=p?Ed.has(r)?Math.ceil(e.sellUnitsOverride):e.sellUnitsOverride:null,f=X=>({requestedAmount:a,requestedUnit:o,salesUnitSize:e.salesUnitSize??e.uoiCount??null,sellUnit:r,calculatedSellUnits:null,requiredSellUnits:m,unitPrice:e.price,lineTotal:e.price!=null&&m!=null?e.price*m:null,calculation:m!=null?`${X} Order quantity set to ${m} ${r}.`:X,costingMode:"review"});if(!Number.isFinite(a)||a<=0)return f("Quantity needs confirmation.");let d=Td(a,o),g=zd(a,o),w=tt(o,r)?null:d!=null&&!O_.includes(e.conversionType??"")?Cv(e,"volume"):g!=null&&!B_.includes(e.conversionType??"")?Cv(e,"weight"):null,A=w?.ml!=null?d:g,L=w?.ml??w?.g??null;if(A!=null&&L!=null){let X=Ta(e.uoi)||r,J=w?.ml!=null?`${L/1e3} l`:`${L/1e3} kg`,ze=p?m:Math.ceil(A*(1+c)/L-1e-9);return{requestedAmount:a,requestedUnit:o,salesUnitSize:1,sellUnit:X,calculatedSellUnits:ze,requiredSellUnits:ze,unitPrice:e.price,lineTotal:e.price!=null?e.price*ze:null,calculation:`${a} ${o}${c>0?` x ${1+c}`:""} / ${J} per ${X} (from product description) = ${ze} ${X}`,costingMode:"derived"}}if(o==="sales_unit"){let X=Ta(e.uoi)||r,J=p?m:Rd(a*(1+c),e.roundingRule??"round_up_each");return{requestedAmount:a,requestedUnit:X,salesUnitSize:1,sellUnit:X,calculatedSellUnits:J,requiredSellUnits:J,unitPrice:e.price,lineTotal:e.price!=null?e.price*J:null,calculation:`${a} ${X}${c>0?` x ${1+c}`:""} = ${J} ${X}`,costingMode:"direct"}}let h=A_.has(o),u=/\b(?:pack|box)\s+of\s+(\d+)\s+(?:rolls?|coils?)\b|\b(\d+)\s+(?:rolls?|coils?)\s+(?:per|in each)\s+(?:pack|box)\b/i.test(e.description),b=r==="pack"?e.itemsPerPack:null,v=(e.derivedLengthM??0)>0||(e.derivedCoverageM2??0)>0||/^(?:m2|m²|sqm|m)\s*(?:per|\/)/i.test(e.coverageUom??"");if(h&&["each","pack"].includes(r)&&l===1&&!(b!=null&&b>1)&&!u&&v){let X=p?m:Rd(a*(1+c),e.roundingRule??"round_up_each");return{requestedAmount:a,requestedUnit:o,salesUnitSize:l,sellUnit:r,calculatedSellUnits:X,requiredSellUnits:X,unitPrice:e.price,lineTotal:e.price!=null?e.price*X:null,calculation:`${a} ${o}${c>0?` x ${1+c}`:""} = ${X} ${r} (one product per sale unit)`,costingMode:"derived"}}if(!D_(e,o))return f("Requested unit is not supported by this catalogue conversion.");let _=null,C="review",R=e.roundingRule,T=`Quantity review required, initial request needed ${a} ${o}.`,D=1+c,V=L_(e,o,r),oe=e.unitConversions?.find(X=>Ad(1,o,X.requestUom)!=null),_e=oe?Ad(a,o,oe.requestUom):null;if(!!e.saleUnit&&(tt(o,r)||!!oe||tt(o,"each")&&!Md.has(r)))if(tt(o,r))_=a*D/l,C="direct",T=`${a} ${o}${c>0?` x ${D}`:""}`;else if(oe&&_e!=null){_=_e*D/oe.quantityPerSaleUnit,C="derived";let X=1/oe.quantityPerSaleUnit,J=Math.round(X),ze=tt(r,"each")&&oe.quantityPerSaleUnit<1&&Math.abs(X-J)<1e-9,Ee=tt(o,oe.requestUom)?`${a} ${o}`:`${a} ${o} (${_e} ${oe.requestUom})`;T=ze?`${a} ${o}${c>0?` x ${D}`:""} x ${J} per ${o}`:`${Ee}${c>0?` x ${D}`:""} / ${oe.quantityPerSaleUnit} ${oe.requestUom} per ${r}`}else tt(o,"each")&&!Md.has(r)&&(_=a*D/l,C="derived",T=`${a} ${r}${c>0?` x ${D}`:""}`);else if(tt(o,r)&&l>0)_=a*D/l,C="direct",T=c>0?`${a} ${o} x ${D} / ${l} ${r} per sell unit`:`${a} ${o} / ${l} ${r} per sell unit`;else if(tt(o,"each")&&l>0&&Ed.has(r))_=a*D/l,C="derived",T=c>0?`${a} each x ${D} / ${l} each per ${r}`:`${a} each / ${l} each per ${r}`;else if(Nv(e,o)!=null&&l>0){let X=Nv(e,o)??0;_=a*X*D/l,C="derived";let J=`${a} ${o} x ${X} each${c>0?` x ${D}`:""}`;T=l===1&&tt(r,"each")?J:`${J} / ${l} each per ${r}`}else if(V!=null)_=a*D/V,C="derived",R??(R="round_up_each"),T=`${a} m2 x ${D} / ${V} m2 per ${r} (from product description)`;else if(e.conversionType==="basket_line_unit")l>0&&(_=a*D/l,C="derived",T=`${a} ${o}${c>0?` x ${D}`:""} / ${l} ${o} per ${r}`);else{if(e.conversionType==="count_only")return f(`Quantity review required, initial request needed ${a} ${o}.`);if(["area_from_dims","explicit_coverage_area","roll_area"].includes(e.conversionType??"")){let X=e.coverageQty??e.derivedCoverageM2??null;tt(o,"m2")&&X!=null&&X>0&&(_=a*D/X,C="derived",T=`${a} m2 x ${D} / ${X} m2 per ${r}`)}else if(e.conversionType==="count_per_area"){let X=e.coverageQty??null;tt(o,"m2")&&X!=null&&X>0?(_=a/X,C="derived",T=`${a} m2 / ${X} m2 per sell unit`):tt(o,"m2")&&e.itemsPerM2!=null&&e.itemsPerM2>0&&l>0&&(_=a*e.itemsPerM2*D/l,C="derived",T=`${a} m2 x ${e.itemsPerM2} ${r}/m2 x ${D} / ${l}`)}else if(e.conversionType==="length_from_dims"){let X=e.coverageQty??e.derivedLengthM??null;tt(o,"m")&&X!=null&&X>0&&(_=a*D/X,C="derived",T=`${a} m x ${D} / ${X} m per ${r}`)}else if(e.conversionType==="volume_from_description"){let X=Td(a,o),J=Td(e.coverageQty??0,Ta(e.coverageUom));X!=null&&J!=null&&J>0&&(_=X*D/J,C="derived",T=`${a} ${o} x ${D} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="weight_from_description"||e.conversionType==="mass_from_pack"){let X=Ta((e.coverageUom??"").split(" ")[0]),J=zd(a,o),ze=zd(e.coverageQty??0,X);J!=null&&ze!=null&&ze>0&&(_=J*D/ze,C="derived",T=`${a} ${o} x ${D} / ${e.coverageQty} ${X} per ${r}`)}else if(e.conversionType==="same_unit_volume"){let X=e.coverageQty??null;tt(o,"m3")&&X!=null&&X>0&&(_=a/X,C="derived",T=`${a} m3 / ${X} m3 per ${r}`)}}if(_==null||!Number.isFinite(_)||_<0)return f(`Quantity review required, initial request needed ${a} ${o}.`);let Oe=Rd(_,R),xe=p?m:Oe;return{requestedAmount:a,requestedUnit:o,salesUnitSize:l,sellUnit:r,calculatedSellUnits:Oe,requiredSellUnits:xe,unitPrice:e.price,lineTotal:e.price!=null&&xe!=null?e.price*xe:null,calculation:p?`${T} = ${Oe} ${r} (manually set to ${xe})`:`${T} = ${xe} ${r}`,costingMode:C}}var il=$(ee());function Ud({unit:e}){return(0,il.jsx)(il.Fragment,{children:e.split(/([²³])/).map((t,a)=>t==="\xB2"||t==="\xB3"?(0,il.jsx)("span",{className:"unit-sup",children:t},a):t)})}var Mv=$(ee());function Q_(e,t){return t===1||/^(m\d*|mm|cm|ml|kg|g)$/i.test(e)?e:/(s|x|z|ch|sh)$/i.test(e)?`${e}es`:/[^aeiou]y$/i.test(e)?`${e.slice(0,-1)}ies`:`${e}s`}function Wt(e,t){let a=(e??"").trim();if(!a||a==="-")return"";let r=/^each$/i.test(a)?"unit":/^l$/i.test(a)?"litre":a;return t!=null?Q_(r,t):r}function xa(e,t){let a=Wt(e,t);return a?(0,Mv.jsx)(Ud,{unit:a}):null}function ol(e){let t=(e??"").trim();if(!t)return"";let a=t.match(/^per\s+(.+)$/i);if(!a)return t;let r=Wt(a[1]);return r?`per ${r}`:""}var Tv=()=>import("./xlsx-K4MOA2QM.js"),sl=["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","Review required","Decision reason","Selected candidate ID","Selected candidate description","Price basis","Price","Line total","Confidence","Status"],G_=sl.indexOf("Line total");function j_(e){return e.unmatchable?"Not matched (labour/plant/referential)":e.best?"Selected":"Needs review"}async function zv(e){let t=await Tv(),a=t.utils.book_new(),r=new Date().toISOString().slice(0,10),n=[sl],i=0;for(let c of e){let{item:p,best:m,qty:f,band:d,unmatchable:g,decision:w}=c,A=[p.section,p.subsection,p.subheading].filter(Boolean).join(" / "),L=!g&&m?.price!=null?m.price*f:null;L!=null&&(i+=L),n.push([p.source_line_id,p.line_id,p.description_original||"(no description)",A,f,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(", "),m?"no":"yes",w?.reason??"",g?"-":m?.product_id??w?.selected_candidate_id??"-",g?"-":m?.description??"-",g?"-":m?.price_basis??"-",g?null:m?.price??null,L,g?"-":d,j_(c)])}n.push(Array(sl.length).fill(null));let o=Array(sl.length).fill(null);o[0]="Estimated total",o[G_]=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(sl.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 ll=["Product ID","Description","Costing mode","Required amount","Req unit","Sell unit size","Sell unit","Required sell units","Unit price","Line total"];async function Rv(e,t){let a=await Tv(),r=a.utils.book_new(),n=new Date().toISOString().slice(0,10),i=t?[["Account",t.name+" ("+t.id+")"],[],ll]:[ll],o=0;for(let p of e){let m=Ft(p),f=m.lineTotal;f!=null&&(o+=f),i.push([p.productId,p.description,m.costingMode,m.requestedAmount,Wt(m.requestedUnit),m.salesUnitSize,Wt(m.sellUnit),m.requiredSellUnits,m.unitPrice,f])}i.push(Array(ll.length).fill(null));let l=Array(ll.length).fill(null);l[0]="Estimated total",l[ll.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 Dd=$(ee());function Vr(){return(0,Dd.jsx)("svg",{className:"back-arrow",viewBox:"0 0 16 16",fill:"none",xmlns:"http://www.w3.org/2000/svg",children:(0,Dd.jsx)("path",{d:"M13 8H3M3 8L7 4M3 8L7 12",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})})}var Od=$(ee());function _n(){return(0,Od.jsx)("svg",{width:"8",height:"5",viewBox:"0 0 8 5",fill:"none",children:(0,Od.jsx)("path",{d:"M1 4L4 1L7 4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}var xn=$(ee());function Bd(){return(0,xn.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,xn.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,xn.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,xn.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,xn.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}var ja=$(ee());function Ld(e){return(0,ja.jsxs)("svg",{viewBox:"0 0 640 420",preserveAspectRatio:"xMidYMid slice",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",...e,children:[(0,ja.jsx)("rect",{width:"640",height:"420",fill:"#fbf1cf"}),(0,ja.jsx)("rect",{x:"88",y:"78",width:"432",height:"264",rx:"16",fill:"#f0c43f"}),(0,ja.jsx)("rect",{x:"120",y:"110",width:"368",height:"200",rx:"10",fill:"#ffd95e"}),(0,ja.jsxs)("g",{stroke:"#e2b12e",strokeWidth:"8",opacity:"0.75",children:[(0,ja.jsx)("line",{x1:"140",y1:"140",x2:"468",y2:"140"}),(0,ja.jsx)("line",{x1:"140",y1:"190",x2:"468",y2:"190"}),(0,ja.jsx)("line",{x1:"140",y1:"240",x2:"468",y2:"240"})]})]})}var Xr=$(ee());function Hd(e){return(0,Xr.jsxs)("svg",{viewBox:"0 0 640 420",preserveAspectRatio:"xMidYMid slice",xmlns:"http://www.w3.org/2000/svg","aria-hidden":"true",...e,children:[(0,Xr.jsx)("rect",{width:"640",height:"420",fill:"#edf1f5"}),(0,Xr.jsx)("rect",{x:"132",y:"108",width:"376",height:"204",rx:"18",fill:"#d5dde6"}),(0,Xr.jsx)("rect",{x:"168",y:"144",width:"304",height:"24",rx:"12",fill:"#9aa6b2"}),(0,Xr.jsx)("rect",{x:"168",y:"188",width:"250",height:"24",rx:"12",fill:"#aab5c0"}),(0,Xr.jsx)("rect",{x:"168",y:"232",width:"220",height:"24",rx:"12",fill:"#aab5c0"})]})}var Qd=$(ee()),Y_=[{match:["building sand"],path:"/schedule-products/building-sand.webp"},{match:["drywall screw"],path:"/schedule-products/drywall-screws.webp"},{match:["scrim"],path:"/schedule-products/scrim-tape.webp"},{match:["loft insulation","loft roll"],path:"/schedule-products/loft-insulation-roll.webp"},{match:["wall tie"],path:"/schedule-products/wall-ties.webp"},{match:["red multi","multi stock","brick"],path:"/schedule-products/red-multi-stock-bricks.webp"}];function za({description:e,photoUrl:t,className:a,width:r,height:n}){let i=(e||"").toLowerCase(),o=Y_.find(p=>p.match.some(m=>i.includes(m))),l=t||o&&It(o.path);if(l)return(0,Qd.jsx)("img",{className:a,src:l,alt:"",width:r,height:n});let c=i.includes("insulation")?Ld:Hd;return(0,Qd.jsx)(c,{className:a,width:r,height:n})}var M=$(ee()),Av=.2,cl=10,Uv="Enter a valid email address so we can send your quote.",$_=(e,t)=>{let a=`${t.requestedAmount} ${Wt(t.requestedUnit,t.requestedAmount)}`,r=`${t.requiredSellUnits} ${Wt(t.sellUnit,t.requiredSellUnits??0)}`,n=e.unitConversions?.find(o=>o.requestUom===t.requestedUnit);if(n&&n.quantityPerSaleUnit<1){let o=Math.round(1/n.quantityPerSaleUnit),l=Math.abs(o*n.quantityPerSaleUnit-1)<1e-9?`${o} ${Wt(t.sellUnit,o)} per ${Wt(t.requestedUnit,1)}`:`${n.quantityPerSaleUnit} ${Wt(t.requestedUnit,n.quantityPerSaleUnit)} per ${Wt(t.sellUnit,1)}`;return`${a} requested \u2192 order ${r} (${l})`}let i=t.sellUnit==="bulk bag"?e.description.match(/(\d+(?:\.\d+)?)\s*kg\b/i):null;return i?`${a} requested \u2192 order ${r} (${i[1]} kg each)`:e.coverageQty&&/^m per /i.test(e.coverageUom??"")?`${a} requested \u2192 order ${r} (${e.coverageQty} ${e.coverageUom})`:`${a} requested \u2192 order ${r}`},V_=e=>["box","pack"].includes(e.requestedUnit)?"Pack size needed to calculate the order quantity.":`This product is sold by the ${Wt(e.sellUnit,1)}.`;function ul({cart:e,onUpdateQty:t,onUpdateSellUnits:a,onResolveConversions:r,onRemove:n,onBack:i,onStartNewQuote:o,onQuoteRequested:l,internal:c=!1}){let p=(0,mt.useId)(),m=Ei(),f=!c&&Is()==="QZA6-MRA4",d=!c,g=Object.values(e),w=(0,mt.useRef)(new Map),[A,L]=(0,mt.useState)(""),[h,u]=(0,mt.useState)(!1),[b,v]=(0,mt.useState)(!1),[_,C]=(0,mt.useState)(""),[R,T]=(0,mt.useState)({}),[D,V]=(0,mt.useState)({}),[oe,_e]=(0,mt.useState)(1),[Te,Oe]=(0,mt.useState)({}),[xe,X]=(0,mt.useState)(!1),[J,ze]=(0,mt.useState)("0"),[Ee,wt]=(0,mt.useState)({});(0,mt.useEffect)(()=>{if(!r)return;for(let U of Object.values(e))Ft(U).requiredSellUnits!=null&&w.current.delete(U.lineId);let x=Object.values(e).filter(U=>{if(U.productId==="-"||Ft(U).requiredSellUnits!=null)return!1;let Z=Ui(U);return w.current.get(U.lineId)===Z?!1:(w.current.set(U.lineId,Z),!0)});if(x.length===0)return;let E=new Map(x.map(U=>[U.lineId,Ui(U)]));wt(U=>({...U,...Object.fromEntries(E)})),fetch(Ma("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Mi()},body:JSON.stringify({lines:x.map(U=>({line_id:U.lineId,product_id:U.productId,requested_description:U.requestedDescription??U.description,requested_qty:U.qty,requested_uom:U.unit||null,linked_context:U.linkedContext??[],selected_description:U.description,selected_uoi:U.uoi,selected_uoi_count:U.uoiCount,selected_conversion:{sales_uom_normalised:U.salesUomNormalised,conversion_type:U.conversionType,sales_unit_size:U.salesUnitSize,sales_unit_size_uom:U.salesUnitSizeUom,coverage_qty:U.coverageQty,coverage_uom:U.coverageUom}}))})}).then(U=>U.ok?Ga(U):null).then(U=>{let Z={},N=new Map(x.map(G=>[G.lineId,Ui(G)]));for(let G of U?.data?.items??U?.items??[]){let Y=G?.conversion;!Y||typeof G?.line_id!="string"||w.current.get(G.line_id)!==N.get(G.line_id)||(Z[G.line_id]={conversionConfidence:Y.conversion_confidence,conversionNotes:Y.conversion_notes,...Number.isFinite(Y.suggested_order_qty)&&Y.suggested_order_qty>0?{sellUnitsOverride:Y.suggested_order_qty}:{}})}Object.keys(Z).length>0&&r(Z)}).catch(U=>console.error("Catalogue conversion resolution failed",U)).finally(()=>{wt(U=>{let Z={...U};for(let[N,G]of E)Z[N]===G&&delete Z[N];return Z})})},[e,r]);function P(x){T(E=>{let U={...E};return delete U[x],U})}function pe(x,E){let U=parseFloat(E);!isNaN(U)&&U>=0&&t(x,Math.min(U,1e5)),P(x)}function Re(x,E,U){t(x,Math.min(1e5,Math.max(0,E+U))),P(x)}function Ot(x){V(E=>{let U={...E};return delete U[x],U})}function jt(x,E){let U=parseFloat(E);!isNaN(U)&&U>=0&&a(x,Math.min(U,1e5)),Ot(x)}function qe(x,E,U){a(x,Math.min(1e5,Math.max(0,E+U))),Ot(x)}async function ke(){if(Be.some(({pricing:E})=>E.lineTotal==null)){C(f?"Confirm the highlighted quantities before requesting a quote.":"Confirm the highlighted quantities before sending your basket.");return}let x=A.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(x)){C(Uv);return}C(""),v(!0);try{let E=await fetch(Ma("/api/quote-requests"),{method:"POST",headers:{"Content-Type":"application/json",...Mi()},body:JSON.stringify({email:x,items:Be.map(({item:U,pricing:Z})=>{let N=Z.requiredSellUnits??Z.requestedAmount,G=Z.requiredSellUnits!=null?Z.sellUnit:Z.requestedUnit;return{product_id:U.productId,description:U.description,quantity:N,unit:Wt(G,N),unit_price:Z.requiredSellUnits!=null?Z.unitPrice:null,line_total:Z.lineTotal}})})});if(!E.ok){let U=await Ga(E);console.error("Quote request failed",E.status,U?.message),C(E.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}z!=null&&m("quote_requested",{items:Be.length,total:Math.round(z*100)/100}),u(!0),l?.(),window.scrollTo(0,0)}catch{C("Your request couldn't be sent. Check your connection and try again.")}finally{v(!1)}}let Be=g.map(x=>({item:x,pricing:Ft(x,{wasteFactorEnabled:xe,wasteFactorOverride:Math.max(0,Number.parseFloat(J)||0)/100})})),Ye=sc(g,{wasteFactorEnabled:xe,wasteFactorOverride:Math.max(0,Number.parseFloat(J)||0)/100}),vt=Ye==null?null:Ye*Av,z=Ye==null?null:Ye*(1+Av),H=Be.filter(({pricing:x})=>x.lineTotal==null).length,le=Object.keys(Ee).length,de=!!r&&g.some(x=>{if(x.productId==="-"||Ft(x).requiredSellUnits!=null)return!1;let E=Ui(x);return w.current.get(x.lineId)!==E||Ee[x.lineId]===E}),me=(0,mt.useRef)({items:Be.length,...z==null?{}:{total:Math.round(z*100)/100}});(0,mt.useEffect)(()=>{m("basket_viewed",me.current)},[m]);let $e=Math.max(1,Math.ceil(Be.length/cl)),Le=Math.min(oe,$e),k=Be.slice((Le-1)*cl,Le*cl);return h?(0,M.jsx)("div",{className:"wizard-step entry-stage",children:(0,M.jsxs)("div",{className:"quote-request-sent",role:"status",children:[(0,M.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,M.jsx)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,M.jsx)("polyline",{points:"5 12.5 10 17.5 19 7"})})}),(0,M.jsx)("h1",{children:f?"Quote requested":"Basket sent"}),f?(0,M.jsxs)("p",{children:["You're all done. We'll email your sharper price to ",(0,M.jsx)("strong",{children:A.trim()}),", usually within one working day."]}):(0,M.jsxs)("p",{children:["You're all done. We'll email ",(0,M.jsx)("strong",{children:A.trim()})," to confirm prices, availability and delivery, usually within one working day."]}),(0,M.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,M.jsx)("span",{children:f?"Start a new quote":"Start a new basket"})}),(0,M.jsx)("p",{className:"quote-request-sent-note",children:f?"Nothing is charged until you approve the quote.":"Nothing is charged until you approve the order."})]})}):!c&&g.length===0?(0,M.jsx)("div",{className:"wizard-step entry-stage",children:(0,M.jsxs)("div",{className:"quote-request-sent",children:[(0,M.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,M.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,M.jsx)("path",{d:"M3 9h18l-2 11H5z"}),(0,M.jsx)("path",{d:"M8 9l4-6 4 6"})]})}),(0,M.jsx)("h1",{children:f?"Your quote request is empty":"Your basket is empty"}),(0,M.jsx)("p",{children:f?"Start again with your list to build your quote.":"Start again with your list to fill your basket."}),(0,M.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,M.jsx)("span",{children:"Back to start"})})]})}):(0,M.jsx)("div",{className:`wizard-step entry-stage${f?" basket-layout--qza6-mra4":""}`,children:(0,M.jsxs)("div",{className:`quick-order-card${c?"":" quick-order-card--customer"}`,children:[(0,M.jsxs)("div",{className:`quick-order-hero${c?"":" quick-order-hero--customer"}`,children:[c&&(0,M.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,M.jsxs)("div",{className:"basket-hero-copy",children:[f&&(0,M.jsxs)("button",{type:"button",className:"cta-btn cta-btn-secondary basket-hero-back",onClick:i,children:[(0,M.jsx)(Vr,{}),(0,M.jsx)("span",{children:"Back to results"})]}),(0,M.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,M.jsx)("h1",{children:c?"Your Selection":f?"Request a quote":"Your Basket"}),c&&(0,M.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,M.jsx)("strong",{children:g.length})," ",g.length===1?"item":"items"]})]}),(0,M.jsx)("p",{children:c?"Review the items you've added before exporting them for review.":f?"Check your items and quantities below, and we'll do our best to beat list prices.":"Review your quantities and order summary, then send us your basket."})]})]}),(0,M.jsx)("div",{className:"quick-order-panel",style:{paddingTop:16},children:de?(0,M.jsxs)("div",{className:"basket-resolving",role:"status","aria-label":"Calculating order quantities",children:[(0,M.jsx)("span",{className:"basket-resolving-wheel","aria-hidden":"true"}),(0,M.jsx)("span",{children:"Calculating your quantities\u2026"})]}):g.length===0?(0,M.jsxs)("div",{className:"quick-order-history-empty",children:[(0,M.jsx)("div",{className:"basket-empty-icon","aria-hidden":"true",children:"\u{1F4CB}"}),(0,M.jsx)("p",{children:"Your selection is empty."}),(0,M.jsx)("p",{className:"basket-empty-hint",children:"Go back to your results and add quoted items."}),(0,M.jsx)("div",{className:"btn-row",style:{marginTop:20,justifyContent:"center"},children:(0,M.jsx)("button",{className:"cta-btn",style:{width:"auto",maxWidth:280},onClick:i,"aria-label":"Back to results",children:(0,M.jsx)("span",{children:"Back to Results"})})})]}):(0,M.jsxs)(M.Fragment,{children:[(0,M.jsxs)("div",{className:"basket-layout",children:[(0,M.jsxs)("div",{className:"basket-main",children:[(0,M.jsx)("div",{className:"basket-list","aria-label":c?"Selection items":f?"Quote request items":"Basket items",children:k.map(({item:x,pricing:E})=>{let U=R[x.lineId]??String(E.requestedAmount),Z=Ev(x,E),N=E.requestedUnit===E.sellUnit||Z,G=E.requiredSellUnits==null||E.requestedAmount!==E.requiredSellUnits||E.requestedUnit!==E.sellUnit;return(0,M.jsxs)("article",{className:"basket-card",children:[(0,M.jsxs)("div",{className:"basket-card-top",children:[(0,M.jsx)(za,{className:"basket-card-thumb",description:x.description,photoUrl:x.pdpPhotoUrl,width:48,height:48}),(0,M.jsxs)("div",{className:"basket-card-info",children:[(0,M.jsx)("div",{className:"bom-component-name",children:x.description}),G&&E.costingMode!=="review"&&(0,M.jsxs)("button",{type:"button",className:"basket-calc-toggle",onClick:()=>Oe(Y=>({...Y,[x.lineId]:!Y[x.lineId]})),"aria-expanded":!!Te[x.lineId],children:["How we calculated this",(0,M.jsx)("span",{className:`basket-calc-toggle-chevron${Te[x.lineId]?" basket-calc-toggle-chevron--open":""}`,children:(0,M.jsx)(_n,{})})]})]}),(0,M.jsx)("div",{className:"basket-card-actions",children:(0,M.jsx)("button",{type:"button",className:"mf-remove-small-btn basket-card-remove",onClick:()=>n(x.lineId),"aria-label":`Remove ${x.description}`,children:(0,M.jsx)(Bd,{})})})]}),c&&(0,M.jsxs)("div",{className:"results-detail-block basket-internal-detail",children:[(0,M.jsxs)("dl",{className:"results-detail-grid",children:[(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Conversion type"}),(0,M.jsx)("dd",{children:x.conversionType??"-"})]}),(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Conversion confidence"}),(0,M.jsx)("dd",{children:x.conversionConfidence??"-"})]}),(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Sales unit"}),(0,M.jsx)("dd",{children:x.salesUnitSize!=null?(0,M.jsxs)(M.Fragment,{children:[x.salesUnitSize," ",xa(x.salesUnitSizeUom,x.salesUnitSize)]}):"-"})]}),(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Coverage"}),(0,M.jsx)("dd",{children:x.coverageQty!=null?(0,M.jsxs)(M.Fragment,{children:[x.coverageQty," ",xa(x.coverageUom,x.coverageQty)]}):"-"})]}),(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Waste factor"}),(0,M.jsx)("dd",{children:x.wasteFactorDefault??"-"})]}),(0,M.jsxs)("div",{children:[(0,M.jsx)("dt",{children:"Rounding rule"}),(0,M.jsx)("dd",{children:x.roundingRule??"-"})]})]}),x.conversionNotes&&(0,M.jsx)("p",{className:"results-rerank-note",children:x.conversionNotes})]}),Z?(0,M.jsx)("p",{className:"basket-calc-text basket-calc-text--review",children:Ee[x.lineId]===Ui(x)?(0,M.jsx)("strong",{children:"Calculating order quantity\u2026"}):x.conversionNotes?.trim()?x.conversionNotes.trim():(0,M.jsxs)(M.Fragment,{children:[(0,M.jsx)("strong",{children:"Quantity needs confirmation."})," ",V_(E)]})}):G&&Te[x.lineId]?(0,M.jsx)("p",{className:"basket-calc-text",children:$_(x,E)}):null,(0,M.jsxs)("div",{className:"basket-card-stats",children:[(0,M.jsxs)("div",{className:"basket-stat",children:[(0,M.jsx)("span",{className:"basket-stat-label",children:"Requested qty"}),(0,M.jsxs)("div",{className:"basket-stat-value",children:[(0,M.jsxs)("div",{className:"basket-qty-field",children:[(0,M.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:U,disabled:N,onChange:Y=>T(ce=>({...ce,[x.lineId]:Y.target.value})),onBlur:Y=>pe(x.lineId,Y.target.value),onKeyDown:Y=>{Y.key==="Enter"&&Y.target.blur()},"aria-label":`${x.description} requested quantity`}),(0,M.jsxs)("div",{className:"basket-qty-arrows",children:[(0,M.jsx)("button",{type:"button",className:"basket-qty-arrow",disabled:N,onClick:()=>Re(x.lineId,parseFloat(U)||0,1),"aria-label":`Increase ${x.description} quantity`,children:(0,M.jsx)(_n,{})}),(0,M.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",disabled:N,onClick:()=>Re(x.lineId,parseFloat(U)||0,-1),"aria-label":`Decrease ${x.description} quantity`,children:(0,M.jsx)(_n,{})})]})]}),(0,M.jsx)("span",{className:"basket-metric-unit",children:xa(E.requestedUnit,parseFloat(U)||0)})]})]}),(0,M.jsxs)("div",{className:"basket-stat basket-stat--right",children:[(0,M.jsx)("span",{className:"basket-stat-label",children:"Order qty"}),(0,M.jsxs)("div",{className:"basket-stat-value",children:[(0,M.jsxs)("div",{className:"basket-qty-field",children:[(0,M.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:D[x.lineId]??String(E.requiredSellUnits??""),onChange:Y=>V(ce=>({...ce,[x.lineId]:Y.target.value})),onBlur:Y=>jt(x.lineId,Y.target.value),onKeyDown:Y=>{Y.key==="Enter"&&Y.target.blur()},"aria-label":`${x.description} order quantity`}),(0,M.jsxs)("div",{className:"basket-qty-arrows",children:[(0,M.jsx)("button",{type:"button",className:"basket-qty-arrow",onClick:()=>qe(x.lineId,parseFloat(D[x.lineId]??String(E.requiredSellUnits??"0"))||0,1),"aria-label":`Increase ${x.description} order quantity`,children:(0,M.jsx)(_n,{})}),(0,M.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",onClick:()=>qe(x.lineId,parseFloat(D[x.lineId]??String(E.requiredSellUnits??"0"))||0,-1),"aria-label":`Decrease ${x.description} order quantity`,children:(0,M.jsx)(_n,{})})]})]}),(0,M.jsx)("span",{className:"basket-metric-unit",children:xa(E.sellUnit,parseFloat(D[x.lineId]??String(E.requiredSellUnits??"0"))||0)})]})]}),(0,M.jsxs)("div",{className:"basket-stat basket-stat--total",children:[(0,M.jsx)("span",{className:"basket-stat-label",children:"Total"}),(0,M.jsxs)("div",{className:"basket-stat-value",children:[(0,M.jsx)("strong",{children:E.lineTotal!=null?ot(E.lineTotal):"-"}),E.lineTotal!=null&&(0,M.jsx)("span",{className:"basket-metric-unit",children:"ex. VAT"})]})]})]})]},x.lineId)})}),$e>1&&(0,M.jsxs)("div",{className:"results-pagination",children:[(0,M.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(Le-1)*cl+1,"\u2013",Math.min(Le*cl,Be.length)," of ",Be.length]}),(0,M.jsxs)("div",{className:"results-pagination-controls",children:[(0,M.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>_e(Le-1),disabled:Le===1,children:"Previous"}),(0,M.jsxs)("span",{className:"results-pagination-page",children:["Page ",Le," of ",$e]}),(0,M.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>_e(Le+1),disabled:Le===$e,children:"Next"})]})]})]}),(0,M.jsxs)("aside",{className:"basket-sidebar",children:[(0,M.jsx)("div",{className:"basket-sidebar-title",children:f?"Quote request summary":"Order summary"}),(0,M.jsxs)("div",{className:"basket-sidebar-row",children:[(0,M.jsx)("span",{children:f?"List price (ex. VAT)":"Subtotal (ex. VAT)"}),(0,M.jsx)("span",{children:Ye==null?"To confirm":ot(Ye)})]}),(0,M.jsxs)("div",{className:"basket-sidebar-row",children:[(0,M.jsx)("span",{children:"VAT (20%)"}),(0,M.jsx)("span",{children:vt==null?"To confirm":ot(vt)})]}),(0,M.jsxs)("div",{className:"basket-sidebar-row basket-sidebar-row--total",children:[(0,M.jsx)("span",{children:f?"List price (inc.\xA0VAT)":"Total"}),(0,M.jsx)("span",{children:z==null?"To confirm":ot(z)})]}),!f&&(0,M.jsx)("div",{className:"basket-summary-waste",children:(0,M.jsxs)("div",{className:"basket-waste-control",children:[(0,M.jsxs)("label",{className:"basket-global-waste",children:[(0,M.jsx)("input",{type:"checkbox",checked:xe,onChange:x=>X(x.target.checked)}),(0,M.jsx)("span",{children:"Add waste factor"})]}),(0,M.jsxs)("label",{className:"basket-global-waste-percent",children:[(0,M.jsx)("input",{type:"number",inputMode:"decimal",min:"0",step:"0.1",value:J,onChange:x=>ze(x.target.value),disabled:!xe,"aria-label":"Waste factor percent"}),(0,M.jsx)("span",{children:"%"})]})]})}),(0,M.jsx)("label",{htmlFor:`${p}-basket-reference`,className:"basket-sidebar-label",children:f?"Enter email for your sharper quote":d?"Your email":"Your reference (optional)"}),(0,M.jsx)("input",{id:`${p}-basket-reference`,type:d?"email":"text",className:"basket-sidebar-input",value:A,onChange:x=>{L(x.target.value),d&&C("")},placeholder:d?"you@example.com":"PO number or job reference","aria-invalid":d&&_===Uv,"aria-describedby":d&&_?`${p}-basket-reference-error`:void 0}),d&&_&&(0,M.jsx)("p",{id:`${p}-basket-reference-error`,className:"basket-quote-request-error",role:"alert",children:_}),d?(0,M.jsx)("button",{type:"button",className:"cta-btn",onClick:()=>{ke()},disabled:b||H>0||le>0,"aria-busy":b,children:(0,M.jsx)("span",{children:b?"Sending\u2026":f?"Request our best quote":"Send basket"})}):(0,M.jsx)("button",{className:"cta-btn",onClick:()=>{m("downloaded",{type:"basket",items:g.length}),Rv(g)},"aria-label":"Download selection",children:(0,M.jsx)("span",{children:"Download Quote"})}),(0,M.jsxs)("p",{className:"basket-sidebar-disclaimer",children:[(0,M.jsx)("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),f?"This is a quote request, not an order. We'll confirm our best price, availability and delivery before you approve.":d?"Sending your basket isn't an order. We'll confirm prices, availability and delivery before you approve.":"Prices and availability are estimates and should be confirmed before procurement."]})]})]}),(0,M.jsx)("div",{className:"btn-row results-actions",children:(0,M.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,M.jsx)(Vr,{}),(0,M.jsx)("span",{children:"Back to results"})]})})]})})]})})}var ye=$(Ve());function Oi(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 kn=$(ee());function jd(){return(0,kn.jsxs)("svg",{width:"14",height:"14",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,kn.jsx)("path",{d:"M3 12a9 9 0 0 1 15.36-6.36L21 8"}),(0,kn.jsx)("path",{d:"M21 3v5h-5"}),(0,kn.jsx)("path",{d:"M21 12a9 9 0 0 1-15.36 6.36L3 16"}),(0,kn.jsx)("path",{d:"M3 21v-5h5"})]})}var s=$(ee()),Vd="__none__",pl=24,X_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}];function Lv(e){return e==null?"low":e>=.7?"high":e>=.5?"medium":"low"}var Z_=e=>e.attrs.supply_nature==="labour_only"||e.attrs.supply_nature==="plant"||e.flags.includes("referential");function P_(e,t){if(t!==Vd){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 Dv(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 K_({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 Li(e,t){if(e==null)return"-";let a=ol(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function Xd(e){return e&&e.length>0?e.join(" x "):"-"}function J_(e){return e==null?"-":Number.isInteger(e/1e3)?`${e/1e3}m`:`${(e/1e3).toFixed(1)}m`}function Bi(e){let t=(e??[]).map(a=>a.trim()).filter(Boolean);return t.length>0?t.join(", "):"-"}function Zr(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)"}function I_(e,t){return t>0||e==null?null:ot(e)}var Ov=[{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 F_(e){let t=new Map;return[...new Set(e.filter(Pr).map(r=>r.linked_group_id))].forEach((r,n)=>{let i=n%26;t.set(r,{token:String.fromCharCode(65+i),bubbleStyle:Ov[n%Ov.length]})}),t}function Pr(e){return!1}function Hi(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 Yd({meta:e}){return e?(0,s.jsx)("span",{className:"results-linked-pill",style:e.bubbleStyle,children:`Link ${e.token}`}):null}function W_(e,t,a){let r=t?.rerank?.recommendedCandidateIds??[],n=new Map(e.map(c=>[c.product_id,c])),i=r.length>0?r.map(c=>n.get(c)).filter(c=>c!=null):e.slice(0,6),o=a?n.get(a):void 0,l=o?[o,...i.filter(({product_id:c})=>c!==o.product_id)]:i;return[...new Map(l.map(c=>[c.product_id,c])).values()].slice(0,6)}function $d(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 cc(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 ex({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:cc(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:cc(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:cc(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:cc(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 tx({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:Xd(r.measurements_mm)}),(0,s.jsx)("td",{children:ol(r.price_basis)||"-"}),(0,s.jsx)("td",{children:r.bm25.toFixed(2)})]},`${r.product_id}-${n}`))})]})]},`${t.query}-${a}`))]})}function Bv({item:e,result:t}){let a=t?.retrieval_debug.map(n=>n.query).filter(Boolean)??[],r=[["Procurement intent",e.procurement_intent||"-"],["Procurement aliases",Bi(e.procurement_aliases)],["Retrieval queries",Bi(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)",Xd(e.attrs.measurements_mm)],["Stock length",J_(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",Bi(e.installation_clues)],["System clues",Bi(e.system_clues)],["Component requirements",Bi(e.component_requirements)],["Linked group",Hi(e)||"-"],["Flags",Bi(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)(ye.Fragment,{children:[(0,s.jsx)("dt",{children:n}),(0,s.jsx)("dd",{children:i})]},n))})]})}function ax({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)(ye.Fragment,{children:[(0,s.jsx)("dt",{children:"Attempted"}),(0,s.jsx)("dd",{children:t.attempted?"yes":"no"})]}),(0,s.jsxs)(ye.Fragment,{children:[(0,s.jsx)("dt",{children:"Applied"}),(0,s.jsx)("dd",{children:t.applied?"yes":"no"})]}),(0,s.jsxs)(ye.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned items"}),(0,s.jsx)("dd",{children:t.returned_item_count??"-"})]}),(0,s.jsxs)(ye.Fragment,{children:[(0,s.jsx)("dt",{children:"Reason"}),(0,s.jsx)("dd",{children:t.reason||"-"})]}),(0,s.jsxs)(ye.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 rx({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||"-"]];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)(ye.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 nx({item:e,decision:t,selectedProductId:a,result:r,showRetrievalDebug:n,reviewOnly:i=!1,linkedGroupMeta:o}){if(!t)return null;let l=a==null?"Needs review:":"Selected:";return i?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:l}),"\xA0",t.reason]}),Pr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",o?`Link ${o.token} - `:"",Hi(e)]}):null]}):null:!t.reason&&!n?(0,s.jsx)(Bv,{item:e,result:r}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(Bv,{item:e,result:r}),n&&(0,s.jsx)(ax,{item:e}),n&&(0,s.jsx)(rx,{result:r}),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:l}),"\xA0",t.reason]}),Pr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",o?`Link ${o.token} - `:"",Hi(e)]}):null]}),n&&(0,s.jsx)(tx,{queries:r?.retrieval_debug??[]})]})}function ix({item:e,candidates:t,result:a,decision:r,unmatchable:n,selectedProductId:i,detailMode:o,onPick:l,onClear:c,showAll:p=!1,internal:m=!1,debugEnabled:f=!1,forceReviewNote:d=!1,linkedGroupMeta:g}){let w=m||o==="detailed",A=f&&o==="detailed",L=w||d?(0,s.jsx)(nx,{item:e,decision:r,selectedProductId:i,result:a,showRetrievalDebug:A,reviewOnly:d&&!w,linkedGroupMeta:g}):null;if(n)return(0,s.jsxs)(s.Fragment,{children:[L,(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:[L,(0,s.jsx)("p",{className:"results-empty-hint",children:"No candidates were returned for this line item."})]});let h=p||m||o==="detailed"?t:W_(t,a,i);return(0,s.jsxs)(s.Fragment,{children:[L,(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"}),A&&(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:h.map((u,b)=>{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:Xd(u.measurements_mm??u.debug?.candidate.measurements_mm)})}),(0,s.jsx)("td",{children:Li(u.price,u.price_basis)}),A&&(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)(K_,{band:Lv(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}-${b}`)})})]})]})}function Zd({scheduleResult:e,onStartOver:t,cart:a,onAddToCart:r,onRemoveFromCart:n,onGoToBasket:i,cartSeeded:o,onCartSeeded:l,reviewGateComplete:c,onReviewGateComplete:p,internal:m=!1}){let f=!m&&Is()==="QZA6-MRA4",d=f?"quote":"basket",{results:g,lineItems:w,parseReport:A,timings:L}=e,[h,u]=(0,ye.useState)({}),b=Ei(),[v,_]=(0,ye.useState)({}),[C,R]=(0,ye.useState)({}),[T,D]=(0,ye.useState)(""),[V,oe]=(0,ye.useState)(null),[_e,Te]=(0,ye.useState)(1),Oe=Dt().debug===!0,[xe,X]=(0,ye.useState)("simple"),[J,ze]=(0,ye.useState)(m?"list":"tile"),[Ee,wt]=(0,ye.useState)(!1),[P,pe]=(0,ye.useState)(null),[Re,Ot]=(0,ye.useState)(""),[jt,qe]=(0,ye.useState)([]),[ke,Be]=(0,ye.useState)(!1),[Ye,vt]=(0,ye.useState)(null),[z,H]=(0,ye.useState)(!1),[le,de]=(0,ye.useState)(null),me=(0,ye.useRef)(null),[$e,Le]=(0,ye.useState)(new Set),[k,x]=(0,ye.useState)(new Set),[E,U]=(0,ye.useState)(!1);(0,ye.useEffect)(()=>{Te(1)},[T,V,J]);let Z=new Map(g.map(S=>[S.line_id,S])),N=F_(w),G=w.map(S=>{let Q=Z.get(S.line_id),ge=Q?.decision,ht=Z_(S),Je=h[S.line_id],Za=P_(Q,Je),Un=a[S.line_id],x0=Je===Vd?void 0:v[S.line_id]??(Un&&Un.productId!==Za?.product_id?Dv(Un):Za),Mm=ht?void 0:x0,k0=S.qty??0;return{item:S,result:Q,decision:ge,unmatchable:ht,best:Mm,qty:k0,band:Lv(Mm?.scores?.overall)}}),ce=G.some(S=>!S.unmatchable&&!S.best&&!k.has(S.item.line_id))?null:sc(Object.values(a),{wasteFactorEnabled:!1,wasteFactorOverride:0}),Se=0;for(let S of G){if(S.unmatchable||!S.best)continue;let Q=a[S.item.line_id];(!Q||Ft(Q).lineTotal==null)&&(Se+=1)}Se>0&&(ce=null);let yt=I_(ce,Se),ft=S=>!S.unmatchable&&!S.best&&$d(S.result).length>0,At=S=>S.best??$d(S.result)[0],Jr=G.filter(S=>!S.unmatchable&&!S.best).filter(S=>!k.has(S.item.line_id)),Ec=G.filter(S=>k.has(S.item.line_id)),Yt=G;if(T.trim()){let S=T.trim().toLowerCase();Yt=Yt.filter(Q=>Q.item.description_original?.toLowerCase().includes(S)||At(Q)?.description?.toLowerCase().includes(S))}if(V){let S=V==="asc"?1:-1;Yt=[...Yt].sort((Q,ge)=>S*(Q.item.description_original||"").localeCompare(ge.item.description_original||""))}let hr=Math.max(1,Math.ceil(Yt.length/pl)),_t=Math.min(_e,hr),Zi=Yt.slice((_t-1)*pl,_t*pl),_m=Zi.filter(S=>!S.unmatchable&&S.best),Mc=Zi.filter(S=>!S.unmatchable&&S.best),xm=Zi.filter(S=>S.unmatchable||!S.best),I=P?G.find(S=>S.item.line_id===P)??null:null,h0=!m&&!c&&!I&&Jr.length>0,Pi=(0,ye.useRef)(null),Ki=()=>{let S=me.current;if(!S)return;let{top:Q,left:ge,width:ht,height:Je}=S.getBoundingClientRect(),Un=S.querySelector(".bom-toolbar-btn")?.closest("td")?.getBoundingClientRect().left;de({top:Q,left:ge,width:Un?Un-ge:ht,height:Je})};(0,ye.useEffect)(()=>(window.addEventListener("scroll",Ki,!0),window.addEventListener("resize",Ki),()=>{window.removeEventListener("scroll",Ki,!0),window.removeEventListener("resize",Ki)})),(0,ye.useEffect)(()=>{let S=Q=>{Pi.current&&!Q.composedPath().includes(Pi.current)&&Pi.current.removeAttribute("open")};return document.addEventListener("click",S),()=>document.removeEventListener("click",S)},[]);let Rn=S=>{pe(S),Ot("")},g0=()=>{if(!P)return;let S=a[P];if(S){u(Q=>({...Q,[P]:S.productId})),_(Q=>({...Q,[P]:Dv(S)}));return}u(Q=>{let ge={...Q};return delete ge[P],ge}),_(Q=>{let ge={...Q};return delete ge[P],ge})},Xa=(S=!1)=>{let Q=P?a[P]:void 0;!S&&Q&&I?.best&&Q.productId!==I.best.product_id&&!window.confirm("You have selected a new product. Leave without updating it?")||(S||g0(),pe(null),U(!1))};rl(z,()=>H(!1)),rl(!!I&&!z,()=>Xa());let b0=S=>{if(Le(Q=>new Set(Q).add(S)),Jr.some(Q=>Q.item.line_id!==S)){Xa(!0);return}p(),Xa(!0)},w0=S=>{if(Tc(S),x(Q=>new Set(Q).add(S)),Jr.some(Q=>Q.item.line_id!==S)){Xa(!0);return}p(),Xa(!0)},v0=()=>{x(S=>new Set([...S,...Jr.map(Q=>Q.item.line_id)])),p()},km=()=>{I?.best&&(Nm(I.item.line_id,I.best),r(Ji(I)),E?b0(I.item.line_id):Xa(!0))},Sm=xm.length>0?(0,s.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items needing review",children:[(0,s.jsxs)("div",{className:"results-tile-section__head",children:[(0,s.jsx)("h3",{children:"Needs review"}),(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:xm.map(S=>{let{item:Q,qty:ge}=S;return(0,s.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>Rn(Q.line_id),children:[(0,s.jsx)("span",{className:"results-unmatched-card__main",children:(0,s.jsx)("span",{className:"results-unmatched-card__title",children:Zr(Q,w)})}),(0,s.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},Q.line_id)})})]}):null,Tc=S=>{u(Q=>({...Q,[S]:Vd})),_(Q=>({...Q,[S]:void 0})),R(Q=>({...Q,[S]:void 0})),n(S)},zc=(S,Q)=>{u(ge=>({...ge,[S]:Q.product_id})),_(ge=>({...ge,[S]:Q}))},Nm=(S,Q)=>{Q.method==="catalogue_search"&&R(ge=>({...ge,[S]:Q}))};function $x(){b("downloaded",{type:"schedule",lines:G.length}),zv(G.map(({item:S,best:Q,qty:ge,band:ht,unmatchable:Je,decision:Za})=>({item:S,best:Q,qty:ge,band:ht,unmatchable:Je,decision:Za})))}function Ji(S){let Q=S.best;if(!Q)throw new Error("Cannot add a line item without a selected product.");return Oi(Q,{lineId:S.item.line_id,description:S.item.description_original,unit:S.item.unit,qty:S.qty,linkedContext:S.item.linked_group_role==="dependent"&&S.item.linked_group_id?w.filter(ge=>ge.linked_group_id===S.item.linked_group_id&&ge.linked_group_role==="anchor").slice(0,1).map(ge=>{let ht=a[ge.line_id];return{line_id:ge.line_id,product_id:ht?.productId??null,measurements_mm:ht?.measurementsMm??ge.attrs.measurements_mm,description:ht?.description??ge.description_original,qty:ge.qty,unit:ge.unit,role:"anchor"}}):void 0})}(0,ye.useEffect)(()=>{if(!o){for(let S of G)!S.unmatchable&&S.best&&r(Ji(S));l()}},[o]),(0,ye.useEffect)(()=>{if(!P){qe([]),vt(null),Be(!1);return}let S=Re.trim();if(!S){qe([]),vt(null),Be(!1);return}let Q=!1,ge=window.setTimeout(async()=>{try{Be(!0),vt(null);let ht=await fetch(Ma(`/api/catalogue/search?q=${encodeURIComponent(S)}`),{headers:wn()}),Je=await Ga(ht);if(!ht.ok)throw new Error(Je?.error||Je?.message||"Failed to search catalogue");Q||qe(Array.isArray(Je?.items)?Je.items:[])}catch(ht){Q||(qe([]),vt(ht?.message||"Failed to search catalogue"))}finally{Q||Be(!1)}},250);return()=>{Q=!0,window.clearTimeout(ge)}},[Re,P]);let Rc=Object.keys(a).length,Na=Re.trim(),Ac=$d(I?.result),bl=!!I&&!I.best&&(I.result?.candidates.length===0||I.result?.rerank?.selectedCandidateId===null),Cm=I?.result?.rerank!=null,qm=I?.decision?.reason??(bl?"No catalogue candidate found. Refine the request or search the catalogue.":null),y0=jt.map(S=>({product_id:S.product_id,description:S.description,source_list:S.source_list,price:S.price,price_basis:S.price_basis,uoi_count:S.uoi_count??null,uoi:S.uoi,pdp_photo_url:S.pdp_photo_url??null,conversion:S.conversion,measurements_mm:S.measurements_mm??[],scores:{dimension:0,grade:0,brand:0,fuzzy:0,bm25:0,overall:0},method:"catalogue_search"})),Ii=Na?y0:Ac,An=I?C[I.item.line_id]:void 0,Fi=!Na&&An&&!Ii.some(S=>S.product_id===An.product_id)?[...Ii,An]:Ii,Em=(()=>{let S=Fi.slice(0,Na?12:6);return Na||!An||S.some(Q=>Q.product_id===An.product_id)?S:[...S,An]})(),wl=!!I?.best&&a[I.item.line_id]?.productId===I.best.product_id,_0=!!I?.best&&!!a[I.item.line_id]&&!wl;return(0,s.jsxs)("div",{className:"wizard-step entry-stage",children:[(0,s.jsxs)("div",{className:`quick-order-card${m?"":" quick-order-card--customer"}`,children:[(0,s.jsx)("div",{className:`quick-order-hero${m?"":" quick-order-hero--customer"}`,children:m?(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:yt??"Review quantities"})," 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 ",f?"View Quote":"View Basket"," to continue."]})]}),(0,s.jsxs)("button",{type:"button",className:"results-total-action",onClick:i,disabled:Rc===0,"aria-label":f?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:f?"View Quote":"View Basket"}),yt!=null&&(0,s.jsx)("strong",{children:yt})]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Qt,{})})]})]})}),(0,s.jsxs)("div",{className:"quick-order-panel",style:{paddingTop:16},children:[Oe&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:12},children:(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn","aria-pressed":Ee,onClick:()=>wt(S=>!S),children:Ee?"Hide timings":"Show timings"})}),Oe&&Ee&&(0,s.jsx)(ex,{...L}),!f&&(0,s.jsx)("div",{className:"results-toolbar-row",children:!I&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:0},children:(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:T,onChange:S=>D(S.target.value),"aria-label":"Search line items"}),!m&&(0,s.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,s.jsx)("button",{type:"button",className:`results-view-toggle__btn${J==="tile"?" is-active":""}`,"aria-pressed":J==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>ze("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${J==="list"?" is-active":""}`,"aria-pressed":J==="list","aria-label":"List view",title:"List view",onClick:()=>ze("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"})]})})]}),Oe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>X(S=>S==="simple"?"detailed":"simple"),children:xe==="detailed"?"Hide detailed view":"Show detailed view"}),(0,s.jsxs)("details",{ref:Pi,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:X_.map(S=>{let Q=V===S.dir;return(0,s.jsxs)("button",{type:"button",className:`sort-menu-item${Q?" is-active":""}`,onClick:()=>{oe(Q?null:S.dir),Pi.current?.removeAttribute("open")},children:[(0,s.jsx)("span",{className:"sort-menu-item__check",children:Q?"\u2713":""}),S.label]},S.dir)})})]})]})})}),J==="tile"||I?(0,s.jsxs)(s.Fragment,{children:[I?(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop",role:"dialog","aria-modal":"true","aria-label":"Product options",onClick:()=>Xa(),children:(0,s.jsxs)("section",{className:"quick-order-workflow-modal results-review-modal",onClick:S=>S.stopPropagation(),children:[(0,s.jsx)("button",{type:"button",className:"quick-order-workflow-close results-review-modal__close",onClick:()=>Xa(),"aria-label":"Close product options",children:(0,s.jsx)(nl,{})}),(0,s.jsx)("div",{className:"results-review-page",children:m?(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:()=>Xa(),children:[(0,s.jsx)(Vr,{}),"Back to results"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[Oe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>X(S=>S==="simple"?"detailed":"simple"),children:xe==="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:Re,onChange:S=>Ot(S.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:()=>Tc(I.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)(za,{className:"fill-img results-review-page__image",description:At(I)?.description||I.item.description_original,photoUrl:At(I)?.pdp_photo_url})}),(0,s.jsxs)("div",{className:"results-review-page__summary",children:[(0,s.jsx)("h2",{children:Zr(I.item,w)}),(0,s.jsxs)("p",{className:"results-review-page__meta",children:[yn(I.qty)," ",xa(I.item.unit,I.qty)]}),I.best?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:I.best.description}),I.best.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Li(I.best.price,I.best.price_basis)}):null]}):At(I)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:At(I)?.description}),At(I)?.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Li(At(I)?.price??null,At(I)?.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."}),Pr(I.item)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[(0,s.jsx)(Yd,{meta:N.get(I.item.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:Hi(I.item)})]}):null,(0,s.jsx)("div",{className:"results-review-page__actions",children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[I.item.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[I.item.line_id]?n(I.item.line_id):(I.best&&Nm(I.item.line_id,I.best),r(Ji(I)))},disabled:!I.best,"aria-label":a[I.item.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[I.item.line_id]?"\u2713 Added":m?"+ Add to selection":`Add to ${d}`})})]})]}),ke?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,!ke&&Ye?(0,s.jsx)("div",{className:"results-empty-card",children:Ye}):null,!ke&&!Ye&&Na&&Ii.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No candidate products match this database search."}):!ke&&!Ye?(0,s.jsx)(ix,{item:I.item,candidates:Ii,result:I.result,decision:I.decision,unmatchable:I.unmatchable,selectedProductId:I.best?.product_id??null,detailMode:xe,linkedGroupMeta:Pr(I.item)?N.get(I.item.linked_group_id):void 0,onPick:S=>zc(I.item.line_id,S),onClear:()=>Tc(I.item.line_id),showAll:m||Oe||Na.length>0,internal:m,debugEnabled:Oe,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:Zr(I.item,w)||"Original request"})]}),qm?(0,s.jsxs)("section",{className:"customer-review-ai",children:[(0,s.jsx)("strong",{children:bl?"No automatic match:":"AI review:"})," ",qm]}):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:bl?Ac.length>0?"Choose a product":"No suitable product found":Cm?"Choose a product":"We couldn't review this item"}),(0,s.jsx)("p",{children:bl?Ac.length>0?"No product was selected automatically. Review these related options before adding one.":"Search the catalogue to choose an alternative.":Cm?`Select the option you want to add to your ${d}.`:"Search the catalogue to choose a product."})]})}),!Na&&Fi.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:Em.map(S=>{let Q=S.product_id===I.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${Q?" is-selected":""}`,onClick:()=>zc(I.item.line_id,S),"aria-pressed":Q,children:[(0,s.jsx)(za,{className:"customer-review-option__image",description:S.description,photoUrl:S.pdp_photo_url,width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:S.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:S.price!=null?`\xA3${Li(S.price,S.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:Q?"Selected":"Choose"})]},S.product_id)})}):null,Fi.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:Re,onChange:S=>Ot(S.target.value),"aria-label":"Search catalogue"})]}),Na&&ke?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,Na&&!ke&&Ye?(0,s.jsx)("div",{className:"results-empty-card",children:Ye}):null,Na&&!ke&&!Ye&&Fi.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No products match this search."}):null,Na&&!ke&&!Ye&&Fi.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:Em.map(S=>{let Q=S.product_id===I.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${Q?" is-selected":""}`,onClick:()=>zc(I.item.line_id,S),"aria-pressed":Q,children:[(0,s.jsx)(za,{className:"customer-review-option__image",description:S.description,photoUrl:S.pdp_photo_url,width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:S.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:S.price!=null?`\xA3${Li(S.price,S.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:Q?"Selected":"Choose"})]},S.product_id)})}):null]}),I.best?_0?(0,s.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,s.jsx)("button",{type:"button",className:"cta-btn customer-review-add",onClick:()=>{km()},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(I.item.line_id),children:(0,s.jsx)("span",{children:`Remove from ${d}`})})]}):(0,s.jsx)("button",{type:"button",className:`cta-btn customer-review-add${wl?" cta-btn-secondary":""}`,onClick:()=>{wl?n(I.item.line_id):km()},children:(0,s.jsx)("span",{children:wl?`Remove from ${d}`:`Add selected product to ${d}`})}):null,E?(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-skip",onClick:()=>w0(I.item.line_id),children:"Skip this item"}):null]})})]})}):null,(0,s.jsxs)("div",{className:"results-tile-layout",children:[Yt.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No line items match the current search/filter."}):null,Mc.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:Mc.map(S=>{let{item:Q,best:ge,qty:ht}=S,Je=At(S);return(0,s.jsxs)("article",{className:"results-tile-card",children:[(0,s.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>Rn(Q.line_id),"aria-label":`Review match for ${Zr(Q,w)||"item"}`,children:[(0,s.jsxs)("div",{className:"results-tile-card__media",children:[Pr(Q)?(0,s.jsx)("div",{className:"results-tile-card__badges",children:(0,s.jsx)(Yd,{meta:N.get(Q.linked_group_id)})}):null,(0,s.jsx)(za,{className:"fill-img results-tile-card__image",description:Je?.description||Q.description_original,photoUrl:Je?.pdp_photo_url})]}),(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:"\u21B3 matched from"}),(0,s.jsx)("div",{className:"results-tile-card__match-name",children:Zr(Q,w)}),Pr(Q)?(0,s.jsx)("div",{className:"results-row-meta",children:Hi(Q)}):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:[m&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Rn(Q.line_id),children:"Review"}),(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[Q.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[Q.line_id]?n(Q.line_id):r(Ji(S))},disabled:!ge,"aria-label":a[Q.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[Q.line_id]?"\u2713 Added":m?"+ Add":`Add to ${d}`})]})]},Q.line_id)})})}):null,Sm]})]}):(0,s.jsxs)(s.Fragment,{children:[le&&(0,s.jsx)("div",{className:"results-table__hover-overlay",style:le,"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"}}),xe==="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"}),xe==="simple"&&(0,s.jsx)("th",{style:{textAlign:"center"},children:m?"Selection":f?"Quote":"Basket"})]})}),(0,s.jsxs)("tbody",{children:[Yt.length===0&&(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:xe==="simple"?4:3,className:"results-empty-hint",style:{padding:"16px 8px"},children:"No line items match the current search/filter."})}),Mc.map(S=>{let{item:Q,result:ge,decision:ht,best:Je}=S;return(0,s.jsxs)("tr",{className:"bom-row results-table__review-row",onClick:()=>Rn(Q.line_id),onMouseEnter:Za=>{me.current=Za.currentTarget,Ki()},onMouseLeave:()=>{me.current=null,de(null)},children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{className:"bom-component-name",children:Zr(Q,w)}),Pr(Q)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,s.jsx)(Yd,{meta:N.get(Q.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:Hi(Q)})]}):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}),xe==="detailed"&&ht&&(0,s.jsx)("div",{className:"results-row-meta",children:ht.selected_candidate_id===Je.product_id?"Automatically selected":"Selected"})]}):(0,s.jsx)("span",{className:"results-empty-hint"})}),(0,s.jsx)("td",{style:{textAlign:"center"},children:Je?.price!=null?Li(Je.price,Je.price_basis):"-"}),xe==="simple"&&(0,s.jsx)("td",{style:{textAlign:"center"},children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[Q.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,style:{width:84,justifyContent:"center"},onClick:Za=>{Za.stopPropagation(),a[Q.line_id]?n(Q.line_id):r(Ji(S))},"aria-label":a[Q.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[Q.line_id]?"\u2713 Added":m?"+ Add":`Add to ${d}`})})]},Q.line_id)})]})]})}),Sm]}),!I&&hr>1&&(0,s.jsxs)("div",{className:"results-pagination",children:[(0,s.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(_t-1)*pl+1,"\u2013",Math.min(_t*pl,Yt.length)," of ",Yt.length]}),(0,s.jsxs)("div",{className:"results-pagination-controls",children:[(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Te(_t-1),disabled:_t===1,children:"Previous"}),(0,s.jsxs)("span",{className:"results-pagination-page",children:["Page ",_t," of ",hr]}),(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Te(_t+1),disabled:_t===hr,children:"Next"})]})]}),(A.itemCount!=null||A.headingCount!=null||A.skippedCount!=null)&&(0,s.jsxs)("div",{className:"results-summary",style:{marginTop:16},children:[A.itemCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:A.itemCount})," items parsed"]}),A.headingCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:A.headingCount})," headings"]}),A.skippedCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:A.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."})]}),!I&&(0,s.jsxs)("div",{className:"btn-row results-actions",children:[(0,s.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",gap:10,justifyContent:"center"},onClick:()=>H(!0),"aria-label":"Start over",children:[(0,s.jsx)(jd,{}),(0,s.jsx)("span",{children:"Start Over"})]}),(0,s.jsxs)("button",{className:"cta-btn",style:{flex:"0 1 70%"},onClick:i,disabled:Rc===0,"aria-label":m?"View selection":f?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[m?"View Selection":f?"View Quote":"View Basket"," (",Rc,")"]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Qt,{})})]})]})]})]}),h0&&(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:Jr.map(S=>{let Q=$e.has(S.item.line_id),ge=ft(S);return(0,s.jsx)("div",{className:`review-gate-item${Q?" is-reviewed":""}`,children:(0,s.jsxs)("button",{type:"button",className:"review-gate-item__review",onClick:()=>{U(!0),Rn(S.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Zr(S.item,w)}),(0,s.jsx)("span",{children:S.decision?.reason||(ge?"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:Q?"Choice made":"Choose a product"})]})},S.item.line_id)})}),(0,s.jsx)("button",{type:"button",className:"review-gate-skip",onClick:v0,children:"Skip all"}),Ec.length>0?(0,s.jsxs)("div",{className:"review-gate-skipped",children:[(0,s.jsx)("strong",{children:"Skipped"}),Ec.map(S=>(0,s.jsxs)("button",{type:"button",className:"review-gate-item is-skipped",onClick:()=>{x(Q=>{let ge=new Set(Q);return ge.delete(S.item.line_id),ge}),U(!0),Rn(S.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Zr(S.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"})]},S.item.line_id))]}):null]})}),z&&(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 ",f?"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:()=>H(!1),children:"Cancel"}),(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-danger",onClick:()=>{H(!1),t()},autoFocus:!0,children:"Start Over"})]})]})})]})}var Ya=$(ee()),Pd="metron-quick-quote",ox=1440*60*1e3;function uc(e){return(0,Ya.jsx)(lc,{children:(0,Ya.jsx)(lx,{...e})})}function lx({fullPage:e=!1,hideHeader:t=!1,internal:a=!1}){let[r,n]=(0,Ge.useState)("entry"),[i,o]=(0,Ge.useState)(null),l=(0,Ge.useRef)(null),c=(0,Ge.useRef)(0),[p,m]=(0,Ge.useState)(0),[f,d]=(0,Ge.useState)(null),[g,w]=(0,Ge.useState)(!1),{cart:A,addToCart:L,addManyToCart:h,removeFromCart:u,updateCartQty:b,updateCartSellUnits:v,updateCartConversions:_,clearCart:C}=Di(),[R,T]=(0,Ge.useState)(!1),[D,V]=(0,Ge.useState)(null),oe=()=>{V(null);try{window.sessionStorage.removeItem(oc)}catch{}},_e=(0,Ge.useRef)(null),Te=Js("quick-quote",_e);(0,Ge.useEffect)(()=>{Te("viewed")},[Te]);let[Oe,xe]=(0,Ge.useState)(!1);(0,Ge.useEffect)(()=>{_v();let qe=window.location.hash,ke=null;try{ke=JSON.parse(window.sessionStorage.getItem(Pd)??"null")}catch{}if(ke&&!(Date.now()-(ke.savedAt??0)<ox)&&(ke=null),ke?.scheduleResult)o("schedule"),d(ke.scheduleResult),w(ke.reviewGateComplete),T(ke.cartSeeded),h(Object.values(ke.cart)),qe==="#quote-request"?n("basket"):qe==="#matched-products"&&n("results");else if(qe==="#matched-products"||qe==="#quote-request"){let Be=new URL(window.location.href);Be.hash="",Ri("replaceState",window.history.state,Be)}xe(!0)},[]),(0,Ge.useEffect)(()=>{if(Oe)try{f?window.sessionStorage.setItem(Pd,JSON.stringify({savedAt:Date.now(),scheduleResult:f,reviewGateComplete:g,cartSeeded:R,cart:A})):window.sessionStorage.removeItem(Pd)}catch{}},[Oe,f,g,R,A]);let X=(0,Ge.useCallback)(qe=>{if(typeof window>"u")return;let ke=new URL(window.location.href);ke.hash=qe==="basket"?"quote-request":"matched-products";let Be=qe==="results"&&(window.location.hash==="#matched-products"||window.location.hash==="#quote-request");Ri(Be?"replaceState":"pushState",{boqQuoteStage:qe},ke)},[]),J=(0,Ge.useRef)(!1);(0,Ge.useEffect)(()=>{let qe=()=>{J.current=!1;let ke=window.location.hash;ke==="#quote-request"?n("basket"):ke==="#matched-products"&&f?(o("schedule"),n("results")):n("entry")};return window.addEventListener("popstate",qe),()=>window.removeEventListener("popstate",qe)},[f]);let ze=(0,Ge.useCallback)(()=>{X("basket"),n("basket")},[X]),Ee=(0,Ge.useCallback)(()=>{if(window.location.hash==="#quote-request"){if(J.current)return;J.current=!0,ic();return}n(f?"results":"entry")},[f]),wt=(0,Ge.useRef)(r);(0,Ge.useEffect)(()=>{wt.current!==r&&(wt.current=r,window.scrollTo(0,0))},[r]);let P=()=>{n("entry"),o(null),m(0),d(null),w(!1),C(),T(!1),oe()},pe=(0,Ge.useCallback)(async(qe,ke,Be=!0)=>{let Ye=++c.current;m(0);let vt=0,z=()=>{vt=Math.min(vt+1,3),m(vt)};try{let{jobId:H}=await Ew(qe,ke,Be);if(Ye!==c.current)return;let{promise:le,cancel:de}=Tw(()=>Mw(H),5e3,z,"schedule");l.current=de;let me=await le;if(me.status==="failed"||!me.result)throw new Error(me.error||"Failed to process schedule");let $e=me.result.lineItems.length,Le=me.result.results.filter(k=>k.candidates.length>0).length;Te("results_shown",{lines:$e,matched:Le,unmatched:$e-Le}),C(),T(!1),w(!1),d(me.result),X("results"),n("results")}catch(H){if(Ye!==c.current)return;throw Te("error",{stage:"matching"}),H}finally{Ye===c.current&&(l.current?.(),l.current=null)}},[X,Te,C]),Re=(0,Ge.useCallback)(()=>{c.current++,l.current?.(),l.current=null},[]),Ot=(0,Ge.useCallback)(async(qe,ke,Be=!0)=>{if(!qe.trim())return;o("schedule");let Ye=new File([qe],"pasted-schedule.txt",{type:"text/plain"});await pe(Ye,ke,Be)},[pe]),jt=(0,Ge.useCallback)(async qe=>{o("schedule"),await pe(qe)},[pe]);return(0,Ya.jsx)(tl.Provider,{value:Te,children:(0,Ya.jsx)("div",{ref:_e,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${!e&&r==="processing"?" app-wrapper--loading":""}`,style:Dt().theme,children:(0,Ya.jsxs)("main",{className:"main-content",children:[r==="entry"&&(0,Ya.jsx)(Cd,{onPasteSchedule:Ot,onUploadSchedule:jt,onEntryModeChange:o,draft:D,onSubmitDraft:V,onCancelMatch:Re}),r==="results"&&i==="schedule"&&f&&(0,Ya.jsx)(Zd,{scheduleResult:f,onStartOver:P,cart:A,onAddToCart:L,onRemoveFromCart:u,onGoToBasket:ze,cartSeeded:R,onCartSeeded:()=>T(!0),reviewGateComplete:g,onReviewGateComplete:()=>w(!0),internal:a}),r==="basket"&&(0,Ya.jsx)(ul,{cart:A,onUpdateQty:b,onUpdateSellUnits:v,onResolveConversions:_,onRemove:u,onBack:Ee,onStartNewQuote:P,onQuoteRequested:()=>{d(null),w(!1),T(!1),C(),oe()},internal:a})]})})})}var Va=$(Ve());var Nn=$(Ve());var Hv={"NZ4Y-ZMSQ":{"brick-block":{"brick-common":"105499","brick-engineering-red":"1654","brick-engineering-blue":"1723",block:"501","mortar-cement":"1762 cement","mortar-sand":"564 building sand"},skirting:{"skirting-chamfered":"1525","skirting-ogee":"135 primed mdf ogee","skirting-pencil-round":"892","skirting-torus":"1941"},architrave:{"architrave-ogee":"134 primed mdf ogee","architrave-pencil-round":"1896","architrave-square-edge":"118 primed mdf square","architrave-torus":"1531"},plasterboard:{standard:"1647",moisture:"11 moisture plasterboard",fire:"14 fire plasterboard",sound:"1769",screws:"131160",tape:"1766",adhesive:"108439"},paint:{"paint-emulsion":"157217"},"concrete-aggregate":{cement:"1762 cement","sharp-sand":"563",gravel:"571",mot:"569"},insulation:{"insulation-floor":"152187","insulation-ground":"442","insulation-wall":"147","insulation-roof":"442","insulation-loft":"152180"},timber:{studs:"1213",joists:"208",battens:"1729"},fencing:{"panels-boundary-0.9":"66 lap fence panel","panels-boundary-1.2":"1450","panels-boundary-1.5":"1449","panels-boundary-1.8":"1448","panels-skyline-1.8":"1475","concrete-intermediate-8":"40197","concrete-end-8":"40198","timber-post-6":"141411","timber-post-8":"1709",postcrete:"12142","gate-boundary":"1984","gate-skyline":"40002","gravel-boards":"40200"},decking:{"boards-summit":"24322",joists:"208",screws:"131079"},paving:{"surface-council":"1669","surface-raj":"12363","surface-brindle":"304","surface-charcoal":"296","surface-pea":"431","sub-base":"569",bedding:"563"}}};function dl(e,t){let a=Hv[Dt().client??""]?.[e];if(!a)return null;let r=e==="plasterboard"&&t.key==="board"?t.label.split(" ")[0].toLowerCase():t.key;return a[r]??null}function Sn(e,t){let a=Hv[Dt().client??""]?.[e];return!a||t in a}function Qv(e,t){let a=t.map(r=>{let n=dl(e,r);return n?{key:r.key,productId:n.split(" ")[0],search:n,qty:r.qty,unit:r.unit}:null});return a.length>0&&a.every(Boolean)?a:null}var ae=$(ee()),Gv=[{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"}],pc=e=>Number.parseFloat(e)||0,jv=(e,t)=>pc(e)*(t==="m"?1:.3048),Kd=(e,t)=>pc(e.quantity)*(2*jv(e.height,t)+jv(e.width,t)),sx=()=>({quantity:"1",width:"",height:""});function cx({profile:e}){return(0,ae.jsxs)("svg",{className:"architrave-calculator__profile-diagram",viewBox:"0 0 112 76","aria-hidden":"true",children:[(0,ae.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,ae.jsx)("line",{x1:"12",y1:"66",x2:"100",y2:"66"})]})}function Jd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Nn.useState)("m"),[i,o]=(0,Nn.useState)({quantity:"1",width:"0.76",height:"1.98"}),[l,c]=(0,Nn.useState)({quantity:"0",width:"1.52",height:"1.98"}),[p,m]=(0,Nn.useState)([]),[f,d]=(0,Nn.useState)("ogee"),[g,w]=(0,Nn.useState)("2.4"),A=(_,C,R)=>{_(T=>({...T,[C]:R}))},L=Kd(i,r)+Kd(l,r)+p.reduce((_,C)=>_+Kd(C,r),0),h=pc(g)>0?Math.ceil(L/pc(g)):0,u=Gv.find(_=>_.id===f)?.label??"",b=[{key:`architrave-${f}`,label:`Architrave (${u})`,qty:L,unit:"m",query:`${u} architrave`,category:"architrave"}],v=(_,C,R,T)=>(0,ae.jsxs)("div",{className:"architrave-calculator__opening-row",children:[(0,ae.jsx)("span",{children:_}),(0,ae.jsx)("input",{"aria-label":`${_} quantity`,type:"number",min:"0",step:"1",value:C.quantity,onChange:D=>R("quantity",D.target.value)}),(0,ae.jsx)("input",{"aria-label":`${_} width`,type:"number",min:"0",step:"0.01",value:C.width,onChange:D=>R("width",D.target.value)}),(0,ae.jsx)("input",{"aria-label":`${_} height`,type:"number",min:"0",step:"0.01",value:C.height,onChange:D=>R("height",D.target.value)}),T?(0,ae.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:T,children:"Remove"}):null]});return(0,ae.jsx)(ae.Fragment,{children:(0,ae.jsxs)("div",{className:"truss-estimator",children:[(0,ae.jsxs)("div",{className:"quick-order-hero",children:[(0,ae.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ae.jsx)("h1",{children:"Architrave Calculator"}),(0,ae.jsx)("p",{children:"Estimate architrave lengths and board quantities for door openings."})]}),(0,ae.jsxs)("div",{className:"truss-estimator__card architrave-calculator",children:[(0,ae.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure your openings"}),(0,ae.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,ae.jsxs)("div",{className:"architrave-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Door openings"}),(0,ae.jsx)("p",{className:"architrave-calculator__hint",children:"Each opening is calculated as two side pieces plus one head piece."}),(0,ae.jsxs)("div",{className:"architrave-calculator__unit-row",children:[(0,ae.jsx)("span",{children:"Units"}),(0,ae.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,ae.jsx)("button",{type:"button",className:r==="m"?"is-selected":"",onClick:()=>n("m"),children:"Metres"}),(0,ae.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>n("ft"),children:"Feet"})]})]}),(0,ae.jsxs)("div",{className:"architrave-calculator__dimensions-header",children:[(0,ae.jsx)("span",{children:"Opening"}),(0,ae.jsx)("span",{children:"Qty"}),(0,ae.jsxs)("span",{children:["Width (",r,")"]}),(0,ae.jsxs)("span",{children:["Height (",r,")"]}),(0,ae.jsx)("span",{})]}),v("Single doors",i,(_,C)=>A(o,_,C)),v("Double doors",l,(_,C)=>A(c,_,C)),p.map((_,C)=>v(`Alternative door ${C+1}`,_,(R,T)=>m(D=>D.map((V,oe)=>oe===C?{...V,[R]:T}:V)),()=>m(R=>R.filter((T,D)=>D!==C)))),(0,ae.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>m(_=>[..._,sx()]),children:"+ Add alternative-sized door"})]}),(0,ae.jsxs)("div",{className:"architrave-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Standard profile"}),(0,ae.jsx)("p",{className:"architrave-calculator__hint",children:"Choose the profile you plan to use. Length calculations are the same for each profile."}),(0,ae.jsx)("div",{className:"architrave-calculator__profiles",children:Gv.filter(_=>Sn("architrave",`architrave-${_.id}`)).map(_=>(0,ae.jsxs)("button",{type:"button",className:`truss-estimator__option-card${f===_.id?" is-selected":""}`,onClick:()=>d(_.id),children:[(0,ae.jsx)(cx,{profile:_.id}),(0,ae.jsx)("div",{className:"truss-estimator__option-title",children:_.label}),(0,ae.jsx)("div",{className:"truss-estimator__option-copy",children:_.blurb})]},_.id))})]}),(0,ae.jsxs)("div",{className:"architrave-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,ae.jsx)("div",{className:"architrave-calculator__options",children:(0,ae.jsxs)("label",{className:"truss-estimator__field",children:[(0,ae.jsx)("span",{children:"Board length (m)"}),(0,ae.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,ae.jsx)("p",{className:"architrave-calculator__hint",children:"Waste allows for mitred corners, cuts and damaged lengths."})]}),(0,ae.jsxs)("div",{className:"architrave-calculator__totals",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ae.jsxs)("div",{className:"architrave-calculator__result-grid",children:[(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Architrave needed"}),(0,ae.jsxs)("strong",{children:[L.toFixed(2)," m"]})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Board lengths"}),(0,ae.jsx)("strong",{children:h})]})]})]}),(0,ae.jsxs)("div",{className:"architrave-calculator__actions",children:[(0,ae.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ae.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(b),disabled:L<=0,children:a})]})]})]})})}var Cn=$(Ve()),ne=$(ee()),Yv=60,$v=10,ux=.02,px=.012,Vv=1,Xv=4,dx=1.33,mx=1440,fx=1600,Qi=e=>Number.parseFloat(e)||0,hx=(e,t=2)=>e.toFixed(t);function Id({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Cn.useState)("brick"),[i,o]=(0,Cn.useState)("engineering-red"),[l,c]=(0,Cn.useState)("metric"),[p,m]=(0,Cn.useState)(""),[f,d]=(0,Cn.useState)(""),[g,w]=(0,Cn.useState)(!0),A=l==="metric"?Qi(p)*Qi(f):Qi(p)*Qi(f)*.092903,h=A*(r==="brick"?Yv:$v),u=Math.ceil(h),v=A*(r==="brick"?ux:px)*dx/(Vv+Xv),_=Math.ceil(v*Vv*mx),C=Math.ceil(v*Xv*fx),R=l==="metric"?A:A*10.7639,T=[{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"},...g?[{key:"mortar-cement",label:"General purpose cement",qty:_,unit:"kg",query:"general purpose cement",category:"cement"},{key:"mortar-sand",label:"Building sand",qty:C,unit:"kg",query:"building sand",category:"aggregate"}]:[]],D=V=>{if(V===l)return;let oe=V==="imperial"?3.28084:.3048;m((Qi(p)*oe).toFixed(2)),d((Qi(f)*oe).toFixed(2)),c(V)};return(0,ne.jsx)(ne.Fragment,{children:(0,ne.jsxs)("div",{className:"truss-estimator",children:[(0,ne.jsxs)("div",{className:"quick-order-hero",children:[(0,ne.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ne.jsx)("h1",{children:"Brick and Block Calculator"}),(0,ne.jsx)("p",{children:"Estimate masonry units, sand and cement for a wall."})]}),(0,ne.jsxs)("div",{className:"truss-estimator__card brick-calculator",children:[(0,ne.jsx)("h2",{className:"truss-estimator__step-title",children:"Wall area and masonry type"}),(0,ne.jsx)("p",{className:"truss-estimator__step-sub",children:"Pick brick or block and enter the wall dimensions for unit counts plus the cement and sand for the mortar."}),(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Masonry type"}),(0,ne.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["brick","Brick"],["block","Block"]].map(([V,oe])=>(0,ne.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===V?" is-selected":""}`,onClick:()=>n(V),children:[(0,ne.jsx)("div",{className:"truss-estimator__option-title",children:oe}),(0,ne.jsxs)("div",{className:"truss-estimator__option-copy",children:["Approx. ",V==="brick"?Yv:$v," per m\xB2"]})]},V))})]}),r==="brick"&&(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Brick type"}),(0,ne.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(([V,oe,_e])=>(0,ne.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i===V?" is-selected":""}`,onClick:()=>o(V),children:[(0,ne.jsx)("div",{className:"truss-estimator__option-title",children:oe}),(0,ne.jsx)("div",{className:"truss-estimator__option-copy",children:_e})]},V))})]}),(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,ne.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,ne.jsx)("button",{type:"button",className:l==="metric"?"is-selected":"",onClick:()=>D("metric"),children:"Metric"}),(0,ne.jsx)("button",{type:"button",className:l==="imperial"?"is-selected":"",onClick:()=>D("imperial"),children:"Imperial"})]}),(0,ne.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsxs)("span",{children:["Height (",l==="metric"?"m":"ft",")"]}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:V=>m(V.target.value)})]}),(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsxs)("span",{children:["Width (",l==="metric"?"m":"ft",")"]}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:f,onChange:V=>d(V.target.value)})]})]})]}),(0,ne.jsx)("div",{className:"brick-calculator__options",children:(0,ne.jsxs)("label",{className:"brick-calculator__checkbox",children:[(0,ne.jsx)("input",{type:"checkbox",checked:g,onChange:V=>w(V.target.checked)}),(0,ne.jsx)("span",{children:"Include mortar (cement and building sand, mixed 1:4)"})]})}),(0,ne.jsxs)("div",{className:"brick-calculator__totals",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ne.jsxs)("div",{className:"brick-calculator__result-grid",children:[(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Wall area"}),(0,ne.jsxs)("strong",{children:[hx(R)," ",l==="metric"?"m\xB2":"ft\xB2"]})]}),(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:r==="brick"?"Bricks":"Blocks"}),(0,ne.jsx)("strong",{children:u.toLocaleString("en-GB")})]}),g?(0,ne.jsxs)(ne.Fragment,{children:[(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Cement"}),(0,ne.jsxs)("strong",{children:[_," kg"]})]}),(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Building sand"}),(0,ne.jsxs)("strong",{children:[C," kg"]})]})]}):null]}),(0,ne.jsx)("p",{className:"brick-calculator__note",children:"Estimate based on standard nominal sizes and 10mm joints. Mortar is a general purpose 1:4 cement and sand mix; quantities are approximate, so confirm the specification before ordering."})]}),(0,ne.jsxs)("div",{className:"brick-calculator__actions",children:[(0,ne.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ne.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(T),disabled:A<=0,children:a})]})]})]})})}var qn=$(Ve()),te=$(ee()),gx=1.54,bx=1440,Fd=e=>Number.parseFloat(e)||0,Kr={mot:{label:"MOT Type 1",blurb:"Sub-base for patios and driveways",density:1.7,query:"MOT type 1"},"sharp-sand":{label:"Sharp sand",blurb:"Bedding and general groundwork",density:1.6,query:"sharp sand"},gravel:{label:"20mm gravel",blurb:"Drainage and landscaping",density:1.6,query:"20mm gravel"}};function Wd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,qn.useState)("m"),[i,o]=(0,qn.useState)(""),[l,c]=(0,qn.useState)(""),[p,m]=(0,qn.useState)(""),[f,d]=(0,qn.useState)("concrete"),[g,w]=(0,qn.useState)("mot"),A=r==="m"?1:.3048,L=Fd(i)*A*Fd(l)*A*Fd(p)*(r==="m"?.01:.0254),h=Kr[g],u=L*gx/7,b=u*bx,v=u*2,_=u*4,C=(T,D)=>Math.ceil(T*D*1e3),R=f==="concrete"?[{key:"cement",label:"General purpose cement",qty:Math.ceil(b),unit:"kg",query:"general purpose cement"},{key:"sharp-sand",label:"Sharp sand",qty:C(v,Kr["sharp-sand"].density),unit:"kg",query:Kr["sharp-sand"].query},{key:"gravel",label:"20mm gravel",qty:C(_,Kr.gravel.density),unit:"kg",query:Kr.gravel.query}]:[{key:g,label:h.label,qty:C(L,h.density),unit:"kg",query:h.query}];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:"Concrete and Aggregate Calculator"}),(0,te.jsx)("p",{children:"Calculate fixed site-mix concrete ingredients or aggregate bulk bags."})]}),(0,te.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,te.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose what you need"}),(0,te.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter the area and depth. The calculator works out the materials and adds them to your basket."}),(0,te.jsxs)("div",{className:"materials-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Material type"}),(0,te.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${f==="concrete"?" is-selected":""}`,onClick:()=>d("concrete"),children:[(0,te.jsx)("div",{className:"truss-estimator__option-title",children:"Site-mixed concrete"}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:"Cement, sharp sand and 20mm aggregate"})]}),(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${f==="aggregate"?" is-selected":""}`,onClick:()=>d("aggregate"),children:[(0,te.jsx)("div",{className:"truss-estimator__option-title",children:"Aggregates"}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:"MOT Type 1, sharp sand or 20mm gravel"})]})]})]}),f==="aggregate"&&(0,te.jsxs)("div",{className:"materials-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Aggregate type"}),(0,te.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.keys(Kr).map(T=>(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g===T?" is-selected":""}`,onClick:()=>w(T),children:[(0,te.jsx)("div",{className:"truss-estimator__option-title",children:Kr[T].label}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:Kr[T].blurb})]},T))})]}),(0,te.jsxs)("div",{className:"materials-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and depth"}),(0,te.jsxs)("div",{className:"materials-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:"Metric"}),(0,te.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>n("ft"),children:"Imperial"})]})]}),(0,te.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,te.jsxs)("label",{className:"truss-estimator__field",children:[(0,te.jsxs)("span",{children:["Length (",r,")"]}),(0,te.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:T=>o(T.target.value)})]}),(0,te.jsxs)("label",{className:"truss-estimator__field",children:[(0,te.jsxs)("span",{children:["Width (",r,")"]}),(0,te.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:T=>c(T.target.value)})]})]}),(0,te.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,te.jsxs)("span",{children:["Depth (",r==="m"?"cm":"inches",")"]}),(0,te.jsx)("input",{type:"number",min:"0",step:"0.1",value:p,onChange:T=>m(T.target.value)})]})]}),(0,te.jsxs)("div",{className:"materials-calculator__totals",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Materials required"}),(0,te.jsx)("div",{className:"materials-calculator__result-grid",children:f==="concrete"?(0,te.jsxs)(te.Fragment,{children:[(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Cement"}),(0,te.jsxs)("strong",{children:[b.toFixed(0)," kg"]})]}),(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Sharp sand"}),(0,te.jsxs)("strong",{children:[v.toFixed(2)," m\xB3"]})]}),(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"20mm aggregate"}),(0,te.jsxs)("strong",{children:[_.toFixed(2)," m\xB3"]})]})]}):(0,te.jsxs)(te.Fragment,{children:[(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:h.label}),(0,te.jsxs)("strong",{children:[L.toFixed(2)," m\xB3"]})]}),(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Approx. weight"}),(0,te.jsxs)("strong",{children:[(L*h.density).toFixed(2)," t"]})]}),(0,te.jsx)("div",{})]})}),(0,te.jsx)("p",{className:"materials-calculator__note",children:f==="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."})]}),(0,te.jsxs)("div",{className:"materials-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?.(R),disabled:L<=0,children:a})]})]})]})})}var $a=$(Ve());var O=$(ee()),Gi=12,ji=8,dc=.56,Zv=.21,Ra={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:{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}]}},En=["range","grid","pictureFrame","substructure"],wx={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:""}},mc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),fc=(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),vx=(e,t,a,r)=>{let n=mc(e,t,a),i=mc(e,t,r),o=mc(a,r,e),l=mc(a,r,t);return n===0&&fc(e,t,a)||i===0&&fc(e,t,r)||o===0&&fc(a,r,e)||l===0&&fc(a,r,t)?!0:n>0!=i>0&&o>0!=l>0},em=(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)&&vx(e[r],n,e[i],e[(i+1)%e.length]))return!0}return!1};function tm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,$a.useState)(0),[i,o]=(0,$a.useState)(wx),[l,c]=(0,$a.useState)(1),[p,m]=(0,$a.useState)({x:0,y:0}),[f,d]=(0,$a.useState)(null),g=(0,$a.useRef)(null),w=(0,$a.useRef)(null),A=(0,$a.useRef)(null),L=En[r],h=i.range?Ra.ranges[i.range]:null,u=Gi/l,b=ji/l,v=(Gi-u)/2,_=(ji-b)/2,C=Math.max(-Gi,Math.min(Gi*2-u,v+p.x)),R=Math.max(-ji,Math.min(ji*2-b,_+p.y)),T=Number.parseFloat(i.quickLengthM),D=Number.parseFloat(i.quickWidthM),V=T>0&&D>0,oe=z=>Math.abs(z.reduce((H,le,de)=>{let me=z[(de+1)%z.length];return H+le.x*me.y-me.x*le.y},0))/2,_e=(z,H)=>Math.hypot(H.x-z.x,H.y-z.y),Te=i.isOutlineClosed?oe(i.points):0,Oe=i.isOutlineClosed?i.points.reduce((z,H,le)=>z+_e(H,i.points[(le+1)%i.points.length]),0):0,xe=i.isOutlineClosed?i.points.reduce((z,H,le)=>z+(i.wallSegments.has(le)?0:_e(H,i.points[(le+1)%i.points.length])),0):0,X=i.points.reduce((z,H)=>({x:z.x+H.x/i.points.length,y:z.y+H.y/i.points.length}),{x:0,y:0}),J=i.points.length>1?(()=>{let z=i.points[0],H=i.points[1],le=_e(z,H),de=le?-(H.y-z.y)/le:0,me=le?(H.x-z.x)/le:0,$e=(z.x+H.x)/2,Le=(z.y+H.y)/2,k=de*($e-X.x)+me*(Le-X.y)>=0?1:-1;return{x:$e+de*dc*k,y:Le+me*dc*k}})():null,Ee=(()=>{let z=i.range?Ra.ranges[i.range]:Ra.ranges.meridian,H=i.deckSizeMode==="quick"?T*D:Te,le=i.deckSizeMode==="quick"?2*(T+D):xe,de=i.direction==="diagonal"?Ra.wastage.diagonal:Ra.wastage.straight,me=i.pictureFrame==="yes"?Ra.pictureFrame.extraWastage:0,Le=H/(z.boardWidthM+Ra.boardGapM)/z.boardLengthM,k=Math.ceil(Le*(1+de+me)),x=Math.ceil(H*30*(1+de+me)/200),E=Ra.joist.spacingOptions.find(N=>N.id===i.joistSpacing)??Ra.joist.spacingOptions[1],U=H/E.spacingM,Z=Math.ceil(U);return{range:z,area:H,boardCount:k,screwBoxes:x,joistMetres:Z,spacing:E}})(),wt=Ee?[{key:`boards-${i.range??"meridian"}`,label:`Deck boards (${Ee.range.label})`,qty:Math.round(Ee.boardCount*Ee.range.boardLengthM*100)/100,unit:"m",query:"timber decking board",category:"decking",calculatorWasteIncluded:!0},{key:"joists",label:"Treated C24 joists",qty:Ee.joistMetres,unit:"m",query:"treated joist",category:"timber",calculatorWasteIncluded:!0},{key:"screws",label:"Green decking screws (200/box)",qty:Ee.screwBoxes,unit:"box",query:"green decking screws",category:"fixings",calculatorWasteIncluded:!0}]:[],P=()=>L==="range"?!!i.range:L==="grid"?i.deckSizeMode==="quick"?V:i.isOutlineClosed&&Te>0:L==="pictureFrame"?!!i.pictureFrame&&!!i.direction:L==="substructure"?!!i.joistSpacing:!0,pe=r===En.length-1?a:"Next",Re=(z,H,le=!1)=>{let de=A.current?.getBoundingClientRect();if(!de)return null;let me=le?1:.25;return{x:Math.round(Math.max(C,Math.min(C+u,C+(z-de.left)/de.width*u))/me)*me,y:Math.round(Math.max(R,Math.min(R+b,R+(H-de.top)/de.height*b))/me)*me}},Ot=z=>{if(i.isOutlineClosed){let le=z.target;if(le!==z.currentTarget&&!le.classList.contains("deck-outline__grid"))return;w.current={startX:z.clientX,startY:z.clientY,startViewX:C,startViewY:R},z.currentTarget.setPointerCapture(z.pointerId);return}if(i.drawMode!=="outline")return;let H=Re(z.clientX,z.clientY,!0);H&&(d(null),o(le=>{let de=[...le.points,H];return em(de,!1)?{...le,drawError:"Edges cannot cross. Choose another corner."}:{...le,points:de,drawError:""}}))},jt=(z,H)=>{if(!i.isOutlineClosed){z.stopPropagation(),H===0&&i.points.length>=3&&o(le=>({...le,isOutlineClosed:!0,drawMode:"edges"}));return}z.stopPropagation(),g.current=H,z.currentTarget.setPointerCapture(z.pointerId)},qe=z=>{if(w.current){let de=A.current?.getBoundingClientRect();if(!de)return;let me=w.current,$e=me.startViewX-(z.clientX-me.startX)/de.width*u,Le=me.startViewY-(z.clientY-me.startY)/de.height*b;m({x:$e-v,y:Le-_});return}!i.isOutlineClosed&&i.drawMode==="outline"&&d(Re(z.clientX,z.clientY,!0));let H=g.current;if(H===null)return;let le=Re(z.clientX,z.clientY);le&&o(de=>{let me=de.points.map(($e,Le)=>Le===H?le:$e);return em(me,!0)?{...de,drawError:"Edges cannot cross. Move the corner to a different position."}:{...de,points:me,drawError:""}})},ke=z=>{w.current=null,g.current=null,z.currentTarget.hasPointerCapture(z.pointerId)&&z.currentTarget.releasePointerCapture(z.pointerId)},Be=z=>{o(H=>{let le=new Set(H.wallSegments);return le.has(z)?le.delete(z):le.add(z),{...H,wallSegments:le}})},Ye=()=>{r===0?e():n(z=>z-1)},vt=()=>{P()&&(r===En.length-1?t?.(wt):n(z=>z+1))};return(0,O.jsx)(O.Fragment,{children:(0,O.jsxs)("div",{className:"truss-estimator",children:[(0,O.jsxs)("div",{className:"quick-order-hero",children:[(0,O.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,O.jsx)("h1",{children:"Decking Calculator"}),(0,O.jsx)("p",{children:"Estimate timber boards, joists and screws for your deck."})]}),(0,O.jsxs)("div",{className:"truss-estimator__card",children:[(0,O.jsxs)("div",{className:"truss-estimator__body",children:[L==="range"?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",En.length]}),(0,O.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your timber decking"}),(0,O.jsx)("p",{className:"truss-estimator__step-sub",children:"Both options are fixed, orderable pressure-treated timber boards."}),(0,O.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Ra.ranges).filter(([z])=>Sn("decking",`boards-${z}`)).map(([z,H])=>(0,O.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.range===z?" is-selected":""}`,onClick:()=>o(le=>({...le,range:z})),children:[(0,O.jsx)("div",{className:"truss-estimator__option-title",children:H.label}),(0,O.jsx)("div",{className:"truss-estimator__option-copy",children:H.blurb}),(0,O.jsxs)("div",{className:"truss-estimator__option-copy",children:[H.boardLengthM,"m boards"]})]},z))})]}):null,L==="grid"?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",En.length]}),(0,O.jsx)("h2",{className:"truss-estimator__step-title",children:"Tell us your deck size"}),(0,O.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,O.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,O.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.deckSizeMode==="quick"?" is-selected":""}`,onClick:()=>o(z=>({...z,deckSizeMode:"quick"})),children:"Quick estimate"}),(0,O.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.deckSizeMode==="draw"?" is-selected":""}`,onClick:()=>o(z=>({...z,deckSizeMode:"draw",drawMode:"outline"})),children:"Draw your space"})]}),i.deckSizeMode==="quick"?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,O.jsxs)("label",{className:"truss-estimator__field",children:[(0,O.jsx)("span",{children:"Length (m)"}),(0,O.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:i.quickLengthM,onChange:z=>o(H=>({...H,quickLengthM:z.target.value}))})]}),(0,O.jsxs)("label",{className:"truss-estimator__field",children:[(0,O.jsx)("span",{children:"Width (m)"}),(0,O.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:i.quickWidthM,onChange:z=>o(H=>({...H,quickWidthM:z.target.value}))})]})]}),(0,O.jsx)("div",{className:"truss-estimator__grid-hint",children:"For L-shaped decks, cut-outs, or sides against a wall, use Draw your space."}),V?(0,O.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,O.jsxs)("div",{children:[(T*D).toFixed(2)," m\xB2 deck"]}),(0,O.jsxs)("div",{children:[(2*(T+D)).toFixed(2)," m perimeter"]})]}):null]}):(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)("div",{className:"truss-estimator__section-heading",children:"Draw your deck"}),(0,O.jsx)("p",{className:"truss-estimator__step-sub",children:"Click to add corners, then close the outline. Drag any handle to refine it."}),(0,O.jsxs)("div",{className:"deck-outline__toolbar",children:[i.isOutlineClosed?(0,O.jsxs)("div",{className:"deck-outline__summary",children:[(0,O.jsxs)("div",{children:[(0,O.jsx)("span",{children:"Deck area"}),(0,O.jsxs)("strong",{children:[Te.toFixed(2)," m\xB2"]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)("span",{children:"Perimeter"}),(0,O.jsxs)("strong",{children:[Oe.toFixed(2)," m"]})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)("span",{children:"Wall edges"}),(0,O.jsx)("strong",{children:i.wallSegments.size>0?i.wallSegments.size:"None"})]}),(0,O.jsxs)("div",{children:[(0,O.jsx)("span",{children:"Visible edge"}),(0,O.jsxs)("strong",{children:[xe.toFixed(2)," m"]})]})]}):null,(0,O.jsxs)("div",{className:"deck-outline__actions",children:[(0,O.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(z=>({...z,points:z.points.slice(0,-1)})),disabled:i.points.length===0||i.isOutlineClosed,children:"Undo"}),(0,O.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{d(null),o(z=>({...z,points:[],isOutlineClosed:!1,wallSegments:new Set,drawMode:"outline",drawError:""}))},disabled:i.points.length===0,children:"Clear"}),(0,O.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(z=>({...z,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,O.jsx)("div",{className:"deck-editor-layout",children:(0,O.jsxs)("div",{className:"deck-editor-layout__canvas-column",children:[(0,O.jsxs)("div",{className:"deck-outline",children:[(0,O.jsxs)("svg",{ref:A,className:`deck-outline__canvas${i.isOutlineClosed?" is-pan-mode":""}`,viewBox:`${C} ${R} ${u} ${b}`,preserveAspectRatio:"none","aria-label":"Deck outline drawing area",onPointerDown:Ot,onPointerMove:qe,onPointerUp:ke,onPointerLeave:()=>{d(null),w.current||(g.current=null)},children:[(0,O.jsx)("defs",{children:(0,O.jsx)("pattern",{id:"deck-outline-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,O.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,O.jsx)("rect",{x:-Gi,y:-ji,width:Gi*3,height:ji*3,className:"deck-outline__grid",fill:"url(#deck-outline-grid)"}),i.points.length>1?(0,O.jsx)("polyline",{className:"deck-outline__preview",points:i.points.map(z=>`${z.x},${z.y}`).join(" ")}):null,i.isOutlineClosed?(0,O.jsx)("polygon",{className:"deck-outline__shape",points:i.points.map(z=>`${z.x},${z.y}`).join(" "),stroke:"none"}):null,i.points.length>1?i.points.slice(0,i.isOutlineClosed?void 0:-1).map((z,H)=>{let le=i.points[i.isOutlineClosed?(H+1)%i.points.length:H+1],de=_e(z,le),me=de?-(le.y-z.y)/de:0,$e=de?(le.x-z.x)/de:0,Le=(z.x+le.x)/2,k=(z.y+le.y)/2,x=me*(Le-X.x)+$e*(k-X.y)>=0?1:-1,E=Le+me*dc*x,U=k+$e*dc*x;return(0,O.jsxs)("g",{children:[(0,O.jsx)("line",{className:"deck-outline__edge-hit",x1:z.x,y1:z.y,x2:le.x,y2:le.y,onClick:i.isOutlineClosed?()=>Be(H):void 0}),(0,O.jsx)("line",{className:`deck-outline__edge${i.wallSegments.has(H)?" is-wall":""}`,x1:z.x,y1:z.y,x2:le.x,y2:le.y,pointerEvents:"none"}),(0,O.jsxs)("text",{className:`deck-outline__edge-label${i.wallSegments.has(H)?" is-wall":""}`,x:E,y:U,textAnchor:"middle",dominantBaseline:"central",fontSize:Zv/l,children:[de.toFixed(2)," m"]})]},`segment-${H}`)}):null,!i.isOutlineClosed&&i.points.length>0&&f?(()=>{let z=i.points[i.points.length-1],H=_e(z,f);if(!H)return null;let le=-(f.y-z.y)/H,de=(f.x-z.x)/H,me=(z.x+f.x)/2,$e=(z.y+f.y)/2;return(0,O.jsxs)("g",{className:"deck-outline__live-measurement",children:[(0,O.jsx)("line",{x1:z.x,y1:z.y,x2:f.x,y2:f.y}),(0,O.jsxs)("text",{x:me+le*.34,y:$e+de*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:Zv/l,children:[H.toFixed(2)," m"]})]})})():null,i.points.map((z,H)=>(0,O.jsx)("circle",{className:"deck-outline__point",cx:z.x,cy:z.y,r:"0.13",onPointerDown:le=>jt(le,H)},`point-${H}`))]}),(0,O.jsxs)("div",{className:"deck-outline__zoom","aria-label":"Zoom controls",children:[(0,O.jsx)("button",{type:"button",onClick:()=>c(z=>Math.max(.5,z-.25)),disabled:l===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,O.jsxs)("span",{children:[Math.round(l*100),"%"]}),(0,O.jsx)("button",{type:"button",onClick:()=>c(z=>Math.min(1,z+.25)),disabled:l===1,"aria-label":"Zoom in",children:"+"})]}),i.isOutlineClosed&&i.wallSegments.size===0&&J?(0,O.jsx)("div",{className:"deck-outline__edge-prompt",role:"status",style:{left:`${(J.x-C)/u*100}%`,top:`${(J.y-R)/b*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,O.jsx)("button",{type:"button",className:"deck-outline__close",onClick:()=>o(z=>em(z.points,!0)?{...z,drawError:"Edges cannot cross. Adjust the outline before finishing."}:{...z,isOutlineClosed:!0,drawMode:"edges",drawError:""}),children:"Finish outline"}):null]}),(0,O.jsxs)("div",{className:"deck-outline__supporting",children:[(0,O.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,O.jsx)("div",{className:"deck-outline__error",role:"alert",children:i.drawError}):null]})]})})]})]}):null,L==="pictureFrame"?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",En.length]}),(0,O.jsx)("h2",{className:"truss-estimator__step-title",children:"Picture frame border?"}),(0,O.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,O.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(z=>(0,O.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.pictureFrame===z.id?" is-selected":""}`,onClick:()=>o(H=>({...H,pictureFrame:z.id})),children:[(0,O.jsx)("img",{className:"truss-estimator__visual-card-img",src:It(z.img),alt:""}),(0,O.jsx)("span",{children:z.label})]},z.id))}),(0,O.jsxs)(O.Fragment,{children:[(0,O.jsx)("div",{className:"truss-estimator__section-heading",children:"Board direction"}),(0,O.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(z=>(0,O.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.direction===z.id?" is-selected":""}`,onClick:()=>o(H=>({...H,direction:z.id})),children:[(0,O.jsx)("img",{className:"truss-estimator__visual-card-img",src:It(z.img),alt:""}),(0,O.jsx)("span",{children:z.label})]},z.id))})]})]}):null,L==="substructure"?(0,O.jsxs)(O.Fragment,{children:[(0,O.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",En.length]}),(0,O.jsx)("h2",{className:"truss-estimator__step-title",children:"Substructure"}),(0,O.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,O.jsx)("div",{className:"truss-estimator__section-heading",children:"Joist spacing"}),(0,O.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Ra.joist.spacingOptions.map(z=>(0,O.jsx)("button",{type:"button",className:`truss-estimator__option-card${i.joistSpacing===z.id?" is-selected":""}`,onClick:()=>o(H=>({...H,joistSpacing:z.id})),children:(0,O.jsx)("div",{className:"truss-estimator__option-title",children:z.label})},z.id))})]}):null]}),(0,O.jsxs)("div",{className:"truss-estimator__nav",children:[(0,O.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:Ye,children:"Back"}),(0,O.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:vt,disabled:!P(),children:[(0,O.jsx)("span",{children:pe}),(0,O.jsx)("span",{className:"arrow",children:(0,O.jsx)(Qt,{})})]})]})]})]})})}var Sa=$(Ve());var j=$(ee()),Pv=12,Kv=30,Yi=12,$i=8,Jv=.56,ka={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 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}}},Mn=["range","height","gate","posts"],am=e=>Number(e)<=1.2?"6":"8",Iv=(e,t)=>Sn("fencing",`panels-${e??"boundary"}-${t}`),Fv=(e,t)=>!t||Sn("fencing",e==="concrete"?`concrete-intermediate-${am(t)}`:`timber-post-${am(t)}`),yx={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:""}},hc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),gc=(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),_x=(e,t,a,r)=>{let n=hc(e,t,a),i=hc(e,t,r),o=hc(a,r,e),l=hc(a,r,t);return n===0&&gc(e,t,a)||i===0&&gc(e,t,r)||o===0&&gc(a,r,e)||l===0&&gc(a,r,t)?!0:n>0!=i>0&&o>0!=l>0},bc=(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)&&_x(e[r],e[(r+1)%e.length],e[n],e[(n+1)%e.length]))return!0;return!1};function rm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Sa.useState)(0),[i,o]=(0,Sa.useState)(yx),l=(0,Sa.useRef)(null),c=(0,Sa.useRef)(null),[p,m]=(0,Sa.useState)(1),[f,d]=(0,Sa.useState)({x:0,y:0}),[g,w]=(0,Sa.useState)(null),A=(0,Sa.useRef)(null),L=(0,Sa.useRef)(null),h=(0,Sa.useRef)(null),u=Mn[r],b=i.range?ka.ranges[i.range]:null,v=Yi/p,_=$i/p,C=(Yi-v)/2,R=($i-_)/2,T=Math.max(-Yi,Math.min(Yi*2-v,C+f.x)),D=Math.max(-$i,Math.min($i*2-_,R+f.y)),V=i.boundaryPoints.reduce((k,x)=>({x:k.x+x.x/Math.max(1,i.boundaryPoints.length),y:k.y+x.y/Math.max(1,i.boundaryPoints.length)}),{x:0,y:0}),oe=k=>{let x=new Set,E=[];return k.forEach(U=>{let[Z,N]=U.split(",").map(Number),G=[{key:`H,${Z},${N}`,type:"H",x:Z,y:N},{key:`H,${Z},${N+1}`,type:"H",x:Z,y:N+1},{key:`V,${Z},${N}`,type:"V",x:Z,y:N},{key:`V,${Z+1},${N}`,type:"V",x:Z+1,y:N}],Y=[!k.has(`${Z},${N-1}`),!k.has(`${Z},${N+1}`),!k.has(`${Z-1},${N}`),!k.has(`${Z+1},${N}`)];G.forEach((ce,Se)=>{Y[Se]&&!x.has(ce.key)&&(x.add(ce.key),E.push(ce))})}),E},_e=(k,x)=>oe(k).filter(E=>!x.has(E.key)),Te=(k,x)=>_e(k,x).length,Oe=(k,x)=>{let E={};_e(k,x).forEach(Z=>{var N,G,Y,ce;Z.type==="H"?((E[N=`${Z.x},${Z.y}`]||(E[N]=[])).push("H"),(E[G=`${Z.x+1},${Z.y}`]||(E[G]=[])).push("H")):((E[Y=`${Z.x},${Z.y}`]||(E[Y]=[])).push("V"),(E[ce=`${Z.x},${Z.y+1}`]||(E[ce]=[])).push("V"))});let U=0;return Object.values(E).forEach(Z=>{(Z.length===1||Z.length===2&&Z[0]!==Z[1]||Z.length>=3)&&(U+=1)}),U},X=(()=>{let k=i.range?ka.ranges[i.range]:ka.ranges.boundary,x=i.height??"1.8",E=i.boundaryMode==="quick"?Math.max(0,Number.parseFloat(i.quickLengthM)||0):i.boundaryClosed?i.boundaryPoints.slice(0,-1).reduce((Yt,hr,_t)=>Yt+(i.excludedBoundaryEdges.has(_t)?0:Math.hypot(i.boundaryPoints[_t+1].x-hr.x,i.boundaryPoints[_t+1].y-hr.y)),0):0,U=i.gateType&&i.gateType!=="none"?Number.parseFloat(i.gateWidthM)||ka.gate[i.gateType].widthDefault:0,Z=Math.max(0,E-U),N=Z>0?Math.ceil(Z/k.panelWidthM):0,G=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,Y=i.boundaryMode==="quick"?Z>0?2:0:i.boundaryClosed?i.boundaryPoints.slice(0,G?-1:void 0).reduce((Yt,hr,_t)=>{let Zi=_t>0&&!i.excludedBoundaryEdges.has(_t-1),_m=_t<i.boundaryPoints.length-1&&!i.excludedBoundaryEdges.has(_t);return Yt+(Zi||_m?1:0)},0):0,ce=Z>0?Math.ceil(Z/k.panelWidthM)+1:0,Se=Math.max(0,ce-Y),yt=i.mountingType?ka.mounting[i.mountingType]:ka.mounting.concrete,ft=i.gateType&&i.gateType!=="none"?2:0,At=Se+Y+ft,ym=i.mountingType==="postcrete"?At*ka.mounting.postcrete.bagsPerPost:0,Jr=i.gravelBoard==="yes"?N:0;return{range:k,height:x,totalEdgeM:E,fencedLengthM:Z,gateWidthM:U,panelsCount:N,cornerPostCount:Y,intermediatePostCount:Se,gatePostCount:ft,totalPostCount:At,bagsCount:ym,gravelCount:Jr,capCount:At,mounting:yt}})(),J=i.gateType&&i.gateType!=="none"?ka.gate[i.gateType].label:null,ze=am(X.height),Ee=X?[{key:`panels-${i.range??"boundary"}-${X.height}`,label:`${X.range.label} panels (${X.height}m)`,qty:X.panelsCount,unit:"each",query:"fence panel",category:"fencing"},...i.mountingType==="concrete"?[{key:`concrete-intermediate-${ze}`,label:"Intermediate concrete posts",qty:X.intermediatePostCount,unit:"each",query:"concrete fence post",category:"fencing"},{key:`concrete-end-${ze}`,label:"End and corner concrete posts",qty:X.cornerPostCount+X.gatePostCount,unit:"each",query:"concrete end post",category:"fencing"}]:[{key:`timber-post-${ze}`,label:"Timber fence posts",qty:X.totalPostCount,unit:"each",query:"timber fence post",category:"fencing"},{key:"postcrete",label:"Postcrete",qty:X.bagsCount,unit:"bag",query:"postcrete",category:"cement"}],...J?[{key:`gate-${i.range??"boundary"}`,label:i.range==="skyline"?"Single feather edge gate":"Single lap gate",qty:1,unit:"each",query:i.range==="skyline"?"feather edge gate":"lap gate",category:"fencing"}]:[],...X.gravelCount>0?[{key:"gravel-boards",label:"Concrete gravel boards",qty:X.gravelCount,unit:"each",query:"gravel board",category:"fencing"}]:[]]:[],wt=()=>{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},P=r===Mn.length-1?a:"Next",pe=k=>{o(x=>{let E=k(new Set(x.grid)),U=new Set([...x.excludedEdges].filter(Z=>oe(E).some(N=>N.key===Z)));return{...x,grid:E,excludedEdges:U}})},Re=(k,x,E)=>{pe(U=>{let Z=`${k},${x}`;return E?U.add(Z):U.delete(Z),U})},Ot=(k,x,E,U,Z)=>{let N=k,G=x,Y=Math.abs(E-k),ce=k<E?1:-1,Se=-Math.abs(U-x),yt=x<U?1:-1,ft=Y+Se;for(;Re(N,G,Z),!(N===E&&G===U);){let At=2*ft;At>=Se&&(ft+=Se,N+=ce),At<=Y&&(ft+=Y,G+=yt)}},jt=(k,x)=>{let E=c.current?.getBoundingClientRect();if(!E)return null;let U=Math.floor((k-E.left)/Kv),Z=Math.floor((x-E.top)/Kv);return U<0||Z<0||U>=Pv||Z>=Pv?null:{x:U,y:Z}},qe=k=>{if(i.gridMode!=="draw")return;let x=jt(k.clientX,k.clientY);if(!x)return;k.preventDefault();let E=`${x.x},${x.y}`,U=!i.grid.has(E);l.current={active:!0,paintValue:U,lastX:x.x,lastY:x.y},k.currentTarget.setPointerCapture(k.pointerId),Re(x.x,x.y,U)},ke=k=>{let x=l.current;if(!x?.active)return;let E=jt(k.clientX,k.clientY);E&&(E.x===x.lastX&&E.y===x.lastY||(Ot(x.lastX,x.lastY,E.x,E.y,x.paintValue),l.current={...x,lastX:E.x,lastY:E.y}))},Be=k=>{l.current?.active&&(l.current=null,k.currentTarget.releasePointerCapture(k.pointerId))},Ye=(k,x,E=!1)=>{let U=h.current?.getBoundingClientRect();if(!U)return null;let Z=E?1:.25;return{x:Math.round(Math.max(T,Math.min(T+v,T+(k-U.left)/U.width*v))/Z)*Z,y:Math.round(Math.max(D,Math.min(D+_,D+(x-U.top)/U.height*_))/Z)*Z}},vt=k=>{if(i.boundaryClosed){let E=k.target;if(E!==k.currentTarget&&!E.classList.contains("fence-boundary__grid"))return;L.current={startX:k.clientX,startY:k.clientY,startViewX:T,startViewY:D},k.currentTarget.setPointerCapture(k.pointerId);return}let x=Ye(k.clientX,k.clientY,!0);x&&(w(null),o(E=>{let U=[...E.boundaryPoints,x];return bc(U,!1)?{...E}:{...E,boundaryPoints:U}}))},z=(k,x)=>{if(k.stopPropagation(),!i.boundaryClosed){if(x!==0||i.boundaryPoints.length<3)return;o(E=>bc(E.boundaryPoints,!0)?E:{...E,boundaryPoints:[...E.boundaryPoints,E.boundaryPoints[0]],boundaryClosed:!0});return}A.current=x,k.currentTarget.setPointerCapture(k.pointerId)},H=k=>{if(L.current){let E=h.current?.getBoundingClientRect();if(!E)return;let U=L.current,Z=U.startViewX-(k.clientX-U.startX)/E.width*v,N=U.startViewY-(k.clientY-U.startY)/E.height*_;d({x:Z-C,y:N-R});return}if(i.boundaryClosed||w(Ye(k.clientX,k.clientY,!0)),A.current===null)return;let x=Ye(k.clientX,k.clientY);x&&o(E=>{let U=E.boundaryPoints.length>2&&E.boundaryPoints[0].x===E.boundaryPoints[E.boundaryPoints.length-1].x&&E.boundaryPoints[0].y===E.boundaryPoints[E.boundaryPoints.length-1].y,Z=E.boundaryPoints.map((N,G)=>{let Y=G===A.current,ce=U&&A.current===0&&G===E.boundaryPoints.length-1;return Y||ce?x:N});return bc(Z,!1)?E:{...E,boundaryPoints:Z}})},le=k=>{L.current=null,A.current=null,k.currentTarget.hasPointerCapture(k.pointerId)&&k.currentTarget.releasePointerCapture(k.pointerId)},de=k=>{o(x=>{let E=new Set(x.excludedBoundaryEdges);return E.has(k)?E.delete(k):E.add(k),{...x,excludedBoundaryEdges:E}})},me=()=>{r===0?e():n(k=>k-1)},$e=()=>{wt()&&(r===Mn.length-1?t?.(Ee):n(k=>k+1))},Le=oe(i.grid);return(0,j.jsx)(j.Fragment,{children:(0,j.jsxs)("div",{className:"truss-estimator",children:[(0,j.jsxs)("div",{className:"quick-order-hero",children:[(0,j.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,j.jsx)("h1",{children:"Fencing Calculator"}),(0,j.jsx)("p",{children:"Estimate panels, posts and cost for your fence line in a few steps."})]}),(0,j.jsxs)("div",{className:"truss-estimator__card",children:[(0,j.jsxs)("div",{className:"truss-estimator__body",children:[u==="range"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Mn.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your fence panels"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"The calculator uses fixed, orderable timber panels from the catalogue."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(ka.ranges).map(([k,x])=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.range===k?" is-selected":""}`,onClick:()=>o(E=>({...E,range:k,height:E.height&&Iv(k,E.height)?E.height:null})),children:[(0,j.jsx)("div",{className:"truss-estimator__option-title",children:x.label}),(0,j.jsx)("div",{className:"truss-estimator__option-copy",children:x.blurb})]},k))})]}):null,u==="range"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("div",{className:"truss-estimator__section-heading",children:"Measure your fence line"}),(0,j.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,j.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,j.jsx)("button",{type:"button",className:`truss-estimator__toggle${i.boundaryMode==="quick"?" is-selected":""}`,onClick:()=>o(k=>({...k,boundaryMode:"quick"})),children:"Quick estimate"}),(0,j.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,j.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact fence-boundary__quick-field",children:[(0,j.jsx)("span",{children:"Total fence length (m)"}),(0,j.jsx)("input",{type:"number",min:"0",step:"0.1",value:i.quickLengthM,onChange:k=>o(x=>({...x,quickLengthM:k.target.value}))})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("div",{className:"fence-boundary__toolbar",children:(0,j.jsxs)("div",{className:"fence-boundary__actions",children:[(0,j.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,j.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,j.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,j.jsxs)("div",{className:"fence-boundary",children:[(0,j.jsxs)("svg",{ref:h,className:`fence-boundary__canvas${i.boundaryClosed?" is-pan-mode":""}`,viewBox:`${T} ${D} ${v} ${_}`,preserveAspectRatio:"none","aria-label":"Fence boundary drawing area",onPointerDown:vt,onPointerMove:H,onPointerUp:le,onPointerLeave:()=>{w(null),L.current||(A.current=null)},children:[(0,j.jsx)("defs",{children:(0,j.jsx)("pattern",{id:"fence-boundary-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,j.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,j.jsx)("rect",{x:-Yi,y:-$i,width:Yi*3,height:$i*3,className:"fence-boundary__grid",fill:"url(#fence-boundary-grid)"}),i.boundaryPoints.length>1?(0,j.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,x)=>{let E=i.boundaryPoints[x+1],U=Math.hypot(E.x-k.x,E.y-k.y),Z=U?-(E.y-k.y)/U:0,N=U?(E.x-k.x)/U:0,G=(k.x+E.x)/2,Y=(k.y+E.y)/2,ce=Z*(G-V.x)+N*(Y-V.y)>=0?1:-1,Se=G+Z*Jv*ce,yt=Y+N*Jv*ce;return(0,j.jsxs)("g",{children:[(0,j.jsx)("line",{className:"fence-boundary__edge-hit",x1:k.x,y1:k.y,x2:E.x,y2:E.y,onClick:i.boundaryClosed?()=>de(x):void 0}),(0,j.jsx)("line",{className:`fence-boundary__edge${i.excludedBoundaryEdges.has(x)?" is-excluded":""}`,x1:k.x,y1:k.y,x2:E.x,y2:E.y,pointerEvents:"none"}),(0,j.jsxs)("text",{className:`fence-boundary__edge-label${i.excludedBoundaryEdges.has(x)?" is-excluded":""}`,x:Se,y:yt,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[U.toFixed(2)," m"]})]},`fence-edge-${x}`)}):null,!i.boundaryClosed&&i.boundaryPoints.length>0&&g?(()=>{let k=i.boundaryPoints[i.boundaryPoints.length-1],x=Math.hypot(g.x-k.x,g.y-k.y);if(!x)return null;let E=-(g.y-k.y)/x,U=(g.x-k.x)/x,Z=(k.x+g.x)/2,N=(k.y+g.y)/2;return(0,j.jsxs)("g",{className:"fence-boundary__live-measurement",children:[(0,j.jsx)("line",{x1:k.x,y1:k.y,x2:g.x,y2:g.y}),(0,j.jsxs)("text",{x:Z+E*.34,y:N+U*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[x.toFixed(2)," m"]})]})})():null,i.boundaryPoints.map((k,x)=>x>0&&x===i.boundaryPoints.length-1&&k.x===i.boundaryPoints[0]?.x&&k.y===i.boundaryPoints[0]?.y?null:(0,j.jsx)("circle",{className:`fence-boundary__point${!i.boundaryClosed&&x===0&&i.boundaryPoints.length>=3?" is-close-target":""}`,cx:k.x,cy:k.y,r:"0.13",onPointerDown:E=>z(E,x)},`fence-point-${x}`))]}),(0,j.jsxs)("div",{className:"fence-boundary__zoom","aria-label":"Zoom controls",children:[(0,j.jsx)("button",{type:"button",onClick:()=>m(k=>Math.max(.5,k-.25)),disabled:p===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,j.jsxs)("span",{children:[Math.round(p*100),"%"]}),(0,j.jsx)("button",{type:"button",onClick:()=>m(k=>Math.min(1,k+.25)),disabled:p===1,"aria-label":"Zoom in",children:"+"})]}),!i.boundaryClosed&&i.boundaryPoints.length>=2?(0,j.jsx)("button",{type:"button",className:"fence-boundary__close",onClick:()=>o(k=>bc(k.boundaryPoints,!1)?k:{...k,boundaryClosed:!0}),children:"Finish fence line"}):null]}),(0,j.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,j.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,j.jsx)("div",{children:i.boundaryMode==="quick"?`${(Number.parseFloat(i.quickLengthM)||0).toFixed(2)} m fence line`:`${X.totalEdgeM.toFixed(2)} m fence line`}),i.boundaryMode==="draw"&&i.boundaryClosed?(0,j.jsxs)("div",{children:[X.cornerPostCount," corner/end posts"]}):null]})]}):null,null,u==="height"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Mn.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Fence height"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"Select the nearest available panel height."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:ka.heights.filter(k=>Iv(i.range,k)).map(k=>(0,j.jsx)("button",{type:"button",className:`truss-estimator__visual-card${i.height===k?" is-selected":""}`,onClick:()=>o(x=>({...x,height:k,mountingType:x.mountingType&&Fv(x.mountingType,k)?x.mountingType:null})),children:(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--tall",src:It(`/fencing/height/${k}.webp`),alt:""})},k))}),(0,j.jsx)("div",{className:"truss-estimator__section-heading",children:"Gravel board?"}),(0,j.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,j.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${i.gravelBoard===k.id?" is-selected":""}`,onClick:()=>o(x=>({...x,gravelBoard:k.id})),children:[(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:It(k.img),alt:""}),(0,j.jsx)("span",{children:k.label})]},k.id))})]}):null,u==="gate"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Mn.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Do you need a gate?"}),(0,j.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,j.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,j.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${i.gateType===k.id?" is-selected":""}`,onClick:()=>o(x=>({...x,gateType:k.id,gateWidthM:k.id==="none"?"":String(ka.gate[k.id].widthDefault)})),children:[(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:It(k.img),alt:""}),(0,j.jsx)("span",{children:k.label})]},k.id))}),i.gateType&&i.gateType!=="none"?(0,j.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,j.jsx)("span",{children:"Gate width (m)"}),(0,j.jsx)("input",{type:"text",inputMode:"decimal",value:i.gateWidthM,onChange:k=>o(x=>({...x,gateWidthM:k.target.value}))})]}):null]}):null,u==="posts"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Mn.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Posts and fixing type"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose how the posts will be set."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(ka.mounting).filter(([k])=>Fv(k,i.height)).map(([k,x])=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__option-card${i.mountingType===k?" is-selected":""}`,onClick:()=>o(E=>({...E,mountingType:k})),children:[(0,j.jsx)("div",{className:"truss-estimator__option-title",children:x.label}),(0,j.jsx)("div",{className:"truss-estimator__option-copy",children:x.blurb})]},k))})]}):null]}),(0,j.jsxs)("div",{className:"truss-estimator__nav",children:[(0,j.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:me,children:"Back"}),(0,j.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:$e,disabled:!wt(),children:[(0,j.jsx)("span",{children:P}),(0,j.jsx)("span",{className:"arrow",children:(0,j.jsx)(Qt,{})})]})]})]})]})})}var wc=$(Ve()),be=$(ee()),Wv={floor:{label:"Floor between rooms",product:"Knauf Acoustic Roll",thickness:"100mm",coverage:12.36},ground:{label:"Ground floor",product:"Rigid PIR insulation board",thickness:"100mm",coverage:2.88},wall:{label:"Cavity wall",product:"Celotex CW4100",thickness:"100mm",coverage:3.24},roof:{label:"Pitched roof",product:"Kingspan K107",thickness:"100mm",coverage:8.64},loft:{label:"Loft",product:"Knauf Loft Roll 44",thickness:"100mm",coverage:13.89}};function nm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,wc.useState)("floor"),[i,o]=(0,wc.useState)(""),[l,c]=(0,wc.useState)(""),p=Number.parseFloat(i)*Number.parseFloat(l)||0,m=Wv[r],f=Math.ceil(p/m.coverage),d=[{key:`insulation-${r}`,label:`${m.product} ${m.thickness}`,qty:Math.round(p*100)/100,unit:"m2",query:m.product,category:"insulation"}],g=Object.entries(Wv);return(0,be.jsx)(be.Fragment,{children:(0,be.jsxs)("div",{className:"truss-estimator",children:[(0,be.jsxs)("div",{className:"quick-order-hero",children:[(0,be.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,be.jsx)("h1",{children:"Insulation Calculator"}),(0,be.jsx)("p",{children:"Estimate insulation coverage and pack quantities for floors, walls, roofs and lofts."})]}),(0,be.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,be.jsx)("h2",{className:"truss-estimator__step-title",children:"Where and what you are insulating"}),(0,be.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the application and product, and enter the area, for coverage and pack quantities."}),(0,be.jsxs)("div",{className:"materials-calculator__section",children:[(0,be.jsx)("div",{className:"truss-estimator__section-heading",children:"Application"}),(0,be.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:g.map(([w,A])=>(0,be.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===w?" is-selected":""}`,onClick:()=>n(w),children:[(0,be.jsx)("div",{className:"truss-estimator__option-title",children:A.label}),(0,be.jsxs)("div",{className:"truss-estimator__option-copy",children:[A.product,", ",A.thickness]})]},w))})]}),(0,be.jsxs)("div",{className:"materials-calculator__section",children:[(0,be.jsx)("div",{className:"truss-estimator__section-heading",children:"Area"}),(0,be.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,be.jsxs)("label",{className:"truss-estimator__field",children:[(0,be.jsx)("span",{children:"Length (m)"}),(0,be.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:w=>o(w.target.value)})]}),(0,be.jsxs)("label",{className:"truss-estimator__field",children:[(0,be.jsx)("span",{children:"Width (m)"}),(0,be.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:w=>c(w.target.value)})]})]})]}),(0,be.jsxs)("div",{className:"materials-calculator__totals",children:[(0,be.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,be.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,be.jsxs)("div",{children:[(0,be.jsx)("span",{children:"Insulated area"}),(0,be.jsxs)("strong",{children:[p.toFixed(2)," m\xB2"]})]}),(0,be.jsxs)("div",{children:[(0,be.jsx)("span",{children:m.product}),(0,be.jsxs)("strong",{children:[f," packs"]})]})]}),(0,be.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,be.jsxs)("div",{className:"materials-calculator__actions",children:[(0,be.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,be.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(d),disabled:p<=0,children:a})]})]})]})})}var Vi=$(Ve());var K=$(ee()),xx=10,kx=1.9*.762,Sx=1.9*1.524,vc=()=>({height:"",width:""}),yc=e=>Number.parseFloat(e)||0,e0=({height:e,width:t})=>yc(e)*yc(t);function im({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Vi.useState)([vc()]),[i,o]=(0,Vi.useState)([vc()]),[l,c]=(0,Vi.useState)("0"),[p,m]=(0,Vi.useState)("0"),[f,d]=(0,Vi.useState)(1),g=r.reduce((_,C)=>_+e0(C),0),w=i.reduce((_,C)=>_+e0(C),0),A=yc(l)*kx+yc(p)*Sx,L=Math.max(0,g-w-A),h=L*f/xx,u={key:"paint-emulsion",label:"Matt emulsion, brilliant white",qty:Math.round(h*10)/10,unit:"litres",query:"matt emulsion brilliant white"},b=dl("paint",u)!=null,v=(_,C,R,T)=>{_(D=>D.map((V,oe)=>oe===C?{...V,[R]:T}:V))};return(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)("div",{className:"truss-estimator",children:[(0,K.jsxs)("div",{className:"quick-order-hero",children:[(0,K.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,K.jsx)("h1",{children:"Paint Calculator"}),(0,K.jsx)("p",{children:"Estimate how much paint you need for your walls, including multiple coats and excluded areas."})]}),(0,K.jsxs)("div",{className:"truss-estimator__card paint-calculator",children:[(0,K.jsx)("h2",{className:"truss-estimator__step-title",children:"Walls, exclusions and coats"}),(0,K.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,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Enter the height and width of each wall you want to paint."}),(0,K.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,K.jsx)("span",{}),(0,K.jsx)("span",{children:"Height (m)"}),(0,K.jsx)("span",{children:"Width (m)"}),(0,K.jsx)("span",{})]}),r.map((_,C)=>(0,K.jsxs)("div",{className:"paint-calculator__row",children:[(0,K.jsxs)("span",{className:"paint-calculator__row-label",children:["Wall ",C+1]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,K.jsx)("input",{"aria-label":`Wall ${C+1} height in metres`,type:"number",min:"0",step:"0.01",value:_.height,onChange:R=>v(n,C,"height",R.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,K.jsx)("input",{"aria-label":`Wall ${C+1} width in metres`,type:"number",min:"0",step:"0.01",value:_.width,onChange:R=>v(n,C,"width",R.target.value)})]}),r.length>1?(0,K.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>n(R=>R.filter((T,D)=>D!==C)),children:"Remove"}):null]},`wall-${C}`)),(0,K.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>n(_=>[..._,vc()]),children:"+ Add another wall"})]}),(0,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Areas to exclude"}),(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Add windows, sockets, skirting boards or other areas that will not be painted."}),(0,K.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,K.jsx)("span",{}),(0,K.jsx)("span",{children:"Height (m)"}),(0,K.jsx)("span",{children:"Width (m)"}),(0,K.jsx)("span",{})]}),i.map((_,C)=>(0,K.jsxs)("div",{className:"paint-calculator__row",children:[(0,K.jsxs)("span",{className:"paint-calculator__row-label",children:["Area ",C+1]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,K.jsx)("input",{"aria-label":`Area ${C+1} height in metres`,type:"number",min:"0",step:"0.01",value:_.height,onChange:R=>v(o,C,"height",R.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,K.jsx)("input",{"aria-label":`Area ${C+1} width in metres`,type:"number",min:"0",step:"0.01",value:_.width,onChange:R=>v(o,C,"width",R.target.value)})]}),i.length>1?(0,K.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>o(R=>R.filter((T,D)=>D!==C)),children:"Remove"}):null]},`excluded-${C}`)),(0,K.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>o(_=>[..._,vc()]),children:"+ Add another area"})]}),(0,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Doors and coats"}),(0,K.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,K.jsxs)("div",{className:"truss-estimator__field-grid paint-calculator__small-fields",children:[(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Doors"}),(0,K.jsx)("input",{type:"number",min:"0",step:"1",value:l,onChange:_=>c(_.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Double doors"}),(0,K.jsx)("input",{type:"number",min:"0",step:"1",value:p,onChange:_=>m(_.target.value)})]})]}),(0,K.jsxs)("div",{className:"paint-calculator__coat-field",children:[(0,K.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,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Number of coats"}),(0,K.jsxs)("select",{value:f,onChange:_=>d(Number(_.target.value)),children:[(0,K.jsx)("option",{value:"1",children:"1 coat"}),(0,K.jsx)("option",{value:"2",children:"2 coats"}),(0,K.jsx)("option",{value:"3",children:"3 coats"})]})]})]})]}),(0,K.jsxs)("div",{className:"paint-calculator__totals",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,K.jsxs)("div",{className:"paint-calculator__result-grid",children:[(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Paintable area"}),(0,K.jsxs)("strong",{children:[L.toFixed(2)," m\xB2"]})]}),(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Coverage"}),(0,K.jsxs)("strong",{children:[f," ",f===1?"coat":"coats"]})]}),(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Paint required"}),(0,K.jsxs)("strong",{children:[h.toFixed(1)," litres"]})]})]}),(0,K.jsx)("p",{className:"paint-calculator__note",children:b?"Based on paint coverage of 10 m\xB2 per litre. Ordered as brilliant white matt emulsion, rounded up to whole tins.":"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,K.jsxs)("div",{className:"paint-calculator__actions",children:[(0,K.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),b?(0,K.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.([u]),disabled:h<=0,children:a}):(0,K.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",disabled:!0,children:"Paint products unavailable"})]})]})]})})}var fr=$(Ve()),re=$(ee()),_c=e=>Number.parseFloat(e)||0,om={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 lm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,fr.useState)("paving"),[i,o]=(0,fr.useState)("council"),[l,c]=(0,fr.useState)(""),[p,m]=(0,fr.useState)(""),[f,d]=(0,fr.useState)("100"),[g,w]=(0,fr.useState)("50"),[A,L]=(0,fr.useState)(!0),[h,u]=(0,fr.useState)(!0),b=_c(l)*_c(p),v=b,_=b*(_c(f)/1e3),C=b*.04,R=b*(_c(g)/1e3),T=Math.ceil(v/.36),D=Math.ceil(v/.1),V=Math.ceil(_*1700/800),oe=Math.ceil(C*1600/800),_e=Math.ceil(R*1600/800),Te=r==="paving"?{qty:T,unit:"each"}:r==="block"?{qty:v,unit:"m2"}:{qty:_e,unit:"bag"},Oe={paving:"paving slab",block:"block paver",gravel:"decorative gravel"}[r],xe=[{key:`surface-${i}`,label:om[r].find(J=>J.id===i)?.label??"Surface material",qty:Te.qty,unit:Te.unit,query:Oe,category:"landscaping"},...A?[{key:"sub-base",label:"MOT Type 1 sub-base",qty:V,unit:"bag",query:"MOT Type 1 sub base",category:"aggregate"}]:[],...h?[{key:"bedding",label:"Sharp sand bedding",qty:oe,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 and 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(([J,ze,Ee])=>(0,re.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===J?" is-selected":""}`,onClick:()=>{n(J),o(om[J][0].id)},children:[(0,re.jsx)("div",{className:"truss-estimator__option-title",children:ze}),(0,re.jsx)("div",{className:"truss-estimator__option-copy",children:Ee})]},J))}),(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:J=>o(J.target.value),children:om[r].map(J=>(0,re.jsx)("option",{value:J.id,children:J.label},J.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:J=>c(J.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:J=>m(J.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:g,onChange:J=>w(J.target.value)})]}),A&&(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:f,onChange:J=>d(J.target.value)})]}),(0,re.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,re.jsx)("input",{type:"checkbox",checked:A,onChange:J=>L(J.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:h,onChange:J=>u(J.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:[b.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"?`${T} slabs`:r==="block"?`${v.toFixed(2)} m\xB2`:`${_e} bulk bags`})]}),A&&(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"MOT Type 1"}),(0,re.jsxs)("strong",{children:[V," bulk bags"]})]}),h&&(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Sharp sand"}),(0,re.jsxs)("strong",{children:[oe," 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?.(xe),disabled:b<=0,children:a})]})]})]})})}var ml=$(Ve()),ie=$(ee()),Nx=2.88,t0=[{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"}],a0=()=>({length:"",height:""}),sm=e=>Number.parseFloat(e)||0;function cm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,ml.useState)([a0()]),[i,o]=(0,ml.useState)(""),[l,c]=(0,ml.useState)("standard"),[p,m]=(0,ml.useState)("screws"),f=r.reduce((C,R)=>C+sm(R.length)*sm(R.height),0),d=Math.max(0,f-sm(i)),g=Math.ceil(d/Nx),w=Math.ceil(d*12),A=Math.ceil(w/1e3),L=Math.ceil(d*1.2),h=Math.ceil(L/90),u=Math.ceil(d/3.5),b=t0.find(C=>C.id===l)?.label??"Standard",v=[{key:"board",label:`${b} plasterboard`,qty:g,unit:"sheet",query:`${b} plasterboard`,category:"plasterboard"},...p==="screws"?[{key:"screws",label:"Drywall screws",qty:A,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:h,unit:"roll",query:"plasterboard joint tape",category:"plasterboard"}],_=(C,R,T)=>{n(D=>D.map((V,oe)=>oe===C?{...V,[R]:T}:V))};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 and 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:t0.map(C=>(0,ie.jsxs)("button",{type:"button",className:`truss-estimator__option-card${l===C.id?" is-selected":""}`,onClick:()=>c(C.id),children:[(0,ie.jsx)("div",{className:"truss-estimator__option-title",children:C.label}),(0,ie.jsx)("div",{className:"truss-estimator__option-copy",children:C.blurb})]},C.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(([C,R,T])=>(0,ie.jsxs)("button",{type:"button",className:`truss-estimator__option-card${p===C?" is-selected":""}`,onClick:()=>m(C),children:[(0,ie.jsx)("div",{className:"truss-estimator__option-title",children:R}),(0,ie.jsx)("div",{className:"truss-estimator__option-copy",children:T})]},C))})]}),(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((C,R)=>(0,ie.jsxs)("div",{className:"materials-calculator__surface-row",children:[(0,ie.jsxs)("span",{children:["Surface ",R+1]}),(0,ie.jsx)("input",{"aria-label":`Surface ${R+1} length`,type:"number",min:"0",step:"0.01",value:C.length,onChange:T=>_(R,"length",T.target.value)}),(0,ie.jsx)("input",{"aria-label":`Surface ${R+1} height`,type:"number",min:"0",step:"0.01",value:C.height,onChange:T=>_(R,"height",T.target.value)}),r.length>1?(0,ie.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>n(T=>T.filter((D,V)=>V!==R)),children:"Remove"}):null]},`surface-${R}`)),(0,ie.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>n(C=>[...C,a0()]),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:C=>o(C.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:g})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:p==="screws"?"Drywall screws":"Board adhesive"}),(0,ie.jsx)("strong",{children:p==="screws"?`${w} (${A} boxes)`:`${u} bags`})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:"Joint tape"}),(0,ie.jsxs)("strong",{children:[L," m (",h," 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 fl=$(Ve());var y=$(ee()),Rt={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}}}},xc=["range","pitchAndDimensions","quantityAndGirders","bracing"],Cx={range:null,pitch:null,spanMM:"",overhangMM:"",roofLengthM:"",centres:null,girderCount:0,bracing:null,treatment:null,contact:{name:"",email:""}};function qx({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 Ex({type:e}){let t="#b3835a",a="#5c3b22",r="#d9b48f",n="#d3d8de",i="#7c8494",o=(m,f,d,g,w=8,A)=>{let L=d-m,h=g-f,u=Math.hypot(L,h)||1,b=-h/u,v=L/u,_=w*.2;return(0,y.jsxs)("g",{children:[(0,y.jsx)("line",{x1:m,y1:f,x2:d,y2:g,stroke:a,strokeWidth:w+3,strokeLinecap:"square"}),(0,y.jsx)("line",{x1:m,y1:f,x2:d,y2:g,stroke:t,strokeWidth:w,strokeLinecap:"square"}),(0,y.jsx)("line",{x1:m-b*_,y1:f-v*_,x2:d-b*_,y2:g-v*_,stroke:r,strokeWidth:Math.max(1.5,w*.24),strokeLinecap:"round",opacity:"0.9"})]},A)},l=(m,f,d)=>(0,y.jsxs)("g",{children:[(0,y.jsx)("rect",{x:m-7.5,y:f-5.5,width:"15",height:"11",rx:"2",fill:n,stroke:i,strokeWidth:"1"}),(0,y.jsx)("circle",{cx:m-4,cy:f-2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:m+4,cy:f-2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:m-4,cy:f+2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:m+4,cy:f+2.5,r:"1",fill:i}),(0,y.jsx)("circle",{cx:m,cy:f,r:"1",fill:i})]},d),c=(m,f)=>(0,y.jsx)("rect",{x:m-9,y:"110",width:"18",height:"10",fill:a},f),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 Mx({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 r0({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 um({onBack:e}){let[t,a]=(0,fl.useState)(0),[r,n]=(0,fl.useState)(Cx),[i,o]=(0,fl.useState)(!1),[l,c]=(0,fl.useState)(!1),p=()=>{let h=Number.parseFloat(r.roofLengthM)||0,u=Number.parseFloat(r.centres??"");return h<=0||!u?0:Math.ceil(h*1e3/u)+1},f=(()=>{let h=r.range?Rt.ranges[r.range]:Rt.ranges.standard,u=r.pitch??"22.5",b=Rt.pitchMultipliers[u],v=(Number.parseFloat(r.spanMM)||0)/1e3,C=(Number.parseFloat(r.overhangMM)||0)>Rt.overhang.thresholdMM,R=p(),T=R+r.girderCount,D=Number.parseFloat(r.roofLengthM)||0,V=r.treatment?Rt.treatment[r.treatment]:Rt.treatment.untreated,oe=Rt.estimate.ranges[r.range??"standard"],_e=oe.supplyAt8m*Math.max(.7,v/8)*b*(1+V.surchargePct)+(C?Rt.overhang.surchargePerTruss:0),Te=R*_e,Oe=r.girderCount*_e*Rt.estimate.girderMultiplier,xe=r.bracing==="yes"?D*Rt.estimate.bracingPerMetre:0,X=Te+Oe+xe+Rt.estimate.delivery,J=Rt.estimate.design+R*oe.installPerTruss+r.girderCount*40,ze=X+J,Ee=ze*.2;return{range:h,count:R,girderCount:r.girderCount,overhangApplies:C,overhangUnits:T,roofLengthM:D,treatment:V,trussSupply:Te,bracingMaterials:xe,delivery:Rt.estimate.delivery,labour:J,subtotal:ze,vat:Ee,total:ze+Ee}})(),d=()=>{let h=xc[t];return h==="range"?!!r.range:h==="pitchAndDimensions"?!!r.pitch&&r.spanMM.trim()!==""&&r.overhangMM.trim()!=="":h==="quantityAndGirders"?r.roofLengthM.trim()!==""&&!!r.centres:h==="bracing"?!!r.bracing&&!!r.treatment:!0},g=t===xc.length-1?"View truss request":"Next",w=()=>{i?o(!1):t===0?e():a(h=>h-1)},A=()=>{d()&&(t===xc.length-1?(c(!1),o(!0)):a(h=>h+1))},L=()=>{let h=xc[t];return h==="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(Rt.ranges).map(([u,b])=>(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)(Ex,{type:u}),(0,y.jsxs)("div",{className:"truss-estimator__option-info",children:[(0,y.jsx)("div",{className:"truss-estimator__option-title",children:b.label}),(0,y.jsx)("div",{className:"truss-estimator__option-copy",children:b.blurb})]})]},u))})]}):h==="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(b=>({...b,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(b=>({...b,overhangMM:u.target.value}))}),(0,y.jsxs)("small",{children:["Overhangs beyond ",Rt.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:Rt.pitches.map(u=>(0,y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${r.pitch===u?" is-selected":""}`,onClick:()=>n(b=>({...b,pitch:u})),children:[(0,y.jsx)(qx,{degrees:Number.parseFloat(u)}),(0,y.jsxs)("span",{children:[u,"\xB0"]})]},u))})]}):h==="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(b=>({...b,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:Rt.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(b=>({...b,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:"+"})]})]}):h==="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(b=>({...b,bracing:u.id})),children:[(0,y.jsx)(Mx,{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)(r0,{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)(r0,{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:[f.range.label," roof trusses"]})]}),(0,y.jsxs)("strong",{children:[f.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:f.treatment.label})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Girder trusses"}),(0,y.jsx)("strong",{children:f.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:ot(f.trussSupply)})]}),f.bracingMaterials>0&&(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Bracing materials allowance"}),(0,y.jsx)("strong",{children:ot(f.bracingMaterials)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Delivery allowance"}),(0,y.jsx)("strong",{children:ot(f.delivery)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Design and installation labour"}),(0,y.jsx)("strong",{children:ot(f.labour)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"Subtotal (ex. VAT)"}),(0,y.jsx)("strong",{children:ot(f.subtotal)})]}),(0,y.jsxs)("div",{children:[(0,y.jsx)("span",{children:"VAT (20%)"}),(0,y.jsx)("strong",{children:ot(f.vat)})]}),(0,y.jsxs)("div",{className:"truss-request__price-total",children:[(0,y.jsx)("span",{children:"Estimated total"}),(0,y.jsx)("strong",{children:ot(f.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:L()}),(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:A,disabled:!d(),children:[(0,y.jsx)("span",{children:g}),(0,y.jsx)("span",{className:"arrow",children:(0,y.jsx)(Qt,{})})]})]})]})]})})}var Tn=$(Ve()),W=$(ee()),o0=e=>Number.parseFloat(e)||0,kc=(e,t)=>o0(e)*(t==="m"?1:.3048),n0=()=>({length:"",width:""}),i0=[{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 Tx({profile:e}){return(0,W.jsxs)("svg",{className:"skirting-calculator__profile-diagram",viewBox:"0 0 120 84","aria-hidden":"true",children:[(0,W.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,W.jsx)("line",{x1:"12",y1:"70",x2:"108",y2:"70"})]})}function pm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Tn.useState)("total"),[i,o]=(0,Tn.useState)("m"),[l,c]=(0,Tn.useState)(""),[p,m]=(0,Tn.useState)([n0()]),[f,d]=(0,Tn.useState)(""),[g,w]=(0,Tn.useState)("chamfered"),A="4.4",L=r==="total"?kc(l,i):p.reduce((_,C)=>_+2*(kc(C.length,i)+kc(C.width,i)),0),h=Math.max(0,L-kc(f,i)),u=Math.ceil(h/o0(A)),b=[{key:`skirting-${g}`,label:`${i0.find(_=>_.id===g)?.label} skirting board`,qty:h,unit:"m",query:"skirting board",category:"skirting"}],v=(_,C,R)=>{m(T=>T.map((D,V)=>V===_?{...D,[C]:R}:D))};return(0,W.jsx)(W.Fragment,{children:(0,W.jsxs)("div",{className:"truss-estimator",children:[(0,W.jsxs)("div",{className:"quick-order-hero",children:[(0,W.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,W.jsx)("h1",{children:"Skirting Board Calculator"}),(0,W.jsx)("p",{children:"Work out how many skirting board lengths you need for one room or a whole project."})]}),(0,W.jsxs)("div",{className:"truss-estimator__card skirting-calculator",children:[(0,W.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure by room or total length"}),(0,W.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,W.jsxs)("div",{className:"skirting-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"How would you like to measure?"}),(0,W.jsxs)("div",{className:"brick-calculator__unit-toggle skirting-calculator__mode-toggle",role:"group","aria-label":"Calculation method",children:[(0,W.jsx)("button",{type:"button",className:r==="total"?"is-selected":"",onClick:()=>n("total"),children:"Total length"}),(0,W.jsx)("button",{type:"button",className:r==="rooms"?"is-selected":"",onClick:()=>n("rooms"),children:"Room by room"})]})]}),(0,W.jsxs)("div",{className:"skirting-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Measurements"}),(0,W.jsxs)("div",{className:"skirting-calculator__unit-row",children:[(0,W.jsx)("span",{children:"Units"}),(0,W.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,W.jsx)("button",{type:"button",className:i==="m"?"is-selected":"",onClick:()=>o("m"),children:"Metres"}),(0,W.jsx)("button",{type:"button",className:i==="ft"?"is-selected":"",onClick:()=>o("ft"),children:"Feet"})]})]}),r==="total"?(0,W.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,W.jsxs)("span",{children:["Total skirting length (",i,")"]}),(0,W.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:_=>c(_.target.value)})]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)("div",{className:"skirting-calculator__dimensions-header",children:[(0,W.jsx)("span",{children:"Room"}),(0,W.jsxs)("span",{children:["Length (",i,")"]}),(0,W.jsxs)("span",{children:["Width (",i,")"]}),(0,W.jsx)("span",{})]}),p.map((_,C)=>(0,W.jsxs)("div",{className:"skirting-calculator__room-row",children:[(0,W.jsxs)("span",{className:"skirting-calculator__room-label",children:["Room ",C+1]}),(0,W.jsx)("input",{"aria-label":`Room ${C+1} length in ${i}`,type:"number",min:"0",step:"0.01",value:_.length,onChange:R=>v(C,"length",R.target.value)}),(0,W.jsx)("input",{"aria-label":`Room ${C+1} width in ${i}`,type:"number",min:"0",step:"0.01",value:_.width,onChange:R=>v(C,"width",R.target.value)}),p.length>1?(0,W.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>m(R=>R.filter((T,D)=>D!==C)),children:"Remove"}):null]},`room-${C}`)),(0,W.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>m(_=>[..._,n0()]),children:"+ Add another room"})]}),(0,W.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,W.jsxs)("span",{children:["Openings and doorways to deduct (",i,") ",(0,W.jsx)("small",{children:"optional"})]}),(0,W.jsx)("input",{type:"number",min:"0",step:"0.01",value:f,onChange:_=>d(_.target.value)})]})]}),(0,W.jsxs)("div",{className:"skirting-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Profile"}),(0,W.jsx)("p",{className:"skirting-calculator__hint",children:"Choose the finish you want for the fixed 4.4m white-primed MDF boards."}),(0,W.jsx)("div",{className:"architrave-calculator__profiles",children:i0.map(_=>(0,W.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g===_.id?" is-selected":""}`,onClick:()=>w(_.id),children:[(0,W.jsx)(Tx,{profile:_.id}),(0,W.jsx)("div",{className:"truss-estimator__option-title",children:_.label}),(0,W.jsx)("div",{className:"truss-estimator__option-copy",children:_.blurb})]},_.id))})]}),(0,W.jsxs)("div",{className:"skirting-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,W.jsx)("div",{className:"truss-estimator__field-grid skirting-calculator__options-grid",children:(0,W.jsxs)("label",{className:"truss-estimator__field",children:[(0,W.jsx)("span",{children:"Board length"}),(0,W.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,W.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,W.jsxs)("div",{className:"skirting-calculator__totals",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,W.jsxs)("div",{className:"skirting-calculator__result-grid",children:[(0,W.jsxs)("div",{children:[(0,W.jsx)("span",{children:"Net skirting"}),(0,W.jsxs)("strong",{children:[h.toFixed(2)," m"]})]}),(0,W.jsxs)("div",{children:[(0,W.jsx)("span",{children:"Board lengths"}),(0,W.jsx)("strong",{children:u})]})]}),(0,W.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,W.jsxs)("div",{className:"skirting-calculator__actions",children:[(0,W.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,W.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(b),disabled:h<=0,children:a})]})]})]})})}var Xi=$(Ve()),se=$(ee()),hl=e=>Number.parseFloat(e)||0;function dm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,n]=(0,Xi.useState)("studs"),[i,o]=(0,Xi.useState)(""),[l,c]=(0,Xi.useState)(""),[p,m]=(0,Xi.useState)("600"),[f,d]=(0,Xi.useState)("2.4"),g=i&&l&&p?Math.ceil(hl(l)/(hl(p)/1e3))+1:0,w=g*hl(i),A=hl(f)>0?Math.ceil(w/hl(f)):0,L=[{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"}],h={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"]},b={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,se.jsx)(se.Fragment,{children:(0,se.jsxs)("div",{className:"truss-estimator",children:[(0,se.jsxs)("div",{className:"quick-order-hero",children:[(0,se.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,se.jsx)("h1",{children:"Timber Calculator"}),(0,se.jsx)("p",{children:"Estimate studs, joists or battens from a run length, width and spacing."})]}),(0,se.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,se.jsx)("h2",{className:"truss-estimator__step-title",children:"Member size and spacing"}),(0,se.jsxs)("p",{className:"truss-estimator__step-sub",children:[b.help," Enter the member length and centres to estimate the number of pieces and stock lengths."]}),(0,se.jsxs)("div",{className:"materials-calculator__section",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber use"}),(0,se.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:Object.keys(h).map(v=>(0,se.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===v?" is-selected":""}`,onClick:()=>n(v),children:[(0,se.jsx)("div",{className:"truss-estimator__option-title",children:h[v][0]}),(0,se.jsx)("div",{className:"truss-estimator__option-copy",children:h[v][1]})]},v))})]}),(0,se.jsxs)("div",{className:"materials-calculator__section",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Dimensions and spacing"}),(0,se.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsxs)("span",{children:[b.member," (m)"]}),(0,se.jsx)("input",{type:"number",min:"0",step:"0.01",value:i,onChange:v=>o(v.target.value)})]}),(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsxs)("span",{children:[b.overall," (m)"]}),(0,se.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:v=>c(v.target.value)})]})]}),(0,se.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsx)("span",{children:"Centres (mm)"}),(0,se.jsxs)("select",{value:p,onChange:v=>m(v.target.value),children:[(0,se.jsx)("option",{value:"300",children:"300 mm"}),(0,se.jsx)("option",{value:"400",children:"400 mm"}),(0,se.jsx)("option",{value:"450",children:"450 mm"}),(0,se.jsx)("option",{value:"600",children:"600 mm"})]})]}),(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsx)("span",{children:"Stock length (m)"}),(0,se.jsxs)("select",{value:f,onChange:v=>d(v.target.value),children:[(0,se.jsx)("option",{value:"2.4",children:"2.40 m"}),(0,se.jsx)("option",{value:"3.6",children:"3.60 m"}),(0,se.jsx)("option",{value:"4.8",children:"4.80 m"})]})]})]})]}),(0,se.jsxs)("div",{className:"materials-calculator__totals",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,se.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,se.jsxs)("div",{children:[(0,se.jsx)("span",{children:b.count}),(0,se.jsx)("strong",{children:g})]}),(0,se.jsxs)("div",{children:[(0,se.jsx)("span",{children:"Linear metres"}),(0,se.jsxs)("strong",{children:[w.toFixed(2)," m"]})]}),(0,se.jsxs)("div",{children:[(0,se.jsxs)("span",{children:[f," m lengths"]}),(0,se.jsx)("strong",{children:A})]})]}),(0,se.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,se.jsxs)("div",{className:"materials-calculator__actions",children:[(0,se.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,se.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(L),disabled:w<=0,children:a})]})]})]})})}var mm=[{id:"truss",title:"Roof Truss Calculator",desc:"Estimate trusses, girders and roof structure costs.",imageUrl:"/tool-images/truss.webp",Component:um},{id:"fencing",title:"Fencing Calculator",desc:"Estimate fence panels, posts, gravel boards and fixings.",imageUrl:"/tool-images/fencing.webp",Component:rm},{id:"decking",title:"Decking Calculator",desc:"Estimate boards, substructure and fixing quantities.",imageUrl:"/tool-images/decking.webp",Component:tm},{id:"brick-block",title:"Brick and Block Calculator",desc:"Estimate masonry units and ready-mixed mortar for a wall.",imageUrl:"/tool-images/brick-block.webp",Component:Id},{id:"paint",title:"Paint Calculator",desc:"Estimate paint for walls, doors and multiple coats.",imageUrl:"/tool-images/paint.webp",Component:im},{id:"skirting",title:"Skirting Board Calculator",desc:"Estimate skirting lengths for rooms and wall runs.",imageUrl:"/tool-images/skirting.webp",Component:pm},{id:"architrave",title:"Architrave Calculator",desc:"Estimate architrave lengths for door and window openings.",imageUrl:"/tool-images/architrave.webp",Component:Jd},{id:"concrete-aggregate",title:"Concrete and Aggregate Calculator",desc:"Estimate concrete, MOT, sand and gravel quantities.",imageUrl:"/tool-images/concrete-aggregate.webp",Component:Wd},{id:"plasterboard",title:"Plasterboard Calculator",desc:"Estimate plasterboard sheets, screws, tape and adhesive.",imageUrl:"/tool-images/plasterboard.webp",Component:cm},{id:"insulation",title:"Insulation Calculator",desc:"Estimate insulation packs for floors, walls, roofs and lofts.",imageUrl:"/tool-images/insulation.webp",Component:nm},{id:"timber",title:"Timber Calculator",desc:"Estimate studs, joists and battens from spacing and lengths.",imageUrl:"/tool-images/timber.webp",Component:dm},{id:"paving",title:"Paving and Driveway Calculator",desc:"Estimate paving, block paving, MOT and sharp sand.",imageUrl:"/tool-images/paving.webp",Component:lm}];var fm=$(Ve());var zx=new Set(["bag","box","roll","pack"]),Rx=new Set(["each","bag","box","roll","pack","tub"]);function gl(e,t){let r=(t?.conversion?.request_uoms_supported??"").split(",").map(o=>o.trim().toLowerCase()).includes("sales_unit");if(e==="each"){let o=(t?.uoi_count??1)===1&&(t?.conversion?.sales_unit_size??1)===1;return r&&o?"sales_unit":e}if(!zx.has(e))return e;if(r)return"sales_unit";let n=t?.uoi;return n!=null&&Rx.has(n.toLowerCase())&&(t?.uoi_count??1)===1?n:e}var l0=new Map;function Ax(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 zn(e,t,a=12,r){let n=`${Dt().client??""}||${e}||${t??""}||${a}||${r??""}`,i=l0.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(Ma(`/api/catalogue/search?${o.toString()}`),{headers:wn()}),c=await Ga(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(Ax):[];return l0.set(n,p),p}async function s0(e,t,a){return await Promise.all(e.map(async n=>{try{let i=a?dl(a,n):null,[o,l]=await Promise.all([i?zn(i,void 0,void 0,t).then(p=>p.find(m=>m.product_id===i.split(" ")[0]),()=>{}):void 0,zn(n.query,n.category,void 0,t)]),c=o?[o,...l.filter(p=>p.product_id!==o.product_id)]:l;return{requirement:n,candidates:c}}catch{return{requirement:n,candidates:[]}}}))}async function c0(){let e=await fetch(Ma("/api/catalogue"),{headers:wn()});if(!e.ok)return{itemCount:0,uploadedAt:null};let t=await Ga(e);return{itemCount:Number(t?.itemCount)||0,uploadedAt:t?.uploadedAt??null}}var ea=$(ee()),Ux=1500;function u0(e){let{addManyToCart:t,clearCart:a,openBasket:r}=Di(),[n,i]=(0,fm.useState)(!1),[o,l]=(0,fm.useState)(null);return{adding:n,basketError:o,addToBasket:async(p,m)=>{let f=Date.now();i(!0),l(null);try{let d=await Promise.all(p.filter(w=>w.qty>0).map(async w=>{let A=(await zn(w.search)).find(L=>L.product_id===w.productId);if(!A)throw new Error("A selected product is no longer available in this catalogue.");return Oi(A,{lineId:`${e}:${w.key}`,description:A.description,unit:gl(w.unit??"each",A),qty:w.qty,calculatorWasteIncluded:m})})),g=Ux-(Date.now()-f);g>0&&await new Promise(w=>window.setTimeout(w,g)),a(),t(d),r()}catch(d){l(d instanceof Error?d.message:"Could not add the products to your basket.")}finally{i(!1)}}}}function p0({toolTitle:e}){return(0,ea.jsx)(ea.Fragment,{children:(0,ea.jsxs)("div",{className:"truss-estimator",children:[(0,ea.jsxs)("div",{className:"quick-order-hero",children:[(0,ea.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ea.jsx)("h1",{children:"Your Materials"}),(0,ea.jsxs)("p",{children:["Calculating quantities from the ",e,"."]})]}),(0,ea.jsx)("div",{className:"truss-estimator__card",children:(0,ea.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,ea.jsx)(vn,{}),(0,ea.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})})}var Nc=$(Ve());var je=$(Ve());var q=$(ee()),Dx=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}],hm={wasteFactorEnabled:!0},Ox=3e3,d0=null;function Sc(e,t){let a=ol(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function Bx(e){return e&&e.length>0?e.join(" x "):"-"}function gm({toolId:e,requirements:t,ready:a,onBack:r,onTotalChange:n}){let i=xv(),o=`${e}~${t.map(N=>`${N.key}|${N.query}|${N.category??""}|${N.qty}`).join("~")}`,l=o!==d0,[c,p]=(0,je.useState)(null),[m,f]=(0,je.useState)([]),[d,g]=(0,je.useState)(l),[w,A]=(0,je.useState)(null),[L,h]=(0,je.useState)("tile"),[u,b]=(0,je.useState)(null),[v,_]=(0,je.useState)(""),[C,R]=(0,je.useState)(null),[T,D]=(0,je.useState)(""),[V,oe]=(0,je.useState)([]),[_e,Te]=(0,je.useState)(new Set),[Oe,xe]=(0,je.useState)(null),[X,J]=(0,je.useState)(""),[ze,Ee]=(0,je.useState)([]),wt=(0,je.useRef)(null),P=(0,je.useRef)(!1),pe=N=>`${e}:${N}`,Re=N=>Oi(N.chosen,{lineId:pe(N.requirement.key),description:N.requirement.label,unit:gl(N.requirement.unit,N.chosen),qty:N.requirement.qty}),Ot=(0,je.useMemo)(()=>t.map(N=>`${N.key}|${N.query}|${N.category??""}`).join("~"),[t]);(0,je.useEffect)(()=>{let N=!1;return c0().then(G=>{N||p(G.itemCount>0)}).catch(()=>{N||p(!1)}),()=>{N=!0}},[]),(0,je.useEffect)(()=>{if(!a||!c)return;let N=!1,G;l&&g(!0),A(null);let Y=Date.now();return(async()=>{let ce=null;try{ce=(await s0(t,void 0,e)).map(({requirement:yt,candidates:ft})=>({requirement:yt,candidates:ft,chosen:ft[0]??null}))}catch(Se){N||A(Se instanceof Error?Se.message:"Could not load products")}if(!N){if(d0=o,l){let Se=Ox-(Date.now()-Y);Se>0&&await new Promise(yt=>{G=window.setTimeout(yt,Se)})}N||(ce&&(f(ce),!P.current&&i&&(P.current=!0,i.addManyToCart(ce.filter(Se=>Se.chosen).map(Re)))),g(!1))}})(),()=>{N=!0,window.clearTimeout(G)}},[a,c,Ot]),(0,je.useEffect)(()=>{if(!C)return;let N=T.trim();if(!N){oe([]);return}let G=!1,Y=window.setTimeout(()=>{zn(N).then(ce=>{G||oe(ce)}).catch(()=>{G||oe([])})},250);return()=>{G=!0,window.clearTimeout(Y)}},[C,T]),(0,je.useEffect)(()=>{if(!Oe)return;let N=X.trim();if(!N){Ee([]);return}let G=!1,Y=window.setTimeout(()=>{zn(N).then(ce=>{G||Ee(ce)}).catch(()=>{G||Ee([])})},250);return()=>{G=!0,window.clearTimeout(Y)}},[Oe,X]);let jt=(0,je.useMemo)(()=>{let N=v.trim().toLowerCase(),G=N?m.filter(Y=>Y.requirement.label.toLowerCase().includes(N)||(Y.chosen?.description??"").toLowerCase().includes(N)||(Y.chosen?.product_id??"").toLowerCase().includes(N)):m;return u?[...G].sort((Y,ce)=>{let Se=Y.requirement.label.localeCompare(ce.requirement.label);return u==="asc"?Se:-Se}):G},[m,v,u]),qe=jt.filter(N=>N.chosen),ke=jt.filter(N=>!N.chosen),Be=m.filter(N=>N.chosen),Ye=Be.filter(N=>N.chosen?.price==null).length,vt=Be.reduce((N,G)=>N+(Ft(Re(G),hm).lineTotal??0),0);if((0,je.useEffect)(()=>{n?.(vt)},[vt,n]),!a||c===!1)return null;let z=i?Be.filter(N=>i.cart[pe(N.requirement.key)]).length:0,H=Oe?m.find(N=>N.requirement.key===Oe)??null:null,de=X.trim()?ze:H?.candidates??[],me=N=>{let G=C===N.requirement.key;R(G?null:N.requirement.key),D(G?"":N.requirement.query)},$e=(N,G)=>{let Y=m.find(ce=>ce.requirement.key===N);f(ce=>ce.map(Se=>Se.requirement.key===N?{...Se,chosen:G}:Se)),i&&Y&&i.cart[pe(N)]&&i.addToCart(Re({...Y,chosen:G})),R(null),D("")},Le=N=>{f(G=>G.map(Y=>Y.requirement.key===N?{...Y,chosen:null}:Y)),i?.cart[pe(N)]&&i.removeFromCart(pe(N))},k=N=>{xe(N.requirement.key),J(""),Ee([])},x=()=>{xe(null),J(""),Ee([])},E=N=>{if(!i)return;let G=pe(N.requirement.key);i.cart[G]?i.removeFromCart(G):i.addToCart(Re(N))},U=N=>{Te(G=>{let Y=new Set(G);return Y.has(N)?Y.delete(N):Y.add(N),Y})},Z=N=>{let G=V.length>0?V:N.candidates;return(0,q.jsxs)("div",{className:"estimator-products__picker",children:[(0,q.jsx)("input",{type:"text",className:"results-search-input",value:T,autoFocus:!0,placeholder:"Search products in catalogue...",onChange:Y=>D(Y.target.value),"aria-label":`Search a product for ${N.requirement.label}`}),(0,q.jsxs)("div",{className:"estimator-products__options",children:[G.map(Y=>(0,q.jsxs)("button",{type:"button",className:`estimator-products__option${Y.product_id===N.chosen?.product_id?" is-selected":""}`,onClick:()=>$e(N.requirement.key,Y),children:[(0,q.jsx)("span",{children:Y.description}),(0,q.jsxs)("span",{className:"results-row-meta",children:[Y.product_id,Y.price!=null&&` \xB7 ${ot(Y.price)}`]})]},Y.product_id)),G.length===0&&(0,q.jsx)("p",{className:"results-empty-hint",children:"No matching products."})]})]})};return(0,q.jsxs)("section",{className:"estimator-products results-tile-section","aria-label":"Matched products",children:[!d&&(0,q.jsxs)("div",{className:"estimator-products__head",children:[(0,q.jsxs)("div",{className:"results-tile-section__head",children:[(0,q.jsx)("h3",{children:"Matched Products"}),(0,q.jsx)("p",{children:"Products matched to your estimate, check before adding to your basket."})]}),!H&&(0,q.jsx)("div",{className:"results-summary estimator-products__toolbar",children:(0,q.jsxs)("div",{className:"estimator-products__controls",children:[(0,q.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:v,onChange:N=>_(N.target.value),"aria-label":"Search matched products"}),(0,q.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,q.jsx)("button",{type:"button",className:`results-view-toggle__btn${L==="tile"?" is-active":""}`,"aria-pressed":L==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>h("tile"),children:(0,q.jsxs)("svg",{width:"18",height:"12",viewBox:"0 0 15 10",fill:"currentColor",children:[(0,q.jsx)("rect",{x:"0.5",y:"0.5",width:"4",height:"4"}),(0,q.jsx)("rect",{x:"5.5",y:"0.5",width:"4",height:"4"}),(0,q.jsx)("rect",{x:"10.5",y:"0.5",width:"4",height:"4"}),(0,q.jsx)("rect",{x:"0.5",y:"5.5",width:"4",height:"4"}),(0,q.jsx)("rect",{x:"5.5",y:"5.5",width:"4",height:"4"}),(0,q.jsx)("rect",{x:"10.5",y:"5.5",width:"4",height:"4"})]})}),(0,q.jsx)("button",{type:"button",className:`results-view-toggle__btn${L==="list"?" is-active":""}`,"aria-pressed":L==="list","aria-label":"List view",title:"List view",onClick:()=>h("list"),children:(0,q.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,q.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,q.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,q.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),(0,q.jsxs)("details",{ref:wt,style:{position:"relative"},children:[(0,q.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort materials",style:{fontSize:16},children:"\u21C5"}),(0,q.jsx)("div",{className:"sort-menu-panel",children:Dx.map(N=>{let G=u===N.dir;return(0,q.jsxs)("button",{type:"button",className:`sort-menu-item${G?" is-active":""}`,onClick:()=>{b(G?null:N.dir),wt.current?.removeAttribute("open")},children:[(0,q.jsx)("span",{className:"sort-menu-item__check",children:G?"\u2713":""}),N.label]},N.dir)})})]})]})})]}),H&&(0,q.jsxs)("div",{className:"results-review-page",children:[(0,q.jsxs)("div",{className:"results-review-page__top",children:[(0,q.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:x,children:[(0,q.jsx)(Vr,{}),"Back to results"]}),(0,q.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,q.jsx)("div",{className:"results-review-searchbar",children:(0,q.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:X,onChange:N=>J(N.target.value),"aria-label":`Search a product for ${H.requirement.label}`})}),H.chosen&&(0,q.jsx)("div",{className:"results-candidate-actions",children:(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Le(H.requirement.key),children:"Clear selected product"})})]})]}),(0,q.jsxs)("div",{className:"results-review-page__hero",children:[(0,q.jsx)("div",{className:"results-review-page__image-wrap",children:(0,q.jsx)(za,{className:"fill-img results-review-page__image",description:H.chosen?.description||H.requirement.label,photoUrl:H.chosen?.pdp_photo_url})}),(0,q.jsxs)("div",{className:"results-review-page__summary",children:[(0,q.jsx)("h2",{children:H.requirement.label}),(0,q.jsxs)("p",{className:"results-review-page__meta",children:[yn(H.requirement.qty)," ",xa(H.requirement.unit,H.requirement.qty)]}),H.chosen?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)("div",{className:"results-review-page__product",children:H.chosen.description}),(0,q.jsxs)("div",{className:"results-row-meta",children:[H.chosen.product_id,H.chosen.price!=null?` \xB7 ${Sc(H.chosen.price,H.chosen.price_basis)}`:""]})]}):(0,q.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line."}),(0,q.jsx)("div",{className:"results-review-page__actions",children:(0,q.jsx)("button",{type:"button",className:`bom-toolbar-btn${i?.cart[pe(H.requirement.key)]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(H),disabled:!H.chosen||!i,children:i?.cart[pe(H.requirement.key)]?"\u2713 Added":"+ Add to basket"})})]})]}),de.length===0?(0,q.jsx)("p",{className:"results-empty-hint",children:"No matching products."}):(0,q.jsxs)("table",{className:"score-breakdown-table",children:[(0,q.jsx)("thead",{children:(0,q.jsxs)("tr",{children:[(0,q.jsx)("th",{children:"Product"}),(0,q.jsx)("th",{children:"Dims (mm)"}),(0,q.jsx)("th",{children:"Price"}),(0,q.jsx)("th",{"aria-label":"Actions"})]})}),(0,q.jsx)("tbody",{children:de.map(N=>{let G=N.product_id===H.chosen?.product_id;return(0,q.jsxs)("tr",{className:G?"score-breakdown-row--best":"",children:[(0,q.jsxs)("td",{children:[(0,q.jsx)("div",{children:N.description}),(0,q.jsx)("div",{className:"results-row-meta",children:N.product_id})]}),(0,q.jsx)("td",{children:(0,q.jsx)("span",{className:"unit-badge",children:Bx(N.measurements_mm)})}),(0,q.jsx)("td",{children:N.price!=null?Sc(N.price,N.price_basis):"-"}),(0,q.jsx)("td",{children:(0,q.jsxs)("label",{className:"switch-toggle",title:G?"Currently selected":"Use this candidate",children:[(0,q.jsx)("input",{type:"checkbox",checked:G,onChange:()=>{G?Le(H.requirement.key):$e(H.requirement.key,N)},"aria-label":G?`${N.description} selected`:`Use ${N.description}`}),(0,q.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},N.product_id)})})]})]}),!H&&d&&(0,q.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{padding:"32px 24px"},children:[(0,q.jsx)(vn,{}),(0,q.jsx)("p",{className:"banter-message is-visible",style:{fontSize:15,minHeight:0},children:"Matching your materials against the catalogue\u2026"})]}),!H&&w&&(0,q.jsx)("p",{className:"results-empty-hint estimator-products__error",children:w}),!H&&!d&&!w&&jt.length===0&&m.length>0&&(0,q.jsx)("p",{className:"results-empty-hint",children:"No materials match the current search."}),!H&&!d&&!w&&L==="tile"&&qe.length>0&&(0,q.jsx)("div",{className:"results-tile-grid",children:qe.map(N=>{let{requirement:G,chosen:Y}=N,ce=Y?Ft(Re(N),hm):null,Se=i?!!i.cart[pe(G.key)]:!1;return(0,q.jsxs)("article",{className:"results-tile-card",children:[(0,q.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>k(N),"aria-label":`Review match for ${G.label}`,children:[(0,q.jsx)("div",{className:"results-tile-card__media",children:(0,q.jsx)(za,{className:"fill-img results-tile-card__image",description:Y?.description||G.label,photoUrl:Y?.pdp_photo_url})}),(0,q.jsxs)("div",{className:"results-tile-card__body",children:[Y?(0,q.jsxs)("div",{className:"results-tile-card__heading",children:[(0,q.jsx)("div",{className:"results-tile-card__title",children:Y.description}),(0,q.jsxs)("div",{className:"results-tile-card__match-meta",children:[(0,q.jsx)("span",{children:Y.product_id}),Y.price!=null?(0,q.jsx)("span",{children:Sc(Y.price,Y.price_basis)}):null]})]}):(0,q.jsx)("div",{className:"results-empty-hint",children:"No product matched for this line."}),(0,q.jsxs)("div",{className:"results-tile-card__match",children:[(0,q.jsx)("div",{className:"results-tile-card__match-label",children:"\u21B3 calculated as"}),(0,q.jsx)("div",{className:"results-tile-card__match-name",children:G.label}),(0,q.jsxs)("div",{className:"results-tile-card__meta",children:[yn(G.qty)," ",xa(G.unit,G.qty)]}),ce?.requiredSellUnits!=null?(0,q.jsxs)("div",{className:"results-tile-card__meta estimator-products__order",children:["Order ",ce.requiredSellUnits," ",ce.sellUnit,ce.lineTotal!=null?` \xB7 ${ot(ce.lineTotal)}`:""]}):Y?(0,q.jsx)("div",{className:"results-row-meta",children:"Quantity needs review"}):null]})]})]}),(0,q.jsxs)("div",{className:"results-tile-card__actions",children:[(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>k(N),children:"Review"}),(0,q.jsx)("button",{type:"button",className:`bom-toolbar-btn${Se?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(N),disabled:!Y||!i,children:Se?"\u2713 Added":"+ Add"})]})]},G.key)})}),!H&&!d&&!w&&L==="list"&&qe.length>0&&(0,q.jsx)("div",{className:"bom-table-wrap",children:(0,q.jsxs)("table",{className:"bom-table results-table","aria-label":"Matched materials",children:[(0,q.jsxs)("colgroup",{children:[(0,q.jsx)("col",{style:{width:"56px"}}),(0,q.jsx)("col",{className:"col-item"}),(0,q.jsx)("col",{style:{width:"90px"}}),(0,q.jsx)("col",{style:{width:"80px"}}),(0,q.jsx)("col",{style:{width:"220px"}}),(0,q.jsx)("col",{style:{width:"110px"}})]}),(0,q.jsx)("thead",{children:(0,q.jsxs)("tr",{className:"bom-col-header",children:[(0,q.jsx)("th",{"aria-label":"Expand"}),(0,q.jsx)("th",{style:{textAlign:"left"},children:"Description"}),(0,q.jsx)("th",{style:{textAlign:"center"},children:"Qty"}),(0,q.jsx)("th",{style:{textAlign:"center"},children:"Unit"}),(0,q.jsx)("th",{style:{textAlign:"center"},children:"Product Matched"}),(0,q.jsx)("th",{style:{textAlign:"center"},children:"Basket"})]})}),(0,q.jsx)("tbody",{children:qe.map(N=>{let{requirement:G,chosen:Y}=N,ce=Y?Ft(Re(N),hm):null,Se=i?!!i.cart[pe(G.key)]:!1,yt=_e.has(G.key);return(0,q.jsxs)(je.Fragment,{children:[(0,q.jsxs)("tr",{className:"bom-row",children:[(0,q.jsx)("td",{className:"bom-actions",style:{textAlign:"center",paddingLeft:0,paddingRight:0},children:(0,q.jsx)("button",{type:"button",className:"link-btn",onClick:()=>U(G.key),"aria-expanded":yt,"aria-label":yt?"Collapse product options":"Expand product options",children:yt?"\u25BE":"\u25B8"})}),(0,q.jsxs)("td",{style:{paddingLeft:0},children:[(0,q.jsx)("div",{className:"bom-component-name",children:G.label}),ce?.requiredSellUnits!=null&&(0,q.jsxs)("div",{className:"results-row-meta",children:["Order ",ce.requiredSellUnits," ",ce.sellUnit,ce.lineTotal!=null?` \xB7 ${ot(ce.lineTotal)}`:""]})]}),(0,q.jsx)("td",{className:"bom-qty col-order",style:{textAlign:"center"},children:yn(G.qty)}),(0,q.jsx)("td",{style:{textAlign:"center"},children:xa(G.unit,G.qty)}),(0,q.jsx)("td",{style:{textAlign:"center"},children:Y?(0,q.jsxs)(q.Fragment,{children:[(0,q.jsx)("div",{className:"bom-component-name",children:Y.description}),(0,q.jsxs)("div",{className:"results-row-meta",children:[Y.product_id,Y.price!=null&&` \xB7 ${Sc(Y.price,Y.price_basis)}`]})]}):(0,q.jsx)("span",{className:"results-empty-hint",children:"No match"})}),(0,q.jsx)("td",{style:{textAlign:"center"},children:(0,q.jsx)("button",{type:"button",className:`bom-toolbar-btn${Se?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(N),disabled:!Y||!i,children:Se?"\u2713 Added":"+ Add"})})]}),yt&&(0,q.jsx)("tr",{children:(0,q.jsx)("td",{colSpan:6,style:{paddingLeft:0,paddingRight:0},children:C===G.key?Z(N):(0,q.jsxs)("div",{className:"estimator-products__picker",children:[(0,q.jsxs)("div",{className:"estimator-products__options",children:[N.candidates.map(ft=>(0,q.jsxs)("button",{type:"button",className:`estimator-products__option${ft.product_id===Y?.product_id?" is-selected":""}`,onClick:()=>$e(G.key,ft),children:[(0,q.jsx)("span",{children:ft.description}),(0,q.jsxs)("span",{className:"results-row-meta",children:[ft.product_id,ft.price!=null&&` \xB7 ${ot(ft.price)}`]})]},ft.product_id)),N.candidates.length===0&&(0,q.jsx)("p",{className:"results-empty-hint",children:"No candidates found."})]}),(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>me(N),children:"Search the catalogue"})]})})})]},G.key)})})]})}),!H&&!d&&!w&&ke.length>0&&(0,q.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,q.jsxs)("div",{className:"results-tile-section__head",children:[(0,q.jsx)("h3",{children:"Require Matching"}),(0,q.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,q.jsx)("div",{className:"results-unmatched-list",children:ke.map(N=>(0,q.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>k(N),children:[(0,q.jsxs)("span",{className:"results-unmatched-card__main",children:[(0,q.jsx)("span",{className:"results-unmatched-card__title",children:N.requirement.label}),(0,q.jsxs)("span",{className:"results-row-meta",children:[yn(N.requirement.qty)," ",xa(N.requirement.unit,N.requirement.qty)]})]}),(0,q.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},N.requirement.key))})]}),!d&&!w&&m.length>0&&(0,q.jsxs)("div",{className:"disclaimer-box",style:{alignItems:"center"},children:[(0,q.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,q.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."})]}),!H&&!d&&!w&&(r||z>0)&&(0,q.jsxs)("div",{className:"btn-row estimator-products__footer",children:[r&&(0,q.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:r,children:"Back"}),z>0&&i&&(0,q.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:r?"0 1 70%":1,marginTop:0},onClick:i.openBasket,children:[(0,q.jsxs)("span",{children:["View Basket (",z,")"]}),(0,q.jsx)("span",{className:"arrow",children:(0,q.jsx)(Qt,{})})]})]})]})}var Gt=$(ee());function bm({toolId:e,toolTitle:t,requirements:a,onBack:r}){let[n,i]=(0,Nc.useState)(0),o=(0,Nc.useCallback)(l=>i(l),[]);return(0,Gt.jsx)(Gt.Fragment,{children:(0,Gt.jsxs)("div",{className:"truss-estimator",children:[(0,Gt.jsxs)("div",{className:"quick-order-hero",children:[(0,Gt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Gt.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,Gt.jsx)("h1",{children:"Your Materials"}),n>0&&(0,Gt.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,Gt.jsx)("strong",{children:ot(n)})," Est. total"]})]}),(0,Gt.jsxs)("p",{children:["Quantities from the ",t,", matched against your merchant\u2019s catalogue."]})]}),(0,Gt.jsx)("div",{className:"truss-estimator__card",style:{minHeight:0},children:(0,Gt.jsx)(gm,{toolId:e,requirements:a,ready:!0,onBack:r,onTotalChange:o})})]})})}var Ae=$(ee());function Cc(e){let[t,a]=(0,Va.useState)(!1);return(0,Ae.jsx)(lc,{onOpenBasket:()=>a(!0),children:(0,Ae.jsx)(Lx,{...e,showBasket:t,onShowBasket:a})})}function Lx({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=mm.find(T=>T.id===i),{cart:m,updateCartQty:f,updateCartSellUnits:d,updateCartConversions:g,removeFromCart:w,clearCart:A}=Di(),{adding:L,basketError:h,addToBasket:u}=u0(p?.title??"calculator"),b=(0,Va.useRef)(null),v=Js("estimating-tools",b);(0,Va.useEffect)(()=>{v("viewed")},[v]);let _=r?"basket":L?"adding":l?"review":i??"list",C=(0,Va.useRef)(_);(0,Va.useEffect)(()=>{C.current!==_&&(C.current=_,window.scrollTo(0,0))},[_]);let R=T=>{if(!p)return;v("estimate_completed",{calculator:p.id,lines:T.length});let D=Qv(p.id,T);D?u(D,T[0]?.calculatorWasteIncluded??!1):c(T)};return(0,Ae.jsx)(tl.Provider,{value:v,children:(0,Ae.jsx)("div",{ref:b,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${a?"":" estimating-tools--customer"}`,style:Dt().theme,children:(0,Ae.jsx)("main",{className:"main-content",children:r?(0,Ae.jsx)(ul,{cart:m,onUpdateQty:f,onUpdateSellUnits:d,onResolveConversions:g,onRemove:w,onBack:()=>n(!1),onStartNewQuote:()=>{A(),o(null),c(null),n(!1)},internal:a}):L&&p?(0,Ae.jsx)(p0,{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:R})}),h&&(0,Ae.jsx)("p",{className:"results-empty-hint estimator-products__error",children:h}),l!==null&&(0,Ae.jsx)(bm,{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:mm.map(T=>(0,Ae.jsxs)("button",{type:"button",className:"estimator-tool-card",onClick:()=>{v("calculator_selected",{calculator:T.id}),o(T.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:It(T.imageUrl),alt:""})}),(0,Ae.jsxs)("span",{className:"estimator-tool-card__content",children:[(0,Ae.jsx)("span",{className:"estimator-tool-card__title",children:T.title}),(0,Ae.jsx)("span",{className:"estimator-tool-card__desc",children:T.desc})]})]},T.id))})]})]})})})})})}var qc=$(ee());function wm({config:e,children:t}){return xw(e),(0,qc.jsx)(qc.Fragment,{children:t})}var vm=$(ee()),Hx="https://api.metronlabs.ai",Qx=["client","api-key","api-url","theme","hide-header","analytics"],Gx=["all","events-only","none"];function f0(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.77",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; }
|
|
6975
6975
|
:host > div { all: initial; display: block; }
|
|
6976
6976
|
${_w}`,this.shadowRoot.replaceChildren(i,n),this.root=(0,m0.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")||Hx,client:n,apiKey:i,theme:Yx(e,this.getAttribute("theme")),analytics:jx(this.getAttribute("analytics"))};this.root.render((0,vm.jsx)(wm,{config:o,children:(0,vm.jsx)(t,{hideHeader:this.hasAttribute("hide-header")})}))}},a.observedAttributes=Qx,a))}function jx(e){return Gx.find(t=>t===e)??"all"}function Yx(e,t){if(t)try{return JSON.parse(t)}catch{console.error(`<${e}> theme attribute isn't valid JSON; using the default colours.`);return}}f0("metron-labs-quick-quote",uc);f0("metron-labs-estimating-tools",Cc);
|
|
6977
6977
|
/*! Bundled license information:
|