@metron-labs/quote-react 0.1.45 → 0.1.46
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/stages/BasketStage.d.ts +1 -1
- package/dist/app/stages/BasketStage.js +9 -4
- package/dist/components/estimators/BrickBlockEstimator.js +9 -3
- package/dist/components/estimators/ConcreteAggregateEstimator.js +4 -2
- package/dist/components/estimators/PavingEstimator.js +26 -10
- package/dist/components/estimators/PlasterboardEstimator.js +8 -3
- package/dist/components/estimators/registry.js +3 -3
- package/dist/embed/quote.js +1 -1
- package/package.json +1 -1
package/dist/embed/quote.js
CHANGED
|
@@ -6800,7 +6800,7 @@ C24 timber 4.8m`,value:p,onChange:Z=>d(Z.target.value),"aria-label":"Paste sched
|
|
|
6800
6800
|
<rect x="168" y="188" width="250" height="24" rx="12" fill="#aab5c0"/>
|
|
6801
6801
|
<rect x="168" y="232" width="220" height="24" rx="12" fill="#aab5c0"/>
|
|
6802
6802
|
</svg>
|
|
6803
|
-
`)}function Pr(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 aw=e=>(e??"").trim().toLowerCase(),e_={sqm:"m2","sq m":"m2","m\xB2":"m2",cbm:"m3","cu m":"m3",lm:"m","lin m":"m",metre:"m",meter:"m",each:"each",ea:"each",nr:"each",no:"each",item:"each",unit:"each",units:"each",pc:"each",pcs:"each",board:"sheet",bags:"bag",length:"length",lengths:"length",pallet:"pallet",pallets:"pallet"},vd=new Set(["sheet","length","box","bag","pack","roll","set","tub","each"]),Iv=new Set(["box","bag","pack","pallet","roll","set","tub"]),Wv=(e,t)=>t==="ml"?e:["l","litre","litres"].includes(t)?e*1e3:null,ew=(e,t)=>t==="g"?e:["kg","kilogram","kilograms"].includes(t)?e*1e3:["t","tonne","tonnes"].includes(t)?e*1e6:null,_i=e=>{let t=aw(e);return e_[t]??t},ct=(e,t)=>{let a=_i(e),r=_i(t);return a.length>0&&a===r},t_=(e,t)=>{let a=aw(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},a_=e=>(e??"").split(",").map(t=>_i(t)).filter(Boolean),r_=(e,t)=>{let a=a_(e.requestUomsSupported);return!!(a.length===0||a.includes(t)||ct(t,"pallet")&&e.itemsPerPallet!=null&&e.itemsPerPallet>0||ct(t,"pack")&&e.itemsPerPack!=null&&e.itemsPerPack>0||ct(t,"box")&&e.itemsPerBox!=null&&e.itemsPerBox>0)},tw=(e,t)=>ct(t,"pallet")?e.itemsPerPallet??null:ct(t,"pack")?e.itemsPerPack??null:ct(t,"box")?e.itemsPerBox??null:null,i_=(e,t,a)=>{if(!ct(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||!ct(r[3],a))return null;let i=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(i)&&i>0?i:null};function Is(e,t){return e.reduce((a,r)=>a+(Dt(r,t).lineTotal??0),0)}function Dt(e,t){let a=e.qty,r=_i(e.saleUnit??e.salesUnitSizeUom??e.uoi??e.salesUomNormalised)||"-",i=_i(e.unit)||(a>0&&vd.has(r)?r:"-"),n=e.saleUnitQuantity??e.salesUnitSize??e.uoiCount??1,o=t?.wasteFactorEnabled===!1?0:t?.wasteFactorOverride??e.wasteFactorOverride??e.wasteFactorDefault??0,l=e.sellUnitsOverride!=null&&Number.isFinite(e.sellUnitsOverride)&&e.sellUnitsOverride>0,c=l?vd.has(r)?Math.ceil(e.sellUnitsOverride):e.sellUnitsOverride:null,p=v=>({requestedAmount:a,requestedUnit:i,salesUnitSize:e.salesUnitSize??e.uoiCount??null,sellUnit:r,calculatedSellUnits:null,requiredSellUnits:c,unitPrice:e.price,lineTotal:e.price!=null&&c!=null?e.price*c:null,calculation:c!=null?`${v} Manually set to ${c} ${r}.`:v,costingMode:"review"});if(!r_(e,i))return p("Requested unit is not supported by this catalogue conversion.");let d=null,g="review",f=e.roundingRule,h=`Quantity review required, initial request needed ${a} ${i}.`,w=1+o,M=i_(e,i,r),D=e.unitConversions?.find(v=>ct(v.requestUom,i));if(!!e.saleUnit&&(ct(i,r)||!!D||ct(i,"each")&&!Iv.has(r)))if(ct(i,r))d=a*w/n,g="direct",h=`${a} ${i}${o>0?` x ${w}`:""}`;else if(D){d=a*w/D.quantityPerSaleUnit,g="derived";let v=1/D.quantityPerSaleUnit,N=Math.round(v);h=ct(r,"each")&&D.quantityPerSaleUnit<1&&Math.abs(v-N)<1e-9?`${a} ${i}${o>0?` x ${w}`:""} x ${N} per ${i}`:`${a} ${i}${o>0?` x ${w}`:""} / ${D.quantityPerSaleUnit} ${i} per ${r}`}else ct(i,"each")&&!Iv.has(r)&&(d=a*w/n,g="derived",h=`${a} ${r}${o>0?` x ${w}`:""}`);else if(ct(i,r)&&n>0)d=a*w/n,g="direct",h=o>0?`${a} ${i} x ${w} / ${n} ${r} per sell unit`:`${a} ${i} / ${n} ${r} per sell unit`;else if(ct(i,"each")&&n>0&&vd.has(r))d=a*w/n,g="derived",h=o>0?`${a} each x ${w} / ${n} each per ${r}`:`${a} each / ${n} each per ${r}`;else if(tw(e,i)!=null&&n>0){let v=tw(e,i)??0;d=a*v*w/n,g="derived";let N=`${a} ${i} x ${v} each${o>0?` x ${w}`:""}`;h=n===1&&ct(r,"each")?N:`${N} / ${n} each per ${r}`}else if(M!=null)d=a*w/M,g="derived",f??(f="round_up_each"),h=`${a} m2 x ${w} / ${M} m2 per ${r} (from product description)`;else if(e.conversionType==="basket_line_unit")n>0&&(d=a*w/n,g="derived",h=`${a} ${i}${o>0?` x ${w}`:""} / ${n} ${i} per ${r}`);else{if(e.conversionType==="count_only")return p(`Quantity review required, initial request needed ${a} ${i}.`);if(["area_from_dims","explicit_coverage_area","roll_area"].includes(e.conversionType??"")){let v=e.coverageQty??e.derivedCoverageM2??null;ct(i,"m2")&&v!=null&&v>0&&(d=a*w/v,g="derived",h=`${a} m2 x ${w} / ${v} m2 per ${r}`)}else if(e.conversionType==="count_per_area"){let v=e.coverageQty??null;ct(i,"m2")&&v!=null&&v>0?(d=a/v,g="derived",h=`${a} m2 / ${v} m2 per sell unit`):ct(i,"m2")&&e.itemsPerM2!=null&&e.itemsPerM2>0&&n>0&&(d=a*e.itemsPerM2*w/n,g="derived",h=`${a} m2 x ${e.itemsPerM2} ${r}/m2 x ${w} / ${n}`)}else if(e.conversionType==="length_from_dims"){let v=e.coverageQty??e.derivedLengthM??null;ct(i,"m")&&v!=null&&v>0&&(d=a*w/v,g="derived",h=`${a} m x ${w} / ${v} m per ${r}`)}else if(e.conversionType==="volume_from_description"){let v=Wv(a,i),N=Wv(e.coverageQty??0,_i(e.coverageUom));v!=null&&N!=null&&N>0&&(d=v*w/N,g="derived",h=`${a} ${i} x ${w} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="weight_from_description"){let v=ew(a,i),N=ew(e.coverageQty??0,_i(e.coverageUom));v!=null&&N!=null&&N>0&&(d=v*w/N,g="derived",h=`${a} ${i} x ${w} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="same_unit_volume"){let v=e.coverageQty??null;ct(i,"m3")&&v!=null&&v>0&&(d=a/v,g="derived",h=`${a} m3 / ${v} m3 per ${r}`)}}if(d==null||!Number.isFinite(d)||d<0)return p(`Quantity review required, initial request needed ${a} ${i}.`);let u=t_(d,f),b=l?c:u;return{requestedAmount:a,requestedUnit:i,salesUnitSize:n,sellUnit:r,calculatedSellUnits:u,requiredSellUnits:b,unitPrice:e.price,lineTotal:e.price!=null&&b!=null?e.price*b:null,calculation:l?`${h} = ${u} ${r} (manually set to ${b})`:`${h} = ${b} ${r}`,costingMode:g}}var rw=()=>import("./xlsx-K4MOA2QM.js"),al=["Source Line ID","Split Line ID","Description","Section","Qty","Unit","Procurement intent","Procurement aliases","Build-up type","Layer count","Total thickness (mm)","Installation clues","System clues","Component requirements","Technical classification","Include in quote","Approval required","Approval type","Missing information","Adjudicator confidence","Decision reason","Selected candidate ID","Selected candidate description","Price basis","Price","Line total","Confidence","Status"],n_=al.indexOf("Line total");function o_(e){return e.unmatchable?"Not matched (labour/plant/referential)":e.decision?.include_in_quote===!0&&e.decision.approval_required===!0?"Approval required":e.decision?.include_in_quote===!0?"Quoted":e.decision?.technical_classification==="no_suitable_candidate"?"No suitable candidate":(e.best,"No match")}async function iw(e){let t=await rw(),a=t.utils.book_new(),r=new Date().toISOString().slice(0,10),i=[al],n=0;for(let c of e){let{item:p,best:d,qty:g,band:f,unmatchable:h,decision:w}=c,M=[p.section,p.subsection,p.subheading].filter(Boolean).join(" / "),D=!h&&d?.price!=null?d.price*g:null;D!=null&&(n+=D),i.push([p.source_line_id,p.line_id,p.description_original||"(no description)",M,g,p.unit,p.procurement_intent||"-",p.procurement_aliases.join(", "),p.build_up_type,p.layer_count,p.total_required_thickness_mm,p.installation_clues.join(", "),p.system_clues.join(", "),p.component_requirements.join(", "),w?.technical_classification??"",w?.include_in_quote==null?"":w.include_in_quote?"yes":"no",w?.approval_required==null?"":w.approval_required?"yes":"no",w?.approval_type??"",w?.missing_information.join(", ")??"",w?.confidence??"",w?.reason??"",h?"-":d?.product_id??w?.selected_candidate_id??"-",h?"-":d?.description??"-",h?"-":d?.price_basis??"-",h?null:d?.price??null,D,h?"-":f,o_(c)])}i.push(Array(al.length).fill(null));let o=Array(al.length).fill(null);o[0]="Estimated total",o[n_]=n,i.push(o),i.push(["DISCLAIMER: These matches are generated automatically and should be reviewed before procurement, especially any items flagged as medium or low confidence.",...Array(al.length-1).fill(null)]);let l=t.utils.aoa_to_sheet(i);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 tl=["Product ID","Description","Costing mode","Required amount","Req unit","Sell unit size","Sell unit","Required sell units","Unit price","Line total"];async function nw(e,t){let a=await rw(),r=a.utils.book_new(),i=new Date().toISOString().slice(0,10),n=t?[["Account",t.name+" ("+t.id+")"],[],tl]:[tl],o=0;for(let p of e){let d=Dt(p),g=d.lineTotal;g!=null&&(o+=g),n.push([p.productId,p.description,d.costingMode,d.requestedAmount,ka(d.requestedUnit),d.salesUnitSize,ka(d.sellUnit),d.requiredSellUnits,d.unitPrice,g])}n.push(Array(tl.length).fill(null));let l=Array(tl.length).fill(null);l[0]="Estimated total",l[tl.length-1]=o,n.push(l);let c=a.utils.aoa_to_sheet(n);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}-${i}.xlsx`:`basket-${i}.xlsx`)}var s=X(ie()),yd="__none__",rl=24,l_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}];function cw(e){return e==null?"low":e>=.7?"high":e>=.5?"medium":"low"}var s_=e=>e.attrs.supply_nature==="labour_only"||e.attrs.supply_nature==="plant"||e.flags.includes("referential");function c_(e,t){if(t!==yd){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 ow(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 u_(e){return e?e.replace(/_/g," "):"not stated"}function p_({band:e}){return(0,s.jsx)("span",{className:`status-dot status-dot--${e}`,title:e,children:(0,s.jsx)("span",{className:"status-dot__mark"})})}function Tn(e,t){if(e==null)return"-";let a=el(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function _d(e){return e&&e.length>0?e.join(" x "):"-"}function d_(e){return e==null?"-":Number.isInteger(e/1e3)?`${e/1e3}m`:`${(e/1e3).toFixed(1)}m`}function Mn(e){let t=(e??[]).map(a=>a.trim()).filter(Boolean);return t.length>0?t.join(", "):"-"}function Jr(e,t){let a=typeof e.description_original=="string"?e.description_original.trim():"";return(typeof e.customer_display_label=="string"?e.customer_display_label.trim():"")||a||"(no description)"}var lw=[{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 m_(e){let t=new Map;return[...new Set(e.filter(gr).map(r=>r.linked_group_id))].forEach((r,i)=>{let n=i%26;t.set(r,{token:String.fromCharCode(65+n),bubbleStyle:lw[i%lw.length]})}),t}function gr(e){return!1}function zn(e){if(!e.linked_group_id)return null;let t=e.linked_group_label||"Linked group",a=e.linked_group_role==="anchor"?"anchor":e.linked_group_role==="dependent"?"dependent":"member",r=e.linked_group_shared_width_mm!=null?`, ${e.linked_group_shared_width_mm}mm family`:"";return`${t} (${a}${r})`}function wd({meta:e}){return e?(0,s.jsx)("span",{className:"results-linked-pill",style:e.bubbleStyle,children:`Link ${e.token}`}):null}function f_(e,t,a){let r=t?.rerank?.recommendedCandidateIds??[];if(r.length===0){let o=e.slice(0,5),l=o.some(c=>c.product_id===a)?void 0:e.find(c=>c.product_id===a);return l?[...o,l]:o}let i=new Map(e.map(o=>[o.product_id,o])),n=r.map(o=>i.get(o)).filter(o=>o!=null);if(a&&!n.some(o=>o.product_id===a)){let o=i.get(a);o&&n.unshift(o)}return[...new Map(n.map(o=>[o.product_id,o])).values()].slice(0,5)}function Ws(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 ec(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 g_({processStages:e,llmCalls:t,totalDurationMs:a,llmDurationMs:r,llmCallCount:i}){let n=[...t].sort((l,c)=>c.durationMs-l.durationMs).slice(0,12),o=Math.max(0,t.length-n.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:ec(a)})," total"]}),(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:i})," LLM calls"]}),(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:ec(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:ec(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:n.map((l,c)=>(0,s.jsxs)("tr",{children:[(0,s.jsx)("td",{children:l.label}),(0,s.jsx)("td",{children:ec(l.durationMs)})]},`${l.key}-${c}`))})]}),o>0&&(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Showing slowest ",n.length," of ",t.length," LLM calls."]})]})]})}function h_({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,i)=>(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:_d(r.measurements_mm)}),(0,s.jsx)("td",{children:el(r.price_basis)||"-"}),(0,s.jsx)("td",{children:r.bm25.toFixed(2)})]},`${r.product_id}-${i}`))})]})]},`${t.query}-${a}`))]})}function sw({item:e,result:t}){let a=t?.retrieval_debug.map(i=>i.query).filter(Boolean)??[],r=[["Procurement intent",e.procurement_intent||"-"],["Procurement aliases",Mn(e.procurement_aliases)],["Retrieval queries",Mn(a)],["Category",e.attrs.category||"-"],["Fine category",e.attrs.category_fine||"-"],["Brand",e.attrs.brand||"-"],["Material",e.attrs.material||"-"],["Grade / standard",e.attrs.grade_standard||"-"],["Treatment",e.attrs.treatment||"-"],["Supply nature",e.attrs.supply_nature||"-"],["Measurements (mm)",_d(e.attrs.measurements_mm)],["Stock length",d_(e.attrs.stock_length_mm)],["Matching mode",e.matching_mode||"-"],["Build-up type",e.build_up_type||"-"],["Layer count",e.layer_count!=null?String(e.layer_count):"-"],["Required thickness (mm)",e.total_required_thickness_mm!=null?String(e.total_required_thickness_mm):"-"],["Allowed layer thicknesses (mm)",e.acceptable_layer_thicknesses_mm.length>0?e.acceptable_layer_thicknesses_mm.join(", "):"-"],["Installation clues",Mn(e.installation_clues)],["System clues",Mn(e.system_clues)],["Component requirements",Mn(e.component_requirements)],["Linked group",zn(e)||"-"],["Flags",Mn(e.flags)]];return(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Search context"}),(0,s.jsx)("dl",{className:"results-detail-grid",children:r.map(([i,n])=>(0,s.jsxs)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:i}),(0,s.jsx)("dd",{children:n})]},i))})]})}function b_({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)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:"Attempted"}),(0,s.jsx)("dd",{children:t.attempted?"yes":"no"})]}),(0,s.jsxs)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:"Applied"}),(0,s.jsx)("dd",{children:t.applied?"yes":"no"})]}),(0,s.jsxs)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned items"}),(0,s.jsx)("dd",{children:t.returned_item_count??"-"})]}),(0,s.jsxs)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:"Reason"}),(0,s.jsx)("dd",{children:t.reason||"-"})]}),(0,s.jsxs)(Ne.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 v_({result:e}){let t=e?.adjudication_debug;if(!t)return null;let a=[["Dependent rerank applied",t.dependent_rerank_applied?"yes":"no"],["Linked parent selected product",t.linked_parent_selected_candidate_description||t.linked_parent_selected_candidate_id||"-"],["Dimension reason overridden",t.dimension_reason_overridden?"yes":"no"]];return(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Adjudication context"}),(0,s.jsx)("dl",{className:"results-detail-grid",children:a.map(([r,i])=>(0,s.jsxs)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:r}),(0,s.jsx)("dd",{children:i})]},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 w_({item:e,decision:t,result:a,showRetrievalDebug:r,reviewOnly:i=!1,linkedGroupMeta:n}){if(!t)return null;let o=t.technical_classification==="no_suitable_candidate"?"Exact match not found:":`AI review (${t.confidence??"confidence not stated"}):`;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:o}),"\xA0",t.reason]}),gr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",n?`Link ${n.token} - `:"",zn(e)]}):null]}):null:!t.reason&&!r?(0,s.jsx)(sw,{item:e,result:a}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(sw,{item:e,result:a}),r&&(0,s.jsx)(b_,{item:e}),r&&(0,s.jsx)(v_,{result:a}),t.reason&&(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,s.jsx)("strong",{children:o}),"\xA0",t.reason]}),gr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",n?`Link ${n.token} - `:"",zn(e)]}):null]}),r&&(0,s.jsx)(h_,{queries:a?.retrieval_debug??[]})]})}function y_({item:e,candidates:t,result:a,decision:r,unmatchable:i,selectedProductId:n,detailMode:o,onPick:l,onClear:c,showAll:p=!1,internal:d=!1,debugEnabled:g=!1,forceReviewNote:f=!1,linkedGroupMeta:h}){let w=d||o==="detailed",M=g&&o==="detailed",D=w||f?(0,s.jsx)(w_,{item:e,decision:r,result:a,showRetrievalDebug:M,reviewOnly:f&&!w,linkedGroupMeta:h}):null;if(i)return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsx)("p",{className:"results-empty-hint",children:"Classified as labour/plant or referencing another line item - skipped by design."})]});if(t.length===0)return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsx)("p",{className:"results-empty-hint",children:"No candidates were returned for this line item."})]});let m=p||d||o==="detailed"?t:f_(t,a,n);return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsxs)("table",{className:"score-breakdown-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Product"}),(0,s.jsx)("th",{children:"Dims (mm)"}),(0,s.jsx)("th",{children:"Price"}),M&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("th",{children:"dimension"}),(0,s.jsx)("th",{children:"grade"}),(0,s.jsx)("th",{children:"brand"}),(0,s.jsx)("th",{children:"fuzzy"}),(0,s.jsx)("th",{children:"bm25"}),(0,s.jsx)("th",{children:"overall"})]}),(0,s.jsx)("th",{"aria-label":"Actions"})]})}),(0,s.jsx)("tbody",{children:m.map((u,b)=>{let v=u.product_id===n;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:_d(u.measurements_mm??u.debug?.candidate.measurements_mm)})}),(0,s.jsx)("td",{children:Tn(u.price,u.price_basis)}),M&&(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)(p_,{band:cw(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 xd({scheduleResult:e,onStartOver:t,cart:a,onAddToCart:r,onRemoveFromCart:i,onGoToBasket:n,cartSeeded:o,onCartSeeded:l,reviewGateComplete:c,onReviewGateComplete:p,internal:d=!1}){let g=!d&&Vs()==="QZA6-MRA4",f=g?"quote":"basket",{results:h,lineItems:w,parseReport:M,timings:D}=e,[m,u]=(0,Ne.useState)({}),b=Sn(),[v,N]=(0,Ne.useState)({}),[A,T]=(0,Ne.useState)({}),[z,G]=(0,Ne.useState)(""),[P,be]=(0,Ne.useState)(null),[De,Le]=(0,Ne.useState)(1),He=Ra().debug===!0,[ze,me]=(0,Ne.useState)("simple"),[ce,fe]=(0,Ne.useState)(d?"list":"tile"),[Ee,ut]=(0,Ne.useState)(!1),[Se,Z]=(0,Ne.useState)(null),[de,Je]=(0,Ne.useState)(""),[Ye,pt]=(0,Ne.useState)([]),[ot,at]=(0,Ne.useState)(!1),[ge,W]=(0,Ne.useState)(null),[k,R]=(0,Ne.useState)(!1),[E,O]=(0,Ne.useState)(null),ee=(0,Ne.useRef)(null),[xe,we]=(0,Ne.useState)(new Set),[y,j]=(0,Ne.useState)(new Set),[B,ae]=(0,Ne.useState)(!1);(0,Ne.useEffect)(()=>{Le(1)},[z,P,ce]);let te=new Map(h.map(x=>[x.line_id,x])),q=m_(w),Y=w.map(x=>{let H=te.get(x.line_id),ye=H?.decision,ft=s_(x),Ke=m[x.line_id],Wt=c_(H,Ke),Ti=a[x.line_id],Xw=Ke===yd?void 0:v[x.line_id]??(Ti&&Ti.productId!==Wt?.product_id?ow(Ti):Wt),om=ft?void 0:Xw,Vw=x.qty??0;return{item:x,result:H,decision:ye,unmatchable:ft,best:om,qty:Vw,band:cw(om?.scores?.overall)}}),K=Is(Object.values(a),{wasteFactorEnabled:!1,wasteFactorOverride:0}),pe=0;for(let x of Y){if(x.unmatchable||x.decision?.include_in_quote!==!0||!x.best)continue;let H=a[x.item.line_id];(!H||Dt(H).lineTotal==null)&&(pe+=1)}pe>0&&(K=null);let ke=x=>!x.unmatchable&&!x.best&&x.decision?.technical_classification!=="no_suitable_candidate"&&Ws(x.result).length>0,Fe=x=>x.best??Ws(x.result)[0],ua=Y.filter(x=>!x.unmatchable&&!x.best).filter(x=>!y.has(x.item.line_id)),ul=Y.filter(x=>y.has(x.item.line_id)),pa=Y;if(z.trim()){let x=z.trim().toLowerCase();pa=pa.filter(H=>H.item.description_original?.toLowerCase().includes(x)||Fe(H)?.description?.toLowerCase().includes(x))}if(P){let x=P==="asc"?1:-1;pa=[...pa].sort((H,ye)=>x*(H.item.description_original||"").localeCompare(ye.item.description_original||""))}let Qn=Math.max(1,Math.ceil(pa.length/rl)),It=Math.min(De,Qn),vr=pa.slice((It-1)*rl,It*rl),$a=vr.filter(x=>!x.unmatchable&&x.best),Fd=vr.filter(x=>ke(x)),Gn=vr.filter(x=>!x.unmatchable&&(x.best||ke(x))),Id=vr.filter(x=>x.unmatchable||!x.best&&!ke(x)),J=Se?Y.find(x=>x.item.line_id===Se)??null:null,Bw=!d&&!c&&!J&&ua.length>0,Yn=(0,Ne.useRef)(null),Xn=()=>{let x=ee.current;if(!x)return;let{top:H,left:ye,width:ft,height:Ke}=x.getBoundingClientRect(),Ti=x.querySelector(".bom-toolbar-btn")?.closest("td")?.getBoundingClientRect().left;O({top:H,left:ye,width:Ti?Ti-ye:ft,height:Ke})};(0,Ne.useEffect)(()=>(window.addEventListener("scroll",Xn,!0),window.addEventListener("resize",Xn),()=>{window.removeEventListener("scroll",Xn,!0),window.removeEventListener("resize",Xn)})),(0,Ne.useEffect)(()=>{let x=H=>{Yn.current&&!H.composedPath().includes(Yn.current)&&Yn.current.removeAttribute("open")};return document.addEventListener("click",x),()=>document.removeEventListener("click",x)},[]);let qi=x=>{Z(x),Je("")},Lw=()=>{if(!Se)return;let x=a[Se];if(x){u(H=>({...H,[Se]:x.productId})),N(H=>({...H,[Se]:ow(x)}));return}u(H=>{let ye={...H};return delete ye[Se],ye}),N(H=>{let ye={...H};return delete ye[Se],ye})},Za=(x=!1)=>{let H=Se?a[Se]:void 0;!x&&H&&J?.best&&H.productId!==J.best.product_id&&!window.confirm("You have selected a new product. Leave without updating it?")||(x||Lw(),Z(null),ae(!1))};Io(k,()=>R(!1)),Io(!!J&&!k,()=>Za());let Hw=x=>{if(we(H=>new Set(H).add(x)),ua.some(H=>H.item.line_id!==x)){Za(!0);return}p(),Za(!0)},jw=x=>{if(_c(x),j(H=>new Set(H).add(x)),ua.some(H=>H.item.line_id!==x)){Za(!0);return}p(),Za(!0)},Qw=()=>{j(x=>new Set([...x,...ua.map(H=>H.item.line_id)])),p()},Wd=()=>{J?.best&&(tm(J.item.line_id,J.best),r(Ei(J)),B?Hw(J.item.line_id):Za(!0))},em=Id.length>0?(0,s.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,s.jsxs)("div",{className:"results-tile-section__head",children:[(0,s.jsx)("h3",{children:"Require Matching"}),(0,s.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,s.jsx)("div",{className:"results-unmatched-list",children:Id.map(x=>{let{item:H,qty:ye}=x;return(0,s.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>qi(H.line_id),children:[(0,s.jsx)("span",{className:"results-unmatched-card__main",children:(0,s.jsx)("span",{className:"results-unmatched-card__title",children:Jr(H,w)})}),(0,s.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},H.line_id)})})]}):null,_c=x=>{u(H=>({...H,[x]:yd})),N(H=>({...H,[x]:void 0})),T(H=>({...H,[x]:void 0})),i(x)},xc=(x,H)=>{u(ye=>({...ye,[x]:H.product_id})),N(ye=>({...ye,[x]:H}))},tm=(x,H)=>{H.method==="catalogue_search"&&T(ye=>({...ye,[x]:H}))};function sx(){b("downloaded",{type:"schedule",lines:Y.length}),iw(Y.map(({item:x,best:H,qty:ye,band:ft,unmatchable:Ke,decision:Wt})=>({item:x,best:H,qty:ye,band:ft,unmatchable:Ke,decision:Wt})))}function Ei(x){let H=x.best??Ws(x.result)[0];return Pr(H,{lineId:x.item.line_id,description:x.item.description_original,unit:x.item.unit,qty:x.qty,linkedContext:x.item.linked_group_role==="dependent"&&x.item.linked_group_id?w.filter(ye=>ye.linked_group_id===x.item.linked_group_id&&ye.linked_group_role==="anchor").slice(0,1).map(ye=>{let ft=a[ye.line_id];return{line_id:ye.line_id,product_id:ft?.productId??null,measurements_mm:ft?.measurementsMm??ye.attrs.measurements_mm,description:ft?.description??ye.description_original,qty:ye.qty,unit:ye.unit,role:"anchor"}}):void 0})}(0,Ne.useEffect)(()=>{if(!o){for(let x of Y)!x.unmatchable&&x.best&&r(Ei(x));l()}},[o]),(0,Ne.useEffect)(()=>{for(let x of Y)!a[x.item.line_id]&&!x.unmatchable&&x.best&&r(Ei(x))},[e]),(0,Ne.useEffect)(()=>{if(!Se){pt([]),W(null),at(!1);return}let x=de.trim();if(!x){pt([]),W(null),at(!1);return}let H=!1,ye=window.setTimeout(async()=>{try{at(!0),W(null);let ft=await fetch(Ht(`/api/catalogue/search?q=${encodeURIComponent(x)}`),{headers:vi()}),Ke=await Pt(ft);if(!ft.ok)throw new Error(Ke?.error||Ke?.message||"Failed to search catalogue");H||pt(Array.isArray(Ke?.items)?Ke.items:[])}catch(ft){H||(pt([]),W(ft?.message||"Failed to search catalogue"))}finally{H||at(!1)}},250);return()=>{H=!0,window.clearTimeout(ye)}},[de,Se]);let kc=Object.keys(a).length,Ma=de.trim(),am=Ws(J?.result),pl=J?.decision?.technical_classification==="no_suitable_candidate"||!!J&&!J.best,rm=J?.decision?.technical_classification!=null,im=J?.decision?.reason??(pl?"No catalogue candidate found. Refine the request or search the catalogue.":null),Gw=Ye.map(x=>({product_id:x.product_id,description:x.description,source_list:x.source_list,price:x.price,price_basis:x.price_basis,uoi_count:x.uoi_count??null,uoi:x.uoi,pdp_photo_url:x.pdp_photo_url??null,conversion:x.conversion,measurements_mm:x.measurements_mm??[],scores:{dimension:0,grade:0,brand:0,fuzzy:0,bm25:0,overall:0},method:"catalogue_search"})),Vn=Ma?Gw:am,Mi=J?A[J.item.line_id]:void 0,$n=!Ma&&Mi&&!Vn.some(x=>x.product_id===Mi.product_id)?[...Vn,Mi]:Vn,nm=(()=>{let x=$n.slice(0,Ma?12:3);return Ma||!Mi||x.some(H=>H.product_id===Mi.product_id)?x:[...x,Mi]})(),dl=!!J?.best&&a[J.item.line_id]?.productId===J.best.product_id,Yw=!!J?.best&&!!a[J.item.line_id]&&!dl;return(0,s.jsxs)("div",{className:"wizard-step entry-stage",children:[(0,s.jsxs)("div",{className:`quick-order-card${d?"":" quick-order-card--customer"}`,children:[(0,s.jsx)("div",{className:`quick-order-hero${d?"":" quick-order-hero--customer"}`,children:d?(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:K==null?"Calculating\u2026":nt(K)})," 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 ",g?"View Quote":"View Basket"," to continue."]})]}),(0,s.jsxs)("button",{type:"button",className:"results-total-action",onClick:n,"aria-label":g?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:g?"View Quote":"View Basket"}),(0,s.jsx)("strong",{children:K==null?"Calculating\u2026":nt(K)})]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(jt,{})})]})]})}),(0,s.jsxs)("div",{className:"quick-order-panel",style:{paddingTop:16},children:[He&&(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:()=>ut(x=>!x),children:Ee?"Hide timings":"Show timings"})}),He&&Ee&&(0,s.jsx)(g_,{...D}),!g&&(0,s.jsx)("div",{className:"results-toolbar-row",children:!J&&(0,s.jsxs)("div",{className:"results-summary",style:{marginBottom:0},children:[pe>0&&(0,s.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,s.jsx)("strong",{children:pe})," need pricing"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:z,onChange:x=>G(x.target.value),"aria-label":"Search line items"}),!d&&(0,s.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,s.jsx)("button",{type:"button",className:`results-view-toggle__btn${ce==="tile"?" is-active":""}`,"aria-pressed":ce==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>fe("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${ce==="list"?" is-active":""}`,"aria-pressed":ce==="list","aria-label":"List view",title:"List view",onClick:()=>fe("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"})]})})]}),He&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>me(x=>x==="simple"?"detailed":"simple"),children:ze==="detailed"?"Hide detailed view":"Show detailed view"}),(0,s.jsxs)("details",{ref:Yn,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:l_.map(x=>{let H=P===x.dir;return(0,s.jsxs)("button",{type:"button",className:`sort-menu-item${H?" is-active":""}`,onClick:()=>{be(H?null:x.dir),Yn.current?.removeAttribute("open")},children:[(0,s.jsx)("span",{className:"sort-menu-item__check",children:H?"\u2713":""}),x.label]},x.dir)})})]})]})]})}),ce==="tile"||J?(0,s.jsxs)(s.Fragment,{children:[J?(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop",role:"dialog","aria-modal":"true","aria-label":"Product options",onClick:()=>Za(),children:(0,s.jsxs)("section",{className:"quick-order-workflow-modal results-review-modal",onClick:x=>x.stopPropagation(),children:[(0,s.jsx)("button",{type:"button",className:"quick-order-workflow-close results-review-modal__close",onClick:()=>Za(),"aria-label":"Close product options",children:(0,s.jsx)(Jo,{})}),(0,s.jsx)("div",{className:"results-review-page",children:d?(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:()=>Za(),children:[(0,s.jsx)(Kr,{}),"Back to results"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[He&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>me(x=>x==="simple"?"detailed":"simple"),children:ze==="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:de,onChange:x=>Je(x.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:()=>_c(J.item.line_id),children:"Clear selected product"})})]})]}),(0,s.jsxs)("div",{className:"results-review-page__hero",children:[(0,s.jsx)("div",{className:"results-review-page__image-wrap",children:(0,s.jsx)("img",{className:"fill-img results-review-page__image",src:Ya(Fe(J)?.description||J.item.description_original,Fe(J)?.product_id,Fe(J)?.pdp_photo_url),alt:""})}),(0,s.jsxs)("div",{className:"results-review-page__summary",children:[(0,s.jsx)("h2",{children:Jr(J.item,w)}),(0,s.jsxs)("p",{className:"results-review-page__meta",children:[yi(J.qty)," ",Na(J.item.unit,J.qty)]}),J.best?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:J.best.description}),J.best.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Tn(J.best.price,J.best.price_basis)}):null]}):Fe(J)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:Fe(J)?.description}),Fe(J)?.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Tn(Fe(J)?.price??null,Fe(J)?.price_basis??null)}):null,(0,s.jsx)("div",{className:"results-row-meta",children:"Best reviewed alternative - not yet selected"})]}):(0,s.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line item."}),gr(J.item)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[(0,s.jsx)(wd,{meta:q.get(J.item.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:zn(J.item)})]}):null,(0,s.jsx)("div",{className:"results-review-page__actions",children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[J.item.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[J.item.line_id]?i(J.item.line_id):(J.best&&tm(J.item.line_id,J.best),r(Ei(J)))},disabled:!J.best,"aria-label":a[J.item.line_id]?d?"Remove from selection":`Remove from ${f}`:d?"Add to selection":`Add to ${f}`,children:a[J.item.line_id]?"\u2713 Added":d?"+ Add to selection":`Add to ${f}`})})]})]}),ot?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,!ot&&ge?(0,s.jsx)("div",{className:"results-empty-card",children:ge}):null,!ot&&!ge&&Ma&&Vn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No candidate products match this database search."}):!ot&&!ge?(0,s.jsx)(y_,{item:J.item,candidates:Vn,result:J.result,decision:J.decision,unmatchable:J.unmatchable,selectedProductId:J.best?.product_id??null,detailMode:ze,linkedGroupMeta:gr(J.item)?q.get(J.item.linked_group_id):void 0,onPick:x=>xc(J.item.line_id,x),onClear:()=>_c(J.item.line_id),showAll:d||He||Ma.length>0,internal:d,debugEnabled:He,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:Jr(J.item,w)||"Original request"})]}),im?(0,s.jsxs)("section",{className:"customer-review-ai",children:[(0,s.jsx)("strong",{children:pl?"Exact match not found:":"AI review:"})," ",im]}):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:pl?"We couldn't find a suitable product":rm?"Choose a product":"We couldn't review this item"}),(0,s.jsx)("p",{children:pl?am.length>0?"These AI-reviewed alternatives may be useful, but need approval.":"Search the catalogue to choose an alternative.":rm?`Select the option you want to add to your ${f}.`:"Search the catalogue to choose a product."})]})}),!Ma&&$n.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:nm.map(x=>{let H=x.product_id===J.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${H?" is-selected":""}`,onClick:()=>xc(J.item.line_id,x),"aria-pressed":H,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Ya(x.description,x.product_id,x.pdp_photo_url),alt:"",width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:x.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:x.price!=null?`\xA3${Tn(x.price,x.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:H?"Selected":"Choose"})]},x.product_id)})}):null,$n.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:de,onChange:x=>Je(x.target.value),"aria-label":"Search catalogue"})]}),Ma&&ot?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,Ma&&!ot&&ge?(0,s.jsx)("div",{className:"results-empty-card",children:ge}):null,Ma&&!ot&&!ge&&$n.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No products match this search."}):null,Ma&&!ot&&!ge&&$n.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:nm.map(x=>{let H=x.product_id===J.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${H?" is-selected":""}`,onClick:()=>xc(J.item.line_id,x),"aria-pressed":H,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Ya(x.description,x.product_id,x.pdp_photo_url),alt:"",width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:x.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:x.price!=null?`\xA3${Tn(x.price,x.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:H?"Selected":"Choose"})]},x.product_id)})}):null]}),J.best?Yw?(0,s.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,s.jsx)("button",{type:"button",className:"cta-btn customer-review-add",onClick:()=>{Wd()},children:(0,s.jsx)("span",{children:"Update product"})}),(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-add",onClick:()=>i(J.item.line_id),children:(0,s.jsx)("span",{children:`Remove from ${f}`})})]}):(0,s.jsx)("button",{type:"button",className:`cta-btn customer-review-add${dl?" cta-btn-secondary":""}`,onClick:()=>{dl?i(J.item.line_id):Wd()},children:(0,s.jsx)("span",{children:dl?`Remove from ${f}`:`Add selected product to ${f}`})}):null,B?(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-skip",onClick:()=>jw(J.item.line_id),children:"Skip this item"}):null]})})]})}):null,(0,s.jsxs)("div",{className:"results-tile-layout",children:[pa.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No line items match the current search/filter."}):null,Gn.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:Gn.map(x=>{let{item:H,best:ye,qty:ft}=x,Ke=Fe(x),Wt=!ye&&ke(x);return(0,s.jsxs)("article",{className:"results-tile-card",children:[(0,s.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>qi(H.line_id),"aria-label":`Review match for ${Jr(H,w)||"item"}`,children:[(0,s.jsxs)("div",{className:"results-tile-card__media",children:[Wt||gr(H)?(0,s.jsxs)("div",{className:"results-tile-card__badges",children:[gr(H)?(0,s.jsx)(wd,{meta:q.get(H.linked_group_id)}):(0,s.jsx)("span",{}),Wt?(0,s.jsx)("span",{style:{padding:"6px 10px",borderRadius:999,background:"#fef3c7",color:"#92400e",fontSize:12,fontWeight:700,lineHeight:1},children:"Partially matched"}):null]}):null,(0,s.jsx)("img",{className:"fill-img results-tile-card__image",src:Ya(Ke?.description||H.description_original,Ke?.product_id,Ke?.pdp_photo_url),alt:""})]}),(0,s.jsxs)("div",{className:"results-tile-card__body",children:[Ke?(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:Ke.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:Ke?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-tile-card__match-label",children:Wt?"\u21B3 partially matched from":"\u21B3 matched from"}),(0,s.jsx)("div",{className:"results-tile-card__match-name",children:Jr(H,w)}),gr(H)?(0,s.jsx)("div",{className:"results-row-meta",children:zn(H)}):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:[d&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>qi(H.line_id),children:"Review"}),(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[H.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[H.line_id]?i(H.line_id):r(Ei(x))},disabled:!Ke,"aria-label":a[H.line_id]?d?"Remove from selection":`Remove from ${f}`:d?"Add to selection":`Add to ${f}`,children:a[H.line_id]?"\u2713 Added":d?"+ Add":`Add to ${f}`})]})]},H.line_id)})})}):null,em]})]}):(0,s.jsxs)(s.Fragment,{children:[E&&(0,s.jsx)("div",{className:"results-table__hover-overlay",style:E,"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"}}),ze==="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"}),ze==="simple"&&(0,s.jsx)("th",{style:{textAlign:"center"},children:d?"Selection":g?"Quote":"Basket"})]})}),(0,s.jsxs)("tbody",{children:[pa.length===0&&(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:ze==="simple"?4:3,className:"results-empty-hint",style:{padding:"16px 8px"},children:"No line items match the current search/filter."})}),Gn.map(x=>{let{item:H,result:ye,decision:ft,best:Ke}=x;return(0,s.jsxs)("tr",{className:"bom-row results-table__review-row",onClick:()=>qi(H.line_id),onMouseEnter:Wt=>{ee.current=Wt.currentTarget,Xn()},onMouseLeave:()=>{ee.current=null,O(null)},children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{className:"bom-component-name",children:Jr(H,w)}),gr(H)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,s.jsx)(wd,{meta:q.get(H.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:zn(H)})]}):null]}),(0,s.jsx)("td",{children:Ke?(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"results-match-cell-text",title:Ke.description,children:Ke.description}),ze==="detailed"&&ft?.technical_classification&&(0,s.jsxs)("div",{className:"results-row-meta",children:[u_(ft.technical_classification),ft.approval_required?" - approval required":""]})]}):(0,s.jsx)("span",{className:"results-empty-hint"})}),(0,s.jsx)("td",{style:{textAlign:"center"},children:Ke?.price!=null?Tn(Ke.price,Ke.price_basis):"-"}),ze==="simple"&&(0,s.jsx)("td",{style:{textAlign:"center"},children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[H.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,style:{width:84,justifyContent:"center"},onClick:Wt=>{Wt.stopPropagation(),a[H.line_id]?i(H.line_id):r(Ei(x))},"aria-label":a[H.line_id]?d?"Remove from selection":`Remove from ${f}`:d?"Add to selection":`Add to ${f}`,children:a[H.line_id]?"\u2713 Added":d?"+ Add":`Add to ${f}`})})]},H.line_id)})]})]})}),em]}),!J&&Qn>1&&(0,s.jsxs)("div",{className:"results-pagination",children:[(0,s.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(It-1)*rl+1,"\u2013",Math.min(It*rl,pa.length)," of ",pa.length]}),(0,s.jsxs)("div",{className:"results-pagination-controls",children:[(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Le(It-1),disabled:It===1,children:"Previous"}),(0,s.jsxs)("span",{className:"results-pagination-page",children:["Page ",It," of ",Qn]}),(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Le(It+1),disabled:It===Qn,children:"Next"})]})]}),(M.itemCount!=null||M.headingCount!=null||M.skippedCount!=null)&&(0,s.jsxs)("div",{className:"results-summary",style:{marginTop:16},children:[M.itemCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.itemCount})," items parsed"]}),M.headingCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.headingCount})," headings"]}),M.skippedCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.skippedCount})," rows skipped"]})]}),(0,s.jsxs)("div",{className:"disclaimer-box",children:[(0,s.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,s.jsx)("p",{className:"disclaimer-text",children:"These matches are generated automatically and should be reviewed before purchase."})]}),!J&&(0,s.jsxs)("div",{className:"btn-row results-actions",children:[(0,s.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:(kc>0,"0 1 30%"),gap:10,justifyContent:"center"},onClick:()=>R(!0),"aria-label":"Start over",children:[(0,s.jsx)(hd,{}),(0,s.jsx)("span",{children:"Start Over"})]}),kc>0&&(0,s.jsxs)("button",{className:"cta-btn",style:{flex:"0 1 70%"},onClick:n,"aria-label":d?"View selection":g?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[d?"View Selection":g?"View Quote":"View Basket"," (",kc,")"]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(jt,{})})]})]})]})]}),Bw&&(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:ua.map(x=>{let H=xe.has(x.item.line_id),ye=ke(x);return(0,s.jsx)("div",{className:`review-gate-item${H?" is-reviewed":""}`,children:(0,s.jsxs)("button",{type:"button",className:"review-gate-item__review",onClick:()=>{ae(!0),qi(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Jr(x.item,w)}),(0,s.jsx)("span",{children:x.decision?.reason||(ye?"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:H?"Choice made":"Choose a product"})]})},x.item.line_id)})}),(0,s.jsx)("button",{type:"button",className:"review-gate-skip",onClick:Qw,children:"Skip all"}),ul.length>0?(0,s.jsxs)("div",{className:"review-gate-skipped",children:[(0,s.jsx)("strong",{children:"Skipped"}),ul.map(x=>(0,s.jsxs)("button",{type:"button",className:"review-gate-item is-skipped",onClick:()=>{j(H=>{let ye=new Set(H);return ye.delete(x.item.line_id),ye}),ae(!0),qi(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Jr(x.item,w)}),(0,s.jsx)("span",{children:`Not added to your ${f}.`})]}),(0,s.jsx)("span",{className:"review-gate-item__action",children:"Choose a product"})]},x.item.line_id))]}):null]})}),k&&(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 ",g?"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:()=>R(!1),children:"Cancel"}),(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-danger",onClick:()=>{R(!1),t()},autoFocus:!0,children:"Start Over"})]})]})})]})}var _t=X(Xe());var C=X(ie()),__=.2,il=10,uw="Enter a valid email address so we can send your quote.",x_=(e,t)=>{let a=`${t.requestedAmount} ${ka(t.requestedUnit,t.requestedAmount)}`,r=`${t.requiredSellUnits} ${ka(t.sellUnit,t.requiredSellUnits??0)}`,i=e.unitConversions?.find(n=>n.requestUom===t.requestedUnit);return i&&i.quantityPerSaleUnit<1?`${a} requested \u2192 order ${r} (${Math.round(1/i.quantityPerSaleUnit)} ${ka(t.sellUnit,2)} per ${ka(t.requestedUnit,1)})`:e.coverageQty&&/^m per /i.test(e.coverageUom??"")?`${a} requested \u2192 order ${r} (${e.coverageQty} ${e.coverageUom})`:`${a} requested \u2192 order ${r}`},k_=e=>["box","pack"].includes(e.requestedUnit)?"Pack size needed to calculate the order quantity.":`This product is sold by ${ka(e.sellUnit,1)}.`;function N_(){return(0,C.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,C.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,C.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,C.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,C.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function nl(){return(0,C.jsx)("svg",{width:"8",height:"5",viewBox:"0 0 8 5",fill:"none",children:(0,C.jsx)("path",{d:"M1 4L4 1L7 4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function ol({cart:e,onUpdateQty:t,onUpdateSellUnits:a,onResolveConversions:r,onRemove:i,onBack:n,onStartNewQuote:o,onQuoteRequested:l,internal:c=!1}){let p=(0,_t.useId)(),d=!c&&Vs()==="QZA6-MRA4",g=Object.values(e),[f,h]=(0,_t.useState)(""),[w,M]=(0,_t.useState)(!1),[D,m]=(0,_t.useState)(!1),u=Sn(),[b,v]=(0,_t.useState)(""),[N,A]=(0,_t.useState)({}),[T,z]=(0,_t.useState)({}),[G,P]=(0,_t.useState)(1),[be,De]=(0,_t.useState)({}),[Le,He]=(0,_t.useState)(!1),[ze,me]=(0,_t.useState)("0"),ce=(0,_t.useRef)(new Set);(0,_t.useEffect)(()=>{if(!r)return;for(let O of Object.values(e))Dt(O).requiredSellUnits!=null&&ce.current.delete(O.lineId);let E=Object.values(e).filter(O=>O.productId!=="-"&&Dt(O).requiredSellUnits==null&&!ce.current.has(O.lineId));E.length!==0&&(E.forEach(O=>ce.current.add(O.lineId)),fetch(Ht("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({lines:E.map(O=>({line_id:O.lineId,product_id:O.productId,requested_description:O.requestedDescription??O.description,requested_qty:O.qty,requested_uom:O.unit||null,linked_context:O.linkedContext??[],selected_description:O.description,selected_uoi:O.uoi,selected_uoi_count:O.uoiCount,selected_conversion:{sales_uom_normalised:O.salesUomNormalised,conversion_type:O.conversionType,sales_unit_size:O.salesUnitSize,sales_unit_size_uom:O.salesUnitSizeUom,coverage_qty:O.coverageQty,coverage_uom:O.coverageUom}}))})}).then(O=>O.ok?Pt(O):null).then(O=>{let ee={};for(let xe of O?.data?.items??O?.items??[]){let we=xe?.conversion;if(!we||typeof xe?.line_id!="string")continue;let y=e[xe.line_id];ee[xe.line_id]={conversionType:we.conversion_type,requestUomsSupported:we.request_uoms_supported,salesUomNormalised:we.sales_uom_normalised,salesUnitSize:we.sales_unit_size,salesUnitSizeUom:we.sales_unit_size_uom,coverageQty:we.coverage_qty,coverageUom:we.coverage_uom,roundingRule:we.rounding_rule,conversionConfidence:we.conversion_confidence,conversionNotes:we.conversion_notes,...y?.qty===0&&Number.isFinite(we.suggested_order_qty)&&we.suggested_order_qty>0?{qty:we.suggested_order_qty,unit:we.suggested_order_uom||y.unit}:{}}}Object.keys(ee).length>0&&r(ee)}).catch(O=>console.error("Catalogue conversion resolution failed",O)))},[e,r]);function fe(E){A(O=>{let ee={...O};return delete ee[E],ee})}function Ee(E,O){let ee=parseFloat(O);!isNaN(ee)&&ee>=0&&t(E,Math.min(ee,1e5)),fe(E)}function ut(E,O,ee){t(E,Math.min(1e5,Math.max(0,O+ee))),fe(E)}function Se(E){z(O=>{let ee={...O};return delete ee[E],ee})}function Z(E,O){let ee=parseFloat(O);!isNaN(ee)&&ee>=0&&a(E,Math.min(ee,1e5)),Se(E)}function de(E,O,ee){a(E,Math.min(1e5,Math.max(0,O+ee))),Se(E)}async function Je(){let E=f.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(E)){v(uw);return}v(""),m(!0);try{let O=await fetch(Ht("/api/quote-requests"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({email:E,items:Ye.map(({item:ee,pricing:xe})=>{let we=xe.requiredSellUnits??xe.requestedAmount,y=xe.requiredSellUnits!=null?xe.sellUnit:xe.requestedUnit;return{product_id:ee.productId,description:ee.description,quantity:we,unit:ka(y,we),unit_price:xe.requiredSellUnits!=null?xe.unitPrice:null,line_total:xe.lineTotal}})})});if(!O.ok){let ee=await Pt(O);console.error("Quote request failed",O.status,ee?.message),v(O.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}u("quote_requested",{items:Ye.length,total:Math.round(at*100)/100}),M(!0),l?.(),window.scrollTo(0,0)}catch{v("Your request couldn't be sent. Check your connection and try again.")}finally{m(!1)}}let Ye=g.map(E=>({item:E,pricing:Dt(E,{wasteFactorEnabled:Le,wasteFactorOverride:Math.max(0,Number.parseFloat(ze)||0)/100})})),pt=Is(g,{wasteFactorEnabled:Le,wasteFactorOverride:Math.max(0,Number.parseFloat(ze)||0)/100}),ot=pt*__,at=pt+ot,ge=(0,_t.useRef)({items:Ye.length,total:Math.round(at*100)/100});(0,_t.useEffect)(()=>{u("basket_viewed",ge.current)},[u]);let W=Math.max(1,Math.ceil(Ye.length/il)),k=Math.min(G,W),R=Ye.slice((k-1)*il,k*il);return w?(0,C.jsx)("div",{className:"wizard-step entry-stage",children:(0,C.jsxs)("div",{className:"quote-request-sent",role:"status",children:[(0,C.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,C.jsx)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,C.jsx)("polyline",{points:"5 12.5 10 17.5 19 7"})})}),(0,C.jsx)("h1",{children:"Quote requested"}),(0,C.jsxs)("p",{children:["You're all done. We'll email your sharper price to ",(0,C.jsx)("strong",{children:f.trim()}),", usually within one working day."]}),(0,C.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,C.jsx)("span",{children:"Start a new quote"})}),(0,C.jsx)("p",{className:"quote-request-sent-note",children:"Nothing is charged until you approve the quote."})]})}):!c&&g.length===0?(0,C.jsx)("div",{className:"wizard-step entry-stage",children:(0,C.jsxs)("div",{className:"quote-request-sent",children:[(0,C.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,C.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,C.jsx)("path",{d:"M3 9h18l-2 11H5z"}),(0,C.jsx)("path",{d:"M8 9l4-6 4 6"})]})}),(0,C.jsx)("h1",{children:d?"Your quote request is empty":"Your basket is empty"}),(0,C.jsx)("p",{children:d?"Start again with your list to build your quote.":"Start again with your list to fill your basket."}),(0,C.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,C.jsx)("span",{children:"Back to start"})})]})}):(0,C.jsx)("div",{className:`wizard-step entry-stage${d?" basket-layout--qza6-mra4":""}`,children:(0,C.jsxs)("div",{className:`quick-order-card${c?"":" quick-order-card--customer"}`,children:[(0,C.jsxs)("div",{className:`quick-order-hero${c?"":" quick-order-hero--customer"}`,children:[c&&(0,C.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,C.jsxs)("div",{className:"basket-hero-copy",children:[d&&(0,C.jsxs)("button",{type:"button",className:"cta-btn cta-btn-secondary basket-hero-back",onClick:n,children:[(0,C.jsx)(Kr,{}),(0,C.jsx)("span",{children:"Back to results"})]}),(0,C.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,C.jsx)("h1",{children:c?"Your Selection":d?"Request a quote":"Your Basket"}),c&&(0,C.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,C.jsx)("strong",{children:g.length})," ",g.length===1?"item":"items"]})]}),(0,C.jsx)("p",{children:c?"Review the items you've added before exporting them for review.":d?"Check your items & quantities below, and we'll do our best to beat list prices.":"Review your quantities and order summary before you buy."})]})]}),(0,C.jsx)("div",{className:"quick-order-panel",style:{paddingTop:16},children:g.length===0?(0,C.jsxs)("div",{className:"quick-order-history-empty",children:[(0,C.jsx)("div",{className:"basket-empty-icon","aria-hidden":"true",children:"\u{1F4CB}"}),(0,C.jsx)("p",{children:"Your selection is empty."}),(0,C.jsx)("p",{className:"basket-empty-hint",children:"Go back to your results and add quoted items."}),(0,C.jsx)("div",{className:"btn-row",style:{marginTop:20,justifyContent:"center"},children:(0,C.jsx)("button",{className:"cta-btn",style:{width:"auto",maxWidth:280},onClick:n,"aria-label":"Back to results",children:(0,C.jsx)("span",{children:"Back to Results"})})})]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)("div",{className:"basket-layout",children:[(0,C.jsxs)("div",{className:"basket-main",children:[(0,C.jsx)("div",{className:"basket-list","aria-label":c?"Selection items":d?"Quote request items":"Basket items",children:R.map(({item:E,pricing:O})=>{let ee=N[E.lineId]??String(O.requestedAmount),xe=O.requestedUnit===O.sellUnit||O.costingMode==="review",we=O.requiredSellUnits==null||O.requestedAmount!==O.requiredSellUnits||O.requestedUnit!==O.sellUnit;return(0,C.jsxs)("article",{className:"basket-card",children:[(0,C.jsxs)("div",{className:"basket-card-top",children:[(0,C.jsx)("img",{className:"basket-card-thumb",src:Ya(E.description,E.productId,E.pdpPhotoUrl),alt:"",width:48,height:48}),(0,C.jsxs)("div",{className:"basket-card-info",children:[(0,C.jsx)("div",{className:"bom-component-name",children:E.description}),we&&O.costingMode!=="review"&&(0,C.jsxs)("button",{type:"button",className:"basket-calc-toggle",onClick:()=>De(y=>({...y,[E.lineId]:!y[E.lineId]})),"aria-expanded":!!be[E.lineId],children:["How we calculated this",(0,C.jsx)("span",{className:`basket-calc-toggle-chevron${be[E.lineId]?" basket-calc-toggle-chevron--open":""}`,children:(0,C.jsx)(nl,{})})]})]}),(0,C.jsx)("div",{className:"basket-card-actions",children:(0,C.jsx)("button",{type:"button",className:"mf-remove-small-btn basket-card-remove",onClick:()=>i(E.lineId),"aria-label":`Remove ${E.description}`,children:(0,C.jsx)(N_,{})})})]}),c&&(0,C.jsxs)("div",{className:"results-detail-block basket-internal-detail",children:[(0,C.jsxs)("dl",{className:"results-detail-grid",children:[(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Conversion type"}),(0,C.jsx)("dd",{children:E.conversionType??"-"})]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Conversion confidence"}),(0,C.jsx)("dd",{children:E.conversionConfidence??"-"})]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Sales unit"}),(0,C.jsx)("dd",{children:E.salesUnitSize!=null?(0,C.jsxs)(C.Fragment,{children:[E.salesUnitSize," ",Na(E.salesUnitSizeUom,E.salesUnitSize)]}):"-"})]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Coverage"}),(0,C.jsx)("dd",{children:E.coverageQty!=null?(0,C.jsxs)(C.Fragment,{children:[E.coverageQty," ",Na(E.coverageUom,E.coverageQty)]}):"-"})]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Waste factor"}),(0,C.jsx)("dd",{children:E.wasteFactorDefault??"-"})]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Rounding rule"}),(0,C.jsx)("dd",{children:E.roundingRule??"-"})]})]}),E.conversionNotes&&(0,C.jsx)("p",{className:"results-rerank-note",children:E.conversionNotes})]}),O.costingMode==="review"?(0,C.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,C.jsx)("strong",{children:"Quantity needs confirmation."})," ",k_(O)]}):we&&be[E.lineId]?(0,C.jsx)("p",{className:"basket-calc-text",children:x_(E,O)}):null,(0,C.jsxs)("div",{className:"basket-card-stats",children:[(0,C.jsxs)("div",{className:"basket-stat",children:[(0,C.jsx)("span",{className:"basket-stat-label",children:"Requested qty"}),(0,C.jsxs)("div",{className:"basket-stat-value",children:[(0,C.jsxs)("div",{className:"basket-qty-field",children:[(0,C.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:ee,disabled:xe,onChange:y=>A(j=>({...j,[E.lineId]:y.target.value})),onBlur:y=>Ee(E.lineId,y.target.value),onKeyDown:y=>{y.key==="Enter"&&y.target.blur()},"aria-label":`${E.description} requested quantity`}),(0,C.jsxs)("div",{className:"basket-qty-arrows",children:[(0,C.jsx)("button",{type:"button",className:"basket-qty-arrow",disabled:xe,onClick:()=>ut(E.lineId,parseFloat(ee)||0,1),"aria-label":`Increase ${E.description} quantity`,children:(0,C.jsx)(nl,{})}),(0,C.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",disabled:xe,onClick:()=>ut(E.lineId,parseFloat(ee)||0,-1),"aria-label":`Decrease ${E.description} quantity`,children:(0,C.jsx)(nl,{})})]})]}),(0,C.jsx)("span",{className:"basket-metric-unit",children:Na(O.requestedUnit,parseFloat(ee)||0)})]})]}),(0,C.jsxs)("div",{className:"basket-stat basket-stat--right",children:[(0,C.jsx)("span",{className:"basket-stat-label",children:"Order qty"}),(0,C.jsxs)("div",{className:"basket-stat-value",children:[(0,C.jsxs)("div",{className:"basket-qty-field",children:[(0,C.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:T[E.lineId]??String(O.requiredSellUnits??""),onChange:y=>z(j=>({...j,[E.lineId]:y.target.value})),onBlur:y=>Z(E.lineId,y.target.value),onKeyDown:y=>{y.key==="Enter"&&y.target.blur()},"aria-label":`${E.description} order quantity`}),(0,C.jsxs)("div",{className:"basket-qty-arrows",children:[(0,C.jsx)("button",{type:"button",className:"basket-qty-arrow",onClick:()=>de(E.lineId,parseFloat(T[E.lineId]??String(O.requiredSellUnits??"0"))||0,1),"aria-label":`Increase ${E.description} order quantity`,children:(0,C.jsx)(nl,{})}),(0,C.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",onClick:()=>de(E.lineId,parseFloat(T[E.lineId]??String(O.requiredSellUnits??"0"))||0,-1),"aria-label":`Decrease ${E.description} order quantity`,children:(0,C.jsx)(nl,{})})]})]}),(0,C.jsx)("span",{className:"basket-metric-unit",children:Na(O.sellUnit,parseFloat(T[E.lineId]??String(O.requiredSellUnits??"0"))||0)})]})]}),(0,C.jsxs)("div",{className:"basket-stat basket-stat--total",children:[(0,C.jsx)("span",{className:"basket-stat-label",children:"Total"}),(0,C.jsxs)("div",{className:"basket-stat-value",children:[(0,C.jsx)("strong",{children:O.lineTotal!=null?nt(O.lineTotal):"-"}),O.lineTotal!=null&&(0,C.jsx)("span",{className:"basket-metric-unit",children:"ex. VAT"})]})]})]})]},E.lineId)})}),W>1&&(0,C.jsxs)("div",{className:"results-pagination",children:[(0,C.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(k-1)*il+1,"\u2013",Math.min(k*il,Ye.length)," of ",Ye.length]}),(0,C.jsxs)("div",{className:"results-pagination-controls",children:[(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>P(k-1),disabled:k===1,children:"Previous"}),(0,C.jsxs)("span",{className:"results-pagination-page",children:["Page ",k," of ",W]}),(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>P(k+1),disabled:k===W,children:"Next"})]})]})]}),(0,C.jsxs)("aside",{className:"basket-sidebar",children:[(0,C.jsx)("div",{className:"basket-sidebar-title",children:d?"Quote request summary":"Order summary"}),(0,C.jsxs)("div",{className:"basket-sidebar-row",children:[(0,C.jsx)("span",{children:d?"List price (ex. VAT)":"Subtotal (ex. VAT)"}),(0,C.jsx)("span",{children:nt(pt)})]}),(0,C.jsxs)("div",{className:"basket-sidebar-row",children:[(0,C.jsx)("span",{children:"VAT (20%)"}),(0,C.jsx)("span",{children:nt(ot)})]}),(0,C.jsxs)("div",{className:"basket-sidebar-row basket-sidebar-row--total",children:[(0,C.jsx)("span",{children:d?"List price (inc.\xA0VAT)":"Total"}),(0,C.jsx)("span",{children:nt(at)})]}),!d&&(0,C.jsx)("div",{className:"basket-summary-waste",children:(0,C.jsxs)("div",{className:"basket-waste-control",children:[(0,C.jsxs)("label",{className:"basket-global-waste",children:[(0,C.jsx)("input",{type:"checkbox",checked:Le,onChange:E=>He(E.target.checked)}),(0,C.jsx)("span",{children:"Add waste factor"})]}),(0,C.jsxs)("label",{className:"basket-global-waste-percent",children:[(0,C.jsx)("input",{type:"number",inputMode:"decimal",min:"0",step:"0.1",value:ze,onChange:E=>me(E.target.value),disabled:!Le,"aria-label":"Waste factor percent"}),(0,C.jsx)("span",{children:"%"})]})]})}),(0,C.jsx)("label",{htmlFor:`${p}-basket-reference`,className:"basket-sidebar-label",children:d?"Enter email for your sharper quote":"Your reference (optional)"}),(0,C.jsx)("input",{id:`${p}-basket-reference`,type:d?"email":"text",className:"basket-sidebar-input",value:f,onChange:E=>{h(E.target.value),d&&v("")},placeholder:d?"you@example.com":"PO number or job reference","aria-invalid":d&&b===uw,"aria-describedby":d&&b?`${p}-basket-reference-error`:void 0}),d&&b&&(0,C.jsx)("p",{id:`${p}-basket-reference-error`,className:"basket-quote-request-error",role:"alert",children:b}),d?(0,C.jsx)("button",{type:"button",className:"cta-btn",onClick:()=>{Je()},disabled:D,"aria-busy":D,children:(0,C.jsx)("span",{children:D?"Sending\u2026":"Request our best quote"})}):(0,C.jsx)("button",{className:"cta-btn",onClick:()=>{u("downloaded",{type:"basket",items:g.length}),nw(g)},"aria-label":c?"Download selection":"Download basket",children:(0,C.jsx)("span",{children:c?"Download Quote":"Buy Now"})}),(0,C.jsxs)("p",{className:"basket-sidebar-disclaimer",children:[(0,C.jsx)("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),d?"This is a quote request, not an order. We'll confirm our best price, availability and delivery before you approve.":"Prices and availability are estimates and should be confirmed before procurement."]})]})]}),(0,C.jsx)("div",{className:"btn-row results-actions",children:(0,C.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",gap:10,justifyContent:"center"},onClick:n,"aria-label":"Back to results",children:[(0,C.jsx)(Kr,{}),(0,C.jsx)("span",{children:"Back to results"})]})})]})})]})})}var At=X(Xe()),pw=X(ie());function S_(e,t){let a={...e,[t.lineId]:t};for(let[r,i]of Object.entries(a)){if(!i.linkedContext)continue;let n=i.linkedContext.find(l=>l.role==="anchor"&&l.line_id&&a[l.line_id]),o=n?.line_id?a[n.line_id]:void 0;if(!(!n||!o||n.product_id===o.productId&&n.description===o.description)){if(i.conversionType!=="basket_line_unit"){a[r]={...i,linkedContext:i.linkedContext.map(l=>l.line_id===n.line_id?{...l,product_id:o.productId,measurements_mm:o.measurementsMm??[],description:o.description}:l)};continue}a[r]={...i,qty:0,sellUnitsOverride:null,linkedContext:i.linkedContext.map(l=>l.line_id===n.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 Nd=(0,At.createContext)(null);function tc({children:e,onOpenBasket:t}){let[a,r]=(0,At.useState)({}),i=(0,At.useCallback)(f=>{r(h=>S_(h,f))},[]),n=(0,At.useCallback)(f=>{r(h=>{let w={...h};for(let M of f)w[M.lineId]=M;return w})},[]),o=(0,At.useCallback)(f=>{r(h=>{let w={...h};return delete w[f],w})},[]),l=(0,At.useCallback)((f,h)=>{r(w=>w[f]?{...w,[f]:{...w[f],qty:h,sellUnitsOverride:null}}:w)},[]),c=(0,At.useCallback)((f,h)=>{r(w=>w[f]?{...w,[f]:{...w[f],sellUnitsOverride:h}}:w)},[]),p=(0,At.useCallback)(f=>{r(h=>{let w=!1,M={...h};for(let[D,m]of Object.entries(f))M[D]&&(M[D]={...M[D],...m},w=!0);return w?M:h})},[]),d=(0,At.useCallback)(()=>r({}),[]),g=(0,At.useMemo)(()=>({cart:a,count:Object.keys(a).length,addToCart:i,addManyToCart:n,removeFromCart:o,updateCartQty:l,updateCartSellUnits:c,updateCartConversions:p,clearCart:d,openBasket:t??(()=>{})}),[a,i,n,o,l,c,p,d,t]);return(0,pw.jsx)(Nd.Provider,{value:g,children:e})}function An(){let e=(0,At.useContext)(Nd);if(!e)throw new Error("useCart must be used inside a <CartProvider>");return e}function ac(){return(0,At.useContext)(Nd)}var Sa=X(ie()),Sd="metron-quick-quote";function rc(e){return(0,Sa.jsx)(tc,{children:(0,Sa.jsx)(C_,{...e})})}function C_({fullPage:e=!1,hideHeader:t=!1,internal:a=!1}){let[r,i]=(0,Re.useState)("entry"),[n,o]=(0,Re.useState)(null),[l,c]=(0,Re.useState)(""),p=(0,Re.useRef)(null),d=(0,Re.useRef)(0),[g,f]=(0,Re.useState)(0),[h,w]=(0,Re.useState)(null),[M,D]=(0,Re.useState)(!1),{cart:m,addToCart:u,addManyToCart:b,removeFromCart:v,updateCartQty:N,updateCartSellUnits:A,updateCartConversions:T,clearCart:z}=An(),[G,P]=(0,Re.useState)(!1),[be,De]=(0,Re.useState)(null),Le=()=>{De(null);try{window.sessionStorage.removeItem(Fs)}catch{}},He=(0,Re.useRef)(new Map),ze=(0,Re.useRef)(null),me=Xs("quick-quote",ze);(0,Re.useEffect)(()=>{me("viewed")},[me]),(0,Re.useEffect)(()=>{for(let W of Object.values(m))Dt(W).requiredSellUnits!=null&&He.current.delete(W.lineId);let ge=Object.values(m).filter(W=>{if(W.productId==="-"||Dt(W).requiredSellUnits!=null)return!1;let k=`${W.productId}|${W.qty}|${W.unit}`;return He.current.get(W.lineId)===k?!1:(He.current.set(W.lineId,k),!0)});ge.length!==0&&fetch(Ht("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({lines:ge.map(W=>({line_id:W.lineId,product_id:W.productId,requested_description:W.requestedDescription??W.description,requested_qty:W.qty,requested_uom:W.unit||null,selected_description:W.description,selected_uoi:W.uoi,selected_uoi_count:W.uoiCount,linked_context:W.linkedContext??[],selected_conversion:{sales_uom_normalised:W.salesUomNormalised,conversion_type:W.conversionType,sales_unit_size:W.salesUnitSize,sales_unit_size_uom:W.salesUnitSizeUom,coverage_qty:W.coverageQty,coverage_uom:W.coverageUom}}))})}).then(W=>W.ok?Pt(W):null).then(W=>{let k={};for(let R of W?.data?.items??W?.items??[]){let E=R?.conversion;if(!E||typeof R?.line_id!="string")continue;let O=m[R.line_id];k[R.line_id]={conversionType:E.conversion_type,requestUomsSupported:E.request_uoms_supported,salesUomNormalised:E.sales_uom_normalised,salesUnitSize:E.sales_unit_size,salesUnitSizeUom:E.sales_unit_size_uom,coverageQty:E.coverage_qty,coverageUom:E.coverage_uom,roundingRule:E.rounding_rule,conversionConfidence:E.conversion_confidence,conversionNotes:E.conversion_notes,...O?.qty===0&&Number.isFinite(E.suggested_order_qty)&&E.suggested_order_qty>0?{qty:E.suggested_order_qty,unit:E.suggested_order_uom||O.unit}:{}}}Object.keys(k).length>0&&T(k)}).catch(W=>console.error("Catalogue conversion resolution failed",W))},[m,T]);let[ce,fe]=(0,Re.useState)(!1);(0,Re.useEffect)(()=>{let ge=window.location.hash,W=null;try{W=JSON.parse(window.sessionStorage.getItem(Sd)??"null")}catch{}if(W?.scheduleResult)o("schedule"),w(W.scheduleResult),D(W.reviewGateComplete),P(W.cartSeeded),b(Object.values(W.cart)),ge==="#quote-request"?i("basket"):ge==="#matched-products"&&i("results");else if(ge==="#matched-products"||ge==="#quote-request"){let k=new URL(window.location.href);k.hash="",window.history.replaceState(window.history.state,"",k)}fe(!0)},[]),(0,Re.useEffect)(()=>{if(ce)try{h?window.sessionStorage.setItem(Sd,JSON.stringify({scheduleResult:h,reviewGateComplete:M,cartSeeded:G,cart:m})):window.sessionStorage.removeItem(Sd)}catch{}},[ce,h,M,G,m]);let Ee=(0,Re.useCallback)(ge=>{if(typeof window>"u")return;let W=new URL(window.location.href);W.hash=ge==="basket"?"quote-request":"matched-products";let k=ge==="results"&&(window.location.hash==="#matched-products"||window.location.hash==="#quote-request");window.history[k?"replaceState":"pushState"]({boqQuoteStage:ge},"",W)},[]),ut=(0,Re.useRef)(!1);(0,Re.useEffect)(()=>{let ge=W=>{ut.current=!1;let k=window.location.hash;k==="#quote-request"?i("basket"):k==="#matched-products"&&h?(o("schedule"),i("results")):i("entry");let R=W.state,E=window.location.href;setTimeout(()=>{if(window.location.href===E){if(k==="#quote-request"||k==="#matched-products"||k==="#quote-entry"){window.history.replaceState({boqQuoteStage:k==="#quote-request"?"basket":k==="#quote-entry"?"entry":"results"},"",E);return}!R?.turbo&&window.history.state?.turbo&&window.history.replaceState(R,"",E)}})};return window.addEventListener("popstate",ge),()=>window.removeEventListener("popstate",ge)},[h]);let Se=(0,Re.useCallback)(()=>{Ee("basket"),i("basket")},[Ee]),Z=(0,Re.useCallback)(()=>{if(window.location.hash==="#quote-request"){if(ut.current)return;ut.current=!0,window.history.back();return}i(h?"results":"entry")},[h]),de=(0,Re.useRef)(r);(0,Re.useEffect)(()=>{de.current!==r&&(de.current=r,window.scrollTo(0,0))},[r]);let Je=()=>{i("entry"),o(null),c(""),f(0),w(null),D(!1),z(),P(!1),Le()},Ye=(0,Re.useCallback)(async(ge,W,k=!0)=>{let R=++d.current;c(""),f(0);let E=0,O=()=>{E=Math.min(E+1,3),f(E)};try{let{jobId:ee}=await nv(ge,W,k);if(R!==d.current)return;let{promise:xe,cancel:we}=lv(()=>ov(ee),5e3,O,"schedule");p.current=we;let y=await xe;if(y.status==="failed"||!y.result)throw new Error(y.error||"Failed to process schedule");let j=y.result.lineItems.length,B=y.result.results.filter(ae=>ae.candidates.length>0).length;me("results_shown",{lines:j,matched:B,unmatched:j-B}),z(),P(!1),D(!1),w(y.result),Ee("results"),i("results")}catch(ee){if(R!==d.current)return;me("error",{stage:"matching"}),c(ee?.message||"Failed to process schedule"),i("entry")}finally{R===d.current&&(p.current?.(),p.current=null)}},[Ee,me,z]),pt=(0,Re.useCallback)(()=>{d.current++,p.current?.(),p.current=null},[]),ot=(0,Re.useCallback)(async(ge,W,k=!0)=>{if(!ge.trim())return;o("schedule");let R=new File([ge],"pasted-schedule.txt",{type:"text/plain"});await Ye(R,W,k)},[Ye]),at=(0,Re.useCallback)(async ge=>{o("schedule"),await Ye(ge)},[Ye]);return(0,Sa.jsx)(Po.Provider,{value:me,children:(0,Sa.jsx)("div",{ref:ze,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${!e&&r==="processing"?" app-wrapper--loading":""}`,style:Ra().theme,children:(0,Sa.jsxs)("main",{className:"main-content",children:[l&&(0,Sa.jsxs)("div",{className:"error-box",role:"alert",children:[(0,Sa.jsx)("strong",{children:"Error:"})," ",l]}),r==="entry"&&(0,Sa.jsx)(fd,{onPasteSchedule:ot,onUploadSchedule:at,onEntryModeChange:o,draft:be,onSubmitDraft:De,onCancelMatch:pt}),r==="results"&&n==="schedule"&&h&&(0,Sa.jsx)(xd,{scheduleResult:h,onStartOver:Je,cart:m,onAddToCart:u,onRemoveFromCart:v,onGoToBasket:Se,cartSeeded:G,onCartSeeded:()=>P(!0),reviewGateComplete:M,onReviewGateComplete:()=>D(!0),internal:a}),r==="basket"&&(0,Sa.jsx)(ol,{cart:m,onUpdateQty:N,onUpdateSellUnits:A,onRemove:v,onBack:Z,onStartNewQuote:Je,onQuoteRequested:()=>{w(null),D(!1),P(!1),z(),Le()},internal:a})]})})})}var Va=X(Xe());var xi=X(Xe()),re=X(ie()),dw=[{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"}],ic=e=>Number.parseFloat(e)||0,mw=(e,t)=>ic(e)*(t==="m"?1:.3048),Cd=(e,t)=>ic(e.quantity)*(2*mw(e.height,t)+mw(e.width,t)),q_=()=>({quantity:"1",width:"",height:""});function E_({profile:e}){return(0,re.jsxs)("svg",{className:"architrave-calculator__profile-diagram",viewBox:"0 0 112 76","aria-hidden":"true",children:[(0,re.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,re.jsx)("line",{x1:"12",y1:"66",x2:"100",y2:"66"})]})}function qd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,xi.useState)("m"),[n,o]=(0,xi.useState)({quantity:"1",width:"0.76",height:"1.98"}),[l,c]=(0,xi.useState)({quantity:"0",width:"1.52",height:"1.98"}),[p,d]=(0,xi.useState)([]),[g,f]=(0,xi.useState)("ogee"),[h,w]=(0,xi.useState)("2.4"),M=(N,A,T)=>{N(z=>({...z,[A]:T}))},D=Cd(n,r)+Cd(l,r)+p.reduce((N,A)=>N+Cd(A,r),0),m=ic(h)>0?Math.ceil(D/ic(h)):0,u=dw.find(N=>N.id===g)?.label??"",b=[{key:`architrave-${g}`,label:`Architrave (${u})`,qty:D,unit:"m",query:`${u} architrave`,category:"architrave"}],v=(N,A,T,z)=>(0,re.jsxs)("div",{className:"architrave-calculator__opening-row",children:[(0,re.jsx)("span",{children:N}),(0,re.jsx)("input",{"aria-label":`${N} quantity`,type:"number",min:"0",step:"1",value:A.quantity,onChange:G=>T("quantity",G.target.value)}),(0,re.jsx)("input",{"aria-label":`${N} width`,type:"number",min:"0",step:"0.01",value:A.width,onChange:G=>T("width",G.target.value)}),(0,re.jsx)("input",{"aria-label":`${N} height`,type:"number",min:"0",step:"0.01",value:A.height,onChange:G=>T("height",G.target.value)}),z?(0,re.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:z,children:"Remove"}):null]});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:"Architrave Calculator"}),(0,re.jsx)("p",{children:"Estimate architrave lengths and board quantities for door openings."})]}),(0,re.jsxs)("div",{className:"truss-estimator__card architrave-calculator",children:[(0,re.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure your openings"}),(0,re.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,re.jsxs)("div",{className:"architrave-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Door openings"}),(0,re.jsx)("p",{className:"architrave-calculator__hint",children:"Each opening is calculated as two side pieces plus one head piece."}),(0,re.jsxs)("div",{className:"architrave-calculator__unit-row",children:[(0,re.jsx)("span",{children:"Units"}),(0,re.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,re.jsx)("button",{type:"button",className:r==="m"?"is-selected":"",onClick:()=>i("m"),children:"Metres"}),(0,re.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>i("ft"),children:"Feet"})]})]}),(0,re.jsxs)("div",{className:"architrave-calculator__dimensions-header",children:[(0,re.jsx)("span",{children:"Opening"}),(0,re.jsx)("span",{children:"Qty"}),(0,re.jsxs)("span",{children:["Width (",r,")"]}),(0,re.jsxs)("span",{children:["Height (",r,")"]}),(0,re.jsx)("span",{})]}),v("Single doors",n,(N,A)=>M(o,N,A)),v("Double doors",l,(N,A)=>M(c,N,A)),p.map((N,A)=>v(`Alternative door ${A+1}`,N,(T,z)=>d(G=>G.map((P,be)=>be===A?{...P,[T]:z}:P)),()=>d(T=>T.filter((z,G)=>G!==A)))),(0,re.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>d(N=>[...N,q_()]),children:"+ Add alternative-sized door"})]}),(0,re.jsxs)("div",{className:"architrave-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Standard profile"}),(0,re.jsx)("p",{className:"architrave-calculator__hint",children:"Choose the profile you plan to use. Length calculations are the same for each profile."}),(0,re.jsx)("div",{className:"architrave-calculator__profiles",children:dw.map(N=>(0,re.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g===N.id?" is-selected":""}`,onClick:()=>f(N.id),children:[(0,re.jsx)(E_,{profile:N.id}),(0,re.jsx)("div",{className:"truss-estimator__option-title",children:N.label}),(0,re.jsx)("div",{className:"truss-estimator__option-copy",children:N.blurb})]},N.id))})]}),(0,re.jsxs)("div",{className:"architrave-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,re.jsx)("div",{className:"architrave-calculator__options",children:(0,re.jsxs)("label",{className:"truss-estimator__field",children:[(0,re.jsx)("span",{children:"Board length (m)"}),(0,re.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,re.jsx)("p",{className:"architrave-calculator__hint",children:"Waste allows for mitred corners, cuts and damaged lengths."})]}),(0,re.jsxs)("div",{className:"architrave-calculator__totals",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,re.jsxs)("div",{className:"architrave-calculator__result-grid",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Architrave needed"}),(0,re.jsxs)("strong",{children:[D.toFixed(2)," m"]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Board lengths"}),(0,re.jsx)("strong",{children:m})]})]})]}),(0,re.jsxs)("div",{className:"architrave-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?.(b),disabled:D<=0,children:a})]})]})]})})}var ki=X(Xe()),se=X(ie()),fw=60,gw=10,M_=.02,T_=.012,z_=.01,Rn=e=>Number.parseFloat(e)||0,A_=(e,t=2)=>e.toFixed(t);function Ed({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,ki.useState)("brick"),[n,o]=(0,ki.useState)("engineering-red"),[l,c]=(0,ki.useState)("metric"),[p,d]=(0,ki.useState)(""),[g,f]=(0,ki.useState)(""),[h,w]=(0,ki.useState)(!0),M=l==="metric"?Rn(p)*Rn(g):Rn(p)*Rn(g)*.092903,m=M*(r==="brick"?fw:gw),u=Math.ceil(m),b=M*(r==="brick"?M_:T_),v=Math.ceil(b/z_),N=l==="metric"?M:M*10.7639,A=[{key:r==="brick"?`brick-${n}`:"block",label:r==="brick"?{common:"Common concrete bricks","engineering-red":"Red engineering bricks","engineering-blue":"Blue engineering bricks"}[n]:"Blocks",qty:u,unit:"each",query:r==="brick"?"facing brick":"concrete block",category:"masonry"},...h?[{key:"mortar",label:"Blue Circle Quality Assured Mortar Mix 20kg",qty:v,unit:"bag",query:"ready mixed mortar",category:"mortar"}]:[]],T=z=>{if(z===l)return;let G=z==="imperial"?3.28084:.3048;d((Rn(p)*G).toFixed(2)),f((Rn(g)*G).toFixed(2)),c(z)};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:"Brick & Block Calculator"}),(0,se.jsx)("p",{children:"Estimate masonry units, sand and cement for a wall."})]}),(0,se.jsxs)("div",{className:"truss-estimator__card brick-calculator",children:[(0,se.jsx)("h2",{className:"truss-estimator__step-title",children:"Wall area and masonry type"}),(0,se.jsx)("p",{className:"truss-estimator__step-sub",children:"Pick brick or block and enter the wall dimensions for unit counts plus ready-mixed mortar."}),(0,se.jsxs)("div",{className:"brick-calculator__section",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Masonry type"}),(0,se.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["brick","Brick"],["block","Block"]].map(([z,G])=>(0,se.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===z?" is-selected":""}`,onClick:()=>i(z),children:[(0,se.jsx)("div",{className:"truss-estimator__option-title",children:G}),(0,se.jsxs)("div",{className:"truss-estimator__option-copy",children:["Approx. ",z==="brick"?fw:gw," per m\xB2"]})]},z))})]}),r==="brick"&&(0,se.jsxs)("div",{className:"brick-calculator__section",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Brick type"}),(0,se.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:[["common","Common concrete","General-purpose grey concrete brick"],["engineering-red","Engineering red","Class B perforated, 65mm"],["engineering-blue","Engineering blue","Class B solid, 65mm"]].map(([z,G,P])=>(0,se.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n===z?" is-selected":""}`,onClick:()=>o(z),children:[(0,se.jsx)("div",{className:"truss-estimator__option-title",children:G}),(0,se.jsx)("div",{className:"truss-estimator__option-copy",children:P})]},z))})]}),(0,se.jsxs)("div",{className:"brick-calculator__section",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,se.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,se.jsx)("button",{type:"button",className:l==="metric"?"is-selected":"",onClick:()=>T("metric"),children:"Metric"}),(0,se.jsx)("button",{type:"button",className:l==="imperial"?"is-selected":"",onClick:()=>T("imperial"),children:"Imperial"})]}),(0,se.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsxs)("span",{children:["Height (",l==="metric"?"m":"ft",")"]}),(0,se.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:z=>d(z.target.value)})]}),(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsxs)("span",{children:["Width (",l==="metric"?"m":"ft",")"]}),(0,se.jsx)("input",{type:"number",min:"0",step:"0.01",value:g,onChange:z=>f(z.target.value)})]})]})]}),(0,se.jsx)("div",{className:"brick-calculator__options",children:(0,se.jsxs)("label",{className:"brick-calculator__checkbox",children:[(0,se.jsx)("input",{type:"checkbox",checked:h,onChange:z=>w(z.target.checked)}),(0,se.jsx)("span",{children:"Include ready-mixed mortar"})]})}),(0,se.jsxs)("div",{className:"brick-calculator__totals",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,se.jsxs)("div",{className:"brick-calculator__result-grid",children:[(0,se.jsxs)("div",{children:[(0,se.jsx)("span",{children:"Wall area"}),(0,se.jsxs)("strong",{children:[A_(N)," ",l==="metric"?"m\xB2":"ft\xB2"]})]}),(0,se.jsxs)("div",{children:[(0,se.jsx)("span",{children:r==="brick"?"Bricks":"Blocks"}),(0,se.jsx)("strong",{children:u.toLocaleString("en-GB")})]}),h?(0,se.jsxs)("div",{children:[(0,se.jsx)("span",{children:"Ready-mixed mortar"}),(0,se.jsxs)("strong",{children:[v," x 20kg bags"]})]}):null]}),(0,se.jsx)("p",{className:"brick-calculator__note",children:"Estimate based on standard nominal sizes and 10mm joints. Mortar bags are approximate; confirm the required mortar specification before ordering."})]}),(0,se.jsxs)("div",{className:"brick-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?.(A),disabled:M<=0,children:a})]})]})]})})}var hr=X(Xe());var hw=new Map;function R_(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 Fr(e,t,a=12,r){let i=`${e}||${t??""}||${a}||${r??""}`,n=hw.get(i);if(n)return n;let o=new URLSearchParams({q:e,limit:String(a)});t&&o.set("category",t),r&&o.set("account",r);let l=await fetch(Ht(`/api/catalogue/search?${o.toString()}`),{headers:vi()}),c=await Pt(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(R_):[];return hw.set(i,p),p}async function bw(e,t){return await Promise.all(e.map(async r=>{try{return{requirement:r,candidates:await Fr(r.query,r.category,void 0,t)}}catch{return{requirement:r,candidates:[]}}}))}async function vw(){let e=await fetch(Ht("/api/catalogue"),{headers:vi()});if(!e.ok)return{itemCount:0,uploadedAt:null};let t=await Pt(e);return{itemCount:Number(t?.itemCount)||0,uploadedAt:t?.uploadedAt??null}}var V=X(ie()),U_=1.54,D_=1440,O_=25,Md=800,B_=1500,Td=e=>Number.parseFloat(e)||0,Un={mot:{label:"MOT Type 1",blurb:"Sub-base for patios and driveways",density:1.7,productId:"6001007"},"sharp-sand":{label:"Sharp sand",blurb:"Bedding and general groundwork",density:1.6,productId:"6001012"},gravel:{label:"20mm gravel",blurb:"Drainage and landscaping",density:1.6,productId:"6001004"}};function zd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let r=ac(),[i,n]=(0,hr.useState)("m"),[o,l]=(0,hr.useState)(""),[c,p]=(0,hr.useState)(""),[d,g]=(0,hr.useState)(""),[f,h]=(0,hr.useState)("concrete"),[w,M]=(0,hr.useState)("mot"),[D,m]=(0,hr.useState)(!1),[u,b]=(0,hr.useState)(null),v=i==="m"?1:.3048,N=Td(o)*v*Td(c)*v*Td(d)*(i==="m"?.01:.0254),A=Un[w],T=N*U_/7,z=T*D_,G=T*2,P=T*4,be=Math.ceil(z/O_),De=Math.ceil(G*Un["sharp-sand"].density*1e3/Md),Le=Math.ceil(P*Un.gravel.density*1e3/Md),He=Math.ceil(N*A.density*1e3/Md),ze=f==="concrete"?[{key:"cement",label:"Blue Circle General Purpose Grey Cement 25kg",qty:be,productId:"6003004"},{key:"sharp-sand",label:"Sharp Sand Bulk Bag (800kg)",qty:De,productId:"6001012"},{key:"gravel",label:"20mm Non Decorative Pea Shingle/Gravel Bulk Bag (800kg)",qty:Le,productId:"6001004"}]:[{key:w,label:`${A.label} Bulk Bag (800kg)`,qty:He,productId:A.productId}],me=()=>{if(t){t(ze.map(fe=>({key:fe.key,label:fe.label,qty:fe.qty,unit:"each",query:fe.productId})));return}ce()},ce=async()=>{let fe=Date.now();m(!0),b(null);try{let Ee=await Promise.all(ze.map(async Se=>{let Z=(await Fr(Se.productId)).find(de=>de.product_id===Se.productId);if(!Z)throw new Error(`${Se.label} is no longer available in this catalogue.`);return Pr(Z,{lineId:`concrete-aggregate:${Se.key}`,description:Se.label,unit:"bag",qty:Se.qty})})),ut=B_-(Date.now()-fe);ut>0&&await new Promise(Se=>window.setTimeout(Se,ut)),r?.clearCart(),r?.addManyToCart(Ee),r?.openBasket()}catch(Ee){b(Ee instanceof Error?Ee.message:"Could not add the products to your basket.")}finally{m(!1)}};return D?(0,V.jsx)(V.Fragment,{children:(0,V.jsxs)("div",{className:"truss-estimator",children:[(0,V.jsxs)("div",{className:"quick-order-hero",children:[(0,V.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,V.jsx)("h1",{children:"Your Materials"}),(0,V.jsx)("p",{children:"Calculating quantities from the Concrete & Aggregate Calculator."})]}),(0,V.jsx)("div",{className:"truss-estimator__card",children:(0,V.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,V.jsx)(fr,{}),(0,V.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})}):(0,V.jsx)(V.Fragment,{children:(0,V.jsxs)("div",{className:"truss-estimator",children:[(0,V.jsxs)("div",{className:"quick-order-hero",children:[(0,V.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,V.jsx)("h1",{children:"Concrete & Aggregate Calculator"}),(0,V.jsx)("p",{children:"Calculate fixed site-mix concrete ingredients or aggregate bulk bags."})]}),(0,V.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,V.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose what you need"}),(0,V.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter the area and depth. The calculator adds the fixed Materials Market products directly to your basket."}),(0,V.jsxs)("div",{className:"materials-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Material type"}),(0,V.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,V.jsxs)("button",{type:"button",className:`truss-estimator__option-card${f==="concrete"?" is-selected":""}`,onClick:()=>h("concrete"),children:[(0,V.jsx)("div",{className:"truss-estimator__option-title",children:"Site-mixed concrete"}),(0,V.jsx)("div",{className:"truss-estimator__option-copy",children:"Cement, sharp sand and 20mm aggregate"})]}),(0,V.jsxs)("button",{type:"button",className:`truss-estimator__option-card${f==="aggregate"?" is-selected":""}`,onClick:()=>h("aggregate"),children:[(0,V.jsx)("div",{className:"truss-estimator__option-title",children:"Aggregates"}),(0,V.jsx)("div",{className:"truss-estimator__option-copy",children:"MOT Type 1, sharp sand or 20mm gravel"})]})]})]}),f==="aggregate"&&(0,V.jsxs)("div",{className:"materials-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Aggregate type"}),(0,V.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.keys(Un).map(fe=>(0,V.jsxs)("button",{type:"button",className:`truss-estimator__option-card${w===fe?" is-selected":""}`,onClick:()=>M(fe),children:[(0,V.jsx)("div",{className:"truss-estimator__option-title",children:Un[fe].label}),(0,V.jsx)("div",{className:"truss-estimator__option-copy",children:Un[fe].blurb})]},fe))})]}),(0,V.jsxs)("div",{className:"materials-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and depth"}),(0,V.jsxs)("div",{className:"materials-calculator__unit-row",children:[(0,V.jsx)("span",{children:"Units"}),(0,V.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,V.jsx)("button",{type:"button",className:i==="m"?"is-selected":"",onClick:()=>n("m"),children:"Metric"}),(0,V.jsx)("button",{type:"button",className:i==="ft"?"is-selected":"",onClick:()=>n("ft"),children:"Imperial"})]})]}),(0,V.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsxs)("span",{children:["Length (",i,")"]}),(0,V.jsx)("input",{type:"number",min:"0",step:"0.01",value:o,onChange:fe=>l(fe.target.value)})]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsxs)("span",{children:["Width (",i,")"]}),(0,V.jsx)("input",{type:"number",min:"0",step:"0.01",value:c,onChange:fe=>p(fe.target.value)})]})]}),(0,V.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,V.jsxs)("span",{children:["Depth (",i==="m"?"cm":"inches",")"]}),(0,V.jsx)("input",{type:"number",min:"0",step:"0.1",value:d,onChange:fe=>g(fe.target.value)})]})]}),(0,V.jsxs)("div",{className:"materials-calculator__totals",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Materials required"}),(0,V.jsx)("div",{className:"materials-calculator__result-grid",children:f==="concrete"?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Cement"}),(0,V.jsxs)("strong",{children:[z.toFixed(0)," kg"]})]}),(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Sharp sand"}),(0,V.jsxs)("strong",{children:[G.toFixed(2)," m\xB3"]})]}),(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"20mm aggregate"}),(0,V.jsxs)("strong",{children:[P.toFixed(2)," m\xB3"]})]})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:A.label}),(0,V.jsxs)("strong",{children:[N.toFixed(2)," m\xB3"]})]}),(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Approx. weight"}),(0,V.jsxs)("strong",{children:[(N*A.density).toFixed(2)," t"]})]}),(0,V.jsx)("div",{})]})}),(0,V.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."})]}),u&&(0,V.jsx)("p",{className:"results-empty-hint estimator-products__error",children:u}),(0,V.jsxs)("div",{className:"materials-calculator__actions",children:[(0,V.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,V.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:me,disabled:N<=0||D,children:D?"Adding products\u2026":a})]})]})]})})}var Xa=X(Xe());var U=X(ie()),Dn=12,On=8,nc=.56,ww=.21,Ca={ranges:{meridian:{label:"Standard grooved timber",blurb:"32 \xD7 125mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.125},summit:{label:"Wide grooved timber",blurb:"32 \xD7 150mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.15}},boardGapM:.006,wastage:{straight:.05,diagonal:.15},pictureFrame:{extraWastage:.08},joist:{lengthM:2.4,spacingOptions:[{id:"300",label:"300mm centres (heavy duty)",spacingM:.3},{id:"400",label:"400mm centres (standard)",spacingM:.4},{id:"450",label:"450mm centres (light use)",spacingM:.45}]}},Ni=["range","grid","pictureFrame","substructure"],L_={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:""}},oc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),lc=(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),H_=(e,t,a,r)=>{let i=oc(e,t,a),n=oc(e,t,r),o=oc(a,r,e),l=oc(a,r,t);return i===0&&lc(e,t,a)||n===0&&lc(e,t,r)||o===0&&lc(a,r,e)||l===0&&lc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},Ad=(e,t)=>{let a=t?e.length:e.length-1;for(let r=0;r<a;r+=1){let i=e[(r+1)%e.length];for(let n=r+1;n<a;n+=1)if(!(n===r+1||t&&r===0&&n===a-1)&&H_(e[r],i,e[n],e[(n+1)%e.length]))return!0}return!1};function Rd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Xa.useState)(0),[n,o]=(0,Xa.useState)(L_),[l,c]=(0,Xa.useState)(1),[p,d]=(0,Xa.useState)({x:0,y:0}),[g,f]=(0,Xa.useState)(null),h=(0,Xa.useRef)(null),w=(0,Xa.useRef)(null),M=(0,Xa.useRef)(null),D=Ni[r],m=n.range?Ca.ranges[n.range]:null,u=Dn/l,b=On/l,v=(Dn-u)/2,N=(On-b)/2,A=Math.max(-Dn,Math.min(Dn*2-u,v+p.x)),T=Math.max(-On,Math.min(On*2-b,N+p.y)),z=Number.parseFloat(n.quickLengthM),G=Number.parseFloat(n.quickWidthM),P=z>0&&G>0,be=k=>Math.abs(k.reduce((R,E,O)=>{let ee=k[(O+1)%k.length];return R+E.x*ee.y-ee.x*E.y},0))/2,De=(k,R)=>Math.hypot(R.x-k.x,R.y-k.y),Le=n.isOutlineClosed?be(n.points):0,He=n.isOutlineClosed?n.points.reduce((k,R,E)=>k+De(R,n.points[(E+1)%n.points.length]),0):0,ze=n.isOutlineClosed?n.points.reduce((k,R,E)=>k+(n.wallSegments.has(E)?0:De(R,n.points[(E+1)%n.points.length])),0):0,me=n.points.reduce((k,R)=>({x:k.x+R.x/n.points.length,y:k.y+R.y/n.points.length}),{x:0,y:0}),ce=n.points.length>1?(()=>{let k=n.points[0],R=n.points[1],E=De(k,R),O=E?-(R.y-k.y)/E:0,ee=E?(R.x-k.x)/E:0,xe=(k.x+R.x)/2,we=(k.y+R.y)/2,y=O*(xe-me.x)+ee*(we-me.y)>=0?1:-1;return{x:xe+O*nc*y,y:we+ee*nc*y}})():null,Ee=(()=>{let k=n.range?Ca.ranges[n.range]:Ca.ranges.meridian,R=n.deckSizeMode==="quick"?z*G:Le,E=n.deckSizeMode==="quick"?2*(z+G):ze,O=n.direction==="diagonal"?Ca.wastage.diagonal:Ca.wastage.straight,ee=n.pictureFrame==="yes"?Ca.pictureFrame.extraWastage:0,we=R/(k.boardWidthM+Ca.boardGapM)/k.boardLengthM,y=Math.ceil(we*(1+O+ee)),j=Math.ceil(R*30*(1+O+ee)/200),B=Ca.joist.spacingOptions.find(q=>q.id===n.joistSpacing)??Ca.joist.spacingOptions[1],ae=R/B.spacingM,te=Math.ceil(ae/Ca.joist.lengthM);return{range:k,area:R,boardCount:y,screwBoxes:j,joistLengthsNeeded:te,spacing:B}})(),ut=Ee?[{key:`boards-${n.range??"meridian"}`,label:`Deck boards (${Ee.range.label})`,qty:Ee.boardCount,unit:"each",query:"timber decking board",category:"decking",calculatorWasteIncluded:!0},{key:"joists",label:"Treated C24 joists",qty:Ee.joistLengthsNeeded,unit:"each",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}]:[],Se=()=>D==="range"?!!n.range:D==="grid"?n.deckSizeMode==="quick"?P:n.isOutlineClosed&&Le>0:D==="pictureFrame"?!!n.pictureFrame&&!!n.direction:D==="substructure"?!!n.joistSpacing:!0,Z=r===Ni.length-1?a:"Next",de=(k,R,E=!1)=>{let O=M.current?.getBoundingClientRect();if(!O)return null;let ee=E?1:.25;return{x:Math.round(Math.max(A,Math.min(A+u,A+(k-O.left)/O.width*u))/ee)*ee,y:Math.round(Math.max(T,Math.min(T+b,T+(R-O.top)/O.height*b))/ee)*ee}},Je=k=>{if(n.isOutlineClosed){let E=k.target;if(E!==k.currentTarget&&!E.classList.contains("deck-outline__grid"))return;w.current={startX:k.clientX,startY:k.clientY,startViewX:A,startViewY:T},k.currentTarget.setPointerCapture(k.pointerId);return}if(n.drawMode!=="outline")return;let R=de(k.clientX,k.clientY,!0);R&&(f(null),o(E=>{let O=[...E.points,R];return Ad(O,!1)?{...E,drawError:"Edges cannot cross. Choose another corner."}:{...E,points:O,drawError:""}}))},Ye=(k,R)=>{if(!n.isOutlineClosed){k.stopPropagation(),R===0&&n.points.length>=3&&o(E=>({...E,isOutlineClosed:!0,drawMode:"edges"}));return}k.stopPropagation(),h.current=R,k.currentTarget.setPointerCapture(k.pointerId)},pt=k=>{if(w.current){let O=M.current?.getBoundingClientRect();if(!O)return;let ee=w.current,xe=ee.startViewX-(k.clientX-ee.startX)/O.width*u,we=ee.startViewY-(k.clientY-ee.startY)/O.height*b;d({x:xe-v,y:we-N});return}!n.isOutlineClosed&&n.drawMode==="outline"&&f(de(k.clientX,k.clientY,!0));let R=h.current;if(R===null)return;let E=de(k.clientX,k.clientY);E&&o(O=>{let ee=O.points.map((xe,we)=>we===R?E:xe);return Ad(ee,!0)?{...O,drawError:"Edges cannot cross. Move the corner to a different position."}:{...O,points:ee,drawError:""}})},ot=k=>{w.current=null,h.current=null,k.currentTarget.hasPointerCapture(k.pointerId)&&k.currentTarget.releasePointerCapture(k.pointerId)},at=k=>{o(R=>{let E=new Set(R.wallSegments);return E.has(k)?E.delete(k):E.add(k),{...R,wallSegments:E}})},ge=()=>{r===0?e():i(k=>k-1)},W=()=>{Se()&&(r===Ni.length-1?t?.(ut):i(k=>k+1))};return(0,U.jsx)(U.Fragment,{children:(0,U.jsxs)("div",{className:"truss-estimator",children:[(0,U.jsxs)("div",{className:"quick-order-hero",children:[(0,U.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,U.jsx)("h1",{children:"Decking Calculator"}),(0,U.jsx)("p",{children:"Estimate timber boards, joists and screws for your deck."})]}),(0,U.jsxs)("div",{className:"truss-estimator__card",children:[(0,U.jsxs)("div",{className:"truss-estimator__body",children:[D==="range"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ni.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your timber decking"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Both options are fixed, orderable pressure-treated timber boards."}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Ca.ranges).map(([k,R])=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===k?" is-selected":""}`,onClick:()=>o(E=>({...E,range:k})),children:[(0,U.jsx)("div",{className:"truss-estimator__option-title",children:R.label}),(0,U.jsx)("div",{className:"truss-estimator__option-copy",children:R.blurb}),(0,U.jsxs)("div",{className:"truss-estimator__option-copy",children:[R.boardLengthM,"m boards"]})]},k))})]}):null,D==="grid"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ni.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Tell us your deck size"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Start with a quick rectangle estimate, or draw an irregular deck for a more precise result."}),(0,U.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,U.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.deckSizeMode==="quick"?" is-selected":""}`,onClick:()=>o(k=>({...k,deckSizeMode:"quick"})),children:"Quick estimate"}),(0,U.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.deckSizeMode==="draw"?" is-selected":""}`,onClick:()=>o(k=>({...k,deckSizeMode:"draw",drawMode:"outline"})),children:"Draw your space"})]}),n.deckSizeMode==="quick"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,U.jsxs)("label",{className:"truss-estimator__field",children:[(0,U.jsx)("span",{children:"Length (m)"}),(0,U.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:n.quickLengthM,onChange:k=>o(R=>({...R,quickLengthM:k.target.value}))})]}),(0,U.jsxs)("label",{className:"truss-estimator__field",children:[(0,U.jsx)("span",{children:"Width (m)"}),(0,U.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:n.quickWidthM,onChange:k=>o(R=>({...R,quickWidthM:k.target.value}))})]})]}),(0,U.jsx)("div",{className:"truss-estimator__grid-hint",children:"For L-shaped decks, cut-outs, or sides against a wall, use Draw your space."}),P?(0,U.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,U.jsxs)("div",{children:[(z*G).toFixed(2)," m\xB2 deck"]}),(0,U.jsxs)("div",{children:[(2*(z+G)).toFixed(2)," m perimeter"]})]}):null]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Draw your deck"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Click to add corners, then close the outline. Drag any handle to refine it."}),(0,U.jsxs)("div",{className:"deck-outline__toolbar",children:[n.isOutlineClosed?(0,U.jsxs)("div",{className:"deck-outline__summary",children:[(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Deck area"}),(0,U.jsxs)("strong",{children:[Le.toFixed(2)," m\xB2"]})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Perimeter"}),(0,U.jsxs)("strong",{children:[He.toFixed(2)," m"]})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Wall edges"}),(0,U.jsx)("strong",{children:n.wallSegments.size>0?n.wallSegments.size:"None"})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Visible edge"}),(0,U.jsxs)("strong",{children:[ze.toFixed(2)," m"]})]})]}):null,(0,U.jsxs)("div",{className:"deck-outline__actions",children:[(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(k=>({...k,points:k.points.slice(0,-1)})),disabled:n.points.length===0||n.isOutlineClosed,children:"Undo"}),(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{f(null),o(k=>({...k,points:[],isOutlineClosed:!1,wallSegments:new Set,drawMode:"outline",drawError:""}))},disabled:n.points.length===0,children:"Clear"}),(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(k=>({...k,points:[{x:2,y:2},{x:8,y:2},{x:8,y:5},{x:2,y:5}],isOutlineClosed:!0,wallSegments:new Set,drawMode:"edges",drawError:""})),children:"Start with rectangle"})]})]}),(0,U.jsx)("div",{className:"deck-editor-layout",children:(0,U.jsxs)("div",{className:"deck-editor-layout__canvas-column",children:[(0,U.jsxs)("div",{className:"deck-outline",children:[(0,U.jsxs)("svg",{ref:M,className:`deck-outline__canvas${n.isOutlineClosed?" is-pan-mode":""}`,viewBox:`${A} ${T} ${u} ${b}`,preserveAspectRatio:"none","aria-label":"Deck outline drawing area",onPointerDown:Je,onPointerMove:pt,onPointerUp:ot,onPointerLeave:()=>{f(null),w.current||(h.current=null)},children:[(0,U.jsx)("defs",{children:(0,U.jsx)("pattern",{id:"deck-outline-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,U.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,U.jsx)("rect",{x:-Dn,y:-On,width:Dn*3,height:On*3,className:"deck-outline__grid",fill:"url(#deck-outline-grid)"}),n.points.length>1?(0,U.jsx)("polyline",{className:"deck-outline__preview",points:n.points.map(k=>`${k.x},${k.y}`).join(" ")}):null,n.isOutlineClosed?(0,U.jsx)("polygon",{className:"deck-outline__shape",points:n.points.map(k=>`${k.x},${k.y}`).join(" "),stroke:"none"}):null,n.points.length>1?n.points.slice(0,n.isOutlineClosed?void 0:-1).map((k,R)=>{let E=n.points[n.isOutlineClosed?(R+1)%n.points.length:R+1],O=De(k,E),ee=O?-(E.y-k.y)/O:0,xe=O?(E.x-k.x)/O:0,we=(k.x+E.x)/2,y=(k.y+E.y)/2,j=ee*(we-me.x)+xe*(y-me.y)>=0?1:-1,B=we+ee*nc*j,ae=y+xe*nc*j;return(0,U.jsxs)("g",{children:[(0,U.jsx)("line",{className:"deck-outline__edge-hit",x1:k.x,y1:k.y,x2:E.x,y2:E.y,onClick:n.isOutlineClosed?()=>at(R):void 0}),(0,U.jsx)("line",{className:`deck-outline__edge${n.wallSegments.has(R)?" is-wall":""}`,x1:k.x,y1:k.y,x2:E.x,y2:E.y,pointerEvents:"none"}),(0,U.jsxs)("text",{className:`deck-outline__edge-label${n.wallSegments.has(R)?" is-wall":""}`,x:B,y:ae,textAnchor:"middle",dominantBaseline:"central",fontSize:ww/l,children:[O.toFixed(2)," m"]})]},`segment-${R}`)}):null,!n.isOutlineClosed&&n.points.length>0&&g?(()=>{let k=n.points[n.points.length-1],R=De(k,g);if(!R)return null;let E=-(g.y-k.y)/R,O=(g.x-k.x)/R,ee=(k.x+g.x)/2,xe=(k.y+g.y)/2;return(0,U.jsxs)("g",{className:"deck-outline__live-measurement",children:[(0,U.jsx)("line",{x1:k.x,y1:k.y,x2:g.x,y2:g.y}),(0,U.jsxs)("text",{x:ee+E*.34,y:xe+O*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:ww/l,children:[R.toFixed(2)," m"]})]})})():null,n.points.map((k,R)=>(0,U.jsx)("circle",{className:"deck-outline__point",cx:k.x,cy:k.y,r:"0.13",onPointerDown:E=>Ye(E,R)},`point-${R}`))]}),(0,U.jsxs)("div",{className:"deck-outline__zoom","aria-label":"Zoom controls",children:[(0,U.jsx)("button",{type:"button",onClick:()=>c(k=>Math.max(.5,k-.25)),disabled:l===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,U.jsxs)("span",{children:[Math.round(l*100),"%"]}),(0,U.jsx)("button",{type:"button",onClick:()=>c(k=>Math.min(1,k+.25)),disabled:l===1,"aria-label":"Zoom in",children:"+"})]}),n.isOutlineClosed&&n.wallSegments.size===0&&ce?(0,U.jsx)("div",{className:"deck-outline__edge-prompt",role:"status",style:{left:`${(ce.x-A)/u*100}%`,top:`${(ce.y-T)/b*100}%`},children:"Tap an edge to mark it as a wall, or leave it as a visible edge."}):null,!n.isOutlineClosed&&n.points.length>=3?(0,U.jsx)("button",{type:"button",className:"deck-outline__close",onClick:()=>o(k=>Ad(k.points,!0)?{...k,drawError:"Edges cannot cross. Adjust the outline before finishing."}:{...k,isOutlineClosed:!0,drawMode:"edges",drawError:""}),children:"Finish outline"}):null]}),(0,U.jsxs)("div",{className:"deck-outline__supporting",children:[(0,U.jsx)("div",{className:"truss-estimator__grid-hint",children:n.isOutlineClosed?"Drag a corner handle to refine the outline.":"Add at least three corners, then click Finish outline."}),n.drawError?(0,U.jsx)("div",{className:"deck-outline__error",role:"alert",children:n.drawError}):null]})]})})]})]}):null,D==="pictureFrame"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ni.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Picture frame border?"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"A picture frame border runs boards around the perimeter for a finished look and uses extra material."}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"no",label:"No border",img:"/decking/boards/no-border.webp"},{id:"yes",label:"Picture frame",img:"/decking/boards/picture-frame.webp"}].map(k=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.pictureFrame===k.id?" is-selected":""}`,onClick:()=>o(R=>({...R,pictureFrame:k.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:Jt(k.img),alt:""}),(0,U.jsx)("span",{children:k.label})]},k.id))}),(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Board direction"}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"straight",label:"Straight",img:"/decking/boards/straight.webp"},{id:"diagonal",label:"Diagonal",img:"/decking/boards/diagonal.webp"}].map(k=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.direction===k.id?" is-selected":""}`,onClick:()=>o(R=>({...R,direction:k.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:Jt(k.img),alt:""}),(0,U.jsx)("span",{children:k.label})]},k.id))})]})]}):null,D==="substructure"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ni.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Substructure"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the joist spacing. Posts, footings and ground preparation vary by site, so are not included."}),(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Joist spacing"}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Ca.joist.spacingOptions.map(k=>(0,U.jsx)("button",{type:"button",className:`truss-estimator__option-card${n.joistSpacing===k.id?" is-selected":""}`,onClick:()=>o(R=>({...R,joistSpacing:k.id})),children:(0,U.jsx)("div",{className:"truss-estimator__option-title",children:k.label})},k.id))})]}):null]}),(0,U.jsxs)("div",{className:"truss-estimator__nav",children:[(0,U.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:ge,children:"Back"}),(0,U.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:W,disabled:!Se(),children:[(0,U.jsx)("span",{children:Z}),(0,U.jsx)("span",{className:"arrow",children:(0,U.jsx)(jt,{})})]})]})]})]})})}var Ea=X(Xe());var Q=X(ie()),yw=12,_w=30,Bn=12,Ln=8,xw=.56,qa={ranges:{boundary:{label:"Horizontal lap",blurb:"Traditional pressure-treated timber panels.",panelWidthM:1.83},skyline:{label:"Feather edge",blurb:"Heavier timber panels for a more solid boundary.",panelWidthM:1.83}},heights:["0.9","1.2","1.5","1.8"],gate:{single:{label:"Single lap gate",widthDefault:.9}},mounting:{concrete:{label:"Concrete posts",blurb:"Slotted concrete posts with matching panels."},postcrete:{label:"Postcrete bags",blurb:"Fast-set post-mix bags in a dug hole.",bagsPerPost:2}}},Si=["range","height","gate","posts"],j_={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:""}},sc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),cc=(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),Q_=(e,t,a,r)=>{let i=sc(e,t,a),n=sc(e,t,r),o=sc(a,r,e),l=sc(a,r,t);return i===0&&cc(e,t,a)||n===0&&cc(e,t,r)||o===0&&cc(a,r,e)||l===0&&cc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},uc=(e,t)=>{let a=t?e.length:e.length-1;for(let r=0;r<a;r+=1)for(let i=r+1;i<a;i+=1)if(!(i===r+1||t&&r===0&&i===a-1)&&Q_(e[r],e[(r+1)%e.length],e[i],e[(i+1)%e.length]))return!0;return!1};function Ud({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ea.useState)(0),[n,o]=(0,Ea.useState)(j_),l=(0,Ea.useRef)(null),c=(0,Ea.useRef)(null),[p,d]=(0,Ea.useState)(1),[g,f]=(0,Ea.useState)({x:0,y:0}),[h,w]=(0,Ea.useState)(null),M=(0,Ea.useRef)(null),D=(0,Ea.useRef)(null),m=(0,Ea.useRef)(null),u=Si[r],b=n.range?qa.ranges[n.range]:null,v=Bn/p,N=Ln/p,A=(Bn-v)/2,T=(Ln-N)/2,z=Math.max(-Bn,Math.min(Bn*2-v,A+g.x)),G=Math.max(-Ln,Math.min(Ln*2-N,T+g.y)),P=n.boundaryPoints.reduce((y,j)=>({x:y.x+j.x/Math.max(1,n.boundaryPoints.length),y:y.y+j.y/Math.max(1,n.boundaryPoints.length)}),{x:0,y:0}),be=y=>{let j=new Set,B=[];return y.forEach(ae=>{let[te,q]=ae.split(",").map(Number),Y=[{key:`H,${te},${q}`,type:"H",x:te,y:q},{key:`H,${te},${q+1}`,type:"H",x:te,y:q+1},{key:`V,${te},${q}`,type:"V",x:te,y:q},{key:`V,${te+1},${q}`,type:"V",x:te+1,y:q}],K=[!y.has(`${te},${q-1}`),!y.has(`${te},${q+1}`),!y.has(`${te-1},${q}`),!y.has(`${te+1},${q}`)];Y.forEach((pe,ke)=>{K[ke]&&!j.has(pe.key)&&(j.add(pe.key),B.push(pe))})}),B},De=(y,j)=>be(y).filter(B=>!j.has(B.key)),Le=(y,j)=>De(y,j).length,He=(y,j)=>{let B={};De(y,j).forEach(te=>{var q,Y,K,pe;te.type==="H"?((B[q=`${te.x},${te.y}`]||(B[q]=[])).push("H"),(B[Y=`${te.x+1},${te.y}`]||(B[Y]=[])).push("H")):((B[K=`${te.x},${te.y}`]||(B[K]=[])).push("V"),(B[pe=`${te.x},${te.y+1}`]||(B[pe]=[])).push("V"))});let ae=0;return Object.values(B).forEach(te=>{(te.length===1||te.length===2&&te[0]!==te[1]||te.length>=3)&&(ae+=1)}),ae},me=(()=>{let y=n.range?qa.ranges[n.range]:qa.ranges.boundary,j=n.height??"1.8",B=n.boundaryMode==="quick"?Math.max(0,Number.parseFloat(n.quickLengthM)||0):n.boundaryClosed?n.boundaryPoints.slice(0,-1).reduce((It,vr,$a)=>It+(n.excludedBoundaryEdges.has($a)?0:Math.hypot(n.boundaryPoints[$a+1].x-vr.x,n.boundaryPoints[$a+1].y-vr.y)),0):0,ae=n.gateType&&n.gateType!=="none"?Number.parseFloat(n.gateWidthM)||qa.gate[n.gateType].widthDefault:0,te=Math.max(0,B-ae),q=te>0?Math.ceil(te/y.panelWidthM):0,Y=n.boundaryPoints.length>2&&n.boundaryPoints[0].x===n.boundaryPoints[n.boundaryPoints.length-1].x&&n.boundaryPoints[0].y===n.boundaryPoints[n.boundaryPoints.length-1].y,K=n.boundaryMode==="quick"?te>0?2:0:n.boundaryClosed?n.boundaryPoints.slice(0,Y?-1:void 0).reduce((It,vr,$a)=>{let Fd=$a>0&&!n.excludedBoundaryEdges.has($a-1),Gn=$a<n.boundaryPoints.length-1&&!n.excludedBoundaryEdges.has($a);return It+(Fd||Gn?1:0)},0):0,pe=te>0?Math.ceil(te/y.panelWidthM)+1:0,ke=Math.max(0,pe-K),Fe=n.mountingType?qa.mounting[n.mountingType]:qa.mounting.concrete,xt=n.gateType&&n.gateType!=="none"?2:0,ua=ke+K+xt,ul=n.mountingType==="postcrete"?ua*qa.mounting.postcrete.bagsPerPost:0,pa=n.gravelBoard==="yes"?q:0;return{range:y,height:j,totalEdgeM:B,fencedLengthM:te,gateWidthM:ae,panelsCount:q,cornerPostCount:K,intermediatePostCount:ke,gatePostCount:xt,totalPostCount:ua,bagsCount:ul,gravelCount:pa,capCount:ua,mounting:Fe}})(),ce=n.gateType&&n.gateType!=="none"?qa.gate[n.gateType].label:null,fe=Number(me.height)<=1.2?"6":"8",Ee=me?[{key:`panels-${n.range??"boundary"}-${me.height}`,label:`${me.range.label} panels (${me.height}m)`,qty:me.panelsCount,unit:"each",query:"fence panel",category:"fencing"},...n.mountingType==="concrete"?[{key:`concrete-intermediate-${fe}`,label:"Intermediate concrete posts",qty:me.intermediatePostCount,unit:"each",query:"concrete fence post",category:"fencing"},{key:`concrete-end-${fe}`,label:"End and corner concrete posts",qty:me.cornerPostCount+me.gatePostCount,unit:"each",query:"concrete end post",category:"fencing"}]:[{key:`timber-post-${fe}`,label:"Timber fence posts",qty:me.totalPostCount,unit:"each",query:"timber fence post",category:"fencing"},{key:"postcrete",label:"Postcrete",qty:me.bagsCount,unit:"bag",query:"postcrete",category:"cement"}],...ce?[{key:"gate",label:ce,qty:1,unit:"each",query:"lap gate",category:"fencing"}]:[],...me.gravelCount>0?[{key:"gravel-boards",label:"Concrete gravel boards",qty:me.gravelCount,unit:"each",query:"gravel board",category:"fencing"}]:[]]:[],ut=()=>{if(u==="range"){let y=n.boundaryMode==="quick"?(Number.parseFloat(n.quickLengthM)||0)>0:n.boundaryClosed&&n.boundaryPoints.length>=2;return!!n.range&&y}return u==="height"?!!n.height&&!!n.gravelBoard:u==="gate"?!!n.gateType&&(n.gateType==="none"||n.gateWidthM.trim()!==""):u==="posts"?!!n.mountingType:!0},Se=r===Si.length-1?a:"Next",Z=y=>{o(j=>{let B=y(new Set(j.grid)),ae=new Set([...j.excludedEdges].filter(te=>be(B).some(q=>q.key===te)));return{...j,grid:B,excludedEdges:ae}})},de=(y,j,B)=>{Z(ae=>{let te=`${y},${j}`;return B?ae.add(te):ae.delete(te),ae})},Je=(y,j,B,ae,te)=>{let q=y,Y=j,K=Math.abs(B-y),pe=y<B?1:-1,ke=-Math.abs(ae-j),Fe=j<ae?1:-1,xt=K+ke;for(;de(q,Y,te),!(q===B&&Y===ae);){let ua=2*xt;ua>=ke&&(xt+=ke,q+=pe),ua<=K&&(xt+=K,Y+=Fe)}},Ye=(y,j)=>{let B=c.current?.getBoundingClientRect();if(!B)return null;let ae=Math.floor((y-B.left)/_w),te=Math.floor((j-B.top)/_w);return ae<0||te<0||ae>=yw||te>=yw?null:{x:ae,y:te}},pt=y=>{if(n.gridMode!=="draw")return;let j=Ye(y.clientX,y.clientY);if(!j)return;y.preventDefault();let B=`${j.x},${j.y}`,ae=!n.grid.has(B);l.current={active:!0,paintValue:ae,lastX:j.x,lastY:j.y},y.currentTarget.setPointerCapture(y.pointerId),de(j.x,j.y,ae)},ot=y=>{let j=l.current;if(!j?.active)return;let B=Ye(y.clientX,y.clientY);B&&(B.x===j.lastX&&B.y===j.lastY||(Je(j.lastX,j.lastY,B.x,B.y,j.paintValue),l.current={...j,lastX:B.x,lastY:B.y}))},at=y=>{l.current?.active&&(l.current=null,y.currentTarget.releasePointerCapture(y.pointerId))},ge=(y,j,B=!1)=>{let ae=m.current?.getBoundingClientRect();if(!ae)return null;let te=B?1:.25;return{x:Math.round(Math.max(z,Math.min(z+v,z+(y-ae.left)/ae.width*v))/te)*te,y:Math.round(Math.max(G,Math.min(G+N,G+(j-ae.top)/ae.height*N))/te)*te}},W=y=>{if(n.boundaryClosed){let B=y.target;if(B!==y.currentTarget&&!B.classList.contains("fence-boundary__grid"))return;D.current={startX:y.clientX,startY:y.clientY,startViewX:z,startViewY:G},y.currentTarget.setPointerCapture(y.pointerId);return}let j=ge(y.clientX,y.clientY,!0);j&&(w(null),o(B=>{let ae=[...B.boundaryPoints,j];return uc(ae,!1)?{...B}:{...B,boundaryPoints:ae}}))},k=(y,j)=>{if(y.stopPropagation(),!n.boundaryClosed){if(j!==0||n.boundaryPoints.length<3)return;o(B=>uc(B.boundaryPoints,!0)?B:{...B,boundaryPoints:[...B.boundaryPoints,B.boundaryPoints[0]],boundaryClosed:!0});return}M.current=j,y.currentTarget.setPointerCapture(y.pointerId)},R=y=>{if(D.current){let B=m.current?.getBoundingClientRect();if(!B)return;let ae=D.current,te=ae.startViewX-(y.clientX-ae.startX)/B.width*v,q=ae.startViewY-(y.clientY-ae.startY)/B.height*N;f({x:te-A,y:q-T});return}if(n.boundaryClosed||w(ge(y.clientX,y.clientY,!0)),M.current===null)return;let j=ge(y.clientX,y.clientY);j&&o(B=>{let ae=B.boundaryPoints.length>2&&B.boundaryPoints[0].x===B.boundaryPoints[B.boundaryPoints.length-1].x&&B.boundaryPoints[0].y===B.boundaryPoints[B.boundaryPoints.length-1].y,te=B.boundaryPoints.map((q,Y)=>{let K=Y===M.current,pe=ae&&M.current===0&&Y===B.boundaryPoints.length-1;return K||pe?j:q});return uc(te,!1)?B:{...B,boundaryPoints:te}})},E=y=>{D.current=null,M.current=null,y.currentTarget.hasPointerCapture(y.pointerId)&&y.currentTarget.releasePointerCapture(y.pointerId)},O=y=>{o(j=>{let B=new Set(j.excludedBoundaryEdges);return B.has(y)?B.delete(y):B.add(y),{...j,excludedBoundaryEdges:B}})},ee=()=>{r===0?e():i(y=>y-1)},xe=()=>{ut()&&(r===Si.length-1?t?.(Ee):i(y=>y+1))},we=be(n.grid);return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)("div",{className:"truss-estimator",children:[(0,Q.jsxs)("div",{className:"quick-order-hero",children:[(0,Q.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Q.jsx)("h1",{children:"Fencing Calculator"}),(0,Q.jsx)("p",{children:"Estimate panels, posts and cost for your fence line in a few steps."})]}),(0,Q.jsxs)("div",{className:"truss-estimator__card",children:[(0,Q.jsxs)("div",{className:"truss-estimator__body",children:[u==="range"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Q.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your fence panels"}),(0,Q.jsx)("p",{className:"truss-estimator__step-sub",children:"The calculator uses fixed, orderable timber panels from the catalogue."}),(0,Q.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(qa.ranges).map(([y,j])=>(0,Q.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===y?" is-selected":""}`,onClick:()=>o(B=>({...B,range:y})),children:[(0,Q.jsx)("div",{className:"truss-estimator__option-title",children:j.label}),(0,Q.jsx)("div",{className:"truss-estimator__option-copy",children:j.blurb})]},y))})]}):null,u==="range"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)("div",{className:"truss-estimator__section-heading",children:"Measure your fence line"}),(0,Q.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,Q.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,Q.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="quick"?" is-selected":""}`,onClick:()=>o(y=>({...y,boundaryMode:"quick"})),children:"Quick estimate"}),(0,Q.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="draw"?" is-selected":""}`,onClick:()=>o(y=>({...y,boundaryMode:"draw"})),children:"Draw your boundary"})]}),n.boundaryMode==="quick"?(0,Q.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact fence-boundary__quick-field",children:[(0,Q.jsx)("span",{children:"Total fence length (m)"}),(0,Q.jsx)("input",{type:"number",min:"0",step:"0.1",value:n.quickLengthM,onChange:y=>o(j=>({...j,quickLengthM:y.target.value}))})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)("div",{className:"fence-boundary__toolbar",children:(0,Q.jsxs)("div",{className:"fence-boundary__actions",children:[(0,Q.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(y=>({...y,boundaryPoints:y.boundaryPoints.slice(0,-1),boundaryClosed:!1,excludedBoundaryEdges:new Set})),disabled:n.boundaryPoints.length===0||n.boundaryClosed,children:"Undo"}),(0,Q.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{f({x:0,y:0}),w(null),o(y=>({...y,boundaryPoints:[],boundaryClosed:!1,excludedBoundaryEdges:new Set}))},disabled:n.boundaryPoints.length===0,children:"Clear"}),(0,Q.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(y=>({...y,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,Q.jsxs)("div",{className:"fence-boundary",children:[(0,Q.jsxs)("svg",{ref:m,className:`fence-boundary__canvas${n.boundaryClosed?" is-pan-mode":""}`,viewBox:`${z} ${G} ${v} ${N}`,preserveAspectRatio:"none","aria-label":"Fence boundary drawing area",onPointerDown:W,onPointerMove:R,onPointerUp:E,onPointerLeave:()=>{w(null),D.current||(M.current=null)},children:[(0,Q.jsx)("defs",{children:(0,Q.jsx)("pattern",{id:"fence-boundary-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,Q.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,Q.jsx)("rect",{x:-Bn,y:-Ln,width:Bn*3,height:Ln*3,className:"fence-boundary__grid",fill:"url(#fence-boundary-grid)"}),n.boundaryPoints.length>1?(0,Q.jsx)("polyline",{className:"fence-boundary__preview",points:n.boundaryPoints.map(y=>`${y.x},${y.y}`).join(" ")}):null,n.boundaryPoints.length>1?n.boundaryPoints.slice(0,-1).map((y,j)=>{let B=n.boundaryPoints[j+1],ae=Math.hypot(B.x-y.x,B.y-y.y),te=ae?-(B.y-y.y)/ae:0,q=ae?(B.x-y.x)/ae:0,Y=(y.x+B.x)/2,K=(y.y+B.y)/2,pe=te*(Y-P.x)+q*(K-P.y)>=0?1:-1,ke=Y+te*xw*pe,Fe=K+q*xw*pe;return(0,Q.jsxs)("g",{children:[(0,Q.jsx)("line",{className:"fence-boundary__edge-hit",x1:y.x,y1:y.y,x2:B.x,y2:B.y,onClick:n.boundaryClosed?()=>O(j):void 0}),(0,Q.jsx)("line",{className:`fence-boundary__edge${n.excludedBoundaryEdges.has(j)?" is-excluded":""}`,x1:y.x,y1:y.y,x2:B.x,y2:B.y,pointerEvents:"none"}),(0,Q.jsxs)("text",{className:`fence-boundary__edge-label${n.excludedBoundaryEdges.has(j)?" is-excluded":""}`,x:ke,y:Fe,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[ae.toFixed(2)," m"]})]},`fence-edge-${j}`)}):null,!n.boundaryClosed&&n.boundaryPoints.length>0&&h?(()=>{let y=n.boundaryPoints[n.boundaryPoints.length-1],j=Math.hypot(h.x-y.x,h.y-y.y);if(!j)return null;let B=-(h.y-y.y)/j,ae=(h.x-y.x)/j,te=(y.x+h.x)/2,q=(y.y+h.y)/2;return(0,Q.jsxs)("g",{className:"fence-boundary__live-measurement",children:[(0,Q.jsx)("line",{x1:y.x,y1:y.y,x2:h.x,y2:h.y}),(0,Q.jsxs)("text",{x:te+B*.34,y:q+ae*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[j.toFixed(2)," m"]})]})})():null,n.boundaryPoints.map((y,j)=>j>0&&j===n.boundaryPoints.length-1&&y.x===n.boundaryPoints[0]?.x&&y.y===n.boundaryPoints[0]?.y?null:(0,Q.jsx)("circle",{className:`fence-boundary__point${!n.boundaryClosed&&j===0&&n.boundaryPoints.length>=3?" is-close-target":""}`,cx:y.x,cy:y.y,r:"0.13",onPointerDown:B=>k(B,j)},`fence-point-${j}`))]}),(0,Q.jsxs)("div",{className:"fence-boundary__zoom","aria-label":"Zoom controls",children:[(0,Q.jsx)("button",{type:"button",onClick:()=>d(y=>Math.max(.5,y-.25)),disabled:p===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,Q.jsxs)("span",{children:[Math.round(p*100),"%"]}),(0,Q.jsx)("button",{type:"button",onClick:()=>d(y=>Math.min(1,y+.25)),disabled:p===1,"aria-label":"Zoom in",children:"+"})]}),!n.boundaryClosed&&n.boundaryPoints.length>=2?(0,Q.jsx)("button",{type:"button",className:"fence-boundary__close",onClick:()=>o(y=>uc(y.boundaryPoints,!1)?y:{...y,boundaryClosed:!0}),children:"Finish fence line"}):null]}),(0,Q.jsx)("div",{className:"truss-estimator__grid-hint",children:n.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,Q.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,Q.jsx)("div",{children:n.boundaryMode==="quick"?`${(Number.parseFloat(n.quickLengthM)||0).toFixed(2)} m fence line`:`${me.totalEdgeM.toFixed(2)} m fence line`}),n.boundaryMode==="draw"&&n.boundaryClosed?(0,Q.jsxs)("div",{children:[me.cornerPostCount," corner/end posts"]}):null]})]}):null,null,u==="height"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Q.jsx)("h2",{className:"truss-estimator__step-title",children:"Fence height"}),(0,Q.jsx)("p",{className:"truss-estimator__step-sub",children:"Select the nearest available panel height."}),(0,Q.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:qa.heights.map(y=>(0,Q.jsx)("button",{type:"button",className:`truss-estimator__visual-card${n.height===y?" is-selected":""}`,onClick:()=>o(j=>({...j,height:y})),children:(0,Q.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--tall",src:Jt(`/fencing/height/${y}.webp`),alt:""})},y))}),(0,Q.jsx)("div",{className:"truss-estimator__section-heading",children:"Gravel board?"}),(0,Q.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(y=>(0,Q.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.gravelBoard===y.id?" is-selected":""}`,onClick:()=>o(j=>({...j,gravelBoard:y.id})),children:[(0,Q.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Jt(y.img),alt:""}),(0,Q.jsx)("span",{children:y.label})]},y.id))})]}):null,u==="gate"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Q.jsx)("h2",{className:"truss-estimator__step-title",children:"Do you need a gate?"}),(0,Q.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,Q.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(y=>(0,Q.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${n.gateType===y.id?" is-selected":""}`,onClick:()=>o(j=>({...j,gateType:y.id,gateWidthM:y.id==="none"?"":String(qa.gate[y.id].widthDefault)})),children:[(0,Q.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Jt(y.img),alt:""}),(0,Q.jsx)("span",{children:y.label})]},y.id))}),n.gateType&&n.gateType!=="none"?(0,Q.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,Q.jsx)("span",{children:"Gate width (m)"}),(0,Q.jsx)("input",{type:"text",inputMode:"decimal",value:n.gateWidthM,onChange:y=>o(j=>({...j,gateWidthM:y.target.value}))})]}):null]}):null,u==="posts"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Q.jsx)("h2",{className:"truss-estimator__step-title",children:"Posts and fixing type"}),(0,Q.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose how the posts will be set."}),(0,Q.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(qa.mounting).map(([y,j])=>(0,Q.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.mountingType===y?" is-selected":""}`,onClick:()=>o(B=>({...B,mountingType:y})),children:[(0,Q.jsx)("div",{className:"truss-estimator__option-title",children:j.label}),(0,Q.jsx)("div",{className:"truss-estimator__option-copy",children:j.blurb})]},y))})]}):null]}),(0,Q.jsxs)("div",{className:"truss-estimator__nav",children:[(0,Q.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:ee,children:"Back"}),(0,Q.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:xe,disabled:!ut(),children:[(0,Q.jsx)("span",{children:Se}),(0,Q.jsx)("span",{className:"arrow",children:(0,Q.jsx)(jt,{})})]})]})]})]})})}var pc=X(Xe()),_e=X(ie()),kw={floor:{label:"Floor",product:"Knauf Acoustic Roll",thickness:"100mm",coverage:12.36,salesUnit:"roll"},wall:{label:"Cavity wall",product:"Celotex CW4100",thickness:"100mm",coverage:3.24,salesUnit:"pack"},roof:{label:"Pitched roof",product:"Kingspan K107",thickness:"100mm",coverage:8.64,salesUnit:"pack"},loft:{label:"Loft",product:"Knauf Loft Roll 44",thickness:"100mm",coverage:13.89,salesUnit:"roll"}};function Dd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,pc.useState)("floor"),[n,o]=(0,pc.useState)(""),[l,c]=(0,pc.useState)(""),p=Number.parseFloat(n)*Number.parseFloat(l)||0,d=kw[r],g=Math.ceil(p/d.coverage),f=[{key:`insulation-${r}`,label:`${d.product} ${d.thickness}`,qty:g,unit:d.salesUnit,query:d.product,category:"insulation"}],h=Object.entries(kw);return(0,_e.jsx)(_e.Fragment,{children:(0,_e.jsxs)("div",{className:"truss-estimator",children:[(0,_e.jsxs)("div",{className:"quick-order-hero",children:[(0,_e.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,_e.jsx)("h1",{children:"Insulation Calculator"}),(0,_e.jsx)("p",{children:"Estimate insulation coverage and pack quantities for floors, walls, roofs and lofts."})]}),(0,_e.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,_e.jsx)("h2",{className:"truss-estimator__step-title",children:"Where and what you are insulating"}),(0,_e.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the application and product, and enter the area, for coverage and pack quantities."}),(0,_e.jsxs)("div",{className:"materials-calculator__section",children:[(0,_e.jsx)("div",{className:"truss-estimator__section-heading",children:"Application"}),(0,_e.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:h.map(([w,M])=>(0,_e.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===w?" is-selected":""}`,onClick:()=>i(w),children:[(0,_e.jsx)("div",{className:"truss-estimator__option-title",children:M.label}),(0,_e.jsxs)("div",{className:"truss-estimator__option-copy",children:[M.product,", ",M.thickness]})]},w))})]}),(0,_e.jsxs)("div",{className:"materials-calculator__section",children:[(0,_e.jsx)("div",{className:"truss-estimator__section-heading",children:"Area"}),(0,_e.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,_e.jsxs)("label",{className:"truss-estimator__field",children:[(0,_e.jsx)("span",{children:"Length (m)"}),(0,_e.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:w=>o(w.target.value)})]}),(0,_e.jsxs)("label",{className:"truss-estimator__field",children:[(0,_e.jsx)("span",{children:"Width (m)"}),(0,_e.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:w=>c(w.target.value)})]})]})]}),(0,_e.jsxs)("div",{className:"materials-calculator__totals",children:[(0,_e.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,_e.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,_e.jsxs)("div",{children:[(0,_e.jsx)("span",{children:"Insulated area"}),(0,_e.jsxs)("strong",{children:[p.toFixed(2)," m\xB2"]})]}),(0,_e.jsxs)("div",{children:[(0,_e.jsx)("span",{children:d.product}),(0,_e.jsxs)("strong",{children:[g," packs"]})]})]}),(0,_e.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,_e.jsxs)("div",{className:"materials-calculator__actions",children:[(0,_e.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,_e.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(f),disabled:p<=0,children:a})]})]})]})})}var Hn=X(Xe()),$=X(ie()),G_=10,Y_=1.9*.762,X_=1.9*1.524,dc=()=>({height:"",width:""}),mc=e=>Number.parseFloat(e)||0,Nw=({height:e,width:t})=>mc(e)*mc(t);function Od({onBack:e}){let[t,a]=(0,Hn.useState)([dc()]),[r,i]=(0,Hn.useState)([dc()]),[n,o]=(0,Hn.useState)("0"),[l,c]=(0,Hn.useState)("0"),[p,d]=(0,Hn.useState)(1),g=t.reduce((m,u)=>m+Nw(u),0),f=r.reduce((m,u)=>m+Nw(u),0),h=mc(n)*Y_+mc(l)*X_,w=Math.max(0,g-f-h),M=w*p/G_,D=(m,u,b,v)=>{m(N=>N.map((A,T)=>T===u?{...A,[b]:v}:A))};return(0,$.jsx)($.Fragment,{children:(0,$.jsxs)("div",{className:"truss-estimator",children:[(0,$.jsxs)("div",{className:"quick-order-hero",children:[(0,$.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,$.jsx)("h1",{children:"Paint Calculator"}),(0,$.jsx)("p",{children:"Estimate how much paint you need for your walls, including multiple coats and excluded areas."})]}),(0,$.jsxs)("div",{className:"truss-estimator__card paint-calculator",children:[(0,$.jsx)("h2",{className:"truss-estimator__step-title",children:"Walls, exclusions and coats"}),(0,$.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,$.jsxs)("div",{className:"paint-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,$.jsx)("p",{className:"paint-calculator__hint",children:"Enter the height and width of each wall you want to paint."}),(0,$.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,$.jsx)("span",{}),(0,$.jsx)("span",{children:"Height (m)"}),(0,$.jsx)("span",{children:"Width (m)"}),(0,$.jsx)("span",{})]}),t.map((m,u)=>(0,$.jsxs)("div",{className:"paint-calculator__row",children:[(0,$.jsxs)("span",{className:"paint-calculator__row-label",children:["Wall ",u+1]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,$.jsx)("input",{"aria-label":`Wall ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:m.height,onChange:b=>D(a,u,"height",b.target.value)})]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,$.jsx)("input",{"aria-label":`Wall ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:m.width,onChange:b=>D(a,u,"width",b.target.value)})]}),t.length>1?(0,$.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>a(b=>b.filter((v,N)=>N!==u)),children:"Remove"}):null]},`wall-${u}`)),(0,$.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>a(m=>[...m,dc()]),children:"+ Add another wall"})]}),(0,$.jsxs)("div",{className:"paint-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Areas to exclude"}),(0,$.jsx)("p",{className:"paint-calculator__hint",children:"Add windows, sockets, skirting boards or other areas that will not be painted."}),(0,$.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,$.jsx)("span",{}),(0,$.jsx)("span",{children:"Height (m)"}),(0,$.jsx)("span",{children:"Width (m)"}),(0,$.jsx)("span",{})]}),r.map((m,u)=>(0,$.jsxs)("div",{className:"paint-calculator__row",children:[(0,$.jsxs)("span",{className:"paint-calculator__row-label",children:["Area ",u+1]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,$.jsx)("input",{"aria-label":`Area ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:m.height,onChange:b=>D(i,u,"height",b.target.value)})]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,$.jsx)("input",{"aria-label":`Area ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:m.width,onChange:b=>D(i,u,"width",b.target.value)})]}),r.length>1?(0,$.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(b=>b.filter((v,N)=>N!==u)),children:"Remove"}):null]},`excluded-${u}`)),(0,$.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(m=>[...m,dc()]),children:"+ Add another area"})]}),(0,$.jsxs)("div",{className:"paint-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Doors and coats"}),(0,$.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,$.jsxs)("div",{className:"truss-estimator__field-grid paint-calculator__small-fields",children:[(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{children:"Doors"}),(0,$.jsx)("input",{type:"number",min:"0",step:"1",value:n,onChange:m=>o(m.target.value)})]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{children:"Double doors"}),(0,$.jsx)("input",{type:"number",min:"0",step:"1",value:l,onChange:m=>c(m.target.value)})]})]}),(0,$.jsxs)("div",{className:"paint-calculator__coat-field",children:[(0,$.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,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{children:"Number of coats"}),(0,$.jsxs)("select",{value:p,onChange:m=>d(Number(m.target.value)),children:[(0,$.jsx)("option",{value:"1",children:"1 coat"}),(0,$.jsx)("option",{value:"2",children:"2 coats"}),(0,$.jsx)("option",{value:"3",children:"3 coats"})]})]})]})]}),(0,$.jsxs)("div",{className:"paint-calculator__totals",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,$.jsxs)("div",{className:"paint-calculator__result-grid",children:[(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Paintable area"}),(0,$.jsxs)("strong",{children:[w.toFixed(2)," m\xB2"]})]}),(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Coverage"}),(0,$.jsxs)("strong",{children:[p," ",p===1?"coat":"coats"]})]}),(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Paint required"}),(0,$.jsxs)("strong",{children:[M.toFixed(1)," litres"]})]})]}),(0,$.jsx)("p",{className:"paint-calculator__note",children:"Based on paint coverage of 10 m\xB2 per litre. Decorative paint is not currently stocked in this catalogue, so this remains an estimate only."})]}),(0,$.jsxs)("div",{className:"paint-calculator__actions",children:[(0,$.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,$.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",disabled:!0,children:"Paint products unavailable"})]})]})]})})}var br=X(Xe()),ne=X(ie()),fc=e=>Number.parseFloat(e)||0,Bd={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 Ld({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,br.useState)("paving"),[n,o]=(0,br.useState)("council"),[l,c]=(0,br.useState)(""),[p,d]=(0,br.useState)(""),[g,f]=(0,br.useState)("100"),[h,w]=(0,br.useState)("50"),[M,D]=(0,br.useState)(!0),[m,u]=(0,br.useState)(!0),b=fc(l)*fc(p),v=b,N=b*(fc(g)/1e3),A=b*.04,T=b*(fc(h)/1e3),z=Math.ceil(v/.36),G=Math.ceil(v/.1),P=Math.ceil(N*1700/800),be=Math.ceil(A*1600/800),De=Math.ceil(T*1600/800),Le=r==="paving"?{qty:z,unit:"each"}:r==="block"?{qty:v,unit:"m2"}:{qty:De,unit:"bag"},He={paving:"paving slab",block:"block paver",gravel:"decorative gravel"}[r],ze=[{key:`surface-${n}`,label:Bd[r].find(ce=>ce.id===n)?.label??"Surface material",qty:Le.qty,unit:Le.unit,query:He,category:"landscaping"},...M?[{key:"sub-base",label:"MOT Type 1 sub-base",qty:P,unit:"bag",query:"MOT Type 1 sub base",category:"aggregate"}]:[],...m?[{key:"bedding",label:"Sharp sand bedding",qty:be,unit:"bag",query:"sharp sand",category:"aggregate"}]:[]];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:"Paving & Driveway Calculator"}),(0,ne.jsx)("p",{children:"Estimate paving, block paving, sub-base and bedding materials for outdoor areas."})]}),(0,ne.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,ne.jsx)("h2",{className:"truss-estimator__step-title",children:"Surface and ground build-up"}),(0,ne.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,ne.jsxs)("div",{className:"materials-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Surface material"}),(0,ne.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(([ce,fe,Ee])=>(0,ne.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===ce?" is-selected":""}`,onClick:()=>{i(ce),o(Bd[ce][0].id)},children:[(0,ne.jsx)("div",{className:"truss-estimator__option-title",children:fe}),(0,ne.jsx)("div",{className:"truss-estimator__option-copy",children:Ee})]},ce))}),(0,ne.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,ne.jsx)("span",{children:"Finish"}),(0,ne.jsx)("select",{value:n,onChange:ce=>o(ce.target.value),children:Bd[r].map(ce=>(0,ne.jsx)("option",{value:ce.id,children:ce.label},ce.id))})]})]}),(0,ne.jsxs)("div",{className:"materials-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and groundwork"}),(0,ne.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsx)("span",{children:"Length (m)"}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:ce=>c(ce.target.value)})]}),(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsx)("span",{children:"Width (m)"}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:ce=>d(ce.target.value)})]})]}),r==="gravel"&&(0,ne.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,ne.jsx)("span",{children:"Gravel depth (mm)"}),(0,ne.jsx)("input",{type:"number",min:"0",step:"10",value:h,onChange:ce=>w(ce.target.value)})]}),M&&(0,ne.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,ne.jsx)("span",{children:"Sub-base depth (mm)"}),(0,ne.jsx)("input",{type:"number",min:"0",step:"10",value:g,onChange:ce=>f(ce.target.value)})]}),(0,ne.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,ne.jsx)("input",{type:"checkbox",checked:M,onChange:ce=>D(ce.target.checked)}),(0,ne.jsx)("span",{children:"Include MOT Type 1 sub-base"})]}),(0,ne.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,ne.jsx)("input",{type:"checkbox",checked:m,onChange:ce=>u(ce.target.checked)}),(0,ne.jsx)("span",{children:"Include sharp sand bedding"})]})]}),(0,ne.jsxs)("div",{className:"materials-calculator__totals",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ne.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Surface area"}),(0,ne.jsxs)("strong",{children:[b.toFixed(2)," m\xB2"]})]}),(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:r==="paving"?"Paving slabs":r==="block"?"Block paving":"Gravel"}),(0,ne.jsx)("strong",{children:r==="paving"?`${z} slabs`:r==="block"?`${v.toFixed(2)} m\xB2`:`${De} bulk bags`})]}),M&&(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"MOT Type 1"}),(0,ne.jsxs)("strong",{children:[P," bulk bags"]})]}),m&&(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Sharp sand"}),(0,ne.jsxs)("strong",{children:[be," bulk bags"]})]})]}),(0,ne.jsx)("p",{className:"materials-calculator__note",children:"Slab and block quantities use typical sizes. Confirm pack coverage and laying pattern before ordering."})]}),(0,ne.jsxs)("div",{className:"materials-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?.(ze),disabled:b<=0,children:a})]})]})]})})}var ll=X(Xe()),oe=X(ie()),V_=2.88,Sw=[{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"}],Cw=()=>({length:"",height:""}),Hd=e=>Number.parseFloat(e)||0;function jd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,ll.useState)([Cw()]),[n,o]=(0,ll.useState)(""),[l,c]=(0,ll.useState)("standard"),[p,d]=(0,ll.useState)("screws"),g=r.reduce((A,T)=>A+Hd(T.length)*Hd(T.height),0),f=Math.max(0,g-Hd(n)),h=Math.ceil(f/V_),w=Math.ceil(f*12),M=Math.ceil(w/1e3),D=Math.ceil(f*1.2),m=Math.ceil(D/90),u=Math.ceil(f/3.5),b=Sw.find(A=>A.id===l)?.label??"Standard",v=[{key:"board",label:`${b} plasterboard`,qty:h,unit:"sheet",query:`${b} plasterboard`,category:"plasterboard"},...p==="screws"?[{key:"screws",label:"Drywall screws",qty:M,unit:"box",query:"drywall screws",category:"fixings"}]:[{key:"adhesive",label:"Board adhesive",qty:u,unit:"bag",query:"drywall board adhesive",category:"plasterboard"}],{key:"tape",label:"Joint tape",qty:m,unit:"roll",query:"plasterboard joint tape",category:"plasterboard"}],N=(A,T,z)=>{i(G=>G.map((P,be)=>be===A?{...P,[T]:z}:P))};return(0,oe.jsx)(oe.Fragment,{children:(0,oe.jsxs)("div",{className:"truss-estimator",children:[(0,oe.jsxs)("div",{className:"quick-order-hero",children:[(0,oe.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,oe.jsx)("h1",{children:"Plasterboard & Drylining Calculator"}),(0,oe.jsx)("p",{children:"Estimate boards, fixings and jointing materials for walls and ceilings."})]}),(0,oe.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,oe.jsx)("h2",{className:"truss-estimator__step-title",children:"Boards, fixings and jointing"}),(0,oe.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,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Board type"}),(0,oe.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Sw.map(A=>(0,oe.jsxs)("button",{type:"button",className:`truss-estimator__option-card${l===A.id?" is-selected":""}`,onClick:()=>c(A.id),children:[(0,oe.jsx)("div",{className:"truss-estimator__option-title",children:A.label}),(0,oe.jsx)("div",{className:"truss-estimator__option-copy",children:A.blurb})]},A.id))})]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Fixing method"}),(0,oe.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(([A,T,z])=>(0,oe.jsxs)("button",{type:"button",className:`truss-estimator__option-card${p===A?" is-selected":""}`,onClick:()=>d(A),children:[(0,oe.jsx)("div",{className:"truss-estimator__option-title",children:T}),(0,oe.jsx)("div",{className:"truss-estimator__option-copy",children:z})]},A))})]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall and ceiling areas"}),(0,oe.jsx)("p",{className:"materials-calculator__hint",children:"Add each surface separately so different wall sizes are easy to measure."}),(0,oe.jsxs)("div",{className:"materials-calculator__dimensions-header",children:[(0,oe.jsx)("span",{children:"Surface"}),(0,oe.jsx)("span",{children:"Length (m)"}),(0,oe.jsx)("span",{children:"Height (m)"}),(0,oe.jsx)("span",{})]}),r.map((A,T)=>(0,oe.jsxs)("div",{className:"materials-calculator__surface-row",children:[(0,oe.jsxs)("span",{children:["Surface ",T+1]}),(0,oe.jsx)("input",{"aria-label":`Surface ${T+1} length`,type:"number",min:"0",step:"0.01",value:A.length,onChange:z=>N(T,"length",z.target.value)}),(0,oe.jsx)("input",{"aria-label":`Surface ${T+1} height`,type:"number",min:"0",step:"0.01",value:A.height,onChange:z=>N(T,"height",z.target.value)}),r.length>1?(0,oe.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(z=>z.filter((G,P)=>P!==T)),children:"Remove"}):null]},`surface-${T}`)),(0,oe.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(A=>[...A,Cw()]),children:"+ Add another surface"}),(0,oe.jsxs)("label",{className:"truss-estimator__field materials-calculator__openings",children:[(0,oe.jsxs)("span",{children:["Openings to deduct (m\xB2) ",(0,oe.jsx)("small",{children:"optional"})]}),(0,oe.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:A=>o(A.target.value)})]})]}),(0,oe.jsxs)("div",{className:"materials-calculator__totals",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,oe.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:"Board area"}),(0,oe.jsxs)("strong",{children:[f.toFixed(2)," m\xB2"]})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:"2.4 x 1.2 m boards"}),(0,oe.jsx)("strong",{children:h})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:p==="screws"?"Drywall screws":"Board adhesive"}),(0,oe.jsx)("strong",{children:p==="screws"?`${w} (${M} boxes)`:`${u} bags`})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:"Joint tape"}),(0,oe.jsxs)("strong",{children:[D," m (",m," rolls)"]})]})]}),(0,oe.jsx)("p",{className:"materials-calculator__note",children:"Figures are estimates. Confirm board specification, fixing patterns and fire or acoustic requirements before ordering."})]}),(0,oe.jsxs)("div",{className:"materials-calculator__actions",children:[(0,oe.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,oe.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(v),disabled:f<=0,children:a})]})]})]})})}var sl=X(Xe());var _=X(ie()),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}}}},gc=["range","pitchAndDimensions","quantityAndGirders","bracing"],$_={range:null,pitch:null,spanMM:"",overhangMM:"",roofLengthM:"",centres:null,girderCount:0,bracing:null,treatment:null,contact:{name:"",email:""}};function Z_({degrees:e}){let a=e*Math.PI/180,i=82-Math.min(58,38*Math.tan(a));return(0,_.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,_.jsx)("line",{x1:"6",y1:"82",x2:"94",y2:"82",stroke:"var(--border)",strokeWidth:"2"}),(0,_.jsx)("polygon",{points:`12,82 88,82 50,${i}`,fill:"var(--accent-light)",stroke:"var(--accent)",strokeWidth:"3",strokeLinejoin:"round"})]})}function K_({type:e}){let t="#b3835a",a="#5c3b22",r="#d9b48f",i="#d3d8de",n="#7c8494",o=(d,g,f,h,w=8,M)=>{let D=f-d,m=h-g,u=Math.hypot(D,m)||1,b=-m/u,v=D/u,N=w*.2;return(0,_.jsxs)("g",{children:[(0,_.jsx)("line",{x1:d,y1:g,x2:f,y2:h,stroke:a,strokeWidth:w+3,strokeLinecap:"square"}),(0,_.jsx)("line",{x1:d,y1:g,x2:f,y2:h,stroke:t,strokeWidth:w,strokeLinecap:"square"}),(0,_.jsx)("line",{x1:d-b*N,y1:g-v*N,x2:f-b*N,y2:h-v*N,stroke:r,strokeWidth:Math.max(1.5,w*.24),strokeLinecap:"round",opacity:"0.9"})]},M)},l=(d,g,f)=>(0,_.jsxs)("g",{children:[(0,_.jsx)("rect",{x:d-7.5,y:g-5.5,width:"15",height:"11",rx:"2",fill:i,stroke:n,strokeWidth:"1"}),(0,_.jsx)("circle",{cx:d-4,cy:g-2.5,r:"1",fill:n}),(0,_.jsx)("circle",{cx:d+4,cy:g-2.5,r:"1",fill:n}),(0,_.jsx)("circle",{cx:d-4,cy:g+2.5,r:"1",fill:n}),(0,_.jsx)("circle",{cx:d+4,cy:g+2.5,r:"1",fill:n}),(0,_.jsx)("circle",{cx:d,cy:g,r:"1",fill:n})]},f),c=(d,g)=>(0,_.jsx)("rect",{x:d-9,y:"110",width:"18",height:"10",fill:a},g),p=(0,_.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"});return e==="attic"?(0,_.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,_.jsx)("rect",{x:"90",y:"82",width:"20",height:"24",fill:"#cfe3f2",stroke:a,strokeWidth:"2"}),(0,_.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,_.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,_.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,_.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 P_({enabled:e}){return(0,_.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[(0,_.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"}),(0,_.jsx)("rect",{x:"17",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,_.jsx)("rect",{x:"165",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,_.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,_.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,_.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,_.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,_.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,_.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),e?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("line",{x1:"45",y1:"112",x2:"140",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"}),(0,_.jsx)("line",{x1:"155",y1:"112",x2:"60",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"})]}):null,(0,_.jsx)("rect",{x:"18.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,_.jsx)("rect",{x:"166.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,_.jsx)("rect",{x:"92.5",y:"28.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"})]})}function qw({treated:e}){let t=e?"#5a7a4a":"var(--accent)";return(0,_.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,_.jsx)("rect",{x:"10",y:"22",width:"80",height:"14",rx:"2",fill:t}),(0,_.jsx)("rect",{x:"10",y:"43",width:"80",height:"14",rx:"2",fill:e?"#8faf7a":"var(--accent-light)"}),(0,_.jsx)("rect",{x:"10",y:"64",width:"80",height:"14",rx:"2",fill:t})]})}function Qd({onBack:e}){let[t,a]=(0,sl.useState)(0),[r,i]=(0,sl.useState)($_),[n,o]=(0,sl.useState)(!1),[l,c]=(0,sl.useState)(!1),p=()=>{let m=Number.parseFloat(r.roofLengthM)||0,u=Number.parseFloat(r.centres??"");return m<=0||!u?0:Math.ceil(m*1e3/u)+1},g=(()=>{let m=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,A=(Number.parseFloat(r.overhangMM)||0)>Rt.overhang.thresholdMM,T=p(),z=T+r.girderCount,G=Number.parseFloat(r.roofLengthM)||0,P=r.treatment?Rt.treatment[r.treatment]:Rt.treatment.untreated,be=Rt.estimate.ranges[r.range??"standard"],De=be.supplyAt8m*Math.max(.7,v/8)*b*(1+P.surchargePct)+(A?Rt.overhang.surchargePerTruss:0),Le=T*De,He=r.girderCount*De*Rt.estimate.girderMultiplier,ze=r.bracing==="yes"?G*Rt.estimate.bracingPerMetre:0,me=Le+He+ze+Rt.estimate.delivery,ce=Rt.estimate.design+T*be.installPerTruss+r.girderCount*40,fe=me+ce,Ee=fe*.2;return{range:m,count:T,girderCount:r.girderCount,overhangApplies:A,overhangUnits:z,roofLengthM:G,treatment:P,trussSupply:Le,bracingMaterials:ze,delivery:Rt.estimate.delivery,labour:ce,subtotal:fe,vat:Ee,total:fe+Ee}})(),f=()=>{let m=gc[t];return m==="range"?!!r.range:m==="pitchAndDimensions"?!!r.pitch&&r.spanMM.trim()!==""&&r.overhangMM.trim()!=="":m==="quantityAndGirders"?r.roofLengthM.trim()!==""&&!!r.centres:m==="bracing"?!!r.bracing&&!!r.treatment:!0},h=t===gc.length-1?"View truss request":"Next",w=()=>{n?o(!1):t===0?e():a(m=>m-1)},M=()=>{f()&&(t===gc.length-1?(c(!1),o(!0)):a(m=>m+1))},D=()=>{let m=gc[t];return m==="range"?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Step 1 of 4"}),(0,_.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your truss range"}),(0,_.jsx)("p",{className:"truss-estimator__step-sub",children:"Pricing shown is placeholder. Swap in your real engineering and pricing catalogue."}),(0,_.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--range",children:Object.entries(Rt.ranges).map(([u,b])=>(0,_.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r.range===u?" is-selected":""}`,onClick:()=>i(v=>({...v,range:u})),children:[(0,_.jsx)(K_,{type:u}),(0,_.jsxs)("div",{className:"truss-estimator__option-info",children:[(0,_.jsx)("div",{className:"truss-estimator__option-title",children:b.label}),(0,_.jsx)("div",{className:"truss-estimator__option-copy",children:b.blurb})]})]},u))})]}):m==="pitchAndDimensions"?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Step 2 of 4"}),(0,_.jsx)("h2",{className:"truss-estimator__step-title",children:"Span, overhang and roof pitch"}),(0,_.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,_.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,_.jsxs)("label",{className:"truss-estimator__field",children:[(0,_.jsx)("span",{children:"Span (mm)"}),(0,_.jsx)("input",{type:"text",inputMode:"numeric",value:r.spanMM,onChange:u=>i(b=>({...b,spanMM:u.target.value}))})]}),(0,_.jsxs)("label",{className:"truss-estimator__field",children:[(0,_.jsx)("span",{children:"Overhang (mm)"}),(0,_.jsx)("input",{type:"text",inputMode:"numeric",value:r.overhangMM,onChange:u=>i(b=>({...b,overhangMM:u.target.value}))}),(0,_.jsxs)("small",{children:["Overhangs beyond ",Rt.overhang.thresholdMM,"mm add a small surcharge per truss."]})]})]}),(0,_.jsx)("div",{className:"truss-estimator__section-heading",children:"Roof pitch"}),(0,_.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:Rt.pitches.map(u=>(0,_.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${r.pitch===u?" is-selected":""}`,onClick:()=>i(b=>({...b,pitch:u})),children:[(0,_.jsx)(Z_,{degrees:Number.parseFloat(u)}),(0,_.jsxs)("span",{children:[u,"\xB0"]})]},u))})]}):m==="quantityAndGirders"?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Step 3 of 4"}),(0,_.jsx)("h2",{className:"truss-estimator__step-title",children:"Roof length"}),(0,_.jsx)("p",{className:"truss-estimator__step-sub",children:"Trusses are based on designs at 400mm or 600mm centres wherever possible."}),(0,_.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,_.jsx)("span",{children:"Roof length (m)"}),(0,_.jsx)("input",{type:"text",inputMode:"decimal",value:r.roofLengthM,onChange:u=>i(b=>({...b,roofLengthM:u.target.value}))})]}),(0,_.jsx)("div",{className:"truss-estimator__section-heading",children:"Truss centres"}),(0,_.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--centres",children:Rt.centresOptions.map(u=>(0,_.jsx)("button",{type:"button",className:`truss-estimator__option-card truss-estimator__option-card--compact${r.centres===u?" is-selected":""}`,onClick:()=>i(b=>({...b,centres:u})),children:(0,_.jsxs)("div",{className:"truss-estimator__option-title",children:[u,"mm centres"]})},u))}),(0,_.jsxs)("div",{className:"truss-estimator__stat",children:[p()," trusses estimated"]}),(0,_.jsx)("div",{className:"truss-estimator__section-heading",children:"Girder trusses"}),(0,_.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,_.jsxs)("div",{className:"truss-estimator__stepper",children:[(0,_.jsx)("button",{type:"button",onClick:()=>i(u=>({...u,girderCount:Math.max(0,u.girderCount-1)})),children:"\u2212"}),(0,_.jsx)("span",{children:r.girderCount}),(0,_.jsx)("button",{type:"button",onClick:()=>i(u=>({...u,girderCount:Math.min(3,u.girderCount+1)})),children:"+"})]})]}):m==="bracing"?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Step 4 of 4"}),(0,_.jsx)("h2",{className:"truss-estimator__step-title",children:"Bracing pack?"}),(0,_.jsx)("p",{className:"truss-estimator__step-sub",children:"A timber bracing pack stabilises the roof structure once trusses are erected."}),(0,_.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,_.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.bracing===u.id?" is-selected":""}`,onClick:()=>i(b=>({...b,bracing:u.id})),children:[(0,_.jsx)(P_,{enabled:u.id==="yes"}),(0,_.jsx)("span",{children:u.label})]},u.id))}),(0,_.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber treatment"}),(0,_.jsx)("p",{className:"truss-estimator__step-sub",children:"Tanalised timber protects against rot in exposed or damp locations."}),(0,_.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,_.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.treatment==="untreated"?" is-selected":""}`,onClick:()=>i(u=>({...u,treatment:"untreated"})),children:[(0,_.jsx)(qw,{treated:!1}),(0,_.jsx)("span",{children:"Untreated"})]}),(0,_.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.treatment==="treated"?" is-selected":""}`,onClick:()=>i(u=>({...u,treatment:"treated"})),children:[(0,_.jsx)(qw,{treated:!0}),(0,_.jsx)("span",{children:"Treated (+8% cost)"}),(0,_.jsx)("small",{children:"Applies to trusses, girders and overhang"})]})]})]}):null};return n?(0,_.jsx)(_.Fragment,{children:(0,_.jsxs)("div",{className:"truss-estimator",children:[(0,_.jsxs)("div",{className:"quick-order-hero",children:[(0,_.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,_.jsx)("h1",{children:"Your truss estimate"}),(0,_.jsx)("p",{children:"A provisional quantity and specification based on the dimensions you entered."})]}),(0,_.jsxs)("div",{className:"truss-estimator__card truss-request",style:{minHeight:0},children:[(0,_.jsxs)("div",{className:"truss-request__heading",children:[(0,_.jsxs)("div",{children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Estimated requirement"}),(0,_.jsxs)("h2",{children:[g.range.label," roof trusses"]})]}),(0,_.jsxs)("strong",{children:[g.count,(0,_.jsx)("span",{children:"trusses"})]})]}),(0,_.jsxs)("div",{className:"truss-request__grid",children:[(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Span"}),(0,_.jsxs)("strong",{children:[r.spanMM," mm"]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Roof length"}),(0,_.jsxs)("strong",{children:[r.roofLengthM," m"]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Pitch"}),(0,_.jsxs)("strong",{children:[r.pitch,"\xB0"]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Centres"}),(0,_.jsxs)("strong",{children:[r.centres," mm"]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Overhang"}),(0,_.jsxs)("strong",{children:[r.overhangMM," mm"]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Treatment"}),(0,_.jsx)("strong",{children:g.treatment.label})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Girder trusses"}),(0,_.jsx)("strong",{children:g.girderCount||"None"})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Bracing pack"}),(0,_.jsx)("strong",{children:r.bracing==="yes"?"Included":"Not included"})]})]}),(0,_.jsxs)("div",{className:"truss-request__price",children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Indicative cost estimate"}),(0,_.jsxs)("div",{className:"truss-request__price-grid",children:[(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Truss supply allowance"}),(0,_.jsx)("strong",{children:nt(g.trussSupply)})]}),g.bracingMaterials>0&&(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Bracing materials allowance"}),(0,_.jsx)("strong",{children:nt(g.bracingMaterials)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Delivery allowance"}),(0,_.jsx)("strong",{children:nt(g.delivery)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Design and installation labour"}),(0,_.jsx)("strong",{children:nt(g.labour)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Subtotal (ex. VAT)"}),(0,_.jsx)("strong",{children:nt(g.subtotal)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"VAT (20%)"}),(0,_.jsx)("strong",{children:nt(g.vat)})]}),(0,_.jsxs)("div",{className:"truss-request__price-total",children:[(0,_.jsx)("span",{children:"Estimated total"}),(0,_.jsx)("strong",{children:nt(g.total)})]})]}),(0,_.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,_.jsxs)("div",{className:"truss-request__notice",children:[(0,_.jsx)("strong",{children:"Before ordering"}),(0,_.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,_.jsxs)("div",{className:"truss-estimator__nav",children:[(0,_.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,_.jsx)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",justifyContent:"center",marginTop:0},onClick:()=>c(!0),children:"Request order"})]}),l&&(0,_.jsx)("p",{className:"truss-request__demo",children:"Demo only \u2014 no order has been sent."})]})]})}):(0,_.jsx)(_.Fragment,{children:(0,_.jsxs)("div",{className:"truss-estimator",children:[(0,_.jsxs)("div",{className:"quick-order-hero",children:[(0,_.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,_.jsx)("h1",{children:"Roof Truss Calculator"}),(0,_.jsx)("p",{children:"Estimate trusses, girders and cost for your roof in a few steps."})]}),(0,_.jsxs)("div",{className:"truss-estimator__card",children:[(0,_.jsx)("div",{className:"truss-estimator__body",children:D()}),(0,_.jsxs)("div",{className:"truss-estimator__nav",children:[(0,_.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:w,children:"Back"}),(0,_.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:M,disabled:!f(),children:[(0,_.jsx)("span",{children:h}),(0,_.jsx)("span",{className:"arrow",children:(0,_.jsx)(jt,{})})]})]})]})]})})}var Ci=X(Xe()),I=X(ie()),Tw=e=>Number.parseFloat(e)||0,hc=(e,t)=>Tw(e)*(t==="m"?1:.3048),Ew=()=>({length:"",width:""}),Mw=[{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 J_({profile:e}){return(0,I.jsxs)("svg",{className:"skirting-calculator__profile-diagram",viewBox:"0 0 120 84","aria-hidden":"true",children:[(0,I.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,I.jsx)("line",{x1:"12",y1:"70",x2:"108",y2:"70"})]})}function Gd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ci.useState)("total"),[n,o]=(0,Ci.useState)("m"),[l,c]=(0,Ci.useState)(""),[p,d]=(0,Ci.useState)([Ew()]),[g,f]=(0,Ci.useState)(""),[h,w]=(0,Ci.useState)("chamfered"),M="4.2",D=r==="total"?hc(l,n):p.reduce((N,A)=>N+2*(hc(A.length,n)+hc(A.width,n)),0),m=Math.max(0,D-hc(g,n)),u=Math.ceil(m/Tw(M)),b=[{key:`skirting-${h}`,label:`${Mw.find(N=>N.id===h)?.label} skirting board`,qty:m,unit:"m",query:"skirting board",category:"skirting"}],v=(N,A,T)=>{d(z=>z.map((G,P)=>P===N?{...G,[A]:T}:G))};return(0,I.jsx)(I.Fragment,{children:(0,I.jsxs)("div",{className:"truss-estimator",children:[(0,I.jsxs)("div",{className:"quick-order-hero",children:[(0,I.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,I.jsx)("h1",{children:"Skirting Board Calculator"}),(0,I.jsx)("p",{children:"Work out how many skirting board lengths you need for one room or a whole project."})]}),(0,I.jsxs)("div",{className:"truss-estimator__card skirting-calculator",children:[(0,I.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure by room or total length"}),(0,I.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,I.jsxs)("div",{className:"skirting-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"How would you like to measure?"}),(0,I.jsxs)("div",{className:"brick-calculator__unit-toggle skirting-calculator__mode-toggle",role:"group","aria-label":"Calculation method",children:[(0,I.jsx)("button",{type:"button",className:r==="total"?"is-selected":"",onClick:()=>i("total"),children:"Total length"}),(0,I.jsx)("button",{type:"button",className:r==="rooms"?"is-selected":"",onClick:()=>i("rooms"),children:"Room by room"})]})]}),(0,I.jsxs)("div",{className:"skirting-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Measurements"}),(0,I.jsxs)("div",{className:"skirting-calculator__unit-row",children:[(0,I.jsx)("span",{children:"Units"}),(0,I.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,I.jsx)("button",{type:"button",className:n==="m"?"is-selected":"",onClick:()=>o("m"),children:"Metres"}),(0,I.jsx)("button",{type:"button",className:n==="ft"?"is-selected":"",onClick:()=>o("ft"),children:"Feet"})]})]}),r==="total"?(0,I.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,I.jsxs)("span",{children:["Total skirting length (",n,")"]}),(0,I.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:N=>c(N.target.value)})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("div",{className:"skirting-calculator__dimensions-header",children:[(0,I.jsx)("span",{children:"Room"}),(0,I.jsxs)("span",{children:["Length (",n,")"]}),(0,I.jsxs)("span",{children:["Width (",n,")"]}),(0,I.jsx)("span",{})]}),p.map((N,A)=>(0,I.jsxs)("div",{className:"skirting-calculator__room-row",children:[(0,I.jsxs)("span",{className:"skirting-calculator__room-label",children:["Room ",A+1]}),(0,I.jsx)("input",{"aria-label":`Room ${A+1} length in ${n}`,type:"number",min:"0",step:"0.01",value:N.length,onChange:T=>v(A,"length",T.target.value)}),(0,I.jsx)("input",{"aria-label":`Room ${A+1} width in ${n}`,type:"number",min:"0",step:"0.01",value:N.width,onChange:T=>v(A,"width",T.target.value)}),p.length>1?(0,I.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>d(T=>T.filter((z,G)=>G!==A)),children:"Remove"}):null]},`room-${A}`)),(0,I.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>d(N=>[...N,Ew()]),children:"+ Add another room"})]}),(0,I.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,I.jsxs)("span",{children:["Openings and doorways to deduct (",n,") ",(0,I.jsx)("small",{children:"optional"})]}),(0,I.jsx)("input",{type:"number",min:"0",step:"0.01",value:g,onChange:N=>f(N.target.value)})]})]}),(0,I.jsxs)("div",{className:"skirting-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Profile"}),(0,I.jsx)("p",{className:"skirting-calculator__hint",children:"Choose the finish you want for the fixed 4.2m white-primed MDF boards."}),(0,I.jsx)("div",{className:"architrave-calculator__profiles",children:Mw.map(N=>(0,I.jsxs)("button",{type:"button",className:`truss-estimator__option-card${h===N.id?" is-selected":""}`,onClick:()=>w(N.id),children:[(0,I.jsx)(J_,{profile:N.id}),(0,I.jsx)("div",{className:"truss-estimator__option-title",children:N.label}),(0,I.jsx)("div",{className:"truss-estimator__option-copy",children:N.blurb})]},N.id))})]}),(0,I.jsxs)("div",{className:"skirting-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,I.jsx)("div",{className:"truss-estimator__field-grid skirting-calculator__options-grid",children:(0,I.jsxs)("label",{className:"truss-estimator__field",children:[(0,I.jsx)("span",{children:"Board length"}),(0,I.jsx)("input",{value:"4.20 m",disabled:!0})]})}),(0,I.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,I.jsxs)("div",{className:"skirting-calculator__totals",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,I.jsxs)("div",{className:"skirting-calculator__result-grid",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"Net skirting"}),(0,I.jsxs)("strong",{children:[m.toFixed(2)," m"]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"Board lengths"}),(0,I.jsx)("strong",{children:u})]})]}),(0,I.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,I.jsxs)("div",{className:"skirting-calculator__actions",children:[(0,I.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,I.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(b),disabled:m<=0,children:a})]})]})]})})}var jn=X(Xe()),le=X(ie()),cl=e=>Number.parseFloat(e)||0;function Yd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,jn.useState)("studs"),[n,o]=(0,jn.useState)(""),[l,c]=(0,jn.useState)(""),[p,d]=(0,jn.useState)("600"),[g,f]=(0,jn.useState)("2.4"),h=n&&l&&p?Math.ceil(cl(l)/(cl(p)/1e3))+1:0,w=h*cl(n),M=cl(g)>0?Math.ceil(w/cl(g)):0,D=[{key:r,label:{studs:"Stud timber",joists:"Joist timber",battens:"Batten timber"}[r],qty:w,unit:"m",query:{studs:"cls studwork timber",joists:"timber joist",battens:"roofing batten"}[r],category:"timber"}],m={studs:["Stud wall","Vertical studs along a wall length"],joists:["Joists","Parallel joists across a floor or deck"],battens:["Battens","Regularly spaced battens for lining or cladding"]},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,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"truss-estimator",children:[(0,le.jsxs)("div",{className:"quick-order-hero",children:[(0,le.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,le.jsx)("h1",{children:"Timber Calculator"}),(0,le.jsx)("p",{children:"Estimate studs, joists or battens from a run length, width and spacing."})]}),(0,le.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,le.jsx)("h2",{className:"truss-estimator__step-title",children:"Member size and spacing"}),(0,le.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,le.jsxs)("div",{className:"materials-calculator__section",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber use"}),(0,le.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:Object.keys(m).map(v=>(0,le.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===v?" is-selected":""}`,onClick:()=>i(v),children:[(0,le.jsx)("div",{className:"truss-estimator__option-title",children:m[v][0]}),(0,le.jsx)("div",{className:"truss-estimator__option-copy",children:m[v][1]})]},v))})]}),(0,le.jsxs)("div",{className:"materials-calculator__section",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Dimensions and spacing"}),(0,le.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsxs)("span",{children:[b.member," (m)"]}),(0,le.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:v=>o(v.target.value)})]}),(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsxs)("span",{children:[b.overall," (m)"]}),(0,le.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:v=>c(v.target.value)})]})]}),(0,le.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsx)("span",{children:"Centres (mm)"}),(0,le.jsxs)("select",{value:p,onChange:v=>d(v.target.value),children:[(0,le.jsx)("option",{value:"300",children:"300 mm"}),(0,le.jsx)("option",{value:"400",children:"400 mm"}),(0,le.jsx)("option",{value:"450",children:"450 mm"}),(0,le.jsx)("option",{value:"600",children:"600 mm"})]})]}),(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsx)("span",{children:"Stock length (m)"}),(0,le.jsxs)("select",{value:g,onChange:v=>f(v.target.value),children:[(0,le.jsx)("option",{value:"2.4",children:"2.40 m"}),(0,le.jsx)("option",{value:"3.6",children:"3.60 m"}),(0,le.jsx)("option",{value:"4.8",children:"4.80 m"})]})]})]})]}),(0,le.jsxs)("div",{className:"materials-calculator__totals",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,le.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{children:b.count}),(0,le.jsx)("strong",{children:h})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{children:"Linear metres"}),(0,le.jsxs)("strong",{children:[w.toFixed(2)," m"]})]}),(0,le.jsxs)("div",{children:[(0,le.jsxs)("span",{children:[g," m lengths"]}),(0,le.jsx)("strong",{children:M})]})]}),(0,le.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,le.jsxs)("div",{className:"materials-calculator__actions",children:[(0,le.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,le.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(D),disabled:w<=0,children:a})]})]})]})})}var Xd=[{id:"truss",title:"Roof Truss Calculator",desc:"Estimate trusses, girders and roof structure costs.",imageUrl:"/tool-images/truss.webp",Component:Qd},{id:"fencing",title:"Fencing Calculator",desc:"Estimate fence panels, posts, gravel boards and fixings.",imageUrl:"/tool-images/fencing.webp",Component:Ud},{id:"decking",title:"Decking Calculator",desc:"Estimate boards, substructure and fixing quantities.",imageUrl:"/tool-images/decking.webp",Component:Rd},{id:"brick-block",title:"Brick & Block Calculator",desc:"Estimate masonry units and ready-mixed mortar for a wall.",imageUrl:"/tool-images/brick-block.webp",Component:Ed},{id:"paint",title:"Paint Calculator",desc:"Estimate paint for walls, doors and multiple coats.",imageUrl:"/tool-images/paint.webp",Component:Od},{id:"skirting",title:"Skirting Board Calculator",desc:"Estimate skirting lengths for rooms and wall runs.",imageUrl:"/tool-images/skirting.webp",Component:Gd},{id:"architrave",title:"Architrave Calculator",desc:"Estimate architrave lengths for door and window openings.",imageUrl:"/tool-images/architrave.webp",Component:qd},{id:"concrete-aggregate",title:"Concrete & Aggregate Calculator",desc:"Estimate concrete, MOT, sand and gravel quantities.",imageUrl:"/tool-images/concrete-aggregate.webp",Component:zd},{id:"plasterboard",title:"Plasterboard Calculator",desc:"Estimate plasterboard sheets, screws, tape and adhesive.",imageUrl:"/tool-images/plasterboard.webp",Component:jd},{id:"insulation",title:"Insulation Calculator",desc:"Estimate insulation packs for floors, walls, roofs and lofts.",imageUrl:"/tool-images/insulation.webp",Component:Dd},{id:"timber",title:"Timber Calculator",desc:"Estimate studs, joists and battens from spacing and lengths.",imageUrl:"/tool-images/timber.webp",Component:Yd},{id:"paving",title:"Paving & Driveway Calculator",desc:"Estimate paving, block paving, MOT and sharp sand.",imageUrl:"/tool-images/paving.webp",Component:Ld}];var vc=X(Xe());var Ge=X(Xe());var S=X(ie()),F_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}],Vd={wasteFactorEnabled:!0},I_=3e3,zw=null;function bc(e,t){let a=el(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function W_(e){return e&&e.length>0?e.join(" x "):"-"}function $d({toolId:e,requirements:t,ready:a,onBack:r,onTotalChange:i}){let n=ac(),o=`${e}~${t.map(q=>`${q.key}|${q.query}|${q.category??""}|${q.qty}`).join("~")}`,l=o!==zw,[c,p]=(0,Ge.useState)(null),[d,g]=(0,Ge.useState)([]),[f,h]=(0,Ge.useState)(l),[w,M]=(0,Ge.useState)(null),[D,m]=(0,Ge.useState)("tile"),[u,b]=(0,Ge.useState)(null),[v,N]=(0,Ge.useState)(""),[A,T]=(0,Ge.useState)(null),[z,G]=(0,Ge.useState)(""),[P,be]=(0,Ge.useState)([]),[De,Le]=(0,Ge.useState)(new Set),[He,ze]=(0,Ge.useState)(null),[me,ce]=(0,Ge.useState)(""),[fe,Ee]=(0,Ge.useState)([]),ut=(0,Ge.useRef)(null),Se=(0,Ge.useRef)(!1),Z=q=>`${e}:${q}`,de=q=>Pr(q.chosen,{lineId:Z(q.requirement.key),description:q.requirement.label,unit:q.requirement.unit,qty:q.requirement.qty}),Je=(0,Ge.useMemo)(()=>t.map(q=>`${q.key}|${q.query}|${q.category??""}`).join("~"),[t]);(0,Ge.useEffect)(()=>{let q=!1;return vw().then(Y=>{q||p(Y.itemCount>0)}).catch(()=>{q||p(!1)}),()=>{q=!0}},[]),(0,Ge.useEffect)(()=>{if(!a||!c)return;let q=!1,Y;l&&h(!0),M(null);let K=Date.now();return(async()=>{let pe=null;try{pe=(await bw(t)).map(({requirement:Fe,candidates:xt})=>({requirement:Fe,candidates:xt,chosen:xt[0]??null}))}catch(ke){q||M(ke instanceof Error?ke.message:"Could not load products")}if(!q){if(zw=o,l){let ke=I_-(Date.now()-K);ke>0&&await new Promise(Fe=>{Y=window.setTimeout(Fe,ke)})}q||(pe&&(g(pe),!Se.current&&n&&(Se.current=!0,n.addManyToCart(pe.filter(ke=>ke.chosen).map(de)))),h(!1))}})(),()=>{q=!0,window.clearTimeout(Y)}},[a,c,Je]),(0,Ge.useEffect)(()=>{if(!A)return;let q=z.trim();if(!q){be([]);return}let Y=!1,K=window.setTimeout(()=>{Fr(q).then(pe=>{Y||be(pe)}).catch(()=>{Y||be([])})},250);return()=>{Y=!0,window.clearTimeout(K)}},[A,z]),(0,Ge.useEffect)(()=>{if(!He)return;let q=me.trim();if(!q){Ee([]);return}let Y=!1,K=window.setTimeout(()=>{Fr(q).then(pe=>{Y||Ee(pe)}).catch(()=>{Y||Ee([])})},250);return()=>{Y=!0,window.clearTimeout(K)}},[He,me]);let Ye=(0,Ge.useMemo)(()=>{let q=v.trim().toLowerCase(),Y=q?d.filter(K=>K.requirement.label.toLowerCase().includes(q)||(K.chosen?.description??"").toLowerCase().includes(q)||(K.chosen?.product_id??"").toLowerCase().includes(q)):d;return u?[...Y].sort((K,pe)=>{let ke=K.requirement.label.localeCompare(pe.requirement.label);return u==="asc"?ke:-ke}):Y},[d,v,u]),pt=Ye.filter(q=>q.chosen),ot=Ye.filter(q=>!q.chosen),at=d.filter(q=>q.chosen),ge=at.filter(q=>q.chosen?.price==null).length,W=at.reduce((q,Y)=>q+(Dt(de(Y),Vd).lineTotal??0),0);if((0,Ge.useEffect)(()=>{i?.(W)},[W,i]),!a||c===!1)return null;let k=n?at.filter(q=>n.cart[Z(q.requirement.key)]).length:0,R=He?d.find(q=>q.requirement.key===He)??null:null,O=me.trim()?fe:R?.candidates??[],ee=q=>{let Y=A===q.requirement.key;T(Y?null:q.requirement.key),G(Y?"":q.requirement.query)},xe=(q,Y)=>{let K=d.find(pe=>pe.requirement.key===q);g(pe=>pe.map(ke=>ke.requirement.key===q?{...ke,chosen:Y}:ke)),n&&K&&n.cart[Z(q)]&&n.addToCart(de({...K,chosen:Y})),T(null),G("")},we=q=>{g(Y=>Y.map(K=>K.requirement.key===q?{...K,chosen:null}:K)),n?.cart[Z(q)]&&n.removeFromCart(Z(q))},y=q=>{ze(q.requirement.key),ce(""),Ee([])},j=()=>{ze(null),ce(""),Ee([])},B=q=>{if(!n)return;let Y=Z(q.requirement.key);n.cart[Y]?n.removeFromCart(Y):n.addToCart(de(q))},ae=q=>{Le(Y=>{let K=new Set(Y);return K.has(q)?K.delete(q):K.add(q),K})},te=q=>{let Y=P.length>0?P:q.candidates;return(0,S.jsxs)("div",{className:"estimator-products__picker",children:[(0,S.jsx)("input",{type:"text",className:"results-search-input",value:z,autoFocus:!0,placeholder:"Search products in catalogue...",onChange:K=>G(K.target.value),"aria-label":`Search a product for ${q.requirement.label}`}),(0,S.jsxs)("div",{className:"estimator-products__options",children:[Y.map(K=>(0,S.jsxs)("button",{type:"button",className:`estimator-products__option${K.product_id===q.chosen?.product_id?" is-selected":""}`,onClick:()=>xe(q.requirement.key,K),children:[(0,S.jsx)("span",{children:K.description}),(0,S.jsxs)("span",{className:"results-row-meta",children:[K.product_id,K.price!=null&&` \xB7 ${nt(K.price)}`]})]},K.product_id)),Y.length===0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No matching products."})]})]})};return(0,S.jsxs)("section",{className:"estimator-products results-tile-section","aria-label":"Matched products",children:[!f&&(0,S.jsxs)("div",{className:"estimator-products__head",children:[(0,S.jsxs)("div",{className:"results-tile-section__head",children:[(0,S.jsx)("h3",{children:"Matched Products"}),(0,S.jsx)("p",{children:"Products matched to your estimate, check before adding to your basket."})]}),!R&&(0,S.jsxs)("div",{className:"results-summary estimator-products__toolbar",children:[ge>0&&(0,S.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,S.jsx)("strong",{children:ge})," need pricing"]}),(0,S.jsxs)("div",{className:"estimator-products__controls",children:[(0,S.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:v,onChange:q=>N(q.target.value),"aria-label":"Search matched products"}),(0,S.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,S.jsx)("button",{type:"button",className:`results-view-toggle__btn${D==="tile"?" is-active":""}`,"aria-pressed":D==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>m("tile"),children:(0,S.jsxs)("svg",{width:"18",height:"12",viewBox:"0 0 15 10",fill:"currentColor",children:[(0,S.jsx)("rect",{x:"0.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"5.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"10.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"0.5",y:"5.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"5.5",y:"5.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"10.5",y:"5.5",width:"4",height:"4"})]})}),(0,S.jsx)("button",{type:"button",className:`results-view-toggle__btn${D==="list"?" is-active":""}`,"aria-pressed":D==="list","aria-label":"List view",title:"List view",onClick:()=>m("list"),children:(0,S.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,S.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,S.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,S.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),(0,S.jsxs)("details",{ref:ut,style:{position:"relative"},children:[(0,S.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort materials",style:{fontSize:16},children:"\u21C5"}),(0,S.jsx)("div",{className:"sort-menu-panel",children:F_.map(q=>{let Y=u===q.dir;return(0,S.jsxs)("button",{type:"button",className:`sort-menu-item${Y?" is-active":""}`,onClick:()=>{b(Y?null:q.dir),ut.current?.removeAttribute("open")},children:[(0,S.jsx)("span",{className:"sort-menu-item__check",children:Y?"\u2713":""}),q.label]},q.dir)})})]})]})]})]}),R&&(0,S.jsxs)("div",{className:"results-review-page",children:[(0,S.jsxs)("div",{className:"results-review-page__top",children:[(0,S.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:j,children:[(0,S.jsx)(Kr,{}),"Back to results"]}),(0,S.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,S.jsx)("div",{className:"results-review-searchbar",children:(0,S.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:me,onChange:q=>ce(q.target.value),"aria-label":`Search a product for ${R.requirement.label}`})}),R.chosen&&(0,S.jsx)("div",{className:"results-candidate-actions",children:(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>we(R.requirement.key),children:"Clear selected product"})})]})]}),(0,S.jsxs)("div",{className:"results-review-page__hero",children:[(0,S.jsx)("div",{className:"results-review-page__image-wrap",children:(0,S.jsx)("img",{className:"fill-img results-review-page__image",src:Ya(R.chosen?.description||R.requirement.label,R.chosen?.product_id,R.chosen?.pdp_photo_url),alt:""})}),(0,S.jsxs)("div",{className:"results-review-page__summary",children:[(0,S.jsx)("h2",{children:R.requirement.label}),(0,S.jsxs)("p",{className:"results-review-page__meta",children:[yi(R.requirement.qty)," ",Na(R.requirement.unit,R.requirement.qty)]}),R.chosen?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("div",{className:"results-review-page__product",children:R.chosen.description}),(0,S.jsxs)("div",{className:"results-row-meta",children:[R.chosen.product_id,R.chosen.price!=null?` \xB7 ${bc(R.chosen.price,R.chosen.price_basis)}`:""]})]}):(0,S.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line."}),(0,S.jsx)("div",{className:"results-review-page__actions",children:(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${n?.cart[Z(R.requirement.key)]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>B(R),disabled:!R.chosen||!n,children:n?.cart[Z(R.requirement.key)]?"\u2713 Added":"+ Add to basket"})})]})]}),O.length===0?(0,S.jsx)("p",{className:"results-empty-hint",children:"No matching products."}):(0,S.jsxs)("table",{className:"score-breakdown-table",children:[(0,S.jsx)("thead",{children:(0,S.jsxs)("tr",{children:[(0,S.jsx)("th",{children:"Product"}),(0,S.jsx)("th",{children:"Dims (mm)"}),(0,S.jsx)("th",{children:"Price"}),(0,S.jsx)("th",{"aria-label":"Actions"})]})}),(0,S.jsx)("tbody",{children:O.map(q=>{let Y=q.product_id===R.chosen?.product_id;return(0,S.jsxs)("tr",{className:Y?"score-breakdown-row--best":"",children:[(0,S.jsxs)("td",{children:[(0,S.jsx)("div",{children:q.description}),(0,S.jsx)("div",{className:"results-row-meta",children:q.product_id})]}),(0,S.jsx)("td",{children:(0,S.jsx)("span",{className:"unit-badge",children:W_(q.measurements_mm)})}),(0,S.jsx)("td",{children:q.price!=null?bc(q.price,q.price_basis):"-"}),(0,S.jsx)("td",{children:(0,S.jsxs)("label",{className:"switch-toggle",title:Y?"Currently selected":"Use this candidate",children:[(0,S.jsx)("input",{type:"checkbox",checked:Y,onChange:()=>{Y?we(R.requirement.key):xe(R.requirement.key,q)},"aria-label":Y?`${q.description} selected`:`Use ${q.description}`}),(0,S.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},q.product_id)})})]})]}),!R&&f&&(0,S.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{padding:"32px 24px"},children:[(0,S.jsx)(fr,{}),(0,S.jsx)("p",{className:"banter-message is-visible",style:{fontSize:15,minHeight:0},children:"Matching your materials against the catalogue\u2026"})]}),!R&&w&&(0,S.jsx)("p",{className:"results-empty-hint estimator-products__error",children:w}),!R&&!f&&!w&&Ye.length===0&&d.length>0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No materials match the current search."}),!R&&!f&&!w&&D==="tile"&&pt.length>0&&(0,S.jsx)("div",{className:"results-tile-grid",children:pt.map(q=>{let{requirement:Y,chosen:K}=q,pe=K?Dt(de(q),Vd):null,ke=n?!!n.cart[Z(Y.key)]:!1;return(0,S.jsxs)("article",{className:"results-tile-card",children:[(0,S.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>y(q),"aria-label":`Review match for ${Y.label}`,children:[(0,S.jsx)("div",{className:"results-tile-card__media",children:(0,S.jsx)("img",{className:"fill-img results-tile-card__image",src:Ya(K?.description||Y.label,K?.product_id,K?.pdp_photo_url),alt:""})}),(0,S.jsxs)("div",{className:"results-tile-card__body",children:[K?(0,S.jsxs)("div",{className:"results-tile-card__heading",children:[(0,S.jsx)("div",{className:"results-tile-card__title",children:K.description}),(0,S.jsxs)("div",{className:"results-tile-card__match-meta",children:[(0,S.jsx)("span",{children:K.product_id}),K.price!=null?(0,S.jsx)("span",{children:bc(K.price,K.price_basis)}):null]})]}):(0,S.jsx)("div",{className:"results-empty-hint",children:"No product matched for this line."}),(0,S.jsxs)("div",{className:"results-tile-card__match",children:[(0,S.jsx)("div",{className:"results-tile-card__match-label",children:"\u21B3 calculated as"}),(0,S.jsx)("div",{className:"results-tile-card__match-name",children:Y.label}),(0,S.jsxs)("div",{className:"results-tile-card__meta",children:[yi(Y.qty)," ",Na(Y.unit,Y.qty)]}),pe?.requiredSellUnits!=null?(0,S.jsxs)("div",{className:"results-tile-card__meta estimator-products__order",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${nt(pe.lineTotal)}`:""]}):K?(0,S.jsx)("div",{className:"results-row-meta",children:"Quantity needs review"}):null]})]})]}),(0,S.jsxs)("div",{className:"results-tile-card__actions",children:[(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>y(q),children:"Review"}),(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${ke?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>B(q),disabled:!K||!n,children:ke?"\u2713 Added":"+ Add"})]})]},Y.key)})}),!R&&!f&&!w&&D==="list"&&pt.length>0&&(0,S.jsx)("div",{className:"bom-table-wrap",children:(0,S.jsxs)("table",{className:"bom-table results-table","aria-label":"Matched materials",children:[(0,S.jsxs)("colgroup",{children:[(0,S.jsx)("col",{style:{width:"56px"}}),(0,S.jsx)("col",{className:"col-item"}),(0,S.jsx)("col",{style:{width:"90px"}}),(0,S.jsx)("col",{style:{width:"80px"}}),(0,S.jsx)("col",{style:{width:"220px"}}),(0,S.jsx)("col",{style:{width:"110px"}})]}),(0,S.jsx)("thead",{children:(0,S.jsxs)("tr",{className:"bom-col-header",children:[(0,S.jsx)("th",{"aria-label":"Expand"}),(0,S.jsx)("th",{style:{textAlign:"left"},children:"Description"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Qty"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Unit"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Product Matched"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Basket"})]})}),(0,S.jsx)("tbody",{children:pt.map(q=>{let{requirement:Y,chosen:K}=q,pe=K?Dt(de(q),Vd):null,ke=n?!!n.cart[Z(Y.key)]:!1,Fe=De.has(Y.key);return(0,S.jsxs)(Ge.Fragment,{children:[(0,S.jsxs)("tr",{className:"bom-row",children:[(0,S.jsx)("td",{className:"bom-actions",style:{textAlign:"center",paddingLeft:0,paddingRight:0},children:(0,S.jsx)("button",{type:"button",className:"link-btn",onClick:()=>ae(Y.key),"aria-expanded":Fe,"aria-label":Fe?"Collapse product options":"Expand product options",children:Fe?"\u25BE":"\u25B8"})}),(0,S.jsxs)("td",{style:{paddingLeft:0},children:[(0,S.jsx)("div",{className:"bom-component-name",children:Y.label}),pe?.requiredSellUnits!=null&&(0,S.jsxs)("div",{className:"results-row-meta",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${nt(pe.lineTotal)}`:""]})]}),(0,S.jsx)("td",{className:"bom-qty col-order",style:{textAlign:"center"},children:yi(Y.qty)}),(0,S.jsx)("td",{style:{textAlign:"center"},children:Na(Y.unit,Y.qty)}),(0,S.jsx)("td",{style:{textAlign:"center"},children:K?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("div",{className:"bom-component-name",children:K.description}),(0,S.jsxs)("div",{className:"results-row-meta",children:[K.product_id,K.price!=null&&` \xB7 ${bc(K.price,K.price_basis)}`]})]}):(0,S.jsx)("span",{className:"results-empty-hint",children:"No match"})}),(0,S.jsx)("td",{style:{textAlign:"center"},children:(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${ke?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>B(q),disabled:!K||!n,children:ke?"\u2713 Added":"+ Add"})})]}),Fe&&(0,S.jsx)("tr",{children:(0,S.jsx)("td",{colSpan:6,style:{paddingLeft:0,paddingRight:0},children:A===Y.key?te(q):(0,S.jsxs)("div",{className:"estimator-products__picker",children:[(0,S.jsxs)("div",{className:"estimator-products__options",children:[q.candidates.map(xt=>(0,S.jsxs)("button",{type:"button",className:`estimator-products__option${xt.product_id===K?.product_id?" is-selected":""}`,onClick:()=>xe(Y.key,xt),children:[(0,S.jsx)("span",{children:xt.description}),(0,S.jsxs)("span",{className:"results-row-meta",children:[xt.product_id,xt.price!=null&&` \xB7 ${nt(xt.price)}`]})]},xt.product_id)),q.candidates.length===0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No candidates found."})]}),(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ee(q),children:"Search the catalogue"})]})})})]},Y.key)})})]})}),!R&&!f&&!w&&ot.length>0&&(0,S.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,S.jsxs)("div",{className:"results-tile-section__head",children:[(0,S.jsx)("h3",{children:"Require Matching"}),(0,S.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,S.jsx)("div",{className:"results-unmatched-list",children:ot.map(q=>(0,S.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>y(q),children:[(0,S.jsxs)("span",{className:"results-unmatched-card__main",children:[(0,S.jsx)("span",{className:"results-unmatched-card__title",children:q.requirement.label}),(0,S.jsxs)("span",{className:"results-row-meta",children:[yi(q.requirement.qty)," ",Na(q.requirement.unit,q.requirement.qty)]})]}),(0,S.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},q.requirement.key))})]}),!f&&!w&&d.length>0&&(0,S.jsxs)("div",{className:"disclaimer-box",style:{alignItems:"center"},children:[(0,S.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,S.jsx)("p",{className:"disclaimer-text",children:"These matches are generated automatically and should be reviewed before procurement, especially any items flagged as medium or low confidence."})]}),!R&&!f&&!w&&(r||k>0)&&(0,S.jsxs)("div",{className:"btn-row estimator-products__footer",children:[r&&(0,S.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:r,children:"Back"}),k>0&&n&&(0,S.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:r?"0 1 70%":1,marginTop:0},onClick:n.openBasket,children:[(0,S.jsxs)("span",{children:["View Basket (",k,")"]}),(0,S.jsx)("span",{className:"arrow",children:(0,S.jsx)(jt,{})})]})]})]})}var Qt=X(ie());function Zd({toolId:e,toolTitle:t,requirements:a,onBack:r}){let[i,n]=(0,vc.useState)(0),o=(0,vc.useCallback)(l=>n(l),[]);return(0,Qt.jsx)(Qt.Fragment,{children:(0,Qt.jsxs)("div",{className:"truss-estimator",children:[(0,Qt.jsxs)("div",{className:"quick-order-hero",children:[(0,Qt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Qt.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,Qt.jsx)("h1",{children:"Your Materials"}),i>0&&(0,Qt.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,Qt.jsx)("strong",{children:nt(i)})," Est. total"]})]}),(0,Qt.jsxs)("p",{children:["Quantities from the ",t,", matched against your merchant\u2019s catalogue."]})]}),(0,Qt.jsx)("div",{className:"truss-estimator__card",style:{minHeight:0},children:(0,Qt.jsx)($d,{toolId:e,requirements:a,ready:!0,onBack:r,onTotalChange:o})})]})})}var ex=(e,t)=>{let a=t.key,r={"brick-block":{"brick-common":"5001444","brick-engineering-red":"5002008","brick-engineering-blue":"5001439",block:"5003187",mortar:"6003088"},skirting:{"skirting-chamfered":"4006057","skirting-ogee":"4006045","skirting-pencil-round":"4006048","skirting-torus":"4006042"},architrave:{"architrave-ogee":"4006060","architrave-ovolo":"4006063","architrave-pencil-round":"4006061","architrave-square-edge":"4006062","architrave-torus":"4006059"},plasterboard:{board:"2001035",screws:"2006040",tape:"2007043",adhesive:"2004023"},insulation:{"insulation-floor":"3002110","insulation-wall":"3002012","insulation-roof":"3004047","insulation-loft":"3003046"},timber:{studs:"4001168",joists:"4001201",battens:"4001053"},fencing:{"panels-boundary-0.9":"4001268","panels-boundary-1.2":"4001269","panels-boundary-1.5":"4001270","panels-boundary-1.8":"4001271","panels-skyline-0.9":"4001264","panels-skyline-1.2":"4001265","panels-skyline-1.5":"4001266","panels-skyline-1.8":"4001267","concrete-intermediate-6":"4001290","concrete-intermediate-8":"4001291","concrete-end-6":"4001294","concrete-end-8":"4001295","timber-post-6":"4001242","timber-post-8":"4001243",postcrete:"6003008",gate:"4001630","gravel-boards":"4001284"},decking:{"boards-meridian":"4001251","boards-summit":"4001360",joists:"4001201",screws:"1001103"},paving:{"surface-council":"7003121","surface-raj":"7003003","surface-brindle":"4001621","surface-charcoal":"4001622","surface-pea":"6001004","sub-base":"6001007",bedding:"6001012"}};return e==="plasterboard"?{standard:"2001035",moisture:"2002039",fire:"2002087",sound:"2002044"}[t.label.split(" ")[0].toLowerCase()]??r[e]?.[a]??null:r[e]?.[a]??null};function Aw(e,t){if(e==="paint"||e==="concrete-aggregate")return null;let a=t.map(r=>{let i=ex(e,r);return i?{key:r.key,productId:i,qty:r.qty,unit:r.unit}:null});return a.every(Boolean)?a:null}var Kd=X(Xe());var Ft=X(ie()),tx=1500;function Rw(e){let{addManyToCart:t,clearCart:a,openBasket:r}=An(),[i,n]=(0,Kd.useState)(!1),[o,l]=(0,Kd.useState)(null);return{adding:i,basketError:o,addToBasket:async(p,d)=>{let g=Date.now();n(!0),l(null);try{let f=await Promise.all(p.filter(w=>w.qty>0).map(async w=>{let M=(await Fr(w.productId)).find(D=>D.product_id===w.productId);if(!M)throw new Error("A selected product is no longer available in this catalogue.");return Pr(M,{lineId:`${e}:${w.key}`,description:M.description,unit:w.unit??"each",qty:w.qty,calculatorWasteIncluded:d})})),h=tx-(Date.now()-g);h>0&&await new Promise(w=>window.setTimeout(w,h)),a(),t(f),r()}catch(f){l(f instanceof Error?f.message:"Could not add the products to your basket.")}finally{n(!1)}}}}function Uw({toolTitle:e}){return(0,Ft.jsx)(Ft.Fragment,{children:(0,Ft.jsxs)("div",{className:"truss-estimator",children:[(0,Ft.jsxs)("div",{className:"quick-order-hero",children:[(0,Ft.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Ft.jsx)("h1",{children:"Your Materials"}),(0,Ft.jsxs)("p",{children:["Calculating quantities from the ",e,"."]})]}),(0,Ft.jsx)("div",{className:"truss-estimator__card",children:(0,Ft.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,Ft.jsx)(fr,{}),(0,Ft.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})})}var Ue=X(ie());function wc(e){let[t,a]=(0,Va.useState)(!1);return(0,Ue.jsx)(tc,{onOpenBasket:()=>a(!0),children:(0,Ue.jsx)(ax,{...e,showBasket:t,onShowBasket:a})})}function ax({fullPage:e=!1,hideHeader:t=!1,internal:a=!1,showBasket:r,onShowBasket:i}){let[n,o]=(0,Va.useState)(null),[l,c]=(0,Va.useState)(null),p=Xd.find(z=>z.id===n),{cart:d,updateCartQty:g,updateCartSellUnits:f,updateCartConversions:h,removeFromCart:w,clearCart:M}=An(),{adding:D,basketError:m,addToBasket:u}=Rw(p?.title??"calculator"),b=(0,Va.useRef)(null),v=Xs("estimating-tools",b);(0,Va.useEffect)(()=>{v("viewed")},[v]);let N=r?"basket":D?"adding":l?"review":n??"list",A=(0,Va.useRef)(N);(0,Va.useEffect)(()=>{A.current!==N&&(A.current=N,window.scrollTo(0,0))},[N]);let T=z=>{if(!p)return;v("estimate_completed",{calculator:p.id,lines:z.length});let G=Aw(p.id,z);G?u(G,z[0]?.calculatorWasteIncluded??!1):c(z)};return(0,Ue.jsx)(Po.Provider,{value:v,children:(0,Ue.jsx)("div",{ref:b,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}`,style:Ra().theme,children:(0,Ue.jsx)("main",{className:"main-content",children:r?(0,Ue.jsx)(ol,{cart:d,onUpdateQty:g,onUpdateSellUnits:f,onResolveConversions:h,onRemove:w,onBack:()=>i(!1),onStartNewQuote:()=>{M(),o(null),c(null),i(!1)},internal:a}):D&&p?(0,Ue.jsx)(Uw,{toolTitle:p.title}):p?(0,Ue.jsxs)(Ue.Fragment,{children:[(0,Ue.jsx)("div",{hidden:l!==null,children:(0,Ue.jsx)(p.Component,{onBack:()=>o(null),onReview:T})}),m&&(0,Ue.jsx)("p",{className:"results-empty-hint estimator-products__error",children:m}),l!==null&&(0,Ue.jsx)(Zd,{toolId:p.id,toolTitle:p.title,requirements:l,onBack:()=>c(null)})]}):(0,Ue.jsx)(Ue.Fragment,{children:(0,Ue.jsxs)("div",{className:"quick-order-card",children:[(0,Ue.jsxs)("div",{className:"quick-order-hero",children:[(0,Ue.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,Ue.jsx)("h1",{children:"Estimating Tools"}),(0,Ue.jsx)("p",{children:"Trade-specific calculators for trusses, fencing, decking, masonry and painting. Dial in your specs and get an instant material estimate."})]}),(0,Ue.jsxs)("div",{className:"quick-order-alt",children:[(0,Ue.jsx)("div",{className:"quick-order-alt-title",children:"Choose a Calculator"}),(0,Ue.jsx)("div",{className:"estimator-tools-grid",children:Xd.map(z=>(0,Ue.jsxs)("button",{type:"button",className:"estimator-tool-card",onClick:()=>{v("calculator_selected",{calculator:z.id}),o(z.id),c(null)},children:[(0,Ue.jsx)("span",{className:"estimator-tool-card__image-wrap",children:(0,Ue.jsx)("img",{className:"fill-img estimator-tool-card__image",src:Jt(z.imageUrl),alt:""})}),(0,Ue.jsxs)("span",{className:"estimator-tool-card__content",children:[(0,Ue.jsx)("span",{className:"estimator-tool-card__title",children:z.title}),(0,Ue.jsx)("span",{className:"estimator-tool-card__desc",children:z.desc})]})]},z.id))})]})]})})})})})}var yc=X(ie());function Pd({config:e,children:t}){return Wb(e),(0,yc.jsx)(yc.Fragment,{children:t})}var Jd=X(ie()),rx="https://api.metronlabs.ai",ix=["client","api-key","api-url","theme","hide-header","analytics"],nx=["all","events-only","none"];function Ow(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.45",this.id||(this.id=e),this.setAttribute("data-turbo-permanent",""),this.setAttribute("data-turbolinks-permanent",""),!this.root){let i=document.createElement("div"),n=document.createElement("style");n.textContent=`:host { display: block; }
|
|
6803
|
+
`)}function Pr(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 aw=e=>(e??"").trim().toLowerCase(),e_={sqm:"m2","sq m":"m2","m\xB2":"m2",cbm:"m3","cu m":"m3",lm:"m","lin m":"m",metre:"m",meter:"m",each:"each",ea:"each",nr:"each",no:"each",item:"each",unit:"each",units:"each",pc:"each",pcs:"each",board:"sheet",bags:"bag",length:"length",lengths:"length",pallet:"pallet",pallets:"pallet"},vd=new Set(["sheet","length","box","bag","pack","roll","set","tub","each"]),Iv=new Set(["box","bag","pack","pallet","roll","set","tub"]),Wv=(e,t)=>t==="ml"?e:["l","litre","litres"].includes(t)?e*1e3:null,ew=(e,t)=>t==="g"?e:["kg","kilogram","kilograms"].includes(t)?e*1e3:["t","tonne","tonnes"].includes(t)?e*1e6:null,_i=e=>{let t=aw(e);return e_[t]??t},ct=(e,t)=>{let a=_i(e),r=_i(t);return a.length>0&&a===r},t_=(e,t)=>{let a=aw(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},a_=e=>(e??"").split(",").map(t=>_i(t)).filter(Boolean),r_=(e,t)=>{let a=a_(e.requestUomsSupported);return!!(a.length===0||a.includes(t)||ct(t,"pallet")&&e.itemsPerPallet!=null&&e.itemsPerPallet>0||ct(t,"pack")&&e.itemsPerPack!=null&&e.itemsPerPack>0||ct(t,"box")&&e.itemsPerBox!=null&&e.itemsPerBox>0)},tw=(e,t)=>ct(t,"pallet")?e.itemsPerPallet??null:ct(t,"pack")?e.itemsPerPack??null:ct(t,"box")?e.itemsPerBox??null:null,i_=(e,t,a)=>{if(!ct(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||!ct(r[3],a))return null;let i=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(i)&&i>0?i:null};function Is(e,t){return e.reduce((a,r)=>a+(Dt(r,t).lineTotal??0),0)}function Dt(e,t){let a=e.qty,r=_i(e.saleUnit??e.salesUnitSizeUom??e.uoi??e.salesUomNormalised)||"-",i=_i(e.unit)||(a>0&&vd.has(r)?r:"-"),n=e.saleUnitQuantity??e.salesUnitSize??e.uoiCount??1,o=t?.wasteFactorEnabled===!1?0:t?.wasteFactorOverride??e.wasteFactorOverride??e.wasteFactorDefault??0,l=e.sellUnitsOverride!=null&&Number.isFinite(e.sellUnitsOverride)&&e.sellUnitsOverride>0,c=l?vd.has(r)?Math.ceil(e.sellUnitsOverride):e.sellUnitsOverride:null,p=v=>({requestedAmount:a,requestedUnit:i,salesUnitSize:e.salesUnitSize??e.uoiCount??null,sellUnit:r,calculatedSellUnits:null,requiredSellUnits:c,unitPrice:e.price,lineTotal:e.price!=null&&c!=null?e.price*c:null,calculation:c!=null?`${v} Manually set to ${c} ${r}.`:v,costingMode:"review"});if(!r_(e,i))return p("Requested unit is not supported by this catalogue conversion.");let d=null,g="review",f=e.roundingRule,h=`Quantity review required, initial request needed ${a} ${i}.`,w=1+o,M=i_(e,i,r),D=e.unitConversions?.find(v=>ct(v.requestUom,i));if(!!e.saleUnit&&(ct(i,r)||!!D||ct(i,"each")&&!Iv.has(r)))if(ct(i,r))d=a*w/n,g="direct",h=`${a} ${i}${o>0?` x ${w}`:""}`;else if(D){d=a*w/D.quantityPerSaleUnit,g="derived";let v=1/D.quantityPerSaleUnit,N=Math.round(v);h=ct(r,"each")&&D.quantityPerSaleUnit<1&&Math.abs(v-N)<1e-9?`${a} ${i}${o>0?` x ${w}`:""} x ${N} per ${i}`:`${a} ${i}${o>0?` x ${w}`:""} / ${D.quantityPerSaleUnit} ${i} per ${r}`}else ct(i,"each")&&!Iv.has(r)&&(d=a*w/n,g="derived",h=`${a} ${r}${o>0?` x ${w}`:""}`);else if(ct(i,r)&&n>0)d=a*w/n,g="direct",h=o>0?`${a} ${i} x ${w} / ${n} ${r} per sell unit`:`${a} ${i} / ${n} ${r} per sell unit`;else if(ct(i,"each")&&n>0&&vd.has(r))d=a*w/n,g="derived",h=o>0?`${a} each x ${w} / ${n} each per ${r}`:`${a} each / ${n} each per ${r}`;else if(tw(e,i)!=null&&n>0){let v=tw(e,i)??0;d=a*v*w/n,g="derived";let N=`${a} ${i} x ${v} each${o>0?` x ${w}`:""}`;h=n===1&&ct(r,"each")?N:`${N} / ${n} each per ${r}`}else if(M!=null)d=a*w/M,g="derived",f??(f="round_up_each"),h=`${a} m2 x ${w} / ${M} m2 per ${r} (from product description)`;else if(e.conversionType==="basket_line_unit")n>0&&(d=a*w/n,g="derived",h=`${a} ${i}${o>0?` x ${w}`:""} / ${n} ${i} per ${r}`);else{if(e.conversionType==="count_only")return p(`Quantity review required, initial request needed ${a} ${i}.`);if(["area_from_dims","explicit_coverage_area","roll_area"].includes(e.conversionType??"")){let v=e.coverageQty??e.derivedCoverageM2??null;ct(i,"m2")&&v!=null&&v>0&&(d=a*w/v,g="derived",h=`${a} m2 x ${w} / ${v} m2 per ${r}`)}else if(e.conversionType==="count_per_area"){let v=e.coverageQty??null;ct(i,"m2")&&v!=null&&v>0?(d=a/v,g="derived",h=`${a} m2 / ${v} m2 per sell unit`):ct(i,"m2")&&e.itemsPerM2!=null&&e.itemsPerM2>0&&n>0&&(d=a*e.itemsPerM2*w/n,g="derived",h=`${a} m2 x ${e.itemsPerM2} ${r}/m2 x ${w} / ${n}`)}else if(e.conversionType==="length_from_dims"){let v=e.coverageQty??e.derivedLengthM??null;ct(i,"m")&&v!=null&&v>0&&(d=a*w/v,g="derived",h=`${a} m x ${w} / ${v} m per ${r}`)}else if(e.conversionType==="volume_from_description"){let v=Wv(a,i),N=Wv(e.coverageQty??0,_i(e.coverageUom));v!=null&&N!=null&&N>0&&(d=v*w/N,g="derived",h=`${a} ${i} x ${w} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="weight_from_description"){let v=ew(a,i),N=ew(e.coverageQty??0,_i(e.coverageUom));v!=null&&N!=null&&N>0&&(d=v*w/N,g="derived",h=`${a} ${i} x ${w} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="same_unit_volume"){let v=e.coverageQty??null;ct(i,"m3")&&v!=null&&v>0&&(d=a/v,g="derived",h=`${a} m3 / ${v} m3 per ${r}`)}}if(d==null||!Number.isFinite(d)||d<0)return p(`Quantity review required, initial request needed ${a} ${i}.`);let u=t_(d,f),b=l?c:u;return{requestedAmount:a,requestedUnit:i,salesUnitSize:n,sellUnit:r,calculatedSellUnits:u,requiredSellUnits:b,unitPrice:e.price,lineTotal:e.price!=null&&b!=null?e.price*b:null,calculation:l?`${h} = ${u} ${r} (manually set to ${b})`:`${h} = ${b} ${r}`,costingMode:g}}var rw=()=>import("./xlsx-K4MOA2QM.js"),al=["Source Line ID","Split Line ID","Description","Section","Qty","Unit","Procurement intent","Procurement aliases","Build-up type","Layer count","Total thickness (mm)","Installation clues","System clues","Component requirements","Technical classification","Include in quote","Approval required","Approval type","Missing information","Adjudicator confidence","Decision reason","Selected candidate ID","Selected candidate description","Price basis","Price","Line total","Confidence","Status"],n_=al.indexOf("Line total");function o_(e){return e.unmatchable?"Not matched (labour/plant/referential)":e.decision?.include_in_quote===!0&&e.decision.approval_required===!0?"Approval required":e.decision?.include_in_quote===!0?"Quoted":e.decision?.technical_classification==="no_suitable_candidate"?"No suitable candidate":(e.best,"No match")}async function iw(e){let t=await rw(),a=t.utils.book_new(),r=new Date().toISOString().slice(0,10),i=[al],n=0;for(let c of e){let{item:p,best:d,qty:g,band:f,unmatchable:h,decision:w}=c,M=[p.section,p.subsection,p.subheading].filter(Boolean).join(" / "),D=!h&&d?.price!=null?d.price*g:null;D!=null&&(n+=D),i.push([p.source_line_id,p.line_id,p.description_original||"(no description)",M,g,p.unit,p.procurement_intent||"-",p.procurement_aliases.join(", "),p.build_up_type,p.layer_count,p.total_required_thickness_mm,p.installation_clues.join(", "),p.system_clues.join(", "),p.component_requirements.join(", "),w?.technical_classification??"",w?.include_in_quote==null?"":w.include_in_quote?"yes":"no",w?.approval_required==null?"":w.approval_required?"yes":"no",w?.approval_type??"",w?.missing_information.join(", ")??"",w?.confidence??"",w?.reason??"",h?"-":d?.product_id??w?.selected_candidate_id??"-",h?"-":d?.description??"-",h?"-":d?.price_basis??"-",h?null:d?.price??null,D,h?"-":f,o_(c)])}i.push(Array(al.length).fill(null));let o=Array(al.length).fill(null);o[0]="Estimated total",o[n_]=n,i.push(o),i.push(["DISCLAIMER: These matches are generated automatically and should be reviewed before procurement, especially any items flagged as medium or low confidence.",...Array(al.length-1).fill(null)]);let l=t.utils.aoa_to_sheet(i);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 tl=["Product ID","Description","Costing mode","Required amount","Req unit","Sell unit size","Sell unit","Required sell units","Unit price","Line total"];async function nw(e,t){let a=await rw(),r=a.utils.book_new(),i=new Date().toISOString().slice(0,10),n=t?[["Account",t.name+" ("+t.id+")"],[],tl]:[tl],o=0;for(let p of e){let d=Dt(p),g=d.lineTotal;g!=null&&(o+=g),n.push([p.productId,p.description,d.costingMode,d.requestedAmount,ka(d.requestedUnit),d.salesUnitSize,ka(d.sellUnit),d.requiredSellUnits,d.unitPrice,g])}n.push(Array(tl.length).fill(null));let l=Array(tl.length).fill(null);l[0]="Estimated total",l[tl.length-1]=o,n.push(l);let c=a.utils.aoa_to_sheet(n);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}-${i}.xlsx`:`basket-${i}.xlsx`)}var s=X(ie()),yd="__none__",rl=24,l_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}];function cw(e){return e==null?"low":e>=.7?"high":e>=.5?"medium":"low"}var s_=e=>e.attrs.supply_nature==="labour_only"||e.attrs.supply_nature==="plant"||e.flags.includes("referential");function c_(e,t){if(t!==yd){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 ow(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 u_(e){return e?e.replace(/_/g," "):"not stated"}function p_({band:e}){return(0,s.jsx)("span",{className:`status-dot status-dot--${e}`,title:e,children:(0,s.jsx)("span",{className:"status-dot__mark"})})}function Tn(e,t){if(e==null)return"-";let a=el(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function _d(e){return e&&e.length>0?e.join(" x "):"-"}function d_(e){return e==null?"-":Number.isInteger(e/1e3)?`${e/1e3}m`:`${(e/1e3).toFixed(1)}m`}function Mn(e){let t=(e??[]).map(a=>a.trim()).filter(Boolean);return t.length>0?t.join(", "):"-"}function Jr(e,t){let a=typeof e.description_original=="string"?e.description_original.trim():"";return(typeof e.customer_display_label=="string"?e.customer_display_label.trim():"")||a||"(no description)"}var lw=[{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 m_(e){let t=new Map;return[...new Set(e.filter(gr).map(r=>r.linked_group_id))].forEach((r,i)=>{let n=i%26;t.set(r,{token:String.fromCharCode(65+n),bubbleStyle:lw[i%lw.length]})}),t}function gr(e){return!1}function zn(e){if(!e.linked_group_id)return null;let t=e.linked_group_label||"Linked group",a=e.linked_group_role==="anchor"?"anchor":e.linked_group_role==="dependent"?"dependent":"member",r=e.linked_group_shared_width_mm!=null?`, ${e.linked_group_shared_width_mm}mm family`:"";return`${t} (${a}${r})`}function wd({meta:e}){return e?(0,s.jsx)("span",{className:"results-linked-pill",style:e.bubbleStyle,children:`Link ${e.token}`}):null}function f_(e,t,a){let r=t?.rerank?.recommendedCandidateIds??[];if(r.length===0){let o=e.slice(0,5),l=o.some(c=>c.product_id===a)?void 0:e.find(c=>c.product_id===a);return l?[...o,l]:o}let i=new Map(e.map(o=>[o.product_id,o])),n=r.map(o=>i.get(o)).filter(o=>o!=null);if(a&&!n.some(o=>o.product_id===a)){let o=i.get(a);o&&n.unshift(o)}return[...new Map(n.map(o=>[o.product_id,o])).values()].slice(0,5)}function Ws(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 ec(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 g_({processStages:e,llmCalls:t,totalDurationMs:a,llmDurationMs:r,llmCallCount:i}){let n=[...t].sort((l,c)=>c.durationMs-l.durationMs).slice(0,12),o=Math.max(0,t.length-n.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:ec(a)})," total"]}),(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:i})," LLM calls"]}),(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:ec(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:ec(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:n.map((l,c)=>(0,s.jsxs)("tr",{children:[(0,s.jsx)("td",{children:l.label}),(0,s.jsx)("td",{children:ec(l.durationMs)})]},`${l.key}-${c}`))})]}),o>0&&(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Showing slowest ",n.length," of ",t.length," LLM calls."]})]})]})}function h_({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,i)=>(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:_d(r.measurements_mm)}),(0,s.jsx)("td",{children:el(r.price_basis)||"-"}),(0,s.jsx)("td",{children:r.bm25.toFixed(2)})]},`${r.product_id}-${i}`))})]})]},`${t.query}-${a}`))]})}function sw({item:e,result:t}){let a=t?.retrieval_debug.map(i=>i.query).filter(Boolean)??[],r=[["Procurement intent",e.procurement_intent||"-"],["Procurement aliases",Mn(e.procurement_aliases)],["Retrieval queries",Mn(a)],["Category",e.attrs.category||"-"],["Fine category",e.attrs.category_fine||"-"],["Brand",e.attrs.brand||"-"],["Material",e.attrs.material||"-"],["Grade / standard",e.attrs.grade_standard||"-"],["Treatment",e.attrs.treatment||"-"],["Supply nature",e.attrs.supply_nature||"-"],["Measurements (mm)",_d(e.attrs.measurements_mm)],["Stock length",d_(e.attrs.stock_length_mm)],["Matching mode",e.matching_mode||"-"],["Build-up type",e.build_up_type||"-"],["Layer count",e.layer_count!=null?String(e.layer_count):"-"],["Required thickness (mm)",e.total_required_thickness_mm!=null?String(e.total_required_thickness_mm):"-"],["Allowed layer thicknesses (mm)",e.acceptable_layer_thicknesses_mm.length>0?e.acceptable_layer_thicknesses_mm.join(", "):"-"],["Installation clues",Mn(e.installation_clues)],["System clues",Mn(e.system_clues)],["Component requirements",Mn(e.component_requirements)],["Linked group",zn(e)||"-"],["Flags",Mn(e.flags)]];return(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Search context"}),(0,s.jsx)("dl",{className:"results-detail-grid",children:r.map(([i,n])=>(0,s.jsxs)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:i}),(0,s.jsx)("dd",{children:n})]},i))})]})}function b_({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)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:"Attempted"}),(0,s.jsx)("dd",{children:t.attempted?"yes":"no"})]}),(0,s.jsxs)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:"Applied"}),(0,s.jsx)("dd",{children:t.applied?"yes":"no"})]}),(0,s.jsxs)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned items"}),(0,s.jsx)("dd",{children:t.returned_item_count??"-"})]}),(0,s.jsxs)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:"Reason"}),(0,s.jsx)("dd",{children:t.reason||"-"})]}),(0,s.jsxs)(Ne.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 v_({result:e}){let t=e?.adjudication_debug;if(!t)return null;let a=[["Dependent rerank applied",t.dependent_rerank_applied?"yes":"no"],["Linked parent selected product",t.linked_parent_selected_candidate_description||t.linked_parent_selected_candidate_id||"-"],["Dimension reason overridden",t.dimension_reason_overridden?"yes":"no"]];return(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsx)("h4",{style:{margin:"0 0 12px"},children:"Adjudication context"}),(0,s.jsx)("dl",{className:"results-detail-grid",children:a.map(([r,i])=>(0,s.jsxs)(Ne.Fragment,{children:[(0,s.jsx)("dt",{children:r}),(0,s.jsx)("dd",{children:i})]},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 w_({item:e,decision:t,result:a,showRetrievalDebug:r,reviewOnly:i=!1,linkedGroupMeta:n}){if(!t)return null;let o=t.technical_classification==="no_suitable_candidate"?"Exact match not found:":`AI review (${t.confidence??"confidence not stated"}):`;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:o}),"\xA0",t.reason]}),gr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",n?`Link ${n.token} - `:"",zn(e)]}):null]}):null:!t.reason&&!r?(0,s.jsx)(sw,{item:e,result:a}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(sw,{item:e,result:a}),r&&(0,s.jsx)(b_,{item:e}),r&&(0,s.jsx)(v_,{result:a}),t.reason&&(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,s.jsx)("strong",{children:o}),"\xA0",t.reason]}),gr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",n?`Link ${n.token} - `:"",zn(e)]}):null]}),r&&(0,s.jsx)(h_,{queries:a?.retrieval_debug??[]})]})}function y_({item:e,candidates:t,result:a,decision:r,unmatchable:i,selectedProductId:n,detailMode:o,onPick:l,onClear:c,showAll:p=!1,internal:d=!1,debugEnabled:g=!1,forceReviewNote:f=!1,linkedGroupMeta:h}){let w=d||o==="detailed",M=g&&o==="detailed",D=w||f?(0,s.jsx)(w_,{item:e,decision:r,result:a,showRetrievalDebug:M,reviewOnly:f&&!w,linkedGroupMeta:h}):null;if(i)return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsx)("p",{className:"results-empty-hint",children:"Classified as labour/plant or referencing another line item - skipped by design."})]});if(t.length===0)return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsx)("p",{className:"results-empty-hint",children:"No candidates were returned for this line item."})]});let m=p||d||o==="detailed"?t:f_(t,a,n);return(0,s.jsxs)(s.Fragment,{children:[D,(0,s.jsxs)("table",{className:"score-breakdown-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Product"}),(0,s.jsx)("th",{children:"Dims (mm)"}),(0,s.jsx)("th",{children:"Price"}),M&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("th",{children:"dimension"}),(0,s.jsx)("th",{children:"grade"}),(0,s.jsx)("th",{children:"brand"}),(0,s.jsx)("th",{children:"fuzzy"}),(0,s.jsx)("th",{children:"bm25"}),(0,s.jsx)("th",{children:"overall"})]}),(0,s.jsx)("th",{"aria-label":"Actions"})]})}),(0,s.jsx)("tbody",{children:m.map((u,b)=>{let v=u.product_id===n;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:_d(u.measurements_mm??u.debug?.candidate.measurements_mm)})}),(0,s.jsx)("td",{children:Tn(u.price,u.price_basis)}),M&&(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)(p_,{band:cw(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 xd({scheduleResult:e,onStartOver:t,cart:a,onAddToCart:r,onRemoveFromCart:i,onGoToBasket:n,cartSeeded:o,onCartSeeded:l,reviewGateComplete:c,onReviewGateComplete:p,internal:d=!1}){let g=!d&&Vs()==="QZA6-MRA4",f=g?"quote":"basket",{results:h,lineItems:w,parseReport:M,timings:D}=e,[m,u]=(0,Ne.useState)({}),b=Sn(),[v,N]=(0,Ne.useState)({}),[A,T]=(0,Ne.useState)({}),[z,G]=(0,Ne.useState)(""),[P,be]=(0,Ne.useState)(null),[De,Le]=(0,Ne.useState)(1),He=Ra().debug===!0,[ze,me]=(0,Ne.useState)("simple"),[ce,fe]=(0,Ne.useState)(d?"list":"tile"),[Ee,ut]=(0,Ne.useState)(!1),[Se,Z]=(0,Ne.useState)(null),[de,Je]=(0,Ne.useState)(""),[Ye,pt]=(0,Ne.useState)([]),[ot,at]=(0,Ne.useState)(!1),[ge,W]=(0,Ne.useState)(null),[k,R]=(0,Ne.useState)(!1),[E,O]=(0,Ne.useState)(null),ee=(0,Ne.useRef)(null),[xe,we]=(0,Ne.useState)(new Set),[y,j]=(0,Ne.useState)(new Set),[B,ae]=(0,Ne.useState)(!1);(0,Ne.useEffect)(()=>{Le(1)},[z,P,ce]);let te=new Map(h.map(x=>[x.line_id,x])),q=m_(w),Y=w.map(x=>{let H=te.get(x.line_id),ye=H?.decision,ft=s_(x),Ke=m[x.line_id],Wt=c_(H,Ke),Ti=a[x.line_id],Xw=Ke===yd?void 0:v[x.line_id]??(Ti&&Ti.productId!==Wt?.product_id?ow(Ti):Wt),om=ft?void 0:Xw,Vw=x.qty??0;return{item:x,result:H,decision:ye,unmatchable:ft,best:om,qty:Vw,band:cw(om?.scores?.overall)}}),K=Is(Object.values(a),{wasteFactorEnabled:!1,wasteFactorOverride:0}),pe=0;for(let x of Y){if(x.unmatchable||x.decision?.include_in_quote!==!0||!x.best)continue;let H=a[x.item.line_id];(!H||Dt(H).lineTotal==null)&&(pe+=1)}pe>0&&(K=null);let ke=x=>!x.unmatchable&&!x.best&&x.decision?.technical_classification!=="no_suitable_candidate"&&Ws(x.result).length>0,Fe=x=>x.best??Ws(x.result)[0],ua=Y.filter(x=>!x.unmatchable&&!x.best).filter(x=>!y.has(x.item.line_id)),ul=Y.filter(x=>y.has(x.item.line_id)),pa=Y;if(z.trim()){let x=z.trim().toLowerCase();pa=pa.filter(H=>H.item.description_original?.toLowerCase().includes(x)||Fe(H)?.description?.toLowerCase().includes(x))}if(P){let x=P==="asc"?1:-1;pa=[...pa].sort((H,ye)=>x*(H.item.description_original||"").localeCompare(ye.item.description_original||""))}let Qn=Math.max(1,Math.ceil(pa.length/rl)),It=Math.min(De,Qn),vr=pa.slice((It-1)*rl,It*rl),$a=vr.filter(x=>!x.unmatchable&&x.best),Fd=vr.filter(x=>ke(x)),Gn=vr.filter(x=>!x.unmatchable&&(x.best||ke(x))),Id=vr.filter(x=>x.unmatchable||!x.best&&!ke(x)),J=Se?Y.find(x=>x.item.line_id===Se)??null:null,Bw=!d&&!c&&!J&&ua.length>0,Yn=(0,Ne.useRef)(null),Xn=()=>{let x=ee.current;if(!x)return;let{top:H,left:ye,width:ft,height:Ke}=x.getBoundingClientRect(),Ti=x.querySelector(".bom-toolbar-btn")?.closest("td")?.getBoundingClientRect().left;O({top:H,left:ye,width:Ti?Ti-ye:ft,height:Ke})};(0,Ne.useEffect)(()=>(window.addEventListener("scroll",Xn,!0),window.addEventListener("resize",Xn),()=>{window.removeEventListener("scroll",Xn,!0),window.removeEventListener("resize",Xn)})),(0,Ne.useEffect)(()=>{let x=H=>{Yn.current&&!H.composedPath().includes(Yn.current)&&Yn.current.removeAttribute("open")};return document.addEventListener("click",x),()=>document.removeEventListener("click",x)},[]);let qi=x=>{Z(x),Je("")},Lw=()=>{if(!Se)return;let x=a[Se];if(x){u(H=>({...H,[Se]:x.productId})),N(H=>({...H,[Se]:ow(x)}));return}u(H=>{let ye={...H};return delete ye[Se],ye}),N(H=>{let ye={...H};return delete ye[Se],ye})},Za=(x=!1)=>{let H=Se?a[Se]:void 0;!x&&H&&J?.best&&H.productId!==J.best.product_id&&!window.confirm("You have selected a new product. Leave without updating it?")||(x||Lw(),Z(null),ae(!1))};Io(k,()=>R(!1)),Io(!!J&&!k,()=>Za());let Hw=x=>{if(we(H=>new Set(H).add(x)),ua.some(H=>H.item.line_id!==x)){Za(!0);return}p(),Za(!0)},jw=x=>{if(_c(x),j(H=>new Set(H).add(x)),ua.some(H=>H.item.line_id!==x)){Za(!0);return}p(),Za(!0)},Qw=()=>{j(x=>new Set([...x,...ua.map(H=>H.item.line_id)])),p()},Wd=()=>{J?.best&&(tm(J.item.line_id,J.best),r(Ei(J)),B?Hw(J.item.line_id):Za(!0))},em=Id.length>0?(0,s.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,s.jsxs)("div",{className:"results-tile-section__head",children:[(0,s.jsx)("h3",{children:"Require Matching"}),(0,s.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,s.jsx)("div",{className:"results-unmatched-list",children:Id.map(x=>{let{item:H,qty:ye}=x;return(0,s.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>qi(H.line_id),children:[(0,s.jsx)("span",{className:"results-unmatched-card__main",children:(0,s.jsx)("span",{className:"results-unmatched-card__title",children:Jr(H,w)})}),(0,s.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},H.line_id)})})]}):null,_c=x=>{u(H=>({...H,[x]:yd})),N(H=>({...H,[x]:void 0})),T(H=>({...H,[x]:void 0})),i(x)},xc=(x,H)=>{u(ye=>({...ye,[x]:H.product_id})),N(ye=>({...ye,[x]:H}))},tm=(x,H)=>{H.method==="catalogue_search"&&T(ye=>({...ye,[x]:H}))};function sx(){b("downloaded",{type:"schedule",lines:Y.length}),iw(Y.map(({item:x,best:H,qty:ye,band:ft,unmatchable:Ke,decision:Wt})=>({item:x,best:H,qty:ye,band:ft,unmatchable:Ke,decision:Wt})))}function Ei(x){let H=x.best??Ws(x.result)[0];return Pr(H,{lineId:x.item.line_id,description:x.item.description_original,unit:x.item.unit,qty:x.qty,linkedContext:x.item.linked_group_role==="dependent"&&x.item.linked_group_id?w.filter(ye=>ye.linked_group_id===x.item.linked_group_id&&ye.linked_group_role==="anchor").slice(0,1).map(ye=>{let ft=a[ye.line_id];return{line_id:ye.line_id,product_id:ft?.productId??null,measurements_mm:ft?.measurementsMm??ye.attrs.measurements_mm,description:ft?.description??ye.description_original,qty:ye.qty,unit:ye.unit,role:"anchor"}}):void 0})}(0,Ne.useEffect)(()=>{if(!o){for(let x of Y)!x.unmatchable&&x.best&&r(Ei(x));l()}},[o]),(0,Ne.useEffect)(()=>{for(let x of Y)!a[x.item.line_id]&&!x.unmatchable&&x.best&&r(Ei(x))},[e]),(0,Ne.useEffect)(()=>{if(!Se){pt([]),W(null),at(!1);return}let x=de.trim();if(!x){pt([]),W(null),at(!1);return}let H=!1,ye=window.setTimeout(async()=>{try{at(!0),W(null);let ft=await fetch(Ht(`/api/catalogue/search?q=${encodeURIComponent(x)}`),{headers:vi()}),Ke=await Pt(ft);if(!ft.ok)throw new Error(Ke?.error||Ke?.message||"Failed to search catalogue");H||pt(Array.isArray(Ke?.items)?Ke.items:[])}catch(ft){H||(pt([]),W(ft?.message||"Failed to search catalogue"))}finally{H||at(!1)}},250);return()=>{H=!0,window.clearTimeout(ye)}},[de,Se]);let kc=Object.keys(a).length,Ma=de.trim(),am=Ws(J?.result),pl=J?.decision?.technical_classification==="no_suitable_candidate"||!!J&&!J.best,rm=J?.decision?.technical_classification!=null,im=J?.decision?.reason??(pl?"No catalogue candidate found. Refine the request or search the catalogue.":null),Gw=Ye.map(x=>({product_id:x.product_id,description:x.description,source_list:x.source_list,price:x.price,price_basis:x.price_basis,uoi_count:x.uoi_count??null,uoi:x.uoi,pdp_photo_url:x.pdp_photo_url??null,conversion:x.conversion,measurements_mm:x.measurements_mm??[],scores:{dimension:0,grade:0,brand:0,fuzzy:0,bm25:0,overall:0},method:"catalogue_search"})),Vn=Ma?Gw:am,Mi=J?A[J.item.line_id]:void 0,$n=!Ma&&Mi&&!Vn.some(x=>x.product_id===Mi.product_id)?[...Vn,Mi]:Vn,nm=(()=>{let x=$n.slice(0,Ma?12:3);return Ma||!Mi||x.some(H=>H.product_id===Mi.product_id)?x:[...x,Mi]})(),dl=!!J?.best&&a[J.item.line_id]?.productId===J.best.product_id,Yw=!!J?.best&&!!a[J.item.line_id]&&!dl;return(0,s.jsxs)("div",{className:"wizard-step entry-stage",children:[(0,s.jsxs)("div",{className:`quick-order-card${d?"":" quick-order-card--customer"}`,children:[(0,s.jsx)("div",{className:`quick-order-hero${d?"":" quick-order-hero--customer"}`,children:d?(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:K==null?"Calculating\u2026":nt(K)})," 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 ",g?"View Quote":"View Basket"," to continue."]})]}),(0,s.jsxs)("button",{type:"button",className:"results-total-action",onClick:n,"aria-label":g?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:g?"View Quote":"View Basket"}),(0,s.jsx)("strong",{children:K==null?"Calculating\u2026":nt(K)})]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(jt,{})})]})]})}),(0,s.jsxs)("div",{className:"quick-order-panel",style:{paddingTop:16},children:[He&&(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:()=>ut(x=>!x),children:Ee?"Hide timings":"Show timings"})}),He&&Ee&&(0,s.jsx)(g_,{...D}),!g&&(0,s.jsx)("div",{className:"results-toolbar-row",children:!J&&(0,s.jsxs)("div",{className:"results-summary",style:{marginBottom:0},children:[pe>0&&(0,s.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,s.jsx)("strong",{children:pe})," need pricing"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:z,onChange:x=>G(x.target.value),"aria-label":"Search line items"}),!d&&(0,s.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,s.jsx)("button",{type:"button",className:`results-view-toggle__btn${ce==="tile"?" is-active":""}`,"aria-pressed":ce==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>fe("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${ce==="list"?" is-active":""}`,"aria-pressed":ce==="list","aria-label":"List view",title:"List view",onClick:()=>fe("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"})]})})]}),He&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>me(x=>x==="simple"?"detailed":"simple"),children:ze==="detailed"?"Hide detailed view":"Show detailed view"}),(0,s.jsxs)("details",{ref:Yn,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:l_.map(x=>{let H=P===x.dir;return(0,s.jsxs)("button",{type:"button",className:`sort-menu-item${H?" is-active":""}`,onClick:()=>{be(H?null:x.dir),Yn.current?.removeAttribute("open")},children:[(0,s.jsx)("span",{className:"sort-menu-item__check",children:H?"\u2713":""}),x.label]},x.dir)})})]})]})]})}),ce==="tile"||J?(0,s.jsxs)(s.Fragment,{children:[J?(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop",role:"dialog","aria-modal":"true","aria-label":"Product options",onClick:()=>Za(),children:(0,s.jsxs)("section",{className:"quick-order-workflow-modal results-review-modal",onClick:x=>x.stopPropagation(),children:[(0,s.jsx)("button",{type:"button",className:"quick-order-workflow-close results-review-modal__close",onClick:()=>Za(),"aria-label":"Close product options",children:(0,s.jsx)(Jo,{})}),(0,s.jsx)("div",{className:"results-review-page",children:d?(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:()=>Za(),children:[(0,s.jsx)(Kr,{}),"Back to results"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[He&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>me(x=>x==="simple"?"detailed":"simple"),children:ze==="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:de,onChange:x=>Je(x.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:()=>_c(J.item.line_id),children:"Clear selected product"})})]})]}),(0,s.jsxs)("div",{className:"results-review-page__hero",children:[(0,s.jsx)("div",{className:"results-review-page__image-wrap",children:(0,s.jsx)("img",{className:"fill-img results-review-page__image",src:Ya(Fe(J)?.description||J.item.description_original,Fe(J)?.product_id,Fe(J)?.pdp_photo_url),alt:""})}),(0,s.jsxs)("div",{className:"results-review-page__summary",children:[(0,s.jsx)("h2",{children:Jr(J.item,w)}),(0,s.jsxs)("p",{className:"results-review-page__meta",children:[yi(J.qty)," ",Na(J.item.unit,J.qty)]}),J.best?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:J.best.description}),J.best.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Tn(J.best.price,J.best.price_basis)}):null]}):Fe(J)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:Fe(J)?.description}),Fe(J)?.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:Tn(Fe(J)?.price??null,Fe(J)?.price_basis??null)}):null,(0,s.jsx)("div",{className:"results-row-meta",children:"Best reviewed alternative - not yet selected"})]}):(0,s.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line item."}),gr(J.item)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[(0,s.jsx)(wd,{meta:q.get(J.item.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:zn(J.item)})]}):null,(0,s.jsx)("div",{className:"results-review-page__actions",children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[J.item.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[J.item.line_id]?i(J.item.line_id):(J.best&&tm(J.item.line_id,J.best),r(Ei(J)))},disabled:!J.best,"aria-label":a[J.item.line_id]?d?"Remove from selection":`Remove from ${f}`:d?"Add to selection":`Add to ${f}`,children:a[J.item.line_id]?"\u2713 Added":d?"+ Add to selection":`Add to ${f}`})})]})]}),ot?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,!ot&&ge?(0,s.jsx)("div",{className:"results-empty-card",children:ge}):null,!ot&&!ge&&Ma&&Vn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No candidate products match this database search."}):!ot&&!ge?(0,s.jsx)(y_,{item:J.item,candidates:Vn,result:J.result,decision:J.decision,unmatchable:J.unmatchable,selectedProductId:J.best?.product_id??null,detailMode:ze,linkedGroupMeta:gr(J.item)?q.get(J.item.linked_group_id):void 0,onPick:x=>xc(J.item.line_id,x),onClear:()=>_c(J.item.line_id),showAll:d||He||Ma.length>0,internal:d,debugEnabled:He,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:Jr(J.item,w)||"Original request"})]}),im?(0,s.jsxs)("section",{className:"customer-review-ai",children:[(0,s.jsx)("strong",{children:pl?"Exact match not found:":"AI review:"})," ",im]}):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:pl?"We couldn't find a suitable product":rm?"Choose a product":"We couldn't review this item"}),(0,s.jsx)("p",{children:pl?am.length>0?"These AI-reviewed alternatives may be useful, but need approval.":"Search the catalogue to choose an alternative.":rm?`Select the option you want to add to your ${f}.`:"Search the catalogue to choose a product."})]})}),!Ma&&$n.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:nm.map(x=>{let H=x.product_id===J.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${H?" is-selected":""}`,onClick:()=>xc(J.item.line_id,x),"aria-pressed":H,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Ya(x.description,x.product_id,x.pdp_photo_url),alt:"",width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:x.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:x.price!=null?`\xA3${Tn(x.price,x.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:H?"Selected":"Choose"})]},x.product_id)})}):null,$n.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:de,onChange:x=>Je(x.target.value),"aria-label":"Search catalogue"})]}),Ma&&ot?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,Ma&&!ot&&ge?(0,s.jsx)("div",{className:"results-empty-card",children:ge}):null,Ma&&!ot&&!ge&&$n.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No products match this search."}):null,Ma&&!ot&&!ge&&$n.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:nm.map(x=>{let H=x.product_id===J.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${H?" is-selected":""}`,onClick:()=>xc(J.item.line_id,x),"aria-pressed":H,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Ya(x.description,x.product_id,x.pdp_photo_url),alt:"",width:64,height:64}),(0,s.jsx)("span",{className:"customer-review-option__copy",children:(0,s.jsx)("strong",{children:x.description})}),(0,s.jsx)("span",{className:"customer-review-option__price",children:x.price!=null?`\xA3${Tn(x.price,x.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:H?"Selected":"Choose"})]},x.product_id)})}):null]}),J.best?Yw?(0,s.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,s.jsx)("button",{type:"button",className:"cta-btn customer-review-add",onClick:()=>{Wd()},children:(0,s.jsx)("span",{children:"Update product"})}),(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-add",onClick:()=>i(J.item.line_id),children:(0,s.jsx)("span",{children:`Remove from ${f}`})})]}):(0,s.jsx)("button",{type:"button",className:`cta-btn customer-review-add${dl?" cta-btn-secondary":""}`,onClick:()=>{dl?i(J.item.line_id):Wd()},children:(0,s.jsx)("span",{children:dl?`Remove from ${f}`:`Add selected product to ${f}`})}):null,B?(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-skip",onClick:()=>jw(J.item.line_id),children:"Skip this item"}):null]})})]})}):null,(0,s.jsxs)("div",{className:"results-tile-layout",children:[pa.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No line items match the current search/filter."}):null,Gn.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:Gn.map(x=>{let{item:H,best:ye,qty:ft}=x,Ke=Fe(x),Wt=!ye&&ke(x);return(0,s.jsxs)("article",{className:"results-tile-card",children:[(0,s.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>qi(H.line_id),"aria-label":`Review match for ${Jr(H,w)||"item"}`,children:[(0,s.jsxs)("div",{className:"results-tile-card__media",children:[Wt||gr(H)?(0,s.jsxs)("div",{className:"results-tile-card__badges",children:[gr(H)?(0,s.jsx)(wd,{meta:q.get(H.linked_group_id)}):(0,s.jsx)("span",{}),Wt?(0,s.jsx)("span",{style:{padding:"6px 10px",borderRadius:999,background:"#fef3c7",color:"#92400e",fontSize:12,fontWeight:700,lineHeight:1},children:"Partially matched"}):null]}):null,(0,s.jsx)("img",{className:"fill-img results-tile-card__image",src:Ya(Ke?.description||H.description_original,Ke?.product_id,Ke?.pdp_photo_url),alt:""})]}),(0,s.jsxs)("div",{className:"results-tile-card__body",children:[Ke?(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:Ke.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:Ke?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-tile-card__match-label",children:Wt?"\u21B3 partially matched from":"\u21B3 matched from"}),(0,s.jsx)("div",{className:"results-tile-card__match-name",children:Jr(H,w)}),gr(H)?(0,s.jsx)("div",{className:"results-row-meta",children:zn(H)}):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:[d&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>qi(H.line_id),children:"Review"}),(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[H.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[H.line_id]?i(H.line_id):r(Ei(x))},disabled:!Ke,"aria-label":a[H.line_id]?d?"Remove from selection":`Remove from ${f}`:d?"Add to selection":`Add to ${f}`,children:a[H.line_id]?"\u2713 Added":d?"+ Add":`Add to ${f}`})]})]},H.line_id)})})}):null,em]})]}):(0,s.jsxs)(s.Fragment,{children:[E&&(0,s.jsx)("div",{className:"results-table__hover-overlay",style:E,"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"}}),ze==="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"}),ze==="simple"&&(0,s.jsx)("th",{style:{textAlign:"center"},children:d?"Selection":g?"Quote":"Basket"})]})}),(0,s.jsxs)("tbody",{children:[pa.length===0&&(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:ze==="simple"?4:3,className:"results-empty-hint",style:{padding:"16px 8px"},children:"No line items match the current search/filter."})}),Gn.map(x=>{let{item:H,result:ye,decision:ft,best:Ke}=x;return(0,s.jsxs)("tr",{className:"bom-row results-table__review-row",onClick:()=>qi(H.line_id),onMouseEnter:Wt=>{ee.current=Wt.currentTarget,Xn()},onMouseLeave:()=>{ee.current=null,O(null)},children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{className:"bom-component-name",children:Jr(H,w)}),gr(H)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,s.jsx)(wd,{meta:q.get(H.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:zn(H)})]}):null]}),(0,s.jsx)("td",{children:Ke?(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"results-match-cell-text",title:Ke.description,children:Ke.description}),ze==="detailed"&&ft?.technical_classification&&(0,s.jsxs)("div",{className:"results-row-meta",children:[u_(ft.technical_classification),ft.approval_required?" - approval required":""]})]}):(0,s.jsx)("span",{className:"results-empty-hint"})}),(0,s.jsx)("td",{style:{textAlign:"center"},children:Ke?.price!=null?Tn(Ke.price,Ke.price_basis):"-"}),ze==="simple"&&(0,s.jsx)("td",{style:{textAlign:"center"},children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[H.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,style:{width:84,justifyContent:"center"},onClick:Wt=>{Wt.stopPropagation(),a[H.line_id]?i(H.line_id):r(Ei(x))},"aria-label":a[H.line_id]?d?"Remove from selection":`Remove from ${f}`:d?"Add to selection":`Add to ${f}`,children:a[H.line_id]?"\u2713 Added":d?"+ Add":`Add to ${f}`})})]},H.line_id)})]})]})}),em]}),!J&&Qn>1&&(0,s.jsxs)("div",{className:"results-pagination",children:[(0,s.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(It-1)*rl+1,"\u2013",Math.min(It*rl,pa.length)," of ",pa.length]}),(0,s.jsxs)("div",{className:"results-pagination-controls",children:[(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Le(It-1),disabled:It===1,children:"Previous"}),(0,s.jsxs)("span",{className:"results-pagination-page",children:["Page ",It," of ",Qn]}),(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Le(It+1),disabled:It===Qn,children:"Next"})]})]}),(M.itemCount!=null||M.headingCount!=null||M.skippedCount!=null)&&(0,s.jsxs)("div",{className:"results-summary",style:{marginTop:16},children:[M.itemCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.itemCount})," items parsed"]}),M.headingCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.headingCount})," headings"]}),M.skippedCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.skippedCount})," rows skipped"]})]}),(0,s.jsxs)("div",{className:"disclaimer-box",children:[(0,s.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,s.jsx)("p",{className:"disclaimer-text",children:"These matches are generated automatically and should be reviewed before purchase."})]}),!J&&(0,s.jsxs)("div",{className:"btn-row results-actions",children:[(0,s.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:(kc>0,"0 1 30%"),gap:10,justifyContent:"center"},onClick:()=>R(!0),"aria-label":"Start over",children:[(0,s.jsx)(hd,{}),(0,s.jsx)("span",{children:"Start Over"})]}),kc>0&&(0,s.jsxs)("button",{className:"cta-btn",style:{flex:"0 1 70%"},onClick:n,"aria-label":d?"View selection":g?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[d?"View Selection":g?"View Quote":"View Basket"," (",kc,")"]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(jt,{})})]})]})]})]}),Bw&&(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:ua.map(x=>{let H=xe.has(x.item.line_id),ye=ke(x);return(0,s.jsx)("div",{className:`review-gate-item${H?" is-reviewed":""}`,children:(0,s.jsxs)("button",{type:"button",className:"review-gate-item__review",onClick:()=>{ae(!0),qi(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Jr(x.item,w)}),(0,s.jsx)("span",{children:x.decision?.reason||(ye?"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:H?"Choice made":"Choose a product"})]})},x.item.line_id)})}),(0,s.jsx)("button",{type:"button",className:"review-gate-skip",onClick:Qw,children:"Skip all"}),ul.length>0?(0,s.jsxs)("div",{className:"review-gate-skipped",children:[(0,s.jsx)("strong",{children:"Skipped"}),ul.map(x=>(0,s.jsxs)("button",{type:"button",className:"review-gate-item is-skipped",onClick:()=>{j(H=>{let ye=new Set(H);return ye.delete(x.item.line_id),ye}),ae(!0),qi(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Jr(x.item,w)}),(0,s.jsx)("span",{children:`Not added to your ${f}.`})]}),(0,s.jsx)("span",{className:"review-gate-item__action",children:"Choose a product"})]},x.item.line_id))]}):null]})}),k&&(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 ",g?"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:()=>R(!1),children:"Cancel"}),(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-danger",onClick:()=>{R(!1),t()},autoFocus:!0,children:"Start Over"})]})]})})]})}var _t=X(Xe());var C=X(ie()),__=.2,il=10,uw="Enter a valid email address so we can send your quote.",x_=(e,t)=>{let a=`${t.requestedAmount} ${ka(t.requestedUnit,t.requestedAmount)}`,r=`${t.requiredSellUnits} ${ka(t.sellUnit,t.requiredSellUnits??0)}`,i=e.unitConversions?.find(n=>n.requestUom===t.requestedUnit);return i&&i.quantityPerSaleUnit<1?`${a} requested \u2192 order ${r} (${Math.round(1/i.quantityPerSaleUnit)} ${ka(t.sellUnit,2)} per ${ka(t.requestedUnit,1)})`:e.coverageQty&&/^m per /i.test(e.coverageUom??"")?`${a} requested \u2192 order ${r} (${e.coverageQty} ${e.coverageUom})`:`${a} requested \u2192 order ${r}`},k_=e=>["box","pack"].includes(e.requestedUnit)?"Pack size needed to calculate the order quantity.":`This product is sold by ${ka(e.sellUnit,1)}.`;function N_(){return(0,C.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,C.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,C.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,C.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,C.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function nl(){return(0,C.jsx)("svg",{width:"8",height:"5",viewBox:"0 0 8 5",fill:"none",children:(0,C.jsx)("path",{d:"M1 4L4 1L7 4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function ol({cart:e,onUpdateQty:t,onUpdateSellUnits:a,onResolveConversions:r,onRemove:i,onBack:n,onStartNewQuote:o,onQuoteRequested:l,internal:c=!1}){let p=(0,_t.useId)(),d=!c&&Vs()==="QZA6-MRA4",g=Object.values(e),[f,h]=(0,_t.useState)(""),[w,M]=(0,_t.useState)(!1),[D,m]=(0,_t.useState)(!1),u=Sn(),[b,v]=(0,_t.useState)(""),[N,A]=(0,_t.useState)({}),[T,z]=(0,_t.useState)({}),[G,P]=(0,_t.useState)(1),[be,De]=(0,_t.useState)({}),[Le,He]=(0,_t.useState)(!1),[ze,me]=(0,_t.useState)("0"),ce=(0,_t.useRef)(new Set);(0,_t.useEffect)(()=>{if(!r)return;for(let O of Object.values(e))Dt(O).requiredSellUnits!=null&&ce.current.delete(O.lineId);let E=Object.values(e).filter(O=>O.productId!=="-"&&Dt(O).requiredSellUnits==null&&!ce.current.has(O.lineId));E.length!==0&&(E.forEach(O=>ce.current.add(O.lineId)),fetch(Ht("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({lines:E.map(O=>({line_id:O.lineId,product_id:O.productId,requested_description:O.requestedDescription??O.description,requested_qty:O.qty,requested_uom:O.unit||null,linked_context:O.linkedContext??[],selected_description:O.description,selected_uoi:O.uoi,selected_uoi_count:O.uoiCount,selected_conversion:{sales_uom_normalised:O.salesUomNormalised,conversion_type:O.conversionType,sales_unit_size:O.salesUnitSize,sales_unit_size_uom:O.salesUnitSizeUom,coverage_qty:O.coverageQty,coverage_uom:O.coverageUom}}))})}).then(O=>O.ok?Pt(O):null).then(O=>{let ee={};for(let xe of O?.data?.items??O?.items??[]){let we=xe?.conversion;if(!we||typeof xe?.line_id!="string")continue;let y=e[xe.line_id];ee[xe.line_id]={conversionType:we.conversion_type,requestUomsSupported:we.request_uoms_supported,salesUomNormalised:we.sales_uom_normalised,salesUnitSize:we.sales_unit_size,salesUnitSizeUom:we.sales_unit_size_uom,coverageQty:we.coverage_qty,coverageUom:we.coverage_uom,roundingRule:we.rounding_rule,conversionConfidence:we.conversion_confidence,conversionNotes:we.conversion_notes,...y?.qty===0&&Number.isFinite(we.suggested_order_qty)&&we.suggested_order_qty>0?{qty:we.suggested_order_qty,unit:we.suggested_order_uom||y.unit}:{}}}Object.keys(ee).length>0&&r(ee)}).catch(O=>console.error("Catalogue conversion resolution failed",O)))},[e,r]);function fe(E){A(O=>{let ee={...O};return delete ee[E],ee})}function Ee(E,O){let ee=parseFloat(O);!isNaN(ee)&&ee>=0&&t(E,Math.min(ee,1e5)),fe(E)}function ut(E,O,ee){t(E,Math.min(1e5,Math.max(0,O+ee))),fe(E)}function Se(E){z(O=>{let ee={...O};return delete ee[E],ee})}function Z(E,O){let ee=parseFloat(O);!isNaN(ee)&&ee>=0&&a(E,Math.min(ee,1e5)),Se(E)}function de(E,O,ee){a(E,Math.min(1e5,Math.max(0,O+ee))),Se(E)}async function Je(){let E=f.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(E)){v(uw);return}v(""),m(!0);try{let O=await fetch(Ht("/api/quote-requests"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({email:E,items:Ye.map(({item:ee,pricing:xe})=>{let we=xe.requiredSellUnits??xe.requestedAmount,y=xe.requiredSellUnits!=null?xe.sellUnit:xe.requestedUnit;return{product_id:ee.productId,description:ee.description,quantity:we,unit:ka(y,we),unit_price:xe.requiredSellUnits!=null?xe.unitPrice:null,line_total:xe.lineTotal}})})});if(!O.ok){let ee=await Pt(O);console.error("Quote request failed",O.status,ee?.message),v(O.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}u("quote_requested",{items:Ye.length,total:Math.round(at*100)/100}),M(!0),l?.(),window.scrollTo(0,0)}catch{v("Your request couldn't be sent. Check your connection and try again.")}finally{m(!1)}}let Ye=g.map(E=>({item:E,pricing:Dt(E,{wasteFactorEnabled:Le,wasteFactorOverride:Math.max(0,Number.parseFloat(ze)||0)/100})})),pt=Is(g,{wasteFactorEnabled:Le,wasteFactorOverride:Math.max(0,Number.parseFloat(ze)||0)/100}),ot=pt*__,at=pt+ot,ge=(0,_t.useRef)({items:Ye.length,total:Math.round(at*100)/100});(0,_t.useEffect)(()=>{u("basket_viewed",ge.current)},[u]);let W=Math.max(1,Math.ceil(Ye.length/il)),k=Math.min(G,W),R=Ye.slice((k-1)*il,k*il);return w?(0,C.jsx)("div",{className:"wizard-step entry-stage",children:(0,C.jsxs)("div",{className:"quote-request-sent",role:"status",children:[(0,C.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,C.jsx)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,C.jsx)("polyline",{points:"5 12.5 10 17.5 19 7"})})}),(0,C.jsx)("h1",{children:"Quote requested"}),(0,C.jsxs)("p",{children:["You're all done. We'll email your sharper price to ",(0,C.jsx)("strong",{children:f.trim()}),", usually within one working day."]}),(0,C.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,C.jsx)("span",{children:"Start a new quote"})}),(0,C.jsx)("p",{className:"quote-request-sent-note",children:"Nothing is charged until you approve the quote."})]})}):!c&&g.length===0?(0,C.jsx)("div",{className:"wizard-step entry-stage",children:(0,C.jsxs)("div",{className:"quote-request-sent",children:[(0,C.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,C.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,C.jsx)("path",{d:"M3 9h18l-2 11H5z"}),(0,C.jsx)("path",{d:"M8 9l4-6 4 6"})]})}),(0,C.jsx)("h1",{children:d?"Your quote request is empty":"Your basket is empty"}),(0,C.jsx)("p",{children:d?"Start again with your list to build your quote.":"Start again with your list to fill your basket."}),(0,C.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,C.jsx)("span",{children:"Back to start"})})]})}):(0,C.jsx)("div",{className:`wizard-step entry-stage${d?" basket-layout--qza6-mra4":""}`,children:(0,C.jsxs)("div",{className:`quick-order-card${c?"":" quick-order-card--customer"}`,children:[(0,C.jsxs)("div",{className:`quick-order-hero${c?"":" quick-order-hero--customer"}`,children:[c&&(0,C.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,C.jsxs)("div",{className:"basket-hero-copy",children:[d&&(0,C.jsxs)("button",{type:"button",className:"cta-btn cta-btn-secondary basket-hero-back",onClick:n,children:[(0,C.jsx)(Kr,{}),(0,C.jsx)("span",{children:"Back to results"})]}),(0,C.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,C.jsx)("h1",{children:c?"Your Selection":d?"Request a quote":"Your Basket"}),c&&(0,C.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,C.jsx)("strong",{children:g.length})," ",g.length===1?"item":"items"]})]}),(0,C.jsx)("p",{children:c?"Review the items you've added before exporting them for review.":d?"Check your items and quantities below, and we'll do our best to beat list prices.":"Review your quantities and order summary before you buy."})]})]}),(0,C.jsx)("div",{className:"quick-order-panel",style:{paddingTop:16},children:g.length===0?(0,C.jsxs)("div",{className:"quick-order-history-empty",children:[(0,C.jsx)("div",{className:"basket-empty-icon","aria-hidden":"true",children:"\u{1F4CB}"}),(0,C.jsx)("p",{children:"Your selection is empty."}),(0,C.jsx)("p",{className:"basket-empty-hint",children:"Go back to your results and add quoted items."}),(0,C.jsx)("div",{className:"btn-row",style:{marginTop:20,justifyContent:"center"},children:(0,C.jsx)("button",{className:"cta-btn",style:{width:"auto",maxWidth:280},onClick:n,"aria-label":"Back to results",children:(0,C.jsx)("span",{children:"Back to Results"})})})]}):(0,C.jsxs)(C.Fragment,{children:[(0,C.jsxs)("div",{className:"basket-layout",children:[(0,C.jsxs)("div",{className:"basket-main",children:[(0,C.jsx)("div",{className:"basket-list","aria-label":c?"Selection items":d?"Quote request items":"Basket items",children:R.map(({item:E,pricing:O})=>{let ee=N[E.lineId]??String(O.requestedAmount),xe=O.requestedUnit===O.sellUnit||O.costingMode==="review",we=O.requiredSellUnits==null||O.requestedAmount!==O.requiredSellUnits||O.requestedUnit!==O.sellUnit;return(0,C.jsxs)("article",{className:"basket-card",children:[(0,C.jsxs)("div",{className:"basket-card-top",children:[(0,C.jsx)("img",{className:"basket-card-thumb",src:Ya(E.description,E.productId,E.pdpPhotoUrl),alt:"",width:48,height:48}),(0,C.jsxs)("div",{className:"basket-card-info",children:[(0,C.jsx)("div",{className:"bom-component-name",children:E.description}),we&&O.costingMode!=="review"&&(0,C.jsxs)("button",{type:"button",className:"basket-calc-toggle",onClick:()=>De(y=>({...y,[E.lineId]:!y[E.lineId]})),"aria-expanded":!!be[E.lineId],children:["How we calculated this",(0,C.jsx)("span",{className:`basket-calc-toggle-chevron${be[E.lineId]?" basket-calc-toggle-chevron--open":""}`,children:(0,C.jsx)(nl,{})})]})]}),(0,C.jsx)("div",{className:"basket-card-actions",children:(0,C.jsx)("button",{type:"button",className:"mf-remove-small-btn basket-card-remove",onClick:()=>i(E.lineId),"aria-label":`Remove ${E.description}`,children:(0,C.jsx)(N_,{})})})]}),c&&(0,C.jsxs)("div",{className:"results-detail-block basket-internal-detail",children:[(0,C.jsxs)("dl",{className:"results-detail-grid",children:[(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Conversion type"}),(0,C.jsx)("dd",{children:E.conversionType??"-"})]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Conversion confidence"}),(0,C.jsx)("dd",{children:E.conversionConfidence??"-"})]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Sales unit"}),(0,C.jsx)("dd",{children:E.salesUnitSize!=null?(0,C.jsxs)(C.Fragment,{children:[E.salesUnitSize," ",Na(E.salesUnitSizeUom,E.salesUnitSize)]}):"-"})]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Coverage"}),(0,C.jsx)("dd",{children:E.coverageQty!=null?(0,C.jsxs)(C.Fragment,{children:[E.coverageQty," ",Na(E.coverageUom,E.coverageQty)]}):"-"})]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Waste factor"}),(0,C.jsx)("dd",{children:E.wasteFactorDefault??"-"})]}),(0,C.jsxs)("div",{children:[(0,C.jsx)("dt",{children:"Rounding rule"}),(0,C.jsx)("dd",{children:E.roundingRule??"-"})]})]}),E.conversionNotes&&(0,C.jsx)("p",{className:"results-rerank-note",children:E.conversionNotes})]}),O.costingMode==="review"?(0,C.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,C.jsx)("strong",{children:"Quantity needs confirmation."})," ",k_(O)]}):we&&be[E.lineId]?(0,C.jsx)("p",{className:"basket-calc-text",children:x_(E,O)}):null,(0,C.jsxs)("div",{className:"basket-card-stats",children:[(0,C.jsxs)("div",{className:"basket-stat",children:[(0,C.jsx)("span",{className:"basket-stat-label",children:"Requested qty"}),(0,C.jsxs)("div",{className:"basket-stat-value",children:[(0,C.jsxs)("div",{className:"basket-qty-field",children:[(0,C.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:ee,disabled:xe,onChange:y=>A(j=>({...j,[E.lineId]:y.target.value})),onBlur:y=>Ee(E.lineId,y.target.value),onKeyDown:y=>{y.key==="Enter"&&y.target.blur()},"aria-label":`${E.description} requested quantity`}),(0,C.jsxs)("div",{className:"basket-qty-arrows",children:[(0,C.jsx)("button",{type:"button",className:"basket-qty-arrow",disabled:xe,onClick:()=>ut(E.lineId,parseFloat(ee)||0,1),"aria-label":`Increase ${E.description} quantity`,children:(0,C.jsx)(nl,{})}),(0,C.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",disabled:xe,onClick:()=>ut(E.lineId,parseFloat(ee)||0,-1),"aria-label":`Decrease ${E.description} quantity`,children:(0,C.jsx)(nl,{})})]})]}),(0,C.jsx)("span",{className:"basket-metric-unit",children:Na(O.requestedUnit,parseFloat(ee)||0)})]})]}),(0,C.jsxs)("div",{className:"basket-stat basket-stat--right",children:[(0,C.jsx)("span",{className:"basket-stat-label",children:"Order qty"}),(0,C.jsxs)("div",{className:"basket-stat-value",children:[(0,C.jsxs)("div",{className:"basket-qty-field",children:[(0,C.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:T[E.lineId]??String(O.requiredSellUnits??""),onChange:y=>z(j=>({...j,[E.lineId]:y.target.value})),onBlur:y=>Z(E.lineId,y.target.value),onKeyDown:y=>{y.key==="Enter"&&y.target.blur()},"aria-label":`${E.description} order quantity`}),(0,C.jsxs)("div",{className:"basket-qty-arrows",children:[(0,C.jsx)("button",{type:"button",className:"basket-qty-arrow",onClick:()=>de(E.lineId,parseFloat(T[E.lineId]??String(O.requiredSellUnits??"0"))||0,1),"aria-label":`Increase ${E.description} order quantity`,children:(0,C.jsx)(nl,{})}),(0,C.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",onClick:()=>de(E.lineId,parseFloat(T[E.lineId]??String(O.requiredSellUnits??"0"))||0,-1),"aria-label":`Decrease ${E.description} order quantity`,children:(0,C.jsx)(nl,{})})]})]}),(0,C.jsx)("span",{className:"basket-metric-unit",children:Na(O.sellUnit,parseFloat(T[E.lineId]??String(O.requiredSellUnits??"0"))||0)})]})]}),(0,C.jsxs)("div",{className:"basket-stat basket-stat--total",children:[(0,C.jsx)("span",{className:"basket-stat-label",children:"Total"}),(0,C.jsxs)("div",{className:"basket-stat-value",children:[(0,C.jsx)("strong",{children:O.lineTotal!=null?nt(O.lineTotal):"-"}),O.lineTotal!=null&&(0,C.jsx)("span",{className:"basket-metric-unit",children:"ex. VAT"})]})]})]})]},E.lineId)})}),W>1&&(0,C.jsxs)("div",{className:"results-pagination",children:[(0,C.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(k-1)*il+1,"\u2013",Math.min(k*il,Ye.length)," of ",Ye.length]}),(0,C.jsxs)("div",{className:"results-pagination-controls",children:[(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>P(k-1),disabled:k===1,children:"Previous"}),(0,C.jsxs)("span",{className:"results-pagination-page",children:["Page ",k," of ",W]}),(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>P(k+1),disabled:k===W,children:"Next"})]})]})]}),(0,C.jsxs)("aside",{className:"basket-sidebar",children:[(0,C.jsx)("div",{className:"basket-sidebar-title",children:d?"Quote request summary":"Order summary"}),(0,C.jsxs)("div",{className:"basket-sidebar-row",children:[(0,C.jsx)("span",{children:d?"List price (ex. VAT)":"Subtotal (ex. VAT)"}),(0,C.jsx)("span",{children:nt(pt)})]}),(0,C.jsxs)("div",{className:"basket-sidebar-row",children:[(0,C.jsx)("span",{children:"VAT (20%)"}),(0,C.jsx)("span",{children:nt(ot)})]}),(0,C.jsxs)("div",{className:"basket-sidebar-row basket-sidebar-row--total",children:[(0,C.jsx)("span",{children:d?"List price (inc.\xA0VAT)":"Total"}),(0,C.jsx)("span",{children:nt(at)})]}),!d&&(0,C.jsx)("div",{className:"basket-summary-waste",children:(0,C.jsxs)("div",{className:"basket-waste-control",children:[(0,C.jsxs)("label",{className:"basket-global-waste",children:[(0,C.jsx)("input",{type:"checkbox",checked:Le,onChange:E=>He(E.target.checked)}),(0,C.jsx)("span",{children:"Add waste factor"})]}),(0,C.jsxs)("label",{className:"basket-global-waste-percent",children:[(0,C.jsx)("input",{type:"number",inputMode:"decimal",min:"0",step:"0.1",value:ze,onChange:E=>me(E.target.value),disabled:!Le,"aria-label":"Waste factor percent"}),(0,C.jsx)("span",{children:"%"})]})]})}),(0,C.jsx)("label",{htmlFor:`${p}-basket-reference`,className:"basket-sidebar-label",children:d?"Enter email for your sharper quote":"Your reference (optional)"}),(0,C.jsx)("input",{id:`${p}-basket-reference`,type:d?"email":"text",className:"basket-sidebar-input",value:f,onChange:E=>{h(E.target.value),d&&v("")},placeholder:d?"you@example.com":"PO number or job reference","aria-invalid":d&&b===uw,"aria-describedby":d&&b?`${p}-basket-reference-error`:void 0}),d&&b&&(0,C.jsx)("p",{id:`${p}-basket-reference-error`,className:"basket-quote-request-error",role:"alert",children:b}),d?(0,C.jsx)("button",{type:"button",className:"cta-btn",onClick:()=>{Je()},disabled:D,"aria-busy":D,children:(0,C.jsx)("span",{children:D?"Sending\u2026":"Request our best quote"})}):(0,C.jsx)("button",{className:"cta-btn",onClick:()=>{u("downloaded",{type:"basket",items:g.length}),nw(g)},"aria-label":c?"Download selection":"Download basket",children:(0,C.jsx)("span",{children:c?"Download Quote":"Buy Now"})}),(0,C.jsxs)("p",{className:"basket-sidebar-disclaimer",children:[(0,C.jsx)("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),d?"This is a quote request, not an order. We'll confirm our best price, availability and delivery before you approve.":"Prices and availability are estimates and should be confirmed before procurement."]})]})]}),(0,C.jsx)("div",{className:"btn-row results-actions",children:(0,C.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",gap:10,justifyContent:"center"},onClick:n,"aria-label":"Back to results",children:[(0,C.jsx)(Kr,{}),(0,C.jsx)("span",{children:"Back to results"})]})})]})})]})})}var At=X(Xe()),pw=X(ie());function S_(e,t){let a={...e,[t.lineId]:t};for(let[r,i]of Object.entries(a)){if(!i.linkedContext)continue;let n=i.linkedContext.find(l=>l.role==="anchor"&&l.line_id&&a[l.line_id]),o=n?.line_id?a[n.line_id]:void 0;if(!(!n||!o||n.product_id===o.productId&&n.description===o.description)){if(i.conversionType!=="basket_line_unit"){a[r]={...i,linkedContext:i.linkedContext.map(l=>l.line_id===n.line_id?{...l,product_id:o.productId,measurements_mm:o.measurementsMm??[],description:o.description}:l)};continue}a[r]={...i,qty:0,sellUnitsOverride:null,linkedContext:i.linkedContext.map(l=>l.line_id===n.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 Nd=(0,At.createContext)(null);function tc({children:e,onOpenBasket:t}){let[a,r]=(0,At.useState)({}),i=(0,At.useCallback)(f=>{r(h=>S_(h,f))},[]),n=(0,At.useCallback)(f=>{r(h=>{let w={...h};for(let M of f)w[M.lineId]=M;return w})},[]),o=(0,At.useCallback)(f=>{r(h=>{let w={...h};return delete w[f],w})},[]),l=(0,At.useCallback)((f,h)=>{r(w=>w[f]?{...w,[f]:{...w[f],qty:h,sellUnitsOverride:null}}:w)},[]),c=(0,At.useCallback)((f,h)=>{r(w=>w[f]?{...w,[f]:{...w[f],sellUnitsOverride:h}}:w)},[]),p=(0,At.useCallback)(f=>{r(h=>{let w=!1,M={...h};for(let[D,m]of Object.entries(f))M[D]&&(M[D]={...M[D],...m},w=!0);return w?M:h})},[]),d=(0,At.useCallback)(()=>r({}),[]),g=(0,At.useMemo)(()=>({cart:a,count:Object.keys(a).length,addToCart:i,addManyToCart:n,removeFromCart:o,updateCartQty:l,updateCartSellUnits:c,updateCartConversions:p,clearCart:d,openBasket:t??(()=>{})}),[a,i,n,o,l,c,p,d,t]);return(0,pw.jsx)(Nd.Provider,{value:g,children:e})}function An(){let e=(0,At.useContext)(Nd);if(!e)throw new Error("useCart must be used inside a <CartProvider>");return e}function ac(){return(0,At.useContext)(Nd)}var Sa=X(ie()),Sd="metron-quick-quote";function rc(e){return(0,Sa.jsx)(tc,{children:(0,Sa.jsx)(C_,{...e})})}function C_({fullPage:e=!1,hideHeader:t=!1,internal:a=!1}){let[r,i]=(0,Re.useState)("entry"),[n,o]=(0,Re.useState)(null),[l,c]=(0,Re.useState)(""),p=(0,Re.useRef)(null),d=(0,Re.useRef)(0),[g,f]=(0,Re.useState)(0),[h,w]=(0,Re.useState)(null),[M,D]=(0,Re.useState)(!1),{cart:m,addToCart:u,addManyToCart:b,removeFromCart:v,updateCartQty:N,updateCartSellUnits:A,updateCartConversions:T,clearCart:z}=An(),[G,P]=(0,Re.useState)(!1),[be,De]=(0,Re.useState)(null),Le=()=>{De(null);try{window.sessionStorage.removeItem(Fs)}catch{}},He=(0,Re.useRef)(new Map),ze=(0,Re.useRef)(null),me=Xs("quick-quote",ze);(0,Re.useEffect)(()=>{me("viewed")},[me]),(0,Re.useEffect)(()=>{for(let W of Object.values(m))Dt(W).requiredSellUnits!=null&&He.current.delete(W.lineId);let ge=Object.values(m).filter(W=>{if(W.productId==="-"||Dt(W).requiredSellUnits!=null)return!1;let k=`${W.productId}|${W.qty}|${W.unit}`;return He.current.get(W.lineId)===k?!1:(He.current.set(W.lineId,k),!0)});ge.length!==0&&fetch(Ht("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Ga()},body:JSON.stringify({lines:ge.map(W=>({line_id:W.lineId,product_id:W.productId,requested_description:W.requestedDescription??W.description,requested_qty:W.qty,requested_uom:W.unit||null,selected_description:W.description,selected_uoi:W.uoi,selected_uoi_count:W.uoiCount,linked_context:W.linkedContext??[],selected_conversion:{sales_uom_normalised:W.salesUomNormalised,conversion_type:W.conversionType,sales_unit_size:W.salesUnitSize,sales_unit_size_uom:W.salesUnitSizeUom,coverage_qty:W.coverageQty,coverage_uom:W.coverageUom}}))})}).then(W=>W.ok?Pt(W):null).then(W=>{let k={};for(let R of W?.data?.items??W?.items??[]){let E=R?.conversion;if(!E||typeof R?.line_id!="string")continue;let O=m[R.line_id];k[R.line_id]={conversionType:E.conversion_type,requestUomsSupported:E.request_uoms_supported,salesUomNormalised:E.sales_uom_normalised,salesUnitSize:E.sales_unit_size,salesUnitSizeUom:E.sales_unit_size_uom,coverageQty:E.coverage_qty,coverageUom:E.coverage_uom,roundingRule:E.rounding_rule,conversionConfidence:E.conversion_confidence,conversionNotes:E.conversion_notes,...O?.qty===0&&Number.isFinite(E.suggested_order_qty)&&E.suggested_order_qty>0?{qty:E.suggested_order_qty,unit:E.suggested_order_uom||O.unit}:{}}}Object.keys(k).length>0&&T(k)}).catch(W=>console.error("Catalogue conversion resolution failed",W))},[m,T]);let[ce,fe]=(0,Re.useState)(!1);(0,Re.useEffect)(()=>{let ge=window.location.hash,W=null;try{W=JSON.parse(window.sessionStorage.getItem(Sd)??"null")}catch{}if(W?.scheduleResult)o("schedule"),w(W.scheduleResult),D(W.reviewGateComplete),P(W.cartSeeded),b(Object.values(W.cart)),ge==="#quote-request"?i("basket"):ge==="#matched-products"&&i("results");else if(ge==="#matched-products"||ge==="#quote-request"){let k=new URL(window.location.href);k.hash="",window.history.replaceState(window.history.state,"",k)}fe(!0)},[]),(0,Re.useEffect)(()=>{if(ce)try{h?window.sessionStorage.setItem(Sd,JSON.stringify({scheduleResult:h,reviewGateComplete:M,cartSeeded:G,cart:m})):window.sessionStorage.removeItem(Sd)}catch{}},[ce,h,M,G,m]);let Ee=(0,Re.useCallback)(ge=>{if(typeof window>"u")return;let W=new URL(window.location.href);W.hash=ge==="basket"?"quote-request":"matched-products";let k=ge==="results"&&(window.location.hash==="#matched-products"||window.location.hash==="#quote-request");window.history[k?"replaceState":"pushState"]({boqQuoteStage:ge},"",W)},[]),ut=(0,Re.useRef)(!1);(0,Re.useEffect)(()=>{let ge=W=>{ut.current=!1;let k=window.location.hash;k==="#quote-request"?i("basket"):k==="#matched-products"&&h?(o("schedule"),i("results")):i("entry");let R=W.state,E=window.location.href;setTimeout(()=>{if(window.location.href===E){if(k==="#quote-request"||k==="#matched-products"||k==="#quote-entry"){window.history.replaceState({boqQuoteStage:k==="#quote-request"?"basket":k==="#quote-entry"?"entry":"results"},"",E);return}!R?.turbo&&window.history.state?.turbo&&window.history.replaceState(R,"",E)}})};return window.addEventListener("popstate",ge),()=>window.removeEventListener("popstate",ge)},[h]);let Se=(0,Re.useCallback)(()=>{Ee("basket"),i("basket")},[Ee]),Z=(0,Re.useCallback)(()=>{if(window.location.hash==="#quote-request"){if(ut.current)return;ut.current=!0,window.history.back();return}i(h?"results":"entry")},[h]),de=(0,Re.useRef)(r);(0,Re.useEffect)(()=>{de.current!==r&&(de.current=r,window.scrollTo(0,0))},[r]);let Je=()=>{i("entry"),o(null),c(""),f(0),w(null),D(!1),z(),P(!1),Le()},Ye=(0,Re.useCallback)(async(ge,W,k=!0)=>{let R=++d.current;c(""),f(0);let E=0,O=()=>{E=Math.min(E+1,3),f(E)};try{let{jobId:ee}=await nv(ge,W,k);if(R!==d.current)return;let{promise:xe,cancel:we}=lv(()=>ov(ee),5e3,O,"schedule");p.current=we;let y=await xe;if(y.status==="failed"||!y.result)throw new Error(y.error||"Failed to process schedule");let j=y.result.lineItems.length,B=y.result.results.filter(ae=>ae.candidates.length>0).length;me("results_shown",{lines:j,matched:B,unmatched:j-B}),z(),P(!1),D(!1),w(y.result),Ee("results"),i("results")}catch(ee){if(R!==d.current)return;me("error",{stage:"matching"}),c(ee?.message||"Failed to process schedule"),i("entry")}finally{R===d.current&&(p.current?.(),p.current=null)}},[Ee,me,z]),pt=(0,Re.useCallback)(()=>{d.current++,p.current?.(),p.current=null},[]),ot=(0,Re.useCallback)(async(ge,W,k=!0)=>{if(!ge.trim())return;o("schedule");let R=new File([ge],"pasted-schedule.txt",{type:"text/plain"});await Ye(R,W,k)},[Ye]),at=(0,Re.useCallback)(async ge=>{o("schedule"),await Ye(ge)},[Ye]);return(0,Sa.jsx)(Po.Provider,{value:me,children:(0,Sa.jsx)("div",{ref:ze,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${!e&&r==="processing"?" app-wrapper--loading":""}`,style:Ra().theme,children:(0,Sa.jsxs)("main",{className:"main-content",children:[l&&(0,Sa.jsxs)("div",{className:"error-box",role:"alert",children:[(0,Sa.jsx)("strong",{children:"Error:"})," ",l]}),r==="entry"&&(0,Sa.jsx)(fd,{onPasteSchedule:ot,onUploadSchedule:at,onEntryModeChange:o,draft:be,onSubmitDraft:De,onCancelMatch:pt}),r==="results"&&n==="schedule"&&h&&(0,Sa.jsx)(xd,{scheduleResult:h,onStartOver:Je,cart:m,onAddToCart:u,onRemoveFromCart:v,onGoToBasket:Se,cartSeeded:G,onCartSeeded:()=>P(!0),reviewGateComplete:M,onReviewGateComplete:()=>D(!0),internal:a}),r==="basket"&&(0,Sa.jsx)(ol,{cart:m,onUpdateQty:N,onUpdateSellUnits:A,onRemove:v,onBack:Z,onStartNewQuote:Je,onQuoteRequested:()=>{w(null),D(!1),P(!1),z(),Le()},internal:a})]})})})}var Va=X(Xe());var xi=X(Xe()),re=X(ie()),dw=[{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"}],ic=e=>Number.parseFloat(e)||0,mw=(e,t)=>ic(e)*(t==="m"?1:.3048),Cd=(e,t)=>ic(e.quantity)*(2*mw(e.height,t)+mw(e.width,t)),q_=()=>({quantity:"1",width:"",height:""});function E_({profile:e}){return(0,re.jsxs)("svg",{className:"architrave-calculator__profile-diagram",viewBox:"0 0 112 76","aria-hidden":"true",children:[(0,re.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,re.jsx)("line",{x1:"12",y1:"66",x2:"100",y2:"66"})]})}function qd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,xi.useState)("m"),[n,o]=(0,xi.useState)({quantity:"1",width:"0.76",height:"1.98"}),[l,c]=(0,xi.useState)({quantity:"0",width:"1.52",height:"1.98"}),[p,d]=(0,xi.useState)([]),[g,f]=(0,xi.useState)("ogee"),[h,w]=(0,xi.useState)("2.4"),M=(N,A,T)=>{N(z=>({...z,[A]:T}))},D=Cd(n,r)+Cd(l,r)+p.reduce((N,A)=>N+Cd(A,r),0),m=ic(h)>0?Math.ceil(D/ic(h)):0,u=dw.find(N=>N.id===g)?.label??"",b=[{key:`architrave-${g}`,label:`Architrave (${u})`,qty:D,unit:"m",query:`${u} architrave`,category:"architrave"}],v=(N,A,T,z)=>(0,re.jsxs)("div",{className:"architrave-calculator__opening-row",children:[(0,re.jsx)("span",{children:N}),(0,re.jsx)("input",{"aria-label":`${N} quantity`,type:"number",min:"0",step:"1",value:A.quantity,onChange:G=>T("quantity",G.target.value)}),(0,re.jsx)("input",{"aria-label":`${N} width`,type:"number",min:"0",step:"0.01",value:A.width,onChange:G=>T("width",G.target.value)}),(0,re.jsx)("input",{"aria-label":`${N} height`,type:"number",min:"0",step:"0.01",value:A.height,onChange:G=>T("height",G.target.value)}),z?(0,re.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:z,children:"Remove"}):null]});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:"Architrave Calculator"}),(0,re.jsx)("p",{children:"Estimate architrave lengths and board quantities for door openings."})]}),(0,re.jsxs)("div",{className:"truss-estimator__card architrave-calculator",children:[(0,re.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure your openings"}),(0,re.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,re.jsxs)("div",{className:"architrave-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Door openings"}),(0,re.jsx)("p",{className:"architrave-calculator__hint",children:"Each opening is calculated as two side pieces plus one head piece."}),(0,re.jsxs)("div",{className:"architrave-calculator__unit-row",children:[(0,re.jsx)("span",{children:"Units"}),(0,re.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,re.jsx)("button",{type:"button",className:r==="m"?"is-selected":"",onClick:()=>i("m"),children:"Metres"}),(0,re.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>i("ft"),children:"Feet"})]})]}),(0,re.jsxs)("div",{className:"architrave-calculator__dimensions-header",children:[(0,re.jsx)("span",{children:"Opening"}),(0,re.jsx)("span",{children:"Qty"}),(0,re.jsxs)("span",{children:["Width (",r,")"]}),(0,re.jsxs)("span",{children:["Height (",r,")"]}),(0,re.jsx)("span",{})]}),v("Single doors",n,(N,A)=>M(o,N,A)),v("Double doors",l,(N,A)=>M(c,N,A)),p.map((N,A)=>v(`Alternative door ${A+1}`,N,(T,z)=>d(G=>G.map((P,be)=>be===A?{...P,[T]:z}:P)),()=>d(T=>T.filter((z,G)=>G!==A)))),(0,re.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>d(N=>[...N,q_()]),children:"+ Add alternative-sized door"})]}),(0,re.jsxs)("div",{className:"architrave-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Standard profile"}),(0,re.jsx)("p",{className:"architrave-calculator__hint",children:"Choose the profile you plan to use. Length calculations are the same for each profile."}),(0,re.jsx)("div",{className:"architrave-calculator__profiles",children:dw.map(N=>(0,re.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g===N.id?" is-selected":""}`,onClick:()=>f(N.id),children:[(0,re.jsx)(E_,{profile:N.id}),(0,re.jsx)("div",{className:"truss-estimator__option-title",children:N.label}),(0,re.jsx)("div",{className:"truss-estimator__option-copy",children:N.blurb})]},N.id))})]}),(0,re.jsxs)("div",{className:"architrave-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,re.jsx)("div",{className:"architrave-calculator__options",children:(0,re.jsxs)("label",{className:"truss-estimator__field",children:[(0,re.jsx)("span",{children:"Board length (m)"}),(0,re.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,re.jsx)("p",{className:"architrave-calculator__hint",children:"Waste allows for mitred corners, cuts and damaged lengths."})]}),(0,re.jsxs)("div",{className:"architrave-calculator__totals",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,re.jsxs)("div",{className:"architrave-calculator__result-grid",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Architrave needed"}),(0,re.jsxs)("strong",{children:[D.toFixed(2)," m"]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Board lengths"}),(0,re.jsx)("strong",{children:m})]})]})]}),(0,re.jsxs)("div",{className:"architrave-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?.(b),disabled:D<=0,children:a})]})]})]})})}var ki=X(Xe()),se=X(ie()),fw=60,gw=10,M_=.02,T_=.012,z_=.01,Rn=e=>Number.parseFloat(e)||0,A_=(e,t=2)=>e.toFixed(t);function Ed({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,ki.useState)("brick"),[n,o]=(0,ki.useState)("engineering-red"),[l,c]=(0,ki.useState)("metric"),[p,d]=(0,ki.useState)(""),[g,f]=(0,ki.useState)(""),[h,w]=(0,ki.useState)(!0),M=l==="metric"?Rn(p)*Rn(g):Rn(p)*Rn(g)*.092903,m=M*(r==="brick"?fw:gw),u=Math.ceil(m),b=M*(r==="brick"?M_:T_),v=Math.ceil(b/z_),N=l==="metric"?M:M*10.7639,A=[{key:r==="brick"?`brick-${n}`:"block",label:r==="brick"?{common:"Common concrete bricks","engineering-red":"Red engineering bricks","engineering-blue":"Blue engineering bricks"}[n]:"Blocks",qty:u,unit:"each",query:r==="brick"?"facing brick":"concrete block",category:"masonry"},...h?[{key:"mortar",label:"Blue Circle Quality Assured Mortar Mix 20kg",qty:v,unit:"bag",query:"ready mixed mortar",category:"mortar"}]:[]],T=z=>{if(z===l)return;let G=z==="imperial"?3.28084:.3048;d((Rn(p)*G).toFixed(2)),f((Rn(g)*G).toFixed(2)),c(z)};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:"Brick and Block Calculator"}),(0,se.jsx)("p",{children:"Estimate masonry units, sand and cement for a wall."})]}),(0,se.jsxs)("div",{className:"truss-estimator__card brick-calculator",children:[(0,se.jsx)("h2",{className:"truss-estimator__step-title",children:"Wall area and masonry type"}),(0,se.jsx)("p",{className:"truss-estimator__step-sub",children:"Pick brick or block and enter the wall dimensions for unit counts plus ready-mixed mortar."}),(0,se.jsxs)("div",{className:"brick-calculator__section",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Masonry type"}),(0,se.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["brick","Brick"],["block","Block"]].map(([z,G])=>(0,se.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===z?" is-selected":""}`,onClick:()=>i(z),children:[(0,se.jsx)("div",{className:"truss-estimator__option-title",children:G}),(0,se.jsxs)("div",{className:"truss-estimator__option-copy",children:["Approx. ",z==="brick"?fw:gw," per m\xB2"]})]},z))})]}),r==="brick"&&(0,se.jsxs)("div",{className:"brick-calculator__section",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Brick type"}),(0,se.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:[["common","Common concrete","General-purpose grey concrete brick"],["engineering-red","Engineering red","Class B perforated, 65mm"],["engineering-blue","Engineering blue","Class B solid, 65mm"]].map(([z,G,P])=>(0,se.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n===z?" is-selected":""}`,onClick:()=>o(z),children:[(0,se.jsx)("div",{className:"truss-estimator__option-title",children:G}),(0,se.jsx)("div",{className:"truss-estimator__option-copy",children:P})]},z))})]}),(0,se.jsxs)("div",{className:"brick-calculator__section",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,se.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,se.jsx)("button",{type:"button",className:l==="metric"?"is-selected":"",onClick:()=>T("metric"),children:"Metric"}),(0,se.jsx)("button",{type:"button",className:l==="imperial"?"is-selected":"",onClick:()=>T("imperial"),children:"Imperial"})]}),(0,se.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsxs)("span",{children:["Height (",l==="metric"?"m":"ft",")"]}),(0,se.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:z=>d(z.target.value)})]}),(0,se.jsxs)("label",{className:"truss-estimator__field",children:[(0,se.jsxs)("span",{children:["Width (",l==="metric"?"m":"ft",")"]}),(0,se.jsx)("input",{type:"number",min:"0",step:"0.01",value:g,onChange:z=>f(z.target.value)})]})]})]}),(0,se.jsx)("div",{className:"brick-calculator__options",children:(0,se.jsxs)("label",{className:"brick-calculator__checkbox",children:[(0,se.jsx)("input",{type:"checkbox",checked:h,onChange:z=>w(z.target.checked)}),(0,se.jsx)("span",{children:"Include ready-mixed mortar"})]})}),(0,se.jsxs)("div",{className:"brick-calculator__totals",children:[(0,se.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,se.jsxs)("div",{className:"brick-calculator__result-grid",children:[(0,se.jsxs)("div",{children:[(0,se.jsx)("span",{children:"Wall area"}),(0,se.jsxs)("strong",{children:[A_(N)," ",l==="metric"?"m\xB2":"ft\xB2"]})]}),(0,se.jsxs)("div",{children:[(0,se.jsx)("span",{children:r==="brick"?"Bricks":"Blocks"}),(0,se.jsx)("strong",{children:u.toLocaleString("en-GB")})]}),h?(0,se.jsxs)("div",{children:[(0,se.jsx)("span",{children:"Ready-mixed mortar"}),(0,se.jsxs)("strong",{children:[v," x 20kg bags"]})]}):null]}),(0,se.jsx)("p",{className:"brick-calculator__note",children:"Estimate based on standard nominal sizes and 10mm joints. Mortar bags are approximate; confirm the required mortar specification before ordering."})]}),(0,se.jsxs)("div",{className:"brick-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?.(A),disabled:M<=0,children:a})]})]})]})})}var hr=X(Xe());var hw=new Map;function R_(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 Fr(e,t,a=12,r){let i=`${e}||${t??""}||${a}||${r??""}`,n=hw.get(i);if(n)return n;let o=new URLSearchParams({q:e,limit:String(a)});t&&o.set("category",t),r&&o.set("account",r);let l=await fetch(Ht(`/api/catalogue/search?${o.toString()}`),{headers:vi()}),c=await Pt(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(R_):[];return hw.set(i,p),p}async function bw(e,t){return await Promise.all(e.map(async r=>{try{return{requirement:r,candidates:await Fr(r.query,r.category,void 0,t)}}catch{return{requirement:r,candidates:[]}}}))}async function vw(){let e=await fetch(Ht("/api/catalogue"),{headers:vi()});if(!e.ok)return{itemCount:0,uploadedAt:null};let t=await Pt(e);return{itemCount:Number(t?.itemCount)||0,uploadedAt:t?.uploadedAt??null}}var V=X(ie()),U_=1.54,D_=1440,O_=25,Md=800,B_=1500,Td=e=>Number.parseFloat(e)||0,Un={mot:{label:"MOT Type 1",blurb:"Sub-base for patios and driveways",density:1.7,productId:"6001007"},"sharp-sand":{label:"Sharp sand",blurb:"Bedding and general groundwork",density:1.6,productId:"6001012"},gravel:{label:"20mm gravel",blurb:"Drainage and landscaping",density:1.6,productId:"6001004"}};function zd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let r=ac(),[i,n]=(0,hr.useState)("m"),[o,l]=(0,hr.useState)(""),[c,p]=(0,hr.useState)(""),[d,g]=(0,hr.useState)(""),[f,h]=(0,hr.useState)("concrete"),[w,M]=(0,hr.useState)("mot"),[D,m]=(0,hr.useState)(!1),[u,b]=(0,hr.useState)(null),v=i==="m"?1:.3048,N=Td(o)*v*Td(c)*v*Td(d)*(i==="m"?.01:.0254),A=Un[w],T=N*U_/7,z=T*D_,G=T*2,P=T*4,be=Math.ceil(z/O_),De=Math.ceil(G*Un["sharp-sand"].density*1e3/Md),Le=Math.ceil(P*Un.gravel.density*1e3/Md),He=Math.ceil(N*A.density*1e3/Md),ze=f==="concrete"?[{key:"cement",label:"Blue Circle General Purpose Grey Cement 25kg",qty:be,productId:"6003004"},{key:"sharp-sand",label:"Sharp Sand Bulk Bag (800kg)",qty:De,productId:"6001012"},{key:"gravel",label:"20mm Non Decorative Pea Shingle/Gravel Bulk Bag (800kg)",qty:Le,productId:"6001004"}]:[{key:w,label:`${A.label} Bulk Bag (800kg)`,qty:He,productId:A.productId}],me=()=>{if(t){t(ze.map(fe=>({key:fe.key,label:fe.label,qty:fe.qty,unit:"each",query:fe.productId})));return}ce()},ce=async()=>{let fe=Date.now();m(!0),b(null);try{let Ee=await Promise.all(ze.map(async Se=>{let Z=(await Fr(Se.productId)).find(de=>de.product_id===Se.productId);if(!Z)throw new Error(`${Se.label} is no longer available in this catalogue.`);return Pr(Z,{lineId:`concrete-aggregate:${Se.key}`,description:Se.label,unit:"bag",qty:Se.qty})})),ut=B_-(Date.now()-fe);ut>0&&await new Promise(Se=>window.setTimeout(Se,ut)),r?.clearCart(),r?.addManyToCart(Ee),r?.openBasket()}catch(Ee){b(Ee instanceof Error?Ee.message:"Could not add the products to your basket.")}finally{m(!1)}};return D?(0,V.jsx)(V.Fragment,{children:(0,V.jsxs)("div",{className:"truss-estimator",children:[(0,V.jsxs)("div",{className:"quick-order-hero",children:[(0,V.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,V.jsx)("h1",{children:"Your Materials"}),(0,V.jsx)("p",{children:"Calculating quantities from the Concrete and Aggregate Calculator."})]}),(0,V.jsx)("div",{className:"truss-estimator__card",children:(0,V.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,V.jsx)(fr,{}),(0,V.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})}):(0,V.jsx)(V.Fragment,{children:(0,V.jsxs)("div",{className:"truss-estimator",children:[(0,V.jsxs)("div",{className:"quick-order-hero",children:[(0,V.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,V.jsx)("h1",{children:"Concrete and Aggregate Calculator"}),(0,V.jsx)("p",{children:"Calculate fixed site-mix concrete ingredients or aggregate bulk bags."})]}),(0,V.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,V.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose what you need"}),(0,V.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter the area and depth. The calculator adds the fixed Materials Market products directly to your basket."}),(0,V.jsxs)("div",{className:"materials-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Material type"}),(0,V.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,V.jsxs)("button",{type:"button",className:`truss-estimator__option-card${f==="concrete"?" is-selected":""}`,onClick:()=>h("concrete"),children:[(0,V.jsx)("div",{className:"truss-estimator__option-title",children:"Site-mixed concrete"}),(0,V.jsx)("div",{className:"truss-estimator__option-copy",children:"Cement, sharp sand and 20mm aggregate"})]}),(0,V.jsxs)("button",{type:"button",className:`truss-estimator__option-card${f==="aggregate"?" is-selected":""}`,onClick:()=>h("aggregate"),children:[(0,V.jsx)("div",{className:"truss-estimator__option-title",children:"Aggregates"}),(0,V.jsx)("div",{className:"truss-estimator__option-copy",children:"MOT Type 1, sharp sand or 20mm gravel"})]})]})]}),f==="aggregate"&&(0,V.jsxs)("div",{className:"materials-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Aggregate type"}),(0,V.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.keys(Un).map(fe=>(0,V.jsxs)("button",{type:"button",className:`truss-estimator__option-card${w===fe?" is-selected":""}`,onClick:()=>M(fe),children:[(0,V.jsx)("div",{className:"truss-estimator__option-title",children:Un[fe].label}),(0,V.jsx)("div",{className:"truss-estimator__option-copy",children:Un[fe].blurb})]},fe))})]}),(0,V.jsxs)("div",{className:"materials-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and depth"}),(0,V.jsxs)("div",{className:"materials-calculator__unit-row",children:[(0,V.jsx)("span",{children:"Units"}),(0,V.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,V.jsx)("button",{type:"button",className:i==="m"?"is-selected":"",onClick:()=>n("m"),children:"Metric"}),(0,V.jsx)("button",{type:"button",className:i==="ft"?"is-selected":"",onClick:()=>n("ft"),children:"Imperial"})]})]}),(0,V.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsxs)("span",{children:["Length (",i,")"]}),(0,V.jsx)("input",{type:"number",min:"0",step:"0.01",value:o,onChange:fe=>l(fe.target.value)})]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsxs)("span",{children:["Width (",i,")"]}),(0,V.jsx)("input",{type:"number",min:"0",step:"0.01",value:c,onChange:fe=>p(fe.target.value)})]})]}),(0,V.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,V.jsxs)("span",{children:["Depth (",i==="m"?"cm":"inches",")"]}),(0,V.jsx)("input",{type:"number",min:"0",step:"0.1",value:d,onChange:fe=>g(fe.target.value)})]})]}),(0,V.jsxs)("div",{className:"materials-calculator__totals",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Materials required"}),(0,V.jsx)("div",{className:"materials-calculator__result-grid",children:f==="concrete"?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Cement"}),(0,V.jsxs)("strong",{children:[z.toFixed(0)," kg"]})]}),(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Sharp sand"}),(0,V.jsxs)("strong",{children:[G.toFixed(2)," m\xB3"]})]}),(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"20mm aggregate"}),(0,V.jsxs)("strong",{children:[P.toFixed(2)," m\xB3"]})]})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:A.label}),(0,V.jsxs)("strong",{children:[N.toFixed(2)," m\xB3"]})]}),(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Approx. weight"}),(0,V.jsxs)("strong",{children:[(N*A.density).toFixed(2)," t"]})]}),(0,V.jsx)("div",{})]})}),(0,V.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."})]}),u&&(0,V.jsx)("p",{className:"results-empty-hint estimator-products__error",children:u}),(0,V.jsxs)("div",{className:"materials-calculator__actions",children:[(0,V.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,V.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:me,disabled:N<=0||D,children:D?"Adding products\u2026":a})]})]})]})})}var Xa=X(Xe());var U=X(ie()),Dn=12,On=8,nc=.56,ww=.21,Ca={ranges:{meridian:{label:"Standard grooved timber",blurb:"32 \xD7 125mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.125},summit:{label:"Wide grooved timber",blurb:"32 \xD7 150mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.15}},boardGapM:.006,wastage:{straight:.05,diagonal:.15},pictureFrame:{extraWastage:.08},joist:{lengthM:2.4,spacingOptions:[{id:"300",label:"300mm centres (heavy duty)",spacingM:.3},{id:"400",label:"400mm centres (standard)",spacingM:.4},{id:"450",label:"450mm centres (light use)",spacingM:.45}]}},Ni=["range","grid","pictureFrame","substructure"],L_={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:""}},oc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),lc=(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),H_=(e,t,a,r)=>{let i=oc(e,t,a),n=oc(e,t,r),o=oc(a,r,e),l=oc(a,r,t);return i===0&&lc(e,t,a)||n===0&&lc(e,t,r)||o===0&&lc(a,r,e)||l===0&&lc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},Ad=(e,t)=>{let a=t?e.length:e.length-1;for(let r=0;r<a;r+=1){let i=e[(r+1)%e.length];for(let n=r+1;n<a;n+=1)if(!(n===r+1||t&&r===0&&n===a-1)&&H_(e[r],i,e[n],e[(n+1)%e.length]))return!0}return!1};function Rd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Xa.useState)(0),[n,o]=(0,Xa.useState)(L_),[l,c]=(0,Xa.useState)(1),[p,d]=(0,Xa.useState)({x:0,y:0}),[g,f]=(0,Xa.useState)(null),h=(0,Xa.useRef)(null),w=(0,Xa.useRef)(null),M=(0,Xa.useRef)(null),D=Ni[r],m=n.range?Ca.ranges[n.range]:null,u=Dn/l,b=On/l,v=(Dn-u)/2,N=(On-b)/2,A=Math.max(-Dn,Math.min(Dn*2-u,v+p.x)),T=Math.max(-On,Math.min(On*2-b,N+p.y)),z=Number.parseFloat(n.quickLengthM),G=Number.parseFloat(n.quickWidthM),P=z>0&&G>0,be=k=>Math.abs(k.reduce((R,E,O)=>{let ee=k[(O+1)%k.length];return R+E.x*ee.y-ee.x*E.y},0))/2,De=(k,R)=>Math.hypot(R.x-k.x,R.y-k.y),Le=n.isOutlineClosed?be(n.points):0,He=n.isOutlineClosed?n.points.reduce((k,R,E)=>k+De(R,n.points[(E+1)%n.points.length]),0):0,ze=n.isOutlineClosed?n.points.reduce((k,R,E)=>k+(n.wallSegments.has(E)?0:De(R,n.points[(E+1)%n.points.length])),0):0,me=n.points.reduce((k,R)=>({x:k.x+R.x/n.points.length,y:k.y+R.y/n.points.length}),{x:0,y:0}),ce=n.points.length>1?(()=>{let k=n.points[0],R=n.points[1],E=De(k,R),O=E?-(R.y-k.y)/E:0,ee=E?(R.x-k.x)/E:0,xe=(k.x+R.x)/2,we=(k.y+R.y)/2,y=O*(xe-me.x)+ee*(we-me.y)>=0?1:-1;return{x:xe+O*nc*y,y:we+ee*nc*y}})():null,Ee=(()=>{let k=n.range?Ca.ranges[n.range]:Ca.ranges.meridian,R=n.deckSizeMode==="quick"?z*G:Le,E=n.deckSizeMode==="quick"?2*(z+G):ze,O=n.direction==="diagonal"?Ca.wastage.diagonal:Ca.wastage.straight,ee=n.pictureFrame==="yes"?Ca.pictureFrame.extraWastage:0,we=R/(k.boardWidthM+Ca.boardGapM)/k.boardLengthM,y=Math.ceil(we*(1+O+ee)),j=Math.ceil(R*30*(1+O+ee)/200),B=Ca.joist.spacingOptions.find(q=>q.id===n.joistSpacing)??Ca.joist.spacingOptions[1],ae=R/B.spacingM,te=Math.ceil(ae/Ca.joist.lengthM);return{range:k,area:R,boardCount:y,screwBoxes:j,joistLengthsNeeded:te,spacing:B}})(),ut=Ee?[{key:`boards-${n.range??"meridian"}`,label:`Deck boards (${Ee.range.label})`,qty:Ee.boardCount,unit:"each",query:"timber decking board",category:"decking",calculatorWasteIncluded:!0},{key:"joists",label:"Treated C24 joists",qty:Ee.joistLengthsNeeded,unit:"each",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}]:[],Se=()=>D==="range"?!!n.range:D==="grid"?n.deckSizeMode==="quick"?P:n.isOutlineClosed&&Le>0:D==="pictureFrame"?!!n.pictureFrame&&!!n.direction:D==="substructure"?!!n.joistSpacing:!0,Z=r===Ni.length-1?a:"Next",de=(k,R,E=!1)=>{let O=M.current?.getBoundingClientRect();if(!O)return null;let ee=E?1:.25;return{x:Math.round(Math.max(A,Math.min(A+u,A+(k-O.left)/O.width*u))/ee)*ee,y:Math.round(Math.max(T,Math.min(T+b,T+(R-O.top)/O.height*b))/ee)*ee}},Je=k=>{if(n.isOutlineClosed){let E=k.target;if(E!==k.currentTarget&&!E.classList.contains("deck-outline__grid"))return;w.current={startX:k.clientX,startY:k.clientY,startViewX:A,startViewY:T},k.currentTarget.setPointerCapture(k.pointerId);return}if(n.drawMode!=="outline")return;let R=de(k.clientX,k.clientY,!0);R&&(f(null),o(E=>{let O=[...E.points,R];return Ad(O,!1)?{...E,drawError:"Edges cannot cross. Choose another corner."}:{...E,points:O,drawError:""}}))},Ye=(k,R)=>{if(!n.isOutlineClosed){k.stopPropagation(),R===0&&n.points.length>=3&&o(E=>({...E,isOutlineClosed:!0,drawMode:"edges"}));return}k.stopPropagation(),h.current=R,k.currentTarget.setPointerCapture(k.pointerId)},pt=k=>{if(w.current){let O=M.current?.getBoundingClientRect();if(!O)return;let ee=w.current,xe=ee.startViewX-(k.clientX-ee.startX)/O.width*u,we=ee.startViewY-(k.clientY-ee.startY)/O.height*b;d({x:xe-v,y:we-N});return}!n.isOutlineClosed&&n.drawMode==="outline"&&f(de(k.clientX,k.clientY,!0));let R=h.current;if(R===null)return;let E=de(k.clientX,k.clientY);E&&o(O=>{let ee=O.points.map((xe,we)=>we===R?E:xe);return Ad(ee,!0)?{...O,drawError:"Edges cannot cross. Move the corner to a different position."}:{...O,points:ee,drawError:""}})},ot=k=>{w.current=null,h.current=null,k.currentTarget.hasPointerCapture(k.pointerId)&&k.currentTarget.releasePointerCapture(k.pointerId)},at=k=>{o(R=>{let E=new Set(R.wallSegments);return E.has(k)?E.delete(k):E.add(k),{...R,wallSegments:E}})},ge=()=>{r===0?e():i(k=>k-1)},W=()=>{Se()&&(r===Ni.length-1?t?.(ut):i(k=>k+1))};return(0,U.jsx)(U.Fragment,{children:(0,U.jsxs)("div",{className:"truss-estimator",children:[(0,U.jsxs)("div",{className:"quick-order-hero",children:[(0,U.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,U.jsx)("h1",{children:"Decking Calculator"}),(0,U.jsx)("p",{children:"Estimate timber boards, joists and screws for your deck."})]}),(0,U.jsxs)("div",{className:"truss-estimator__card",children:[(0,U.jsxs)("div",{className:"truss-estimator__body",children:[D==="range"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ni.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your timber decking"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Both options are fixed, orderable pressure-treated timber boards."}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Ca.ranges).map(([k,R])=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===k?" is-selected":""}`,onClick:()=>o(E=>({...E,range:k})),children:[(0,U.jsx)("div",{className:"truss-estimator__option-title",children:R.label}),(0,U.jsx)("div",{className:"truss-estimator__option-copy",children:R.blurb}),(0,U.jsxs)("div",{className:"truss-estimator__option-copy",children:[R.boardLengthM,"m boards"]})]},k))})]}):null,D==="grid"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ni.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Tell us your deck size"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Start with a quick rectangle estimate, or draw an irregular deck for a more precise result."}),(0,U.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,U.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.deckSizeMode==="quick"?" is-selected":""}`,onClick:()=>o(k=>({...k,deckSizeMode:"quick"})),children:"Quick estimate"}),(0,U.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.deckSizeMode==="draw"?" is-selected":""}`,onClick:()=>o(k=>({...k,deckSizeMode:"draw",drawMode:"outline"})),children:"Draw your space"})]}),n.deckSizeMode==="quick"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,U.jsxs)("label",{className:"truss-estimator__field",children:[(0,U.jsx)("span",{children:"Length (m)"}),(0,U.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:n.quickLengthM,onChange:k=>o(R=>({...R,quickLengthM:k.target.value}))})]}),(0,U.jsxs)("label",{className:"truss-estimator__field",children:[(0,U.jsx)("span",{children:"Width (m)"}),(0,U.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:n.quickWidthM,onChange:k=>o(R=>({...R,quickWidthM:k.target.value}))})]})]}),(0,U.jsx)("div",{className:"truss-estimator__grid-hint",children:"For L-shaped decks, cut-outs, or sides against a wall, use Draw your space."}),P?(0,U.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,U.jsxs)("div",{children:[(z*G).toFixed(2)," m\xB2 deck"]}),(0,U.jsxs)("div",{children:[(2*(z+G)).toFixed(2)," m perimeter"]})]}):null]}):(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Draw your deck"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Click to add corners, then close the outline. Drag any handle to refine it."}),(0,U.jsxs)("div",{className:"deck-outline__toolbar",children:[n.isOutlineClosed?(0,U.jsxs)("div",{className:"deck-outline__summary",children:[(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Deck area"}),(0,U.jsxs)("strong",{children:[Le.toFixed(2)," m\xB2"]})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Perimeter"}),(0,U.jsxs)("strong",{children:[He.toFixed(2)," m"]})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Wall edges"}),(0,U.jsx)("strong",{children:n.wallSegments.size>0?n.wallSegments.size:"None"})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Visible edge"}),(0,U.jsxs)("strong",{children:[ze.toFixed(2)," m"]})]})]}):null,(0,U.jsxs)("div",{className:"deck-outline__actions",children:[(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(k=>({...k,points:k.points.slice(0,-1)})),disabled:n.points.length===0||n.isOutlineClosed,children:"Undo"}),(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{f(null),o(k=>({...k,points:[],isOutlineClosed:!1,wallSegments:new Set,drawMode:"outline",drawError:""}))},disabled:n.points.length===0,children:"Clear"}),(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(k=>({...k,points:[{x:2,y:2},{x:8,y:2},{x:8,y:5},{x:2,y:5}],isOutlineClosed:!0,wallSegments:new Set,drawMode:"edges",drawError:""})),children:"Start with rectangle"})]})]}),(0,U.jsx)("div",{className:"deck-editor-layout",children:(0,U.jsxs)("div",{className:"deck-editor-layout__canvas-column",children:[(0,U.jsxs)("div",{className:"deck-outline",children:[(0,U.jsxs)("svg",{ref:M,className:`deck-outline__canvas${n.isOutlineClosed?" is-pan-mode":""}`,viewBox:`${A} ${T} ${u} ${b}`,preserveAspectRatio:"none","aria-label":"Deck outline drawing area",onPointerDown:Je,onPointerMove:pt,onPointerUp:ot,onPointerLeave:()=>{f(null),w.current||(h.current=null)},children:[(0,U.jsx)("defs",{children:(0,U.jsx)("pattern",{id:"deck-outline-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,U.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,U.jsx)("rect",{x:-Dn,y:-On,width:Dn*3,height:On*3,className:"deck-outline__grid",fill:"url(#deck-outline-grid)"}),n.points.length>1?(0,U.jsx)("polyline",{className:"deck-outline__preview",points:n.points.map(k=>`${k.x},${k.y}`).join(" ")}):null,n.isOutlineClosed?(0,U.jsx)("polygon",{className:"deck-outline__shape",points:n.points.map(k=>`${k.x},${k.y}`).join(" "),stroke:"none"}):null,n.points.length>1?n.points.slice(0,n.isOutlineClosed?void 0:-1).map((k,R)=>{let E=n.points[n.isOutlineClosed?(R+1)%n.points.length:R+1],O=De(k,E),ee=O?-(E.y-k.y)/O:0,xe=O?(E.x-k.x)/O:0,we=(k.x+E.x)/2,y=(k.y+E.y)/2,j=ee*(we-me.x)+xe*(y-me.y)>=0?1:-1,B=we+ee*nc*j,ae=y+xe*nc*j;return(0,U.jsxs)("g",{children:[(0,U.jsx)("line",{className:"deck-outline__edge-hit",x1:k.x,y1:k.y,x2:E.x,y2:E.y,onClick:n.isOutlineClosed?()=>at(R):void 0}),(0,U.jsx)("line",{className:`deck-outline__edge${n.wallSegments.has(R)?" is-wall":""}`,x1:k.x,y1:k.y,x2:E.x,y2:E.y,pointerEvents:"none"}),(0,U.jsxs)("text",{className:`deck-outline__edge-label${n.wallSegments.has(R)?" is-wall":""}`,x:B,y:ae,textAnchor:"middle",dominantBaseline:"central",fontSize:ww/l,children:[O.toFixed(2)," m"]})]},`segment-${R}`)}):null,!n.isOutlineClosed&&n.points.length>0&&g?(()=>{let k=n.points[n.points.length-1],R=De(k,g);if(!R)return null;let E=-(g.y-k.y)/R,O=(g.x-k.x)/R,ee=(k.x+g.x)/2,xe=(k.y+g.y)/2;return(0,U.jsxs)("g",{className:"deck-outline__live-measurement",children:[(0,U.jsx)("line",{x1:k.x,y1:k.y,x2:g.x,y2:g.y}),(0,U.jsxs)("text",{x:ee+E*.34,y:xe+O*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:ww/l,children:[R.toFixed(2)," m"]})]})})():null,n.points.map((k,R)=>(0,U.jsx)("circle",{className:"deck-outline__point",cx:k.x,cy:k.y,r:"0.13",onPointerDown:E=>Ye(E,R)},`point-${R}`))]}),(0,U.jsxs)("div",{className:"deck-outline__zoom","aria-label":"Zoom controls",children:[(0,U.jsx)("button",{type:"button",onClick:()=>c(k=>Math.max(.5,k-.25)),disabled:l===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,U.jsxs)("span",{children:[Math.round(l*100),"%"]}),(0,U.jsx)("button",{type:"button",onClick:()=>c(k=>Math.min(1,k+.25)),disabled:l===1,"aria-label":"Zoom in",children:"+"})]}),n.isOutlineClosed&&n.wallSegments.size===0&&ce?(0,U.jsx)("div",{className:"deck-outline__edge-prompt",role:"status",style:{left:`${(ce.x-A)/u*100}%`,top:`${(ce.y-T)/b*100}%`},children:"Tap an edge to mark it as a wall, or leave it as a visible edge."}):null,!n.isOutlineClosed&&n.points.length>=3?(0,U.jsx)("button",{type:"button",className:"deck-outline__close",onClick:()=>o(k=>Ad(k.points,!0)?{...k,drawError:"Edges cannot cross. Adjust the outline before finishing."}:{...k,isOutlineClosed:!0,drawMode:"edges",drawError:""}),children:"Finish outline"}):null]}),(0,U.jsxs)("div",{className:"deck-outline__supporting",children:[(0,U.jsx)("div",{className:"truss-estimator__grid-hint",children:n.isOutlineClosed?"Drag a corner handle to refine the outline.":"Add at least three corners, then click Finish outline."}),n.drawError?(0,U.jsx)("div",{className:"deck-outline__error",role:"alert",children:n.drawError}):null]})]})})]})]}):null,D==="pictureFrame"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ni.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Picture frame border?"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"A picture frame border runs boards around the perimeter for a finished look and uses extra material."}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"no",label:"No border",img:"/decking/boards/no-border.webp"},{id:"yes",label:"Picture frame",img:"/decking/boards/picture-frame.webp"}].map(k=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.pictureFrame===k.id?" is-selected":""}`,onClick:()=>o(R=>({...R,pictureFrame:k.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:Jt(k.img),alt:""}),(0,U.jsx)("span",{children:k.label})]},k.id))}),(0,U.jsxs)(U.Fragment,{children:[(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Board direction"}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"straight",label:"Straight",img:"/decking/boards/straight.webp"},{id:"diagonal",label:"Diagonal",img:"/decking/boards/diagonal.webp"}].map(k=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.direction===k.id?" is-selected":""}`,onClick:()=>o(R=>({...R,direction:k.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:Jt(k.img),alt:""}),(0,U.jsx)("span",{children:k.label})]},k.id))})]})]}):null,D==="substructure"?(0,U.jsxs)(U.Fragment,{children:[(0,U.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Ni.length]}),(0,U.jsx)("h2",{className:"truss-estimator__step-title",children:"Substructure"}),(0,U.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the joist spacing. Posts, footings and ground preparation vary by site, so are not included."}),(0,U.jsx)("div",{className:"truss-estimator__section-heading",children:"Joist spacing"}),(0,U.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Ca.joist.spacingOptions.map(k=>(0,U.jsx)("button",{type:"button",className:`truss-estimator__option-card${n.joistSpacing===k.id?" is-selected":""}`,onClick:()=>o(R=>({...R,joistSpacing:k.id})),children:(0,U.jsx)("div",{className:"truss-estimator__option-title",children:k.label})},k.id))})]}):null]}),(0,U.jsxs)("div",{className:"truss-estimator__nav",children:[(0,U.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:ge,children:"Back"}),(0,U.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:W,disabled:!Se(),children:[(0,U.jsx)("span",{children:Z}),(0,U.jsx)("span",{className:"arrow",children:(0,U.jsx)(jt,{})})]})]})]})]})})}var Ea=X(Xe());var Q=X(ie()),yw=12,_w=30,Bn=12,Ln=8,xw=.56,qa={ranges:{boundary:{label:"Horizontal lap",blurb:"Traditional pressure-treated timber panels.",panelWidthM:1.83},skyline:{label:"Feather edge",blurb:"Heavier timber panels for a more solid boundary.",panelWidthM:1.83}},heights:["0.9","1.2","1.5","1.8"],gate:{single:{label:"Single lap gate",widthDefault:.9}},mounting:{concrete:{label:"Concrete posts",blurb:"Slotted concrete posts with matching panels."},postcrete:{label:"Postcrete bags",blurb:"Fast-set post-mix bags in a dug hole.",bagsPerPost:2}}},Si=["range","height","gate","posts"],j_={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:""}},sc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),cc=(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),Q_=(e,t,a,r)=>{let i=sc(e,t,a),n=sc(e,t,r),o=sc(a,r,e),l=sc(a,r,t);return i===0&&cc(e,t,a)||n===0&&cc(e,t,r)||o===0&&cc(a,r,e)||l===0&&cc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},uc=(e,t)=>{let a=t?e.length:e.length-1;for(let r=0;r<a;r+=1)for(let i=r+1;i<a;i+=1)if(!(i===r+1||t&&r===0&&i===a-1)&&Q_(e[r],e[(r+1)%e.length],e[i],e[(i+1)%e.length]))return!0;return!1};function Ud({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ea.useState)(0),[n,o]=(0,Ea.useState)(j_),l=(0,Ea.useRef)(null),c=(0,Ea.useRef)(null),[p,d]=(0,Ea.useState)(1),[g,f]=(0,Ea.useState)({x:0,y:0}),[h,w]=(0,Ea.useState)(null),M=(0,Ea.useRef)(null),D=(0,Ea.useRef)(null),m=(0,Ea.useRef)(null),u=Si[r],b=n.range?qa.ranges[n.range]:null,v=Bn/p,N=Ln/p,A=(Bn-v)/2,T=(Ln-N)/2,z=Math.max(-Bn,Math.min(Bn*2-v,A+g.x)),G=Math.max(-Ln,Math.min(Ln*2-N,T+g.y)),P=n.boundaryPoints.reduce((y,j)=>({x:y.x+j.x/Math.max(1,n.boundaryPoints.length),y:y.y+j.y/Math.max(1,n.boundaryPoints.length)}),{x:0,y:0}),be=y=>{let j=new Set,B=[];return y.forEach(ae=>{let[te,q]=ae.split(",").map(Number),Y=[{key:`H,${te},${q}`,type:"H",x:te,y:q},{key:`H,${te},${q+1}`,type:"H",x:te,y:q+1},{key:`V,${te},${q}`,type:"V",x:te,y:q},{key:`V,${te+1},${q}`,type:"V",x:te+1,y:q}],K=[!y.has(`${te},${q-1}`),!y.has(`${te},${q+1}`),!y.has(`${te-1},${q}`),!y.has(`${te+1},${q}`)];Y.forEach((pe,ke)=>{K[ke]&&!j.has(pe.key)&&(j.add(pe.key),B.push(pe))})}),B},De=(y,j)=>be(y).filter(B=>!j.has(B.key)),Le=(y,j)=>De(y,j).length,He=(y,j)=>{let B={};De(y,j).forEach(te=>{var q,Y,K,pe;te.type==="H"?((B[q=`${te.x},${te.y}`]||(B[q]=[])).push("H"),(B[Y=`${te.x+1},${te.y}`]||(B[Y]=[])).push("H")):((B[K=`${te.x},${te.y}`]||(B[K]=[])).push("V"),(B[pe=`${te.x},${te.y+1}`]||(B[pe]=[])).push("V"))});let ae=0;return Object.values(B).forEach(te=>{(te.length===1||te.length===2&&te[0]!==te[1]||te.length>=3)&&(ae+=1)}),ae},me=(()=>{let y=n.range?qa.ranges[n.range]:qa.ranges.boundary,j=n.height??"1.8",B=n.boundaryMode==="quick"?Math.max(0,Number.parseFloat(n.quickLengthM)||0):n.boundaryClosed?n.boundaryPoints.slice(0,-1).reduce((It,vr,$a)=>It+(n.excludedBoundaryEdges.has($a)?0:Math.hypot(n.boundaryPoints[$a+1].x-vr.x,n.boundaryPoints[$a+1].y-vr.y)),0):0,ae=n.gateType&&n.gateType!=="none"?Number.parseFloat(n.gateWidthM)||qa.gate[n.gateType].widthDefault:0,te=Math.max(0,B-ae),q=te>0?Math.ceil(te/y.panelWidthM):0,Y=n.boundaryPoints.length>2&&n.boundaryPoints[0].x===n.boundaryPoints[n.boundaryPoints.length-1].x&&n.boundaryPoints[0].y===n.boundaryPoints[n.boundaryPoints.length-1].y,K=n.boundaryMode==="quick"?te>0?2:0:n.boundaryClosed?n.boundaryPoints.slice(0,Y?-1:void 0).reduce((It,vr,$a)=>{let Fd=$a>0&&!n.excludedBoundaryEdges.has($a-1),Gn=$a<n.boundaryPoints.length-1&&!n.excludedBoundaryEdges.has($a);return It+(Fd||Gn?1:0)},0):0,pe=te>0?Math.ceil(te/y.panelWidthM)+1:0,ke=Math.max(0,pe-K),Fe=n.mountingType?qa.mounting[n.mountingType]:qa.mounting.concrete,xt=n.gateType&&n.gateType!=="none"?2:0,ua=ke+K+xt,ul=n.mountingType==="postcrete"?ua*qa.mounting.postcrete.bagsPerPost:0,pa=n.gravelBoard==="yes"?q:0;return{range:y,height:j,totalEdgeM:B,fencedLengthM:te,gateWidthM:ae,panelsCount:q,cornerPostCount:K,intermediatePostCount:ke,gatePostCount:xt,totalPostCount:ua,bagsCount:ul,gravelCount:pa,capCount:ua,mounting:Fe}})(),ce=n.gateType&&n.gateType!=="none"?qa.gate[n.gateType].label:null,fe=Number(me.height)<=1.2?"6":"8",Ee=me?[{key:`panels-${n.range??"boundary"}-${me.height}`,label:`${me.range.label} panels (${me.height}m)`,qty:me.panelsCount,unit:"each",query:"fence panel",category:"fencing"},...n.mountingType==="concrete"?[{key:`concrete-intermediate-${fe}`,label:"Intermediate concrete posts",qty:me.intermediatePostCount,unit:"each",query:"concrete fence post",category:"fencing"},{key:`concrete-end-${fe}`,label:"End and corner concrete posts",qty:me.cornerPostCount+me.gatePostCount,unit:"each",query:"concrete end post",category:"fencing"}]:[{key:`timber-post-${fe}`,label:"Timber fence posts",qty:me.totalPostCount,unit:"each",query:"timber fence post",category:"fencing"},{key:"postcrete",label:"Postcrete",qty:me.bagsCount,unit:"bag",query:"postcrete",category:"cement"}],...ce?[{key:"gate",label:ce,qty:1,unit:"each",query:"lap gate",category:"fencing"}]:[],...me.gravelCount>0?[{key:"gravel-boards",label:"Concrete gravel boards",qty:me.gravelCount,unit:"each",query:"gravel board",category:"fencing"}]:[]]:[],ut=()=>{if(u==="range"){let y=n.boundaryMode==="quick"?(Number.parseFloat(n.quickLengthM)||0)>0:n.boundaryClosed&&n.boundaryPoints.length>=2;return!!n.range&&y}return u==="height"?!!n.height&&!!n.gravelBoard:u==="gate"?!!n.gateType&&(n.gateType==="none"||n.gateWidthM.trim()!==""):u==="posts"?!!n.mountingType:!0},Se=r===Si.length-1?a:"Next",Z=y=>{o(j=>{let B=y(new Set(j.grid)),ae=new Set([...j.excludedEdges].filter(te=>be(B).some(q=>q.key===te)));return{...j,grid:B,excludedEdges:ae}})},de=(y,j,B)=>{Z(ae=>{let te=`${y},${j}`;return B?ae.add(te):ae.delete(te),ae})},Je=(y,j,B,ae,te)=>{let q=y,Y=j,K=Math.abs(B-y),pe=y<B?1:-1,ke=-Math.abs(ae-j),Fe=j<ae?1:-1,xt=K+ke;for(;de(q,Y,te),!(q===B&&Y===ae);){let ua=2*xt;ua>=ke&&(xt+=ke,q+=pe),ua<=K&&(xt+=K,Y+=Fe)}},Ye=(y,j)=>{let B=c.current?.getBoundingClientRect();if(!B)return null;let ae=Math.floor((y-B.left)/_w),te=Math.floor((j-B.top)/_w);return ae<0||te<0||ae>=yw||te>=yw?null:{x:ae,y:te}},pt=y=>{if(n.gridMode!=="draw")return;let j=Ye(y.clientX,y.clientY);if(!j)return;y.preventDefault();let B=`${j.x},${j.y}`,ae=!n.grid.has(B);l.current={active:!0,paintValue:ae,lastX:j.x,lastY:j.y},y.currentTarget.setPointerCapture(y.pointerId),de(j.x,j.y,ae)},ot=y=>{let j=l.current;if(!j?.active)return;let B=Ye(y.clientX,y.clientY);B&&(B.x===j.lastX&&B.y===j.lastY||(Je(j.lastX,j.lastY,B.x,B.y,j.paintValue),l.current={...j,lastX:B.x,lastY:B.y}))},at=y=>{l.current?.active&&(l.current=null,y.currentTarget.releasePointerCapture(y.pointerId))},ge=(y,j,B=!1)=>{let ae=m.current?.getBoundingClientRect();if(!ae)return null;let te=B?1:.25;return{x:Math.round(Math.max(z,Math.min(z+v,z+(y-ae.left)/ae.width*v))/te)*te,y:Math.round(Math.max(G,Math.min(G+N,G+(j-ae.top)/ae.height*N))/te)*te}},W=y=>{if(n.boundaryClosed){let B=y.target;if(B!==y.currentTarget&&!B.classList.contains("fence-boundary__grid"))return;D.current={startX:y.clientX,startY:y.clientY,startViewX:z,startViewY:G},y.currentTarget.setPointerCapture(y.pointerId);return}let j=ge(y.clientX,y.clientY,!0);j&&(w(null),o(B=>{let ae=[...B.boundaryPoints,j];return uc(ae,!1)?{...B}:{...B,boundaryPoints:ae}}))},k=(y,j)=>{if(y.stopPropagation(),!n.boundaryClosed){if(j!==0||n.boundaryPoints.length<3)return;o(B=>uc(B.boundaryPoints,!0)?B:{...B,boundaryPoints:[...B.boundaryPoints,B.boundaryPoints[0]],boundaryClosed:!0});return}M.current=j,y.currentTarget.setPointerCapture(y.pointerId)},R=y=>{if(D.current){let B=m.current?.getBoundingClientRect();if(!B)return;let ae=D.current,te=ae.startViewX-(y.clientX-ae.startX)/B.width*v,q=ae.startViewY-(y.clientY-ae.startY)/B.height*N;f({x:te-A,y:q-T});return}if(n.boundaryClosed||w(ge(y.clientX,y.clientY,!0)),M.current===null)return;let j=ge(y.clientX,y.clientY);j&&o(B=>{let ae=B.boundaryPoints.length>2&&B.boundaryPoints[0].x===B.boundaryPoints[B.boundaryPoints.length-1].x&&B.boundaryPoints[0].y===B.boundaryPoints[B.boundaryPoints.length-1].y,te=B.boundaryPoints.map((q,Y)=>{let K=Y===M.current,pe=ae&&M.current===0&&Y===B.boundaryPoints.length-1;return K||pe?j:q});return uc(te,!1)?B:{...B,boundaryPoints:te}})},E=y=>{D.current=null,M.current=null,y.currentTarget.hasPointerCapture(y.pointerId)&&y.currentTarget.releasePointerCapture(y.pointerId)},O=y=>{o(j=>{let B=new Set(j.excludedBoundaryEdges);return B.has(y)?B.delete(y):B.add(y),{...j,excludedBoundaryEdges:B}})},ee=()=>{r===0?e():i(y=>y-1)},xe=()=>{ut()&&(r===Si.length-1?t?.(Ee):i(y=>y+1))},we=be(n.grid);return(0,Q.jsx)(Q.Fragment,{children:(0,Q.jsxs)("div",{className:"truss-estimator",children:[(0,Q.jsxs)("div",{className:"quick-order-hero",children:[(0,Q.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Q.jsx)("h1",{children:"Fencing Calculator"}),(0,Q.jsx)("p",{children:"Estimate panels, posts and cost for your fence line in a few steps."})]}),(0,Q.jsxs)("div",{className:"truss-estimator__card",children:[(0,Q.jsxs)("div",{className:"truss-estimator__body",children:[u==="range"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Q.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your fence panels"}),(0,Q.jsx)("p",{className:"truss-estimator__step-sub",children:"The calculator uses fixed, orderable timber panels from the catalogue."}),(0,Q.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(qa.ranges).map(([y,j])=>(0,Q.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===y?" is-selected":""}`,onClick:()=>o(B=>({...B,range:y})),children:[(0,Q.jsx)("div",{className:"truss-estimator__option-title",children:j.label}),(0,Q.jsx)("div",{className:"truss-estimator__option-copy",children:j.blurb})]},y))})]}):null,u==="range"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)("div",{className:"truss-estimator__section-heading",children:"Measure your fence line"}),(0,Q.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,Q.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,Q.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="quick"?" is-selected":""}`,onClick:()=>o(y=>({...y,boundaryMode:"quick"})),children:"Quick estimate"}),(0,Q.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="draw"?" is-selected":""}`,onClick:()=>o(y=>({...y,boundaryMode:"draw"})),children:"Draw your boundary"})]}),n.boundaryMode==="quick"?(0,Q.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact fence-boundary__quick-field",children:[(0,Q.jsx)("span",{children:"Total fence length (m)"}),(0,Q.jsx)("input",{type:"number",min:"0",step:"0.1",value:n.quickLengthM,onChange:y=>o(j=>({...j,quickLengthM:y.target.value}))})]}):(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsx)("div",{className:"fence-boundary__toolbar",children:(0,Q.jsxs)("div",{className:"fence-boundary__actions",children:[(0,Q.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(y=>({...y,boundaryPoints:y.boundaryPoints.slice(0,-1),boundaryClosed:!1,excludedBoundaryEdges:new Set})),disabled:n.boundaryPoints.length===0||n.boundaryClosed,children:"Undo"}),(0,Q.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{f({x:0,y:0}),w(null),o(y=>({...y,boundaryPoints:[],boundaryClosed:!1,excludedBoundaryEdges:new Set}))},disabled:n.boundaryPoints.length===0,children:"Clear"}),(0,Q.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(y=>({...y,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,Q.jsxs)("div",{className:"fence-boundary",children:[(0,Q.jsxs)("svg",{ref:m,className:`fence-boundary__canvas${n.boundaryClosed?" is-pan-mode":""}`,viewBox:`${z} ${G} ${v} ${N}`,preserveAspectRatio:"none","aria-label":"Fence boundary drawing area",onPointerDown:W,onPointerMove:R,onPointerUp:E,onPointerLeave:()=>{w(null),D.current||(M.current=null)},children:[(0,Q.jsx)("defs",{children:(0,Q.jsx)("pattern",{id:"fence-boundary-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,Q.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,Q.jsx)("rect",{x:-Bn,y:-Ln,width:Bn*3,height:Ln*3,className:"fence-boundary__grid",fill:"url(#fence-boundary-grid)"}),n.boundaryPoints.length>1?(0,Q.jsx)("polyline",{className:"fence-boundary__preview",points:n.boundaryPoints.map(y=>`${y.x},${y.y}`).join(" ")}):null,n.boundaryPoints.length>1?n.boundaryPoints.slice(0,-1).map((y,j)=>{let B=n.boundaryPoints[j+1],ae=Math.hypot(B.x-y.x,B.y-y.y),te=ae?-(B.y-y.y)/ae:0,q=ae?(B.x-y.x)/ae:0,Y=(y.x+B.x)/2,K=(y.y+B.y)/2,pe=te*(Y-P.x)+q*(K-P.y)>=0?1:-1,ke=Y+te*xw*pe,Fe=K+q*xw*pe;return(0,Q.jsxs)("g",{children:[(0,Q.jsx)("line",{className:"fence-boundary__edge-hit",x1:y.x,y1:y.y,x2:B.x,y2:B.y,onClick:n.boundaryClosed?()=>O(j):void 0}),(0,Q.jsx)("line",{className:`fence-boundary__edge${n.excludedBoundaryEdges.has(j)?" is-excluded":""}`,x1:y.x,y1:y.y,x2:B.x,y2:B.y,pointerEvents:"none"}),(0,Q.jsxs)("text",{className:`fence-boundary__edge-label${n.excludedBoundaryEdges.has(j)?" is-excluded":""}`,x:ke,y:Fe,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[ae.toFixed(2)," m"]})]},`fence-edge-${j}`)}):null,!n.boundaryClosed&&n.boundaryPoints.length>0&&h?(()=>{let y=n.boundaryPoints[n.boundaryPoints.length-1],j=Math.hypot(h.x-y.x,h.y-y.y);if(!j)return null;let B=-(h.y-y.y)/j,ae=(h.x-y.x)/j,te=(y.x+h.x)/2,q=(y.y+h.y)/2;return(0,Q.jsxs)("g",{className:"fence-boundary__live-measurement",children:[(0,Q.jsx)("line",{x1:y.x,y1:y.y,x2:h.x,y2:h.y}),(0,Q.jsxs)("text",{x:te+B*.34,y:q+ae*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[j.toFixed(2)," m"]})]})})():null,n.boundaryPoints.map((y,j)=>j>0&&j===n.boundaryPoints.length-1&&y.x===n.boundaryPoints[0]?.x&&y.y===n.boundaryPoints[0]?.y?null:(0,Q.jsx)("circle",{className:`fence-boundary__point${!n.boundaryClosed&&j===0&&n.boundaryPoints.length>=3?" is-close-target":""}`,cx:y.x,cy:y.y,r:"0.13",onPointerDown:B=>k(B,j)},`fence-point-${j}`))]}),(0,Q.jsxs)("div",{className:"fence-boundary__zoom","aria-label":"Zoom controls",children:[(0,Q.jsx)("button",{type:"button",onClick:()=>d(y=>Math.max(.5,y-.25)),disabled:p===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,Q.jsxs)("span",{children:[Math.round(p*100),"%"]}),(0,Q.jsx)("button",{type:"button",onClick:()=>d(y=>Math.min(1,y+.25)),disabled:p===1,"aria-label":"Zoom in",children:"+"})]}),!n.boundaryClosed&&n.boundaryPoints.length>=2?(0,Q.jsx)("button",{type:"button",className:"fence-boundary__close",onClick:()=>o(y=>uc(y.boundaryPoints,!1)?y:{...y,boundaryClosed:!0}),children:"Finish fence line"}):null]}),(0,Q.jsx)("div",{className:"truss-estimator__grid-hint",children:n.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,Q.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,Q.jsx)("div",{children:n.boundaryMode==="quick"?`${(Number.parseFloat(n.quickLengthM)||0).toFixed(2)} m fence line`:`${me.totalEdgeM.toFixed(2)} m fence line`}),n.boundaryMode==="draw"&&n.boundaryClosed?(0,Q.jsxs)("div",{children:[me.cornerPostCount," corner/end posts"]}):null]})]}):null,null,u==="height"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Q.jsx)("h2",{className:"truss-estimator__step-title",children:"Fence height"}),(0,Q.jsx)("p",{className:"truss-estimator__step-sub",children:"Select the nearest available panel height."}),(0,Q.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:qa.heights.map(y=>(0,Q.jsx)("button",{type:"button",className:`truss-estimator__visual-card${n.height===y?" is-selected":""}`,onClick:()=>o(j=>({...j,height:y})),children:(0,Q.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--tall",src:Jt(`/fencing/height/${y}.webp`),alt:""})},y))}),(0,Q.jsx)("div",{className:"truss-estimator__section-heading",children:"Gravel board?"}),(0,Q.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(y=>(0,Q.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.gravelBoard===y.id?" is-selected":""}`,onClick:()=>o(j=>({...j,gravelBoard:y.id})),children:[(0,Q.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Jt(y.img),alt:""}),(0,Q.jsx)("span",{children:y.label})]},y.id))})]}):null,u==="gate"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Q.jsx)("h2",{className:"truss-estimator__step-title",children:"Do you need a gate?"}),(0,Q.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,Q.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(y=>(0,Q.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${n.gateType===y.id?" is-selected":""}`,onClick:()=>o(j=>({...j,gateType:y.id,gateWidthM:y.id==="none"?"":String(qa.gate[y.id].widthDefault)})),children:[(0,Q.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Jt(y.img),alt:""}),(0,Q.jsx)("span",{children:y.label})]},y.id))}),n.gateType&&n.gateType!=="none"?(0,Q.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,Q.jsx)("span",{children:"Gate width (m)"}),(0,Q.jsx)("input",{type:"text",inputMode:"decimal",value:n.gateWidthM,onChange:y=>o(j=>({...j,gateWidthM:y.target.value}))})]}):null]}):null,u==="posts"?(0,Q.jsxs)(Q.Fragment,{children:[(0,Q.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Q.jsx)("h2",{className:"truss-estimator__step-title",children:"Posts and fixing type"}),(0,Q.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose how the posts will be set."}),(0,Q.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(qa.mounting).map(([y,j])=>(0,Q.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.mountingType===y?" is-selected":""}`,onClick:()=>o(B=>({...B,mountingType:y})),children:[(0,Q.jsx)("div",{className:"truss-estimator__option-title",children:j.label}),(0,Q.jsx)("div",{className:"truss-estimator__option-copy",children:j.blurb})]},y))})]}):null]}),(0,Q.jsxs)("div",{className:"truss-estimator__nav",children:[(0,Q.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:ee,children:"Back"}),(0,Q.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:xe,disabled:!ut(),children:[(0,Q.jsx)("span",{children:Se}),(0,Q.jsx)("span",{className:"arrow",children:(0,Q.jsx)(jt,{})})]})]})]})]})})}var pc=X(Xe()),_e=X(ie()),kw={floor:{label:"Floor",product:"Knauf Acoustic Roll",thickness:"100mm",coverage:12.36,salesUnit:"roll"},wall:{label:"Cavity wall",product:"Celotex CW4100",thickness:"100mm",coverage:3.24,salesUnit:"pack"},roof:{label:"Pitched roof",product:"Kingspan K107",thickness:"100mm",coverage:8.64,salesUnit:"pack"},loft:{label:"Loft",product:"Knauf Loft Roll 44",thickness:"100mm",coverage:13.89,salesUnit:"roll"}};function Dd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,pc.useState)("floor"),[n,o]=(0,pc.useState)(""),[l,c]=(0,pc.useState)(""),p=Number.parseFloat(n)*Number.parseFloat(l)||0,d=kw[r],g=Math.ceil(p/d.coverage),f=[{key:`insulation-${r}`,label:`${d.product} ${d.thickness}`,qty:g,unit:d.salesUnit,query:d.product,category:"insulation"}],h=Object.entries(kw);return(0,_e.jsx)(_e.Fragment,{children:(0,_e.jsxs)("div",{className:"truss-estimator",children:[(0,_e.jsxs)("div",{className:"quick-order-hero",children:[(0,_e.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,_e.jsx)("h1",{children:"Insulation Calculator"}),(0,_e.jsx)("p",{children:"Estimate insulation coverage and pack quantities for floors, walls, roofs and lofts."})]}),(0,_e.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,_e.jsx)("h2",{className:"truss-estimator__step-title",children:"Where and what you are insulating"}),(0,_e.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the application and product, and enter the area, for coverage and pack quantities."}),(0,_e.jsxs)("div",{className:"materials-calculator__section",children:[(0,_e.jsx)("div",{className:"truss-estimator__section-heading",children:"Application"}),(0,_e.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:h.map(([w,M])=>(0,_e.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===w?" is-selected":""}`,onClick:()=>i(w),children:[(0,_e.jsx)("div",{className:"truss-estimator__option-title",children:M.label}),(0,_e.jsxs)("div",{className:"truss-estimator__option-copy",children:[M.product,", ",M.thickness]})]},w))})]}),(0,_e.jsxs)("div",{className:"materials-calculator__section",children:[(0,_e.jsx)("div",{className:"truss-estimator__section-heading",children:"Area"}),(0,_e.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,_e.jsxs)("label",{className:"truss-estimator__field",children:[(0,_e.jsx)("span",{children:"Length (m)"}),(0,_e.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:w=>o(w.target.value)})]}),(0,_e.jsxs)("label",{className:"truss-estimator__field",children:[(0,_e.jsx)("span",{children:"Width (m)"}),(0,_e.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:w=>c(w.target.value)})]})]})]}),(0,_e.jsxs)("div",{className:"materials-calculator__totals",children:[(0,_e.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,_e.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,_e.jsxs)("div",{children:[(0,_e.jsx)("span",{children:"Insulated area"}),(0,_e.jsxs)("strong",{children:[p.toFixed(2)," m\xB2"]})]}),(0,_e.jsxs)("div",{children:[(0,_e.jsx)("span",{children:d.product}),(0,_e.jsxs)("strong",{children:[g," packs"]})]})]}),(0,_e.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,_e.jsxs)("div",{className:"materials-calculator__actions",children:[(0,_e.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,_e.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(f),disabled:p<=0,children:a})]})]})]})})}var Hn=X(Xe()),$=X(ie()),G_=10,Y_=1.9*.762,X_=1.9*1.524,dc=()=>({height:"",width:""}),mc=e=>Number.parseFloat(e)||0,Nw=({height:e,width:t})=>mc(e)*mc(t);function Od({onBack:e}){let[t,a]=(0,Hn.useState)([dc()]),[r,i]=(0,Hn.useState)([dc()]),[n,o]=(0,Hn.useState)("0"),[l,c]=(0,Hn.useState)("0"),[p,d]=(0,Hn.useState)(1),g=t.reduce((m,u)=>m+Nw(u),0),f=r.reduce((m,u)=>m+Nw(u),0),h=mc(n)*Y_+mc(l)*X_,w=Math.max(0,g-f-h),M=w*p/G_,D=(m,u,b,v)=>{m(N=>N.map((A,T)=>T===u?{...A,[b]:v}:A))};return(0,$.jsx)($.Fragment,{children:(0,$.jsxs)("div",{className:"truss-estimator",children:[(0,$.jsxs)("div",{className:"quick-order-hero",children:[(0,$.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,$.jsx)("h1",{children:"Paint Calculator"}),(0,$.jsx)("p",{children:"Estimate how much paint you need for your walls, including multiple coats and excluded areas."})]}),(0,$.jsxs)("div",{className:"truss-estimator__card paint-calculator",children:[(0,$.jsx)("h2",{className:"truss-estimator__step-title",children:"Walls, exclusions and coats"}),(0,$.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,$.jsxs)("div",{className:"paint-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,$.jsx)("p",{className:"paint-calculator__hint",children:"Enter the height and width of each wall you want to paint."}),(0,$.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,$.jsx)("span",{}),(0,$.jsx)("span",{children:"Height (m)"}),(0,$.jsx)("span",{children:"Width (m)"}),(0,$.jsx)("span",{})]}),t.map((m,u)=>(0,$.jsxs)("div",{className:"paint-calculator__row",children:[(0,$.jsxs)("span",{className:"paint-calculator__row-label",children:["Wall ",u+1]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,$.jsx)("input",{"aria-label":`Wall ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:m.height,onChange:b=>D(a,u,"height",b.target.value)})]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,$.jsx)("input",{"aria-label":`Wall ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:m.width,onChange:b=>D(a,u,"width",b.target.value)})]}),t.length>1?(0,$.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>a(b=>b.filter((v,N)=>N!==u)),children:"Remove"}):null]},`wall-${u}`)),(0,$.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>a(m=>[...m,dc()]),children:"+ Add another wall"})]}),(0,$.jsxs)("div",{className:"paint-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Areas to exclude"}),(0,$.jsx)("p",{className:"paint-calculator__hint",children:"Add windows, sockets, skirting boards or other areas that will not be painted."}),(0,$.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,$.jsx)("span",{}),(0,$.jsx)("span",{children:"Height (m)"}),(0,$.jsx)("span",{children:"Width (m)"}),(0,$.jsx)("span",{})]}),r.map((m,u)=>(0,$.jsxs)("div",{className:"paint-calculator__row",children:[(0,$.jsxs)("span",{className:"paint-calculator__row-label",children:["Area ",u+1]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,$.jsx)("input",{"aria-label":`Area ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:m.height,onChange:b=>D(i,u,"height",b.target.value)})]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,$.jsx)("input",{"aria-label":`Area ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:m.width,onChange:b=>D(i,u,"width",b.target.value)})]}),r.length>1?(0,$.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(b=>b.filter((v,N)=>N!==u)),children:"Remove"}):null]},`excluded-${u}`)),(0,$.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(m=>[...m,dc()]),children:"+ Add another area"})]}),(0,$.jsxs)("div",{className:"paint-calculator__section",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Doors and coats"}),(0,$.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,$.jsxs)("div",{className:"truss-estimator__field-grid paint-calculator__small-fields",children:[(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{children:"Doors"}),(0,$.jsx)("input",{type:"number",min:"0",step:"1",value:n,onChange:m=>o(m.target.value)})]}),(0,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{children:"Double doors"}),(0,$.jsx)("input",{type:"number",min:"0",step:"1",value:l,onChange:m=>c(m.target.value)})]})]}),(0,$.jsxs)("div",{className:"paint-calculator__coat-field",children:[(0,$.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,$.jsxs)("label",{className:"truss-estimator__field",children:[(0,$.jsx)("span",{children:"Number of coats"}),(0,$.jsxs)("select",{value:p,onChange:m=>d(Number(m.target.value)),children:[(0,$.jsx)("option",{value:"1",children:"1 coat"}),(0,$.jsx)("option",{value:"2",children:"2 coats"}),(0,$.jsx)("option",{value:"3",children:"3 coats"})]})]})]})]}),(0,$.jsxs)("div",{className:"paint-calculator__totals",children:[(0,$.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,$.jsxs)("div",{className:"paint-calculator__result-grid",children:[(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Paintable area"}),(0,$.jsxs)("strong",{children:[w.toFixed(2)," m\xB2"]})]}),(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Coverage"}),(0,$.jsxs)("strong",{children:[p," ",p===1?"coat":"coats"]})]}),(0,$.jsxs)("div",{children:[(0,$.jsx)("span",{children:"Paint required"}),(0,$.jsxs)("strong",{children:[M.toFixed(1)," litres"]})]})]}),(0,$.jsx)("p",{className:"paint-calculator__note",children:"Based on paint coverage of 10 m\xB2 per litre. Decorative paint is not currently stocked in this catalogue, so this remains an estimate only."})]}),(0,$.jsxs)("div",{className:"paint-calculator__actions",children:[(0,$.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,$.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",disabled:!0,children:"Paint products unavailable"})]})]})]})})}var br=X(Xe()),ne=X(ie()),fc=e=>Number.parseFloat(e)||0,Bd={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 Ld({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,br.useState)("paving"),[n,o]=(0,br.useState)("council"),[l,c]=(0,br.useState)(""),[p,d]=(0,br.useState)(""),[g,f]=(0,br.useState)("100"),[h,w]=(0,br.useState)("50"),[M,D]=(0,br.useState)(!0),[m,u]=(0,br.useState)(!0),b=fc(l)*fc(p),v=b,N=b*(fc(g)/1e3),A=b*.04,T=b*(fc(h)/1e3),z=Math.ceil(v/.36),G=Math.ceil(v/.1),P=Math.ceil(N*1700/800),be=Math.ceil(A*1600/800),De=Math.ceil(T*1600/800),Le=r==="paving"?{qty:z,unit:"each"}:r==="block"?{qty:v,unit:"m2"}:{qty:De,unit:"bag"},He={paving:"paving slab",block:"block paver",gravel:"decorative gravel"}[r],ze=[{key:`surface-${n}`,label:Bd[r].find(ce=>ce.id===n)?.label??"Surface material",qty:Le.qty,unit:Le.unit,query:He,category:"landscaping"},...M?[{key:"sub-base",label:"MOT Type 1 sub-base",qty:P,unit:"bag",query:"MOT Type 1 sub base",category:"aggregate"}]:[],...m?[{key:"bedding",label:"Sharp sand bedding",qty:be,unit:"bag",query:"sharp sand",category:"aggregate"}]:[]];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:"Paving and Driveway Calculator"}),(0,ne.jsx)("p",{children:"Estimate paving, block paving, sub-base and bedding materials for outdoor areas."})]}),(0,ne.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,ne.jsx)("h2",{className:"truss-estimator__step-title",children:"Surface and ground build-up"}),(0,ne.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,ne.jsxs)("div",{className:"materials-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Surface material"}),(0,ne.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(([ce,fe,Ee])=>(0,ne.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===ce?" is-selected":""}`,onClick:()=>{i(ce),o(Bd[ce][0].id)},children:[(0,ne.jsx)("div",{className:"truss-estimator__option-title",children:fe}),(0,ne.jsx)("div",{className:"truss-estimator__option-copy",children:Ee})]},ce))}),(0,ne.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,ne.jsx)("span",{children:"Finish"}),(0,ne.jsx)("select",{value:n,onChange:ce=>o(ce.target.value),children:Bd[r].map(ce=>(0,ne.jsx)("option",{value:ce.id,children:ce.label},ce.id))})]})]}),(0,ne.jsxs)("div",{className:"materials-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and groundwork"}),(0,ne.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsx)("span",{children:"Length (m)"}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:ce=>c(ce.target.value)})]}),(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsx)("span",{children:"Width (m)"}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:ce=>d(ce.target.value)})]})]}),r==="gravel"&&(0,ne.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,ne.jsx)("span",{children:"Gravel depth (mm)"}),(0,ne.jsx)("input",{type:"number",min:"0",step:"10",value:h,onChange:ce=>w(ce.target.value)})]}),M&&(0,ne.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,ne.jsx)("span",{children:"Sub-base depth (mm)"}),(0,ne.jsx)("input",{type:"number",min:"0",step:"10",value:g,onChange:ce=>f(ce.target.value)})]}),(0,ne.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,ne.jsx)("input",{type:"checkbox",checked:M,onChange:ce=>D(ce.target.checked)}),(0,ne.jsx)("span",{children:"Include MOT Type 1 sub-base"})]}),(0,ne.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,ne.jsx)("input",{type:"checkbox",checked:m,onChange:ce=>u(ce.target.checked)}),(0,ne.jsx)("span",{children:"Include sharp sand bedding"})]})]}),(0,ne.jsxs)("div",{className:"materials-calculator__totals",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ne.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Surface area"}),(0,ne.jsxs)("strong",{children:[b.toFixed(2)," m\xB2"]})]}),(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:r==="paving"?"Paving slabs":r==="block"?"Block paving":"Gravel"}),(0,ne.jsx)("strong",{children:r==="paving"?`${z} slabs`:r==="block"?`${v.toFixed(2)} m\xB2`:`${De} bulk bags`})]}),M&&(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"MOT Type 1"}),(0,ne.jsxs)("strong",{children:[P," bulk bags"]})]}),m&&(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Sharp sand"}),(0,ne.jsxs)("strong",{children:[be," bulk bags"]})]})]}),(0,ne.jsx)("p",{className:"materials-calculator__note",children:"Slab and block quantities use typical sizes. Confirm pack coverage and laying pattern before ordering."})]}),(0,ne.jsxs)("div",{className:"materials-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?.(ze),disabled:b<=0,children:a})]})]})]})})}var ll=X(Xe()),oe=X(ie()),V_=2.88,Sw=[{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"}],Cw=()=>({length:"",height:""}),Hd=e=>Number.parseFloat(e)||0;function jd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,ll.useState)([Cw()]),[n,o]=(0,ll.useState)(""),[l,c]=(0,ll.useState)("standard"),[p,d]=(0,ll.useState)("screws"),g=r.reduce((A,T)=>A+Hd(T.length)*Hd(T.height),0),f=Math.max(0,g-Hd(n)),h=Math.ceil(f/V_),w=Math.ceil(f*12),M=Math.ceil(w/1e3),D=Math.ceil(f*1.2),m=Math.ceil(D/90),u=Math.ceil(f/3.5),b=Sw.find(A=>A.id===l)?.label??"Standard",v=[{key:"board",label:`${b} plasterboard`,qty:h,unit:"sheet",query:`${b} plasterboard`,category:"plasterboard"},...p==="screws"?[{key:"screws",label:"Drywall screws",qty:M,unit:"box",query:"drywall screws",category:"fixings"}]:[{key:"adhesive",label:"Board adhesive",qty:u,unit:"bag",query:"drywall board adhesive",category:"plasterboard"}],{key:"tape",label:"Joint tape",qty:m,unit:"roll",query:"plasterboard joint tape",category:"plasterboard"}],N=(A,T,z)=>{i(G=>G.map((P,be)=>be===A?{...P,[T]:z}:P))};return(0,oe.jsx)(oe.Fragment,{children:(0,oe.jsxs)("div",{className:"truss-estimator",children:[(0,oe.jsxs)("div",{className:"quick-order-hero",children:[(0,oe.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,oe.jsx)("h1",{children:"Plasterboard and Drylining Calculator"}),(0,oe.jsx)("p",{children:"Estimate boards, fixings and jointing materials for walls and ceilings."})]}),(0,oe.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,oe.jsx)("h2",{className:"truss-estimator__step-title",children:"Boards, fixings and jointing"}),(0,oe.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,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Board type"}),(0,oe.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Sw.map(A=>(0,oe.jsxs)("button",{type:"button",className:`truss-estimator__option-card${l===A.id?" is-selected":""}`,onClick:()=>c(A.id),children:[(0,oe.jsx)("div",{className:"truss-estimator__option-title",children:A.label}),(0,oe.jsx)("div",{className:"truss-estimator__option-copy",children:A.blurb})]},A.id))})]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Fixing method"}),(0,oe.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(([A,T,z])=>(0,oe.jsxs)("button",{type:"button",className:`truss-estimator__option-card${p===A?" is-selected":""}`,onClick:()=>d(A),children:[(0,oe.jsx)("div",{className:"truss-estimator__option-title",children:T}),(0,oe.jsx)("div",{className:"truss-estimator__option-copy",children:z})]},A))})]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall and ceiling areas"}),(0,oe.jsx)("p",{className:"materials-calculator__hint",children:"Add each surface separately so different wall sizes are easy to measure."}),(0,oe.jsxs)("div",{className:"materials-calculator__dimensions-header",children:[(0,oe.jsx)("span",{children:"Surface"}),(0,oe.jsx)("span",{children:"Length (m)"}),(0,oe.jsx)("span",{children:"Height (m)"}),(0,oe.jsx)("span",{})]}),r.map((A,T)=>(0,oe.jsxs)("div",{className:"materials-calculator__surface-row",children:[(0,oe.jsxs)("span",{children:["Surface ",T+1]}),(0,oe.jsx)("input",{"aria-label":`Surface ${T+1} length`,type:"number",min:"0",step:"0.01",value:A.length,onChange:z=>N(T,"length",z.target.value)}),(0,oe.jsx)("input",{"aria-label":`Surface ${T+1} height`,type:"number",min:"0",step:"0.01",value:A.height,onChange:z=>N(T,"height",z.target.value)}),r.length>1?(0,oe.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(z=>z.filter((G,P)=>P!==T)),children:"Remove"}):null]},`surface-${T}`)),(0,oe.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(A=>[...A,Cw()]),children:"+ Add another surface"}),(0,oe.jsxs)("label",{className:"truss-estimator__field materials-calculator__openings",children:[(0,oe.jsxs)("span",{children:["Openings to deduct (m\xB2) ",(0,oe.jsx)("small",{children:"optional"})]}),(0,oe.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:A=>o(A.target.value)})]})]}),(0,oe.jsxs)("div",{className:"materials-calculator__totals",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,oe.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:"Board area"}),(0,oe.jsxs)("strong",{children:[f.toFixed(2)," m\xB2"]})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:"2.4 x 1.2 m boards"}),(0,oe.jsx)("strong",{children:h})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:p==="screws"?"Drywall screws":"Board adhesive"}),(0,oe.jsx)("strong",{children:p==="screws"?`${w} (${M} boxes)`:`${u} bags`})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:"Joint tape"}),(0,oe.jsxs)("strong",{children:[D," m (",m," rolls)"]})]})]}),(0,oe.jsx)("p",{className:"materials-calculator__note",children:"Figures are estimates. Confirm board specification, fixing patterns and fire or acoustic requirements before ordering."})]}),(0,oe.jsxs)("div",{className:"materials-calculator__actions",children:[(0,oe.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,oe.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(v),disabled:f<=0,children:a})]})]})]})})}var sl=X(Xe());var _=X(ie()),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}}}},gc=["range","pitchAndDimensions","quantityAndGirders","bracing"],$_={range:null,pitch:null,spanMM:"",overhangMM:"",roofLengthM:"",centres:null,girderCount:0,bracing:null,treatment:null,contact:{name:"",email:""}};function Z_({degrees:e}){let a=e*Math.PI/180,i=82-Math.min(58,38*Math.tan(a));return(0,_.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,_.jsx)("line",{x1:"6",y1:"82",x2:"94",y2:"82",stroke:"var(--border)",strokeWidth:"2"}),(0,_.jsx)("polygon",{points:`12,82 88,82 50,${i}`,fill:"var(--accent-light)",stroke:"var(--accent)",strokeWidth:"3",strokeLinejoin:"round"})]})}function K_({type:e}){let t="#b3835a",a="#5c3b22",r="#d9b48f",i="#d3d8de",n="#7c8494",o=(d,g,f,h,w=8,M)=>{let D=f-d,m=h-g,u=Math.hypot(D,m)||1,b=-m/u,v=D/u,N=w*.2;return(0,_.jsxs)("g",{children:[(0,_.jsx)("line",{x1:d,y1:g,x2:f,y2:h,stroke:a,strokeWidth:w+3,strokeLinecap:"square"}),(0,_.jsx)("line",{x1:d,y1:g,x2:f,y2:h,stroke:t,strokeWidth:w,strokeLinecap:"square"}),(0,_.jsx)("line",{x1:d-b*N,y1:g-v*N,x2:f-b*N,y2:h-v*N,stroke:r,strokeWidth:Math.max(1.5,w*.24),strokeLinecap:"round",opacity:"0.9"})]},M)},l=(d,g,f)=>(0,_.jsxs)("g",{children:[(0,_.jsx)("rect",{x:d-7.5,y:g-5.5,width:"15",height:"11",rx:"2",fill:i,stroke:n,strokeWidth:"1"}),(0,_.jsx)("circle",{cx:d-4,cy:g-2.5,r:"1",fill:n}),(0,_.jsx)("circle",{cx:d+4,cy:g-2.5,r:"1",fill:n}),(0,_.jsx)("circle",{cx:d-4,cy:g+2.5,r:"1",fill:n}),(0,_.jsx)("circle",{cx:d+4,cy:g+2.5,r:"1",fill:n}),(0,_.jsx)("circle",{cx:d,cy:g,r:"1",fill:n})]},f),c=(d,g)=>(0,_.jsx)("rect",{x:d-9,y:"110",width:"18",height:"10",fill:a},g),p=(0,_.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"});return e==="attic"?(0,_.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,_.jsx)("rect",{x:"90",y:"82",width:"20",height:"24",fill:"#cfe3f2",stroke:a,strokeWidth:"2"}),(0,_.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,_.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,_.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,_.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 P_({enabled:e}){return(0,_.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[(0,_.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"}),(0,_.jsx)("rect",{x:"17",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,_.jsx)("rect",{x:"165",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,_.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,_.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,_.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,_.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,_.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,_.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),e?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("line",{x1:"45",y1:"112",x2:"140",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"}),(0,_.jsx)("line",{x1:"155",y1:"112",x2:"60",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"})]}):null,(0,_.jsx)("rect",{x:"18.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,_.jsx)("rect",{x:"166.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,_.jsx)("rect",{x:"92.5",y:"28.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"})]})}function qw({treated:e}){let t=e?"#5a7a4a":"var(--accent)";return(0,_.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,_.jsx)("rect",{x:"10",y:"22",width:"80",height:"14",rx:"2",fill:t}),(0,_.jsx)("rect",{x:"10",y:"43",width:"80",height:"14",rx:"2",fill:e?"#8faf7a":"var(--accent-light)"}),(0,_.jsx)("rect",{x:"10",y:"64",width:"80",height:"14",rx:"2",fill:t})]})}function Qd({onBack:e}){let[t,a]=(0,sl.useState)(0),[r,i]=(0,sl.useState)($_),[n,o]=(0,sl.useState)(!1),[l,c]=(0,sl.useState)(!1),p=()=>{let m=Number.parseFloat(r.roofLengthM)||0,u=Number.parseFloat(r.centres??"");return m<=0||!u?0:Math.ceil(m*1e3/u)+1},g=(()=>{let m=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,A=(Number.parseFloat(r.overhangMM)||0)>Rt.overhang.thresholdMM,T=p(),z=T+r.girderCount,G=Number.parseFloat(r.roofLengthM)||0,P=r.treatment?Rt.treatment[r.treatment]:Rt.treatment.untreated,be=Rt.estimate.ranges[r.range??"standard"],De=be.supplyAt8m*Math.max(.7,v/8)*b*(1+P.surchargePct)+(A?Rt.overhang.surchargePerTruss:0),Le=T*De,He=r.girderCount*De*Rt.estimate.girderMultiplier,ze=r.bracing==="yes"?G*Rt.estimate.bracingPerMetre:0,me=Le+He+ze+Rt.estimate.delivery,ce=Rt.estimate.design+T*be.installPerTruss+r.girderCount*40,fe=me+ce,Ee=fe*.2;return{range:m,count:T,girderCount:r.girderCount,overhangApplies:A,overhangUnits:z,roofLengthM:G,treatment:P,trussSupply:Le,bracingMaterials:ze,delivery:Rt.estimate.delivery,labour:ce,subtotal:fe,vat:Ee,total:fe+Ee}})(),f=()=>{let m=gc[t];return m==="range"?!!r.range:m==="pitchAndDimensions"?!!r.pitch&&r.spanMM.trim()!==""&&r.overhangMM.trim()!=="":m==="quantityAndGirders"?r.roofLengthM.trim()!==""&&!!r.centres:m==="bracing"?!!r.bracing&&!!r.treatment:!0},h=t===gc.length-1?"View truss request":"Next",w=()=>{n?o(!1):t===0?e():a(m=>m-1)},M=()=>{f()&&(t===gc.length-1?(c(!1),o(!0)):a(m=>m+1))},D=()=>{let m=gc[t];return m==="range"?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Step 1 of 4"}),(0,_.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your truss range"}),(0,_.jsx)("p",{className:"truss-estimator__step-sub",children:"Pricing shown is placeholder. Swap in your real engineering and pricing catalogue."}),(0,_.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--range",children:Object.entries(Rt.ranges).map(([u,b])=>(0,_.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r.range===u?" is-selected":""}`,onClick:()=>i(v=>({...v,range:u})),children:[(0,_.jsx)(K_,{type:u}),(0,_.jsxs)("div",{className:"truss-estimator__option-info",children:[(0,_.jsx)("div",{className:"truss-estimator__option-title",children:b.label}),(0,_.jsx)("div",{className:"truss-estimator__option-copy",children:b.blurb})]})]},u))})]}):m==="pitchAndDimensions"?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Step 2 of 4"}),(0,_.jsx)("h2",{className:"truss-estimator__step-title",children:"Span, overhang and roof pitch"}),(0,_.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,_.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,_.jsxs)("label",{className:"truss-estimator__field",children:[(0,_.jsx)("span",{children:"Span (mm)"}),(0,_.jsx)("input",{type:"text",inputMode:"numeric",value:r.spanMM,onChange:u=>i(b=>({...b,spanMM:u.target.value}))})]}),(0,_.jsxs)("label",{className:"truss-estimator__field",children:[(0,_.jsx)("span",{children:"Overhang (mm)"}),(0,_.jsx)("input",{type:"text",inputMode:"numeric",value:r.overhangMM,onChange:u=>i(b=>({...b,overhangMM:u.target.value}))}),(0,_.jsxs)("small",{children:["Overhangs beyond ",Rt.overhang.thresholdMM,"mm add a small surcharge per truss."]})]})]}),(0,_.jsx)("div",{className:"truss-estimator__section-heading",children:"Roof pitch"}),(0,_.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:Rt.pitches.map(u=>(0,_.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${r.pitch===u?" is-selected":""}`,onClick:()=>i(b=>({...b,pitch:u})),children:[(0,_.jsx)(Z_,{degrees:Number.parseFloat(u)}),(0,_.jsxs)("span",{children:[u,"\xB0"]})]},u))})]}):m==="quantityAndGirders"?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Step 3 of 4"}),(0,_.jsx)("h2",{className:"truss-estimator__step-title",children:"Roof length"}),(0,_.jsx)("p",{className:"truss-estimator__step-sub",children:"Trusses are based on designs at 400mm or 600mm centres wherever possible."}),(0,_.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,_.jsx)("span",{children:"Roof length (m)"}),(0,_.jsx)("input",{type:"text",inputMode:"decimal",value:r.roofLengthM,onChange:u=>i(b=>({...b,roofLengthM:u.target.value}))})]}),(0,_.jsx)("div",{className:"truss-estimator__section-heading",children:"Truss centres"}),(0,_.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--centres",children:Rt.centresOptions.map(u=>(0,_.jsx)("button",{type:"button",className:`truss-estimator__option-card truss-estimator__option-card--compact${r.centres===u?" is-selected":""}`,onClick:()=>i(b=>({...b,centres:u})),children:(0,_.jsxs)("div",{className:"truss-estimator__option-title",children:[u,"mm centres"]})},u))}),(0,_.jsxs)("div",{className:"truss-estimator__stat",children:[p()," trusses estimated"]}),(0,_.jsx)("div",{className:"truss-estimator__section-heading",children:"Girder trusses"}),(0,_.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,_.jsxs)("div",{className:"truss-estimator__stepper",children:[(0,_.jsx)("button",{type:"button",onClick:()=>i(u=>({...u,girderCount:Math.max(0,u.girderCount-1)})),children:"\u2212"}),(0,_.jsx)("span",{children:r.girderCount}),(0,_.jsx)("button",{type:"button",onClick:()=>i(u=>({...u,girderCount:Math.min(3,u.girderCount+1)})),children:"+"})]})]}):m==="bracing"?(0,_.jsxs)(_.Fragment,{children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Step 4 of 4"}),(0,_.jsx)("h2",{className:"truss-estimator__step-title",children:"Bracing pack?"}),(0,_.jsx)("p",{className:"truss-estimator__step-sub",children:"A timber bracing pack stabilises the roof structure once trusses are erected."}),(0,_.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,_.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.bracing===u.id?" is-selected":""}`,onClick:()=>i(b=>({...b,bracing:u.id})),children:[(0,_.jsx)(P_,{enabled:u.id==="yes"}),(0,_.jsx)("span",{children:u.label})]},u.id))}),(0,_.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber treatment"}),(0,_.jsx)("p",{className:"truss-estimator__step-sub",children:"Tanalised timber protects against rot in exposed or damp locations."}),(0,_.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,_.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.treatment==="untreated"?" is-selected":""}`,onClick:()=>i(u=>({...u,treatment:"untreated"})),children:[(0,_.jsx)(qw,{treated:!1}),(0,_.jsx)("span",{children:"Untreated"})]}),(0,_.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.treatment==="treated"?" is-selected":""}`,onClick:()=>i(u=>({...u,treatment:"treated"})),children:[(0,_.jsx)(qw,{treated:!0}),(0,_.jsx)("span",{children:"Treated (+8% cost)"}),(0,_.jsx)("small",{children:"Applies to trusses, girders and overhang"})]})]})]}):null};return n?(0,_.jsx)(_.Fragment,{children:(0,_.jsxs)("div",{className:"truss-estimator",children:[(0,_.jsxs)("div",{className:"quick-order-hero",children:[(0,_.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,_.jsx)("h1",{children:"Your truss estimate"}),(0,_.jsx)("p",{children:"A provisional quantity and specification based on the dimensions you entered."})]}),(0,_.jsxs)("div",{className:"truss-estimator__card truss-request",style:{minHeight:0},children:[(0,_.jsxs)("div",{className:"truss-request__heading",children:[(0,_.jsxs)("div",{children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Estimated requirement"}),(0,_.jsxs)("h2",{children:[g.range.label," roof trusses"]})]}),(0,_.jsxs)("strong",{children:[g.count,(0,_.jsx)("span",{children:"trusses"})]})]}),(0,_.jsxs)("div",{className:"truss-request__grid",children:[(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Span"}),(0,_.jsxs)("strong",{children:[r.spanMM," mm"]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Roof length"}),(0,_.jsxs)("strong",{children:[r.roofLengthM," m"]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Pitch"}),(0,_.jsxs)("strong",{children:[r.pitch,"\xB0"]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Centres"}),(0,_.jsxs)("strong",{children:[r.centres," mm"]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Overhang"}),(0,_.jsxs)("strong",{children:[r.overhangMM," mm"]})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Treatment"}),(0,_.jsx)("strong",{children:g.treatment.label})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Girder trusses"}),(0,_.jsx)("strong",{children:g.girderCount||"None"})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Bracing pack"}),(0,_.jsx)("strong",{children:r.bracing==="yes"?"Included":"Not included"})]})]}),(0,_.jsxs)("div",{className:"truss-request__price",children:[(0,_.jsx)("div",{className:"truss-estimator__step-label",children:"Indicative cost estimate"}),(0,_.jsxs)("div",{className:"truss-request__price-grid",children:[(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Truss supply allowance"}),(0,_.jsx)("strong",{children:nt(g.trussSupply)})]}),g.bracingMaterials>0&&(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Bracing materials allowance"}),(0,_.jsx)("strong",{children:nt(g.bracingMaterials)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Delivery allowance"}),(0,_.jsx)("strong",{children:nt(g.delivery)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Design and installation labour"}),(0,_.jsx)("strong",{children:nt(g.labour)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Subtotal (ex. VAT)"}),(0,_.jsx)("strong",{children:nt(g.subtotal)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"VAT (20%)"}),(0,_.jsx)("strong",{children:nt(g.vat)})]}),(0,_.jsxs)("div",{className:"truss-request__price-total",children:[(0,_.jsx)("span",{children:"Estimated total"}),(0,_.jsx)("strong",{children:nt(g.total)})]})]}),(0,_.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,_.jsxs)("div",{className:"truss-request__notice",children:[(0,_.jsx)("strong",{children:"Before ordering"}),(0,_.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,_.jsxs)("div",{className:"truss-estimator__nav",children:[(0,_.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,_.jsx)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",justifyContent:"center",marginTop:0},onClick:()=>c(!0),children:"Request order"})]}),l&&(0,_.jsx)("p",{className:"truss-request__demo",children:"Demo only \u2014 no order has been sent."})]})]})}):(0,_.jsx)(_.Fragment,{children:(0,_.jsxs)("div",{className:"truss-estimator",children:[(0,_.jsxs)("div",{className:"quick-order-hero",children:[(0,_.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,_.jsx)("h1",{children:"Roof Truss Calculator"}),(0,_.jsx)("p",{children:"Estimate trusses, girders and cost for your roof in a few steps."})]}),(0,_.jsxs)("div",{className:"truss-estimator__card",children:[(0,_.jsx)("div",{className:"truss-estimator__body",children:D()}),(0,_.jsxs)("div",{className:"truss-estimator__nav",children:[(0,_.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:w,children:"Back"}),(0,_.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:M,disabled:!f(),children:[(0,_.jsx)("span",{children:h}),(0,_.jsx)("span",{className:"arrow",children:(0,_.jsx)(jt,{})})]})]})]})]})})}var Ci=X(Xe()),I=X(ie()),Tw=e=>Number.parseFloat(e)||0,hc=(e,t)=>Tw(e)*(t==="m"?1:.3048),Ew=()=>({length:"",width:""}),Mw=[{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 J_({profile:e}){return(0,I.jsxs)("svg",{className:"skirting-calculator__profile-diagram",viewBox:"0 0 120 84","aria-hidden":"true",children:[(0,I.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,I.jsx)("line",{x1:"12",y1:"70",x2:"108",y2:"70"})]})}function Gd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ci.useState)("total"),[n,o]=(0,Ci.useState)("m"),[l,c]=(0,Ci.useState)(""),[p,d]=(0,Ci.useState)([Ew()]),[g,f]=(0,Ci.useState)(""),[h,w]=(0,Ci.useState)("chamfered"),M="4.2",D=r==="total"?hc(l,n):p.reduce((N,A)=>N+2*(hc(A.length,n)+hc(A.width,n)),0),m=Math.max(0,D-hc(g,n)),u=Math.ceil(m/Tw(M)),b=[{key:`skirting-${h}`,label:`${Mw.find(N=>N.id===h)?.label} skirting board`,qty:m,unit:"m",query:"skirting board",category:"skirting"}],v=(N,A,T)=>{d(z=>z.map((G,P)=>P===N?{...G,[A]:T}:G))};return(0,I.jsx)(I.Fragment,{children:(0,I.jsxs)("div",{className:"truss-estimator",children:[(0,I.jsxs)("div",{className:"quick-order-hero",children:[(0,I.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,I.jsx)("h1",{children:"Skirting Board Calculator"}),(0,I.jsx)("p",{children:"Work out how many skirting board lengths you need for one room or a whole project."})]}),(0,I.jsxs)("div",{className:"truss-estimator__card skirting-calculator",children:[(0,I.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure by room or total length"}),(0,I.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,I.jsxs)("div",{className:"skirting-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"How would you like to measure?"}),(0,I.jsxs)("div",{className:"brick-calculator__unit-toggle skirting-calculator__mode-toggle",role:"group","aria-label":"Calculation method",children:[(0,I.jsx)("button",{type:"button",className:r==="total"?"is-selected":"",onClick:()=>i("total"),children:"Total length"}),(0,I.jsx)("button",{type:"button",className:r==="rooms"?"is-selected":"",onClick:()=>i("rooms"),children:"Room by room"})]})]}),(0,I.jsxs)("div",{className:"skirting-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Measurements"}),(0,I.jsxs)("div",{className:"skirting-calculator__unit-row",children:[(0,I.jsx)("span",{children:"Units"}),(0,I.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,I.jsx)("button",{type:"button",className:n==="m"?"is-selected":"",onClick:()=>o("m"),children:"Metres"}),(0,I.jsx)("button",{type:"button",className:n==="ft"?"is-selected":"",onClick:()=>o("ft"),children:"Feet"})]})]}),r==="total"?(0,I.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,I.jsxs)("span",{children:["Total skirting length (",n,")"]}),(0,I.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:N=>c(N.target.value)})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("div",{className:"skirting-calculator__dimensions-header",children:[(0,I.jsx)("span",{children:"Room"}),(0,I.jsxs)("span",{children:["Length (",n,")"]}),(0,I.jsxs)("span",{children:["Width (",n,")"]}),(0,I.jsx)("span",{})]}),p.map((N,A)=>(0,I.jsxs)("div",{className:"skirting-calculator__room-row",children:[(0,I.jsxs)("span",{className:"skirting-calculator__room-label",children:["Room ",A+1]}),(0,I.jsx)("input",{"aria-label":`Room ${A+1} length in ${n}`,type:"number",min:"0",step:"0.01",value:N.length,onChange:T=>v(A,"length",T.target.value)}),(0,I.jsx)("input",{"aria-label":`Room ${A+1} width in ${n}`,type:"number",min:"0",step:"0.01",value:N.width,onChange:T=>v(A,"width",T.target.value)}),p.length>1?(0,I.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>d(T=>T.filter((z,G)=>G!==A)),children:"Remove"}):null]},`room-${A}`)),(0,I.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>d(N=>[...N,Ew()]),children:"+ Add another room"})]}),(0,I.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,I.jsxs)("span",{children:["Openings and doorways to deduct (",n,") ",(0,I.jsx)("small",{children:"optional"})]}),(0,I.jsx)("input",{type:"number",min:"0",step:"0.01",value:g,onChange:N=>f(N.target.value)})]})]}),(0,I.jsxs)("div",{className:"skirting-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Profile"}),(0,I.jsx)("p",{className:"skirting-calculator__hint",children:"Choose the finish you want for the fixed 4.2m white-primed MDF boards."}),(0,I.jsx)("div",{className:"architrave-calculator__profiles",children:Mw.map(N=>(0,I.jsxs)("button",{type:"button",className:`truss-estimator__option-card${h===N.id?" is-selected":""}`,onClick:()=>w(N.id),children:[(0,I.jsx)(J_,{profile:N.id}),(0,I.jsx)("div",{className:"truss-estimator__option-title",children:N.label}),(0,I.jsx)("div",{className:"truss-estimator__option-copy",children:N.blurb})]},N.id))})]}),(0,I.jsxs)("div",{className:"skirting-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,I.jsx)("div",{className:"truss-estimator__field-grid skirting-calculator__options-grid",children:(0,I.jsxs)("label",{className:"truss-estimator__field",children:[(0,I.jsx)("span",{children:"Board length"}),(0,I.jsx)("input",{value:"4.20 m",disabled:!0})]})}),(0,I.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,I.jsxs)("div",{className:"skirting-calculator__totals",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,I.jsxs)("div",{className:"skirting-calculator__result-grid",children:[(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"Net skirting"}),(0,I.jsxs)("strong",{children:[m.toFixed(2)," m"]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"Board lengths"}),(0,I.jsx)("strong",{children:u})]})]}),(0,I.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,I.jsxs)("div",{className:"skirting-calculator__actions",children:[(0,I.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,I.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(b),disabled:m<=0,children:a})]})]})]})})}var jn=X(Xe()),le=X(ie()),cl=e=>Number.parseFloat(e)||0;function Yd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,jn.useState)("studs"),[n,o]=(0,jn.useState)(""),[l,c]=(0,jn.useState)(""),[p,d]=(0,jn.useState)("600"),[g,f]=(0,jn.useState)("2.4"),h=n&&l&&p?Math.ceil(cl(l)/(cl(p)/1e3))+1:0,w=h*cl(n),M=cl(g)>0?Math.ceil(w/cl(g)):0,D=[{key:r,label:{studs:"Stud timber",joists:"Joist timber",battens:"Batten timber"}[r],qty:w,unit:"m",query:{studs:"cls studwork timber",joists:"timber joist",battens:"roofing batten"}[r],category:"timber"}],m={studs:["Stud wall","Vertical studs along a wall length"],joists:["Joists","Parallel joists across a floor or deck"],battens:["Battens","Regularly spaced battens for lining or cladding"]},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,le.jsx)(le.Fragment,{children:(0,le.jsxs)("div",{className:"truss-estimator",children:[(0,le.jsxs)("div",{className:"quick-order-hero",children:[(0,le.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,le.jsx)("h1",{children:"Timber Calculator"}),(0,le.jsx)("p",{children:"Estimate studs, joists or battens from a run length, width and spacing."})]}),(0,le.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,le.jsx)("h2",{className:"truss-estimator__step-title",children:"Member size and spacing"}),(0,le.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,le.jsxs)("div",{className:"materials-calculator__section",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber use"}),(0,le.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:Object.keys(m).map(v=>(0,le.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===v?" is-selected":""}`,onClick:()=>i(v),children:[(0,le.jsx)("div",{className:"truss-estimator__option-title",children:m[v][0]}),(0,le.jsx)("div",{className:"truss-estimator__option-copy",children:m[v][1]})]},v))})]}),(0,le.jsxs)("div",{className:"materials-calculator__section",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Dimensions and spacing"}),(0,le.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsxs)("span",{children:[b.member," (m)"]}),(0,le.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:v=>o(v.target.value)})]}),(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsxs)("span",{children:[b.overall," (m)"]}),(0,le.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:v=>c(v.target.value)})]})]}),(0,le.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsx)("span",{children:"Centres (mm)"}),(0,le.jsxs)("select",{value:p,onChange:v=>d(v.target.value),children:[(0,le.jsx)("option",{value:"300",children:"300 mm"}),(0,le.jsx)("option",{value:"400",children:"400 mm"}),(0,le.jsx)("option",{value:"450",children:"450 mm"}),(0,le.jsx)("option",{value:"600",children:"600 mm"})]})]}),(0,le.jsxs)("label",{className:"truss-estimator__field",children:[(0,le.jsx)("span",{children:"Stock length (m)"}),(0,le.jsxs)("select",{value:g,onChange:v=>f(v.target.value),children:[(0,le.jsx)("option",{value:"2.4",children:"2.40 m"}),(0,le.jsx)("option",{value:"3.6",children:"3.60 m"}),(0,le.jsx)("option",{value:"4.8",children:"4.80 m"})]})]})]})]}),(0,le.jsxs)("div",{className:"materials-calculator__totals",children:[(0,le.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,le.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{children:b.count}),(0,le.jsx)("strong",{children:h})]}),(0,le.jsxs)("div",{children:[(0,le.jsx)("span",{children:"Linear metres"}),(0,le.jsxs)("strong",{children:[w.toFixed(2)," m"]})]}),(0,le.jsxs)("div",{children:[(0,le.jsxs)("span",{children:[g," m lengths"]}),(0,le.jsx)("strong",{children:M})]})]}),(0,le.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,le.jsxs)("div",{className:"materials-calculator__actions",children:[(0,le.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,le.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(D),disabled:w<=0,children:a})]})]})]})})}var Xd=[{id:"truss",title:"Roof Truss Calculator",desc:"Estimate trusses, girders and roof structure costs.",imageUrl:"/tool-images/truss.webp",Component:Qd},{id:"fencing",title:"Fencing Calculator",desc:"Estimate fence panels, posts, gravel boards and fixings.",imageUrl:"/tool-images/fencing.webp",Component:Ud},{id:"decking",title:"Decking Calculator",desc:"Estimate boards, substructure and fixing quantities.",imageUrl:"/tool-images/decking.webp",Component:Rd},{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:Ed},{id:"paint",title:"Paint Calculator",desc:"Estimate paint for walls, doors and multiple coats.",imageUrl:"/tool-images/paint.webp",Component:Od},{id:"skirting",title:"Skirting Board Calculator",desc:"Estimate skirting lengths for rooms and wall runs.",imageUrl:"/tool-images/skirting.webp",Component:Gd},{id:"architrave",title:"Architrave Calculator",desc:"Estimate architrave lengths for door and window openings.",imageUrl:"/tool-images/architrave.webp",Component:qd},{id:"concrete-aggregate",title:"Concrete and Aggregate Calculator",desc:"Estimate concrete, MOT, sand and gravel quantities.",imageUrl:"/tool-images/concrete-aggregate.webp",Component:zd},{id:"plasterboard",title:"Plasterboard Calculator",desc:"Estimate plasterboard sheets, screws, tape and adhesive.",imageUrl:"/tool-images/plasterboard.webp",Component:jd},{id:"insulation",title:"Insulation Calculator",desc:"Estimate insulation packs for floors, walls, roofs and lofts.",imageUrl:"/tool-images/insulation.webp",Component:Dd},{id:"timber",title:"Timber Calculator",desc:"Estimate studs, joists and battens from spacing and lengths.",imageUrl:"/tool-images/timber.webp",Component:Yd},{id:"paving",title:"Paving and Driveway Calculator",desc:"Estimate paving, block paving, MOT and sharp sand.",imageUrl:"/tool-images/paving.webp",Component:Ld}];var vc=X(Xe());var Ge=X(Xe());var S=X(ie()),F_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}],Vd={wasteFactorEnabled:!0},I_=3e3,zw=null;function bc(e,t){let a=el(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function W_(e){return e&&e.length>0?e.join(" x "):"-"}function $d({toolId:e,requirements:t,ready:a,onBack:r,onTotalChange:i}){let n=ac(),o=`${e}~${t.map(q=>`${q.key}|${q.query}|${q.category??""}|${q.qty}`).join("~")}`,l=o!==zw,[c,p]=(0,Ge.useState)(null),[d,g]=(0,Ge.useState)([]),[f,h]=(0,Ge.useState)(l),[w,M]=(0,Ge.useState)(null),[D,m]=(0,Ge.useState)("tile"),[u,b]=(0,Ge.useState)(null),[v,N]=(0,Ge.useState)(""),[A,T]=(0,Ge.useState)(null),[z,G]=(0,Ge.useState)(""),[P,be]=(0,Ge.useState)([]),[De,Le]=(0,Ge.useState)(new Set),[He,ze]=(0,Ge.useState)(null),[me,ce]=(0,Ge.useState)(""),[fe,Ee]=(0,Ge.useState)([]),ut=(0,Ge.useRef)(null),Se=(0,Ge.useRef)(!1),Z=q=>`${e}:${q}`,de=q=>Pr(q.chosen,{lineId:Z(q.requirement.key),description:q.requirement.label,unit:q.requirement.unit,qty:q.requirement.qty}),Je=(0,Ge.useMemo)(()=>t.map(q=>`${q.key}|${q.query}|${q.category??""}`).join("~"),[t]);(0,Ge.useEffect)(()=>{let q=!1;return vw().then(Y=>{q||p(Y.itemCount>0)}).catch(()=>{q||p(!1)}),()=>{q=!0}},[]),(0,Ge.useEffect)(()=>{if(!a||!c)return;let q=!1,Y;l&&h(!0),M(null);let K=Date.now();return(async()=>{let pe=null;try{pe=(await bw(t)).map(({requirement:Fe,candidates:xt})=>({requirement:Fe,candidates:xt,chosen:xt[0]??null}))}catch(ke){q||M(ke instanceof Error?ke.message:"Could not load products")}if(!q){if(zw=o,l){let ke=I_-(Date.now()-K);ke>0&&await new Promise(Fe=>{Y=window.setTimeout(Fe,ke)})}q||(pe&&(g(pe),!Se.current&&n&&(Se.current=!0,n.addManyToCart(pe.filter(ke=>ke.chosen).map(de)))),h(!1))}})(),()=>{q=!0,window.clearTimeout(Y)}},[a,c,Je]),(0,Ge.useEffect)(()=>{if(!A)return;let q=z.trim();if(!q){be([]);return}let Y=!1,K=window.setTimeout(()=>{Fr(q).then(pe=>{Y||be(pe)}).catch(()=>{Y||be([])})},250);return()=>{Y=!0,window.clearTimeout(K)}},[A,z]),(0,Ge.useEffect)(()=>{if(!He)return;let q=me.trim();if(!q){Ee([]);return}let Y=!1,K=window.setTimeout(()=>{Fr(q).then(pe=>{Y||Ee(pe)}).catch(()=>{Y||Ee([])})},250);return()=>{Y=!0,window.clearTimeout(K)}},[He,me]);let Ye=(0,Ge.useMemo)(()=>{let q=v.trim().toLowerCase(),Y=q?d.filter(K=>K.requirement.label.toLowerCase().includes(q)||(K.chosen?.description??"").toLowerCase().includes(q)||(K.chosen?.product_id??"").toLowerCase().includes(q)):d;return u?[...Y].sort((K,pe)=>{let ke=K.requirement.label.localeCompare(pe.requirement.label);return u==="asc"?ke:-ke}):Y},[d,v,u]),pt=Ye.filter(q=>q.chosen),ot=Ye.filter(q=>!q.chosen),at=d.filter(q=>q.chosen),ge=at.filter(q=>q.chosen?.price==null).length,W=at.reduce((q,Y)=>q+(Dt(de(Y),Vd).lineTotal??0),0);if((0,Ge.useEffect)(()=>{i?.(W)},[W,i]),!a||c===!1)return null;let k=n?at.filter(q=>n.cart[Z(q.requirement.key)]).length:0,R=He?d.find(q=>q.requirement.key===He)??null:null,O=me.trim()?fe:R?.candidates??[],ee=q=>{let Y=A===q.requirement.key;T(Y?null:q.requirement.key),G(Y?"":q.requirement.query)},xe=(q,Y)=>{let K=d.find(pe=>pe.requirement.key===q);g(pe=>pe.map(ke=>ke.requirement.key===q?{...ke,chosen:Y}:ke)),n&&K&&n.cart[Z(q)]&&n.addToCart(de({...K,chosen:Y})),T(null),G("")},we=q=>{g(Y=>Y.map(K=>K.requirement.key===q?{...K,chosen:null}:K)),n?.cart[Z(q)]&&n.removeFromCart(Z(q))},y=q=>{ze(q.requirement.key),ce(""),Ee([])},j=()=>{ze(null),ce(""),Ee([])},B=q=>{if(!n)return;let Y=Z(q.requirement.key);n.cart[Y]?n.removeFromCart(Y):n.addToCart(de(q))},ae=q=>{Le(Y=>{let K=new Set(Y);return K.has(q)?K.delete(q):K.add(q),K})},te=q=>{let Y=P.length>0?P:q.candidates;return(0,S.jsxs)("div",{className:"estimator-products__picker",children:[(0,S.jsx)("input",{type:"text",className:"results-search-input",value:z,autoFocus:!0,placeholder:"Search products in catalogue...",onChange:K=>G(K.target.value),"aria-label":`Search a product for ${q.requirement.label}`}),(0,S.jsxs)("div",{className:"estimator-products__options",children:[Y.map(K=>(0,S.jsxs)("button",{type:"button",className:`estimator-products__option${K.product_id===q.chosen?.product_id?" is-selected":""}`,onClick:()=>xe(q.requirement.key,K),children:[(0,S.jsx)("span",{children:K.description}),(0,S.jsxs)("span",{className:"results-row-meta",children:[K.product_id,K.price!=null&&` \xB7 ${nt(K.price)}`]})]},K.product_id)),Y.length===0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No matching products."})]})]})};return(0,S.jsxs)("section",{className:"estimator-products results-tile-section","aria-label":"Matched products",children:[!f&&(0,S.jsxs)("div",{className:"estimator-products__head",children:[(0,S.jsxs)("div",{className:"results-tile-section__head",children:[(0,S.jsx)("h3",{children:"Matched Products"}),(0,S.jsx)("p",{children:"Products matched to your estimate, check before adding to your basket."})]}),!R&&(0,S.jsxs)("div",{className:"results-summary estimator-products__toolbar",children:[ge>0&&(0,S.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,S.jsx)("strong",{children:ge})," need pricing"]}),(0,S.jsxs)("div",{className:"estimator-products__controls",children:[(0,S.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:v,onChange:q=>N(q.target.value),"aria-label":"Search matched products"}),(0,S.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,S.jsx)("button",{type:"button",className:`results-view-toggle__btn${D==="tile"?" is-active":""}`,"aria-pressed":D==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>m("tile"),children:(0,S.jsxs)("svg",{width:"18",height:"12",viewBox:"0 0 15 10",fill:"currentColor",children:[(0,S.jsx)("rect",{x:"0.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"5.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"10.5",y:"0.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"0.5",y:"5.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"5.5",y:"5.5",width:"4",height:"4"}),(0,S.jsx)("rect",{x:"10.5",y:"5.5",width:"4",height:"4"})]})}),(0,S.jsx)("button",{type:"button",className:`results-view-toggle__btn${D==="list"?" is-active":""}`,"aria-pressed":D==="list","aria-label":"List view",title:"List view",onClick:()=>m("list"),children:(0,S.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,S.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,S.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,S.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),(0,S.jsxs)("details",{ref:ut,style:{position:"relative"},children:[(0,S.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort materials",style:{fontSize:16},children:"\u21C5"}),(0,S.jsx)("div",{className:"sort-menu-panel",children:F_.map(q=>{let Y=u===q.dir;return(0,S.jsxs)("button",{type:"button",className:`sort-menu-item${Y?" is-active":""}`,onClick:()=>{b(Y?null:q.dir),ut.current?.removeAttribute("open")},children:[(0,S.jsx)("span",{className:"sort-menu-item__check",children:Y?"\u2713":""}),q.label]},q.dir)})})]})]})]})]}),R&&(0,S.jsxs)("div",{className:"results-review-page",children:[(0,S.jsxs)("div",{className:"results-review-page__top",children:[(0,S.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:j,children:[(0,S.jsx)(Kr,{}),"Back to results"]}),(0,S.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,S.jsx)("div",{className:"results-review-searchbar",children:(0,S.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:me,onChange:q=>ce(q.target.value),"aria-label":`Search a product for ${R.requirement.label}`})}),R.chosen&&(0,S.jsx)("div",{className:"results-candidate-actions",children:(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>we(R.requirement.key),children:"Clear selected product"})})]})]}),(0,S.jsxs)("div",{className:"results-review-page__hero",children:[(0,S.jsx)("div",{className:"results-review-page__image-wrap",children:(0,S.jsx)("img",{className:"fill-img results-review-page__image",src:Ya(R.chosen?.description||R.requirement.label,R.chosen?.product_id,R.chosen?.pdp_photo_url),alt:""})}),(0,S.jsxs)("div",{className:"results-review-page__summary",children:[(0,S.jsx)("h2",{children:R.requirement.label}),(0,S.jsxs)("p",{className:"results-review-page__meta",children:[yi(R.requirement.qty)," ",Na(R.requirement.unit,R.requirement.qty)]}),R.chosen?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("div",{className:"results-review-page__product",children:R.chosen.description}),(0,S.jsxs)("div",{className:"results-row-meta",children:[R.chosen.product_id,R.chosen.price!=null?` \xB7 ${bc(R.chosen.price,R.chosen.price_basis)}`:""]})]}):(0,S.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line."}),(0,S.jsx)("div",{className:"results-review-page__actions",children:(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${n?.cart[Z(R.requirement.key)]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>B(R),disabled:!R.chosen||!n,children:n?.cart[Z(R.requirement.key)]?"\u2713 Added":"+ Add to basket"})})]})]}),O.length===0?(0,S.jsx)("p",{className:"results-empty-hint",children:"No matching products."}):(0,S.jsxs)("table",{className:"score-breakdown-table",children:[(0,S.jsx)("thead",{children:(0,S.jsxs)("tr",{children:[(0,S.jsx)("th",{children:"Product"}),(0,S.jsx)("th",{children:"Dims (mm)"}),(0,S.jsx)("th",{children:"Price"}),(0,S.jsx)("th",{"aria-label":"Actions"})]})}),(0,S.jsx)("tbody",{children:O.map(q=>{let Y=q.product_id===R.chosen?.product_id;return(0,S.jsxs)("tr",{className:Y?"score-breakdown-row--best":"",children:[(0,S.jsxs)("td",{children:[(0,S.jsx)("div",{children:q.description}),(0,S.jsx)("div",{className:"results-row-meta",children:q.product_id})]}),(0,S.jsx)("td",{children:(0,S.jsx)("span",{className:"unit-badge",children:W_(q.measurements_mm)})}),(0,S.jsx)("td",{children:q.price!=null?bc(q.price,q.price_basis):"-"}),(0,S.jsx)("td",{children:(0,S.jsxs)("label",{className:"switch-toggle",title:Y?"Currently selected":"Use this candidate",children:[(0,S.jsx)("input",{type:"checkbox",checked:Y,onChange:()=>{Y?we(R.requirement.key):xe(R.requirement.key,q)},"aria-label":Y?`${q.description} selected`:`Use ${q.description}`}),(0,S.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},q.product_id)})})]})]}),!R&&f&&(0,S.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{padding:"32px 24px"},children:[(0,S.jsx)(fr,{}),(0,S.jsx)("p",{className:"banter-message is-visible",style:{fontSize:15,minHeight:0},children:"Matching your materials against the catalogue\u2026"})]}),!R&&w&&(0,S.jsx)("p",{className:"results-empty-hint estimator-products__error",children:w}),!R&&!f&&!w&&Ye.length===0&&d.length>0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No materials match the current search."}),!R&&!f&&!w&&D==="tile"&&pt.length>0&&(0,S.jsx)("div",{className:"results-tile-grid",children:pt.map(q=>{let{requirement:Y,chosen:K}=q,pe=K?Dt(de(q),Vd):null,ke=n?!!n.cart[Z(Y.key)]:!1;return(0,S.jsxs)("article",{className:"results-tile-card",children:[(0,S.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>y(q),"aria-label":`Review match for ${Y.label}`,children:[(0,S.jsx)("div",{className:"results-tile-card__media",children:(0,S.jsx)("img",{className:"fill-img results-tile-card__image",src:Ya(K?.description||Y.label,K?.product_id,K?.pdp_photo_url),alt:""})}),(0,S.jsxs)("div",{className:"results-tile-card__body",children:[K?(0,S.jsxs)("div",{className:"results-tile-card__heading",children:[(0,S.jsx)("div",{className:"results-tile-card__title",children:K.description}),(0,S.jsxs)("div",{className:"results-tile-card__match-meta",children:[(0,S.jsx)("span",{children:K.product_id}),K.price!=null?(0,S.jsx)("span",{children:bc(K.price,K.price_basis)}):null]})]}):(0,S.jsx)("div",{className:"results-empty-hint",children:"No product matched for this line."}),(0,S.jsxs)("div",{className:"results-tile-card__match",children:[(0,S.jsx)("div",{className:"results-tile-card__match-label",children:"\u21B3 calculated as"}),(0,S.jsx)("div",{className:"results-tile-card__match-name",children:Y.label}),(0,S.jsxs)("div",{className:"results-tile-card__meta",children:[yi(Y.qty)," ",Na(Y.unit,Y.qty)]}),pe?.requiredSellUnits!=null?(0,S.jsxs)("div",{className:"results-tile-card__meta estimator-products__order",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${nt(pe.lineTotal)}`:""]}):K?(0,S.jsx)("div",{className:"results-row-meta",children:"Quantity needs review"}):null]})]})]}),(0,S.jsxs)("div",{className:"results-tile-card__actions",children:[(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>y(q),children:"Review"}),(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${ke?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>B(q),disabled:!K||!n,children:ke?"\u2713 Added":"+ Add"})]})]},Y.key)})}),!R&&!f&&!w&&D==="list"&&pt.length>0&&(0,S.jsx)("div",{className:"bom-table-wrap",children:(0,S.jsxs)("table",{className:"bom-table results-table","aria-label":"Matched materials",children:[(0,S.jsxs)("colgroup",{children:[(0,S.jsx)("col",{style:{width:"56px"}}),(0,S.jsx)("col",{className:"col-item"}),(0,S.jsx)("col",{style:{width:"90px"}}),(0,S.jsx)("col",{style:{width:"80px"}}),(0,S.jsx)("col",{style:{width:"220px"}}),(0,S.jsx)("col",{style:{width:"110px"}})]}),(0,S.jsx)("thead",{children:(0,S.jsxs)("tr",{className:"bom-col-header",children:[(0,S.jsx)("th",{"aria-label":"Expand"}),(0,S.jsx)("th",{style:{textAlign:"left"},children:"Description"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Qty"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Unit"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Product Matched"}),(0,S.jsx)("th",{style:{textAlign:"center"},children:"Basket"})]})}),(0,S.jsx)("tbody",{children:pt.map(q=>{let{requirement:Y,chosen:K}=q,pe=K?Dt(de(q),Vd):null,ke=n?!!n.cart[Z(Y.key)]:!1,Fe=De.has(Y.key);return(0,S.jsxs)(Ge.Fragment,{children:[(0,S.jsxs)("tr",{className:"bom-row",children:[(0,S.jsx)("td",{className:"bom-actions",style:{textAlign:"center",paddingLeft:0,paddingRight:0},children:(0,S.jsx)("button",{type:"button",className:"link-btn",onClick:()=>ae(Y.key),"aria-expanded":Fe,"aria-label":Fe?"Collapse product options":"Expand product options",children:Fe?"\u25BE":"\u25B8"})}),(0,S.jsxs)("td",{style:{paddingLeft:0},children:[(0,S.jsx)("div",{className:"bom-component-name",children:Y.label}),pe?.requiredSellUnits!=null&&(0,S.jsxs)("div",{className:"results-row-meta",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${nt(pe.lineTotal)}`:""]})]}),(0,S.jsx)("td",{className:"bom-qty col-order",style:{textAlign:"center"},children:yi(Y.qty)}),(0,S.jsx)("td",{style:{textAlign:"center"},children:Na(Y.unit,Y.qty)}),(0,S.jsx)("td",{style:{textAlign:"center"},children:K?(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)("div",{className:"bom-component-name",children:K.description}),(0,S.jsxs)("div",{className:"results-row-meta",children:[K.product_id,K.price!=null&&` \xB7 ${bc(K.price,K.price_basis)}`]})]}):(0,S.jsx)("span",{className:"results-empty-hint",children:"No match"})}),(0,S.jsx)("td",{style:{textAlign:"center"},children:(0,S.jsx)("button",{type:"button",className:`bom-toolbar-btn${ke?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>B(q),disabled:!K||!n,children:ke?"\u2713 Added":"+ Add"})})]}),Fe&&(0,S.jsx)("tr",{children:(0,S.jsx)("td",{colSpan:6,style:{paddingLeft:0,paddingRight:0},children:A===Y.key?te(q):(0,S.jsxs)("div",{className:"estimator-products__picker",children:[(0,S.jsxs)("div",{className:"estimator-products__options",children:[q.candidates.map(xt=>(0,S.jsxs)("button",{type:"button",className:`estimator-products__option${xt.product_id===K?.product_id?" is-selected":""}`,onClick:()=>xe(Y.key,xt),children:[(0,S.jsx)("span",{children:xt.description}),(0,S.jsxs)("span",{className:"results-row-meta",children:[xt.product_id,xt.price!=null&&` \xB7 ${nt(xt.price)}`]})]},xt.product_id)),q.candidates.length===0&&(0,S.jsx)("p",{className:"results-empty-hint",children:"No candidates found."})]}),(0,S.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ee(q),children:"Search the catalogue"})]})})})]},Y.key)})})]})}),!R&&!f&&!w&&ot.length>0&&(0,S.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,S.jsxs)("div",{className:"results-tile-section__head",children:[(0,S.jsx)("h3",{children:"Require Matching"}),(0,S.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,S.jsx)("div",{className:"results-unmatched-list",children:ot.map(q=>(0,S.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>y(q),children:[(0,S.jsxs)("span",{className:"results-unmatched-card__main",children:[(0,S.jsx)("span",{className:"results-unmatched-card__title",children:q.requirement.label}),(0,S.jsxs)("span",{className:"results-row-meta",children:[yi(q.requirement.qty)," ",Na(q.requirement.unit,q.requirement.qty)]})]}),(0,S.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},q.requirement.key))})]}),!f&&!w&&d.length>0&&(0,S.jsxs)("div",{className:"disclaimer-box",style:{alignItems:"center"},children:[(0,S.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,S.jsx)("p",{className:"disclaimer-text",children:"These matches are generated automatically and should be reviewed before procurement, especially any items flagged as medium or low confidence."})]}),!R&&!f&&!w&&(r||k>0)&&(0,S.jsxs)("div",{className:"btn-row estimator-products__footer",children:[r&&(0,S.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:r,children:"Back"}),k>0&&n&&(0,S.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:r?"0 1 70%":1,marginTop:0},onClick:n.openBasket,children:[(0,S.jsxs)("span",{children:["View Basket (",k,")"]}),(0,S.jsx)("span",{className:"arrow",children:(0,S.jsx)(jt,{})})]})]})]})}var Qt=X(ie());function Zd({toolId:e,toolTitle:t,requirements:a,onBack:r}){let[i,n]=(0,vc.useState)(0),o=(0,vc.useCallback)(l=>n(l),[]);return(0,Qt.jsx)(Qt.Fragment,{children:(0,Qt.jsxs)("div",{className:"truss-estimator",children:[(0,Qt.jsxs)("div",{className:"quick-order-hero",children:[(0,Qt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Qt.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,Qt.jsx)("h1",{children:"Your Materials"}),i>0&&(0,Qt.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,Qt.jsx)("strong",{children:nt(i)})," Est. total"]})]}),(0,Qt.jsxs)("p",{children:["Quantities from the ",t,", matched against your merchant\u2019s catalogue."]})]}),(0,Qt.jsx)("div",{className:"truss-estimator__card",style:{minHeight:0},children:(0,Qt.jsx)($d,{toolId:e,requirements:a,ready:!0,onBack:r,onTotalChange:o})})]})})}var ex=(e,t)=>{let a=t.key,r={"brick-block":{"brick-common":"5001444","brick-engineering-red":"5002008","brick-engineering-blue":"5001439",block:"5003187",mortar:"6003088"},skirting:{"skirting-chamfered":"4006057","skirting-ogee":"4006045","skirting-pencil-round":"4006048","skirting-torus":"4006042"},architrave:{"architrave-ogee":"4006060","architrave-ovolo":"4006063","architrave-pencil-round":"4006061","architrave-square-edge":"4006062","architrave-torus":"4006059"},plasterboard:{board:"2001035",screws:"2006040",tape:"2007043",adhesive:"2004023"},insulation:{"insulation-floor":"3002110","insulation-wall":"3002012","insulation-roof":"3004047","insulation-loft":"3003046"},timber:{studs:"4001168",joists:"4001201",battens:"4001053"},fencing:{"panels-boundary-0.9":"4001268","panels-boundary-1.2":"4001269","panels-boundary-1.5":"4001270","panels-boundary-1.8":"4001271","panels-skyline-0.9":"4001264","panels-skyline-1.2":"4001265","panels-skyline-1.5":"4001266","panels-skyline-1.8":"4001267","concrete-intermediate-6":"4001290","concrete-intermediate-8":"4001291","concrete-end-6":"4001294","concrete-end-8":"4001295","timber-post-6":"4001242","timber-post-8":"4001243",postcrete:"6003008",gate:"4001630","gravel-boards":"4001284"},decking:{"boards-meridian":"4001251","boards-summit":"4001360",joists:"4001201",screws:"1001103"},paving:{"surface-council":"7003121","surface-raj":"7003003","surface-brindle":"4001621","surface-charcoal":"4001622","surface-pea":"6001004","sub-base":"6001007",bedding:"6001012"}};return e==="plasterboard"?{standard:"2001035",moisture:"2002039",fire:"2002087",sound:"2002044"}[t.label.split(" ")[0].toLowerCase()]??r[e]?.[a]??null:r[e]?.[a]??null};function Aw(e,t){if(e==="paint"||e==="concrete-aggregate")return null;let a=t.map(r=>{let i=ex(e,r);return i?{key:r.key,productId:i,qty:r.qty,unit:r.unit}:null});return a.every(Boolean)?a:null}var Kd=X(Xe());var Ft=X(ie()),tx=1500;function Rw(e){let{addManyToCart:t,clearCart:a,openBasket:r}=An(),[i,n]=(0,Kd.useState)(!1),[o,l]=(0,Kd.useState)(null);return{adding:i,basketError:o,addToBasket:async(p,d)=>{let g=Date.now();n(!0),l(null);try{let f=await Promise.all(p.filter(w=>w.qty>0).map(async w=>{let M=(await Fr(w.productId)).find(D=>D.product_id===w.productId);if(!M)throw new Error("A selected product is no longer available in this catalogue.");return Pr(M,{lineId:`${e}:${w.key}`,description:M.description,unit:w.unit??"each",qty:w.qty,calculatorWasteIncluded:d})})),h=tx-(Date.now()-g);h>0&&await new Promise(w=>window.setTimeout(w,h)),a(),t(f),r()}catch(f){l(f instanceof Error?f.message:"Could not add the products to your basket.")}finally{n(!1)}}}}function Uw({toolTitle:e}){return(0,Ft.jsx)(Ft.Fragment,{children:(0,Ft.jsxs)("div",{className:"truss-estimator",children:[(0,Ft.jsxs)("div",{className:"quick-order-hero",children:[(0,Ft.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Ft.jsx)("h1",{children:"Your Materials"}),(0,Ft.jsxs)("p",{children:["Calculating quantities from the ",e,"."]})]}),(0,Ft.jsx)("div",{className:"truss-estimator__card",children:(0,Ft.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,Ft.jsx)(fr,{}),(0,Ft.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})})}var Ue=X(ie());function wc(e){let[t,a]=(0,Va.useState)(!1);return(0,Ue.jsx)(tc,{onOpenBasket:()=>a(!0),children:(0,Ue.jsx)(ax,{...e,showBasket:t,onShowBasket:a})})}function ax({fullPage:e=!1,hideHeader:t=!1,internal:a=!1,showBasket:r,onShowBasket:i}){let[n,o]=(0,Va.useState)(null),[l,c]=(0,Va.useState)(null),p=Xd.find(z=>z.id===n),{cart:d,updateCartQty:g,updateCartSellUnits:f,updateCartConversions:h,removeFromCart:w,clearCart:M}=An(),{adding:D,basketError:m,addToBasket:u}=Rw(p?.title??"calculator"),b=(0,Va.useRef)(null),v=Xs("estimating-tools",b);(0,Va.useEffect)(()=>{v("viewed")},[v]);let N=r?"basket":D?"adding":l?"review":n??"list",A=(0,Va.useRef)(N);(0,Va.useEffect)(()=>{A.current!==N&&(A.current=N,window.scrollTo(0,0))},[N]);let T=z=>{if(!p)return;v("estimate_completed",{calculator:p.id,lines:z.length});let G=Aw(p.id,z);G?u(G,z[0]?.calculatorWasteIncluded??!1):c(z)};return(0,Ue.jsx)(Po.Provider,{value:v,children:(0,Ue.jsx)("div",{ref:b,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}`,style:Ra().theme,children:(0,Ue.jsx)("main",{className:"main-content",children:r?(0,Ue.jsx)(ol,{cart:d,onUpdateQty:g,onUpdateSellUnits:f,onResolveConversions:h,onRemove:w,onBack:()=>i(!1),onStartNewQuote:()=>{M(),o(null),c(null),i(!1)},internal:a}):D&&p?(0,Ue.jsx)(Uw,{toolTitle:p.title}):p?(0,Ue.jsxs)(Ue.Fragment,{children:[(0,Ue.jsx)("div",{hidden:l!==null,children:(0,Ue.jsx)(p.Component,{onBack:()=>o(null),onReview:T})}),m&&(0,Ue.jsx)("p",{className:"results-empty-hint estimator-products__error",children:m}),l!==null&&(0,Ue.jsx)(Zd,{toolId:p.id,toolTitle:p.title,requirements:l,onBack:()=>c(null)})]}):(0,Ue.jsx)(Ue.Fragment,{children:(0,Ue.jsxs)("div",{className:"quick-order-card",children:[(0,Ue.jsxs)("div",{className:"quick-order-hero",children:[(0,Ue.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,Ue.jsx)("h1",{children:"Estimating Tools"}),(0,Ue.jsx)("p",{children:"Trade-specific calculators for trusses, fencing, decking, masonry and painting. Dial in your specs and get an instant material estimate."})]}),(0,Ue.jsxs)("div",{className:"quick-order-alt",children:[(0,Ue.jsx)("div",{className:"quick-order-alt-title",children:"Choose a Calculator"}),(0,Ue.jsx)("div",{className:"estimator-tools-grid",children:Xd.map(z=>(0,Ue.jsxs)("button",{type:"button",className:"estimator-tool-card",onClick:()=>{v("calculator_selected",{calculator:z.id}),o(z.id),c(null)},children:[(0,Ue.jsx)("span",{className:"estimator-tool-card__image-wrap",children:(0,Ue.jsx)("img",{className:"fill-img estimator-tool-card__image",src:Jt(z.imageUrl),alt:""})}),(0,Ue.jsxs)("span",{className:"estimator-tool-card__content",children:[(0,Ue.jsx)("span",{className:"estimator-tool-card__title",children:z.title}),(0,Ue.jsx)("span",{className:"estimator-tool-card__desc",children:z.desc})]})]},z.id))})]})]})})})})})}var yc=X(ie());function Pd({config:e,children:t}){return Wb(e),(0,yc.jsx)(yc.Fragment,{children:t})}var Jd=X(ie()),rx="https://api.metronlabs.ai",ix=["client","api-key","api-url","theme","hide-header","analytics"],nx=["all","events-only","none"];function Ow(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.46",this.id||(this.id=e),this.setAttribute("data-turbo-permanent",""),this.setAttribute("data-turbolinks-permanent",""),!this.root){let i=document.createElement("div"),n=document.createElement("style");n.textContent=`:host { display: block; }
|
|
6804
6804
|
:host > div { all: initial; display: block; }
|
|
6805
6805
|
${Ib}`,this.shadowRoot.replaceChildren(n,i),this.root=(0,Dw.createRoot)(i)}this.renderWidget()}disconnectedCallback(){queueMicrotask(()=>{this.isConnected||!this.root||(this.root.unmount(),this.root=null)})}attributeChangedCallback(){this.root&&this.renderWidget()}renderWidget(){let i=this.getAttribute("client")??void 0,n=this.getAttribute("api-key")??void 0;(!i||!n)&&console.error(`<${e}> needs client and api-key attributes.`);let o={apiBaseUrl:this.getAttribute("api-url")||rx,client:i,apiKey:n,theme:lx(e,this.getAttribute("theme")),analytics:ox(this.getAttribute("analytics"))};this.root.render((0,Jd.jsx)(Pd,{config:o,children:(0,Jd.jsx)(t,{hideHeader:this.hasAttribute("hide-header")})}))}},a.observedAttributes=ix,a))}function ox(e){return nx.find(t=>t===e)??"all"}function lx(e,t){if(t)try{return JSON.parse(t)}catch{console.error(`<${e}> theme attribute isn't valid JSON; using the default colours.`);return}}Ow("metron-labs-quick-quote",rc);Ow("metron-labs-estimating-tools",wc);
|
|
6806
6806
|
/*! Bundled license information:
|