@metron-labs/quote-react 0.1.52 → 0.1.53

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.
@@ -2096,6 +2096,23 @@ Error generating stack: `+r.message+`
2096
2096
  gap: 14px;
2097
2097
  }
2098
2098
 
2099
+ /* 1\u20132 cards: go horizontal (image left, details right) so they fill the row
2100
+ like the notice and buttons below, instead of stretching tall-and-wide. */
2101
+ @media (min-width: 721px) {
2102
+ :where(.app-wrapper) .results-tile-grid:not(:has(> :nth-child(3))) .results-tile-card__surface {
2103
+ flex-direction: row;
2104
+ }
2105
+
2106
+ :where(.app-wrapper) .results-tile-grid:not(:has(> :nth-child(3))) .results-tile-card__media {
2107
+ flex: 0 0 40%;
2108
+ max-width: 240px;
2109
+ min-height: 150px;
2110
+ aspect-ratio: auto;
2111
+ border-bottom: 0;
2112
+ border-right: 1px solid var(--border);
2113
+ }
2114
+ }
2115
+
2099
2116
  :where(.app-wrapper) .results-tile-card,
2100
2117
  :where(.app-wrapper) .results-empty-card {
2101
2118
  border: 1px solid var(--border);
@@ -6966,7 +6983,7 @@ C24 timber 4.8m`,value:p,onChange:$=>d($.target.value),"aria-label":"Paste sched
6966
6983
  <rect x="168" y="188" width="250" height="24" rx="12" fill="#aab5c0"/>
6967
6984
  <rect x="168" y="232" width="220" height="24" rx="12" fill="#aab5c0"/>
6968
6985
  </svg>
6969
- `)}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 ov=e=>(e??"").trim().toLowerCase(),n_={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"},yd=new Set(["sheet","length","box","bag","pack","roll","set","tub","each"]),av=new Set(["box","bag","pack","pallet","roll","set","tub"]),rv=(e,t)=>t==="ml"?e:["l","litre","litres"].includes(t)?e*1e3:null,iv=(e,t)=>t==="g"?e:["kg","kilogram","kilograms"].includes(t)?e*1e3:["t","tonne","tonnes"].includes(t)?e*1e6:null,_i=e=>{let t=ov(e);return n_[t]??t},st=(e,t)=>{let a=_i(e),r=_i(t);return a.length>0&&a===r},o_=(e,t)=>{let a=ov(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},l_=e=>(e??"").split(",").map(t=>_i(t)).filter(Boolean),s_=(e,t)=>{let a=l_(e.requestUomsSupported);return!!(a.length===0||a.includes(t)||st(t,"pallet")&&e.itemsPerPallet!=null&&e.itemsPerPallet>0||st(t,"pack")&&e.itemsPerPack!=null&&e.itemsPerPack>0||st(t,"box")&&e.itemsPerBox!=null&&e.itemsPerBox>0)},nv=(e,t)=>st(t,"pallet")?e.itemsPerPallet??null:st(t,"pack")?e.itemsPerPack??null:st(t,"box")?e.itemsPerBox??null:null,c_=(e,t,a)=>{if(!st(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||!st(r[3],a))return null;let i=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(i)&&i>0?i:null};function Is(e,t){let a=e.map(r=>Ft(r,t).lineTotal);return a.some(r=>r==null)?null:a.reduce((r,i)=>r+(i??0),0)}function Ft(e,t){let a=e.qty,r=_i(e.saleUnit??e.salesUnitSizeUom??e.uoi??e.salesUomNormalised)||"-",i=_i(e.unit)||(a>0&&yd.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?yd.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(!Number.isFinite(a)||a<=0)return p("Quantity needs confirmation.");if(!s_(e,i))return p("Requested unit is not supported by this catalogue conversion.");let d=null,g="review",m=e.roundingRule,b=`Quantity review required, initial request needed ${a} ${i}.`,y=1+o,T=c_(e,i,r),D=e.unitConversions?.find(v=>st(v.requestUom,i));if(!!e.saleUnit&&(st(i,r)||!!D||st(i,"each")&&!av.has(r)))if(st(i,r))d=a*y/n,g="direct",b=`${a} ${i}${o>0?` x ${y}`:""}`;else if(D){d=a*y/D.quantityPerSaleUnit,g="derived";let v=1/D.quantityPerSaleUnit,S=Math.round(v);b=st(r,"each")&&D.quantityPerSaleUnit<1&&Math.abs(v-S)<1e-9?`${a} ${i}${o>0?` x ${y}`:""} x ${S} per ${i}`:`${a} ${i}${o>0?` x ${y}`:""} / ${D.quantityPerSaleUnit} ${i} per ${r}`}else st(i,"each")&&!av.has(r)&&(d=a*y/n,g="derived",b=`${a} ${r}${o>0?` x ${y}`:""}`);else if(st(i,r)&&n>0)d=a*y/n,g="direct",b=o>0?`${a} ${i} x ${y} / ${n} ${r} per sell unit`:`${a} ${i} / ${n} ${r} per sell unit`;else if(st(i,"each")&&n>0&&yd.has(r))d=a*y/n,g="derived",b=o>0?`${a} each x ${y} / ${n} each per ${r}`:`${a} each / ${n} each per ${r}`;else if(nv(e,i)!=null&&n>0){let v=nv(e,i)??0;d=a*v*y/n,g="derived";let S=`${a} ${i} x ${v} each${o>0?` x ${y}`:""}`;b=n===1&&st(r,"each")?S:`${S} / ${n} each per ${r}`}else if(T!=null)d=a*y/T,g="derived",m??(m="round_up_each"),b=`${a} m2 x ${y} / ${T} m2 per ${r} (from product description)`;else if(e.conversionType==="basket_line_unit")n>0&&(d=a*y/n,g="derived",b=`${a} ${i}${o>0?` x ${y}`:""} / ${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;st(i,"m2")&&v!=null&&v>0&&(d=a*y/v,g="derived",b=`${a} m2 x ${y} / ${v} m2 per ${r}`)}else if(e.conversionType==="count_per_area"){let v=e.coverageQty??null;st(i,"m2")&&v!=null&&v>0?(d=a/v,g="derived",b=`${a} m2 / ${v} m2 per sell unit`):st(i,"m2")&&e.itemsPerM2!=null&&e.itemsPerM2>0&&n>0&&(d=a*e.itemsPerM2*y/n,g="derived",b=`${a} m2 x ${e.itemsPerM2} ${r}/m2 x ${y} / ${n}`)}else if(e.conversionType==="length_from_dims"){let v=e.coverageQty??e.derivedLengthM??null;st(i,"m")&&v!=null&&v>0&&(d=a*y/v,g="derived",b=`${a} m x ${y} / ${v} m per ${r}`)}else if(e.conversionType==="volume_from_description"){let v=rv(a,i),S=rv(e.coverageQty??0,_i(e.coverageUom));v!=null&&S!=null&&S>0&&(d=v*y/S,g="derived",b=`${a} ${i} x ${y} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="weight_from_description"){let v=iv(a,i),S=iv(e.coverageQty??0,_i(e.coverageUom));v!=null&&S!=null&&S>0&&(d=v*y/S,g="derived",b=`${a} ${i} x ${y} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="same_unit_volume"){let v=e.coverageQty??null;st(i,"m3")&&v!=null&&v>0&&(d=a/v,g="derived",b=`${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=o_(d,m),w=l?c:u;return{requestedAmount:a,requestedUnit:i,salesUnitSize:n,sellUnit:r,calculatedSellUnits:u,requiredSellUnits:w,unitPrice:e.price,lineTotal:e.price!=null&&w!=null?e.price*w:null,calculation:l?`${b} = ${u} ${r} (manually set to ${w})`:`${b} = ${w} ${r}`,costingMode:g}}var lv=()=>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"],u_=al.indexOf("Line total");function p_(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 sv(e){let t=await lv(),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:m,unmatchable:b,decision:y}=c,T=[p.section,p.subsection,p.subheading].filter(Boolean).join(" / "),D=!b&&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)",T,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(", "),y?.technical_classification??"",y?.include_in_quote==null?"":y.include_in_quote?"yes":"no",y?.approval_required==null?"":y.approval_required?"yes":"no",y?.approval_type??"",y?.missing_information.join(", ")??"",y?.confidence??"",y?.reason??"",b?"-":d?.product_id??y?.selected_candidate_id??"-",b?"-":d?.description??"-",b?"-":d?.price_basis??"-",b?null:d?.price??null,D,b?"-":m,p_(c)])}i.push(Array(al.length).fill(null));let o=Array(al.length).fill(null);o[0]="Estimated total",o[u_]=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 cv(e,t){let a=await lv(),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=Ft(p),g=d.lineTotal;g!=null&&(o+=g),n.push([p.productId,p.description,d.costingMode,d.requestedAmount,Na(d.requestedUnit),d.salesUnitSize,Na(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=G(ee()),xd="__none__",rl=24,d_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}];function mv(e){return e==null?"low":e>=.7?"high":e>=.5?"medium":"low"}var m_=e=>e.attrs.supply_nature==="labour_only"||e.attrs.supply_nature==="plant"||e.flags.includes("referential");function f_(e,t){if(t!==xd){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 uv(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 h_(e){return e?e.replace(/_/g," "):"not stated"}function g_({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 zn(e,t){if(e==null)return"-";let a=el(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function kd(e){return e&&e.length>0?e.join(" x "):"-"}function b_(e){return e==null?"-":Number.isInteger(e/1e3)?`${e/1e3}m`:`${(e/1e3).toFixed(1)}m`}function Tn(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)"}function w_(e,t){return t>0||e==null?null:lt(e)}var pv=[{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 v_(e){let t=new Map;return[...new Set(e.filter(mr).map(r=>r.linked_group_id))].forEach((r,i)=>{let n=i%26;t.set(r,{token:String.fromCharCode(65+n),bubbleStyle:pv[i%pv.length]})}),t}function mr(e){return!1}function An(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 _d({meta:e}){return e?(0,s.jsx)("span",{className:"results-linked-pill",style:e.bubbleStyle,children:`Link ${e.token}`}):null}function y_(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 Fs(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 Ws(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 __({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:Ws(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:Ws(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:Ws(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:Ws(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 x_({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:kd(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 dv({item:e,result:t}){let a=t?.retrieval_debug.map(i=>i.query).filter(Boolean)??[],r=[["Procurement intent",e.procurement_intent||"-"],["Procurement aliases",Tn(e.procurement_aliases)],["Retrieval queries",Tn(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)",kd(e.attrs.measurements_mm)],["Stock length",b_(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",Tn(e.installation_clues)],["System clues",Tn(e.system_clues)],["Component requirements",Tn(e.component_requirements)],["Linked group",An(e)||"-"],["Flags",Tn(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)(ke.Fragment,{children:[(0,s.jsx)("dt",{children:i}),(0,s.jsx)("dd",{children:n})]},i))})]})}function k_({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)(ke.Fragment,{children:[(0,s.jsx)("dt",{children:"Attempted"}),(0,s.jsx)("dd",{children:t.attempted?"yes":"no"})]}),(0,s.jsxs)(ke.Fragment,{children:[(0,s.jsx)("dt",{children:"Applied"}),(0,s.jsx)("dd",{children:t.applied?"yes":"no"})]}),(0,s.jsxs)(ke.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned items"}),(0,s.jsx)("dd",{children:t.returned_item_count??"-"})]}),(0,s.jsxs)(ke.Fragment,{children:[(0,s.jsx)("dt",{children:"Reason"}),(0,s.jsx)("dd",{children:t.reason||"-"})]}),(0,s.jsxs)(ke.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 N_({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)(ke.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 S_({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"?"No automatic match:":`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]}),mr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",n?`Link ${n.token} - `:"",An(e)]}):null]}):null:!t.reason&&!r?(0,s.jsx)(dv,{item:e,result:a}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(dv,{item:e,result:a}),r&&(0,s.jsx)(k_,{item:e}),r&&(0,s.jsx)(N_,{result:a}),t.reason&&(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,s.jsx)("strong",{children:o}),"\xA0",t.reason]}),mr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",n?`Link ${n.token} - `:"",An(e)]}):null]}),r&&(0,s.jsx)(x_,{queries:a?.retrieval_debug??[]})]})}function C_({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:m=!1,linkedGroupMeta:b}){let y=d||o==="detailed",T=g&&o==="detailed",D=y||m?(0,s.jsx)(S_,{item:e,decision:r,result:a,showRetrievalDebug:T,reviewOnly:m&&!y,linkedGroupMeta:b}):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 f=p||d||o==="detailed"?t:y_(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"}),T&&(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:f.map((u,w)=>{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:kd(u.measurements_mm??u.debug?.candidate.measurements_mm)})}),(0,s.jsx)("td",{children:zn(u.price,u.price_basis)}),T&&(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)(g_,{band:mv(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}-${w}`)})})]})]})}function Nd({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&&Xs()==="QZA6-MRA4",m=g?"quote":"basket",{results:b,lineItems:y,parseReport:T,timings:D}=e,[f,u]=(0,ke.useState)({}),w=Cn(),[v,S]=(0,ke.useState)({}),[R,z]=(0,ke.useState)({}),[A,Q]=(0,ke.useState)(""),[K,fe]=(0,ke.useState)(null),[Ue,Be]=(0,ke.useState)(1),Ye=jt().debug===!0,[Ne,ve]=(0,ke.useState)("simple"),[oe,se]=(0,ke.useState)(d?"list":"tile"),[ye,wt]=(0,ke.useState)(!1),[Ee,$]=(0,ke.useState)(null),[ue,Ze]=(0,ke.useState)(""),[pt,vt]=(0,ke.useState)([]),[He,de]=(0,ke.useState)(!1),[_e,Se]=(0,ke.useState)(null),[E,O]=(0,ke.useState)(!1),[re,ce]=(0,ke.useState)(null),ge=(0,ke.useRef)(null),[Ae,Pe]=(0,ke.useState)(new Set),[h,M]=(0,ke.useState)(new Set),[N,Y]=(0,ke.useState)(!1);(0,ke.useEffect)(()=>{Be(1)},[A,K,oe]);let Z=new Map(b.map(x=>[x.line_id,x])),k=v_(y),L=y.map(x=>{let H=Z.get(x.line_id),be=H?.decision,dt=m_(x),Je=f[x.line_id],ea=f_(H,Je),zi=a[x.line_id],Pv=Je===xd?void 0:v[x.line_id]??(zi&&zi.productId!==ea?.product_id?uv(zi):ea),um=dt?void 0:Pv,Jv=x.qty??0;return{item:x,result:H,decision:be,unmatchable:dt,best:um,qty:Jv,band:mv(um?.scores?.overall)}}),pe=L.some(x=>!x.unmatchable&&!x.best&&!h.has(x.item.line_id))?null:Is(Object.values(a),{wasteFactorEnabled:!1,wasteFactorOverride:0}),xe=0;for(let x of L){if(x.unmatchable||x.decision?.include_in_quote!==!0||!x.best)continue;let H=a[x.item.line_id];(!H||Ft(H).lineTotal==null)&&(xe+=1)}xe>0&&(pe=null);let xt=w_(pe,xe),it=x=>!x.unmatchable&&!x.best&&x.decision?.technical_classification!=="no_suitable_candidate"&&Fs(x.result).length>0,Et=x=>x.best??Fs(x.result)[0],Ir=L.filter(x=>!x.unmatchable&&!x.best).filter(x=>!h.has(x.item.line_id)),yc=L.filter(x=>h.has(x.item.line_id)),Yt=L;if(A.trim()){let x=A.trim().toLowerCase();Yt=Yt.filter(H=>H.item.description_original?.toLowerCase().includes(x)||Et(H)?.description?.toLowerCase().includes(x))}if(K){let x=K==="asc"?1:-1;Yt=[...Yt].sort((H,be)=>x*(H.item.description_original||"").localeCompare(be.item.description_original||""))}let br=Math.max(1,Math.ceil(Yt.length/rl)),kt=Math.min(Ue,br),qi=Yt.slice((kt-1)*rl,kt*rl),am=qi.filter(x=>!x.unmatchable&&x.best),hx=qi.filter(x=>it(x)),_c=qi.filter(x=>!x.unmatchable&&(x.best||it(x))),rm=qi.filter(x=>x.unmatchable||!x.best&&!it(x)),J=Ee?L.find(x=>x.item.line_id===Ee)??null:null,Gv=!d&&!c&&!J&&Ir.length>0,Yn=(0,ke.useRef)(null),Xn=()=>{let x=ge.current;if(!x)return;let{top:H,left:be,width:dt,height:Je}=x.getBoundingClientRect(),zi=x.querySelector(".bom-toolbar-btn")?.closest("td")?.getBoundingClientRect().left;ce({top:H,left:be,width:zi?zi-be:dt,height:Je})};(0,ke.useEffect)(()=>(window.addEventListener("scroll",Xn,!0),window.addEventListener("resize",Xn),()=>{window.removeEventListener("scroll",Xn,!0),window.removeEventListener("resize",Xn)})),(0,ke.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 Ei=x=>{$(x),Ze("")},Yv=()=>{if(!Ee)return;let x=a[Ee];if(x){u(H=>({...H,[Ee]:x.productId})),S(H=>({...H,[Ee]:uv(x)}));return}u(H=>{let be={...H};return delete be[Ee],be}),S(H=>{let be={...H};return delete be[Ee],be})},Va=(x=!1)=>{let H=Ee?a[Ee]: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||Yv(),$(null),Y(!1))};Fo(E,()=>O(!1)),Fo(!!J&&!E,()=>Va());let Xv=x=>{if(Pe(H=>new Set(H).add(x)),Ir.some(H=>H.item.line_id!==x)){Va(!0);return}p(),Va(!0)},Vv=x=>{if(xc(x),M(H=>new Set(H).add(x)),Ir.some(H=>H.item.line_id!==x)){Va(!0);return}p(),Va(!0)},$v=()=>{M(x=>new Set([...x,...Ir.map(H=>H.item.line_id)])),p()},im=()=>{J?.best&&(om(J.item.line_id,J.best),r(Mi(J)),N?Xv(J.item.line_id):Va(!0))},nm=rm.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:rm.map(x=>{let{item:H,qty:be}=x;return(0,s.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>Ei(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,y)})}),(0,s.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},H.line_id)})})]}):null,xc=x=>{u(H=>({...H,[x]:xd})),S(H=>({...H,[x]:void 0})),z(H=>({...H,[x]:void 0})),i(x)},kc=(x,H)=>{u(be=>({...be,[x]:H.product_id})),S(be=>({...be,[x]:H}))},om=(x,H)=>{H.method==="catalogue_search"&&z(be=>({...be,[x]:H}))};function gx(){w("downloaded",{type:"schedule",lines:L.length}),sv(L.map(({item:x,best:H,qty:be,band:dt,unmatchable:Je,decision:ea})=>({item:x,best:H,qty:be,band:dt,unmatchable:Je,decision:ea})))}function Mi(x){let H=x.best??Fs(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?y.filter(be=>be.linked_group_id===x.item.linked_group_id&&be.linked_group_role==="anchor").slice(0,1).map(be=>{let dt=a[be.line_id];return{line_id:be.line_id,product_id:dt?.productId??null,measurements_mm:dt?.measurementsMm??be.attrs.measurements_mm,description:dt?.description??be.description_original,qty:be.qty,unit:be.unit,role:"anchor"}}):void 0})}(0,ke.useEffect)(()=>{if(!o){for(let x of L)!x.unmatchable&&x.best&&r(Mi(x));l()}},[o]),(0,ke.useEffect)(()=>{for(let x of L)!a[x.item.line_id]&&!x.unmatchable&&x.best&&r(Mi(x))},[e]),(0,ke.useEffect)(()=>{if(!Ee){vt([]),Se(null),de(!1);return}let x=ue.trim();if(!x){vt([]),Se(null),de(!1);return}let H=!1,be=window.setTimeout(async()=>{try{de(!0),Se(null);let dt=await fetch(pa(`/api/catalogue/search?q=${encodeURIComponent(x)}`),{headers:wi()}),Je=await ka(dt);if(!dt.ok)throw new Error(Je?.error||Je?.message||"Failed to search catalogue");H||vt(Array.isArray(Je?.items)?Je.items:[])}catch(dt){H||(vt([]),Se(dt?.message||"Failed to search catalogue"))}finally{H||de(!1)}},250);return()=>{H=!0,window.clearTimeout(be)}},[ue,Ee]);let Nc=Object.keys(a).length,Ma=ue.trim(),Sc=Fs(J?.result),ul=J?.decision?.technical_classification==="no_suitable_candidate"||!!J&&!J.best,lm=J?.decision?.technical_classification!=null,sm=J?.decision?.reason??(ul?"No catalogue candidate found. Refine the request or search the catalogue.":null),Zv=pt.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?Zv:Sc,Ti=J?R[J.item.line_id]:void 0,$n=!Ma&&Ti&&!Vn.some(x=>x.product_id===Ti.product_id)?[...Vn,Ti]:Vn,cm=(()=>{let x=$n.slice(0,Ma?12:3);return Ma||!Ti||x.some(H=>H.product_id===Ti.product_id)?x:[...x,Ti]})(),pl=!!J?.best&&a[J.item.line_id]?.productId===J.best.product_id,Kv=!!J?.best&&!!a[J.item.line_id]&&!pl;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:xt??"Review quantities"})," Est. total"]})]}),(0,s.jsx)("p",{children:"Each line item from your schedule matched against your catalogue, ranked by confidence."})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{children:"Review your matched products"}),(0,s.jsxs)("p",{children:["Check you're happy with these items, then click ",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"}),xt!=null&&(0,s.jsx)("strong",{children:xt})]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Qt,{})})]})]})}),(0,s.jsxs)("div",{className:"quick-order-panel",style:{paddingTop:16},children:[Ye&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:12},children:(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn","aria-pressed":ye,onClick:()=>wt(x=>!x),children:ye?"Hide timings":"Show timings"})}),Ye&&ye&&(0,s.jsx)(__,{...D}),!g&&(0,s.jsx)("div",{className:"results-toolbar-row",children:!J&&(0,s.jsxs)("div",{className:"results-summary",style:{marginBottom:0},children:[xe>0&&(0,s.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,s.jsx)("strong",{children:xe})," 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:A,onChange:x=>Q(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${oe==="tile"?" is-active":""}`,"aria-pressed":oe==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>se("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${oe==="list"?" is-active":""}`,"aria-pressed":oe==="list","aria-label":"List view",title:"List view",onClick:()=>se("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"})]})})]}),Ye&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ve(x=>x==="simple"?"detailed":"simple"),children:Ne==="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:d_.map(x=>{let H=K===x.dir;return(0,s.jsxs)("button",{type:"button",className:`sort-menu-item${H?" is-active":""}`,onClick:()=>{fe(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)})})]})]})]})}),oe==="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:()=>Va(),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:()=>Va(),"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:()=>Va(),children:[(0,s.jsx)(Kr,{}),"Back to results"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[Ye&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ve(x=>x==="simple"?"detailed":"simple"),children:Ne==="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:ue,onChange:x=>Ze(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:()=>xc(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:Ga(Et(J)?.description||J.item.description_original,Et(J)?.product_id,Et(J)?.pdp_photo_url),alt:""})}),(0,s.jsxs)("div",{className:"results-review-page__summary",children:[(0,s.jsx)("h2",{children:Jr(J.item,y)}),(0,s.jsxs)("p",{className:"results-review-page__meta",children:[yi(J.qty)," ",Sa(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:zn(J.best.price,J.best.price_basis)}):null]}):Et(J)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:Et(J)?.description}),Et(J)?.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:zn(Et(J)?.price??null,Et(J)?.price_basis??null)}):null,(0,s.jsx)("div",{className:"results-row-meta",children:"Best reviewed alternative - not yet selected"})]}):(0,s.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line item."}),mr(J.item)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[(0,s.jsx)(_d,{meta:k.get(J.item.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:An(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&&om(J.item.line_id,J.best),r(Mi(J)))},disabled:!J.best,"aria-label":a[J.item.line_id]?d?"Remove from selection":`Remove from ${m}`:d?"Add to selection":`Add to ${m}`,children:a[J.item.line_id]?"\u2713 Added":d?"+ Add to selection":`Add to ${m}`})})]})]}),He?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,!He&&_e?(0,s.jsx)("div",{className:"results-empty-card",children:_e}):null,!He&&!_e&&Ma&&Vn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No candidate products match this database search."}):!He&&!_e?(0,s.jsx)(C_,{item:J.item,candidates:Vn,result:J.result,decision:J.decision,unmatchable:J.unmatchable,selectedProductId:J.best?.product_id??null,detailMode:Ne,linkedGroupMeta:mr(J.item)?k.get(J.item.linked_group_id):void 0,onPick:x=>kc(J.item.line_id,x),onClear:()=>xc(J.item.line_id),showAll:d||Ye||Ma.length>0,internal:d,debugEnabled:Ye,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,y)||"Original request"})]}),sm?(0,s.jsxs)("section",{className:"customer-review-ai",children:[(0,s.jsx)("strong",{children:ul?"No automatic match:":"AI review:"})," ",sm]}):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:ul?Sc.length>0?"Choose a product":"No suitable product found":lm?"Choose a product":"We couldn't review this item"}),(0,s.jsx)("p",{children:ul?Sc.length>0?"No product was selected automatically. Review these related options before adding one.":"Search the catalogue to choose an alternative.":lm?`Select the option you want to add to your ${m}.`:"Search the catalogue to choose a product."})]})}),!Ma&&$n.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:cm.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:()=>kc(J.item.line_id,x),"aria-pressed":H,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Ga(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${zn(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:ue,onChange:x=>Ze(x.target.value),"aria-label":"Search catalogue"})]}),Ma&&He?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,Ma&&!He&&_e?(0,s.jsx)("div",{className:"results-empty-card",children:_e}):null,Ma&&!He&&!_e&&$n.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No products match this search."}):null,Ma&&!He&&!_e&&$n.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:cm.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:()=>kc(J.item.line_id,x),"aria-pressed":H,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Ga(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${zn(x.price,x.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:H?"Selected":"Choose"})]},x.product_id)})}):null]}),J.best?Kv?(0,s.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,s.jsx)("button",{type:"button",className:"cta-btn customer-review-add",onClick:()=>{im()},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 ${m}`})})]}):(0,s.jsx)("button",{type:"button",className:`cta-btn customer-review-add${pl?" cta-btn-secondary":""}`,onClick:()=>{pl?i(J.item.line_id):im()},children:(0,s.jsx)("span",{children:pl?`Remove from ${m}`:`Add selected product to ${m}`})}):null,N?(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-skip",onClick:()=>Vv(J.item.line_id),children:"Skip this item"}):null]})})]})}):null,(0,s.jsxs)("div",{className:"results-tile-layout",children:[Yt.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No line items match the current search/filter."}):null,_c.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:_c.map(x=>{let{item:H,best:be,qty:dt}=x,Je=Et(x),ea=!be&&it(x);return(0,s.jsxs)("article",{className:"results-tile-card",children:[(0,s.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>Ei(H.line_id),"aria-label":`Review match for ${Jr(H,y)||"item"}`,children:[(0,s.jsxs)("div",{className:"results-tile-card__media",children:[ea||mr(H)?(0,s.jsxs)("div",{className:"results-tile-card__badges",children:[mr(H)?(0,s.jsx)(_d,{meta:k.get(H.linked_group_id)}):(0,s.jsx)("span",{}),ea?(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:Ga(Je?.description||H.description_original,Je?.product_id,Je?.pdp_photo_url),alt:""})]}),(0,s.jsxs)("div",{className:"results-tile-card__body",children:[Je?(0,s.jsx)(s.Fragment,{children:(0,s.jsx)("div",{className:"results-tile-card__heading",children:(0,s.jsx)("div",{className:"results-tile-card__title",children:Je.description})})}):(0,s.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line item."}),(0,s.jsx)("div",{className:"results-tile-card__match",children:Je?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-tile-card__match-label",children:ea?"\u21B3 partially matched from":"\u21B3 matched from"}),(0,s.jsx)("div",{className:"results-tile-card__match-name",children:Jr(H,y)}),mr(H)?(0,s.jsx)("div",{className:"results-row-meta",children:An(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:()=>Ei(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(Mi(x))},disabled:!Je,"aria-label":a[H.line_id]?d?"Remove from selection":`Remove from ${m}`:d?"Add to selection":`Add to ${m}`,children:a[H.line_id]?"\u2713 Added":d?"+ Add":`Add to ${m}`})]})]},H.line_id)})})}):null,nm]})]}):(0,s.jsxs)(s.Fragment,{children:[re&&(0,s.jsx)("div",{className:"results-table__hover-overlay",style:re,"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"}}),Ne==="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"}),Ne==="simple"&&(0,s.jsx)("th",{style:{textAlign:"center"},children:d?"Selection":g?"Quote":"Basket"})]})}),(0,s.jsxs)("tbody",{children:[Yt.length===0&&(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:Ne==="simple"?4:3,className:"results-empty-hint",style:{padding:"16px 8px"},children:"No line items match the current search/filter."})}),_c.map(x=>{let{item:H,result:be,decision:dt,best:Je}=x;return(0,s.jsxs)("tr",{className:"bom-row results-table__review-row",onClick:()=>Ei(H.line_id),onMouseEnter:ea=>{ge.current=ea.currentTarget,Xn()},onMouseLeave:()=>{ge.current=null,ce(null)},children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{className:"bom-component-name",children:Jr(H,y)}),mr(H)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,s.jsx)(_d,{meta:k.get(H.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:An(H)})]}):null]}),(0,s.jsx)("td",{children:Je?(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"results-match-cell-text",title:Je.description,children:Je.description}),Ne==="detailed"&&dt?.technical_classification&&(0,s.jsxs)("div",{className:"results-row-meta",children:[h_(dt.technical_classification),dt.approval_required?" - approval required":""]})]}):(0,s.jsx)("span",{className:"results-empty-hint"})}),(0,s.jsx)("td",{style:{textAlign:"center"},children:Je?.price!=null?zn(Je.price,Je.price_basis):"-"}),Ne==="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:ea=>{ea.stopPropagation(),a[H.line_id]?i(H.line_id):r(Mi(x))},"aria-label":a[H.line_id]?d?"Remove from selection":`Remove from ${m}`:d?"Add to selection":`Add to ${m}`,children:a[H.line_id]?"\u2713 Added":d?"+ Add":`Add to ${m}`})})]},H.line_id)})]})]})}),nm]}),!J&&br>1&&(0,s.jsxs)("div",{className:"results-pagination",children:[(0,s.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(kt-1)*rl+1,"\u2013",Math.min(kt*rl,Yt.length)," of ",Yt.length]}),(0,s.jsxs)("div",{className:"results-pagination-controls",children:[(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Be(kt-1),disabled:kt===1,children:"Previous"}),(0,s.jsxs)("span",{className:"results-pagination-page",children:["Page ",kt," of ",br]}),(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Be(kt+1),disabled:kt===br,children:"Next"})]})]}),(T.itemCount!=null||T.headingCount!=null||T.skippedCount!=null)&&(0,s.jsxs)("div",{className:"results-summary",style:{marginTop:16},children:[T.itemCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:T.itemCount})," items parsed"]}),T.headingCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:T.headingCount})," headings"]}),T.skippedCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:T.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:(Nc>0,"0 1 30%"),gap:10,justifyContent:"center"},onClick:()=>O(!0),"aria-label":"Start over",children:[(0,s.jsx)(wd,{}),(0,s.jsx)("span",{children:"Start Over"})]}),Nc>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"," (",Nc,")"]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Qt,{})})]})]})]})]}),Gv&&(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop review-gate-modal-backdrop",role:"dialog","aria-modal":"true","aria-labelledby":"review-gate-title",children:(0,s.jsxs)("section",{className:"quick-order-workflow-modal review-gate-modal",children:[(0,s.jsxs)("div",{className:"review-gate-modal__header",children:[(0,s.jsx)("h2",{id:"review-gate-title",children:"Choose products for these items"}),(0,s.jsx)("p",{children:"We couldn\u2019t find a clear match for these items, so we need your help. Select an option from the suggestions, search the catalogue, or leave the item out."})]}),(0,s.jsx)("div",{className:"review-gate-list",children:Ir.map(x=>{let H=Ae.has(x.item.line_id),be=it(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:()=>{Y(!0),Ei(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Jr(x.item,y)}),(0,s.jsx)("span",{children:x.decision?.reason||(be?"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:$v,children:"Skip all"}),yc.length>0?(0,s.jsxs)("div",{className:"review-gate-skipped",children:[(0,s.jsx)("strong",{children:"Skipped"}),yc.map(x=>(0,s.jsxs)("button",{type:"button",className:"review-gate-item is-skipped",onClick:()=>{M(H=>{let be=new Set(H);return be.delete(x.item.line_id),be}),Y(!0),Ei(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Jr(x.item,y)}),(0,s.jsx)("span",{children:`Not added to your ${m}.`})]}),(0,s.jsx)("span",{className:"review-gate-item__action",children:"Choose a product"})]},x.item.line_id))]}):null]})}),E&&(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:()=>O(!1),children:"Cancel"}),(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-danger",onClick:()=>{O(!1),t()},autoFocus:!0,children:"Start Over"})]})]})})]})}var bt=G(Xe());var Ut=G(Xe()),fv=G(ee());function Rn(e){return JSON.stringify([e.productId,e.qty,e.unit,e.linkedContext??[]])}function q_(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 Sd=(0,Ut.createContext)(null);function ec({children:e,onOpenBasket:t}){let[a,r]=(0,Ut.useState)({}),i=(0,Ut.useCallback)(m=>{r(b=>q_(b,m))},[]),n=(0,Ut.useCallback)(m=>{r(b=>{let y={...b};for(let T of m)y[T.lineId]=T;return y})},[]),o=(0,Ut.useCallback)(m=>{r(b=>{let y={...b};return delete y[m],y})},[]),l=(0,Ut.useCallback)((m,b)=>{r(y=>y[m]?{...y,[m]:{...y[m],qty:b,sellUnitsOverride:null}}:y)},[]),c=(0,Ut.useCallback)((m,b)=>{r(y=>y[m]?{...y,[m]:{...y[m],sellUnitsOverride:b}}:y)},[]),p=(0,Ut.useCallback)(m=>{r(b=>{let y=!1,T={...b};for(let[D,f]of Object.entries(m))T[D]&&(T[D]={...T[D],...f},y=!0);return y?T:b})},[]),d=(0,Ut.useCallback)(()=>r({}),[]),g=(0,Ut.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,fv.jsx)(Sd.Provider,{value:g,children:e})}function Un(){let e=(0,Ut.useContext)(Sd);if(!e)throw new Error("useCart must be used inside a <CartProvider>");return e}function tc(){return(0,Ut.useContext)(Sd)}var q=G(ee()),hv=.2,il=10,gv="Enter a valid email address so we can send your quote.",E_=(e,t)=>{let a=`${t.requestedAmount} ${Na(t.requestedUnit,t.requestedAmount)}`,r=`${t.requiredSellUnits} ${Na(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)} ${Na(t.sellUnit,2)} per ${Na(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}`},M_=e=>["box","pack"].includes(e.requestedUnit)?"Pack size needed to calculate the order quantity.":`This product is sold by ${Na(e.sellUnit,1)}.`;function T_(){return(0,q.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,q.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,q.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),(0,q.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,q.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function nl(){return(0,q.jsx)("svg",{width:"8",height:"5",viewBox:"0 0 8 5",fill:"none",children:(0,q.jsx)("path",{d:"M1 4L4 1L7 4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function ol({cart:e,onUpdateQty:t,onUpdateSellUnits:a,onResolveConversions:r,onRemove:i,onBack:n,onStartNewQuote:o,onQuoteRequested:l,internal:c=!1}){let p=(0,bt.useId)(),d=!c&&Xs()==="QZA6-MRA4",g=Object.values(e),[m,b]=(0,bt.useState)(""),[y,T]=(0,bt.useState)(!1),[D,f]=(0,bt.useState)(!1),u=Cn(),[w,v]=(0,bt.useState)(""),[S,R]=(0,bt.useState)({}),[z,A]=(0,bt.useState)({}),[Q,K]=(0,bt.useState)(1),[fe,Ue]=(0,bt.useState)({}),[Be,Ye]=(0,bt.useState)(!1),[Ne,ve]=(0,bt.useState)("0"),[oe,se]=(0,bt.useState)({}),ye=(0,bt.useRef)(new Map);(0,bt.useEffect)(()=>{if(!r)return;for(let N of Object.values(e))Ft(N).requiredSellUnits!=null&&ye.current.delete(N.lineId);let h=Object.values(e).filter(N=>{if(N.productId==="-"||Ft(N).requiredSellUnits!=null)return!1;let Y=Rn(N);return ye.current.get(N.lineId)===Y?!1:(ye.current.set(N.lineId,Y),!0)});if(h.length===0)return;let M=new Map(h.map(N=>[N.lineId,Rn(N)]));se(N=>({...N,...Object.fromEntries(M)})),fetch(pa("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...$r()},body:JSON.stringify({lines:h.map(N=>({line_id:N.lineId,product_id:N.productId,requested_description:N.requestedDescription??N.description,requested_qty:N.qty,requested_uom:N.unit||null,linked_context:N.linkedContext??[],selected_description:N.description,selected_uoi:N.uoi,selected_uoi_count:N.uoiCount,selected_conversion:{sales_uom_normalised:N.salesUomNormalised,conversion_type:N.conversionType,sales_unit_size:N.salesUnitSize,sales_unit_size_uom:N.salesUnitSizeUom,coverage_qty:N.coverageQty,coverage_uom:N.coverageUom}}))})}).then(N=>N.ok?ka(N):null).then(N=>{let Y={},Z=new Map(h.map(k=>[k.lineId,Rn(k)]));for(let k of N?.data?.items??N?.items??[]){let L=k?.conversion;if(!L||typeof k?.line_id!="string"||ye.current.get(k.line_id)!==Z.get(k.line_id))continue;let P=e[k.line_id];Y[k.line_id]={conversionType:L.conversion_type,requestUomsSupported:L.request_uoms_supported,salesUomNormalised:L.sales_uom_normalised,salesUnitSize:L.sales_unit_size,salesUnitSizeUom:L.sales_unit_size_uom,coverageQty:L.coverage_qty,coverageUom:L.coverage_uom,roundingRule:L.rounding_rule,conversionConfidence:L.conversion_confidence,conversionNotes:L.conversion_notes,...P?.qty===0&&Number.isFinite(L.suggested_order_qty)&&L.suggested_order_qty>0?{qty:L.suggested_order_qty,unit:L.suggested_order_uom||P.unit}:{}}}Object.keys(Y).length>0&&r(Y)}).catch(N=>console.error("Catalogue conversion resolution failed",N)).finally(()=>{se(N=>{let Y={...N};for(let[Z,k]of M)Y[Z]===k&&delete Y[Z];return Y})})},[e,r]);function wt(h){R(M=>{let N={...M};return delete N[h],N})}function Ee(h,M){let N=parseFloat(M);!isNaN(N)&&N>=0&&t(h,Math.min(N,1e5)),wt(h)}function $(h,M,N){t(h,Math.min(1e5,Math.max(0,M+N))),wt(h)}function ue(h){A(M=>{let N={...M};return delete N[h],N})}function Ze(h,M){let N=parseFloat(M);!isNaN(N)&&N>=0&&a(h,Math.min(N,1e5)),ue(h)}function pt(h,M,N){a(h,Math.min(1e5,Math.max(0,M+N))),ue(h)}async function vt(){if(He.some(({pricing:M})=>M.lineTotal==null)){v("Confirm the highlighted quantities before requesting a quote.");return}let h=m.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(h)){v(gv);return}v(""),f(!0);try{let M=await fetch(pa("/api/quote-requests"),{method:"POST",headers:{"Content-Type":"application/json",...$r()},body:JSON.stringify({email:h,items:He.map(({item:N,pricing:Y})=>{let Z=Y.requiredSellUnits??Y.requestedAmount,k=Y.requiredSellUnits!=null?Y.sellUnit:Y.requestedUnit;return{product_id:N.productId,description:N.description,quantity:Z,unit:Na(k,Z),unit_price:Y.requiredSellUnits!=null?Y.unitPrice:null,line_total:Y.lineTotal}})})});if(!M.ok){let N=await ka(M);console.error("Quote request failed",M.status,N?.message),v(M.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}Se!=null&&u("quote_requested",{items:He.length,total:Math.round(Se*100)/100}),T(!0),l?.(),window.scrollTo(0,0)}catch{v("Your request couldn't be sent. Check your connection and try again.")}finally{f(!1)}}let He=g.map(h=>({item:h,pricing:Ft(h,{wasteFactorEnabled:Be,wasteFactorOverride:Math.max(0,Number.parseFloat(Ne)||0)/100})})),de=Is(g,{wasteFactorEnabled:Be,wasteFactorOverride:Math.max(0,Number.parseFloat(Ne)||0)/100}),_e=de==null?null:de*hv,Se=de==null?null:de*(1+hv),E=He.filter(({pricing:h})=>h.lineTotal==null).length,O=Object.keys(oe).length,re=!!r&&g.some(h=>{if(h.productId==="-"||Ft(h).requiredSellUnits!=null)return!1;let M=Rn(h);return ye.current.get(h.lineId)!==M||oe[h.lineId]===M}),ce=(0,bt.useRef)({items:He.length,...Se==null?{}:{total:Math.round(Se*100)/100}});(0,bt.useEffect)(()=>{u("basket_viewed",ce.current)},[u]);let ge=Math.max(1,Math.ceil(He.length/il)),Ae=Math.min(Q,ge),Pe=He.slice((Ae-1)*il,Ae*il);return y?(0,q.jsx)("div",{className:"wizard-step entry-stage",children:(0,q.jsxs)("div",{className:"quote-request-sent",role:"status",children:[(0,q.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,q.jsx)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,q.jsx)("polyline",{points:"5 12.5 10 17.5 19 7"})})}),(0,q.jsx)("h1",{children:"Quote requested"}),(0,q.jsxs)("p",{children:["You're all done. We'll email your sharper price to ",(0,q.jsx)("strong",{children:m.trim()}),", usually within one working day."]}),(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,q.jsx)("span",{children:"Start a new quote"})}),(0,q.jsx)("p",{className:"quote-request-sent-note",children:"Nothing is charged until you approve the quote."})]})}):!c&&g.length===0?(0,q.jsx)("div",{className:"wizard-step entry-stage",children:(0,q.jsxs)("div",{className:"quote-request-sent",children:[(0,q.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,q.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,q.jsx)("path",{d:"M3 9h18l-2 11H5z"}),(0,q.jsx)("path",{d:"M8 9l4-6 4 6"})]})}),(0,q.jsx)("h1",{children:d?"Your quote request is empty":"Your basket is empty"}),(0,q.jsx)("p",{children:d?"Start again with your list to build your quote.":"Start again with your list to fill your basket."}),(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,q.jsx)("span",{children:"Back to start"})})]})}):(0,q.jsx)("div",{className:`wizard-step entry-stage${d?" basket-layout--qza6-mra4":""}`,children:(0,q.jsxs)("div",{className:`quick-order-card${c?"":" quick-order-card--customer"}`,children:[(0,q.jsxs)("div",{className:`quick-order-hero${c?"":" quick-order-hero--customer"}`,children:[c&&(0,q.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,q.jsxs)("div",{className:"basket-hero-copy",children:[d&&(0,q.jsxs)("button",{type:"button",className:"cta-btn cta-btn-secondary basket-hero-back",onClick:n,children:[(0,q.jsx)(Kr,{}),(0,q.jsx)("span",{children:"Back to results"})]}),(0,q.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,q.jsx)("h1",{children:c?"Your Selection":d?"Request a quote":"Your Basket"}),c&&(0,q.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,q.jsx)("strong",{children:g.length})," ",g.length===1?"item":"items"]})]}),(0,q.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,q.jsx)("div",{className:"quick-order-panel",style:{paddingTop:16},children:re?(0,q.jsxs)("div",{className:"basket-resolving",role:"status","aria-label":"Calculating order quantities",children:[(0,q.jsx)("span",{className:"basket-resolving-wheel","aria-hidden":"true"}),(0,q.jsx)("span",{children:"Calculating your quantities\u2026"})]}):g.length===0?(0,q.jsxs)("div",{className:"quick-order-history-empty",children:[(0,q.jsx)("div",{className:"basket-empty-icon","aria-hidden":"true",children:"\u{1F4CB}"}),(0,q.jsx)("p",{children:"Your selection is empty."}),(0,q.jsx)("p",{className:"basket-empty-hint",children:"Go back to your results and add quoted items."}),(0,q.jsx)("div",{className:"btn-row",style:{marginTop:20,justifyContent:"center"},children:(0,q.jsx)("button",{className:"cta-btn",style:{width:"auto",maxWidth:280},onClick:n,"aria-label":"Back to results",children:(0,q.jsx)("span",{children:"Back to Results"})})})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)("div",{className:"basket-layout",children:[(0,q.jsxs)("div",{className:"basket-main",children:[(0,q.jsx)("div",{className:"basket-list","aria-label":c?"Selection items":d?"Quote request items":"Basket items",children:Pe.map(({item:h,pricing:M})=>{let N=S[h.lineId]??String(M.requestedAmount),Y=M.requestedUnit===M.sellUnit||M.costingMode==="review",Z=M.requiredSellUnits==null||M.requestedAmount!==M.requiredSellUnits||M.requestedUnit!==M.sellUnit;return(0,q.jsxs)("article",{className:"basket-card",children:[(0,q.jsxs)("div",{className:"basket-card-top",children:[(0,q.jsx)("img",{className:"basket-card-thumb",src:Ga(h.description,h.productId,h.pdpPhotoUrl),alt:"",width:48,height:48}),(0,q.jsxs)("div",{className:"basket-card-info",children:[(0,q.jsx)("div",{className:"bom-component-name",children:h.description}),Z&&M.costingMode!=="review"&&(0,q.jsxs)("button",{type:"button",className:"basket-calc-toggle",onClick:()=>Ue(k=>({...k,[h.lineId]:!k[h.lineId]})),"aria-expanded":!!fe[h.lineId],children:["How we calculated this",(0,q.jsx)("span",{className:`basket-calc-toggle-chevron${fe[h.lineId]?" basket-calc-toggle-chevron--open":""}`,children:(0,q.jsx)(nl,{})})]})]}),(0,q.jsx)("div",{className:"basket-card-actions",children:(0,q.jsx)("button",{type:"button",className:"mf-remove-small-btn basket-card-remove",onClick:()=>i(h.lineId),"aria-label":`Remove ${h.description}`,children:(0,q.jsx)(T_,{})})})]}),c&&(0,q.jsxs)("div",{className:"results-detail-block basket-internal-detail",children:[(0,q.jsxs)("dl",{className:"results-detail-grid",children:[(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Conversion type"}),(0,q.jsx)("dd",{children:h.conversionType??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Conversion confidence"}),(0,q.jsx)("dd",{children:h.conversionConfidence??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Sales unit"}),(0,q.jsx)("dd",{children:h.salesUnitSize!=null?(0,q.jsxs)(q.Fragment,{children:[h.salesUnitSize," ",Sa(h.salesUnitSizeUom,h.salesUnitSize)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Coverage"}),(0,q.jsx)("dd",{children:h.coverageQty!=null?(0,q.jsxs)(q.Fragment,{children:[h.coverageQty," ",Sa(h.coverageUom,h.coverageQty)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Waste factor"}),(0,q.jsx)("dd",{children:h.wasteFactorDefault??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Rounding rule"}),(0,q.jsx)("dd",{children:h.roundingRule??"-"})]})]}),h.conversionNotes&&(0,q.jsx)("p",{className:"results-rerank-note",children:h.conversionNotes})]}),M.costingMode==="review"?(0,q.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,q.jsx)("strong",{children:oe[h.lineId]===Rn(h)?"Calculating order quantity\u2026":"Quantity needs confirmation."})," ",M_(M)]}):Z&&fe[h.lineId]?(0,q.jsx)("p",{className:"basket-calc-text",children:E_(h,M)}):null,(0,q.jsxs)("div",{className:"basket-card-stats",children:[(0,q.jsxs)("div",{className:"basket-stat",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Requested qty"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsxs)("div",{className:"basket-qty-field",children:[(0,q.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:N,disabled:Y,onChange:k=>R(L=>({...L,[h.lineId]:k.target.value})),onBlur:k=>Ee(h.lineId,k.target.value),onKeyDown:k=>{k.key==="Enter"&&k.target.blur()},"aria-label":`${h.description} requested quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",disabled:Y,onClick:()=>$(h.lineId,parseFloat(N)||0,1),"aria-label":`Increase ${h.description} quantity`,children:(0,q.jsx)(nl,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",disabled:Y,onClick:()=>$(h.lineId,parseFloat(N)||0,-1),"aria-label":`Decrease ${h.description} quantity`,children:(0,q.jsx)(nl,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:Sa(M.requestedUnit,parseFloat(N)||0)})]})]}),(0,q.jsxs)("div",{className:"basket-stat basket-stat--right",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Order qty"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsxs)("div",{className:"basket-qty-field",children:[(0,q.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:z[h.lineId]??String(M.requiredSellUnits??""),onChange:k=>A(L=>({...L,[h.lineId]:k.target.value})),onBlur:k=>Ze(h.lineId,k.target.value),onKeyDown:k=>{k.key==="Enter"&&k.target.blur()},"aria-label":`${h.description} order quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",onClick:()=>pt(h.lineId,parseFloat(z[h.lineId]??String(M.requiredSellUnits??"0"))||0,1),"aria-label":`Increase ${h.description} order quantity`,children:(0,q.jsx)(nl,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",onClick:()=>pt(h.lineId,parseFloat(z[h.lineId]??String(M.requiredSellUnits??"0"))||0,-1),"aria-label":`Decrease ${h.description} order quantity`,children:(0,q.jsx)(nl,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:Sa(M.sellUnit,parseFloat(z[h.lineId]??String(M.requiredSellUnits??"0"))||0)})]})]}),(0,q.jsxs)("div",{className:"basket-stat basket-stat--total",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Total"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsx)("strong",{children:M.lineTotal!=null?lt(M.lineTotal):"-"}),M.lineTotal!=null&&(0,q.jsx)("span",{className:"basket-metric-unit",children:"ex. VAT"})]})]})]})]},h.lineId)})}),ge>1&&(0,q.jsxs)("div",{className:"results-pagination",children:[(0,q.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(Ae-1)*il+1,"\u2013",Math.min(Ae*il,He.length)," of ",He.length]}),(0,q.jsxs)("div",{className:"results-pagination-controls",children:[(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>K(Ae-1),disabled:Ae===1,children:"Previous"}),(0,q.jsxs)("span",{className:"results-pagination-page",children:["Page ",Ae," of ",ge]}),(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>K(Ae+1),disabled:Ae===ge,children:"Next"})]})]})]}),(0,q.jsxs)("aside",{className:"basket-sidebar",children:[(0,q.jsx)("div",{className:"basket-sidebar-title",children:d?"Quote request summary":"Order summary"}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:d?"List price (ex. VAT)":"Subtotal (ex. VAT)"}),(0,q.jsx)("span",{children:de==null?"To confirm":lt(de)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:"VAT (20%)"}),(0,q.jsx)("span",{children:_e==null?"To confirm":lt(_e)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row basket-sidebar-row--total",children:[(0,q.jsx)("span",{children:d?"List price (inc.\xA0VAT)":"Total"}),(0,q.jsx)("span",{children:Se==null?"To confirm":lt(Se)})]}),!d&&(0,q.jsx)("div",{className:"basket-summary-waste",children:(0,q.jsxs)("div",{className:"basket-waste-control",children:[(0,q.jsxs)("label",{className:"basket-global-waste",children:[(0,q.jsx)("input",{type:"checkbox",checked:Be,onChange:h=>Ye(h.target.checked)}),(0,q.jsx)("span",{children:"Add waste factor"})]}),(0,q.jsxs)("label",{className:"basket-global-waste-percent",children:[(0,q.jsx)("input",{type:"number",inputMode:"decimal",min:"0",step:"0.1",value:Ne,onChange:h=>ve(h.target.value),disabled:!Be,"aria-label":"Waste factor percent"}),(0,q.jsx)("span",{children:"%"})]})]})}),(0,q.jsx)("label",{htmlFor:`${p}-basket-reference`,className:"basket-sidebar-label",children:d?"Enter email for your sharper quote":"Your reference (optional)"}),(0,q.jsx)("input",{id:`${p}-basket-reference`,type:d?"email":"text",className:"basket-sidebar-input",value:m,onChange:h=>{b(h.target.value),d&&v("")},placeholder:d?"you@example.com":"PO number or job reference","aria-invalid":d&&w===gv,"aria-describedby":d&&w?`${p}-basket-reference-error`:void 0}),d&&w&&(0,q.jsx)("p",{id:`${p}-basket-reference-error`,className:"basket-quote-request-error",role:"alert",children:w}),d?(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:()=>{vt()},disabled:D||E>0||O>0,"aria-busy":D,children:(0,q.jsx)("span",{children:D?"Sending\u2026":"Request our best quote"})}):(0,q.jsx)("button",{className:"cta-btn",onClick:()=>{u("downloaded",{type:"basket",items:g.length}),cv(g)},"aria-label":c?"Download selection":"Download basket",children:(0,q.jsx)("span",{children:c?"Download Quote":"Buy Now"})}),(0,q.jsxs)("p",{className:"basket-sidebar-disclaimer",children:[(0,q.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,q.jsx)("div",{className:"btn-row results-actions",children:(0,q.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",gap:10,justifyContent:"center"},onClick:n,"aria-label":"Back to results",children:[(0,q.jsx)(Kr,{}),(0,q.jsx)("span",{children:"Back to results"})]})})]})})]})})}var Ca=G(ee()),qd="metron-quick-quote";function ac(e){return(0,Ca.jsx)(ec,{children:(0,Ca.jsx)(z_,{...e})})}function z_({fullPage:e=!1,hideHeader:t=!1,internal:a=!1}){let[r,i]=(0,Le.useState)("entry"),[n,o]=(0,Le.useState)(null),[l,c]=(0,Le.useState)(""),p=(0,Le.useRef)(null),d=(0,Le.useRef)(0),[g,m]=(0,Le.useState)(0),[b,y]=(0,Le.useState)(null),[T,D]=(0,Le.useState)(!1),{cart:f,addToCart:u,addManyToCart:w,removeFromCart:v,updateCartQty:S,updateCartSellUnits:R,updateCartConversions:z,clearCart:A}=Un(),[Q,K]=(0,Le.useState)(!1),[fe,Ue]=(0,Le.useState)(null),Be=()=>{Ue(null);try{window.sessionStorage.removeItem(Js)}catch{}},Ye=(0,Le.useRef)(null),Ne=Ys("quick-quote",Ye);(0,Le.useEffect)(()=>{Ne("viewed")},[Ne]);let[ve,oe]=(0,Le.useState)(!1);(0,Le.useEffect)(()=>{let de=window.location.hash,_e=null;try{_e=JSON.parse(window.sessionStorage.getItem(qd)??"null")}catch{}if(_e?.scheduleResult)o("schedule"),y(_e.scheduleResult),D(_e.reviewGateComplete),K(_e.cartSeeded),w(Object.values(_e.cart)),de==="#quote-request"?i("basket"):de==="#matched-products"&&i("results");else if(de==="#matched-products"||de==="#quote-request"){let Se=new URL(window.location.href);Se.hash="",window.history.replaceState(window.history.state,"",Se)}oe(!0)},[]),(0,Le.useEffect)(()=>{if(ve)try{b?window.sessionStorage.setItem(qd,JSON.stringify({scheduleResult:b,reviewGateComplete:T,cartSeeded:Q,cart:f})):window.sessionStorage.removeItem(qd)}catch{}},[ve,b,T,Q,f]);let se=(0,Le.useCallback)(de=>{if(typeof window>"u")return;let _e=new URL(window.location.href);_e.hash=de==="basket"?"quote-request":"matched-products";let Se=de==="results"&&(window.location.hash==="#matched-products"||window.location.hash==="#quote-request");window.history[Se?"replaceState":"pushState"]({boqQuoteStage:de},"",_e)},[]),ye=(0,Le.useRef)(!1);(0,Le.useEffect)(()=>{let de=_e=>{ye.current=!1;let Se=window.location.hash;Se==="#quote-request"?i("basket"):Se==="#matched-products"&&b?(o("schedule"),i("results")):i("entry");let E=_e.state,O=window.location.href;setTimeout(()=>{if(window.location.href===O){if(Se==="#quote-request"||Se==="#matched-products"||Se==="#quote-entry"){window.history.replaceState({boqQuoteStage:Se==="#quote-request"?"basket":Se==="#quote-entry"?"entry":"results"},"",O);return}!E?.turbo&&window.history.state?.turbo&&window.history.replaceState(E,"",O)}})};return window.addEventListener("popstate",de),()=>window.removeEventListener("popstate",de)},[b]);let wt=(0,Le.useCallback)(()=>{se("basket"),i("basket")},[se]),Ee=(0,Le.useCallback)(()=>{if(window.location.hash==="#quote-request"){if(ye.current)return;ye.current=!0,window.history.back();return}i(b?"results":"entry")},[b]),$=(0,Le.useRef)(r);(0,Le.useEffect)(()=>{$.current!==r&&($.current=r,window.scrollTo(0,0))},[r]);let ue=()=>{i("entry"),o(null),c(""),m(0),y(null),D(!1),A(),K(!1),Be()},Ze=(0,Le.useCallback)(async(de,_e,Se=!0)=>{let E=++d.current;c(""),m(0);let O=0,re=()=>{O=Math.min(O+1,3),m(O)};try{let{jobId:ce}=await cw(de,_e,Se);if(E!==d.current)return;let{promise:ge,cancel:Ae}=pw(()=>uw(ce),5e3,re,"schedule");p.current=Ae;let Pe=await ge;if(Pe.status==="failed"||!Pe.result)throw new Error(Pe.error||"Failed to process schedule");let h=Pe.result.lineItems.length,M=Pe.result.results.filter(N=>N.candidates.length>0).length;Ne("results_shown",{lines:h,matched:M,unmatched:h-M}),A(),K(!1),D(!1),y(Pe.result),se("results"),i("results")}catch(ce){if(E!==d.current)return;Ne("error",{stage:"matching"}),c(ce?.message||"Failed to process schedule"),i("entry")}finally{E===d.current&&(p.current?.(),p.current=null)}},[se,Ne,A]),pt=(0,Le.useCallback)(()=>{d.current++,p.current?.(),p.current=null},[]),vt=(0,Le.useCallback)(async(de,_e,Se=!0)=>{if(!de.trim())return;o("schedule");let E=new File([de],"pasted-schedule.txt",{type:"text/plain"});await Ze(E,_e,Se)},[Ze]),He=(0,Le.useCallback)(async de=>{o("schedule"),await Ze(de)},[Ze]);return(0,Ca.jsx)(Po.Provider,{value:Ne,children:(0,Ca.jsx)("div",{ref:Ye,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${!e&&r==="processing"?" app-wrapper--loading":""}`,style:jt().theme,children:(0,Ca.jsxs)("main",{className:"main-content",children:[l&&(0,Ca.jsxs)("div",{className:"error-box",role:"alert",children:[(0,Ca.jsx)("strong",{children:"Error:"})," ",l]}),r==="entry"&&(0,Ca.jsx)(gd,{onPasteSchedule:vt,onUploadSchedule:He,onEntryModeChange:o,draft:fe,onSubmitDraft:Ue,onCancelMatch:pt}),r==="results"&&n==="schedule"&&b&&(0,Ca.jsx)(Nd,{scheduleResult:b,onStartOver:ue,cart:f,onAddToCart:u,onRemoveFromCart:v,onGoToBasket:wt,cartSeeded:Q,onCartSeeded:()=>K(!0),reviewGateComplete:T,onReviewGateComplete:()=>D(!0),internal:a}),r==="basket"&&(0,Ca.jsx)(ol,{cart:f,onUpdateQty:S,onUpdateSellUnits:R,onResolveConversions:z,onRemove:v,onBack:Ee,onStartNewQuote:ue,onQuoteRequested:()=>{y(null),D(!1),K(!1),A(),Be()},internal:a})]})})})}var Xa=G(Xe());var xi=G(Xe()),W=G(ee()),bv=[{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"}],rc=e=>Number.parseFloat(e)||0,wv=(e,t)=>rc(e)*(t==="m"?1:.3048),Ed=(e,t)=>rc(e.quantity)*(2*wv(e.height,t)+wv(e.width,t)),A_=()=>({quantity:"1",width:"",height:""});function R_({profile:e}){return(0,W.jsxs)("svg",{className:"architrave-calculator__profile-diagram",viewBox:"0 0 112 76","aria-hidden":"true",children:[(0,W.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,W.jsx)("line",{x1:"12",y1:"66",x2:"100",y2:"66"})]})}function Md({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,m]=(0,xi.useState)("ogee"),[b,y]=(0,xi.useState)("2.4"),T=(S,R,z)=>{S(A=>({...A,[R]:z}))},D=Ed(n,r)+Ed(l,r)+p.reduce((S,R)=>S+Ed(R,r),0),f=rc(b)>0?Math.ceil(D/rc(b)):0,u=bv.find(S=>S.id===g)?.label??"",w=[{key:`architrave-${g}`,label:`Architrave (${u})`,qty:D,unit:"m",query:`${u} architrave`,category:"architrave"}],v=(S,R,z,A)=>(0,W.jsxs)("div",{className:"architrave-calculator__opening-row",children:[(0,W.jsx)("span",{children:S}),(0,W.jsx)("input",{"aria-label":`${S} quantity`,type:"number",min:"0",step:"1",value:R.quantity,onChange:Q=>z("quantity",Q.target.value)}),(0,W.jsx)("input",{"aria-label":`${S} width`,type:"number",min:"0",step:"0.01",value:R.width,onChange:Q=>z("width",Q.target.value)}),(0,W.jsx)("input",{"aria-label":`${S} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:Q=>z("height",Q.target.value)}),A?(0,W.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:A,children:"Remove"}):null]});return(0,W.jsx)(W.Fragment,{children:(0,W.jsxs)("div",{className:"truss-estimator",children:[(0,W.jsxs)("div",{className:"quick-order-hero",children:[(0,W.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,W.jsx)("h1",{children:"Architrave Calculator"}),(0,W.jsx)("p",{children:"Estimate architrave lengths and board quantities for door openings."})]}),(0,W.jsxs)("div",{className:"truss-estimator__card architrave-calculator",children:[(0,W.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure your openings"}),(0,W.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,W.jsxs)("div",{className:"architrave-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Door openings"}),(0,W.jsx)("p",{className:"architrave-calculator__hint",children:"Each opening is calculated as two side pieces plus one head piece."}),(0,W.jsxs)("div",{className:"architrave-calculator__unit-row",children:[(0,W.jsx)("span",{children:"Units"}),(0,W.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,W.jsx)("button",{type:"button",className:r==="m"?"is-selected":"",onClick:()=>i("m"),children:"Metres"}),(0,W.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>i("ft"),children:"Feet"})]})]}),(0,W.jsxs)("div",{className:"architrave-calculator__dimensions-header",children:[(0,W.jsx)("span",{children:"Opening"}),(0,W.jsx)("span",{children:"Qty"}),(0,W.jsxs)("span",{children:["Width (",r,")"]}),(0,W.jsxs)("span",{children:["Height (",r,")"]}),(0,W.jsx)("span",{})]}),v("Single doors",n,(S,R)=>T(o,S,R)),v("Double doors",l,(S,R)=>T(c,S,R)),p.map((S,R)=>v(`Alternative door ${R+1}`,S,(z,A)=>d(Q=>Q.map((K,fe)=>fe===R?{...K,[z]:A}:K)),()=>d(z=>z.filter((A,Q)=>Q!==R)))),(0,W.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>d(S=>[...S,A_()]),children:"+ Add alternative-sized door"})]}),(0,W.jsxs)("div",{className:"architrave-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Standard profile"}),(0,W.jsx)("p",{className:"architrave-calculator__hint",children:"Choose the profile you plan to use. Length calculations are the same for each profile."}),(0,W.jsx)("div",{className:"architrave-calculator__profiles",children:bv.map(S=>(0,W.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g===S.id?" is-selected":""}`,onClick:()=>m(S.id),children:[(0,W.jsx)(R_,{profile:S.id}),(0,W.jsx)("div",{className:"truss-estimator__option-title",children:S.label}),(0,W.jsx)("div",{className:"truss-estimator__option-copy",children:S.blurb})]},S.id))})]}),(0,W.jsxs)("div",{className:"architrave-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,W.jsx)("div",{className:"architrave-calculator__options",children:(0,W.jsxs)("label",{className:"truss-estimator__field",children:[(0,W.jsx)("span",{children:"Board length (m)"}),(0,W.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,W.jsx)("p",{className:"architrave-calculator__hint",children:"Waste allows for mitred corners, cuts and damaged lengths."})]}),(0,W.jsxs)("div",{className:"architrave-calculator__totals",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,W.jsxs)("div",{className:"architrave-calculator__result-grid",children:[(0,W.jsxs)("div",{children:[(0,W.jsx)("span",{children:"Architrave needed"}),(0,W.jsxs)("strong",{children:[D.toFixed(2)," m"]})]}),(0,W.jsxs)("div",{children:[(0,W.jsx)("span",{children:"Board lengths"}),(0,W.jsx)("strong",{children:f})]})]})]}),(0,W.jsxs)("div",{className:"architrave-calculator__actions",children:[(0,W.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,W.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(w),disabled:D<=0,children:a})]})]})]})})}var ki=G(Xe()),ne=G(ee()),vv=60,yv=10,U_=.02,D_=.012,O_=.01,Dn=e=>Number.parseFloat(e)||0,B_=(e,t=2)=>e.toFixed(t);function Td({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,m]=(0,ki.useState)(""),[b,y]=(0,ki.useState)(!0),T=l==="metric"?Dn(p)*Dn(g):Dn(p)*Dn(g)*.092903,f=T*(r==="brick"?vv:yv),u=Math.ceil(f),w=T*(r==="brick"?U_:D_),v=Math.ceil(w/O_),S=l==="metric"?T:T*10.7639,R=[{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"},...b?[{key:"mortar",label:"Blue Circle Quality Assured Mortar Mix 20kg",qty:v,unit:"bag",query:"ready mixed mortar",category:"mortar"}]:[]],z=A=>{if(A===l)return;let Q=A==="imperial"?3.28084:.3048;d((Dn(p)*Q).toFixed(2)),m((Dn(g)*Q).toFixed(2)),c(A)};return(0,ne.jsx)(ne.Fragment,{children:(0,ne.jsxs)("div",{className:"truss-estimator",children:[(0,ne.jsxs)("div",{className:"quick-order-hero",children:[(0,ne.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ne.jsx)("h1",{children:"Brick and Block Calculator"}),(0,ne.jsx)("p",{children:"Estimate masonry units, sand and cement for a wall."})]}),(0,ne.jsxs)("div",{className:"truss-estimator__card brick-calculator",children:[(0,ne.jsx)("h2",{className:"truss-estimator__step-title",children:"Wall area and masonry type"}),(0,ne.jsx)("p",{className:"truss-estimator__step-sub",children:"Pick brick or block and enter the wall dimensions for unit counts plus ready-mixed mortar."}),(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Masonry type"}),(0,ne.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["brick","Brick"],["block","Block"]].map(([A,Q])=>(0,ne.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===A?" is-selected":""}`,onClick:()=>i(A),children:[(0,ne.jsx)("div",{className:"truss-estimator__option-title",children:Q}),(0,ne.jsxs)("div",{className:"truss-estimator__option-copy",children:["Approx. ",A==="brick"?vv:yv," per m\xB2"]})]},A))})]}),r==="brick"&&(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Brick type"}),(0,ne.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:[["common","Common concrete","General-purpose grey concrete brick"],["engineering-red","Engineering red","Class B perforated, 65mm"],["engineering-blue","Engineering blue","Class B solid, 65mm"]].map(([A,Q,K])=>(0,ne.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n===A?" is-selected":""}`,onClick:()=>o(A),children:[(0,ne.jsx)("div",{className:"truss-estimator__option-title",children:Q}),(0,ne.jsx)("div",{className:"truss-estimator__option-copy",children:K})]},A))})]}),(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,ne.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,ne.jsx)("button",{type:"button",className:l==="metric"?"is-selected":"",onClick:()=>z("metric"),children:"Metric"}),(0,ne.jsx)("button",{type:"button",className:l==="imperial"?"is-selected":"",onClick:()=>z("imperial"),children:"Imperial"})]}),(0,ne.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsxs)("span",{children:["Height (",l==="metric"?"m":"ft",")"]}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:A=>d(A.target.value)})]}),(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsxs)("span",{children:["Width (",l==="metric"?"m":"ft",")"]}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:g,onChange:A=>m(A.target.value)})]})]})]}),(0,ne.jsx)("div",{className:"brick-calculator__options",children:(0,ne.jsxs)("label",{className:"brick-calculator__checkbox",children:[(0,ne.jsx)("input",{type:"checkbox",checked:b,onChange:A=>y(A.target.checked)}),(0,ne.jsx)("span",{children:"Include ready-mixed mortar"})]})}),(0,ne.jsxs)("div",{className:"brick-calculator__totals",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ne.jsxs)("div",{className:"brick-calculator__result-grid",children:[(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Wall area"}),(0,ne.jsxs)("strong",{children:[B_(S)," ",l==="metric"?"m\xB2":"ft\xB2"]})]}),(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:r==="brick"?"Bricks":"Blocks"}),(0,ne.jsx)("strong",{children:u.toLocaleString("en-GB")})]}),b?(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Ready-mixed mortar"}),(0,ne.jsxs)("strong",{children:[v," x 20kg bags"]})]}):null]}),(0,ne.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,ne.jsxs)("div",{className:"brick-calculator__actions",children:[(0,ne.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ne.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(R),disabled:T<=0,children:a})]})]})]})})}var hr=G(Xe());var L_={"NZ4Y-ZMSQ":{"brick-block":{"brick-common":"105499","brick-engineering-red":"1654","brick-engineering-blue":"1723",block:"501",mortar:"646"},skirting:{"skirting-chamfered":"1525","skirting-ogee":"135 primed mdf ogee","skirting-pencil-round":"892","skirting-torus":"1941"},architrave:{"architrave-ogee":"134 primed mdf ogee","architrave-ovolo":"1531","architrave-pencil-round":"1896","architrave-square-edge":"118 primed mdf square","architrave-torus":"1531"},plasterboard:{standard:"1647",moisture:"11 moisture plasterboard",fire:"14 fire plasterboard",sound:"1769",screws:"131160",tape:"1766",adhesive:"108439"},insulation:{"insulation-floor":"152187","insulation-wall":"147","insulation-roof":"442","insulation-loft":"152180"},timber:{studs:"1213",joists:"208",battens:"1729"},fencing:{"panels-boundary-0.9":"66 lap fence panel","panels-boundary-1.2":"1450","panels-boundary-1.5":"1449","panels-boundary-1.8":"1448","panels-skyline-1.8":"1475","concrete-intermediate-8":"40197","concrete-end-8":"40198","timber-post-6":"141411","timber-post-8":"1709",postcrete:"12142",gate:"1984","gravel-boards":"40200"},decking:{"boards-summit":"24322",joists:"208",screws:"131079"},paving:{"surface-council":"23995","surface-raj":"12369","surface-brindle":"304","surface-charcoal":"296","surface-pea":"431","sub-base":"569",bedding:"563"}}};function zd(e,t){let a=L_[jt().client??""]?.[e];if(!a)return null;let r=e==="plasterboard"&&t.key==="board"?t.label.split(" ")[0].toLowerCase():t.key;return a[r]??null}function _v(e,t){let a=t.map(r=>{let i=zd(e,r);return i?{key:r.key,productId:i.split(" ")[0],search:i,qty:r.qty,unit:r.unit}:null});return a.length>0&&a.every(Boolean)?a:null}var xv=new Map;function H_(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=`${jt().client??""}||${e}||${t??""}||${a}||${r??""}`,n=xv.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(pa(`/api/catalogue/search?${o.toString()}`),{headers:wi()}),c=await ka(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(H_):[];return xv.set(i,p),p}var j_=new Set(["bag","box","roll","pack"]),Q_=new Set(["each","bag","box","roll","pack","tub"]);function Ad(e,t){let a=t?.uoi,r=a!=null&&Q_.has(a.toLowerCase())&&(t?.uoi_count??1)===1;return j_.has(e)&&r?a:e}async function kv(e,t,a){return await Promise.all(e.map(async i=>{try{let n=a?zd(a,i):null,[o,l]=await Promise.all([n?fr(n,void 0,void 0,t).then(p=>p.find(d=>d.product_id===n.split(" ")[0]),()=>{}):void 0,fr(i.query,i.category,void 0,t)]),c=o?[o,...l.filter(p=>p.product_id!==o.product_id)]:l;return{requirement:{...i,unit:Ad(i.unit,c[0])},candidates:c}}catch{return{requirement:i,candidates:[]}}}))}async function Nv(){let e=await fetch(pa("/api/catalogue"),{headers:wi()});if(!e.ok)return{itemCount:0,uploadedAt:null};let t=await ka(e);return{itemCount:Number(t?.itemCount)||0,uploadedAt:t?.uploadedAt??null}}var X=G(ee()),G_=1.54,Y_=1440,X_=25,Rd=800,V_=1500,Ud=e=>Number.parseFloat(e)||0,On={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 Dd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let r=tc(),[i,n]=(0,hr.useState)("m"),[o,l]=(0,hr.useState)(""),[c,p]=(0,hr.useState)(""),[d,g]=(0,hr.useState)(""),[m,b]=(0,hr.useState)("concrete"),[y,T]=(0,hr.useState)("mot"),[D,f]=(0,hr.useState)(!1),[u,w]=(0,hr.useState)(null),v=i==="m"?1:.3048,S=Ud(o)*v*Ud(c)*v*Ud(d)*(i==="m"?.01:.0254),R=On[y],z=S*G_/7,A=z*Y_,Q=z*2,K=z*4,fe=Math.ceil(A/X_),Ue=Math.ceil(Q*On["sharp-sand"].density*1e3/Rd),Be=Math.ceil(K*On.gravel.density*1e3/Rd),Ye=Math.ceil(S*R.density*1e3/Rd),Ne=m==="concrete"?[{key:"cement",label:"Blue Circle General Purpose Grey Cement 25kg",qty:fe,productId:"6003004"},{key:"sharp-sand",label:"Sharp Sand Bulk Bag (800kg)",qty:Ue,productId:"6001012"},{key:"gravel",label:"20mm Non Decorative Pea Shingle/Gravel Bulk Bag (800kg)",qty:Be,productId:"6001004"}]:[{key:y,label:`${R.label} Bulk Bag (800kg)`,qty:Ye,productId:R.productId}],ve=()=>{if(t){t(Ne.map(se=>({key:se.key,label:se.label,qty:se.qty,unit:"each",query:se.productId})));return}oe()},oe=async()=>{let se=Date.now();f(!0),w(null);try{let ye=await Promise.all(Ne.map(async Ee=>{let $=(await fr(Ee.productId)).find(ue=>ue.product_id===Ee.productId);if(!$)throw new Error(`${Ee.label} is no longer available in this catalogue.`);return Pr($,{lineId:`concrete-aggregate:${Ee.key}`,description:Ee.label,unit:"bag",qty:Ee.qty})})),wt=V_-(Date.now()-se);wt>0&&await new Promise(Ee=>window.setTimeout(Ee,wt)),r?.clearCart(),r?.addManyToCart(ye),r?.openBasket()}catch(ye){w(ye instanceof Error?ye.message:"Could not add the products to your basket.")}finally{f(!1)}};return D?(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)("div",{className:"truss-estimator",children:[(0,X.jsxs)("div",{className:"quick-order-hero",children:[(0,X.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,X.jsx)("h1",{children:"Your Materials"}),(0,X.jsx)("p",{children:"Calculating quantities from the Concrete and Aggregate Calculator."})]}),(0,X.jsx)("div",{className:"truss-estimator__card",children:(0,X.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,X.jsx)(dr,{}),(0,X.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})}):(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)("div",{className:"truss-estimator",children:[(0,X.jsxs)("div",{className:"quick-order-hero",children:[(0,X.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,X.jsx)("h1",{children:"Concrete and Aggregate Calculator"}),(0,X.jsx)("p",{children:"Calculate fixed site-mix concrete ingredients or aggregate bulk bags."})]}),(0,X.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,X.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose what you need"}),(0,X.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,X.jsxs)("div",{className:"materials-calculator__section",children:[(0,X.jsx)("div",{className:"truss-estimator__section-heading",children:"Material type"}),(0,X.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,X.jsxs)("button",{type:"button",className:`truss-estimator__option-card${m==="concrete"?" is-selected":""}`,onClick:()=>b("concrete"),children:[(0,X.jsx)("div",{className:"truss-estimator__option-title",children:"Site-mixed concrete"}),(0,X.jsx)("div",{className:"truss-estimator__option-copy",children:"Cement, sharp sand and 20mm aggregate"})]}),(0,X.jsxs)("button",{type:"button",className:`truss-estimator__option-card${m==="aggregate"?" is-selected":""}`,onClick:()=>b("aggregate"),children:[(0,X.jsx)("div",{className:"truss-estimator__option-title",children:"Aggregates"}),(0,X.jsx)("div",{className:"truss-estimator__option-copy",children:"MOT Type 1, sharp sand or 20mm gravel"})]})]})]}),m==="aggregate"&&(0,X.jsxs)("div",{className:"materials-calculator__section",children:[(0,X.jsx)("div",{className:"truss-estimator__section-heading",children:"Aggregate type"}),(0,X.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.keys(On).map(se=>(0,X.jsxs)("button",{type:"button",className:`truss-estimator__option-card${y===se?" is-selected":""}`,onClick:()=>T(se),children:[(0,X.jsx)("div",{className:"truss-estimator__option-title",children:On[se].label}),(0,X.jsx)("div",{className:"truss-estimator__option-copy",children:On[se].blurb})]},se))})]}),(0,X.jsxs)("div",{className:"materials-calculator__section",children:[(0,X.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and depth"}),(0,X.jsxs)("div",{className:"materials-calculator__unit-row",children:[(0,X.jsx)("span",{children:"Units"}),(0,X.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,X.jsx)("button",{type:"button",className:i==="m"?"is-selected":"",onClick:()=>n("m"),children:"Metric"}),(0,X.jsx)("button",{type:"button",className:i==="ft"?"is-selected":"",onClick:()=>n("ft"),children:"Imperial"})]})]}),(0,X.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,X.jsxs)("label",{className:"truss-estimator__field",children:[(0,X.jsxs)("span",{children:["Length (",i,")"]}),(0,X.jsx)("input",{type:"number",min:"0",step:"0.01",value:o,onChange:se=>l(se.target.value)})]}),(0,X.jsxs)("label",{className:"truss-estimator__field",children:[(0,X.jsxs)("span",{children:["Width (",i,")"]}),(0,X.jsx)("input",{type:"number",min:"0",step:"0.01",value:c,onChange:se=>p(se.target.value)})]})]}),(0,X.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,X.jsxs)("span",{children:["Depth (",i==="m"?"cm":"inches",")"]}),(0,X.jsx)("input",{type:"number",min:"0",step:"0.1",value:d,onChange:se=>g(se.target.value)})]})]}),(0,X.jsxs)("div",{className:"materials-calculator__totals",children:[(0,X.jsx)("div",{className:"truss-estimator__section-heading",children:"Materials required"}),(0,X.jsx)("div",{className:"materials-calculator__result-grid",children:m==="concrete"?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)("div",{children:[(0,X.jsx)("span",{children:"Cement"}),(0,X.jsxs)("strong",{children:[A.toFixed(0)," kg"]})]}),(0,X.jsxs)("div",{children:[(0,X.jsx)("span",{children:"Sharp sand"}),(0,X.jsxs)("strong",{children:[Q.toFixed(2)," m\xB3"]})]}),(0,X.jsxs)("div",{children:[(0,X.jsx)("span",{children:"20mm aggregate"}),(0,X.jsxs)("strong",{children:[K.toFixed(2)," m\xB3"]})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)("div",{children:[(0,X.jsx)("span",{children:R.label}),(0,X.jsxs)("strong",{children:[S.toFixed(2)," m\xB3"]})]}),(0,X.jsxs)("div",{children:[(0,X.jsx)("span",{children:"Approx. weight"}),(0,X.jsxs)("strong",{children:[(S*R.density).toFixed(2)," t"]})]}),(0,X.jsx)("div",{})]})}),(0,X.jsx)("p",{className:"materials-calculator__note",children:m==="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,X.jsx)("p",{className:"results-empty-hint estimator-products__error",children:u}),(0,X.jsxs)("div",{className:"materials-calculator__actions",children:[(0,X.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,X.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:ve,disabled:S<=0||D,children:D?"Adding products\u2026":a})]})]})]})})}var Ya=G(Xe());var U=G(ee()),Bn=12,Ln=8,ic=.56,Sv=.21,Ra={ranges:{meridian:{label:"Standard grooved timber",blurb:"32 \xD7 125mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.125},summit:{label:"Wide grooved timber",blurb:"32 \xD7 150mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.15}},boardGapM:.006,wastage:{straight:.05,diagonal:.15},pictureFrame:{extraWastage:.08},joist:{spacingOptions:[{id:"300",label:"300mm centres (heavy duty)",spacingM:.3},{id:"400",label:"400mm centres (standard)",spacingM:.4},{id:"450",label:"450mm centres (light use)",spacingM:.45}]}},Ni=["range","grid","pictureFrame","substructure"],$_={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:""}},nc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),oc=(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),Z_=(e,t,a,r)=>{let i=nc(e,t,a),n=nc(e,t,r),o=nc(a,r,e),l=nc(a,r,t);return i===0&&oc(e,t,a)||n===0&&oc(e,t,r)||o===0&&oc(a,r,e)||l===0&&oc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},Od=(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)&&Z_(e[r],i,e[n],e[(n+1)%e.length]))return!0}return!1};function Bd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ya.useState)(0),[n,o]=(0,Ya.useState)($_),[l,c]=(0,Ya.useState)(1),[p,d]=(0,Ya.useState)({x:0,y:0}),[g,m]=(0,Ya.useState)(null),b=(0,Ya.useRef)(null),y=(0,Ya.useRef)(null),T=(0,Ya.useRef)(null),D=Ni[r],f=n.range?Ra.ranges[n.range]:null,u=Bn/l,w=Ln/l,v=(Bn-u)/2,S=(Ln-w)/2,R=Math.max(-Bn,Math.min(Bn*2-u,v+p.x)),z=Math.max(-Ln,Math.min(Ln*2-w,S+p.y)),A=Number.parseFloat(n.quickLengthM),Q=Number.parseFloat(n.quickWidthM),K=A>0&&Q>0,fe=E=>Math.abs(E.reduce((O,re,ce)=>{let ge=E[(ce+1)%E.length];return O+re.x*ge.y-ge.x*re.y},0))/2,Ue=(E,O)=>Math.hypot(O.x-E.x,O.y-E.y),Be=n.isOutlineClosed?fe(n.points):0,Ye=n.isOutlineClosed?n.points.reduce((E,O,re)=>E+Ue(O,n.points[(re+1)%n.points.length]),0):0,Ne=n.isOutlineClosed?n.points.reduce((E,O,re)=>E+(n.wallSegments.has(re)?0:Ue(O,n.points[(re+1)%n.points.length])),0):0,ve=n.points.reduce((E,O)=>({x:E.x+O.x/n.points.length,y:E.y+O.y/n.points.length}),{x:0,y:0}),oe=n.points.length>1?(()=>{let E=n.points[0],O=n.points[1],re=Ue(E,O),ce=re?-(O.y-E.y)/re:0,ge=re?(O.x-E.x)/re:0,Ae=(E.x+O.x)/2,Pe=(E.y+O.y)/2,h=ce*(Ae-ve.x)+ge*(Pe-ve.y)>=0?1:-1;return{x:Ae+ce*ic*h,y:Pe+ge*ic*h}})():null,ye=(()=>{let E=n.range?Ra.ranges[n.range]:Ra.ranges.meridian,O=n.deckSizeMode==="quick"?A*Q:Be,re=n.deckSizeMode==="quick"?2*(A+Q):Ne,ce=n.direction==="diagonal"?Ra.wastage.diagonal:Ra.wastage.straight,ge=n.pictureFrame==="yes"?Ra.pictureFrame.extraWastage:0,Pe=O/(E.boardWidthM+Ra.boardGapM)/E.boardLengthM,h=Math.ceil(Pe*(1+ce+ge)),M=Math.ceil(O*30*(1+ce+ge)/200),N=Ra.joist.spacingOptions.find(k=>k.id===n.joistSpacing)??Ra.joist.spacingOptions[1],Y=O/N.spacingM,Z=Math.ceil(Y);return{range:E,area:O,boardCount:h,screwBoxes:M,joistMetres:Z,spacing:N}})(),wt=ye?[{key:`boards-${n.range??"meridian"}`,label:`Deck boards (${ye.range.label})`,qty:ye.boardCount,unit:"each",query:"timber decking board",category:"decking",calculatorWasteIncluded:!0},{key:"joists",label:"Treated C24 joists",qty:ye.joistMetres,unit:"m",query:"treated joist",category:"timber",calculatorWasteIncluded:!0},{key:"screws",label:"Green decking screws (200/box)",qty:ye.screwBoxes,unit:"box",query:"green decking screws",category:"fixings",calculatorWasteIncluded:!0}]:[],Ee=()=>D==="range"?!!n.range:D==="grid"?n.deckSizeMode==="quick"?K:n.isOutlineClosed&&Be>0:D==="pictureFrame"?!!n.pictureFrame&&!!n.direction:D==="substructure"?!!n.joistSpacing:!0,$=r===Ni.length-1?a:"Next",ue=(E,O,re=!1)=>{let ce=T.current?.getBoundingClientRect();if(!ce)return null;let ge=re?1:.25;return{x:Math.round(Math.max(R,Math.min(R+u,R+(E-ce.left)/ce.width*u))/ge)*ge,y:Math.round(Math.max(z,Math.min(z+w,z+(O-ce.top)/ce.height*w))/ge)*ge}},Ze=E=>{if(n.isOutlineClosed){let re=E.target;if(re!==E.currentTarget&&!re.classList.contains("deck-outline__grid"))return;y.current={startX:E.clientX,startY:E.clientY,startViewX:R,startViewY:z},E.currentTarget.setPointerCapture(E.pointerId);return}if(n.drawMode!=="outline")return;let O=ue(E.clientX,E.clientY,!0);O&&(m(null),o(re=>{let ce=[...re.points,O];return Od(ce,!1)?{...re,drawError:"Edges cannot cross. Choose another corner."}:{...re,points:ce,drawError:""}}))},pt=(E,O)=>{if(!n.isOutlineClosed){E.stopPropagation(),O===0&&n.points.length>=3&&o(re=>({...re,isOutlineClosed:!0,drawMode:"edges"}));return}E.stopPropagation(),b.current=O,E.currentTarget.setPointerCapture(E.pointerId)},vt=E=>{if(y.current){let ce=T.current?.getBoundingClientRect();if(!ce)return;let ge=y.current,Ae=ge.startViewX-(E.clientX-ge.startX)/ce.width*u,Pe=ge.startViewY-(E.clientY-ge.startY)/ce.height*w;d({x:Ae-v,y:Pe-S});return}!n.isOutlineClosed&&n.drawMode==="outline"&&m(ue(E.clientX,E.clientY,!0));let O=b.current;if(O===null)return;let re=ue(E.clientX,E.clientY);re&&o(ce=>{let ge=ce.points.map((Ae,Pe)=>Pe===O?re:Ae);return Od(ge,!0)?{...ce,drawError:"Edges cannot cross. Move the corner to a different position."}:{...ce,points:ge,drawError:""}})},He=E=>{y.current=null,b.current=null,E.currentTarget.hasPointerCapture(E.pointerId)&&E.currentTarget.releasePointerCapture(E.pointerId)},de=E=>{o(O=>{let re=new Set(O.wallSegments);return re.has(E)?re.delete(E):re.add(E),{...O,wallSegments:re}})},_e=()=>{r===0?e():i(E=>E-1)},Se=()=>{Ee()&&(r===Ni.length-1?t?.(wt):i(E=>E+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(Ra.ranges).map(([E,O])=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===E?" is-selected":""}`,onClick:()=>o(re=>({...re,range:E})),children:[(0,U.jsx)("div",{className:"truss-estimator__option-title",children:O.label}),(0,U.jsx)("div",{className:"truss-estimator__option-copy",children:O.blurb}),(0,U.jsxs)("div",{className:"truss-estimator__option-copy",children:[O.boardLengthM,"m boards"]})]},E))})]}):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(E=>({...E,deckSizeMode:"quick"})),children:"Quick estimate"}),(0,U.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.deckSizeMode==="draw"?" is-selected":""}`,onClick:()=>o(E=>({...E,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:E=>o(O=>({...O,quickLengthM:E.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:E=>o(O=>({...O,quickWidthM:E.target.value}))})]})]}),(0,U.jsx)("div",{className:"truss-estimator__grid-hint",children:"For L-shaped decks, cut-outs, or sides against a wall, use Draw your space."}),K?(0,U.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,U.jsxs)("div",{children:[(A*Q).toFixed(2)," m\xB2 deck"]}),(0,U.jsxs)("div",{children:[(2*(A+Q)).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:[Be.toFixed(2)," m\xB2"]})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Perimeter"}),(0,U.jsxs)("strong",{children:[Ye.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:[Ne.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(E=>({...E,points:E.points.slice(0,-1)})),disabled:n.points.length===0||n.isOutlineClosed,children:"Undo"}),(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{m(null),o(E=>({...E,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(E=>({...E,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:T,className:`deck-outline__canvas${n.isOutlineClosed?" is-pan-mode":""}`,viewBox:`${R} ${z} ${u} ${w}`,preserveAspectRatio:"none","aria-label":"Deck outline drawing area",onPointerDown:Ze,onPointerMove:vt,onPointerUp:He,onPointerLeave:()=>{m(null),y.current||(b.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:-Bn,y:-Ln,width:Bn*3,height:Ln*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(E=>`${E.x},${E.y}`).join(" ")}):null,n.isOutlineClosed?(0,U.jsx)("polygon",{className:"deck-outline__shape",points:n.points.map(E=>`${E.x},${E.y}`).join(" "),stroke:"none"}):null,n.points.length>1?n.points.slice(0,n.isOutlineClosed?void 0:-1).map((E,O)=>{let re=n.points[n.isOutlineClosed?(O+1)%n.points.length:O+1],ce=Ue(E,re),ge=ce?-(re.y-E.y)/ce:0,Ae=ce?(re.x-E.x)/ce:0,Pe=(E.x+re.x)/2,h=(E.y+re.y)/2,M=ge*(Pe-ve.x)+Ae*(h-ve.y)>=0?1:-1,N=Pe+ge*ic*M,Y=h+Ae*ic*M;return(0,U.jsxs)("g",{children:[(0,U.jsx)("line",{className:"deck-outline__edge-hit",x1:E.x,y1:E.y,x2:re.x,y2:re.y,onClick:n.isOutlineClosed?()=>de(O):void 0}),(0,U.jsx)("line",{className:`deck-outline__edge${n.wallSegments.has(O)?" is-wall":""}`,x1:E.x,y1:E.y,x2:re.x,y2:re.y,pointerEvents:"none"}),(0,U.jsxs)("text",{className:`deck-outline__edge-label${n.wallSegments.has(O)?" is-wall":""}`,x:N,y:Y,textAnchor:"middle",dominantBaseline:"central",fontSize:Sv/l,children:[ce.toFixed(2)," m"]})]},`segment-${O}`)}):null,!n.isOutlineClosed&&n.points.length>0&&g?(()=>{let E=n.points[n.points.length-1],O=Ue(E,g);if(!O)return null;let re=-(g.y-E.y)/O,ce=(g.x-E.x)/O,ge=(E.x+g.x)/2,Ae=(E.y+g.y)/2;return(0,U.jsxs)("g",{className:"deck-outline__live-measurement",children:[(0,U.jsx)("line",{x1:E.x,y1:E.y,x2:g.x,y2:g.y}),(0,U.jsxs)("text",{x:ge+re*.34,y:Ae+ce*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:Sv/l,children:[O.toFixed(2)," m"]})]})})():null,n.points.map((E,O)=>(0,U.jsx)("circle",{className:"deck-outline__point",cx:E.x,cy:E.y,r:"0.13",onPointerDown:re=>pt(re,O)},`point-${O}`))]}),(0,U.jsxs)("div",{className:"deck-outline__zoom","aria-label":"Zoom controls",children:[(0,U.jsx)("button",{type:"button",onClick:()=>c(E=>Math.max(.5,E-.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(E=>Math.min(1,E+.25)),disabled:l===1,"aria-label":"Zoom in",children:"+"})]}),n.isOutlineClosed&&n.wallSegments.size===0&&oe?(0,U.jsx)("div",{className:"deck-outline__edge-prompt",role:"status",style:{left:`${(oe.x-R)/u*100}%`,top:`${(oe.y-z)/w*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(E=>Od(E.points,!0)?{...E,drawError:"Edges cannot cross. Adjust the outline before finishing."}:{...E,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(E=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.pictureFrame===E.id?" is-selected":""}`,onClick:()=>o(O=>({...O,pictureFrame:E.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:It(E.img),alt:""}),(0,U.jsx)("span",{children:E.label})]},E.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(E=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.direction===E.id?" is-selected":""}`,onClick:()=>o(O=>({...O,direction:E.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:It(E.img),alt:""}),(0,U.jsx)("span",{children:E.label})]},E.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:Ra.joist.spacingOptions.map(E=>(0,U.jsx)("button",{type:"button",className:`truss-estimator__option-card${n.joistSpacing===E.id?" is-selected":""}`,onClick:()=>o(O=>({...O,joistSpacing:E.id})),children:(0,U.jsx)("div",{className:"truss-estimator__option-title",children:E.label})},E.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:_e,children:"Back"}),(0,U.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:Se,disabled:!Ee(),children:[(0,U.jsx)("span",{children:$}),(0,U.jsx)("span",{className:"arrow",children:(0,U.jsx)(Qt,{})})]})]})]})]})})}var Ea=G(Xe());var j=G(ee()),Cv=12,qv=30,Hn=12,jn=8,Ev=.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"],K_={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:""}},lc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),sc=(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),P_=(e,t,a,r)=>{let i=lc(e,t,a),n=lc(e,t,r),o=lc(a,r,e),l=lc(a,r,t);return i===0&&sc(e,t,a)||n===0&&sc(e,t,r)||o===0&&sc(a,r,e)||l===0&&sc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},cc=(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)&&P_(e[r],e[(r+1)%e.length],e[i],e[(i+1)%e.length]))return!0;return!1};function Ld({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ea.useState)(0),[n,o]=(0,Ea.useState)(K_),l=(0,Ea.useRef)(null),c=(0,Ea.useRef)(null),[p,d]=(0,Ea.useState)(1),[g,m]=(0,Ea.useState)({x:0,y:0}),[b,y]=(0,Ea.useState)(null),T=(0,Ea.useRef)(null),D=(0,Ea.useRef)(null),f=(0,Ea.useRef)(null),u=Si[r],w=n.range?qa.ranges[n.range]:null,v=Hn/p,S=jn/p,R=(Hn-v)/2,z=(jn-S)/2,A=Math.max(-Hn,Math.min(Hn*2-v,R+g.x)),Q=Math.max(-jn,Math.min(jn*2-S,z+g.y)),K=n.boundaryPoints.reduce((h,M)=>({x:h.x+M.x/Math.max(1,n.boundaryPoints.length),y:h.y+M.y/Math.max(1,n.boundaryPoints.length)}),{x:0,y:0}),fe=h=>{let M=new Set,N=[];return h.forEach(Y=>{let[Z,k]=Y.split(",").map(Number),L=[{key:`H,${Z},${k}`,type:"H",x:Z,y:k},{key:`H,${Z},${k+1}`,type:"H",x:Z,y:k+1},{key:`V,${Z},${k}`,type:"V",x:Z,y:k},{key:`V,${Z+1},${k}`,type:"V",x:Z+1,y:k}],P=[!h.has(`${Z},${k-1}`),!h.has(`${Z},${k+1}`),!h.has(`${Z-1},${k}`),!h.has(`${Z+1},${k}`)];L.forEach((pe,xe)=>{P[xe]&&!M.has(pe.key)&&(M.add(pe.key),N.push(pe))})}),N},Ue=(h,M)=>fe(h).filter(N=>!M.has(N.key)),Be=(h,M)=>Ue(h,M).length,Ye=(h,M)=>{let N={};Ue(h,M).forEach(Z=>{var k,L,P,pe;Z.type==="H"?((N[k=`${Z.x},${Z.y}`]||(N[k]=[])).push("H"),(N[L=`${Z.x+1},${Z.y}`]||(N[L]=[])).push("H")):((N[P=`${Z.x},${Z.y}`]||(N[P]=[])).push("V"),(N[pe=`${Z.x},${Z.y+1}`]||(N[pe]=[])).push("V"))});let Y=0;return Object.values(N).forEach(Z=>{(Z.length===1||Z.length===2&&Z[0]!==Z[1]||Z.length>=3)&&(Y+=1)}),Y},ve=(()=>{let h=n.range?qa.ranges[n.range]:qa.ranges.boundary,M=n.height??"1.8",N=n.boundaryMode==="quick"?Math.max(0,Number.parseFloat(n.quickLengthM)||0):n.boundaryClosed?n.boundaryPoints.slice(0,-1).reduce((Yt,br,kt)=>Yt+(n.excludedBoundaryEdges.has(kt)?0:Math.hypot(n.boundaryPoints[kt+1].x-br.x,n.boundaryPoints[kt+1].y-br.y)),0):0,Y=n.gateType&&n.gateType!=="none"?Number.parseFloat(n.gateWidthM)||qa.gate[n.gateType].widthDefault:0,Z=Math.max(0,N-Y),k=Z>0?Math.ceil(Z/h.panelWidthM):0,L=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,P=n.boundaryMode==="quick"?Z>0?2:0:n.boundaryClosed?n.boundaryPoints.slice(0,L?-1:void 0).reduce((Yt,br,kt)=>{let qi=kt>0&&!n.excludedBoundaryEdges.has(kt-1),am=kt<n.boundaryPoints.length-1&&!n.excludedBoundaryEdges.has(kt);return Yt+(qi||am?1:0)},0):0,pe=Z>0?Math.ceil(Z/h.panelWidthM)+1:0,xe=Math.max(0,pe-P),xt=n.mountingType?qa.mounting[n.mountingType]:qa.mounting.concrete,it=n.gateType&&n.gateType!=="none"?2:0,Et=xe+P+it,tm=n.mountingType==="postcrete"?Et*qa.mounting.postcrete.bagsPerPost:0,Ir=n.gravelBoard==="yes"?k:0;return{range:h,height:M,totalEdgeM:N,fencedLengthM:Z,gateWidthM:Y,panelsCount:k,cornerPostCount:P,intermediatePostCount:xe,gatePostCount:it,totalPostCount:Et,bagsCount:tm,gravelCount:Ir,capCount:Et,mounting:xt}})(),oe=n.gateType&&n.gateType!=="none"?qa.gate[n.gateType].label:null,se=Number(ve.height)<=1.2?"6":"8",ye=ve?[{key:`panels-${n.range??"boundary"}-${ve.height}`,label:`${ve.range.label} panels (${ve.height}m)`,qty:ve.panelsCount,unit:"each",query:"fence panel",category:"fencing"},...n.mountingType==="concrete"?[{key:`concrete-intermediate-${se}`,label:"Intermediate concrete posts",qty:ve.intermediatePostCount,unit:"each",query:"concrete fence post",category:"fencing"},{key:`concrete-end-${se}`,label:"End and corner concrete posts",qty:ve.cornerPostCount+ve.gatePostCount,unit:"each",query:"concrete end post",category:"fencing"}]:[{key:`timber-post-${se}`,label:"Timber fence posts",qty:ve.totalPostCount,unit:"each",query:"timber fence post",category:"fencing"},{key:"postcrete",label:"Postcrete",qty:ve.bagsCount,unit:"bag",query:"postcrete",category:"cement"}],...oe?[{key:"gate",label:oe,qty:1,unit:"each",query:"lap gate",category:"fencing"}]:[],...ve.gravelCount>0?[{key:"gravel-boards",label:"Concrete gravel boards",qty:ve.gravelCount,unit:"each",query:"gravel board",category:"fencing"}]:[]]:[],wt=()=>{if(u==="range"){let h=n.boundaryMode==="quick"?(Number.parseFloat(n.quickLengthM)||0)>0:n.boundaryClosed&&n.boundaryPoints.length>=2;return!!n.range&&h}return u==="height"?!!n.height&&!!n.gravelBoard:u==="gate"?!!n.gateType&&(n.gateType==="none"||n.gateWidthM.trim()!==""):u==="posts"?!!n.mountingType:!0},Ee=r===Si.length-1?a:"Next",$=h=>{o(M=>{let N=h(new Set(M.grid)),Y=new Set([...M.excludedEdges].filter(Z=>fe(N).some(k=>k.key===Z)));return{...M,grid:N,excludedEdges:Y}})},ue=(h,M,N)=>{$(Y=>{let Z=`${h},${M}`;return N?Y.add(Z):Y.delete(Z),Y})},Ze=(h,M,N,Y,Z)=>{let k=h,L=M,P=Math.abs(N-h),pe=h<N?1:-1,xe=-Math.abs(Y-M),xt=M<Y?1:-1,it=P+xe;for(;ue(k,L,Z),!(k===N&&L===Y);){let Et=2*it;Et>=xe&&(it+=xe,k+=pe),Et<=P&&(it+=P,L+=xt)}},pt=(h,M)=>{let N=c.current?.getBoundingClientRect();if(!N)return null;let Y=Math.floor((h-N.left)/qv),Z=Math.floor((M-N.top)/qv);return Y<0||Z<0||Y>=Cv||Z>=Cv?null:{x:Y,y:Z}},vt=h=>{if(n.gridMode!=="draw")return;let M=pt(h.clientX,h.clientY);if(!M)return;h.preventDefault();let N=`${M.x},${M.y}`,Y=!n.grid.has(N);l.current={active:!0,paintValue:Y,lastX:M.x,lastY:M.y},h.currentTarget.setPointerCapture(h.pointerId),ue(M.x,M.y,Y)},He=h=>{let M=l.current;if(!M?.active)return;let N=pt(h.clientX,h.clientY);N&&(N.x===M.lastX&&N.y===M.lastY||(Ze(M.lastX,M.lastY,N.x,N.y,M.paintValue),l.current={...M,lastX:N.x,lastY:N.y}))},de=h=>{l.current?.active&&(l.current=null,h.currentTarget.releasePointerCapture(h.pointerId))},_e=(h,M,N=!1)=>{let Y=f.current?.getBoundingClientRect();if(!Y)return null;let Z=N?1:.25;return{x:Math.round(Math.max(A,Math.min(A+v,A+(h-Y.left)/Y.width*v))/Z)*Z,y:Math.round(Math.max(Q,Math.min(Q+S,Q+(M-Y.top)/Y.height*S))/Z)*Z}},Se=h=>{if(n.boundaryClosed){let N=h.target;if(N!==h.currentTarget&&!N.classList.contains("fence-boundary__grid"))return;D.current={startX:h.clientX,startY:h.clientY,startViewX:A,startViewY:Q},h.currentTarget.setPointerCapture(h.pointerId);return}let M=_e(h.clientX,h.clientY,!0);M&&(y(null),o(N=>{let Y=[...N.boundaryPoints,M];return cc(Y,!1)?{...N}:{...N,boundaryPoints:Y}}))},E=(h,M)=>{if(h.stopPropagation(),!n.boundaryClosed){if(M!==0||n.boundaryPoints.length<3)return;o(N=>cc(N.boundaryPoints,!0)?N:{...N,boundaryPoints:[...N.boundaryPoints,N.boundaryPoints[0]],boundaryClosed:!0});return}T.current=M,h.currentTarget.setPointerCapture(h.pointerId)},O=h=>{if(D.current){let N=f.current?.getBoundingClientRect();if(!N)return;let Y=D.current,Z=Y.startViewX-(h.clientX-Y.startX)/N.width*v,k=Y.startViewY-(h.clientY-Y.startY)/N.height*S;m({x:Z-R,y:k-z});return}if(n.boundaryClosed||y(_e(h.clientX,h.clientY,!0)),T.current===null)return;let M=_e(h.clientX,h.clientY);M&&o(N=>{let 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,Z=N.boundaryPoints.map((k,L)=>{let P=L===T.current,pe=Y&&T.current===0&&L===N.boundaryPoints.length-1;return P||pe?M:k});return cc(Z,!1)?N:{...N,boundaryPoints:Z}})},re=h=>{D.current=null,T.current=null,h.currentTarget.hasPointerCapture(h.pointerId)&&h.currentTarget.releasePointerCapture(h.pointerId)},ce=h=>{o(M=>{let N=new Set(M.excludedBoundaryEdges);return N.has(h)?N.delete(h):N.add(h),{...M,excludedBoundaryEdges:N}})},ge=()=>{r===0?e():i(h=>h-1)},Ae=()=>{wt()&&(r===Si.length-1?t?.(ye):i(h=>h+1))},Pe=fe(n.grid);return(0,j.jsx)(j.Fragment,{children:(0,j.jsxs)("div",{className:"truss-estimator",children:[(0,j.jsxs)("div",{className:"quick-order-hero",children:[(0,j.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,j.jsx)("h1",{children:"Fencing Calculator"}),(0,j.jsx)("p",{children:"Estimate panels, posts and cost for your fence line in a few steps."})]}),(0,j.jsxs)("div",{className:"truss-estimator__card",children:[(0,j.jsxs)("div",{className:"truss-estimator__body",children:[u==="range"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your fence panels"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"The calculator uses fixed, orderable timber panels from the catalogue."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(qa.ranges).map(([h,M])=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===h?" is-selected":""}`,onClick:()=>o(N=>({...N,range:h})),children:[(0,j.jsx)("div",{className:"truss-estimator__option-title",children:M.label}),(0,j.jsx)("div",{className:"truss-estimator__option-copy",children:M.blurb})]},h))})]}):null,u==="range"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("div",{className:"truss-estimator__section-heading",children:"Measure your fence line"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"Use a quick total, or draw the boundary to mark existing edges that do not need new fencing."}),(0,j.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,j.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="quick"?" is-selected":""}`,onClick:()=>o(h=>({...h,boundaryMode:"quick"})),children:"Quick estimate"}),(0,j.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="draw"?" is-selected":""}`,onClick:()=>o(h=>({...h,boundaryMode:"draw"})),children:"Draw your boundary"})]}),n.boundaryMode==="quick"?(0,j.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact fence-boundary__quick-field",children:[(0,j.jsx)("span",{children:"Total fence length (m)"}),(0,j.jsx)("input",{type:"number",min:"0",step:"0.1",value:n.quickLengthM,onChange:h=>o(M=>({...M,quickLengthM:h.target.value}))})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("div",{className:"fence-boundary__toolbar",children:(0,j.jsxs)("div",{className:"fence-boundary__actions",children:[(0,j.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(h=>({...h,boundaryPoints:h.boundaryPoints.slice(0,-1),boundaryClosed:!1,excludedBoundaryEdges:new Set})),disabled:n.boundaryPoints.length===0||n.boundaryClosed,children:"Undo"}),(0,j.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{m({x:0,y:0}),y(null),o(h=>({...h,boundaryPoints:[],boundaryClosed:!1,excludedBoundaryEdges:new Set}))},disabled:n.boundaryPoints.length===0,children:"Clear"}),(0,j.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(h=>({...h,boundaryPoints:[{x:2,y:2},{x:8,y:2},{x:8,y:5},{x:2,y:5},{x:2,y:2}],boundaryClosed:!0,excludedBoundaryEdges:new Set})),children:"Start with rectangle"})]})}),(0,j.jsxs)("div",{className:"fence-boundary",children:[(0,j.jsxs)("svg",{ref:f,className:`fence-boundary__canvas${n.boundaryClosed?" is-pan-mode":""}`,viewBox:`${A} ${Q} ${v} ${S}`,preserveAspectRatio:"none","aria-label":"Fence boundary drawing area",onPointerDown:Se,onPointerMove:O,onPointerUp:re,onPointerLeave:()=>{y(null),D.current||(T.current=null)},children:[(0,j.jsx)("defs",{children:(0,j.jsx)("pattern",{id:"fence-boundary-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,j.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,j.jsx)("rect",{x:-Hn,y:-jn,width:Hn*3,height:jn*3,className:"fence-boundary__grid",fill:"url(#fence-boundary-grid)"}),n.boundaryPoints.length>1?(0,j.jsx)("polyline",{className:"fence-boundary__preview",points:n.boundaryPoints.map(h=>`${h.x},${h.y}`).join(" ")}):null,n.boundaryPoints.length>1?n.boundaryPoints.slice(0,-1).map((h,M)=>{let N=n.boundaryPoints[M+1],Y=Math.hypot(N.x-h.x,N.y-h.y),Z=Y?-(N.y-h.y)/Y:0,k=Y?(N.x-h.x)/Y:0,L=(h.x+N.x)/2,P=(h.y+N.y)/2,pe=Z*(L-K.x)+k*(P-K.y)>=0?1:-1,xe=L+Z*Ev*pe,xt=P+k*Ev*pe;return(0,j.jsxs)("g",{children:[(0,j.jsx)("line",{className:"fence-boundary__edge-hit",x1:h.x,y1:h.y,x2:N.x,y2:N.y,onClick:n.boundaryClosed?()=>ce(M):void 0}),(0,j.jsx)("line",{className:`fence-boundary__edge${n.excludedBoundaryEdges.has(M)?" is-excluded":""}`,x1:h.x,y1:h.y,x2:N.x,y2:N.y,pointerEvents:"none"}),(0,j.jsxs)("text",{className:`fence-boundary__edge-label${n.excludedBoundaryEdges.has(M)?" is-excluded":""}`,x:xe,y:xt,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[Y.toFixed(2)," m"]})]},`fence-edge-${M}`)}):null,!n.boundaryClosed&&n.boundaryPoints.length>0&&b?(()=>{let h=n.boundaryPoints[n.boundaryPoints.length-1],M=Math.hypot(b.x-h.x,b.y-h.y);if(!M)return null;let N=-(b.y-h.y)/M,Y=(b.x-h.x)/M,Z=(h.x+b.x)/2,k=(h.y+b.y)/2;return(0,j.jsxs)("g",{className:"fence-boundary__live-measurement",children:[(0,j.jsx)("line",{x1:h.x,y1:h.y,x2:b.x,y2:b.y}),(0,j.jsxs)("text",{x:Z+N*.34,y:k+Y*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[M.toFixed(2)," m"]})]})})():null,n.boundaryPoints.map((h,M)=>M>0&&M===n.boundaryPoints.length-1&&h.x===n.boundaryPoints[0]?.x&&h.y===n.boundaryPoints[0]?.y?null:(0,j.jsx)("circle",{className:`fence-boundary__point${!n.boundaryClosed&&M===0&&n.boundaryPoints.length>=3?" is-close-target":""}`,cx:h.x,cy:h.y,r:"0.13",onPointerDown:N=>E(N,M)},`fence-point-${M}`))]}),(0,j.jsxs)("div",{className:"fence-boundary__zoom","aria-label":"Zoom controls",children:[(0,j.jsx)("button",{type:"button",onClick:()=>d(h=>Math.max(.5,h-.25)),disabled:p===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,j.jsxs)("span",{children:[Math.round(p*100),"%"]}),(0,j.jsx)("button",{type:"button",onClick:()=>d(h=>Math.min(1,h+.25)),disabled:p===1,"aria-label":"Zoom in",children:"+"})]}),!n.boundaryClosed&&n.boundaryPoints.length>=2?(0,j.jsx)("button",{type:"button",className:"fence-boundary__close",onClick:()=>o(h=>cc(h.boundaryPoints,!1)?h:{...h,boundaryClosed:!0}),children:"Finish fence line"}):null]}),(0,j.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,j.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,j.jsx)("div",{children:n.boundaryMode==="quick"?`${(Number.parseFloat(n.quickLengthM)||0).toFixed(2)} m fence line`:`${ve.totalEdgeM.toFixed(2)} m fence line`}),n.boundaryMode==="draw"&&n.boundaryClosed?(0,j.jsxs)("div",{children:[ve.cornerPostCount," corner/end posts"]}):null]})]}):null,null,u==="height"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Fence height"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"Select the nearest available panel height."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:qa.heights.map(h=>(0,j.jsx)("button",{type:"button",className:`truss-estimator__visual-card${n.height===h?" is-selected":""}`,onClick:()=>o(M=>({...M,height:h})),children:(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--tall",src:It(`/fencing/height/${h}.webp`),alt:""})},h))}),(0,j.jsx)("div",{className:"truss-estimator__section-heading",children:"Gravel board?"}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"no",label:"No gravel board",img:"/fencing/no-gravel-board.webp"},{id:"yes",label:"Add gravel board",img:"/fencing/gravel-board.webp"}].map(h=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.gravelBoard===h.id?" is-selected":""}`,onClick:()=>o(M=>({...M,gravelBoard:h.id})),children:[(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:It(h.img),alt:""}),(0,j.jsx)("span",{children:h.label})]},h.id))})]}):null,u==="gate"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Do you need a gate?"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"A gate opening replaces part of the panel run and adds a gate kit with heavy-duty posts."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"none",label:"No gate",img:"/fencing/gates/no-gate.webp"},{id:"single",label:"Single gate",img:"/fencing/gates/single-gate.webp"}].map(h=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${n.gateType===h.id?" is-selected":""}`,onClick:()=>o(M=>({...M,gateType:h.id,gateWidthM:h.id==="none"?"":String(qa.gate[h.id].widthDefault)})),children:[(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:It(h.img),alt:""}),(0,j.jsx)("span",{children:h.label})]},h.id))}),n.gateType&&n.gateType!=="none"?(0,j.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,j.jsx)("span",{children:"Gate width (m)"}),(0,j.jsx)("input",{type:"text",inputMode:"decimal",value:n.gateWidthM,onChange:h=>o(M=>({...M,gateWidthM:h.target.value}))})]}):null]}):null,u==="posts"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Posts and fixing type"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose how the posts will be set."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(qa.mounting).map(([h,M])=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.mountingType===h?" is-selected":""}`,onClick:()=>o(N=>({...N,mountingType:h})),children:[(0,j.jsx)("div",{className:"truss-estimator__option-title",children:M.label}),(0,j.jsx)("div",{className:"truss-estimator__option-copy",children:M.blurb})]},h))})]}):null]}),(0,j.jsxs)("div",{className:"truss-estimator__nav",children:[(0,j.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:ge,children:"Back"}),(0,j.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:Ae,disabled:!wt(),children:[(0,j.jsx)("span",{children:Ee}),(0,j.jsx)("span",{className:"arrow",children:(0,j.jsx)(Qt,{})})]})]})]})]})})}var uc=G(Xe()),we=G(ee()),Mv={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",byArea:!0},loft:{label:"Loft",product:"Knauf Loft Roll 44",thickness:"100mm",coverage:13.89,salesUnit:"roll",byArea:!0}};function Hd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,uc.useState)("floor"),[n,o]=(0,uc.useState)(""),[l,c]=(0,uc.useState)(""),p=Number.parseFloat(n)*Number.parseFloat(l)||0,d=Mv[r],g=Math.ceil(p/d.coverage),m=[{key:`insulation-${r}`,label:`${d.product} ${d.thickness}`,qty:d.byArea?Math.round(p*100)/100:g,unit:d.byArea?"m2":d.salesUnit,query:d.product,category:"insulation"}],b=Object.entries(Mv);return(0,we.jsx)(we.Fragment,{children:(0,we.jsxs)("div",{className:"truss-estimator",children:[(0,we.jsxs)("div",{className:"quick-order-hero",children:[(0,we.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,we.jsx)("h1",{children:"Insulation Calculator"}),(0,we.jsx)("p",{children:"Estimate insulation coverage and pack quantities for floors, walls, roofs and lofts."})]}),(0,we.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,we.jsx)("h2",{className:"truss-estimator__step-title",children:"Where and what you are insulating"}),(0,we.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the application and product, and enter the area, for coverage and pack quantities."}),(0,we.jsxs)("div",{className:"materials-calculator__section",children:[(0,we.jsx)("div",{className:"truss-estimator__section-heading",children:"Application"}),(0,we.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:b.map(([y,T])=>(0,we.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===y?" is-selected":""}`,onClick:()=>i(y),children:[(0,we.jsx)("div",{className:"truss-estimator__option-title",children:T.label}),(0,we.jsxs)("div",{className:"truss-estimator__option-copy",children:[T.product,", ",T.thickness]})]},y))})]}),(0,we.jsxs)("div",{className:"materials-calculator__section",children:[(0,we.jsx)("div",{className:"truss-estimator__section-heading",children:"Area"}),(0,we.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,we.jsxs)("label",{className:"truss-estimator__field",children:[(0,we.jsx)("span",{children:"Length (m)"}),(0,we.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:y=>o(y.target.value)})]}),(0,we.jsxs)("label",{className:"truss-estimator__field",children:[(0,we.jsx)("span",{children:"Width (m)"}),(0,we.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:y=>c(y.target.value)})]})]})]}),(0,we.jsxs)("div",{className:"materials-calculator__totals",children:[(0,we.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,we.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,we.jsxs)("div",{children:[(0,we.jsx)("span",{children:"Insulated area"}),(0,we.jsxs)("strong",{children:[p.toFixed(2)," m\xB2"]})]}),(0,we.jsxs)("div",{children:[(0,we.jsx)("span",{children:d.product}),(0,we.jsxs)("strong",{children:[g," packs"]})]})]}),(0,we.jsx)("p",{className:"materials-calculator__note",children:"This is a simple product choice, not thermal or Building Regulations advice. Confirm the specification before ordering."})]}),(0,we.jsxs)("div",{className:"materials-calculator__actions",children:[(0,we.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,we.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(m),disabled:p<=0,children:a})]})]})]})})}var Qn=G(Xe()),V=G(ee()),J_=10,I_=1.9*.762,F_=1.9*1.524,pc=()=>({height:"",width:""}),dc=e=>Number.parseFloat(e)||0,Tv=({height:e,width:t})=>dc(e)*dc(t);function jd({onBack:e}){let[t,a]=(0,Qn.useState)([pc()]),[r,i]=(0,Qn.useState)([pc()]),[n,o]=(0,Qn.useState)("0"),[l,c]=(0,Qn.useState)("0"),[p,d]=(0,Qn.useState)(1),g=t.reduce((f,u)=>f+Tv(u),0),m=r.reduce((f,u)=>f+Tv(u),0),b=dc(n)*I_+dc(l)*F_,y=Math.max(0,g-m-b),T=y*p/J_,D=(f,u,w,v)=>{f(S=>S.map((R,z)=>z===u?{...R,[w]:v}:R))};return(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:"Paint Calculator"}),(0,V.jsx)("p",{children:"Estimate how much paint you need for your walls, including multiple coats and excluded areas."})]}),(0,V.jsxs)("div",{className:"truss-estimator__card paint-calculator",children:[(0,V.jsx)("h2",{className:"truss-estimator__step-title",children:"Walls, exclusions and coats"}),(0,V.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,V.jsxs)("div",{className:"paint-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,V.jsx)("p",{className:"paint-calculator__hint",children:"Enter the height and width of each wall you want to paint."}),(0,V.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,V.jsx)("span",{}),(0,V.jsx)("span",{children:"Height (m)"}),(0,V.jsx)("span",{children:"Width (m)"}),(0,V.jsx)("span",{})]}),t.map((f,u)=>(0,V.jsxs)("div",{className:"paint-calculator__row",children:[(0,V.jsxs)("span",{className:"paint-calculator__row-label",children:["Wall ",u+1]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,V.jsx)("input",{"aria-label":`Wall ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:f.height,onChange:w=>D(a,u,"height",w.target.value)})]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,V.jsx)("input",{"aria-label":`Wall ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:f.width,onChange:w=>D(a,u,"width",w.target.value)})]}),t.length>1?(0,V.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>a(w=>w.filter((v,S)=>S!==u)),children:"Remove"}):null]},`wall-${u}`)),(0,V.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>a(f=>[...f,pc()]),children:"+ Add another wall"})]}),(0,V.jsxs)("div",{className:"paint-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Areas to exclude"}),(0,V.jsx)("p",{className:"paint-calculator__hint",children:"Add windows, sockets, skirting boards or other areas that will not be painted."}),(0,V.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,V.jsx)("span",{}),(0,V.jsx)("span",{children:"Height (m)"}),(0,V.jsx)("span",{children:"Width (m)"}),(0,V.jsx)("span",{})]}),r.map((f,u)=>(0,V.jsxs)("div",{className:"paint-calculator__row",children:[(0,V.jsxs)("span",{className:"paint-calculator__row-label",children:["Area ",u+1]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,V.jsx)("input",{"aria-label":`Area ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:f.height,onChange:w=>D(i,u,"height",w.target.value)})]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,V.jsx)("input",{"aria-label":`Area ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:f.width,onChange:w=>D(i,u,"width",w.target.value)})]}),r.length>1?(0,V.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(w=>w.filter((v,S)=>S!==u)),children:"Remove"}):null]},`excluded-${u}`)),(0,V.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(f=>[...f,pc()]),children:"+ Add another area"})]}),(0,V.jsxs)("div",{className:"paint-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Doors and coats"}),(0,V.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,V.jsxs)("div",{className:"truss-estimator__field-grid paint-calculator__small-fields",children:[(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{children:"Doors"}),(0,V.jsx)("input",{type:"number",min:"0",step:"1",value:n,onChange:f=>o(f.target.value)})]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{children:"Double doors"}),(0,V.jsx)("input",{type:"number",min:"0",step:"1",value:l,onChange:f=>c(f.target.value)})]})]}),(0,V.jsxs)("div",{className:"paint-calculator__coat-field",children:[(0,V.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,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{children:"Number of coats"}),(0,V.jsxs)("select",{value:p,onChange:f=>d(Number(f.target.value)),children:[(0,V.jsx)("option",{value:"1",children:"1 coat"}),(0,V.jsx)("option",{value:"2",children:"2 coats"}),(0,V.jsx)("option",{value:"3",children:"3 coats"})]})]})]})]}),(0,V.jsxs)("div",{className:"paint-calculator__totals",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,V.jsxs)("div",{className:"paint-calculator__result-grid",children:[(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Paintable area"}),(0,V.jsxs)("strong",{children:[y.toFixed(2)," m\xB2"]})]}),(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Coverage"}),(0,V.jsxs)("strong",{children:[p," ",p===1?"coat":"coats"]})]}),(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Paint required"}),(0,V.jsxs)("strong",{children:[T.toFixed(1)," litres"]})]})]}),(0,V.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,V.jsxs)("div",{className:"paint-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",disabled:!0,children:"Paint products unavailable"})]})]})]})})}var gr=G(Xe()),te=G(ee()),mc=e=>Number.parseFloat(e)||0,Qd={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 Gd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,gr.useState)("paving"),[n,o]=(0,gr.useState)("council"),[l,c]=(0,gr.useState)(""),[p,d]=(0,gr.useState)(""),[g,m]=(0,gr.useState)("100"),[b,y]=(0,gr.useState)("50"),[T,D]=(0,gr.useState)(!0),[f,u]=(0,gr.useState)(!0),w=mc(l)*mc(p),v=w,S=w*(mc(g)/1e3),R=w*.04,z=w*(mc(b)/1e3),A=Math.ceil(v/.36),Q=Math.ceil(v/.1),K=Math.ceil(S*1700/800),fe=Math.ceil(R*1600/800),Ue=Math.ceil(z*1600/800),Be=r==="paving"?{qty:A,unit:"each"}:r==="block"?{qty:v,unit:"m2"}:{qty:Ue,unit:"bag"},Ye={paving:"paving slab",block:"block paver",gravel:"decorative gravel"}[r],Ne=[{key:`surface-${n}`,label:Qd[r].find(oe=>oe.id===n)?.label??"Surface material",qty:Be.qty,unit:Be.unit,query:Ye,category:"landscaping"},...T?[{key:"sub-base",label:"MOT Type 1 sub-base",qty:K,unit:"bag",query:"MOT Type 1 sub base",category:"aggregate"}]:[],...f?[{key:"bedding",label:"Sharp sand bedding",qty:fe,unit:"bag",query:"sharp sand",category:"aggregate"}]:[]];return(0,te.jsx)(te.Fragment,{children:(0,te.jsxs)("div",{className:"truss-estimator",children:[(0,te.jsxs)("div",{className:"quick-order-hero",children:[(0,te.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,te.jsx)("h1",{children:"Paving and Driveway Calculator"}),(0,te.jsx)("p",{children:"Estimate paving, block paving, sub-base and bedding materials for outdoor areas."})]}),(0,te.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,te.jsx)("h2",{className:"truss-estimator__step-title",children:"Surface and ground build-up"}),(0,te.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,te.jsxs)("div",{className:"materials-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Surface material"}),(0,te.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(([oe,se,ye])=>(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===oe?" is-selected":""}`,onClick:()=>{i(oe),o(Qd[oe][0].id)},children:[(0,te.jsx)("div",{className:"truss-estimator__option-title",children:se}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:ye})]},oe))}),(0,te.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,te.jsx)("span",{children:"Finish"}),(0,te.jsx)("select",{value:n,onChange:oe=>o(oe.target.value),children:Qd[r].map(oe=>(0,te.jsx)("option",{value:oe.id,children:oe.label},oe.id))})]})]}),(0,te.jsxs)("div",{className:"materials-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and groundwork"}),(0,te.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,te.jsxs)("label",{className:"truss-estimator__field",children:[(0,te.jsx)("span",{children:"Length (m)"}),(0,te.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:oe=>c(oe.target.value)})]}),(0,te.jsxs)("label",{className:"truss-estimator__field",children:[(0,te.jsx)("span",{children:"Width (m)"}),(0,te.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:oe=>d(oe.target.value)})]})]}),r==="gravel"&&(0,te.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,te.jsx)("span",{children:"Gravel depth (mm)"}),(0,te.jsx)("input",{type:"number",min:"0",step:"10",value:b,onChange:oe=>y(oe.target.value)})]}),T&&(0,te.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,te.jsx)("span",{children:"Sub-base depth (mm)"}),(0,te.jsx)("input",{type:"number",min:"0",step:"10",value:g,onChange:oe=>m(oe.target.value)})]}),(0,te.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,te.jsx)("input",{type:"checkbox",checked:T,onChange:oe=>D(oe.target.checked)}),(0,te.jsx)("span",{children:"Include MOT Type 1 sub-base"})]}),(0,te.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,te.jsx)("input",{type:"checkbox",checked:f,onChange:oe=>u(oe.target.checked)}),(0,te.jsx)("span",{children:"Include sharp sand bedding"})]})]}),(0,te.jsxs)("div",{className:"materials-calculator__totals",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,te.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Surface area"}),(0,te.jsxs)("strong",{children:[w.toFixed(2)," m\xB2"]})]}),(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:r==="paving"?"Paving slabs":r==="block"?"Block paving":"Gravel"}),(0,te.jsx)("strong",{children:r==="paving"?`${A} slabs`:r==="block"?`${v.toFixed(2)} m\xB2`:`${Ue} bulk bags`})]}),T&&(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"MOT Type 1"}),(0,te.jsxs)("strong",{children:[K," bulk bags"]})]}),f&&(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Sharp sand"}),(0,te.jsxs)("strong",{children:[fe," bulk bags"]})]})]}),(0,te.jsx)("p",{className:"materials-calculator__note",children:"Slab and block quantities use typical sizes. Confirm pack coverage and laying pattern before ordering."})]}),(0,te.jsxs)("div",{className:"materials-calculator__actions",children:[(0,te.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,te.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(Ne),disabled:w<=0,children:a})]})]})]})})}var ll=G(Xe()),ae=G(ee()),W_=2.88,zv=[{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"}],Av=()=>({length:"",height:""}),Yd=e=>Number.parseFloat(e)||0;function Xd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,ll.useState)([Av()]),[n,o]=(0,ll.useState)(""),[l,c]=(0,ll.useState)("standard"),[p,d]=(0,ll.useState)("screws"),g=r.reduce((R,z)=>R+Yd(z.length)*Yd(z.height),0),m=Math.max(0,g-Yd(n)),b=Math.ceil(m/W_),y=Math.ceil(m*12),T=Math.ceil(y/1e3),D=Math.ceil(m*1.2),f=Math.ceil(D/90),u=Math.ceil(m/3.5),w=zv.find(R=>R.id===l)?.label??"Standard",v=[{key:"board",label:`${w} plasterboard`,qty:b,unit:"sheet",query:`${w} plasterboard`,category:"plasterboard"},...p==="screws"?[{key:"screws",label:"Drywall screws",qty:T,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:f,unit:"roll",query:"plasterboard joint tape",category:"plasterboard"}],S=(R,z,A)=>{i(Q=>Q.map((K,fe)=>fe===R?{...K,[z]:A}:K))};return(0,ae.jsx)(ae.Fragment,{children:(0,ae.jsxs)("div",{className:"truss-estimator",children:[(0,ae.jsxs)("div",{className:"quick-order-hero",children:[(0,ae.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ae.jsx)("h1",{children:"Plasterboard and Drylining Calculator"}),(0,ae.jsx)("p",{children:"Estimate boards, fixings and jointing materials for walls and ceilings."})]}),(0,ae.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,ae.jsx)("h2",{className:"truss-estimator__step-title",children:"Boards, fixings and jointing"}),(0,ae.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,ae.jsxs)("div",{className:"materials-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Board type"}),(0,ae.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:zv.map(R=>(0,ae.jsxs)("button",{type:"button",className:`truss-estimator__option-card${l===R.id?" is-selected":""}`,onClick:()=>c(R.id),children:[(0,ae.jsx)("div",{className:"truss-estimator__option-title",children:R.label}),(0,ae.jsx)("div",{className:"truss-estimator__option-copy",children:R.blurb})]},R.id))})]}),(0,ae.jsxs)("div",{className:"materials-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Fixing method"}),(0,ae.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["screws","Drywall screws","For timber or metal framing"],["adhesive","Board adhesive","For masonry dot-and-dab"]].map(([R,z,A])=>(0,ae.jsxs)("button",{type:"button",className:`truss-estimator__option-card${p===R?" is-selected":""}`,onClick:()=>d(R),children:[(0,ae.jsx)("div",{className:"truss-estimator__option-title",children:z}),(0,ae.jsx)("div",{className:"truss-estimator__option-copy",children:A})]},R))})]}),(0,ae.jsxs)("div",{className:"materials-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall and ceiling areas"}),(0,ae.jsx)("p",{className:"materials-calculator__hint",children:"Add each surface separately so different wall sizes are easy to measure."}),(0,ae.jsxs)("div",{className:"materials-calculator__dimensions-header",children:[(0,ae.jsx)("span",{children:"Surface"}),(0,ae.jsx)("span",{children:"Length (m)"}),(0,ae.jsx)("span",{children:"Height (m)"}),(0,ae.jsx)("span",{})]}),r.map((R,z)=>(0,ae.jsxs)("div",{className:"materials-calculator__surface-row",children:[(0,ae.jsxs)("span",{children:["Surface ",z+1]}),(0,ae.jsx)("input",{"aria-label":`Surface ${z+1} length`,type:"number",min:"0",step:"0.01",value:R.length,onChange:A=>S(z,"length",A.target.value)}),(0,ae.jsx)("input",{"aria-label":`Surface ${z+1} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:A=>S(z,"height",A.target.value)}),r.length>1?(0,ae.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(A=>A.filter((Q,K)=>K!==z)),children:"Remove"}):null]},`surface-${z}`)),(0,ae.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(R=>[...R,Av()]),children:"+ Add another surface"}),(0,ae.jsxs)("label",{className:"truss-estimator__field materials-calculator__openings",children:[(0,ae.jsxs)("span",{children:["Openings to deduct (m\xB2) ",(0,ae.jsx)("small",{children:"optional"})]}),(0,ae.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:R=>o(R.target.value)})]})]}),(0,ae.jsxs)("div",{className:"materials-calculator__totals",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ae.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Board area"}),(0,ae.jsxs)("strong",{children:[m.toFixed(2)," m\xB2"]})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"2.4 x 1.2 m boards"}),(0,ae.jsx)("strong",{children:b})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:p==="screws"?"Drywall screws":"Board adhesive"}),(0,ae.jsx)("strong",{children:p==="screws"?`${y} (${T} boxes)`:`${u} bags`})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Joint tape"}),(0,ae.jsxs)("strong",{children:[D," m (",f," rolls)"]})]})]}),(0,ae.jsx)("p",{className:"materials-calculator__note",children:"Figures are estimates. Confirm board specification, fixing patterns and fire or acoustic requirements before ordering."})]}),(0,ae.jsxs)("div",{className:"materials-calculator__actions",children:[(0,ae.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ae.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(v),disabled:m<=0,children:a})]})]})]})})}var sl=G(Xe());var _=G(ee()),Dt={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}}}},fc=["range","pitchAndDimensions","quantityAndGirders","bracing"],ex={range:null,pitch:null,spanMM:"",overhangMM:"",roofLengthM:"",centres:null,girderCount:0,bracing:null,treatment:null,contact:{name:"",email:""}};function tx({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 ax({type:e}){let t="#b3835a",a="#5c3b22",r="#d9b48f",i="#d3d8de",n="#7c8494",o=(d,g,m,b,y=8,T)=>{let D=m-d,f=b-g,u=Math.hypot(D,f)||1,w=-f/u,v=D/u,S=y*.2;return(0,_.jsxs)("g",{children:[(0,_.jsx)("line",{x1:d,y1:g,x2:m,y2:b,stroke:a,strokeWidth:y+3,strokeLinecap:"square"}),(0,_.jsx)("line",{x1:d,y1:g,x2:m,y2:b,stroke:t,strokeWidth:y,strokeLinecap:"square"}),(0,_.jsx)("line",{x1:d-w*S,y1:g-v*S,x2:m-w*S,y2:b-v*S,stroke:r,strokeWidth:Math.max(1.5,y*.24),strokeLinecap:"round",opacity:"0.9"})]},T)},l=(d,g,m)=>(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})]},m),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 rx({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 Rv({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 Vd({onBack:e}){let[t,a]=(0,sl.useState)(0),[r,i]=(0,sl.useState)(ex),[n,o]=(0,sl.useState)(!1),[l,c]=(0,sl.useState)(!1),p=()=>{let f=Number.parseFloat(r.roofLengthM)||0,u=Number.parseFloat(r.centres??"");return f<=0||!u?0:Math.ceil(f*1e3/u)+1},g=(()=>{let f=r.range?Dt.ranges[r.range]:Dt.ranges.standard,u=r.pitch??"22.5",w=Dt.pitchMultipliers[u],v=(Number.parseFloat(r.spanMM)||0)/1e3,R=(Number.parseFloat(r.overhangMM)||0)>Dt.overhang.thresholdMM,z=p(),A=z+r.girderCount,Q=Number.parseFloat(r.roofLengthM)||0,K=r.treatment?Dt.treatment[r.treatment]:Dt.treatment.untreated,fe=Dt.estimate.ranges[r.range??"standard"],Ue=fe.supplyAt8m*Math.max(.7,v/8)*w*(1+K.surchargePct)+(R?Dt.overhang.surchargePerTruss:0),Be=z*Ue,Ye=r.girderCount*Ue*Dt.estimate.girderMultiplier,Ne=r.bracing==="yes"?Q*Dt.estimate.bracingPerMetre:0,ve=Be+Ye+Ne+Dt.estimate.delivery,oe=Dt.estimate.design+z*fe.installPerTruss+r.girderCount*40,se=ve+oe,ye=se*.2;return{range:f,count:z,girderCount:r.girderCount,overhangApplies:R,overhangUnits:A,roofLengthM:Q,treatment:K,trussSupply:Be,bracingMaterials:Ne,delivery:Dt.estimate.delivery,labour:oe,subtotal:se,vat:ye,total:se+ye}})(),m=()=>{let f=fc[t];return f==="range"?!!r.range:f==="pitchAndDimensions"?!!r.pitch&&r.spanMM.trim()!==""&&r.overhangMM.trim()!=="":f==="quantityAndGirders"?r.roofLengthM.trim()!==""&&!!r.centres:f==="bracing"?!!r.bracing&&!!r.treatment:!0},b=t===fc.length-1?"View truss request":"Next",y=()=>{n?o(!1):t===0?e():a(f=>f-1)},T=()=>{m()&&(t===fc.length-1?(c(!1),o(!0)):a(f=>f+1))},D=()=>{let f=fc[t];return f==="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(Dt.ranges).map(([u,w])=>(0,_.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r.range===u?" is-selected":""}`,onClick:()=>i(v=>({...v,range:u})),children:[(0,_.jsx)(ax,{type:u}),(0,_.jsxs)("div",{className:"truss-estimator__option-info",children:[(0,_.jsx)("div",{className:"truss-estimator__option-title",children:w.label}),(0,_.jsx)("div",{className:"truss-estimator__option-copy",children:w.blurb})]})]},u))})]}):f==="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(w=>({...w,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(w=>({...w,overhangMM:u.target.value}))}),(0,_.jsxs)("small",{children:["Overhangs beyond ",Dt.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:Dt.pitches.map(u=>(0,_.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${r.pitch===u?" is-selected":""}`,onClick:()=>i(w=>({...w,pitch:u})),children:[(0,_.jsx)(tx,{degrees:Number.parseFloat(u)}),(0,_.jsxs)("span",{children:[u,"\xB0"]})]},u))})]}):f==="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(w=>({...w,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:Dt.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(w=>({...w,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:"+"})]})]}):f==="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(w=>({...w,bracing:u.id})),children:[(0,_.jsx)(rx,{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)(Rv,{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)(Rv,{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:lt(g.trussSupply)})]}),g.bracingMaterials>0&&(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Bracing materials allowance"}),(0,_.jsx)("strong",{children:lt(g.bracingMaterials)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Delivery allowance"}),(0,_.jsx)("strong",{children:lt(g.delivery)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Design and installation labour"}),(0,_.jsx)("strong",{children:lt(g.labour)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Subtotal (ex. VAT)"}),(0,_.jsx)("strong",{children:lt(g.subtotal)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"VAT (20%)"}),(0,_.jsx)("strong",{children:lt(g.vat)})]}),(0,_.jsxs)("div",{className:"truss-request__price-total",children:[(0,_.jsx)("span",{children:"Estimated total"}),(0,_.jsx)("strong",{children:lt(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:y,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:y,children:"Back"}),(0,_.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:T,disabled:!m(),children:[(0,_.jsx)("span",{children:b}),(0,_.jsx)("span",{className:"arrow",children:(0,_.jsx)(Qt,{})})]})]})]})]})})}var Ci=G(Xe()),F=G(ee()),Ov=e=>Number.parseFloat(e)||0,hc=(e,t)=>Ov(e)*(t==="m"?1:.3048),Uv=()=>({length:"",width:""}),Dv=[{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 ix({profile:e}){return(0,F.jsxs)("svg",{className:"skirting-calculator__profile-diagram",viewBox:"0 0 120 84","aria-hidden":"true",children:[(0,F.jsx)("path",{d:{chamfered:"M16 70V43L43 16H104V70Z",ogee:"M16 70V47C16 36 27 31 40 31C40 21 50 16 63 16H104V70Z","pencil-round":"M16 70V37C16 25 25 16 37 16H104V70Z",torus:"M16 70V49C16 39 25 34 36 34C36 22 47 16 61 16H104V70Z"}[e]}),(0,F.jsx)("line",{x1:"12",y1:"70",x2:"108",y2:"70"})]})}function $d({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)([Uv()]),[g,m]=(0,Ci.useState)(""),[b,y]=(0,Ci.useState)("chamfered"),T="4.4",D=r==="total"?hc(l,n):p.reduce((S,R)=>S+2*(hc(R.length,n)+hc(R.width,n)),0),f=Math.max(0,D-hc(g,n)),u=Math.ceil(f/Ov(T)),w=[{key:`skirting-${b}`,label:`${Dv.find(S=>S.id===b)?.label} skirting board`,qty:f,unit:"m",query:"skirting board",category:"skirting"}],v=(S,R,z)=>{d(A=>A.map((Q,K)=>K===S?{...Q,[R]:z}:Q))};return(0,F.jsx)(F.Fragment,{children:(0,F.jsxs)("div",{className:"truss-estimator",children:[(0,F.jsxs)("div",{className:"quick-order-hero",children:[(0,F.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,F.jsx)("h1",{children:"Skirting Board Calculator"}),(0,F.jsx)("p",{children:"Work out how many skirting board lengths you need for one room or a whole project."})]}),(0,F.jsxs)("div",{className:"truss-estimator__card skirting-calculator",children:[(0,F.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure by room or total length"}),(0,F.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter a single total or work room by room. The run is converted straight into board lengths."}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"How would you like to measure?"}),(0,F.jsxs)("div",{className:"brick-calculator__unit-toggle skirting-calculator__mode-toggle",role:"group","aria-label":"Calculation method",children:[(0,F.jsx)("button",{type:"button",className:r==="total"?"is-selected":"",onClick:()=>i("total"),children:"Total length"}),(0,F.jsx)("button",{type:"button",className:r==="rooms"?"is-selected":"",onClick:()=>i("rooms"),children:"Room by room"})]})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Measurements"}),(0,F.jsxs)("div",{className:"skirting-calculator__unit-row",children:[(0,F.jsx)("span",{children:"Units"}),(0,F.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,F.jsx)("button",{type:"button",className:n==="m"?"is-selected":"",onClick:()=>o("m"),children:"Metres"}),(0,F.jsx)("button",{type:"button",className:n==="ft"?"is-selected":"",onClick:()=>o("ft"),children:"Feet"})]})]}),r==="total"?(0,F.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,F.jsxs)("span",{children:["Total skirting length (",n,")"]}),(0,F.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:S=>c(S.target.value)})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)("div",{className:"skirting-calculator__dimensions-header",children:[(0,F.jsx)("span",{children:"Room"}),(0,F.jsxs)("span",{children:["Length (",n,")"]}),(0,F.jsxs)("span",{children:["Width (",n,")"]}),(0,F.jsx)("span",{})]}),p.map((S,R)=>(0,F.jsxs)("div",{className:"skirting-calculator__room-row",children:[(0,F.jsxs)("span",{className:"skirting-calculator__room-label",children:["Room ",R+1]}),(0,F.jsx)("input",{"aria-label":`Room ${R+1} length in ${n}`,type:"number",min:"0",step:"0.01",value:S.length,onChange:z=>v(R,"length",z.target.value)}),(0,F.jsx)("input",{"aria-label":`Room ${R+1} width in ${n}`,type:"number",min:"0",step:"0.01",value:S.width,onChange:z=>v(R,"width",z.target.value)}),p.length>1?(0,F.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>d(z=>z.filter((A,Q)=>Q!==R)),children:"Remove"}):null]},`room-${R}`)),(0,F.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>d(S=>[...S,Uv()]),children:"+ Add another room"})]}),(0,F.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,F.jsxs)("span",{children:["Openings and doorways to deduct (",n,") ",(0,F.jsx)("small",{children:"optional"})]}),(0,F.jsx)("input",{type:"number",min:"0",step:"0.01",value:g,onChange:S=>m(S.target.value)})]})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Profile"}),(0,F.jsx)("p",{className:"skirting-calculator__hint",children:"Choose the finish you want for the fixed 4.4m white-primed MDF boards."}),(0,F.jsx)("div",{className:"architrave-calculator__profiles",children:Dv.map(S=>(0,F.jsxs)("button",{type:"button",className:`truss-estimator__option-card${b===S.id?" is-selected":""}`,onClick:()=>y(S.id),children:[(0,F.jsx)(ix,{profile:S.id}),(0,F.jsx)("div",{className:"truss-estimator__option-title",children:S.label}),(0,F.jsx)("div",{className:"truss-estimator__option-copy",children:S.blurb})]},S.id))})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,F.jsx)("div",{className:"truss-estimator__field-grid skirting-calculator__options-grid",children:(0,F.jsxs)("label",{className:"truss-estimator__field",children:[(0,F.jsx)("span",{children:"Board length"}),(0,F.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,F.jsx)("p",{className:"skirting-calculator__hint",children:"Longer boards can reduce the number of joins, while 10% waste allows for cuts, corners and mistakes."})]}),(0,F.jsxs)("div",{className:"skirting-calculator__totals",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,F.jsxs)("div",{className:"skirting-calculator__result-grid",children:[(0,F.jsxs)("div",{children:[(0,F.jsx)("span",{children:"Net skirting"}),(0,F.jsxs)("strong",{children:[f.toFixed(2)," m"]})]}),(0,F.jsxs)("div",{children:[(0,F.jsx)("span",{children:"Board lengths"}),(0,F.jsx)("strong",{children:u})]})]}),(0,F.jsx)("p",{className:"skirting-calculator__note",children:"Corners and joins vary by room layout. Measure each wall where possible for the most accurate result."})]}),(0,F.jsxs)("div",{className:"skirting-calculator__actions",children:[(0,F.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,F.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(w),disabled:f<=0,children:a})]})]})]})})}var Gn=G(Xe()),ie=G(ee()),cl=e=>Number.parseFloat(e)||0;function Zd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Gn.useState)("studs"),[n,o]=(0,Gn.useState)(""),[l,c]=(0,Gn.useState)(""),[p,d]=(0,Gn.useState)("600"),[g,m]=(0,Gn.useState)("2.4"),b=n&&l&&p?Math.ceil(cl(l)/(cl(p)/1e3))+1:0,y=b*cl(n),T=cl(g)>0?Math.ceil(y/cl(g)):0,D=[{key:r,label:{studs:"Stud timber",joists:"Joist timber",battens:"Batten timber"}[r],qty:y,unit:"m",query:{studs:"cls studwork timber",joists:"timber joist",battens:"roofing batten"}[r],category:"timber"}],f={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"]},w={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,ie.jsx)(ie.Fragment,{children:(0,ie.jsxs)("div",{className:"truss-estimator",children:[(0,ie.jsxs)("div",{className:"quick-order-hero",children:[(0,ie.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ie.jsx)("h1",{children:"Timber Calculator"}),(0,ie.jsx)("p",{children:"Estimate studs, joists or battens from a run length, width and spacing."})]}),(0,ie.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,ie.jsx)("h2",{className:"truss-estimator__step-title",children:"Member size and spacing"}),(0,ie.jsxs)("p",{className:"truss-estimator__step-sub",children:[w.help," Enter the member length and centres to estimate the number of pieces and stock lengths."]}),(0,ie.jsxs)("div",{className:"materials-calculator__section",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber use"}),(0,ie.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:Object.keys(f).map(v=>(0,ie.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===v?" is-selected":""}`,onClick:()=>i(v),children:[(0,ie.jsx)("div",{className:"truss-estimator__option-title",children:f[v][0]}),(0,ie.jsx)("div",{className:"truss-estimator__option-copy",children:f[v][1]})]},v))})]}),(0,ie.jsxs)("div",{className:"materials-calculator__section",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Dimensions and spacing"}),(0,ie.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ie.jsxs)("label",{className:"truss-estimator__field",children:[(0,ie.jsxs)("span",{children:[w.member," (m)"]}),(0,ie.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:v=>o(v.target.value)})]}),(0,ie.jsxs)("label",{className:"truss-estimator__field",children:[(0,ie.jsxs)("span",{children:[w.overall," (m)"]}),(0,ie.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:v=>c(v.target.value)})]})]}),(0,ie.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ie.jsxs)("label",{className:"truss-estimator__field",children:[(0,ie.jsx)("span",{children:"Centres (mm)"}),(0,ie.jsxs)("select",{value:p,onChange:v=>d(v.target.value),children:[(0,ie.jsx)("option",{value:"300",children:"300 mm"}),(0,ie.jsx)("option",{value:"400",children:"400 mm"}),(0,ie.jsx)("option",{value:"450",children:"450 mm"}),(0,ie.jsx)("option",{value:"600",children:"600 mm"})]})]}),(0,ie.jsxs)("label",{className:"truss-estimator__field",children:[(0,ie.jsx)("span",{children:"Stock length (m)"}),(0,ie.jsxs)("select",{value:g,onChange:v=>m(v.target.value),children:[(0,ie.jsx)("option",{value:"2.4",children:"2.40 m"}),(0,ie.jsx)("option",{value:"3.6",children:"3.60 m"}),(0,ie.jsx)("option",{value:"4.8",children:"4.80 m"})]})]})]})]}),(0,ie.jsxs)("div",{className:"materials-calculator__totals",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ie.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:w.count}),(0,ie.jsx)("strong",{children:b})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:"Linear metres"}),(0,ie.jsxs)("strong",{children:[y.toFixed(2)," m"]})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsxs)("span",{children:[g," m lengths"]}),(0,ie.jsx)("strong",{children:T})]})]}),(0,ie.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,ie.jsxs)("div",{className:"materials-calculator__actions",children:[(0,ie.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ie.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(D),disabled:y<=0,children:a})]})]})]})})}var Kd=[{id:"truss",title:"Roof Truss Calculator",desc:"Estimate trusses, girders and roof structure costs.",imageUrl:"/tool-images/truss.webp",Component:Vd},{id:"fencing",title:"Fencing Calculator",desc:"Estimate fence panels, posts, gravel boards and fixings.",imageUrl:"/tool-images/fencing.webp",Component:Ld},{id:"decking",title:"Decking Calculator",desc:"Estimate boards, substructure and fixing quantities.",imageUrl:"/tool-images/decking.webp",Component:Bd},{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:Td},{id:"paint",title:"Paint Calculator",desc:"Estimate paint for walls, doors and multiple coats.",imageUrl:"/tool-images/paint.webp",Component:jd},{id:"skirting",title:"Skirting Board Calculator",desc:"Estimate skirting lengths for rooms and wall runs.",imageUrl:"/tool-images/skirting.webp",Component:$d},{id:"architrave",title:"Architrave Calculator",desc:"Estimate architrave lengths for door and window openings.",imageUrl:"/tool-images/architrave.webp",Component:Md},{id:"concrete-aggregate",title:"Concrete and Aggregate Calculator",desc:"Estimate concrete, MOT, sand and gravel quantities.",imageUrl:"/tool-images/concrete-aggregate.webp",Component:Dd},{id:"plasterboard",title:"Plasterboard Calculator",desc:"Estimate plasterboard sheets, screws, tape and adhesive.",imageUrl:"/tool-images/plasterboard.webp",Component:Xd},{id:"insulation",title:"Insulation Calculator",desc:"Estimate insulation packs for floors, walls, roofs and lofts.",imageUrl:"/tool-images/insulation.webp",Component:Hd},{id:"timber",title:"Timber Calculator",desc:"Estimate studs, joists and battens from spacing and lengths.",imageUrl:"/tool-images/timber.webp",Component:Zd},{id:"paving",title:"Paving and Driveway Calculator",desc:"Estimate paving, block paving, MOT and sharp sand.",imageUrl:"/tool-images/paving.webp",Component:Gd}];var bc=G(Xe());var Ge=G(Xe());var C=G(ee()),nx=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}],Pd={wasteFactorEnabled:!0},ox=3e3,Bv=null;function gc(e,t){let a=el(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function lx(e){return e&&e.length>0?e.join(" x "):"-"}function Jd({toolId:e,requirements:t,ready:a,onBack:r,onTotalChange:i}){let n=tc(),o=`${e}~${t.map(k=>`${k.key}|${k.query}|${k.category??""}|${k.qty}`).join("~")}`,l=o!==Bv,[c,p]=(0,Ge.useState)(null),[d,g]=(0,Ge.useState)([]),[m,b]=(0,Ge.useState)(l),[y,T]=(0,Ge.useState)(null),[D,f]=(0,Ge.useState)("tile"),[u,w]=(0,Ge.useState)(null),[v,S]=(0,Ge.useState)(""),[R,z]=(0,Ge.useState)(null),[A,Q]=(0,Ge.useState)(""),[K,fe]=(0,Ge.useState)([]),[Ue,Be]=(0,Ge.useState)(new Set),[Ye,Ne]=(0,Ge.useState)(null),[ve,oe]=(0,Ge.useState)(""),[se,ye]=(0,Ge.useState)([]),wt=(0,Ge.useRef)(null),Ee=(0,Ge.useRef)(!1),$=k=>`${e}:${k}`,ue=k=>Pr(k.chosen,{lineId:$(k.requirement.key),description:k.requirement.label,unit:k.requirement.unit,qty:k.requirement.qty}),Ze=(0,Ge.useMemo)(()=>t.map(k=>`${k.key}|${k.query}|${k.category??""}`).join("~"),[t]);(0,Ge.useEffect)(()=>{let k=!1;return Nv().then(L=>{k||p(L.itemCount>0)}).catch(()=>{k||p(!1)}),()=>{k=!0}},[]),(0,Ge.useEffect)(()=>{if(!a||!c)return;let k=!1,L;l&&b(!0),T(null);let P=Date.now();return(async()=>{let pe=null;try{pe=(await kv(t,void 0,e)).map(({requirement:xt,candidates:it})=>({requirement:xt,candidates:it,chosen:it[0]??null}))}catch(xe){k||T(xe instanceof Error?xe.message:"Could not load products")}if(!k){if(Bv=o,l){let xe=ox-(Date.now()-P);xe>0&&await new Promise(xt=>{L=window.setTimeout(xt,xe)})}k||(pe&&(g(pe),!Ee.current&&n&&(Ee.current=!0,n.addManyToCart(pe.filter(xe=>xe.chosen).map(ue)))),b(!1))}})(),()=>{k=!0,window.clearTimeout(L)}},[a,c,Ze]),(0,Ge.useEffect)(()=>{if(!R)return;let k=A.trim();if(!k){fe([]);return}let L=!1,P=window.setTimeout(()=>{fr(k).then(pe=>{L||fe(pe)}).catch(()=>{L||fe([])})},250);return()=>{L=!0,window.clearTimeout(P)}},[R,A]),(0,Ge.useEffect)(()=>{if(!Ye)return;let k=ve.trim();if(!k){ye([]);return}let L=!1,P=window.setTimeout(()=>{fr(k).then(pe=>{L||ye(pe)}).catch(()=>{L||ye([])})},250);return()=>{L=!0,window.clearTimeout(P)}},[Ye,ve]);let pt=(0,Ge.useMemo)(()=>{let k=v.trim().toLowerCase(),L=k?d.filter(P=>P.requirement.label.toLowerCase().includes(k)||(P.chosen?.description??"").toLowerCase().includes(k)||(P.chosen?.product_id??"").toLowerCase().includes(k)):d;return u?[...L].sort((P,pe)=>{let xe=P.requirement.label.localeCompare(pe.requirement.label);return u==="asc"?xe:-xe}):L},[d,v,u]),vt=pt.filter(k=>k.chosen),He=pt.filter(k=>!k.chosen),de=d.filter(k=>k.chosen),_e=de.filter(k=>k.chosen?.price==null).length,Se=de.reduce((k,L)=>k+(Ft(ue(L),Pd).lineTotal??0),0);if((0,Ge.useEffect)(()=>{i?.(Se)},[Se,i]),!a||c===!1)return null;let E=n?de.filter(k=>n.cart[$(k.requirement.key)]).length:0,O=Ye?d.find(k=>k.requirement.key===Ye)??null:null,ce=ve.trim()?se:O?.candidates??[],ge=k=>{let L=R===k.requirement.key;z(L?null:k.requirement.key),Q(L?"":k.requirement.query)},Ae=(k,L)=>{let P=d.find(pe=>pe.requirement.key===k);g(pe=>pe.map(xe=>xe.requirement.key===k?{...xe,chosen:L}:xe)),n&&P&&n.cart[$(k)]&&n.addToCart(ue({...P,chosen:L})),z(null),Q("")},Pe=k=>{g(L=>L.map(P=>P.requirement.key===k?{...P,chosen:null}:P)),n?.cart[$(k)]&&n.removeFromCart($(k))},h=k=>{Ne(k.requirement.key),oe(""),ye([])},M=()=>{Ne(null),oe(""),ye([])},N=k=>{if(!n)return;let L=$(k.requirement.key);n.cart[L]?n.removeFromCart(L):n.addToCart(ue(k))},Y=k=>{Be(L=>{let P=new Set(L);return P.has(k)?P.delete(k):P.add(k),P})},Z=k=>{let L=K.length>0?K:k.candidates;return(0,C.jsxs)("div",{className:"estimator-products__picker",children:[(0,C.jsx)("input",{type:"text",className:"results-search-input",value:A,autoFocus:!0,placeholder:"Search products in catalogue...",onChange:P=>Q(P.target.value),"aria-label":`Search a product for ${k.requirement.label}`}),(0,C.jsxs)("div",{className:"estimator-products__options",children:[L.map(P=>(0,C.jsxs)("button",{type:"button",className:`estimator-products__option${P.product_id===k.chosen?.product_id?" is-selected":""}`,onClick:()=>Ae(k.requirement.key,P),children:[(0,C.jsx)("span",{children:P.description}),(0,C.jsxs)("span",{className:"results-row-meta",children:[P.product_id,P.price!=null&&` \xB7 ${lt(P.price)}`]})]},P.product_id)),L.length===0&&(0,C.jsx)("p",{className:"results-empty-hint",children:"No matching products."})]})]})};return(0,C.jsxs)("section",{className:"estimator-products results-tile-section","aria-label":"Matched products",children:[!m&&(0,C.jsxs)("div",{className:"estimator-products__head",children:[(0,C.jsxs)("div",{className:"results-tile-section__head",children:[(0,C.jsx)("h3",{children:"Matched Products"}),(0,C.jsx)("p",{children:"Products matched to your estimate, check before adding to your basket."})]}),!O&&(0,C.jsxs)("div",{className:"results-summary estimator-products__toolbar",children:[_e>0&&(0,C.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,C.jsx)("strong",{children:_e})," need pricing"]}),(0,C.jsxs)("div",{className:"estimator-products__controls",children:[(0,C.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:v,onChange:k=>S(k.target.value),"aria-label":"Search matched products"}),(0,C.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,C.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:()=>f("tile"),children:(0,C.jsxs)("svg",{width:"18",height:"12",viewBox:"0 0 15 10",fill:"currentColor",children:[(0,C.jsx)("rect",{x:"0.5",y:"0.5",width:"4",height:"4"}),(0,C.jsx)("rect",{x:"5.5",y:"0.5",width:"4",height:"4"}),(0,C.jsx)("rect",{x:"10.5",y:"0.5",width:"4",height:"4"}),(0,C.jsx)("rect",{x:"0.5",y:"5.5",width:"4",height:"4"}),(0,C.jsx)("rect",{x:"5.5",y:"5.5",width:"4",height:"4"}),(0,C.jsx)("rect",{x:"10.5",y:"5.5",width:"4",height:"4"})]})}),(0,C.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:()=>f("list"),children:(0,C.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,C.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,C.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,C.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),(0,C.jsxs)("details",{ref:wt,style:{position:"relative"},children:[(0,C.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort materials",style:{fontSize:16},children:"\u21C5"}),(0,C.jsx)("div",{className:"sort-menu-panel",children:nx.map(k=>{let L=u===k.dir;return(0,C.jsxs)("button",{type:"button",className:`sort-menu-item${L?" is-active":""}`,onClick:()=>{w(L?null:k.dir),wt.current?.removeAttribute("open")},children:[(0,C.jsx)("span",{className:"sort-menu-item__check",children:L?"\u2713":""}),k.label]},k.dir)})})]})]})]})]}),O&&(0,C.jsxs)("div",{className:"results-review-page",children:[(0,C.jsxs)("div",{className:"results-review-page__top",children:[(0,C.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:M,children:[(0,C.jsx)(Kr,{}),"Back to results"]}),(0,C.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,C.jsx)("div",{className:"results-review-searchbar",children:(0,C.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:ve,onChange:k=>oe(k.target.value),"aria-label":`Search a product for ${O.requirement.label}`})}),O.chosen&&(0,C.jsx)("div",{className:"results-candidate-actions",children:(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Pe(O.requirement.key),children:"Clear selected product"})})]})]}),(0,C.jsxs)("div",{className:"results-review-page__hero",children:[(0,C.jsx)("div",{className:"results-review-page__image-wrap",children:(0,C.jsx)("img",{className:"fill-img results-review-page__image",src:Ga(O.chosen?.description||O.requirement.label,O.chosen?.product_id,O.chosen?.pdp_photo_url),alt:""})}),(0,C.jsxs)("div",{className:"results-review-page__summary",children:[(0,C.jsx)("h2",{children:O.requirement.label}),(0,C.jsxs)("p",{className:"results-review-page__meta",children:[yi(O.requirement.qty)," ",Sa(O.requirement.unit,O.requirement.qty)]}),O.chosen?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)("div",{className:"results-review-page__product",children:O.chosen.description}),(0,C.jsxs)("div",{className:"results-row-meta",children:[O.chosen.product_id,O.chosen.price!=null?` \xB7 ${gc(O.chosen.price,O.chosen.price_basis)}`:""]})]}):(0,C.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line."}),(0,C.jsx)("div",{className:"results-review-page__actions",children:(0,C.jsx)("button",{type:"button",className:`bom-toolbar-btn${n?.cart[$(O.requirement.key)]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>N(O),disabled:!O.chosen||!n,children:n?.cart[$(O.requirement.key)]?"\u2713 Added":"+ Add to basket"})})]})]}),ce.length===0?(0,C.jsx)("p",{className:"results-empty-hint",children:"No matching products."}):(0,C.jsxs)("table",{className:"score-breakdown-table",children:[(0,C.jsx)("thead",{children:(0,C.jsxs)("tr",{children:[(0,C.jsx)("th",{children:"Product"}),(0,C.jsx)("th",{children:"Dims (mm)"}),(0,C.jsx)("th",{children:"Price"}),(0,C.jsx)("th",{"aria-label":"Actions"})]})}),(0,C.jsx)("tbody",{children:ce.map(k=>{let L=k.product_id===O.chosen?.product_id;return(0,C.jsxs)("tr",{className:L?"score-breakdown-row--best":"",children:[(0,C.jsxs)("td",{children:[(0,C.jsx)("div",{children:k.description}),(0,C.jsx)("div",{className:"results-row-meta",children:k.product_id})]}),(0,C.jsx)("td",{children:(0,C.jsx)("span",{className:"unit-badge",children:lx(k.measurements_mm)})}),(0,C.jsx)("td",{children:k.price!=null?gc(k.price,k.price_basis):"-"}),(0,C.jsx)("td",{children:(0,C.jsxs)("label",{className:"switch-toggle",title:L?"Currently selected":"Use this candidate",children:[(0,C.jsx)("input",{type:"checkbox",checked:L,onChange:()=>{L?Pe(O.requirement.key):Ae(O.requirement.key,k)},"aria-label":L?`${k.description} selected`:`Use ${k.description}`}),(0,C.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},k.product_id)})})]})]}),!O&&m&&(0,C.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{padding:"32px 24px"},children:[(0,C.jsx)(dr,{}),(0,C.jsx)("p",{className:"banter-message is-visible",style:{fontSize:15,minHeight:0},children:"Matching your materials against the catalogue\u2026"})]}),!O&&y&&(0,C.jsx)("p",{className:"results-empty-hint estimator-products__error",children:y}),!O&&!m&&!y&&pt.length===0&&d.length>0&&(0,C.jsx)("p",{className:"results-empty-hint",children:"No materials match the current search."}),!O&&!m&&!y&&D==="tile"&&vt.length>0&&(0,C.jsx)("div",{className:"results-tile-grid",children:vt.map(k=>{let{requirement:L,chosen:P}=k,pe=P?Ft(ue(k),Pd):null,xe=n?!!n.cart[$(L.key)]:!1;return(0,C.jsxs)("article",{className:"results-tile-card",children:[(0,C.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>h(k),"aria-label":`Review match for ${L.label}`,children:[(0,C.jsx)("div",{className:"results-tile-card__media",children:(0,C.jsx)("img",{className:"fill-img results-tile-card__image",src:Ga(P?.description||L.label,P?.product_id,P?.pdp_photo_url),alt:""})}),(0,C.jsxs)("div",{className:"results-tile-card__body",children:[P?(0,C.jsxs)("div",{className:"results-tile-card__heading",children:[(0,C.jsx)("div",{className:"results-tile-card__title",children:P.description}),(0,C.jsxs)("div",{className:"results-tile-card__match-meta",children:[(0,C.jsx)("span",{children:P.product_id}),P.price!=null?(0,C.jsx)("span",{children:gc(P.price,P.price_basis)}):null]})]}):(0,C.jsx)("div",{className:"results-empty-hint",children:"No product matched for this line."}),(0,C.jsxs)("div",{className:"results-tile-card__match",children:[(0,C.jsx)("div",{className:"results-tile-card__match-label",children:"\u21B3 calculated as"}),(0,C.jsx)("div",{className:"results-tile-card__match-name",children:L.label}),(0,C.jsxs)("div",{className:"results-tile-card__meta",children:[yi(L.qty)," ",Sa(L.unit,L.qty)]}),pe?.requiredSellUnits!=null?(0,C.jsxs)("div",{className:"results-tile-card__meta estimator-products__order",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${lt(pe.lineTotal)}`:""]}):P?(0,C.jsx)("div",{className:"results-row-meta",children:"Quantity needs review"}):null]})]})]}),(0,C.jsxs)("div",{className:"results-tile-card__actions",children:[(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>h(k),children:"Review"}),(0,C.jsx)("button",{type:"button",className:`bom-toolbar-btn${xe?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>N(k),disabled:!P||!n,children:xe?"\u2713 Added":"+ Add"})]})]},L.key)})}),!O&&!m&&!y&&D==="list"&&vt.length>0&&(0,C.jsx)("div",{className:"bom-table-wrap",children:(0,C.jsxs)("table",{className:"bom-table results-table","aria-label":"Matched materials",children:[(0,C.jsxs)("colgroup",{children:[(0,C.jsx)("col",{style:{width:"56px"}}),(0,C.jsx)("col",{className:"col-item"}),(0,C.jsx)("col",{style:{width:"90px"}}),(0,C.jsx)("col",{style:{width:"80px"}}),(0,C.jsx)("col",{style:{width:"220px"}}),(0,C.jsx)("col",{style:{width:"110px"}})]}),(0,C.jsx)("thead",{children:(0,C.jsxs)("tr",{className:"bom-col-header",children:[(0,C.jsx)("th",{"aria-label":"Expand"}),(0,C.jsx)("th",{style:{textAlign:"left"},children:"Description"}),(0,C.jsx)("th",{style:{textAlign:"center"},children:"Qty"}),(0,C.jsx)("th",{style:{textAlign:"center"},children:"Unit"}),(0,C.jsx)("th",{style:{textAlign:"center"},children:"Product Matched"}),(0,C.jsx)("th",{style:{textAlign:"center"},children:"Basket"})]})}),(0,C.jsx)("tbody",{children:vt.map(k=>{let{requirement:L,chosen:P}=k,pe=P?Ft(ue(k),Pd):null,xe=n?!!n.cart[$(L.key)]:!1,xt=Ue.has(L.key);return(0,C.jsxs)(Ge.Fragment,{children:[(0,C.jsxs)("tr",{className:"bom-row",children:[(0,C.jsx)("td",{className:"bom-actions",style:{textAlign:"center",paddingLeft:0,paddingRight:0},children:(0,C.jsx)("button",{type:"button",className:"link-btn",onClick:()=>Y(L.key),"aria-expanded":xt,"aria-label":xt?"Collapse product options":"Expand product options",children:xt?"\u25BE":"\u25B8"})}),(0,C.jsxs)("td",{style:{paddingLeft:0},children:[(0,C.jsx)("div",{className:"bom-component-name",children:L.label}),pe?.requiredSellUnits!=null&&(0,C.jsxs)("div",{className:"results-row-meta",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${lt(pe.lineTotal)}`:""]})]}),(0,C.jsx)("td",{className:"bom-qty col-order",style:{textAlign:"center"},children:yi(L.qty)}),(0,C.jsx)("td",{style:{textAlign:"center"},children:Sa(L.unit,L.qty)}),(0,C.jsx)("td",{style:{textAlign:"center"},children:P?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)("div",{className:"bom-component-name",children:P.description}),(0,C.jsxs)("div",{className:"results-row-meta",children:[P.product_id,P.price!=null&&` \xB7 ${gc(P.price,P.price_basis)}`]})]}):(0,C.jsx)("span",{className:"results-empty-hint",children:"No match"})}),(0,C.jsx)("td",{style:{textAlign:"center"},children:(0,C.jsx)("button",{type:"button",className:`bom-toolbar-btn${xe?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>N(k),disabled:!P||!n,children:xe?"\u2713 Added":"+ Add"})})]}),xt&&(0,C.jsx)("tr",{children:(0,C.jsx)("td",{colSpan:6,style:{paddingLeft:0,paddingRight:0},children:R===L.key?Z(k):(0,C.jsxs)("div",{className:"estimator-products__picker",children:[(0,C.jsxs)("div",{className:"estimator-products__options",children:[k.candidates.map(it=>(0,C.jsxs)("button",{type:"button",className:`estimator-products__option${it.product_id===P?.product_id?" is-selected":""}`,onClick:()=>Ae(L.key,it),children:[(0,C.jsx)("span",{children:it.description}),(0,C.jsxs)("span",{className:"results-row-meta",children:[it.product_id,it.price!=null&&` \xB7 ${lt(it.price)}`]})]},it.product_id)),k.candidates.length===0&&(0,C.jsx)("p",{className:"results-empty-hint",children:"No candidates found."})]}),(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ge(k),children:"Search the catalogue"})]})})})]},L.key)})})]})}),!O&&!m&&!y&&He.length>0&&(0,C.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,C.jsxs)("div",{className:"results-tile-section__head",children:[(0,C.jsx)("h3",{children:"Require Matching"}),(0,C.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,C.jsx)("div",{className:"results-unmatched-list",children:He.map(k=>(0,C.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>h(k),children:[(0,C.jsxs)("span",{className:"results-unmatched-card__main",children:[(0,C.jsx)("span",{className:"results-unmatched-card__title",children:k.requirement.label}),(0,C.jsxs)("span",{className:"results-row-meta",children:[yi(k.requirement.qty)," ",Sa(k.requirement.unit,k.requirement.qty)]})]}),(0,C.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},k.requirement.key))})]}),!m&&!y&&d.length>0&&(0,C.jsxs)("div",{className:"disclaimer-box",style:{alignItems:"center"},children:[(0,C.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,C.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."})]}),!O&&!m&&!y&&(r||E>0)&&(0,C.jsxs)("div",{className:"btn-row estimator-products__footer",children:[r&&(0,C.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:r,children:"Back"}),E>0&&n&&(0,C.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:r?"0 1 70%":1,marginTop:0},onClick:n.openBasket,children:[(0,C.jsxs)("span",{children:["View Basket (",E,")"]}),(0,C.jsx)("span",{className:"arrow",children:(0,C.jsx)(Qt,{})})]})]})]})}var Gt=G(ee());function Id({toolId:e,toolTitle:t,requirements:a,onBack:r}){let[i,n]=(0,bc.useState)(0),o=(0,bc.useCallback)(l=>n(l),[]);return(0,Gt.jsx)(Gt.Fragment,{children:(0,Gt.jsxs)("div",{className:"truss-estimator",children:[(0,Gt.jsxs)("div",{className:"quick-order-hero",children:[(0,Gt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Gt.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,Gt.jsx)("h1",{children:"Your Materials"}),i>0&&(0,Gt.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,Gt.jsx)("strong",{children:lt(i)})," Est. total"]})]}),(0,Gt.jsxs)("p",{children:["Quantities from the ",t,", matched against your merchant\u2019s catalogue."]})]}),(0,Gt.jsx)("div",{className:"truss-estimator__card",style:{minHeight:0},children:(0,Gt.jsx)(Jd,{toolId:e,requirements:a,ready:!0,onBack:r,onTotalChange:o})})]})})}var Fd=G(Xe());var Wt=G(ee()),sx=1500;function Lv(e){let{addManyToCart:t,clearCart:a,openBasket:r}=Un(),[i,n]=(0,Fd.useState)(!1),[o,l]=(0,Fd.useState)(null);return{adding:i,basketError:o,addToBasket:async(p,d)=>{let g=Date.now();n(!0),l(null);try{let m=await Promise.all(p.filter(y=>y.qty>0).map(async y=>{let T=(await fr(y.search)).find(D=>D.product_id===y.productId);if(!T)throw new Error("A selected product is no longer available in this catalogue.");return Pr(T,{lineId:`${e}:${y.key}`,description:T.description,unit:Ad(y.unit??"each",T),qty:y.qty,calculatorWasteIncluded:d})})),b=sx-(Date.now()-g);b>0&&await new Promise(y=>window.setTimeout(y,b)),a(),t(m),r()}catch(m){l(m instanceof Error?m.message:"Could not add the products to your basket.")}finally{n(!1)}}}}function Hv({toolTitle:e}){return(0,Wt.jsx)(Wt.Fragment,{children:(0,Wt.jsxs)("div",{className:"truss-estimator",children:[(0,Wt.jsxs)("div",{className:"quick-order-hero",children:[(0,Wt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Wt.jsx)("h1",{children:"Your Materials"}),(0,Wt.jsxs)("p",{children:["Calculating quantities from the ",e,"."]})]}),(0,Wt.jsx)("div",{className:"truss-estimator__card",children:(0,Wt.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,Wt.jsx)(dr,{}),(0,Wt.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})})}var Re=G(ee());function wc(e){let[t,a]=(0,Xa.useState)(!1);return(0,Re.jsx)(ec,{onOpenBasket:()=>a(!0),children:(0,Re.jsx)(cx,{...e,showBasket:t,onShowBasket:a})})}function cx({fullPage:e=!1,hideHeader:t=!1,internal:a=!1,showBasket:r,onShowBasket:i}){let[n,o]=(0,Xa.useState)(null),[l,c]=(0,Xa.useState)(null),p=Kd.find(A=>A.id===n),{cart:d,updateCartQty:g,updateCartSellUnits:m,updateCartConversions:b,removeFromCart:y,clearCart:T}=Un(),{adding:D,basketError:f,addToBasket:u}=Lv(p?.title??"calculator"),w=(0,Xa.useRef)(null),v=Ys("estimating-tools",w);(0,Xa.useEffect)(()=>{v("viewed")},[v]);let S=r?"basket":D?"adding":l?"review":n??"list",R=(0,Xa.useRef)(S);(0,Xa.useEffect)(()=>{R.current!==S&&(R.current=S,window.scrollTo(0,0))},[S]);let z=A=>{if(!p)return;v("estimate_completed",{calculator:p.id,lines:A.length});let Q=_v(p.id,A);Q?u(Q,A[0]?.calculatorWasteIncluded??!1):c(A)};return(0,Re.jsx)(Po.Provider,{value:v,children:(0,Re.jsx)("div",{ref:w,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${a?"":" estimating-tools--customer"}`,style:jt().theme,children:(0,Re.jsx)("main",{className:"main-content",children:r?(0,Re.jsx)(ol,{cart:d,onUpdateQty:g,onUpdateSellUnits:m,onResolveConversions:b,onRemove:y,onBack:()=>i(!1),onStartNewQuote:()=>{T(),o(null),c(null),i(!1)},internal:a}):D&&p?(0,Re.jsx)(Hv,{toolTitle:p.title}):p?(0,Re.jsxs)(Re.Fragment,{children:[(0,Re.jsx)("div",{hidden:l!==null,children:(0,Re.jsx)(p.Component,{onBack:()=>o(null),onReview:z})}),f&&(0,Re.jsx)("p",{className:"results-empty-hint estimator-products__error",children:f}),l!==null&&(0,Re.jsx)(Id,{toolId:p.id,toolTitle:p.title,requirements:l,onBack:()=>c(null)})]}):(0,Re.jsx)(Re.Fragment,{children:(0,Re.jsxs)("div",{className:"quick-order-card",children:[(0,Re.jsxs)("div",{className:"quick-order-hero",children:[(0,Re.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,Re.jsx)("h1",{children:"Estimating Tools"}),(0,Re.jsx)("p",{children:"Trade-specific calculators for trusses, fencing, decking, masonry and painting. Dial in your specs and get an instant material estimate."})]}),(0,Re.jsxs)("div",{className:"quick-order-alt",children:[(0,Re.jsx)("div",{className:"quick-order-alt-title",children:"Choose a Calculator"}),(0,Re.jsx)("div",{className:"estimator-tools-grid",children:Kd.map(A=>(0,Re.jsxs)("button",{type:"button",className:"estimator-tool-card",onClick:()=>{v("calculator_selected",{calculator:A.id}),o(A.id),c(null)},children:[(0,Re.jsx)("span",{className:"estimator-tool-card__image-wrap",children:(0,Re.jsx)("img",{className:"fill-img estimator-tool-card__image",src:It(A.imageUrl),alt:""})}),(0,Re.jsxs)("span",{className:"estimator-tool-card__content",children:[(0,Re.jsx)("span",{className:"estimator-tool-card__title",children:A.title}),(0,Re.jsx)("span",{className:"estimator-tool-card__desc",children:A.desc})]})]},A.id))})]})]})})})})})}var vc=G(ee());function Wd({config:e,children:t}){return rw(e),(0,vc.jsx)(vc.Fragment,{children:t})}var em=G(ee()),ux="https://api.metronlabs.ai",px=["client","api-key","api-url","theme","hide-header","analytics"],dx=["all","events-only","none"];function Qv(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.52",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; }
6986
+ `)}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 ov=e=>(e??"").trim().toLowerCase(),n_={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"},yd=new Set(["sheet","length","box","bag","pack","roll","set","tub","each"]),av=new Set(["box","bag","pack","pallet","roll","set","tub"]),rv=(e,t)=>t==="ml"?e:["l","litre","litres"].includes(t)?e*1e3:null,iv=(e,t)=>t==="g"?e:["kg","kilogram","kilograms"].includes(t)?e*1e3:["t","tonne","tonnes"].includes(t)?e*1e6:null,_i=e=>{let t=ov(e);return n_[t]??t},st=(e,t)=>{let a=_i(e),r=_i(t);return a.length>0&&a===r},o_=(e,t)=>{let a=ov(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},l_=e=>(e??"").split(",").map(t=>_i(t)).filter(Boolean),s_=(e,t)=>{let a=l_(e.requestUomsSupported);return!!(a.length===0||a.includes(t)||st(t,"pallet")&&e.itemsPerPallet!=null&&e.itemsPerPallet>0||st(t,"pack")&&e.itemsPerPack!=null&&e.itemsPerPack>0||st(t,"box")&&e.itemsPerBox!=null&&e.itemsPerBox>0)},nv=(e,t)=>st(t,"pallet")?e.itemsPerPallet??null:st(t,"pack")?e.itemsPerPack??null:st(t,"box")?e.itemsPerBox??null:null,c_=(e,t,a)=>{if(!st(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||!st(r[3],a))return null;let i=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(i)&&i>0?i:null};function Is(e,t){let a=e.map(r=>Ft(r,t).lineTotal);return a.some(r=>r==null)?null:a.reduce((r,i)=>r+(i??0),0)}function Ft(e,t){let a=e.qty,r=_i(e.saleUnit??e.salesUnitSizeUom??e.uoi??e.salesUomNormalised)||"-",i=_i(e.unit)||(a>0&&yd.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?yd.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(!Number.isFinite(a)||a<=0)return p("Quantity needs confirmation.");if(!s_(e,i))return p("Requested unit is not supported by this catalogue conversion.");let d=null,g="review",m=e.roundingRule,b=`Quantity review required, initial request needed ${a} ${i}.`,y=1+o,T=c_(e,i,r),D=e.unitConversions?.find(v=>st(v.requestUom,i));if(!!e.saleUnit&&(st(i,r)||!!D||st(i,"each")&&!av.has(r)))if(st(i,r))d=a*y/n,g="direct",b=`${a} ${i}${o>0?` x ${y}`:""}`;else if(D){d=a*y/D.quantityPerSaleUnit,g="derived";let v=1/D.quantityPerSaleUnit,S=Math.round(v);b=st(r,"each")&&D.quantityPerSaleUnit<1&&Math.abs(v-S)<1e-9?`${a} ${i}${o>0?` x ${y}`:""} x ${S} per ${i}`:`${a} ${i}${o>0?` x ${y}`:""} / ${D.quantityPerSaleUnit} ${i} per ${r}`}else st(i,"each")&&!av.has(r)&&(d=a*y/n,g="derived",b=`${a} ${r}${o>0?` x ${y}`:""}`);else if(st(i,r)&&n>0)d=a*y/n,g="direct",b=o>0?`${a} ${i} x ${y} / ${n} ${r} per sell unit`:`${a} ${i} / ${n} ${r} per sell unit`;else if(st(i,"each")&&n>0&&yd.has(r))d=a*y/n,g="derived",b=o>0?`${a} each x ${y} / ${n} each per ${r}`:`${a} each / ${n} each per ${r}`;else if(nv(e,i)!=null&&n>0){let v=nv(e,i)??0;d=a*v*y/n,g="derived";let S=`${a} ${i} x ${v} each${o>0?` x ${y}`:""}`;b=n===1&&st(r,"each")?S:`${S} / ${n} each per ${r}`}else if(T!=null)d=a*y/T,g="derived",m??(m="round_up_each"),b=`${a} m2 x ${y} / ${T} m2 per ${r} (from product description)`;else if(e.conversionType==="basket_line_unit")n>0&&(d=a*y/n,g="derived",b=`${a} ${i}${o>0?` x ${y}`:""} / ${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;st(i,"m2")&&v!=null&&v>0&&(d=a*y/v,g="derived",b=`${a} m2 x ${y} / ${v} m2 per ${r}`)}else if(e.conversionType==="count_per_area"){let v=e.coverageQty??null;st(i,"m2")&&v!=null&&v>0?(d=a/v,g="derived",b=`${a} m2 / ${v} m2 per sell unit`):st(i,"m2")&&e.itemsPerM2!=null&&e.itemsPerM2>0&&n>0&&(d=a*e.itemsPerM2*y/n,g="derived",b=`${a} m2 x ${e.itemsPerM2} ${r}/m2 x ${y} / ${n}`)}else if(e.conversionType==="length_from_dims"){let v=e.coverageQty??e.derivedLengthM??null;st(i,"m")&&v!=null&&v>0&&(d=a*y/v,g="derived",b=`${a} m x ${y} / ${v} m per ${r}`)}else if(e.conversionType==="volume_from_description"){let v=rv(a,i),S=rv(e.coverageQty??0,_i(e.coverageUom));v!=null&&S!=null&&S>0&&(d=v*y/S,g="derived",b=`${a} ${i} x ${y} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="weight_from_description"){let v=iv(a,i),S=iv(e.coverageQty??0,_i(e.coverageUom));v!=null&&S!=null&&S>0&&(d=v*y/S,g="derived",b=`${a} ${i} x ${y} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="same_unit_volume"){let v=e.coverageQty??null;st(i,"m3")&&v!=null&&v>0&&(d=a/v,g="derived",b=`${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=o_(d,m),w=l?c:u;return{requestedAmount:a,requestedUnit:i,salesUnitSize:n,sellUnit:r,calculatedSellUnits:u,requiredSellUnits:w,unitPrice:e.price,lineTotal:e.price!=null&&w!=null?e.price*w:null,calculation:l?`${b} = ${u} ${r} (manually set to ${w})`:`${b} = ${w} ${r}`,costingMode:g}}var lv=()=>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"],u_=al.indexOf("Line total");function p_(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 sv(e){let t=await lv(),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:m,unmatchable:b,decision:y}=c,T=[p.section,p.subsection,p.subheading].filter(Boolean).join(" / "),D=!b&&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)",T,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(", "),y?.technical_classification??"",y?.include_in_quote==null?"":y.include_in_quote?"yes":"no",y?.approval_required==null?"":y.approval_required?"yes":"no",y?.approval_type??"",y?.missing_information.join(", ")??"",y?.confidence??"",y?.reason??"",b?"-":d?.product_id??y?.selected_candidate_id??"-",b?"-":d?.description??"-",b?"-":d?.price_basis??"-",b?null:d?.price??null,D,b?"-":m,p_(c)])}i.push(Array(al.length).fill(null));let o=Array(al.length).fill(null);o[0]="Estimated total",o[u_]=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 cv(e,t){let a=await lv(),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=Ft(p),g=d.lineTotal;g!=null&&(o+=g),n.push([p.productId,p.description,d.costingMode,d.requestedAmount,Na(d.requestedUnit),d.salesUnitSize,Na(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=G(ee()),xd="__none__",rl=24,d_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}];function mv(e){return e==null?"low":e>=.7?"high":e>=.5?"medium":"low"}var m_=e=>e.attrs.supply_nature==="labour_only"||e.attrs.supply_nature==="plant"||e.flags.includes("referential");function f_(e,t){if(t!==xd){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 uv(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 h_(e){return e?e.replace(/_/g," "):"not stated"}function g_({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 zn(e,t){if(e==null)return"-";let a=el(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function kd(e){return e&&e.length>0?e.join(" x "):"-"}function b_(e){return e==null?"-":Number.isInteger(e/1e3)?`${e/1e3}m`:`${(e/1e3).toFixed(1)}m`}function Tn(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)"}function w_(e,t){return t>0||e==null?null:lt(e)}var pv=[{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 v_(e){let t=new Map;return[...new Set(e.filter(mr).map(r=>r.linked_group_id))].forEach((r,i)=>{let n=i%26;t.set(r,{token:String.fromCharCode(65+n),bubbleStyle:pv[i%pv.length]})}),t}function mr(e){return!1}function An(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 _d({meta:e}){return e?(0,s.jsx)("span",{className:"results-linked-pill",style:e.bubbleStyle,children:`Link ${e.token}`}):null}function y_(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 Fs(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 Ws(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 __({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:Ws(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:Ws(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:Ws(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:Ws(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 x_({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:kd(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 dv({item:e,result:t}){let a=t?.retrieval_debug.map(i=>i.query).filter(Boolean)??[],r=[["Procurement intent",e.procurement_intent||"-"],["Procurement aliases",Tn(e.procurement_aliases)],["Retrieval queries",Tn(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)",kd(e.attrs.measurements_mm)],["Stock length",b_(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",Tn(e.installation_clues)],["System clues",Tn(e.system_clues)],["Component requirements",Tn(e.component_requirements)],["Linked group",An(e)||"-"],["Flags",Tn(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)(ke.Fragment,{children:[(0,s.jsx)("dt",{children:i}),(0,s.jsx)("dd",{children:n})]},i))})]})}function k_({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)(ke.Fragment,{children:[(0,s.jsx)("dt",{children:"Attempted"}),(0,s.jsx)("dd",{children:t.attempted?"yes":"no"})]}),(0,s.jsxs)(ke.Fragment,{children:[(0,s.jsx)("dt",{children:"Applied"}),(0,s.jsx)("dd",{children:t.applied?"yes":"no"})]}),(0,s.jsxs)(ke.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned items"}),(0,s.jsx)("dd",{children:t.returned_item_count??"-"})]}),(0,s.jsxs)(ke.Fragment,{children:[(0,s.jsx)("dt",{children:"Reason"}),(0,s.jsx)("dd",{children:t.reason||"-"})]}),(0,s.jsxs)(ke.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 N_({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)(ke.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 S_({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"?"No automatic match:":`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]}),mr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",n?`Link ${n.token} - `:"",An(e)]}):null]}):null:!t.reason&&!r?(0,s.jsx)(dv,{item:e,result:a}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(dv,{item:e,result:a}),r&&(0,s.jsx)(k_,{item:e}),r&&(0,s.jsx)(N_,{result:a}),t.reason&&(0,s.jsxs)("div",{className:"results-detail-block",children:[(0,s.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,s.jsx)("strong",{children:o}),"\xA0",t.reason]}),mr(e)?(0,s.jsxs)("p",{className:"results-row-meta",style:{marginTop:8},children:["Linked context: ",n?`Link ${n.token} - `:"",An(e)]}):null]}),r&&(0,s.jsx)(x_,{queries:a?.retrieval_debug??[]})]})}function C_({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:m=!1,linkedGroupMeta:b}){let y=d||o==="detailed",T=g&&o==="detailed",D=y||m?(0,s.jsx)(S_,{item:e,decision:r,result:a,showRetrievalDebug:T,reviewOnly:m&&!y,linkedGroupMeta:b}):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 f=p||d||o==="detailed"?t:y_(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"}),T&&(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:f.map((u,w)=>{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:kd(u.measurements_mm??u.debug?.candidate.measurements_mm)})}),(0,s.jsx)("td",{children:zn(u.price,u.price_basis)}),T&&(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)(g_,{band:mv(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}-${w}`)})})]})]})}function Nd({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&&Xs()==="QZA6-MRA4",m=g?"quote":"basket",{results:b,lineItems:y,parseReport:T,timings:D}=e,[f,u]=(0,ke.useState)({}),w=Cn(),[v,S]=(0,ke.useState)({}),[R,z]=(0,ke.useState)({}),[A,Q]=(0,ke.useState)(""),[K,fe]=(0,ke.useState)(null),[Ue,Be]=(0,ke.useState)(1),Ye=jt().debug===!0,[Ne,ve]=(0,ke.useState)("simple"),[oe,se]=(0,ke.useState)(d?"list":"tile"),[ye,wt]=(0,ke.useState)(!1),[Ee,$]=(0,ke.useState)(null),[ue,Ze]=(0,ke.useState)(""),[pt,vt]=(0,ke.useState)([]),[He,de]=(0,ke.useState)(!1),[_e,Se]=(0,ke.useState)(null),[E,O]=(0,ke.useState)(!1),[re,ce]=(0,ke.useState)(null),ge=(0,ke.useRef)(null),[Ae,Pe]=(0,ke.useState)(new Set),[h,M]=(0,ke.useState)(new Set),[N,Y]=(0,ke.useState)(!1);(0,ke.useEffect)(()=>{Be(1)},[A,K,oe]);let Z=new Map(b.map(x=>[x.line_id,x])),k=v_(y),L=y.map(x=>{let H=Z.get(x.line_id),be=H?.decision,dt=m_(x),Je=f[x.line_id],ea=f_(H,Je),zi=a[x.line_id],Pv=Je===xd?void 0:v[x.line_id]??(zi&&zi.productId!==ea?.product_id?uv(zi):ea),um=dt?void 0:Pv,Jv=x.qty??0;return{item:x,result:H,decision:be,unmatchable:dt,best:um,qty:Jv,band:mv(um?.scores?.overall)}}),pe=L.some(x=>!x.unmatchable&&!x.best&&!h.has(x.item.line_id))?null:Is(Object.values(a),{wasteFactorEnabled:!1,wasteFactorOverride:0}),xe=0;for(let x of L){if(x.unmatchable||x.decision?.include_in_quote!==!0||!x.best)continue;let H=a[x.item.line_id];(!H||Ft(H).lineTotal==null)&&(xe+=1)}xe>0&&(pe=null);let xt=w_(pe,xe),it=x=>!x.unmatchable&&!x.best&&x.decision?.technical_classification!=="no_suitable_candidate"&&Fs(x.result).length>0,Et=x=>x.best??Fs(x.result)[0],Ir=L.filter(x=>!x.unmatchable&&!x.best).filter(x=>!h.has(x.item.line_id)),yc=L.filter(x=>h.has(x.item.line_id)),Yt=L;if(A.trim()){let x=A.trim().toLowerCase();Yt=Yt.filter(H=>H.item.description_original?.toLowerCase().includes(x)||Et(H)?.description?.toLowerCase().includes(x))}if(K){let x=K==="asc"?1:-1;Yt=[...Yt].sort((H,be)=>x*(H.item.description_original||"").localeCompare(be.item.description_original||""))}let br=Math.max(1,Math.ceil(Yt.length/rl)),kt=Math.min(Ue,br),qi=Yt.slice((kt-1)*rl,kt*rl),am=qi.filter(x=>!x.unmatchable&&x.best),hx=qi.filter(x=>it(x)),_c=qi.filter(x=>!x.unmatchable&&(x.best||it(x))),rm=qi.filter(x=>x.unmatchable||!x.best&&!it(x)),J=Ee?L.find(x=>x.item.line_id===Ee)??null:null,Gv=!d&&!c&&!J&&Ir.length>0,Yn=(0,ke.useRef)(null),Xn=()=>{let x=ge.current;if(!x)return;let{top:H,left:be,width:dt,height:Je}=x.getBoundingClientRect(),zi=x.querySelector(".bom-toolbar-btn")?.closest("td")?.getBoundingClientRect().left;ce({top:H,left:be,width:zi?zi-be:dt,height:Je})};(0,ke.useEffect)(()=>(window.addEventListener("scroll",Xn,!0),window.addEventListener("resize",Xn),()=>{window.removeEventListener("scroll",Xn,!0),window.removeEventListener("resize",Xn)})),(0,ke.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 Ei=x=>{$(x),Ze("")},Yv=()=>{if(!Ee)return;let x=a[Ee];if(x){u(H=>({...H,[Ee]:x.productId})),S(H=>({...H,[Ee]:uv(x)}));return}u(H=>{let be={...H};return delete be[Ee],be}),S(H=>{let be={...H};return delete be[Ee],be})},Va=(x=!1)=>{let H=Ee?a[Ee]: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||Yv(),$(null),Y(!1))};Fo(E,()=>O(!1)),Fo(!!J&&!E,()=>Va());let Xv=x=>{if(Pe(H=>new Set(H).add(x)),Ir.some(H=>H.item.line_id!==x)){Va(!0);return}p(),Va(!0)},Vv=x=>{if(xc(x),M(H=>new Set(H).add(x)),Ir.some(H=>H.item.line_id!==x)){Va(!0);return}p(),Va(!0)},$v=()=>{M(x=>new Set([...x,...Ir.map(H=>H.item.line_id)])),p()},im=()=>{J?.best&&(om(J.item.line_id,J.best),r(Mi(J)),N?Xv(J.item.line_id):Va(!0))},nm=rm.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:rm.map(x=>{let{item:H,qty:be}=x;return(0,s.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>Ei(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,y)})}),(0,s.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},H.line_id)})})]}):null,xc=x=>{u(H=>({...H,[x]:xd})),S(H=>({...H,[x]:void 0})),z(H=>({...H,[x]:void 0})),i(x)},kc=(x,H)=>{u(be=>({...be,[x]:H.product_id})),S(be=>({...be,[x]:H}))},om=(x,H)=>{H.method==="catalogue_search"&&z(be=>({...be,[x]:H}))};function gx(){w("downloaded",{type:"schedule",lines:L.length}),sv(L.map(({item:x,best:H,qty:be,band:dt,unmatchable:Je,decision:ea})=>({item:x,best:H,qty:be,band:dt,unmatchable:Je,decision:ea})))}function Mi(x){let H=x.best??Fs(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?y.filter(be=>be.linked_group_id===x.item.linked_group_id&&be.linked_group_role==="anchor").slice(0,1).map(be=>{let dt=a[be.line_id];return{line_id:be.line_id,product_id:dt?.productId??null,measurements_mm:dt?.measurementsMm??be.attrs.measurements_mm,description:dt?.description??be.description_original,qty:be.qty,unit:be.unit,role:"anchor"}}):void 0})}(0,ke.useEffect)(()=>{if(!o){for(let x of L)!x.unmatchable&&x.best&&r(Mi(x));l()}},[o]),(0,ke.useEffect)(()=>{for(let x of L)!a[x.item.line_id]&&!x.unmatchable&&x.best&&r(Mi(x))},[e]),(0,ke.useEffect)(()=>{if(!Ee){vt([]),Se(null),de(!1);return}let x=ue.trim();if(!x){vt([]),Se(null),de(!1);return}let H=!1,be=window.setTimeout(async()=>{try{de(!0),Se(null);let dt=await fetch(pa(`/api/catalogue/search?q=${encodeURIComponent(x)}`),{headers:wi()}),Je=await ka(dt);if(!dt.ok)throw new Error(Je?.error||Je?.message||"Failed to search catalogue");H||vt(Array.isArray(Je?.items)?Je.items:[])}catch(dt){H||(vt([]),Se(dt?.message||"Failed to search catalogue"))}finally{H||de(!1)}},250);return()=>{H=!0,window.clearTimeout(be)}},[ue,Ee]);let Nc=Object.keys(a).length,Ma=ue.trim(),Sc=Fs(J?.result),ul=J?.decision?.technical_classification==="no_suitable_candidate"||!!J&&!J.best,lm=J?.decision?.technical_classification!=null,sm=J?.decision?.reason??(ul?"No catalogue candidate found. Refine the request or search the catalogue.":null),Zv=pt.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?Zv:Sc,Ti=J?R[J.item.line_id]:void 0,$n=!Ma&&Ti&&!Vn.some(x=>x.product_id===Ti.product_id)?[...Vn,Ti]:Vn,cm=(()=>{let x=$n.slice(0,Ma?12:3);return Ma||!Ti||x.some(H=>H.product_id===Ti.product_id)?x:[...x,Ti]})(),pl=!!J?.best&&a[J.item.line_id]?.productId===J.best.product_id,Kv=!!J?.best&&!!a[J.item.line_id]&&!pl;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:xt??"Review quantities"})," Est. total"]})]}),(0,s.jsx)("p",{children:"Each line item from your schedule matched against your catalogue, ranked by confidence."})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{children:"Review your matched products"}),(0,s.jsxs)("p",{children:["Check you're happy with these items, then click ",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"}),xt!=null&&(0,s.jsx)("strong",{children:xt})]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Qt,{})})]})]})}),(0,s.jsxs)("div",{className:"quick-order-panel",style:{paddingTop:16},children:[Ye&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:12},children:(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn","aria-pressed":ye,onClick:()=>wt(x=>!x),children:ye?"Hide timings":"Show timings"})}),Ye&&ye&&(0,s.jsx)(__,{...D}),!g&&(0,s.jsx)("div",{className:"results-toolbar-row",children:!J&&(0,s.jsxs)("div",{className:"results-summary",style:{marginBottom:0},children:[xe>0&&(0,s.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,s.jsx)("strong",{children:xe})," 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:A,onChange:x=>Q(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${oe==="tile"?" is-active":""}`,"aria-pressed":oe==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>se("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${oe==="list"?" is-active":""}`,"aria-pressed":oe==="list","aria-label":"List view",title:"List view",onClick:()=>se("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"})]})})]}),Ye&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ve(x=>x==="simple"?"detailed":"simple"),children:Ne==="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:d_.map(x=>{let H=K===x.dir;return(0,s.jsxs)("button",{type:"button",className:`sort-menu-item${H?" is-active":""}`,onClick:()=>{fe(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)})})]})]})]})}),oe==="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:()=>Va(),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:()=>Va(),"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:()=>Va(),children:[(0,s.jsx)(Kr,{}),"Back to results"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[Ye&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ve(x=>x==="simple"?"detailed":"simple"),children:Ne==="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:ue,onChange:x=>Ze(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:()=>xc(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:Ga(Et(J)?.description||J.item.description_original,Et(J)?.product_id,Et(J)?.pdp_photo_url),alt:""})}),(0,s.jsxs)("div",{className:"results-review-page__summary",children:[(0,s.jsx)("h2",{children:Jr(J.item,y)}),(0,s.jsxs)("p",{className:"results-review-page__meta",children:[yi(J.qty)," ",Sa(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:zn(J.best.price,J.best.price_basis)}):null]}):Et(J)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:Et(J)?.description}),Et(J)?.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:zn(Et(J)?.price??null,Et(J)?.price_basis??null)}):null,(0,s.jsx)("div",{className:"results-row-meta",children:"Best reviewed alternative - not yet selected"})]}):(0,s.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line item."}),mr(J.item)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[(0,s.jsx)(_d,{meta:k.get(J.item.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:An(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&&om(J.item.line_id,J.best),r(Mi(J)))},disabled:!J.best,"aria-label":a[J.item.line_id]?d?"Remove from selection":`Remove from ${m}`:d?"Add to selection":`Add to ${m}`,children:a[J.item.line_id]?"\u2713 Added":d?"+ Add to selection":`Add to ${m}`})})]})]}),He?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,!He&&_e?(0,s.jsx)("div",{className:"results-empty-card",children:_e}):null,!He&&!_e&&Ma&&Vn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No candidate products match this database search."}):!He&&!_e?(0,s.jsx)(C_,{item:J.item,candidates:Vn,result:J.result,decision:J.decision,unmatchable:J.unmatchable,selectedProductId:J.best?.product_id??null,detailMode:Ne,linkedGroupMeta:mr(J.item)?k.get(J.item.linked_group_id):void 0,onPick:x=>kc(J.item.line_id,x),onClear:()=>xc(J.item.line_id),showAll:d||Ye||Ma.length>0,internal:d,debugEnabled:Ye,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,y)||"Original request"})]}),sm?(0,s.jsxs)("section",{className:"customer-review-ai",children:[(0,s.jsx)("strong",{children:ul?"No automatic match:":"AI review:"})," ",sm]}):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:ul?Sc.length>0?"Choose a product":"No suitable product found":lm?"Choose a product":"We couldn't review this item"}),(0,s.jsx)("p",{children:ul?Sc.length>0?"No product was selected automatically. Review these related options before adding one.":"Search the catalogue to choose an alternative.":lm?`Select the option you want to add to your ${m}.`:"Search the catalogue to choose a product."})]})}),!Ma&&$n.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:cm.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:()=>kc(J.item.line_id,x),"aria-pressed":H,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Ga(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${zn(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:ue,onChange:x=>Ze(x.target.value),"aria-label":"Search catalogue"})]}),Ma&&He?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,Ma&&!He&&_e?(0,s.jsx)("div",{className:"results-empty-card",children:_e}):null,Ma&&!He&&!_e&&$n.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No products match this search."}):null,Ma&&!He&&!_e&&$n.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:cm.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:()=>kc(J.item.line_id,x),"aria-pressed":H,children:[(0,s.jsx)("img",{className:"customer-review-option__image",src:Ga(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${zn(x.price,x.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:H?"Selected":"Choose"})]},x.product_id)})}):null]}),J.best?Kv?(0,s.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,s.jsx)("button",{type:"button",className:"cta-btn customer-review-add",onClick:()=>{im()},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 ${m}`})})]}):(0,s.jsx)("button",{type:"button",className:`cta-btn customer-review-add${pl?" cta-btn-secondary":""}`,onClick:()=>{pl?i(J.item.line_id):im()},children:(0,s.jsx)("span",{children:pl?`Remove from ${m}`:`Add selected product to ${m}`})}):null,N?(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-skip",onClick:()=>Vv(J.item.line_id),children:"Skip this item"}):null]})})]})}):null,(0,s.jsxs)("div",{className:"results-tile-layout",children:[Yt.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No line items match the current search/filter."}):null,_c.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:_c.map(x=>{let{item:H,best:be,qty:dt}=x,Je=Et(x),ea=!be&&it(x);return(0,s.jsxs)("article",{className:"results-tile-card",children:[(0,s.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>Ei(H.line_id),"aria-label":`Review match for ${Jr(H,y)||"item"}`,children:[(0,s.jsxs)("div",{className:"results-tile-card__media",children:[ea||mr(H)?(0,s.jsxs)("div",{className:"results-tile-card__badges",children:[mr(H)?(0,s.jsx)(_d,{meta:k.get(H.linked_group_id)}):(0,s.jsx)("span",{}),ea?(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:Ga(Je?.description||H.description_original,Je?.product_id,Je?.pdp_photo_url),alt:""})]}),(0,s.jsxs)("div",{className:"results-tile-card__body",children:[Je?(0,s.jsx)(s.Fragment,{children:(0,s.jsx)("div",{className:"results-tile-card__heading",children:(0,s.jsx)("div",{className:"results-tile-card__title",children:Je.description})})}):(0,s.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line item."}),(0,s.jsx)("div",{className:"results-tile-card__match",children:Je?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-tile-card__match-label",children:ea?"\u21B3 partially matched from":"\u21B3 matched from"}),(0,s.jsx)("div",{className:"results-tile-card__match-name",children:Jr(H,y)}),mr(H)?(0,s.jsx)("div",{className:"results-row-meta",children:An(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:()=>Ei(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(Mi(x))},disabled:!Je,"aria-label":a[H.line_id]?d?"Remove from selection":`Remove from ${m}`:d?"Add to selection":`Add to ${m}`,children:a[H.line_id]?"\u2713 Added":d?"+ Add":`Add to ${m}`})]})]},H.line_id)})})}):null,nm]})]}):(0,s.jsxs)(s.Fragment,{children:[re&&(0,s.jsx)("div",{className:"results-table__hover-overlay",style:re,"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"}}),Ne==="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"}),Ne==="simple"&&(0,s.jsx)("th",{style:{textAlign:"center"},children:d?"Selection":g?"Quote":"Basket"})]})}),(0,s.jsxs)("tbody",{children:[Yt.length===0&&(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:Ne==="simple"?4:3,className:"results-empty-hint",style:{padding:"16px 8px"},children:"No line items match the current search/filter."})}),_c.map(x=>{let{item:H,result:be,decision:dt,best:Je}=x;return(0,s.jsxs)("tr",{className:"bom-row results-table__review-row",onClick:()=>Ei(H.line_id),onMouseEnter:ea=>{ge.current=ea.currentTarget,Xn()},onMouseLeave:()=>{ge.current=null,ce(null)},children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{className:"bom-component-name",children:Jr(H,y)}),mr(H)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,s.jsx)(_d,{meta:k.get(H.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:An(H)})]}):null]}),(0,s.jsx)("td",{children:Je?(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"results-match-cell-text",title:Je.description,children:Je.description}),Ne==="detailed"&&dt?.technical_classification&&(0,s.jsxs)("div",{className:"results-row-meta",children:[h_(dt.technical_classification),dt.approval_required?" - approval required":""]})]}):(0,s.jsx)("span",{className:"results-empty-hint"})}),(0,s.jsx)("td",{style:{textAlign:"center"},children:Je?.price!=null?zn(Je.price,Je.price_basis):"-"}),Ne==="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:ea=>{ea.stopPropagation(),a[H.line_id]?i(H.line_id):r(Mi(x))},"aria-label":a[H.line_id]?d?"Remove from selection":`Remove from ${m}`:d?"Add to selection":`Add to ${m}`,children:a[H.line_id]?"\u2713 Added":d?"+ Add":`Add to ${m}`})})]},H.line_id)})]})]})}),nm]}),!J&&br>1&&(0,s.jsxs)("div",{className:"results-pagination",children:[(0,s.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(kt-1)*rl+1,"\u2013",Math.min(kt*rl,Yt.length)," of ",Yt.length]}),(0,s.jsxs)("div",{className:"results-pagination-controls",children:[(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Be(kt-1),disabled:kt===1,children:"Previous"}),(0,s.jsxs)("span",{className:"results-pagination-page",children:["Page ",kt," of ",br]}),(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Be(kt+1),disabled:kt===br,children:"Next"})]})]}),(T.itemCount!=null||T.headingCount!=null||T.skippedCount!=null)&&(0,s.jsxs)("div",{className:"results-summary",style:{marginTop:16},children:[T.itemCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:T.itemCount})," items parsed"]}),T.headingCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:T.headingCount})," headings"]}),T.skippedCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:T.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:(Nc>0,"0 1 30%"),gap:10,justifyContent:"center"},onClick:()=>O(!0),"aria-label":"Start over",children:[(0,s.jsx)(wd,{}),(0,s.jsx)("span",{children:"Start Over"})]}),Nc>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"," (",Nc,")"]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(Qt,{})})]})]})]})]}),Gv&&(0,s.jsx)("div",{className:"modal-backdrop quick-order-modal-backdrop review-gate-modal-backdrop",role:"dialog","aria-modal":"true","aria-labelledby":"review-gate-title",children:(0,s.jsxs)("section",{className:"quick-order-workflow-modal review-gate-modal",children:[(0,s.jsxs)("div",{className:"review-gate-modal__header",children:[(0,s.jsx)("h2",{id:"review-gate-title",children:"Choose products for these items"}),(0,s.jsx)("p",{children:"We couldn\u2019t find a clear match for these items, so we need your help. Select an option from the suggestions, search the catalogue, or leave the item out."})]}),(0,s.jsx)("div",{className:"review-gate-list",children:Ir.map(x=>{let H=Ae.has(x.item.line_id),be=it(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:()=>{Y(!0),Ei(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Jr(x.item,y)}),(0,s.jsx)("span",{children:x.decision?.reason||(be?"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:$v,children:"Skip all"}),yc.length>0?(0,s.jsxs)("div",{className:"review-gate-skipped",children:[(0,s.jsx)("strong",{children:"Skipped"}),yc.map(x=>(0,s.jsxs)("button",{type:"button",className:"review-gate-item is-skipped",onClick:()=>{M(H=>{let be=new Set(H);return be.delete(x.item.line_id),be}),Y(!0),Ei(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Jr(x.item,y)}),(0,s.jsx)("span",{children:`Not added to your ${m}.`})]}),(0,s.jsx)("span",{className:"review-gate-item__action",children:"Choose a product"})]},x.item.line_id))]}):null]})}),E&&(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:()=>O(!1),children:"Cancel"}),(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-danger",onClick:()=>{O(!1),t()},autoFocus:!0,children:"Start Over"})]})]})})]})}var bt=G(Xe());var Ut=G(Xe()),fv=G(ee());function Rn(e){return JSON.stringify([e.productId,e.qty,e.unit,e.linkedContext??[]])}function q_(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 Sd=(0,Ut.createContext)(null);function ec({children:e,onOpenBasket:t}){let[a,r]=(0,Ut.useState)({}),i=(0,Ut.useCallback)(m=>{r(b=>q_(b,m))},[]),n=(0,Ut.useCallback)(m=>{r(b=>{let y={...b};for(let T of m)y[T.lineId]=T;return y})},[]),o=(0,Ut.useCallback)(m=>{r(b=>{let y={...b};return delete y[m],y})},[]),l=(0,Ut.useCallback)((m,b)=>{r(y=>y[m]?{...y,[m]:{...y[m],qty:b,sellUnitsOverride:null}}:y)},[]),c=(0,Ut.useCallback)((m,b)=>{r(y=>y[m]?{...y,[m]:{...y[m],sellUnitsOverride:b}}:y)},[]),p=(0,Ut.useCallback)(m=>{r(b=>{let y=!1,T={...b};for(let[D,f]of Object.entries(m))T[D]&&(T[D]={...T[D],...f},y=!0);return y?T:b})},[]),d=(0,Ut.useCallback)(()=>r({}),[]),g=(0,Ut.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,fv.jsx)(Sd.Provider,{value:g,children:e})}function Un(){let e=(0,Ut.useContext)(Sd);if(!e)throw new Error("useCart must be used inside a <CartProvider>");return e}function tc(){return(0,Ut.useContext)(Sd)}var q=G(ee()),hv=.2,il=10,gv="Enter a valid email address so we can send your quote.",E_=(e,t)=>{let a=`${t.requestedAmount} ${Na(t.requestedUnit,t.requestedAmount)}`,r=`${t.requiredSellUnits} ${Na(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)} ${Na(t.sellUnit,2)} per ${Na(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}`},M_=e=>["box","pack"].includes(e.requestedUnit)?"Pack size needed to calculate the order quantity.":`This product is sold by ${Na(e.sellUnit,1)}.`;function T_(){return(0,q.jsxs)("svg",{width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,q.jsx)("polyline",{points:"3 6 5 6 21 6"}),(0,q.jsx)("path",{d:"M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"}),(0,q.jsx)("line",{x1:"10",y1:"11",x2:"10",y2:"17"}),(0,q.jsx)("line",{x1:"14",y1:"11",x2:"14",y2:"17"})]})}function nl(){return(0,q.jsx)("svg",{width:"8",height:"5",viewBox:"0 0 8 5",fill:"none",children:(0,q.jsx)("path",{d:"M1 4L4 1L7 4",stroke:"currentColor",strokeWidth:"1.4",strokeLinecap:"round",strokeLinejoin:"round"})})}function ol({cart:e,onUpdateQty:t,onUpdateSellUnits:a,onResolveConversions:r,onRemove:i,onBack:n,onStartNewQuote:o,onQuoteRequested:l,internal:c=!1}){let p=(0,bt.useId)(),d=!c&&Xs()==="QZA6-MRA4",g=Object.values(e),[m,b]=(0,bt.useState)(""),[y,T]=(0,bt.useState)(!1),[D,f]=(0,bt.useState)(!1),u=Cn(),[w,v]=(0,bt.useState)(""),[S,R]=(0,bt.useState)({}),[z,A]=(0,bt.useState)({}),[Q,K]=(0,bt.useState)(1),[fe,Ue]=(0,bt.useState)({}),[Be,Ye]=(0,bt.useState)(!1),[Ne,ve]=(0,bt.useState)("0"),[oe,se]=(0,bt.useState)({}),ye=(0,bt.useRef)(new Map);(0,bt.useEffect)(()=>{if(!r)return;for(let N of Object.values(e))Ft(N).requiredSellUnits!=null&&ye.current.delete(N.lineId);let h=Object.values(e).filter(N=>{if(N.productId==="-"||Ft(N).requiredSellUnits!=null)return!1;let Y=Rn(N);return ye.current.get(N.lineId)===Y?!1:(ye.current.set(N.lineId,Y),!0)});if(h.length===0)return;let M=new Map(h.map(N=>[N.lineId,Rn(N)]));se(N=>({...N,...Object.fromEntries(M)})),fetch(pa("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...$r()},body:JSON.stringify({lines:h.map(N=>({line_id:N.lineId,product_id:N.productId,requested_description:N.requestedDescription??N.description,requested_qty:N.qty,requested_uom:N.unit||null,linked_context:N.linkedContext??[],selected_description:N.description,selected_uoi:N.uoi,selected_uoi_count:N.uoiCount,selected_conversion:{sales_uom_normalised:N.salesUomNormalised,conversion_type:N.conversionType,sales_unit_size:N.salesUnitSize,sales_unit_size_uom:N.salesUnitSizeUom,coverage_qty:N.coverageQty,coverage_uom:N.coverageUom}}))})}).then(N=>N.ok?ka(N):null).then(N=>{let Y={},Z=new Map(h.map(k=>[k.lineId,Rn(k)]));for(let k of N?.data?.items??N?.items??[]){let L=k?.conversion;if(!L||typeof k?.line_id!="string"||ye.current.get(k.line_id)!==Z.get(k.line_id))continue;let P=e[k.line_id];Y[k.line_id]={conversionType:L.conversion_type,requestUomsSupported:L.request_uoms_supported,salesUomNormalised:L.sales_uom_normalised,salesUnitSize:L.sales_unit_size,salesUnitSizeUom:L.sales_unit_size_uom,coverageQty:L.coverage_qty,coverageUom:L.coverage_uom,roundingRule:L.rounding_rule,conversionConfidence:L.conversion_confidence,conversionNotes:L.conversion_notes,...P?.qty===0&&Number.isFinite(L.suggested_order_qty)&&L.suggested_order_qty>0?{qty:L.suggested_order_qty,unit:L.suggested_order_uom||P.unit}:{}}}Object.keys(Y).length>0&&r(Y)}).catch(N=>console.error("Catalogue conversion resolution failed",N)).finally(()=>{se(N=>{let Y={...N};for(let[Z,k]of M)Y[Z]===k&&delete Y[Z];return Y})})},[e,r]);function wt(h){R(M=>{let N={...M};return delete N[h],N})}function Ee(h,M){let N=parseFloat(M);!isNaN(N)&&N>=0&&t(h,Math.min(N,1e5)),wt(h)}function $(h,M,N){t(h,Math.min(1e5,Math.max(0,M+N))),wt(h)}function ue(h){A(M=>{let N={...M};return delete N[h],N})}function Ze(h,M){let N=parseFloat(M);!isNaN(N)&&N>=0&&a(h,Math.min(N,1e5)),ue(h)}function pt(h,M,N){a(h,Math.min(1e5,Math.max(0,M+N))),ue(h)}async function vt(){if(He.some(({pricing:M})=>M.lineTotal==null)){v("Confirm the highlighted quantities before requesting a quote.");return}let h=m.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(h)){v(gv);return}v(""),f(!0);try{let M=await fetch(pa("/api/quote-requests"),{method:"POST",headers:{"Content-Type":"application/json",...$r()},body:JSON.stringify({email:h,items:He.map(({item:N,pricing:Y})=>{let Z=Y.requiredSellUnits??Y.requestedAmount,k=Y.requiredSellUnits!=null?Y.sellUnit:Y.requestedUnit;return{product_id:N.productId,description:N.description,quantity:Z,unit:Na(k,Z),unit_price:Y.requiredSellUnits!=null?Y.unitPrice:null,line_total:Y.lineTotal}})})});if(!M.ok){let N=await ka(M);console.error("Quote request failed",M.status,N?.message),v(M.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}Se!=null&&u("quote_requested",{items:He.length,total:Math.round(Se*100)/100}),T(!0),l?.(),window.scrollTo(0,0)}catch{v("Your request couldn't be sent. Check your connection and try again.")}finally{f(!1)}}let He=g.map(h=>({item:h,pricing:Ft(h,{wasteFactorEnabled:Be,wasteFactorOverride:Math.max(0,Number.parseFloat(Ne)||0)/100})})),de=Is(g,{wasteFactorEnabled:Be,wasteFactorOverride:Math.max(0,Number.parseFloat(Ne)||0)/100}),_e=de==null?null:de*hv,Se=de==null?null:de*(1+hv),E=He.filter(({pricing:h})=>h.lineTotal==null).length,O=Object.keys(oe).length,re=!!r&&g.some(h=>{if(h.productId==="-"||Ft(h).requiredSellUnits!=null)return!1;let M=Rn(h);return ye.current.get(h.lineId)!==M||oe[h.lineId]===M}),ce=(0,bt.useRef)({items:He.length,...Se==null?{}:{total:Math.round(Se*100)/100}});(0,bt.useEffect)(()=>{u("basket_viewed",ce.current)},[u]);let ge=Math.max(1,Math.ceil(He.length/il)),Ae=Math.min(Q,ge),Pe=He.slice((Ae-1)*il,Ae*il);return y?(0,q.jsx)("div",{className:"wizard-step entry-stage",children:(0,q.jsxs)("div",{className:"quote-request-sent",role:"status",children:[(0,q.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,q.jsx)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2.5",strokeLinecap:"round",strokeLinejoin:"round",children:(0,q.jsx)("polyline",{points:"5 12.5 10 17.5 19 7"})})}),(0,q.jsx)("h1",{children:"Quote requested"}),(0,q.jsxs)("p",{children:["You're all done. We'll email your sharper price to ",(0,q.jsx)("strong",{children:m.trim()}),", usually within one working day."]}),(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,q.jsx)("span",{children:"Start a new quote"})}),(0,q.jsx)("p",{className:"quote-request-sent-note",children:"Nothing is charged until you approve the quote."})]})}):!c&&g.length===0?(0,q.jsx)("div",{className:"wizard-step entry-stage",children:(0,q.jsxs)("div",{className:"quote-request-sent",children:[(0,q.jsx)("div",{className:"quote-request-sent-icon","aria-hidden":"true",children:(0,q.jsxs)("svg",{width:"40",height:"40",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[(0,q.jsx)("path",{d:"M3 9h18l-2 11H5z"}),(0,q.jsx)("path",{d:"M8 9l4-6 4 6"})]})}),(0,q.jsx)("h1",{children:d?"Your quote request is empty":"Your basket is empty"}),(0,q.jsx)("p",{children:d?"Start again with your list to build your quote.":"Start again with your list to fill your basket."}),(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,q.jsx)("span",{children:"Back to start"})})]})}):(0,q.jsx)("div",{className:`wizard-step entry-stage${d?" basket-layout--qza6-mra4":""}`,children:(0,q.jsxs)("div",{className:`quick-order-card${c?"":" quick-order-card--customer"}`,children:[(0,q.jsxs)("div",{className:`quick-order-hero${c?"":" quick-order-hero--customer"}`,children:[c&&(0,q.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,q.jsxs)("div",{className:"basket-hero-copy",children:[d&&(0,q.jsxs)("button",{type:"button",className:"cta-btn cta-btn-secondary basket-hero-back",onClick:n,children:[(0,q.jsx)(Kr,{}),(0,q.jsx)("span",{children:"Back to results"})]}),(0,q.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,q.jsx)("h1",{children:c?"Your Selection":d?"Request a quote":"Your Basket"}),c&&(0,q.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,q.jsx)("strong",{children:g.length})," ",g.length===1?"item":"items"]})]}),(0,q.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,q.jsx)("div",{className:"quick-order-panel",style:{paddingTop:16},children:re?(0,q.jsxs)("div",{className:"basket-resolving",role:"status","aria-label":"Calculating order quantities",children:[(0,q.jsx)("span",{className:"basket-resolving-wheel","aria-hidden":"true"}),(0,q.jsx)("span",{children:"Calculating your quantities\u2026"})]}):g.length===0?(0,q.jsxs)("div",{className:"quick-order-history-empty",children:[(0,q.jsx)("div",{className:"basket-empty-icon","aria-hidden":"true",children:"\u{1F4CB}"}),(0,q.jsx)("p",{children:"Your selection is empty."}),(0,q.jsx)("p",{className:"basket-empty-hint",children:"Go back to your results and add quoted items."}),(0,q.jsx)("div",{className:"btn-row",style:{marginTop:20,justifyContent:"center"},children:(0,q.jsx)("button",{className:"cta-btn",style:{width:"auto",maxWidth:280},onClick:n,"aria-label":"Back to results",children:(0,q.jsx)("span",{children:"Back to Results"})})})]}):(0,q.jsxs)(q.Fragment,{children:[(0,q.jsxs)("div",{className:"basket-layout",children:[(0,q.jsxs)("div",{className:"basket-main",children:[(0,q.jsx)("div",{className:"basket-list","aria-label":c?"Selection items":d?"Quote request items":"Basket items",children:Pe.map(({item:h,pricing:M})=>{let N=S[h.lineId]??String(M.requestedAmount),Y=M.requestedUnit===M.sellUnit||M.costingMode==="review",Z=M.requiredSellUnits==null||M.requestedAmount!==M.requiredSellUnits||M.requestedUnit!==M.sellUnit;return(0,q.jsxs)("article",{className:"basket-card",children:[(0,q.jsxs)("div",{className:"basket-card-top",children:[(0,q.jsx)("img",{className:"basket-card-thumb",src:Ga(h.description,h.productId,h.pdpPhotoUrl),alt:"",width:48,height:48}),(0,q.jsxs)("div",{className:"basket-card-info",children:[(0,q.jsx)("div",{className:"bom-component-name",children:h.description}),Z&&M.costingMode!=="review"&&(0,q.jsxs)("button",{type:"button",className:"basket-calc-toggle",onClick:()=>Ue(k=>({...k,[h.lineId]:!k[h.lineId]})),"aria-expanded":!!fe[h.lineId],children:["How we calculated this",(0,q.jsx)("span",{className:`basket-calc-toggle-chevron${fe[h.lineId]?" basket-calc-toggle-chevron--open":""}`,children:(0,q.jsx)(nl,{})})]})]}),(0,q.jsx)("div",{className:"basket-card-actions",children:(0,q.jsx)("button",{type:"button",className:"mf-remove-small-btn basket-card-remove",onClick:()=>i(h.lineId),"aria-label":`Remove ${h.description}`,children:(0,q.jsx)(T_,{})})})]}),c&&(0,q.jsxs)("div",{className:"results-detail-block basket-internal-detail",children:[(0,q.jsxs)("dl",{className:"results-detail-grid",children:[(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Conversion type"}),(0,q.jsx)("dd",{children:h.conversionType??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Conversion confidence"}),(0,q.jsx)("dd",{children:h.conversionConfidence??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Sales unit"}),(0,q.jsx)("dd",{children:h.salesUnitSize!=null?(0,q.jsxs)(q.Fragment,{children:[h.salesUnitSize," ",Sa(h.salesUnitSizeUom,h.salesUnitSize)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Coverage"}),(0,q.jsx)("dd",{children:h.coverageQty!=null?(0,q.jsxs)(q.Fragment,{children:[h.coverageQty," ",Sa(h.coverageUom,h.coverageQty)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Waste factor"}),(0,q.jsx)("dd",{children:h.wasteFactorDefault??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Rounding rule"}),(0,q.jsx)("dd",{children:h.roundingRule??"-"})]})]}),h.conversionNotes&&(0,q.jsx)("p",{className:"results-rerank-note",children:h.conversionNotes})]}),M.costingMode==="review"?(0,q.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,q.jsx)("strong",{children:oe[h.lineId]===Rn(h)?"Calculating order quantity\u2026":"Quantity needs confirmation."})," ",M_(M)]}):Z&&fe[h.lineId]?(0,q.jsx)("p",{className:"basket-calc-text",children:E_(h,M)}):null,(0,q.jsxs)("div",{className:"basket-card-stats",children:[(0,q.jsxs)("div",{className:"basket-stat",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Requested qty"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsxs)("div",{className:"basket-qty-field",children:[(0,q.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:N,disabled:Y,onChange:k=>R(L=>({...L,[h.lineId]:k.target.value})),onBlur:k=>Ee(h.lineId,k.target.value),onKeyDown:k=>{k.key==="Enter"&&k.target.blur()},"aria-label":`${h.description} requested quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",disabled:Y,onClick:()=>$(h.lineId,parseFloat(N)||0,1),"aria-label":`Increase ${h.description} quantity`,children:(0,q.jsx)(nl,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",disabled:Y,onClick:()=>$(h.lineId,parseFloat(N)||0,-1),"aria-label":`Decrease ${h.description} quantity`,children:(0,q.jsx)(nl,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:Sa(M.requestedUnit,parseFloat(N)||0)})]})]}),(0,q.jsxs)("div",{className:"basket-stat basket-stat--right",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Order qty"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsxs)("div",{className:"basket-qty-field",children:[(0,q.jsx)("input",{className:"bom-qty-edit",type:"number",inputMode:"decimal",min:"0",placeholder:"-",value:z[h.lineId]??String(M.requiredSellUnits??""),onChange:k=>A(L=>({...L,[h.lineId]:k.target.value})),onBlur:k=>Ze(h.lineId,k.target.value),onKeyDown:k=>{k.key==="Enter"&&k.target.blur()},"aria-label":`${h.description} order quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",onClick:()=>pt(h.lineId,parseFloat(z[h.lineId]??String(M.requiredSellUnits??"0"))||0,1),"aria-label":`Increase ${h.description} order quantity`,children:(0,q.jsx)(nl,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",onClick:()=>pt(h.lineId,parseFloat(z[h.lineId]??String(M.requiredSellUnits??"0"))||0,-1),"aria-label":`Decrease ${h.description} order quantity`,children:(0,q.jsx)(nl,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:Sa(M.sellUnit,parseFloat(z[h.lineId]??String(M.requiredSellUnits??"0"))||0)})]})]}),(0,q.jsxs)("div",{className:"basket-stat basket-stat--total",children:[(0,q.jsx)("span",{className:"basket-stat-label",children:"Total"}),(0,q.jsxs)("div",{className:"basket-stat-value",children:[(0,q.jsx)("strong",{children:M.lineTotal!=null?lt(M.lineTotal):"-"}),M.lineTotal!=null&&(0,q.jsx)("span",{className:"basket-metric-unit",children:"ex. VAT"})]})]})]})]},h.lineId)})}),ge>1&&(0,q.jsxs)("div",{className:"results-pagination",children:[(0,q.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(Ae-1)*il+1,"\u2013",Math.min(Ae*il,He.length)," of ",He.length]}),(0,q.jsxs)("div",{className:"results-pagination-controls",children:[(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>K(Ae-1),disabled:Ae===1,children:"Previous"}),(0,q.jsxs)("span",{className:"results-pagination-page",children:["Page ",Ae," of ",ge]}),(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>K(Ae+1),disabled:Ae===ge,children:"Next"})]})]})]}),(0,q.jsxs)("aside",{className:"basket-sidebar",children:[(0,q.jsx)("div",{className:"basket-sidebar-title",children:d?"Quote request summary":"Order summary"}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:d?"List price (ex. VAT)":"Subtotal (ex. VAT)"}),(0,q.jsx)("span",{children:de==null?"To confirm":lt(de)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:"VAT (20%)"}),(0,q.jsx)("span",{children:_e==null?"To confirm":lt(_e)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row basket-sidebar-row--total",children:[(0,q.jsx)("span",{children:d?"List price (inc.\xA0VAT)":"Total"}),(0,q.jsx)("span",{children:Se==null?"To confirm":lt(Se)})]}),!d&&(0,q.jsx)("div",{className:"basket-summary-waste",children:(0,q.jsxs)("div",{className:"basket-waste-control",children:[(0,q.jsxs)("label",{className:"basket-global-waste",children:[(0,q.jsx)("input",{type:"checkbox",checked:Be,onChange:h=>Ye(h.target.checked)}),(0,q.jsx)("span",{children:"Add waste factor"})]}),(0,q.jsxs)("label",{className:"basket-global-waste-percent",children:[(0,q.jsx)("input",{type:"number",inputMode:"decimal",min:"0",step:"0.1",value:Ne,onChange:h=>ve(h.target.value),disabled:!Be,"aria-label":"Waste factor percent"}),(0,q.jsx)("span",{children:"%"})]})]})}),(0,q.jsx)("label",{htmlFor:`${p}-basket-reference`,className:"basket-sidebar-label",children:d?"Enter email for your sharper quote":"Your reference (optional)"}),(0,q.jsx)("input",{id:`${p}-basket-reference`,type:d?"email":"text",className:"basket-sidebar-input",value:m,onChange:h=>{b(h.target.value),d&&v("")},placeholder:d?"you@example.com":"PO number or job reference","aria-invalid":d&&w===gv,"aria-describedby":d&&w?`${p}-basket-reference-error`:void 0}),d&&w&&(0,q.jsx)("p",{id:`${p}-basket-reference-error`,className:"basket-quote-request-error",role:"alert",children:w}),d?(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:()=>{vt()},disabled:D||E>0||O>0,"aria-busy":D,children:(0,q.jsx)("span",{children:D?"Sending\u2026":"Request our best quote"})}):(0,q.jsx)("button",{className:"cta-btn",onClick:()=>{u("downloaded",{type:"basket",items:g.length}),cv(g)},"aria-label":c?"Download selection":"Download basket",children:(0,q.jsx)("span",{children:c?"Download Quote":"Buy Now"})}),(0,q.jsxs)("p",{className:"basket-sidebar-disclaimer",children:[(0,q.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,q.jsx)("div",{className:"btn-row results-actions",children:(0,q.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",gap:10,justifyContent:"center"},onClick:n,"aria-label":"Back to results",children:[(0,q.jsx)(Kr,{}),(0,q.jsx)("span",{children:"Back to results"})]})})]})})]})})}var Ca=G(ee()),qd="metron-quick-quote";function ac(e){return(0,Ca.jsx)(ec,{children:(0,Ca.jsx)(z_,{...e})})}function z_({fullPage:e=!1,hideHeader:t=!1,internal:a=!1}){let[r,i]=(0,Le.useState)("entry"),[n,o]=(0,Le.useState)(null),[l,c]=(0,Le.useState)(""),p=(0,Le.useRef)(null),d=(0,Le.useRef)(0),[g,m]=(0,Le.useState)(0),[b,y]=(0,Le.useState)(null),[T,D]=(0,Le.useState)(!1),{cart:f,addToCart:u,addManyToCart:w,removeFromCart:v,updateCartQty:S,updateCartSellUnits:R,updateCartConversions:z,clearCart:A}=Un(),[Q,K]=(0,Le.useState)(!1),[fe,Ue]=(0,Le.useState)(null),Be=()=>{Ue(null);try{window.sessionStorage.removeItem(Js)}catch{}},Ye=(0,Le.useRef)(null),Ne=Ys("quick-quote",Ye);(0,Le.useEffect)(()=>{Ne("viewed")},[Ne]);let[ve,oe]=(0,Le.useState)(!1);(0,Le.useEffect)(()=>{let de=window.location.hash,_e=null;try{_e=JSON.parse(window.sessionStorage.getItem(qd)??"null")}catch{}if(_e?.scheduleResult)o("schedule"),y(_e.scheduleResult),D(_e.reviewGateComplete),K(_e.cartSeeded),w(Object.values(_e.cart)),de==="#quote-request"?i("basket"):de==="#matched-products"&&i("results");else if(de==="#matched-products"||de==="#quote-request"){let Se=new URL(window.location.href);Se.hash="",window.history.replaceState(window.history.state,"",Se)}oe(!0)},[]),(0,Le.useEffect)(()=>{if(ve)try{b?window.sessionStorage.setItem(qd,JSON.stringify({scheduleResult:b,reviewGateComplete:T,cartSeeded:Q,cart:f})):window.sessionStorage.removeItem(qd)}catch{}},[ve,b,T,Q,f]);let se=(0,Le.useCallback)(de=>{if(typeof window>"u")return;let _e=new URL(window.location.href);_e.hash=de==="basket"?"quote-request":"matched-products";let Se=de==="results"&&(window.location.hash==="#matched-products"||window.location.hash==="#quote-request");window.history[Se?"replaceState":"pushState"]({boqQuoteStage:de},"",_e)},[]),ye=(0,Le.useRef)(!1);(0,Le.useEffect)(()=>{let de=_e=>{ye.current=!1;let Se=window.location.hash;Se==="#quote-request"?i("basket"):Se==="#matched-products"&&b?(o("schedule"),i("results")):i("entry");let E=_e.state,O=window.location.href;setTimeout(()=>{if(window.location.href===O){if(Se==="#quote-request"||Se==="#matched-products"||Se==="#quote-entry"){window.history.replaceState({boqQuoteStage:Se==="#quote-request"?"basket":Se==="#quote-entry"?"entry":"results"},"",O);return}!E?.turbo&&window.history.state?.turbo&&window.history.replaceState(E,"",O)}})};return window.addEventListener("popstate",de),()=>window.removeEventListener("popstate",de)},[b]);let wt=(0,Le.useCallback)(()=>{se("basket"),i("basket")},[se]),Ee=(0,Le.useCallback)(()=>{if(window.location.hash==="#quote-request"){if(ye.current)return;ye.current=!0,window.history.back();return}i(b?"results":"entry")},[b]),$=(0,Le.useRef)(r);(0,Le.useEffect)(()=>{$.current!==r&&($.current=r,window.scrollTo(0,0))},[r]);let ue=()=>{i("entry"),o(null),c(""),m(0),y(null),D(!1),A(),K(!1),Be()},Ze=(0,Le.useCallback)(async(de,_e,Se=!0)=>{let E=++d.current;c(""),m(0);let O=0,re=()=>{O=Math.min(O+1,3),m(O)};try{let{jobId:ce}=await cw(de,_e,Se);if(E!==d.current)return;let{promise:ge,cancel:Ae}=pw(()=>uw(ce),5e3,re,"schedule");p.current=Ae;let Pe=await ge;if(Pe.status==="failed"||!Pe.result)throw new Error(Pe.error||"Failed to process schedule");let h=Pe.result.lineItems.length,M=Pe.result.results.filter(N=>N.candidates.length>0).length;Ne("results_shown",{lines:h,matched:M,unmatched:h-M}),A(),K(!1),D(!1),y(Pe.result),se("results"),i("results")}catch(ce){if(E!==d.current)return;Ne("error",{stage:"matching"}),c(ce?.message||"Failed to process schedule"),i("entry")}finally{E===d.current&&(p.current?.(),p.current=null)}},[se,Ne,A]),pt=(0,Le.useCallback)(()=>{d.current++,p.current?.(),p.current=null},[]),vt=(0,Le.useCallback)(async(de,_e,Se=!0)=>{if(!de.trim())return;o("schedule");let E=new File([de],"pasted-schedule.txt",{type:"text/plain"});await Ze(E,_e,Se)},[Ze]),He=(0,Le.useCallback)(async de=>{o("schedule"),await Ze(de)},[Ze]);return(0,Ca.jsx)(Po.Provider,{value:Ne,children:(0,Ca.jsx)("div",{ref:Ye,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${!e&&r==="processing"?" app-wrapper--loading":""}`,style:jt().theme,children:(0,Ca.jsxs)("main",{className:"main-content",children:[l&&(0,Ca.jsxs)("div",{className:"error-box",role:"alert",children:[(0,Ca.jsx)("strong",{children:"Error:"})," ",l]}),r==="entry"&&(0,Ca.jsx)(gd,{onPasteSchedule:vt,onUploadSchedule:He,onEntryModeChange:o,draft:fe,onSubmitDraft:Ue,onCancelMatch:pt}),r==="results"&&n==="schedule"&&b&&(0,Ca.jsx)(Nd,{scheduleResult:b,onStartOver:ue,cart:f,onAddToCart:u,onRemoveFromCart:v,onGoToBasket:wt,cartSeeded:Q,onCartSeeded:()=>K(!0),reviewGateComplete:T,onReviewGateComplete:()=>D(!0),internal:a}),r==="basket"&&(0,Ca.jsx)(ol,{cart:f,onUpdateQty:S,onUpdateSellUnits:R,onResolveConversions:z,onRemove:v,onBack:Ee,onStartNewQuote:ue,onQuoteRequested:()=>{y(null),D(!1),K(!1),A(),Be()},internal:a})]})})})}var Xa=G(Xe());var xi=G(Xe()),W=G(ee()),bv=[{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"}],rc=e=>Number.parseFloat(e)||0,wv=(e,t)=>rc(e)*(t==="m"?1:.3048),Ed=(e,t)=>rc(e.quantity)*(2*wv(e.height,t)+wv(e.width,t)),A_=()=>({quantity:"1",width:"",height:""});function R_({profile:e}){return(0,W.jsxs)("svg",{className:"architrave-calculator__profile-diagram",viewBox:"0 0 112 76","aria-hidden":"true",children:[(0,W.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,W.jsx)("line",{x1:"12",y1:"66",x2:"100",y2:"66"})]})}function Md({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,m]=(0,xi.useState)("ogee"),[b,y]=(0,xi.useState)("2.4"),T=(S,R,z)=>{S(A=>({...A,[R]:z}))},D=Ed(n,r)+Ed(l,r)+p.reduce((S,R)=>S+Ed(R,r),0),f=rc(b)>0?Math.ceil(D/rc(b)):0,u=bv.find(S=>S.id===g)?.label??"",w=[{key:`architrave-${g}`,label:`Architrave (${u})`,qty:D,unit:"m",query:`${u} architrave`,category:"architrave"}],v=(S,R,z,A)=>(0,W.jsxs)("div",{className:"architrave-calculator__opening-row",children:[(0,W.jsx)("span",{children:S}),(0,W.jsx)("input",{"aria-label":`${S} quantity`,type:"number",min:"0",step:"1",value:R.quantity,onChange:Q=>z("quantity",Q.target.value)}),(0,W.jsx)("input",{"aria-label":`${S} width`,type:"number",min:"0",step:"0.01",value:R.width,onChange:Q=>z("width",Q.target.value)}),(0,W.jsx)("input",{"aria-label":`${S} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:Q=>z("height",Q.target.value)}),A?(0,W.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:A,children:"Remove"}):null]});return(0,W.jsx)(W.Fragment,{children:(0,W.jsxs)("div",{className:"truss-estimator",children:[(0,W.jsxs)("div",{className:"quick-order-hero",children:[(0,W.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,W.jsx)("h1",{children:"Architrave Calculator"}),(0,W.jsx)("p",{children:"Estimate architrave lengths and board quantities for door openings."})]}),(0,W.jsxs)("div",{className:"truss-estimator__card architrave-calculator",children:[(0,W.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure your openings"}),(0,W.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,W.jsxs)("div",{className:"architrave-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Door openings"}),(0,W.jsx)("p",{className:"architrave-calculator__hint",children:"Each opening is calculated as two side pieces plus one head piece."}),(0,W.jsxs)("div",{className:"architrave-calculator__unit-row",children:[(0,W.jsx)("span",{children:"Units"}),(0,W.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,W.jsx)("button",{type:"button",className:r==="m"?"is-selected":"",onClick:()=>i("m"),children:"Metres"}),(0,W.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>i("ft"),children:"Feet"})]})]}),(0,W.jsxs)("div",{className:"architrave-calculator__dimensions-header",children:[(0,W.jsx)("span",{children:"Opening"}),(0,W.jsx)("span",{children:"Qty"}),(0,W.jsxs)("span",{children:["Width (",r,")"]}),(0,W.jsxs)("span",{children:["Height (",r,")"]}),(0,W.jsx)("span",{})]}),v("Single doors",n,(S,R)=>T(o,S,R)),v("Double doors",l,(S,R)=>T(c,S,R)),p.map((S,R)=>v(`Alternative door ${R+1}`,S,(z,A)=>d(Q=>Q.map((K,fe)=>fe===R?{...K,[z]:A}:K)),()=>d(z=>z.filter((A,Q)=>Q!==R)))),(0,W.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>d(S=>[...S,A_()]),children:"+ Add alternative-sized door"})]}),(0,W.jsxs)("div",{className:"architrave-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Standard profile"}),(0,W.jsx)("p",{className:"architrave-calculator__hint",children:"Choose the profile you plan to use. Length calculations are the same for each profile."}),(0,W.jsx)("div",{className:"architrave-calculator__profiles",children:bv.map(S=>(0,W.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g===S.id?" is-selected":""}`,onClick:()=>m(S.id),children:[(0,W.jsx)(R_,{profile:S.id}),(0,W.jsx)("div",{className:"truss-estimator__option-title",children:S.label}),(0,W.jsx)("div",{className:"truss-estimator__option-copy",children:S.blurb})]},S.id))})]}),(0,W.jsxs)("div",{className:"architrave-calculator__section",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,W.jsx)("div",{className:"architrave-calculator__options",children:(0,W.jsxs)("label",{className:"truss-estimator__field",children:[(0,W.jsx)("span",{children:"Board length (m)"}),(0,W.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,W.jsx)("p",{className:"architrave-calculator__hint",children:"Waste allows for mitred corners, cuts and damaged lengths."})]}),(0,W.jsxs)("div",{className:"architrave-calculator__totals",children:[(0,W.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,W.jsxs)("div",{className:"architrave-calculator__result-grid",children:[(0,W.jsxs)("div",{children:[(0,W.jsx)("span",{children:"Architrave needed"}),(0,W.jsxs)("strong",{children:[D.toFixed(2)," m"]})]}),(0,W.jsxs)("div",{children:[(0,W.jsx)("span",{children:"Board lengths"}),(0,W.jsx)("strong",{children:f})]})]})]}),(0,W.jsxs)("div",{className:"architrave-calculator__actions",children:[(0,W.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,W.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(w),disabled:D<=0,children:a})]})]})]})})}var ki=G(Xe()),ne=G(ee()),vv=60,yv=10,U_=.02,D_=.012,O_=.01,Dn=e=>Number.parseFloat(e)||0,B_=(e,t=2)=>e.toFixed(t);function Td({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,m]=(0,ki.useState)(""),[b,y]=(0,ki.useState)(!0),T=l==="metric"?Dn(p)*Dn(g):Dn(p)*Dn(g)*.092903,f=T*(r==="brick"?vv:yv),u=Math.ceil(f),w=T*(r==="brick"?U_:D_),v=Math.ceil(w/O_),S=l==="metric"?T:T*10.7639,R=[{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"},...b?[{key:"mortar",label:"Blue Circle Quality Assured Mortar Mix 20kg",qty:v,unit:"bag",query:"ready mixed mortar",category:"mortar"}]:[]],z=A=>{if(A===l)return;let Q=A==="imperial"?3.28084:.3048;d((Dn(p)*Q).toFixed(2)),m((Dn(g)*Q).toFixed(2)),c(A)};return(0,ne.jsx)(ne.Fragment,{children:(0,ne.jsxs)("div",{className:"truss-estimator",children:[(0,ne.jsxs)("div",{className:"quick-order-hero",children:[(0,ne.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ne.jsx)("h1",{children:"Brick and Block Calculator"}),(0,ne.jsx)("p",{children:"Estimate masonry units, sand and cement for a wall."})]}),(0,ne.jsxs)("div",{className:"truss-estimator__card brick-calculator",children:[(0,ne.jsx)("h2",{className:"truss-estimator__step-title",children:"Wall area and masonry type"}),(0,ne.jsx)("p",{className:"truss-estimator__step-sub",children:"Pick brick or block and enter the wall dimensions for unit counts plus ready-mixed mortar."}),(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Masonry type"}),(0,ne.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["brick","Brick"],["block","Block"]].map(([A,Q])=>(0,ne.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===A?" is-selected":""}`,onClick:()=>i(A),children:[(0,ne.jsx)("div",{className:"truss-estimator__option-title",children:Q}),(0,ne.jsxs)("div",{className:"truss-estimator__option-copy",children:["Approx. ",A==="brick"?vv:yv," per m\xB2"]})]},A))})]}),r==="brick"&&(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Brick type"}),(0,ne.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:[["common","Common concrete","General-purpose grey concrete brick"],["engineering-red","Engineering red","Class B perforated, 65mm"],["engineering-blue","Engineering blue","Class B solid, 65mm"]].map(([A,Q,K])=>(0,ne.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n===A?" is-selected":""}`,onClick:()=>o(A),children:[(0,ne.jsx)("div",{className:"truss-estimator__option-title",children:Q}),(0,ne.jsx)("div",{className:"truss-estimator__option-copy",children:K})]},A))})]}),(0,ne.jsxs)("div",{className:"brick-calculator__section",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,ne.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,ne.jsx)("button",{type:"button",className:l==="metric"?"is-selected":"",onClick:()=>z("metric"),children:"Metric"}),(0,ne.jsx)("button",{type:"button",className:l==="imperial"?"is-selected":"",onClick:()=>z("imperial"),children:"Imperial"})]}),(0,ne.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsxs)("span",{children:["Height (",l==="metric"?"m":"ft",")"]}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:A=>d(A.target.value)})]}),(0,ne.jsxs)("label",{className:"truss-estimator__field",children:[(0,ne.jsxs)("span",{children:["Width (",l==="metric"?"m":"ft",")"]}),(0,ne.jsx)("input",{type:"number",min:"0",step:"0.01",value:g,onChange:A=>m(A.target.value)})]})]})]}),(0,ne.jsx)("div",{className:"brick-calculator__options",children:(0,ne.jsxs)("label",{className:"brick-calculator__checkbox",children:[(0,ne.jsx)("input",{type:"checkbox",checked:b,onChange:A=>y(A.target.checked)}),(0,ne.jsx)("span",{children:"Include ready-mixed mortar"})]})}),(0,ne.jsxs)("div",{className:"brick-calculator__totals",children:[(0,ne.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ne.jsxs)("div",{className:"brick-calculator__result-grid",children:[(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Wall area"}),(0,ne.jsxs)("strong",{children:[B_(S)," ",l==="metric"?"m\xB2":"ft\xB2"]})]}),(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:r==="brick"?"Bricks":"Blocks"}),(0,ne.jsx)("strong",{children:u.toLocaleString("en-GB")})]}),b?(0,ne.jsxs)("div",{children:[(0,ne.jsx)("span",{children:"Ready-mixed mortar"}),(0,ne.jsxs)("strong",{children:[v," x 20kg bags"]})]}):null]}),(0,ne.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,ne.jsxs)("div",{className:"brick-calculator__actions",children:[(0,ne.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ne.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(R),disabled:T<=0,children:a})]})]})]})})}var hr=G(Xe());var L_={"NZ4Y-ZMSQ":{"brick-block":{"brick-common":"105499","brick-engineering-red":"1654","brick-engineering-blue":"1723",block:"501",mortar:"646"},skirting:{"skirting-chamfered":"1525","skirting-ogee":"135 primed mdf ogee","skirting-pencil-round":"892","skirting-torus":"1941"},architrave:{"architrave-ogee":"134 primed mdf ogee","architrave-ovolo":"1531","architrave-pencil-round":"1896","architrave-square-edge":"118 primed mdf square","architrave-torus":"1531"},plasterboard:{standard:"1647",moisture:"11 moisture plasterboard",fire:"14 fire plasterboard",sound:"1769",screws:"131160",tape:"1766",adhesive:"108439"},insulation:{"insulation-floor":"152187","insulation-wall":"147","insulation-roof":"442","insulation-loft":"152180"},timber:{studs:"1213",joists:"208",battens:"1729"},fencing:{"panels-boundary-0.9":"66 lap fence panel","panels-boundary-1.2":"1450","panels-boundary-1.5":"1449","panels-boundary-1.8":"1448","panels-skyline-1.8":"1475","concrete-intermediate-8":"40197","concrete-end-8":"40198","timber-post-6":"141411","timber-post-8":"1709",postcrete:"12142",gate:"1984","gravel-boards":"40200"},decking:{"boards-summit":"24322",joists:"208",screws:"131079"},paving:{"surface-council":"23995","surface-raj":"12369","surface-brindle":"304","surface-charcoal":"296","surface-pea":"431","sub-base":"569",bedding:"563"}}};function zd(e,t){let a=L_[jt().client??""]?.[e];if(!a)return null;let r=e==="plasterboard"&&t.key==="board"?t.label.split(" ")[0].toLowerCase():t.key;return a[r]??null}function _v(e,t){let a=t.map(r=>{let i=zd(e,r);return i?{key:r.key,productId:i.split(" ")[0],search:i,qty:r.qty,unit:r.unit}:null});return a.length>0&&a.every(Boolean)?a:null}var xv=new Map;function H_(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=`${jt().client??""}||${e}||${t??""}||${a}||${r??""}`,n=xv.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(pa(`/api/catalogue/search?${o.toString()}`),{headers:wi()}),c=await ka(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(H_):[];return xv.set(i,p),p}var j_=new Set(["bag","box","roll","pack"]),Q_=new Set(["each","bag","box","roll","pack","tub"]);function Ad(e,t){let a=t?.uoi,r=a!=null&&Q_.has(a.toLowerCase())&&(t?.uoi_count??1)===1;return j_.has(e)&&r?a:e}async function kv(e,t,a){return await Promise.all(e.map(async i=>{try{let n=a?zd(a,i):null,[o,l]=await Promise.all([n?fr(n,void 0,void 0,t).then(p=>p.find(d=>d.product_id===n.split(" ")[0]),()=>{}):void 0,fr(i.query,i.category,void 0,t)]),c=o?[o,...l.filter(p=>p.product_id!==o.product_id)]:l;return{requirement:{...i,unit:Ad(i.unit,c[0])},candidates:c}}catch{return{requirement:i,candidates:[]}}}))}async function Nv(){let e=await fetch(pa("/api/catalogue"),{headers:wi()});if(!e.ok)return{itemCount:0,uploadedAt:null};let t=await ka(e);return{itemCount:Number(t?.itemCount)||0,uploadedAt:t?.uploadedAt??null}}var X=G(ee()),G_=1.54,Y_=1440,X_=25,Rd=800,V_=1500,Ud=e=>Number.parseFloat(e)||0,On={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 Dd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let r=tc(),[i,n]=(0,hr.useState)("m"),[o,l]=(0,hr.useState)(""),[c,p]=(0,hr.useState)(""),[d,g]=(0,hr.useState)(""),[m,b]=(0,hr.useState)("concrete"),[y,T]=(0,hr.useState)("mot"),[D,f]=(0,hr.useState)(!1),[u,w]=(0,hr.useState)(null),v=i==="m"?1:.3048,S=Ud(o)*v*Ud(c)*v*Ud(d)*(i==="m"?.01:.0254),R=On[y],z=S*G_/7,A=z*Y_,Q=z*2,K=z*4,fe=Math.ceil(A/X_),Ue=Math.ceil(Q*On["sharp-sand"].density*1e3/Rd),Be=Math.ceil(K*On.gravel.density*1e3/Rd),Ye=Math.ceil(S*R.density*1e3/Rd),Ne=m==="concrete"?[{key:"cement",label:"Blue Circle General Purpose Grey Cement 25kg",qty:fe,productId:"6003004"},{key:"sharp-sand",label:"Sharp Sand Bulk Bag (800kg)",qty:Ue,productId:"6001012"},{key:"gravel",label:"20mm Non Decorative Pea Shingle/Gravel Bulk Bag (800kg)",qty:Be,productId:"6001004"}]:[{key:y,label:`${R.label} Bulk Bag (800kg)`,qty:Ye,productId:R.productId}],ve=()=>{if(t){t(Ne.map(se=>({key:se.key,label:se.label,qty:se.qty,unit:"each",query:se.productId})));return}oe()},oe=async()=>{let se=Date.now();f(!0),w(null);try{let ye=await Promise.all(Ne.map(async Ee=>{let $=(await fr(Ee.productId)).find(ue=>ue.product_id===Ee.productId);if(!$)throw new Error(`${Ee.label} is no longer available in this catalogue.`);return Pr($,{lineId:`concrete-aggregate:${Ee.key}`,description:Ee.label,unit:"bag",qty:Ee.qty})})),wt=V_-(Date.now()-se);wt>0&&await new Promise(Ee=>window.setTimeout(Ee,wt)),r?.clearCart(),r?.addManyToCart(ye),r?.openBasket()}catch(ye){w(ye instanceof Error?ye.message:"Could not add the products to your basket.")}finally{f(!1)}};return D?(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)("div",{className:"truss-estimator",children:[(0,X.jsxs)("div",{className:"quick-order-hero",children:[(0,X.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,X.jsx)("h1",{children:"Your Materials"}),(0,X.jsx)("p",{children:"Calculating quantities from the Concrete and Aggregate Calculator."})]}),(0,X.jsx)("div",{className:"truss-estimator__card",children:(0,X.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,X.jsx)(dr,{}),(0,X.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})}):(0,X.jsx)(X.Fragment,{children:(0,X.jsxs)("div",{className:"truss-estimator",children:[(0,X.jsxs)("div",{className:"quick-order-hero",children:[(0,X.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,X.jsx)("h1",{children:"Concrete and Aggregate Calculator"}),(0,X.jsx)("p",{children:"Calculate fixed site-mix concrete ingredients or aggregate bulk bags."})]}),(0,X.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,X.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose what you need"}),(0,X.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,X.jsxs)("div",{className:"materials-calculator__section",children:[(0,X.jsx)("div",{className:"truss-estimator__section-heading",children:"Material type"}),(0,X.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,X.jsxs)("button",{type:"button",className:`truss-estimator__option-card${m==="concrete"?" is-selected":""}`,onClick:()=>b("concrete"),children:[(0,X.jsx)("div",{className:"truss-estimator__option-title",children:"Site-mixed concrete"}),(0,X.jsx)("div",{className:"truss-estimator__option-copy",children:"Cement, sharp sand and 20mm aggregate"})]}),(0,X.jsxs)("button",{type:"button",className:`truss-estimator__option-card${m==="aggregate"?" is-selected":""}`,onClick:()=>b("aggregate"),children:[(0,X.jsx)("div",{className:"truss-estimator__option-title",children:"Aggregates"}),(0,X.jsx)("div",{className:"truss-estimator__option-copy",children:"MOT Type 1, sharp sand or 20mm gravel"})]})]})]}),m==="aggregate"&&(0,X.jsxs)("div",{className:"materials-calculator__section",children:[(0,X.jsx)("div",{className:"truss-estimator__section-heading",children:"Aggregate type"}),(0,X.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.keys(On).map(se=>(0,X.jsxs)("button",{type:"button",className:`truss-estimator__option-card${y===se?" is-selected":""}`,onClick:()=>T(se),children:[(0,X.jsx)("div",{className:"truss-estimator__option-title",children:On[se].label}),(0,X.jsx)("div",{className:"truss-estimator__option-copy",children:On[se].blurb})]},se))})]}),(0,X.jsxs)("div",{className:"materials-calculator__section",children:[(0,X.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and depth"}),(0,X.jsxs)("div",{className:"materials-calculator__unit-row",children:[(0,X.jsx)("span",{children:"Units"}),(0,X.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,X.jsx)("button",{type:"button",className:i==="m"?"is-selected":"",onClick:()=>n("m"),children:"Metric"}),(0,X.jsx)("button",{type:"button",className:i==="ft"?"is-selected":"",onClick:()=>n("ft"),children:"Imperial"})]})]}),(0,X.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,X.jsxs)("label",{className:"truss-estimator__field",children:[(0,X.jsxs)("span",{children:["Length (",i,")"]}),(0,X.jsx)("input",{type:"number",min:"0",step:"0.01",value:o,onChange:se=>l(se.target.value)})]}),(0,X.jsxs)("label",{className:"truss-estimator__field",children:[(0,X.jsxs)("span",{children:["Width (",i,")"]}),(0,X.jsx)("input",{type:"number",min:"0",step:"0.01",value:c,onChange:se=>p(se.target.value)})]})]}),(0,X.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,X.jsxs)("span",{children:["Depth (",i==="m"?"cm":"inches",")"]}),(0,X.jsx)("input",{type:"number",min:"0",step:"0.1",value:d,onChange:se=>g(se.target.value)})]})]}),(0,X.jsxs)("div",{className:"materials-calculator__totals",children:[(0,X.jsx)("div",{className:"truss-estimator__section-heading",children:"Materials required"}),(0,X.jsx)("div",{className:"materials-calculator__result-grid",children:m==="concrete"?(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)("div",{children:[(0,X.jsx)("span",{children:"Cement"}),(0,X.jsxs)("strong",{children:[A.toFixed(0)," kg"]})]}),(0,X.jsxs)("div",{children:[(0,X.jsx)("span",{children:"Sharp sand"}),(0,X.jsxs)("strong",{children:[Q.toFixed(2)," m\xB3"]})]}),(0,X.jsxs)("div",{children:[(0,X.jsx)("span",{children:"20mm aggregate"}),(0,X.jsxs)("strong",{children:[K.toFixed(2)," m\xB3"]})]})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)("div",{children:[(0,X.jsx)("span",{children:R.label}),(0,X.jsxs)("strong",{children:[S.toFixed(2)," m\xB3"]})]}),(0,X.jsxs)("div",{children:[(0,X.jsx)("span",{children:"Approx. weight"}),(0,X.jsxs)("strong",{children:[(S*R.density).toFixed(2)," t"]})]}),(0,X.jsx)("div",{})]})}),(0,X.jsx)("p",{className:"materials-calculator__note",children:m==="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,X.jsx)("p",{className:"results-empty-hint estimator-products__error",children:u}),(0,X.jsxs)("div",{className:"materials-calculator__actions",children:[(0,X.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,X.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:ve,disabled:S<=0||D,children:D?"Adding products\u2026":a})]})]})]})})}var Ya=G(Xe());var U=G(ee()),Bn=12,Ln=8,ic=.56,Sv=.21,Ra={ranges:{meridian:{label:"Standard grooved timber",blurb:"32 \xD7 125mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.125},summit:{label:"Wide grooved timber",blurb:"32 \xD7 150mm pressure-treated softwood boards.",boardLengthM:3.6,boardWidthM:.15}},boardGapM:.006,wastage:{straight:.05,diagonal:.15},pictureFrame:{extraWastage:.08},joist:{spacingOptions:[{id:"300",label:"300mm centres (heavy duty)",spacingM:.3},{id:"400",label:"400mm centres (standard)",spacingM:.4},{id:"450",label:"450mm centres (light use)",spacingM:.45}]}},Ni=["range","grid","pictureFrame","substructure"],$_={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:""}},nc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),oc=(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),Z_=(e,t,a,r)=>{let i=nc(e,t,a),n=nc(e,t,r),o=nc(a,r,e),l=nc(a,r,t);return i===0&&oc(e,t,a)||n===0&&oc(e,t,r)||o===0&&oc(a,r,e)||l===0&&oc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},Od=(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)&&Z_(e[r],i,e[n],e[(n+1)%e.length]))return!0}return!1};function Bd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ya.useState)(0),[n,o]=(0,Ya.useState)($_),[l,c]=(0,Ya.useState)(1),[p,d]=(0,Ya.useState)({x:0,y:0}),[g,m]=(0,Ya.useState)(null),b=(0,Ya.useRef)(null),y=(0,Ya.useRef)(null),T=(0,Ya.useRef)(null),D=Ni[r],f=n.range?Ra.ranges[n.range]:null,u=Bn/l,w=Ln/l,v=(Bn-u)/2,S=(Ln-w)/2,R=Math.max(-Bn,Math.min(Bn*2-u,v+p.x)),z=Math.max(-Ln,Math.min(Ln*2-w,S+p.y)),A=Number.parseFloat(n.quickLengthM),Q=Number.parseFloat(n.quickWidthM),K=A>0&&Q>0,fe=E=>Math.abs(E.reduce((O,re,ce)=>{let ge=E[(ce+1)%E.length];return O+re.x*ge.y-ge.x*re.y},0))/2,Ue=(E,O)=>Math.hypot(O.x-E.x,O.y-E.y),Be=n.isOutlineClosed?fe(n.points):0,Ye=n.isOutlineClosed?n.points.reduce((E,O,re)=>E+Ue(O,n.points[(re+1)%n.points.length]),0):0,Ne=n.isOutlineClosed?n.points.reduce((E,O,re)=>E+(n.wallSegments.has(re)?0:Ue(O,n.points[(re+1)%n.points.length])),0):0,ve=n.points.reduce((E,O)=>({x:E.x+O.x/n.points.length,y:E.y+O.y/n.points.length}),{x:0,y:0}),oe=n.points.length>1?(()=>{let E=n.points[0],O=n.points[1],re=Ue(E,O),ce=re?-(O.y-E.y)/re:0,ge=re?(O.x-E.x)/re:0,Ae=(E.x+O.x)/2,Pe=(E.y+O.y)/2,h=ce*(Ae-ve.x)+ge*(Pe-ve.y)>=0?1:-1;return{x:Ae+ce*ic*h,y:Pe+ge*ic*h}})():null,ye=(()=>{let E=n.range?Ra.ranges[n.range]:Ra.ranges.meridian,O=n.deckSizeMode==="quick"?A*Q:Be,re=n.deckSizeMode==="quick"?2*(A+Q):Ne,ce=n.direction==="diagonal"?Ra.wastage.diagonal:Ra.wastage.straight,ge=n.pictureFrame==="yes"?Ra.pictureFrame.extraWastage:0,Pe=O/(E.boardWidthM+Ra.boardGapM)/E.boardLengthM,h=Math.ceil(Pe*(1+ce+ge)),M=Math.ceil(O*30*(1+ce+ge)/200),N=Ra.joist.spacingOptions.find(k=>k.id===n.joistSpacing)??Ra.joist.spacingOptions[1],Y=O/N.spacingM,Z=Math.ceil(Y);return{range:E,area:O,boardCount:h,screwBoxes:M,joistMetres:Z,spacing:N}})(),wt=ye?[{key:`boards-${n.range??"meridian"}`,label:`Deck boards (${ye.range.label})`,qty:ye.boardCount,unit:"each",query:"timber decking board",category:"decking",calculatorWasteIncluded:!0},{key:"joists",label:"Treated C24 joists",qty:ye.joistMetres,unit:"m",query:"treated joist",category:"timber",calculatorWasteIncluded:!0},{key:"screws",label:"Green decking screws (200/box)",qty:ye.screwBoxes,unit:"box",query:"green decking screws",category:"fixings",calculatorWasteIncluded:!0}]:[],Ee=()=>D==="range"?!!n.range:D==="grid"?n.deckSizeMode==="quick"?K:n.isOutlineClosed&&Be>0:D==="pictureFrame"?!!n.pictureFrame&&!!n.direction:D==="substructure"?!!n.joistSpacing:!0,$=r===Ni.length-1?a:"Next",ue=(E,O,re=!1)=>{let ce=T.current?.getBoundingClientRect();if(!ce)return null;let ge=re?1:.25;return{x:Math.round(Math.max(R,Math.min(R+u,R+(E-ce.left)/ce.width*u))/ge)*ge,y:Math.round(Math.max(z,Math.min(z+w,z+(O-ce.top)/ce.height*w))/ge)*ge}},Ze=E=>{if(n.isOutlineClosed){let re=E.target;if(re!==E.currentTarget&&!re.classList.contains("deck-outline__grid"))return;y.current={startX:E.clientX,startY:E.clientY,startViewX:R,startViewY:z},E.currentTarget.setPointerCapture(E.pointerId);return}if(n.drawMode!=="outline")return;let O=ue(E.clientX,E.clientY,!0);O&&(m(null),o(re=>{let ce=[...re.points,O];return Od(ce,!1)?{...re,drawError:"Edges cannot cross. Choose another corner."}:{...re,points:ce,drawError:""}}))},pt=(E,O)=>{if(!n.isOutlineClosed){E.stopPropagation(),O===0&&n.points.length>=3&&o(re=>({...re,isOutlineClosed:!0,drawMode:"edges"}));return}E.stopPropagation(),b.current=O,E.currentTarget.setPointerCapture(E.pointerId)},vt=E=>{if(y.current){let ce=T.current?.getBoundingClientRect();if(!ce)return;let ge=y.current,Ae=ge.startViewX-(E.clientX-ge.startX)/ce.width*u,Pe=ge.startViewY-(E.clientY-ge.startY)/ce.height*w;d({x:Ae-v,y:Pe-S});return}!n.isOutlineClosed&&n.drawMode==="outline"&&m(ue(E.clientX,E.clientY,!0));let O=b.current;if(O===null)return;let re=ue(E.clientX,E.clientY);re&&o(ce=>{let ge=ce.points.map((Ae,Pe)=>Pe===O?re:Ae);return Od(ge,!0)?{...ce,drawError:"Edges cannot cross. Move the corner to a different position."}:{...ce,points:ge,drawError:""}})},He=E=>{y.current=null,b.current=null,E.currentTarget.hasPointerCapture(E.pointerId)&&E.currentTarget.releasePointerCapture(E.pointerId)},de=E=>{o(O=>{let re=new Set(O.wallSegments);return re.has(E)?re.delete(E):re.add(E),{...O,wallSegments:re}})},_e=()=>{r===0?e():i(E=>E-1)},Se=()=>{Ee()&&(r===Ni.length-1?t?.(wt):i(E=>E+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(Ra.ranges).map(([E,O])=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===E?" is-selected":""}`,onClick:()=>o(re=>({...re,range:E})),children:[(0,U.jsx)("div",{className:"truss-estimator__option-title",children:O.label}),(0,U.jsx)("div",{className:"truss-estimator__option-copy",children:O.blurb}),(0,U.jsxs)("div",{className:"truss-estimator__option-copy",children:[O.boardLengthM,"m boards"]})]},E))})]}):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(E=>({...E,deckSizeMode:"quick"})),children:"Quick estimate"}),(0,U.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.deckSizeMode==="draw"?" is-selected":""}`,onClick:()=>o(E=>({...E,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:E=>o(O=>({...O,quickLengthM:E.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:E=>o(O=>({...O,quickWidthM:E.target.value}))})]})]}),(0,U.jsx)("div",{className:"truss-estimator__grid-hint",children:"For L-shaped decks, cut-outs, or sides against a wall, use Draw your space."}),K?(0,U.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,U.jsxs)("div",{children:[(A*Q).toFixed(2)," m\xB2 deck"]}),(0,U.jsxs)("div",{children:[(2*(A+Q)).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:[Be.toFixed(2)," m\xB2"]})]}),(0,U.jsxs)("div",{children:[(0,U.jsx)("span",{children:"Perimeter"}),(0,U.jsxs)("strong",{children:[Ye.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:[Ne.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(E=>({...E,points:E.points.slice(0,-1)})),disabled:n.points.length===0||n.isOutlineClosed,children:"Undo"}),(0,U.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{m(null),o(E=>({...E,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(E=>({...E,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:T,className:`deck-outline__canvas${n.isOutlineClosed?" is-pan-mode":""}`,viewBox:`${R} ${z} ${u} ${w}`,preserveAspectRatio:"none","aria-label":"Deck outline drawing area",onPointerDown:Ze,onPointerMove:vt,onPointerUp:He,onPointerLeave:()=>{m(null),y.current||(b.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:-Bn,y:-Ln,width:Bn*3,height:Ln*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(E=>`${E.x},${E.y}`).join(" ")}):null,n.isOutlineClosed?(0,U.jsx)("polygon",{className:"deck-outline__shape",points:n.points.map(E=>`${E.x},${E.y}`).join(" "),stroke:"none"}):null,n.points.length>1?n.points.slice(0,n.isOutlineClosed?void 0:-1).map((E,O)=>{let re=n.points[n.isOutlineClosed?(O+1)%n.points.length:O+1],ce=Ue(E,re),ge=ce?-(re.y-E.y)/ce:0,Ae=ce?(re.x-E.x)/ce:0,Pe=(E.x+re.x)/2,h=(E.y+re.y)/2,M=ge*(Pe-ve.x)+Ae*(h-ve.y)>=0?1:-1,N=Pe+ge*ic*M,Y=h+Ae*ic*M;return(0,U.jsxs)("g",{children:[(0,U.jsx)("line",{className:"deck-outline__edge-hit",x1:E.x,y1:E.y,x2:re.x,y2:re.y,onClick:n.isOutlineClosed?()=>de(O):void 0}),(0,U.jsx)("line",{className:`deck-outline__edge${n.wallSegments.has(O)?" is-wall":""}`,x1:E.x,y1:E.y,x2:re.x,y2:re.y,pointerEvents:"none"}),(0,U.jsxs)("text",{className:`deck-outline__edge-label${n.wallSegments.has(O)?" is-wall":""}`,x:N,y:Y,textAnchor:"middle",dominantBaseline:"central",fontSize:Sv/l,children:[ce.toFixed(2)," m"]})]},`segment-${O}`)}):null,!n.isOutlineClosed&&n.points.length>0&&g?(()=>{let E=n.points[n.points.length-1],O=Ue(E,g);if(!O)return null;let re=-(g.y-E.y)/O,ce=(g.x-E.x)/O,ge=(E.x+g.x)/2,Ae=(E.y+g.y)/2;return(0,U.jsxs)("g",{className:"deck-outline__live-measurement",children:[(0,U.jsx)("line",{x1:E.x,y1:E.y,x2:g.x,y2:g.y}),(0,U.jsxs)("text",{x:ge+re*.34,y:Ae+ce*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:Sv/l,children:[O.toFixed(2)," m"]})]})})():null,n.points.map((E,O)=>(0,U.jsx)("circle",{className:"deck-outline__point",cx:E.x,cy:E.y,r:"0.13",onPointerDown:re=>pt(re,O)},`point-${O}`))]}),(0,U.jsxs)("div",{className:"deck-outline__zoom","aria-label":"Zoom controls",children:[(0,U.jsx)("button",{type:"button",onClick:()=>c(E=>Math.max(.5,E-.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(E=>Math.min(1,E+.25)),disabled:l===1,"aria-label":"Zoom in",children:"+"})]}),n.isOutlineClosed&&n.wallSegments.size===0&&oe?(0,U.jsx)("div",{className:"deck-outline__edge-prompt",role:"status",style:{left:`${(oe.x-R)/u*100}%`,top:`${(oe.y-z)/w*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(E=>Od(E.points,!0)?{...E,drawError:"Edges cannot cross. Adjust the outline before finishing."}:{...E,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(E=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.pictureFrame===E.id?" is-selected":""}`,onClick:()=>o(O=>({...O,pictureFrame:E.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:It(E.img),alt:""}),(0,U.jsx)("span",{children:E.label})]},E.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(E=>(0,U.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.direction===E.id?" is-selected":""}`,onClick:()=>o(O=>({...O,direction:E.id})),children:[(0,U.jsx)("img",{className:"truss-estimator__visual-card-img",src:It(E.img),alt:""}),(0,U.jsx)("span",{children:E.label})]},E.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:Ra.joist.spacingOptions.map(E=>(0,U.jsx)("button",{type:"button",className:`truss-estimator__option-card${n.joistSpacing===E.id?" is-selected":""}`,onClick:()=>o(O=>({...O,joistSpacing:E.id})),children:(0,U.jsx)("div",{className:"truss-estimator__option-title",children:E.label})},E.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:_e,children:"Back"}),(0,U.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:Se,disabled:!Ee(),children:[(0,U.jsx)("span",{children:$}),(0,U.jsx)("span",{className:"arrow",children:(0,U.jsx)(Qt,{})})]})]})]})]})})}var Ea=G(Xe());var j=G(ee()),Cv=12,qv=30,Hn=12,jn=8,Ev=.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"],K_={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:""}},lc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),sc=(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),P_=(e,t,a,r)=>{let i=lc(e,t,a),n=lc(e,t,r),o=lc(a,r,e),l=lc(a,r,t);return i===0&&sc(e,t,a)||n===0&&sc(e,t,r)||o===0&&sc(a,r,e)||l===0&&sc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},cc=(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)&&P_(e[r],e[(r+1)%e.length],e[i],e[(i+1)%e.length]))return!0;return!1};function Ld({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ea.useState)(0),[n,o]=(0,Ea.useState)(K_),l=(0,Ea.useRef)(null),c=(0,Ea.useRef)(null),[p,d]=(0,Ea.useState)(1),[g,m]=(0,Ea.useState)({x:0,y:0}),[b,y]=(0,Ea.useState)(null),T=(0,Ea.useRef)(null),D=(0,Ea.useRef)(null),f=(0,Ea.useRef)(null),u=Si[r],w=n.range?qa.ranges[n.range]:null,v=Hn/p,S=jn/p,R=(Hn-v)/2,z=(jn-S)/2,A=Math.max(-Hn,Math.min(Hn*2-v,R+g.x)),Q=Math.max(-jn,Math.min(jn*2-S,z+g.y)),K=n.boundaryPoints.reduce((h,M)=>({x:h.x+M.x/Math.max(1,n.boundaryPoints.length),y:h.y+M.y/Math.max(1,n.boundaryPoints.length)}),{x:0,y:0}),fe=h=>{let M=new Set,N=[];return h.forEach(Y=>{let[Z,k]=Y.split(",").map(Number),L=[{key:`H,${Z},${k}`,type:"H",x:Z,y:k},{key:`H,${Z},${k+1}`,type:"H",x:Z,y:k+1},{key:`V,${Z},${k}`,type:"V",x:Z,y:k},{key:`V,${Z+1},${k}`,type:"V",x:Z+1,y:k}],P=[!h.has(`${Z},${k-1}`),!h.has(`${Z},${k+1}`),!h.has(`${Z-1},${k}`),!h.has(`${Z+1},${k}`)];L.forEach((pe,xe)=>{P[xe]&&!M.has(pe.key)&&(M.add(pe.key),N.push(pe))})}),N},Ue=(h,M)=>fe(h).filter(N=>!M.has(N.key)),Be=(h,M)=>Ue(h,M).length,Ye=(h,M)=>{let N={};Ue(h,M).forEach(Z=>{var k,L,P,pe;Z.type==="H"?((N[k=`${Z.x},${Z.y}`]||(N[k]=[])).push("H"),(N[L=`${Z.x+1},${Z.y}`]||(N[L]=[])).push("H")):((N[P=`${Z.x},${Z.y}`]||(N[P]=[])).push("V"),(N[pe=`${Z.x},${Z.y+1}`]||(N[pe]=[])).push("V"))});let Y=0;return Object.values(N).forEach(Z=>{(Z.length===1||Z.length===2&&Z[0]!==Z[1]||Z.length>=3)&&(Y+=1)}),Y},ve=(()=>{let h=n.range?qa.ranges[n.range]:qa.ranges.boundary,M=n.height??"1.8",N=n.boundaryMode==="quick"?Math.max(0,Number.parseFloat(n.quickLengthM)||0):n.boundaryClosed?n.boundaryPoints.slice(0,-1).reduce((Yt,br,kt)=>Yt+(n.excludedBoundaryEdges.has(kt)?0:Math.hypot(n.boundaryPoints[kt+1].x-br.x,n.boundaryPoints[kt+1].y-br.y)),0):0,Y=n.gateType&&n.gateType!=="none"?Number.parseFloat(n.gateWidthM)||qa.gate[n.gateType].widthDefault:0,Z=Math.max(0,N-Y),k=Z>0?Math.ceil(Z/h.panelWidthM):0,L=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,P=n.boundaryMode==="quick"?Z>0?2:0:n.boundaryClosed?n.boundaryPoints.slice(0,L?-1:void 0).reduce((Yt,br,kt)=>{let qi=kt>0&&!n.excludedBoundaryEdges.has(kt-1),am=kt<n.boundaryPoints.length-1&&!n.excludedBoundaryEdges.has(kt);return Yt+(qi||am?1:0)},0):0,pe=Z>0?Math.ceil(Z/h.panelWidthM)+1:0,xe=Math.max(0,pe-P),xt=n.mountingType?qa.mounting[n.mountingType]:qa.mounting.concrete,it=n.gateType&&n.gateType!=="none"?2:0,Et=xe+P+it,tm=n.mountingType==="postcrete"?Et*qa.mounting.postcrete.bagsPerPost:0,Ir=n.gravelBoard==="yes"?k:0;return{range:h,height:M,totalEdgeM:N,fencedLengthM:Z,gateWidthM:Y,panelsCount:k,cornerPostCount:P,intermediatePostCount:xe,gatePostCount:it,totalPostCount:Et,bagsCount:tm,gravelCount:Ir,capCount:Et,mounting:xt}})(),oe=n.gateType&&n.gateType!=="none"?qa.gate[n.gateType].label:null,se=Number(ve.height)<=1.2?"6":"8",ye=ve?[{key:`panels-${n.range??"boundary"}-${ve.height}`,label:`${ve.range.label} panels (${ve.height}m)`,qty:ve.panelsCount,unit:"each",query:"fence panel",category:"fencing"},...n.mountingType==="concrete"?[{key:`concrete-intermediate-${se}`,label:"Intermediate concrete posts",qty:ve.intermediatePostCount,unit:"each",query:"concrete fence post",category:"fencing"},{key:`concrete-end-${se}`,label:"End and corner concrete posts",qty:ve.cornerPostCount+ve.gatePostCount,unit:"each",query:"concrete end post",category:"fencing"}]:[{key:`timber-post-${se}`,label:"Timber fence posts",qty:ve.totalPostCount,unit:"each",query:"timber fence post",category:"fencing"},{key:"postcrete",label:"Postcrete",qty:ve.bagsCount,unit:"bag",query:"postcrete",category:"cement"}],...oe?[{key:"gate",label:oe,qty:1,unit:"each",query:"lap gate",category:"fencing"}]:[],...ve.gravelCount>0?[{key:"gravel-boards",label:"Concrete gravel boards",qty:ve.gravelCount,unit:"each",query:"gravel board",category:"fencing"}]:[]]:[],wt=()=>{if(u==="range"){let h=n.boundaryMode==="quick"?(Number.parseFloat(n.quickLengthM)||0)>0:n.boundaryClosed&&n.boundaryPoints.length>=2;return!!n.range&&h}return u==="height"?!!n.height&&!!n.gravelBoard:u==="gate"?!!n.gateType&&(n.gateType==="none"||n.gateWidthM.trim()!==""):u==="posts"?!!n.mountingType:!0},Ee=r===Si.length-1?a:"Next",$=h=>{o(M=>{let N=h(new Set(M.grid)),Y=new Set([...M.excludedEdges].filter(Z=>fe(N).some(k=>k.key===Z)));return{...M,grid:N,excludedEdges:Y}})},ue=(h,M,N)=>{$(Y=>{let Z=`${h},${M}`;return N?Y.add(Z):Y.delete(Z),Y})},Ze=(h,M,N,Y,Z)=>{let k=h,L=M,P=Math.abs(N-h),pe=h<N?1:-1,xe=-Math.abs(Y-M),xt=M<Y?1:-1,it=P+xe;for(;ue(k,L,Z),!(k===N&&L===Y);){let Et=2*it;Et>=xe&&(it+=xe,k+=pe),Et<=P&&(it+=P,L+=xt)}},pt=(h,M)=>{let N=c.current?.getBoundingClientRect();if(!N)return null;let Y=Math.floor((h-N.left)/qv),Z=Math.floor((M-N.top)/qv);return Y<0||Z<0||Y>=Cv||Z>=Cv?null:{x:Y,y:Z}},vt=h=>{if(n.gridMode!=="draw")return;let M=pt(h.clientX,h.clientY);if(!M)return;h.preventDefault();let N=`${M.x},${M.y}`,Y=!n.grid.has(N);l.current={active:!0,paintValue:Y,lastX:M.x,lastY:M.y},h.currentTarget.setPointerCapture(h.pointerId),ue(M.x,M.y,Y)},He=h=>{let M=l.current;if(!M?.active)return;let N=pt(h.clientX,h.clientY);N&&(N.x===M.lastX&&N.y===M.lastY||(Ze(M.lastX,M.lastY,N.x,N.y,M.paintValue),l.current={...M,lastX:N.x,lastY:N.y}))},de=h=>{l.current?.active&&(l.current=null,h.currentTarget.releasePointerCapture(h.pointerId))},_e=(h,M,N=!1)=>{let Y=f.current?.getBoundingClientRect();if(!Y)return null;let Z=N?1:.25;return{x:Math.round(Math.max(A,Math.min(A+v,A+(h-Y.left)/Y.width*v))/Z)*Z,y:Math.round(Math.max(Q,Math.min(Q+S,Q+(M-Y.top)/Y.height*S))/Z)*Z}},Se=h=>{if(n.boundaryClosed){let N=h.target;if(N!==h.currentTarget&&!N.classList.contains("fence-boundary__grid"))return;D.current={startX:h.clientX,startY:h.clientY,startViewX:A,startViewY:Q},h.currentTarget.setPointerCapture(h.pointerId);return}let M=_e(h.clientX,h.clientY,!0);M&&(y(null),o(N=>{let Y=[...N.boundaryPoints,M];return cc(Y,!1)?{...N}:{...N,boundaryPoints:Y}}))},E=(h,M)=>{if(h.stopPropagation(),!n.boundaryClosed){if(M!==0||n.boundaryPoints.length<3)return;o(N=>cc(N.boundaryPoints,!0)?N:{...N,boundaryPoints:[...N.boundaryPoints,N.boundaryPoints[0]],boundaryClosed:!0});return}T.current=M,h.currentTarget.setPointerCapture(h.pointerId)},O=h=>{if(D.current){let N=f.current?.getBoundingClientRect();if(!N)return;let Y=D.current,Z=Y.startViewX-(h.clientX-Y.startX)/N.width*v,k=Y.startViewY-(h.clientY-Y.startY)/N.height*S;m({x:Z-R,y:k-z});return}if(n.boundaryClosed||y(_e(h.clientX,h.clientY,!0)),T.current===null)return;let M=_e(h.clientX,h.clientY);M&&o(N=>{let 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,Z=N.boundaryPoints.map((k,L)=>{let P=L===T.current,pe=Y&&T.current===0&&L===N.boundaryPoints.length-1;return P||pe?M:k});return cc(Z,!1)?N:{...N,boundaryPoints:Z}})},re=h=>{D.current=null,T.current=null,h.currentTarget.hasPointerCapture(h.pointerId)&&h.currentTarget.releasePointerCapture(h.pointerId)},ce=h=>{o(M=>{let N=new Set(M.excludedBoundaryEdges);return N.has(h)?N.delete(h):N.add(h),{...M,excludedBoundaryEdges:N}})},ge=()=>{r===0?e():i(h=>h-1)},Ae=()=>{wt()&&(r===Si.length-1?t?.(ye):i(h=>h+1))},Pe=fe(n.grid);return(0,j.jsx)(j.Fragment,{children:(0,j.jsxs)("div",{className:"truss-estimator",children:[(0,j.jsxs)("div",{className:"quick-order-hero",children:[(0,j.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,j.jsx)("h1",{children:"Fencing Calculator"}),(0,j.jsx)("p",{children:"Estimate panels, posts and cost for your fence line in a few steps."})]}),(0,j.jsxs)("div",{className:"truss-estimator__card",children:[(0,j.jsxs)("div",{className:"truss-estimator__body",children:[u==="range"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your fence panels"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"The calculator uses fixed, orderable timber panels from the catalogue."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(qa.ranges).map(([h,M])=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===h?" is-selected":""}`,onClick:()=>o(N=>({...N,range:h})),children:[(0,j.jsx)("div",{className:"truss-estimator__option-title",children:M.label}),(0,j.jsx)("div",{className:"truss-estimator__option-copy",children:M.blurb})]},h))})]}):null,u==="range"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("div",{className:"truss-estimator__section-heading",children:"Measure your fence line"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"Use a quick total, or draw the boundary to mark existing edges that do not need new fencing."}),(0,j.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,j.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="quick"?" is-selected":""}`,onClick:()=>o(h=>({...h,boundaryMode:"quick"})),children:"Quick estimate"}),(0,j.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="draw"?" is-selected":""}`,onClick:()=>o(h=>({...h,boundaryMode:"draw"})),children:"Draw your boundary"})]}),n.boundaryMode==="quick"?(0,j.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact fence-boundary__quick-field",children:[(0,j.jsx)("span",{children:"Total fence length (m)"}),(0,j.jsx)("input",{type:"number",min:"0",step:"0.1",value:n.quickLengthM,onChange:h=>o(M=>({...M,quickLengthM:h.target.value}))})]}):(0,j.jsxs)(j.Fragment,{children:[(0,j.jsx)("div",{className:"fence-boundary__toolbar",children:(0,j.jsxs)("div",{className:"fence-boundary__actions",children:[(0,j.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(h=>({...h,boundaryPoints:h.boundaryPoints.slice(0,-1),boundaryClosed:!1,excludedBoundaryEdges:new Set})),disabled:n.boundaryPoints.length===0||n.boundaryClosed,children:"Undo"}),(0,j.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{m({x:0,y:0}),y(null),o(h=>({...h,boundaryPoints:[],boundaryClosed:!1,excludedBoundaryEdges:new Set}))},disabled:n.boundaryPoints.length===0,children:"Clear"}),(0,j.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(h=>({...h,boundaryPoints:[{x:2,y:2},{x:8,y:2},{x:8,y:5},{x:2,y:5},{x:2,y:2}],boundaryClosed:!0,excludedBoundaryEdges:new Set})),children:"Start with rectangle"})]})}),(0,j.jsxs)("div",{className:"fence-boundary",children:[(0,j.jsxs)("svg",{ref:f,className:`fence-boundary__canvas${n.boundaryClosed?" is-pan-mode":""}`,viewBox:`${A} ${Q} ${v} ${S}`,preserveAspectRatio:"none","aria-label":"Fence boundary drawing area",onPointerDown:Se,onPointerMove:O,onPointerUp:re,onPointerLeave:()=>{y(null),D.current||(T.current=null)},children:[(0,j.jsx)("defs",{children:(0,j.jsx)("pattern",{id:"fence-boundary-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,j.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,j.jsx)("rect",{x:-Hn,y:-jn,width:Hn*3,height:jn*3,className:"fence-boundary__grid",fill:"url(#fence-boundary-grid)"}),n.boundaryPoints.length>1?(0,j.jsx)("polyline",{className:"fence-boundary__preview",points:n.boundaryPoints.map(h=>`${h.x},${h.y}`).join(" ")}):null,n.boundaryPoints.length>1?n.boundaryPoints.slice(0,-1).map((h,M)=>{let N=n.boundaryPoints[M+1],Y=Math.hypot(N.x-h.x,N.y-h.y),Z=Y?-(N.y-h.y)/Y:0,k=Y?(N.x-h.x)/Y:0,L=(h.x+N.x)/2,P=(h.y+N.y)/2,pe=Z*(L-K.x)+k*(P-K.y)>=0?1:-1,xe=L+Z*Ev*pe,xt=P+k*Ev*pe;return(0,j.jsxs)("g",{children:[(0,j.jsx)("line",{className:"fence-boundary__edge-hit",x1:h.x,y1:h.y,x2:N.x,y2:N.y,onClick:n.boundaryClosed?()=>ce(M):void 0}),(0,j.jsx)("line",{className:`fence-boundary__edge${n.excludedBoundaryEdges.has(M)?" is-excluded":""}`,x1:h.x,y1:h.y,x2:N.x,y2:N.y,pointerEvents:"none"}),(0,j.jsxs)("text",{className:`fence-boundary__edge-label${n.excludedBoundaryEdges.has(M)?" is-excluded":""}`,x:xe,y:xt,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[Y.toFixed(2)," m"]})]},`fence-edge-${M}`)}):null,!n.boundaryClosed&&n.boundaryPoints.length>0&&b?(()=>{let h=n.boundaryPoints[n.boundaryPoints.length-1],M=Math.hypot(b.x-h.x,b.y-h.y);if(!M)return null;let N=-(b.y-h.y)/M,Y=(b.x-h.x)/M,Z=(h.x+b.x)/2,k=(h.y+b.y)/2;return(0,j.jsxs)("g",{className:"fence-boundary__live-measurement",children:[(0,j.jsx)("line",{x1:h.x,y1:h.y,x2:b.x,y2:b.y}),(0,j.jsxs)("text",{x:Z+N*.34,y:k+Y*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[M.toFixed(2)," m"]})]})})():null,n.boundaryPoints.map((h,M)=>M>0&&M===n.boundaryPoints.length-1&&h.x===n.boundaryPoints[0]?.x&&h.y===n.boundaryPoints[0]?.y?null:(0,j.jsx)("circle",{className:`fence-boundary__point${!n.boundaryClosed&&M===0&&n.boundaryPoints.length>=3?" is-close-target":""}`,cx:h.x,cy:h.y,r:"0.13",onPointerDown:N=>E(N,M)},`fence-point-${M}`))]}),(0,j.jsxs)("div",{className:"fence-boundary__zoom","aria-label":"Zoom controls",children:[(0,j.jsx)("button",{type:"button",onClick:()=>d(h=>Math.max(.5,h-.25)),disabled:p===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,j.jsxs)("span",{children:[Math.round(p*100),"%"]}),(0,j.jsx)("button",{type:"button",onClick:()=>d(h=>Math.min(1,h+.25)),disabled:p===1,"aria-label":"Zoom in",children:"+"})]}),!n.boundaryClosed&&n.boundaryPoints.length>=2?(0,j.jsx)("button",{type:"button",className:"fence-boundary__close",onClick:()=>o(h=>cc(h.boundaryPoints,!1)?h:{...h,boundaryClosed:!0}),children:"Finish fence line"}):null]}),(0,j.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,j.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,j.jsx)("div",{children:n.boundaryMode==="quick"?`${(Number.parseFloat(n.quickLengthM)||0).toFixed(2)} m fence line`:`${ve.totalEdgeM.toFixed(2)} m fence line`}),n.boundaryMode==="draw"&&n.boundaryClosed?(0,j.jsxs)("div",{children:[ve.cornerPostCount," corner/end posts"]}):null]})]}):null,null,u==="height"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Fence height"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"Select the nearest available panel height."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:qa.heights.map(h=>(0,j.jsx)("button",{type:"button",className:`truss-estimator__visual-card${n.height===h?" is-selected":""}`,onClick:()=>o(M=>({...M,height:h})),children:(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--tall",src:It(`/fencing/height/${h}.webp`),alt:""})},h))}),(0,j.jsx)("div",{className:"truss-estimator__section-heading",children:"Gravel board?"}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"no",label:"No gravel board",img:"/fencing/no-gravel-board.webp"},{id:"yes",label:"Add gravel board",img:"/fencing/gravel-board.webp"}].map(h=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.gravelBoard===h.id?" is-selected":""}`,onClick:()=>o(M=>({...M,gravelBoard:h.id})),children:[(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:It(h.img),alt:""}),(0,j.jsx)("span",{children:h.label})]},h.id))})]}):null,u==="gate"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Do you need a gate?"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"A gate opening replaces part of the panel run and adds a gate kit with heavy-duty posts."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[{id:"none",label:"No gate",img:"/fencing/gates/no-gate.webp"},{id:"single",label:"Single gate",img:"/fencing/gates/single-gate.webp"}].map(h=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${n.gateType===h.id?" is-selected":""}`,onClick:()=>o(M=>({...M,gateType:h.id,gateWidthM:h.id==="none"?"":String(qa.gate[h.id].widthDefault)})),children:[(0,j.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:It(h.img),alt:""}),(0,j.jsx)("span",{children:h.label})]},h.id))}),n.gateType&&n.gateType!=="none"?(0,j.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,j.jsx)("span",{children:"Gate width (m)"}),(0,j.jsx)("input",{type:"text",inputMode:"decimal",value:n.gateWidthM,onChange:h=>o(M=>({...M,gateWidthM:h.target.value}))})]}):null]}):null,u==="posts"?(0,j.jsxs)(j.Fragment,{children:[(0,j.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,j.jsx)("h2",{className:"truss-estimator__step-title",children:"Posts and fixing type"}),(0,j.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose how the posts will be set."}),(0,j.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(qa.mounting).map(([h,M])=>(0,j.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.mountingType===h?" is-selected":""}`,onClick:()=>o(N=>({...N,mountingType:h})),children:[(0,j.jsx)("div",{className:"truss-estimator__option-title",children:M.label}),(0,j.jsx)("div",{className:"truss-estimator__option-copy",children:M.blurb})]},h))})]}):null]}),(0,j.jsxs)("div",{className:"truss-estimator__nav",children:[(0,j.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:ge,children:"Back"}),(0,j.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:Ae,disabled:!wt(),children:[(0,j.jsx)("span",{children:Ee}),(0,j.jsx)("span",{className:"arrow",children:(0,j.jsx)(Qt,{})})]})]})]})]})})}var uc=G(Xe()),we=G(ee()),Mv={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",byArea:!0},loft:{label:"Loft",product:"Knauf Loft Roll 44",thickness:"100mm",coverage:13.89,salesUnit:"roll",byArea:!0}};function Hd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,uc.useState)("floor"),[n,o]=(0,uc.useState)(""),[l,c]=(0,uc.useState)(""),p=Number.parseFloat(n)*Number.parseFloat(l)||0,d=Mv[r],g=Math.ceil(p/d.coverage),m=[{key:`insulation-${r}`,label:`${d.product} ${d.thickness}`,qty:d.byArea?Math.round(p*100)/100:g,unit:d.byArea?"m2":d.salesUnit,query:d.product,category:"insulation"}],b=Object.entries(Mv);return(0,we.jsx)(we.Fragment,{children:(0,we.jsxs)("div",{className:"truss-estimator",children:[(0,we.jsxs)("div",{className:"quick-order-hero",children:[(0,we.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,we.jsx)("h1",{children:"Insulation Calculator"}),(0,we.jsx)("p",{children:"Estimate insulation coverage and pack quantities for floors, walls, roofs and lofts."})]}),(0,we.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,we.jsx)("h2",{className:"truss-estimator__step-title",children:"Where and what you are insulating"}),(0,we.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the application and product, and enter the area, for coverage and pack quantities."}),(0,we.jsxs)("div",{className:"materials-calculator__section",children:[(0,we.jsx)("div",{className:"truss-estimator__section-heading",children:"Application"}),(0,we.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:b.map(([y,T])=>(0,we.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===y?" is-selected":""}`,onClick:()=>i(y),children:[(0,we.jsx)("div",{className:"truss-estimator__option-title",children:T.label}),(0,we.jsxs)("div",{className:"truss-estimator__option-copy",children:[T.product,", ",T.thickness]})]},y))})]}),(0,we.jsxs)("div",{className:"materials-calculator__section",children:[(0,we.jsx)("div",{className:"truss-estimator__section-heading",children:"Area"}),(0,we.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,we.jsxs)("label",{className:"truss-estimator__field",children:[(0,we.jsx)("span",{children:"Length (m)"}),(0,we.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:y=>o(y.target.value)})]}),(0,we.jsxs)("label",{className:"truss-estimator__field",children:[(0,we.jsx)("span",{children:"Width (m)"}),(0,we.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:y=>c(y.target.value)})]})]})]}),(0,we.jsxs)("div",{className:"materials-calculator__totals",children:[(0,we.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,we.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,we.jsxs)("div",{children:[(0,we.jsx)("span",{children:"Insulated area"}),(0,we.jsxs)("strong",{children:[p.toFixed(2)," m\xB2"]})]}),(0,we.jsxs)("div",{children:[(0,we.jsx)("span",{children:d.product}),(0,we.jsxs)("strong",{children:[g," packs"]})]})]}),(0,we.jsx)("p",{className:"materials-calculator__note",children:"This is a simple product choice, not thermal or Building Regulations advice. Confirm the specification before ordering."})]}),(0,we.jsxs)("div",{className:"materials-calculator__actions",children:[(0,we.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,we.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(m),disabled:p<=0,children:a})]})]})]})})}var Qn=G(Xe()),V=G(ee()),J_=10,I_=1.9*.762,F_=1.9*1.524,pc=()=>({height:"",width:""}),dc=e=>Number.parseFloat(e)||0,Tv=({height:e,width:t})=>dc(e)*dc(t);function jd({onBack:e}){let[t,a]=(0,Qn.useState)([pc()]),[r,i]=(0,Qn.useState)([pc()]),[n,o]=(0,Qn.useState)("0"),[l,c]=(0,Qn.useState)("0"),[p,d]=(0,Qn.useState)(1),g=t.reduce((f,u)=>f+Tv(u),0),m=r.reduce((f,u)=>f+Tv(u),0),b=dc(n)*I_+dc(l)*F_,y=Math.max(0,g-m-b),T=y*p/J_,D=(f,u,w,v)=>{f(S=>S.map((R,z)=>z===u?{...R,[w]:v}:R))};return(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:"Paint Calculator"}),(0,V.jsx)("p",{children:"Estimate how much paint you need for your walls, including multiple coats and excluded areas."})]}),(0,V.jsxs)("div",{className:"truss-estimator__card paint-calculator",children:[(0,V.jsx)("h2",{className:"truss-estimator__step-title",children:"Walls, exclusions and coats"}),(0,V.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,V.jsxs)("div",{className:"paint-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,V.jsx)("p",{className:"paint-calculator__hint",children:"Enter the height and width of each wall you want to paint."}),(0,V.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,V.jsx)("span",{}),(0,V.jsx)("span",{children:"Height (m)"}),(0,V.jsx)("span",{children:"Width (m)"}),(0,V.jsx)("span",{})]}),t.map((f,u)=>(0,V.jsxs)("div",{className:"paint-calculator__row",children:[(0,V.jsxs)("span",{className:"paint-calculator__row-label",children:["Wall ",u+1]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,V.jsx)("input",{"aria-label":`Wall ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:f.height,onChange:w=>D(a,u,"height",w.target.value)})]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,V.jsx)("input",{"aria-label":`Wall ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:f.width,onChange:w=>D(a,u,"width",w.target.value)})]}),t.length>1?(0,V.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>a(w=>w.filter((v,S)=>S!==u)),children:"Remove"}):null]},`wall-${u}`)),(0,V.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>a(f=>[...f,pc()]),children:"+ Add another wall"})]}),(0,V.jsxs)("div",{className:"paint-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Areas to exclude"}),(0,V.jsx)("p",{className:"paint-calculator__hint",children:"Add windows, sockets, skirting boards or other areas that will not be painted."}),(0,V.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,V.jsx)("span",{}),(0,V.jsx)("span",{children:"Height (m)"}),(0,V.jsx)("span",{children:"Width (m)"}),(0,V.jsx)("span",{})]}),r.map((f,u)=>(0,V.jsxs)("div",{className:"paint-calculator__row",children:[(0,V.jsxs)("span",{className:"paint-calculator__row-label",children:["Area ",u+1]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,V.jsx)("input",{"aria-label":`Area ${u+1} height in metres`,type:"number",min:"0",step:"0.01",value:f.height,onChange:w=>D(i,u,"height",w.target.value)})]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,V.jsx)("input",{"aria-label":`Area ${u+1} width in metres`,type:"number",min:"0",step:"0.01",value:f.width,onChange:w=>D(i,u,"width",w.target.value)})]}),r.length>1?(0,V.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(w=>w.filter((v,S)=>S!==u)),children:"Remove"}):null]},`excluded-${u}`)),(0,V.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(f=>[...f,pc()]),children:"+ Add another area"})]}),(0,V.jsxs)("div",{className:"paint-calculator__section",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Doors and coats"}),(0,V.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,V.jsxs)("div",{className:"truss-estimator__field-grid paint-calculator__small-fields",children:[(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{children:"Doors"}),(0,V.jsx)("input",{type:"number",min:"0",step:"1",value:n,onChange:f=>o(f.target.value)})]}),(0,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{children:"Double doors"}),(0,V.jsx)("input",{type:"number",min:"0",step:"1",value:l,onChange:f=>c(f.target.value)})]})]}),(0,V.jsxs)("div",{className:"paint-calculator__coat-field",children:[(0,V.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,V.jsxs)("label",{className:"truss-estimator__field",children:[(0,V.jsx)("span",{children:"Number of coats"}),(0,V.jsxs)("select",{value:p,onChange:f=>d(Number(f.target.value)),children:[(0,V.jsx)("option",{value:"1",children:"1 coat"}),(0,V.jsx)("option",{value:"2",children:"2 coats"}),(0,V.jsx)("option",{value:"3",children:"3 coats"})]})]})]})]}),(0,V.jsxs)("div",{className:"paint-calculator__totals",children:[(0,V.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,V.jsxs)("div",{className:"paint-calculator__result-grid",children:[(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Paintable area"}),(0,V.jsxs)("strong",{children:[y.toFixed(2)," m\xB2"]})]}),(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Coverage"}),(0,V.jsxs)("strong",{children:[p," ",p===1?"coat":"coats"]})]}),(0,V.jsxs)("div",{children:[(0,V.jsx)("span",{children:"Paint required"}),(0,V.jsxs)("strong",{children:[T.toFixed(1)," litres"]})]})]}),(0,V.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,V.jsxs)("div",{className:"paint-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",disabled:!0,children:"Paint products unavailable"})]})]})]})})}var gr=G(Xe()),te=G(ee()),mc=e=>Number.parseFloat(e)||0,Qd={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 Gd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,gr.useState)("paving"),[n,o]=(0,gr.useState)("council"),[l,c]=(0,gr.useState)(""),[p,d]=(0,gr.useState)(""),[g,m]=(0,gr.useState)("100"),[b,y]=(0,gr.useState)("50"),[T,D]=(0,gr.useState)(!0),[f,u]=(0,gr.useState)(!0),w=mc(l)*mc(p),v=w,S=w*(mc(g)/1e3),R=w*.04,z=w*(mc(b)/1e3),A=Math.ceil(v/.36),Q=Math.ceil(v/.1),K=Math.ceil(S*1700/800),fe=Math.ceil(R*1600/800),Ue=Math.ceil(z*1600/800),Be=r==="paving"?{qty:A,unit:"each"}:r==="block"?{qty:v,unit:"m2"}:{qty:Ue,unit:"bag"},Ye={paving:"paving slab",block:"block paver",gravel:"decorative gravel"}[r],Ne=[{key:`surface-${n}`,label:Qd[r].find(oe=>oe.id===n)?.label??"Surface material",qty:Be.qty,unit:Be.unit,query:Ye,category:"landscaping"},...T?[{key:"sub-base",label:"MOT Type 1 sub-base",qty:K,unit:"bag",query:"MOT Type 1 sub base",category:"aggregate"}]:[],...f?[{key:"bedding",label:"Sharp sand bedding",qty:fe,unit:"bag",query:"sharp sand",category:"aggregate"}]:[]];return(0,te.jsx)(te.Fragment,{children:(0,te.jsxs)("div",{className:"truss-estimator",children:[(0,te.jsxs)("div",{className:"quick-order-hero",children:[(0,te.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,te.jsx)("h1",{children:"Paving and Driveway Calculator"}),(0,te.jsx)("p",{children:"Estimate paving, block paving, sub-base and bedding materials for outdoor areas."})]}),(0,te.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,te.jsx)("h2",{className:"truss-estimator__step-title",children:"Surface and ground build-up"}),(0,te.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,te.jsxs)("div",{className:"materials-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Surface material"}),(0,te.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(([oe,se,ye])=>(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===oe?" is-selected":""}`,onClick:()=>{i(oe),o(Qd[oe][0].id)},children:[(0,te.jsx)("div",{className:"truss-estimator__option-title",children:se}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:ye})]},oe))}),(0,te.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,te.jsx)("span",{children:"Finish"}),(0,te.jsx)("select",{value:n,onChange:oe=>o(oe.target.value),children:Qd[r].map(oe=>(0,te.jsx)("option",{value:oe.id,children:oe.label},oe.id))})]})]}),(0,te.jsxs)("div",{className:"materials-calculator__section",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and groundwork"}),(0,te.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,te.jsxs)("label",{className:"truss-estimator__field",children:[(0,te.jsx)("span",{children:"Length (m)"}),(0,te.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:oe=>c(oe.target.value)})]}),(0,te.jsxs)("label",{className:"truss-estimator__field",children:[(0,te.jsx)("span",{children:"Width (m)"}),(0,te.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:oe=>d(oe.target.value)})]})]}),r==="gravel"&&(0,te.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,te.jsx)("span",{children:"Gravel depth (mm)"}),(0,te.jsx)("input",{type:"number",min:"0",step:"10",value:b,onChange:oe=>y(oe.target.value)})]}),T&&(0,te.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,te.jsx)("span",{children:"Sub-base depth (mm)"}),(0,te.jsx)("input",{type:"number",min:"0",step:"10",value:g,onChange:oe=>m(oe.target.value)})]}),(0,te.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,te.jsx)("input",{type:"checkbox",checked:T,onChange:oe=>D(oe.target.checked)}),(0,te.jsx)("span",{children:"Include MOT Type 1 sub-base"})]}),(0,te.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,te.jsx)("input",{type:"checkbox",checked:f,onChange:oe=>u(oe.target.checked)}),(0,te.jsx)("span",{children:"Include sharp sand bedding"})]})]}),(0,te.jsxs)("div",{className:"materials-calculator__totals",children:[(0,te.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,te.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Surface area"}),(0,te.jsxs)("strong",{children:[w.toFixed(2)," m\xB2"]})]}),(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:r==="paving"?"Paving slabs":r==="block"?"Block paving":"Gravel"}),(0,te.jsx)("strong",{children:r==="paving"?`${A} slabs`:r==="block"?`${v.toFixed(2)} m\xB2`:`${Ue} bulk bags`})]}),T&&(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"MOT Type 1"}),(0,te.jsxs)("strong",{children:[K," bulk bags"]})]}),f&&(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Sharp sand"}),(0,te.jsxs)("strong",{children:[fe," bulk bags"]})]})]}),(0,te.jsx)("p",{className:"materials-calculator__note",children:"Slab and block quantities use typical sizes. Confirm pack coverage and laying pattern before ordering."})]}),(0,te.jsxs)("div",{className:"materials-calculator__actions",children:[(0,te.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,te.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(Ne),disabled:w<=0,children:a})]})]})]})})}var ll=G(Xe()),ae=G(ee()),W_=2.88,zv=[{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"}],Av=()=>({length:"",height:""}),Yd=e=>Number.parseFloat(e)||0;function Xd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,ll.useState)([Av()]),[n,o]=(0,ll.useState)(""),[l,c]=(0,ll.useState)("standard"),[p,d]=(0,ll.useState)("screws"),g=r.reduce((R,z)=>R+Yd(z.length)*Yd(z.height),0),m=Math.max(0,g-Yd(n)),b=Math.ceil(m/W_),y=Math.ceil(m*12),T=Math.ceil(y/1e3),D=Math.ceil(m*1.2),f=Math.ceil(D/90),u=Math.ceil(m/3.5),w=zv.find(R=>R.id===l)?.label??"Standard",v=[{key:"board",label:`${w} plasterboard`,qty:b,unit:"sheet",query:`${w} plasterboard`,category:"plasterboard"},...p==="screws"?[{key:"screws",label:"Drywall screws",qty:T,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:f,unit:"roll",query:"plasterboard joint tape",category:"plasterboard"}],S=(R,z,A)=>{i(Q=>Q.map((K,fe)=>fe===R?{...K,[z]:A}:K))};return(0,ae.jsx)(ae.Fragment,{children:(0,ae.jsxs)("div",{className:"truss-estimator",children:[(0,ae.jsxs)("div",{className:"quick-order-hero",children:[(0,ae.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ae.jsx)("h1",{children:"Plasterboard and Drylining Calculator"}),(0,ae.jsx)("p",{children:"Estimate boards, fixings and jointing materials for walls and ceilings."})]}),(0,ae.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,ae.jsx)("h2",{className:"truss-estimator__step-title",children:"Boards, fixings and jointing"}),(0,ae.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,ae.jsxs)("div",{className:"materials-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Board type"}),(0,ae.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:zv.map(R=>(0,ae.jsxs)("button",{type:"button",className:`truss-estimator__option-card${l===R.id?" is-selected":""}`,onClick:()=>c(R.id),children:[(0,ae.jsx)("div",{className:"truss-estimator__option-title",children:R.label}),(0,ae.jsx)("div",{className:"truss-estimator__option-copy",children:R.blurb})]},R.id))})]}),(0,ae.jsxs)("div",{className:"materials-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Fixing method"}),(0,ae.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["screws","Drywall screws","For timber or metal framing"],["adhesive","Board adhesive","For masonry dot-and-dab"]].map(([R,z,A])=>(0,ae.jsxs)("button",{type:"button",className:`truss-estimator__option-card${p===R?" is-selected":""}`,onClick:()=>d(R),children:[(0,ae.jsx)("div",{className:"truss-estimator__option-title",children:z}),(0,ae.jsx)("div",{className:"truss-estimator__option-copy",children:A})]},R))})]}),(0,ae.jsxs)("div",{className:"materials-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall and ceiling areas"}),(0,ae.jsx)("p",{className:"materials-calculator__hint",children:"Add each surface separately so different wall sizes are easy to measure."}),(0,ae.jsxs)("div",{className:"materials-calculator__dimensions-header",children:[(0,ae.jsx)("span",{children:"Surface"}),(0,ae.jsx)("span",{children:"Length (m)"}),(0,ae.jsx)("span",{children:"Height (m)"}),(0,ae.jsx)("span",{})]}),r.map((R,z)=>(0,ae.jsxs)("div",{className:"materials-calculator__surface-row",children:[(0,ae.jsxs)("span",{children:["Surface ",z+1]}),(0,ae.jsx)("input",{"aria-label":`Surface ${z+1} length`,type:"number",min:"0",step:"0.01",value:R.length,onChange:A=>S(z,"length",A.target.value)}),(0,ae.jsx)("input",{"aria-label":`Surface ${z+1} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:A=>S(z,"height",A.target.value)}),r.length>1?(0,ae.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(A=>A.filter((Q,K)=>K!==z)),children:"Remove"}):null]},`surface-${z}`)),(0,ae.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(R=>[...R,Av()]),children:"+ Add another surface"}),(0,ae.jsxs)("label",{className:"truss-estimator__field materials-calculator__openings",children:[(0,ae.jsxs)("span",{children:["Openings to deduct (m\xB2) ",(0,ae.jsx)("small",{children:"optional"})]}),(0,ae.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:R=>o(R.target.value)})]})]}),(0,ae.jsxs)("div",{className:"materials-calculator__totals",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ae.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Board area"}),(0,ae.jsxs)("strong",{children:[m.toFixed(2)," m\xB2"]})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"2.4 x 1.2 m boards"}),(0,ae.jsx)("strong",{children:b})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:p==="screws"?"Drywall screws":"Board adhesive"}),(0,ae.jsx)("strong",{children:p==="screws"?`${y} (${T} boxes)`:`${u} bags`})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Joint tape"}),(0,ae.jsxs)("strong",{children:[D," m (",f," rolls)"]})]})]}),(0,ae.jsx)("p",{className:"materials-calculator__note",children:"Figures are estimates. Confirm board specification, fixing patterns and fire or acoustic requirements before ordering."})]}),(0,ae.jsxs)("div",{className:"materials-calculator__actions",children:[(0,ae.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ae.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(v),disabled:m<=0,children:a})]})]})]})})}var sl=G(Xe());var _=G(ee()),Dt={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}}}},fc=["range","pitchAndDimensions","quantityAndGirders","bracing"],ex={range:null,pitch:null,spanMM:"",overhangMM:"",roofLengthM:"",centres:null,girderCount:0,bracing:null,treatment:null,contact:{name:"",email:""}};function tx({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 ax({type:e}){let t="#b3835a",a="#5c3b22",r="#d9b48f",i="#d3d8de",n="#7c8494",o=(d,g,m,b,y=8,T)=>{let D=m-d,f=b-g,u=Math.hypot(D,f)||1,w=-f/u,v=D/u,S=y*.2;return(0,_.jsxs)("g",{children:[(0,_.jsx)("line",{x1:d,y1:g,x2:m,y2:b,stroke:a,strokeWidth:y+3,strokeLinecap:"square"}),(0,_.jsx)("line",{x1:d,y1:g,x2:m,y2:b,stroke:t,strokeWidth:y,strokeLinecap:"square"}),(0,_.jsx)("line",{x1:d-w*S,y1:g-v*S,x2:m-w*S,y2:b-v*S,stroke:r,strokeWidth:Math.max(1.5,y*.24),strokeLinecap:"round",opacity:"0.9"})]},T)},l=(d,g,m)=>(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})]},m),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 rx({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 Rv({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 Vd({onBack:e}){let[t,a]=(0,sl.useState)(0),[r,i]=(0,sl.useState)(ex),[n,o]=(0,sl.useState)(!1),[l,c]=(0,sl.useState)(!1),p=()=>{let f=Number.parseFloat(r.roofLengthM)||0,u=Number.parseFloat(r.centres??"");return f<=0||!u?0:Math.ceil(f*1e3/u)+1},g=(()=>{let f=r.range?Dt.ranges[r.range]:Dt.ranges.standard,u=r.pitch??"22.5",w=Dt.pitchMultipliers[u],v=(Number.parseFloat(r.spanMM)||0)/1e3,R=(Number.parseFloat(r.overhangMM)||0)>Dt.overhang.thresholdMM,z=p(),A=z+r.girderCount,Q=Number.parseFloat(r.roofLengthM)||0,K=r.treatment?Dt.treatment[r.treatment]:Dt.treatment.untreated,fe=Dt.estimate.ranges[r.range??"standard"],Ue=fe.supplyAt8m*Math.max(.7,v/8)*w*(1+K.surchargePct)+(R?Dt.overhang.surchargePerTruss:0),Be=z*Ue,Ye=r.girderCount*Ue*Dt.estimate.girderMultiplier,Ne=r.bracing==="yes"?Q*Dt.estimate.bracingPerMetre:0,ve=Be+Ye+Ne+Dt.estimate.delivery,oe=Dt.estimate.design+z*fe.installPerTruss+r.girderCount*40,se=ve+oe,ye=se*.2;return{range:f,count:z,girderCount:r.girderCount,overhangApplies:R,overhangUnits:A,roofLengthM:Q,treatment:K,trussSupply:Be,bracingMaterials:Ne,delivery:Dt.estimate.delivery,labour:oe,subtotal:se,vat:ye,total:se+ye}})(),m=()=>{let f=fc[t];return f==="range"?!!r.range:f==="pitchAndDimensions"?!!r.pitch&&r.spanMM.trim()!==""&&r.overhangMM.trim()!=="":f==="quantityAndGirders"?r.roofLengthM.trim()!==""&&!!r.centres:f==="bracing"?!!r.bracing&&!!r.treatment:!0},b=t===fc.length-1?"View truss request":"Next",y=()=>{n?o(!1):t===0?e():a(f=>f-1)},T=()=>{m()&&(t===fc.length-1?(c(!1),o(!0)):a(f=>f+1))},D=()=>{let f=fc[t];return f==="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(Dt.ranges).map(([u,w])=>(0,_.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r.range===u?" is-selected":""}`,onClick:()=>i(v=>({...v,range:u})),children:[(0,_.jsx)(ax,{type:u}),(0,_.jsxs)("div",{className:"truss-estimator__option-info",children:[(0,_.jsx)("div",{className:"truss-estimator__option-title",children:w.label}),(0,_.jsx)("div",{className:"truss-estimator__option-copy",children:w.blurb})]})]},u))})]}):f==="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(w=>({...w,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(w=>({...w,overhangMM:u.target.value}))}),(0,_.jsxs)("small",{children:["Overhangs beyond ",Dt.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:Dt.pitches.map(u=>(0,_.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${r.pitch===u?" is-selected":""}`,onClick:()=>i(w=>({...w,pitch:u})),children:[(0,_.jsx)(tx,{degrees:Number.parseFloat(u)}),(0,_.jsxs)("span",{children:[u,"\xB0"]})]},u))})]}):f==="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(w=>({...w,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:Dt.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(w=>({...w,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:"+"})]})]}):f==="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(w=>({...w,bracing:u.id})),children:[(0,_.jsx)(rx,{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)(Rv,{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)(Rv,{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:lt(g.trussSupply)})]}),g.bracingMaterials>0&&(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Bracing materials allowance"}),(0,_.jsx)("strong",{children:lt(g.bracingMaterials)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Delivery allowance"}),(0,_.jsx)("strong",{children:lt(g.delivery)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Design and installation labour"}),(0,_.jsx)("strong",{children:lt(g.labour)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"Subtotal (ex. VAT)"}),(0,_.jsx)("strong",{children:lt(g.subtotal)})]}),(0,_.jsxs)("div",{children:[(0,_.jsx)("span",{children:"VAT (20%)"}),(0,_.jsx)("strong",{children:lt(g.vat)})]}),(0,_.jsxs)("div",{className:"truss-request__price-total",children:[(0,_.jsx)("span",{children:"Estimated total"}),(0,_.jsx)("strong",{children:lt(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:y,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:y,children:"Back"}),(0,_.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:T,disabled:!m(),children:[(0,_.jsx)("span",{children:b}),(0,_.jsx)("span",{className:"arrow",children:(0,_.jsx)(Qt,{})})]})]})]})]})})}var Ci=G(Xe()),F=G(ee()),Ov=e=>Number.parseFloat(e)||0,hc=(e,t)=>Ov(e)*(t==="m"?1:.3048),Uv=()=>({length:"",width:""}),Dv=[{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 ix({profile:e}){return(0,F.jsxs)("svg",{className:"skirting-calculator__profile-diagram",viewBox:"0 0 120 84","aria-hidden":"true",children:[(0,F.jsx)("path",{d:{chamfered:"M16 70V43L43 16H104V70Z",ogee:"M16 70V47C16 36 27 31 40 31C40 21 50 16 63 16H104V70Z","pencil-round":"M16 70V37C16 25 25 16 37 16H104V70Z",torus:"M16 70V49C16 39 25 34 36 34C36 22 47 16 61 16H104V70Z"}[e]}),(0,F.jsx)("line",{x1:"12",y1:"70",x2:"108",y2:"70"})]})}function $d({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)([Uv()]),[g,m]=(0,Ci.useState)(""),[b,y]=(0,Ci.useState)("chamfered"),T="4.4",D=r==="total"?hc(l,n):p.reduce((S,R)=>S+2*(hc(R.length,n)+hc(R.width,n)),0),f=Math.max(0,D-hc(g,n)),u=Math.ceil(f/Ov(T)),w=[{key:`skirting-${b}`,label:`${Dv.find(S=>S.id===b)?.label} skirting board`,qty:f,unit:"m",query:"skirting board",category:"skirting"}],v=(S,R,z)=>{d(A=>A.map((Q,K)=>K===S?{...Q,[R]:z}:Q))};return(0,F.jsx)(F.Fragment,{children:(0,F.jsxs)("div",{className:"truss-estimator",children:[(0,F.jsxs)("div",{className:"quick-order-hero",children:[(0,F.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,F.jsx)("h1",{children:"Skirting Board Calculator"}),(0,F.jsx)("p",{children:"Work out how many skirting board lengths you need for one room or a whole project."})]}),(0,F.jsxs)("div",{className:"truss-estimator__card skirting-calculator",children:[(0,F.jsx)("h2",{className:"truss-estimator__step-title",children:"Measure by room or total length"}),(0,F.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter a single total or work room by room. The run is converted straight into board lengths."}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"How would you like to measure?"}),(0,F.jsxs)("div",{className:"brick-calculator__unit-toggle skirting-calculator__mode-toggle",role:"group","aria-label":"Calculation method",children:[(0,F.jsx)("button",{type:"button",className:r==="total"?"is-selected":"",onClick:()=>i("total"),children:"Total length"}),(0,F.jsx)("button",{type:"button",className:r==="rooms"?"is-selected":"",onClick:()=>i("rooms"),children:"Room by room"})]})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Measurements"}),(0,F.jsxs)("div",{className:"skirting-calculator__unit-row",children:[(0,F.jsx)("span",{children:"Units"}),(0,F.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,F.jsx)("button",{type:"button",className:n==="m"?"is-selected":"",onClick:()=>o("m"),children:"Metres"}),(0,F.jsx)("button",{type:"button",className:n==="ft"?"is-selected":"",onClick:()=>o("ft"),children:"Feet"})]})]}),r==="total"?(0,F.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,F.jsxs)("span",{children:["Total skirting length (",n,")"]}),(0,F.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:S=>c(S.target.value)})]}):(0,F.jsxs)(F.Fragment,{children:[(0,F.jsxs)("div",{className:"skirting-calculator__dimensions-header",children:[(0,F.jsx)("span",{children:"Room"}),(0,F.jsxs)("span",{children:["Length (",n,")"]}),(0,F.jsxs)("span",{children:["Width (",n,")"]}),(0,F.jsx)("span",{})]}),p.map((S,R)=>(0,F.jsxs)("div",{className:"skirting-calculator__room-row",children:[(0,F.jsxs)("span",{className:"skirting-calculator__room-label",children:["Room ",R+1]}),(0,F.jsx)("input",{"aria-label":`Room ${R+1} length in ${n}`,type:"number",min:"0",step:"0.01",value:S.length,onChange:z=>v(R,"length",z.target.value)}),(0,F.jsx)("input",{"aria-label":`Room ${R+1} width in ${n}`,type:"number",min:"0",step:"0.01",value:S.width,onChange:z=>v(R,"width",z.target.value)}),p.length>1?(0,F.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>d(z=>z.filter((A,Q)=>Q!==R)),children:"Remove"}):null]},`room-${R}`)),(0,F.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>d(S=>[...S,Uv()]),children:"+ Add another room"})]}),(0,F.jsxs)("label",{className:"truss-estimator__field skirting-calculator__single-field",children:[(0,F.jsxs)("span",{children:["Openings and doorways to deduct (",n,") ",(0,F.jsx)("small",{children:"optional"})]}),(0,F.jsx)("input",{type:"number",min:"0",step:"0.01",value:g,onChange:S=>m(S.target.value)})]})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Profile"}),(0,F.jsx)("p",{className:"skirting-calculator__hint",children:"Choose the finish you want for the fixed 4.4m white-primed MDF boards."}),(0,F.jsx)("div",{className:"architrave-calculator__profiles",children:Dv.map(S=>(0,F.jsxs)("button",{type:"button",className:`truss-estimator__option-card${b===S.id?" is-selected":""}`,onClick:()=>y(S.id),children:[(0,F.jsx)(ix,{profile:S.id}),(0,F.jsx)("div",{className:"truss-estimator__option-title",children:S.label}),(0,F.jsx)("div",{className:"truss-estimator__option-copy",children:S.blurb})]},S.id))})]}),(0,F.jsxs)("div",{className:"skirting-calculator__section",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Board and waste"}),(0,F.jsx)("div",{className:"truss-estimator__field-grid skirting-calculator__options-grid",children:(0,F.jsxs)("label",{className:"truss-estimator__field",children:[(0,F.jsx)("span",{children:"Board length"}),(0,F.jsx)("input",{value:"4.40 m",disabled:!0})]})}),(0,F.jsx)("p",{className:"skirting-calculator__hint",children:"Longer boards can reduce the number of joins, while 10% waste allows for cuts, corners and mistakes."})]}),(0,F.jsxs)("div",{className:"skirting-calculator__totals",children:[(0,F.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,F.jsxs)("div",{className:"skirting-calculator__result-grid",children:[(0,F.jsxs)("div",{children:[(0,F.jsx)("span",{children:"Net skirting"}),(0,F.jsxs)("strong",{children:[f.toFixed(2)," m"]})]}),(0,F.jsxs)("div",{children:[(0,F.jsx)("span",{children:"Board lengths"}),(0,F.jsx)("strong",{children:u})]})]}),(0,F.jsx)("p",{className:"skirting-calculator__note",children:"Corners and joins vary by room layout. Measure each wall where possible for the most accurate result."})]}),(0,F.jsxs)("div",{className:"skirting-calculator__actions",children:[(0,F.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,F.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(w),disabled:f<=0,children:a})]})]})]})})}var Gn=G(Xe()),ie=G(ee()),cl=e=>Number.parseFloat(e)||0;function Zd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Gn.useState)("studs"),[n,o]=(0,Gn.useState)(""),[l,c]=(0,Gn.useState)(""),[p,d]=(0,Gn.useState)("600"),[g,m]=(0,Gn.useState)("2.4"),b=n&&l&&p?Math.ceil(cl(l)/(cl(p)/1e3))+1:0,y=b*cl(n),T=cl(g)>0?Math.ceil(y/cl(g)):0,D=[{key:r,label:{studs:"Stud timber",joists:"Joist timber",battens:"Batten timber"}[r],qty:y,unit:"m",query:{studs:"cls studwork timber",joists:"timber joist",battens:"roofing batten"}[r],category:"timber"}],f={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"]},w={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,ie.jsx)(ie.Fragment,{children:(0,ie.jsxs)("div",{className:"truss-estimator",children:[(0,ie.jsxs)("div",{className:"quick-order-hero",children:[(0,ie.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,ie.jsx)("h1",{children:"Timber Calculator"}),(0,ie.jsx)("p",{children:"Estimate studs, joists or battens from a run length, width and spacing."})]}),(0,ie.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,ie.jsx)("h2",{className:"truss-estimator__step-title",children:"Member size and spacing"}),(0,ie.jsxs)("p",{className:"truss-estimator__step-sub",children:[w.help," Enter the member length and centres to estimate the number of pieces and stock lengths."]}),(0,ie.jsxs)("div",{className:"materials-calculator__section",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber use"}),(0,ie.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:Object.keys(f).map(v=>(0,ie.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===v?" is-selected":""}`,onClick:()=>i(v),children:[(0,ie.jsx)("div",{className:"truss-estimator__option-title",children:f[v][0]}),(0,ie.jsx)("div",{className:"truss-estimator__option-copy",children:f[v][1]})]},v))})]}),(0,ie.jsxs)("div",{className:"materials-calculator__section",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Dimensions and spacing"}),(0,ie.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ie.jsxs)("label",{className:"truss-estimator__field",children:[(0,ie.jsxs)("span",{children:[w.member," (m)"]}),(0,ie.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:v=>o(v.target.value)})]}),(0,ie.jsxs)("label",{className:"truss-estimator__field",children:[(0,ie.jsxs)("span",{children:[w.overall," (m)"]}),(0,ie.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:v=>c(v.target.value)})]})]}),(0,ie.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ie.jsxs)("label",{className:"truss-estimator__field",children:[(0,ie.jsx)("span",{children:"Centres (mm)"}),(0,ie.jsxs)("select",{value:p,onChange:v=>d(v.target.value),children:[(0,ie.jsx)("option",{value:"300",children:"300 mm"}),(0,ie.jsx)("option",{value:"400",children:"400 mm"}),(0,ie.jsx)("option",{value:"450",children:"450 mm"}),(0,ie.jsx)("option",{value:"600",children:"600 mm"})]})]}),(0,ie.jsxs)("label",{className:"truss-estimator__field",children:[(0,ie.jsx)("span",{children:"Stock length (m)"}),(0,ie.jsxs)("select",{value:g,onChange:v=>m(v.target.value),children:[(0,ie.jsx)("option",{value:"2.4",children:"2.40 m"}),(0,ie.jsx)("option",{value:"3.6",children:"3.60 m"}),(0,ie.jsx)("option",{value:"4.8",children:"4.80 m"})]})]})]})]}),(0,ie.jsxs)("div",{className:"materials-calculator__totals",children:[(0,ie.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ie.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:w.count}),(0,ie.jsx)("strong",{children:b})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsx)("span",{children:"Linear metres"}),(0,ie.jsxs)("strong",{children:[y.toFixed(2)," m"]})]}),(0,ie.jsxs)("div",{children:[(0,ie.jsxs)("span",{children:[g," m lengths"]}),(0,ie.jsx)("strong",{children:T})]})]}),(0,ie.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,ie.jsxs)("div",{className:"materials-calculator__actions",children:[(0,ie.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,ie.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(D),disabled:y<=0,children:a})]})]})]})})}var Kd=[{id:"truss",title:"Roof Truss Calculator",desc:"Estimate trusses, girders and roof structure costs.",imageUrl:"/tool-images/truss.webp",Component:Vd},{id:"fencing",title:"Fencing Calculator",desc:"Estimate fence panels, posts, gravel boards and fixings.",imageUrl:"/tool-images/fencing.webp",Component:Ld},{id:"decking",title:"Decking Calculator",desc:"Estimate boards, substructure and fixing quantities.",imageUrl:"/tool-images/decking.webp",Component:Bd},{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:Td},{id:"paint",title:"Paint Calculator",desc:"Estimate paint for walls, doors and multiple coats.",imageUrl:"/tool-images/paint.webp",Component:jd},{id:"skirting",title:"Skirting Board Calculator",desc:"Estimate skirting lengths for rooms and wall runs.",imageUrl:"/tool-images/skirting.webp",Component:$d},{id:"architrave",title:"Architrave Calculator",desc:"Estimate architrave lengths for door and window openings.",imageUrl:"/tool-images/architrave.webp",Component:Md},{id:"concrete-aggregate",title:"Concrete and Aggregate Calculator",desc:"Estimate concrete, MOT, sand and gravel quantities.",imageUrl:"/tool-images/concrete-aggregate.webp",Component:Dd},{id:"plasterboard",title:"Plasterboard Calculator",desc:"Estimate plasterboard sheets, screws, tape and adhesive.",imageUrl:"/tool-images/plasterboard.webp",Component:Xd},{id:"insulation",title:"Insulation Calculator",desc:"Estimate insulation packs for floors, walls, roofs and lofts.",imageUrl:"/tool-images/insulation.webp",Component:Hd},{id:"timber",title:"Timber Calculator",desc:"Estimate studs, joists and battens from spacing and lengths.",imageUrl:"/tool-images/timber.webp",Component:Zd},{id:"paving",title:"Paving and Driveway Calculator",desc:"Estimate paving, block paving, MOT and sharp sand.",imageUrl:"/tool-images/paving.webp",Component:Gd}];var bc=G(Xe());var Ge=G(Xe());var C=G(ee()),nx=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}],Pd={wasteFactorEnabled:!0},ox=3e3,Bv=null;function gc(e,t){let a=el(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function lx(e){return e&&e.length>0?e.join(" x "):"-"}function Jd({toolId:e,requirements:t,ready:a,onBack:r,onTotalChange:i}){let n=tc(),o=`${e}~${t.map(k=>`${k.key}|${k.query}|${k.category??""}|${k.qty}`).join("~")}`,l=o!==Bv,[c,p]=(0,Ge.useState)(null),[d,g]=(0,Ge.useState)([]),[m,b]=(0,Ge.useState)(l),[y,T]=(0,Ge.useState)(null),[D,f]=(0,Ge.useState)("tile"),[u,w]=(0,Ge.useState)(null),[v,S]=(0,Ge.useState)(""),[R,z]=(0,Ge.useState)(null),[A,Q]=(0,Ge.useState)(""),[K,fe]=(0,Ge.useState)([]),[Ue,Be]=(0,Ge.useState)(new Set),[Ye,Ne]=(0,Ge.useState)(null),[ve,oe]=(0,Ge.useState)(""),[se,ye]=(0,Ge.useState)([]),wt=(0,Ge.useRef)(null),Ee=(0,Ge.useRef)(!1),$=k=>`${e}:${k}`,ue=k=>Pr(k.chosen,{lineId:$(k.requirement.key),description:k.requirement.label,unit:k.requirement.unit,qty:k.requirement.qty}),Ze=(0,Ge.useMemo)(()=>t.map(k=>`${k.key}|${k.query}|${k.category??""}`).join("~"),[t]);(0,Ge.useEffect)(()=>{let k=!1;return Nv().then(L=>{k||p(L.itemCount>0)}).catch(()=>{k||p(!1)}),()=>{k=!0}},[]),(0,Ge.useEffect)(()=>{if(!a||!c)return;let k=!1,L;l&&b(!0),T(null);let P=Date.now();return(async()=>{let pe=null;try{pe=(await kv(t,void 0,e)).map(({requirement:xt,candidates:it})=>({requirement:xt,candidates:it,chosen:it[0]??null}))}catch(xe){k||T(xe instanceof Error?xe.message:"Could not load products")}if(!k){if(Bv=o,l){let xe=ox-(Date.now()-P);xe>0&&await new Promise(xt=>{L=window.setTimeout(xt,xe)})}k||(pe&&(g(pe),!Ee.current&&n&&(Ee.current=!0,n.addManyToCart(pe.filter(xe=>xe.chosen).map(ue)))),b(!1))}})(),()=>{k=!0,window.clearTimeout(L)}},[a,c,Ze]),(0,Ge.useEffect)(()=>{if(!R)return;let k=A.trim();if(!k){fe([]);return}let L=!1,P=window.setTimeout(()=>{fr(k).then(pe=>{L||fe(pe)}).catch(()=>{L||fe([])})},250);return()=>{L=!0,window.clearTimeout(P)}},[R,A]),(0,Ge.useEffect)(()=>{if(!Ye)return;let k=ve.trim();if(!k){ye([]);return}let L=!1,P=window.setTimeout(()=>{fr(k).then(pe=>{L||ye(pe)}).catch(()=>{L||ye([])})},250);return()=>{L=!0,window.clearTimeout(P)}},[Ye,ve]);let pt=(0,Ge.useMemo)(()=>{let k=v.trim().toLowerCase(),L=k?d.filter(P=>P.requirement.label.toLowerCase().includes(k)||(P.chosen?.description??"").toLowerCase().includes(k)||(P.chosen?.product_id??"").toLowerCase().includes(k)):d;return u?[...L].sort((P,pe)=>{let xe=P.requirement.label.localeCompare(pe.requirement.label);return u==="asc"?xe:-xe}):L},[d,v,u]),vt=pt.filter(k=>k.chosen),He=pt.filter(k=>!k.chosen),de=d.filter(k=>k.chosen),_e=de.filter(k=>k.chosen?.price==null).length,Se=de.reduce((k,L)=>k+(Ft(ue(L),Pd).lineTotal??0),0);if((0,Ge.useEffect)(()=>{i?.(Se)},[Se,i]),!a||c===!1)return null;let E=n?de.filter(k=>n.cart[$(k.requirement.key)]).length:0,O=Ye?d.find(k=>k.requirement.key===Ye)??null:null,ce=ve.trim()?se:O?.candidates??[],ge=k=>{let L=R===k.requirement.key;z(L?null:k.requirement.key),Q(L?"":k.requirement.query)},Ae=(k,L)=>{let P=d.find(pe=>pe.requirement.key===k);g(pe=>pe.map(xe=>xe.requirement.key===k?{...xe,chosen:L}:xe)),n&&P&&n.cart[$(k)]&&n.addToCart(ue({...P,chosen:L})),z(null),Q("")},Pe=k=>{g(L=>L.map(P=>P.requirement.key===k?{...P,chosen:null}:P)),n?.cart[$(k)]&&n.removeFromCart($(k))},h=k=>{Ne(k.requirement.key),oe(""),ye([])},M=()=>{Ne(null),oe(""),ye([])},N=k=>{if(!n)return;let L=$(k.requirement.key);n.cart[L]?n.removeFromCart(L):n.addToCart(ue(k))},Y=k=>{Be(L=>{let P=new Set(L);return P.has(k)?P.delete(k):P.add(k),P})},Z=k=>{let L=K.length>0?K:k.candidates;return(0,C.jsxs)("div",{className:"estimator-products__picker",children:[(0,C.jsx)("input",{type:"text",className:"results-search-input",value:A,autoFocus:!0,placeholder:"Search products in catalogue...",onChange:P=>Q(P.target.value),"aria-label":`Search a product for ${k.requirement.label}`}),(0,C.jsxs)("div",{className:"estimator-products__options",children:[L.map(P=>(0,C.jsxs)("button",{type:"button",className:`estimator-products__option${P.product_id===k.chosen?.product_id?" is-selected":""}`,onClick:()=>Ae(k.requirement.key,P),children:[(0,C.jsx)("span",{children:P.description}),(0,C.jsxs)("span",{className:"results-row-meta",children:[P.product_id,P.price!=null&&` \xB7 ${lt(P.price)}`]})]},P.product_id)),L.length===0&&(0,C.jsx)("p",{className:"results-empty-hint",children:"No matching products."})]})]})};return(0,C.jsxs)("section",{className:"estimator-products results-tile-section","aria-label":"Matched products",children:[!m&&(0,C.jsxs)("div",{className:"estimator-products__head",children:[(0,C.jsxs)("div",{className:"results-tile-section__head",children:[(0,C.jsx)("h3",{children:"Matched Products"}),(0,C.jsx)("p",{children:"Products matched to your estimate, check before adding to your basket."})]}),!O&&(0,C.jsxs)("div",{className:"results-summary estimator-products__toolbar",children:[_e>0&&(0,C.jsxs)("span",{className:"summary-chip summary-chip--neutral",children:[(0,C.jsx)("strong",{children:_e})," need pricing"]}),(0,C.jsxs)("div",{className:"estimator-products__controls",children:[(0,C.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:v,onChange:k=>S(k.target.value),"aria-label":"Search matched products"}),(0,C.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,C.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:()=>f("tile"),children:(0,C.jsxs)("svg",{width:"18",height:"12",viewBox:"0 0 15 10",fill:"currentColor",children:[(0,C.jsx)("rect",{x:"0.5",y:"0.5",width:"4",height:"4"}),(0,C.jsx)("rect",{x:"5.5",y:"0.5",width:"4",height:"4"}),(0,C.jsx)("rect",{x:"10.5",y:"0.5",width:"4",height:"4"}),(0,C.jsx)("rect",{x:"0.5",y:"5.5",width:"4",height:"4"}),(0,C.jsx)("rect",{x:"5.5",y:"5.5",width:"4",height:"4"}),(0,C.jsx)("rect",{x:"10.5",y:"5.5",width:"4",height:"4"})]})}),(0,C.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:()=>f("list"),children:(0,C.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,C.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,C.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,C.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),(0,C.jsxs)("details",{ref:wt,style:{position:"relative"},children:[(0,C.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort materials",style:{fontSize:16},children:"\u21C5"}),(0,C.jsx)("div",{className:"sort-menu-panel",children:nx.map(k=>{let L=u===k.dir;return(0,C.jsxs)("button",{type:"button",className:`sort-menu-item${L?" is-active":""}`,onClick:()=>{w(L?null:k.dir),wt.current?.removeAttribute("open")},children:[(0,C.jsx)("span",{className:"sort-menu-item__check",children:L?"\u2713":""}),k.label]},k.dir)})})]})]})]})]}),O&&(0,C.jsxs)("div",{className:"results-review-page",children:[(0,C.jsxs)("div",{className:"results-review-page__top",children:[(0,C.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:M,children:[(0,C.jsx)(Kr,{}),"Back to results"]}),(0,C.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[(0,C.jsx)("div",{className:"results-review-searchbar",children:(0,C.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:ve,onChange:k=>oe(k.target.value),"aria-label":`Search a product for ${O.requirement.label}`})}),O.chosen&&(0,C.jsx)("div",{className:"results-candidate-actions",children:(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Pe(O.requirement.key),children:"Clear selected product"})})]})]}),(0,C.jsxs)("div",{className:"results-review-page__hero",children:[(0,C.jsx)("div",{className:"results-review-page__image-wrap",children:(0,C.jsx)("img",{className:"fill-img results-review-page__image",src:Ga(O.chosen?.description||O.requirement.label,O.chosen?.product_id,O.chosen?.pdp_photo_url),alt:""})}),(0,C.jsxs)("div",{className:"results-review-page__summary",children:[(0,C.jsx)("h2",{children:O.requirement.label}),(0,C.jsxs)("p",{className:"results-review-page__meta",children:[yi(O.requirement.qty)," ",Sa(O.requirement.unit,O.requirement.qty)]}),O.chosen?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)("div",{className:"results-review-page__product",children:O.chosen.description}),(0,C.jsxs)("div",{className:"results-row-meta",children:[O.chosen.product_id,O.chosen.price!=null?` \xB7 ${gc(O.chosen.price,O.chosen.price_basis)}`:""]})]}):(0,C.jsx)("div",{className:"results-empty-hint",children:"No product currently selected for this line."}),(0,C.jsx)("div",{className:"results-review-page__actions",children:(0,C.jsx)("button",{type:"button",className:`bom-toolbar-btn${n?.cart[$(O.requirement.key)]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>N(O),disabled:!O.chosen||!n,children:n?.cart[$(O.requirement.key)]?"\u2713 Added":"+ Add to basket"})})]})]}),ce.length===0?(0,C.jsx)("p",{className:"results-empty-hint",children:"No matching products."}):(0,C.jsxs)("table",{className:"score-breakdown-table",children:[(0,C.jsx)("thead",{children:(0,C.jsxs)("tr",{children:[(0,C.jsx)("th",{children:"Product"}),(0,C.jsx)("th",{children:"Dims (mm)"}),(0,C.jsx)("th",{children:"Price"}),(0,C.jsx)("th",{"aria-label":"Actions"})]})}),(0,C.jsx)("tbody",{children:ce.map(k=>{let L=k.product_id===O.chosen?.product_id;return(0,C.jsxs)("tr",{className:L?"score-breakdown-row--best":"",children:[(0,C.jsxs)("td",{children:[(0,C.jsx)("div",{children:k.description}),(0,C.jsx)("div",{className:"results-row-meta",children:k.product_id})]}),(0,C.jsx)("td",{children:(0,C.jsx)("span",{className:"unit-badge",children:lx(k.measurements_mm)})}),(0,C.jsx)("td",{children:k.price!=null?gc(k.price,k.price_basis):"-"}),(0,C.jsx)("td",{children:(0,C.jsxs)("label",{className:"switch-toggle",title:L?"Currently selected":"Use this candidate",children:[(0,C.jsx)("input",{type:"checkbox",checked:L,onChange:()=>{L?Pe(O.requirement.key):Ae(O.requirement.key,k)},"aria-label":L?`${k.description} selected`:`Use ${k.description}`}),(0,C.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},k.product_id)})})]})]}),!O&&m&&(0,C.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{padding:"32px 24px"},children:[(0,C.jsx)(dr,{}),(0,C.jsx)("p",{className:"banter-message is-visible",style:{fontSize:15,minHeight:0},children:"Matching your materials against the catalogue\u2026"})]}),!O&&y&&(0,C.jsx)("p",{className:"results-empty-hint estimator-products__error",children:y}),!O&&!m&&!y&&pt.length===0&&d.length>0&&(0,C.jsx)("p",{className:"results-empty-hint",children:"No materials match the current search."}),!O&&!m&&!y&&D==="tile"&&vt.length>0&&(0,C.jsx)("div",{className:"results-tile-grid",children:vt.map(k=>{let{requirement:L,chosen:P}=k,pe=P?Ft(ue(k),Pd):null,xe=n?!!n.cart[$(L.key)]:!1;return(0,C.jsxs)("article",{className:"results-tile-card",children:[(0,C.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>h(k),"aria-label":`Review match for ${L.label}`,children:[(0,C.jsx)("div",{className:"results-tile-card__media",children:(0,C.jsx)("img",{className:"fill-img results-tile-card__image",src:Ga(P?.description||L.label,P?.product_id,P?.pdp_photo_url),alt:""})}),(0,C.jsxs)("div",{className:"results-tile-card__body",children:[P?(0,C.jsxs)("div",{className:"results-tile-card__heading",children:[(0,C.jsx)("div",{className:"results-tile-card__title",children:P.description}),(0,C.jsxs)("div",{className:"results-tile-card__match-meta",children:[(0,C.jsx)("span",{children:P.product_id}),P.price!=null?(0,C.jsx)("span",{children:gc(P.price,P.price_basis)}):null]})]}):(0,C.jsx)("div",{className:"results-empty-hint",children:"No product matched for this line."}),(0,C.jsxs)("div",{className:"results-tile-card__match",children:[(0,C.jsx)("div",{className:"results-tile-card__match-label",children:"\u21B3 calculated as"}),(0,C.jsx)("div",{className:"results-tile-card__match-name",children:L.label}),(0,C.jsxs)("div",{className:"results-tile-card__meta",children:[yi(L.qty)," ",Sa(L.unit,L.qty)]}),pe?.requiredSellUnits!=null?(0,C.jsxs)("div",{className:"results-tile-card__meta estimator-products__order",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${lt(pe.lineTotal)}`:""]}):P?(0,C.jsx)("div",{className:"results-row-meta",children:"Quantity needs review"}):null]})]})]}),(0,C.jsxs)("div",{className:"results-tile-card__actions",children:[(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>h(k),children:"Review"}),(0,C.jsx)("button",{type:"button",className:`bom-toolbar-btn${xe?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>N(k),disabled:!P||!n,children:xe?"\u2713 Added":"+ Add"})]})]},L.key)})}),!O&&!m&&!y&&D==="list"&&vt.length>0&&(0,C.jsx)("div",{className:"bom-table-wrap",children:(0,C.jsxs)("table",{className:"bom-table results-table","aria-label":"Matched materials",children:[(0,C.jsxs)("colgroup",{children:[(0,C.jsx)("col",{style:{width:"56px"}}),(0,C.jsx)("col",{className:"col-item"}),(0,C.jsx)("col",{style:{width:"90px"}}),(0,C.jsx)("col",{style:{width:"80px"}}),(0,C.jsx)("col",{style:{width:"220px"}}),(0,C.jsx)("col",{style:{width:"110px"}})]}),(0,C.jsx)("thead",{children:(0,C.jsxs)("tr",{className:"bom-col-header",children:[(0,C.jsx)("th",{"aria-label":"Expand"}),(0,C.jsx)("th",{style:{textAlign:"left"},children:"Description"}),(0,C.jsx)("th",{style:{textAlign:"center"},children:"Qty"}),(0,C.jsx)("th",{style:{textAlign:"center"},children:"Unit"}),(0,C.jsx)("th",{style:{textAlign:"center"},children:"Product Matched"}),(0,C.jsx)("th",{style:{textAlign:"center"},children:"Basket"})]})}),(0,C.jsx)("tbody",{children:vt.map(k=>{let{requirement:L,chosen:P}=k,pe=P?Ft(ue(k),Pd):null,xe=n?!!n.cart[$(L.key)]:!1,xt=Ue.has(L.key);return(0,C.jsxs)(Ge.Fragment,{children:[(0,C.jsxs)("tr",{className:"bom-row",children:[(0,C.jsx)("td",{className:"bom-actions",style:{textAlign:"center",paddingLeft:0,paddingRight:0},children:(0,C.jsx)("button",{type:"button",className:"link-btn",onClick:()=>Y(L.key),"aria-expanded":xt,"aria-label":xt?"Collapse product options":"Expand product options",children:xt?"\u25BE":"\u25B8"})}),(0,C.jsxs)("td",{style:{paddingLeft:0},children:[(0,C.jsx)("div",{className:"bom-component-name",children:L.label}),pe?.requiredSellUnits!=null&&(0,C.jsxs)("div",{className:"results-row-meta",children:["Order ",pe.requiredSellUnits," ",pe.sellUnit,pe.lineTotal!=null?` \xB7 ${lt(pe.lineTotal)}`:""]})]}),(0,C.jsx)("td",{className:"bom-qty col-order",style:{textAlign:"center"},children:yi(L.qty)}),(0,C.jsx)("td",{style:{textAlign:"center"},children:Sa(L.unit,L.qty)}),(0,C.jsx)("td",{style:{textAlign:"center"},children:P?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)("div",{className:"bom-component-name",children:P.description}),(0,C.jsxs)("div",{className:"results-row-meta",children:[P.product_id,P.price!=null&&` \xB7 ${gc(P.price,P.price_basis)}`]})]}):(0,C.jsx)("span",{className:"results-empty-hint",children:"No match"})}),(0,C.jsx)("td",{style:{textAlign:"center"},children:(0,C.jsx)("button",{type:"button",className:`bom-toolbar-btn${xe?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>N(k),disabled:!P||!n,children:xe?"\u2713 Added":"+ Add"})})]}),xt&&(0,C.jsx)("tr",{children:(0,C.jsx)("td",{colSpan:6,style:{paddingLeft:0,paddingRight:0},children:R===L.key?Z(k):(0,C.jsxs)("div",{className:"estimator-products__picker",children:[(0,C.jsxs)("div",{className:"estimator-products__options",children:[k.candidates.map(it=>(0,C.jsxs)("button",{type:"button",className:`estimator-products__option${it.product_id===P?.product_id?" is-selected":""}`,onClick:()=>Ae(L.key,it),children:[(0,C.jsx)("span",{children:it.description}),(0,C.jsxs)("span",{className:"results-row-meta",children:[it.product_id,it.price!=null&&` \xB7 ${lt(it.price)}`]})]},it.product_id)),k.candidates.length===0&&(0,C.jsx)("p",{className:"results-empty-hint",children:"No candidates found."})]}),(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ge(k),children:"Search the catalogue"})]})})})]},L.key)})})]})}),!O&&!m&&!y&&He.length>0&&(0,C.jsxs)("section",{className:"results-tile-section results-tile-section--unmatched","aria-label":"Items requiring matching",children:[(0,C.jsxs)("div",{className:"results-tile-section__head",children:[(0,C.jsx)("h3",{children:"Require Matching"}),(0,C.jsx)("p",{children:"We couldn\u2019t confidently match these to a product. Open one to pick from the closest options."})]}),(0,C.jsx)("div",{className:"results-unmatched-list",children:He.map(k=>(0,C.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>h(k),children:[(0,C.jsxs)("span",{className:"results-unmatched-card__main",children:[(0,C.jsx)("span",{className:"results-unmatched-card__title",children:k.requirement.label}),(0,C.jsxs)("span",{className:"results-row-meta",children:[yi(k.requirement.qty)," ",Sa(k.requirement.unit,k.requirement.qty)]})]}),(0,C.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},k.requirement.key))})]}),!m&&!y&&d.length>0&&(0,C.jsxs)("div",{className:"disclaimer-box",style:{alignItems:"center"},children:[(0,C.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,C.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."})]}),!O&&!m&&!y&&(r||E>0)&&(0,C.jsxs)("div",{className:"btn-row estimator-products__footer",children:[r&&(0,C.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:r,children:"Back"}),E>0&&n&&(0,C.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:r?"0 1 70%":1,marginTop:0},onClick:n.openBasket,children:[(0,C.jsxs)("span",{children:["View Basket (",E,")"]}),(0,C.jsx)("span",{className:"arrow",children:(0,C.jsx)(Qt,{})})]})]})]})}var Gt=G(ee());function Id({toolId:e,toolTitle:t,requirements:a,onBack:r}){let[i,n]=(0,bc.useState)(0),o=(0,bc.useCallback)(l=>n(l),[]);return(0,Gt.jsx)(Gt.Fragment,{children:(0,Gt.jsxs)("div",{className:"truss-estimator",children:[(0,Gt.jsxs)("div",{className:"quick-order-hero",children:[(0,Gt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Gt.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,Gt.jsx)("h1",{children:"Your Materials"}),i>0&&(0,Gt.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,Gt.jsx)("strong",{children:lt(i)})," Est. total"]})]}),(0,Gt.jsxs)("p",{children:["Quantities from the ",t,", matched against your merchant\u2019s catalogue."]})]}),(0,Gt.jsx)("div",{className:"truss-estimator__card",style:{minHeight:0},children:(0,Gt.jsx)(Jd,{toolId:e,requirements:a,ready:!0,onBack:r,onTotalChange:o})})]})})}var Fd=G(Xe());var Wt=G(ee()),sx=1500;function Lv(e){let{addManyToCart:t,clearCart:a,openBasket:r}=Un(),[i,n]=(0,Fd.useState)(!1),[o,l]=(0,Fd.useState)(null);return{adding:i,basketError:o,addToBasket:async(p,d)=>{let g=Date.now();n(!0),l(null);try{let m=await Promise.all(p.filter(y=>y.qty>0).map(async y=>{let T=(await fr(y.search)).find(D=>D.product_id===y.productId);if(!T)throw new Error("A selected product is no longer available in this catalogue.");return Pr(T,{lineId:`${e}:${y.key}`,description:T.description,unit:Ad(y.unit??"each",T),qty:y.qty,calculatorWasteIncluded:d})})),b=sx-(Date.now()-g);b>0&&await new Promise(y=>window.setTimeout(y,b)),a(),t(m),r()}catch(m){l(m instanceof Error?m.message:"Could not add the products to your basket.")}finally{n(!1)}}}}function Hv({toolTitle:e}){return(0,Wt.jsx)(Wt.Fragment,{children:(0,Wt.jsxs)("div",{className:"truss-estimator",children:[(0,Wt.jsxs)("div",{className:"quick-order-hero",children:[(0,Wt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Wt.jsx)("h1",{children:"Your Materials"}),(0,Wt.jsxs)("p",{children:["Calculating quantities from the ",e,"."]})]}),(0,Wt.jsx)("div",{className:"truss-estimator__card",children:(0,Wt.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{flex:1,justifyContent:"center"},children:[(0,Wt.jsx)(dr,{}),(0,Wt.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})})}var Re=G(ee());function wc(e){let[t,a]=(0,Xa.useState)(!1);return(0,Re.jsx)(ec,{onOpenBasket:()=>a(!0),children:(0,Re.jsx)(cx,{...e,showBasket:t,onShowBasket:a})})}function cx({fullPage:e=!1,hideHeader:t=!1,internal:a=!1,showBasket:r,onShowBasket:i}){let[n,o]=(0,Xa.useState)(null),[l,c]=(0,Xa.useState)(null),p=Kd.find(A=>A.id===n),{cart:d,updateCartQty:g,updateCartSellUnits:m,updateCartConversions:b,removeFromCart:y,clearCart:T}=Un(),{adding:D,basketError:f,addToBasket:u}=Lv(p?.title??"calculator"),w=(0,Xa.useRef)(null),v=Ys("estimating-tools",w);(0,Xa.useEffect)(()=>{v("viewed")},[v]);let S=r?"basket":D?"adding":l?"review":n??"list",R=(0,Xa.useRef)(S);(0,Xa.useEffect)(()=>{R.current!==S&&(R.current=S,window.scrollTo(0,0))},[S]);let z=A=>{if(!p)return;v("estimate_completed",{calculator:p.id,lines:A.length});let Q=_v(p.id,A);Q?u(Q,A[0]?.calculatorWasteIncluded??!1):c(A)};return(0,Re.jsx)(Po.Provider,{value:v,children:(0,Re.jsx)("div",{ref:w,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${a?"":" estimating-tools--customer"}`,style:jt().theme,children:(0,Re.jsx)("main",{className:"main-content",children:r?(0,Re.jsx)(ol,{cart:d,onUpdateQty:g,onUpdateSellUnits:m,onResolveConversions:b,onRemove:y,onBack:()=>i(!1),onStartNewQuote:()=>{T(),o(null),c(null),i(!1)},internal:a}):D&&p?(0,Re.jsx)(Hv,{toolTitle:p.title}):p?(0,Re.jsxs)(Re.Fragment,{children:[(0,Re.jsx)("div",{hidden:l!==null,children:(0,Re.jsx)(p.Component,{onBack:()=>o(null),onReview:z})}),f&&(0,Re.jsx)("p",{className:"results-empty-hint estimator-products__error",children:f}),l!==null&&(0,Re.jsx)(Id,{toolId:p.id,toolTitle:p.title,requirements:l,onBack:()=>c(null)})]}):(0,Re.jsx)(Re.Fragment,{children:(0,Re.jsxs)("div",{className:"quick-order-card",children:[(0,Re.jsxs)("div",{className:"quick-order-hero",children:[(0,Re.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,Re.jsx)("h1",{children:"Estimating Tools"}),(0,Re.jsx)("p",{children:"Trade-specific calculators for trusses, fencing, decking, masonry and painting. Dial in your specs and get an instant material estimate."})]}),(0,Re.jsxs)("div",{className:"quick-order-alt",children:[(0,Re.jsx)("div",{className:"quick-order-alt-title",children:"Choose a Calculator"}),(0,Re.jsx)("div",{className:"estimator-tools-grid",children:Kd.map(A=>(0,Re.jsxs)("button",{type:"button",className:"estimator-tool-card",onClick:()=>{v("calculator_selected",{calculator:A.id}),o(A.id),c(null)},children:[(0,Re.jsx)("span",{className:"estimator-tool-card__image-wrap",children:(0,Re.jsx)("img",{className:"fill-img estimator-tool-card__image",src:It(A.imageUrl),alt:""})}),(0,Re.jsxs)("span",{className:"estimator-tool-card__content",children:[(0,Re.jsx)("span",{className:"estimator-tool-card__title",children:A.title}),(0,Re.jsx)("span",{className:"estimator-tool-card__desc",children:A.desc})]})]},A.id))})]})]})})})})})}var vc=G(ee());function Wd({config:e,children:t}){return rw(e),(0,vc.jsx)(vc.Fragment,{children:t})}var em=G(ee()),ux="https://api.metronlabs.ai",px=["client","api-key","api-url","theme","hide-header","analytics"],dx=["all","events-only","none"];function Qv(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.53",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; }
6970
6987
  :host > div { all: initial; display: block; }
6971
6988
  ${aw}`,this.shadowRoot.replaceChildren(n,i),this.root=(0,jv.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")||ux,client:i,apiKey:n,theme:fx(e,this.getAttribute("theme")),analytics:mx(this.getAttribute("analytics"))};this.root.render((0,em.jsx)(Wd,{config:o,children:(0,em.jsx)(t,{hideHeader:this.hasAttribute("hide-header")})}))}},a.observedAttributes=px,a))}function mx(e){return dx.find(t=>t===e)??"all"}function fx(e,t){if(t)try{return JSON.parse(t)}catch{console.error(`<${e}> theme attribute isn't valid JSON; using the default colours.`);return}}Qv("metron-labs-quick-quote",ac);Qv("metron-labs-estimating-tools",wc);
6972
6989
  /*! Bundled license information: