@metron-labs/quote-react 0.1.64 → 0.1.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/embed/quote.js +1 -1
- package/package.json +1 -1
package/dist/embed/quote.js
CHANGED
|
@@ -6990,7 +6990,7 @@ C24 timber 4.8m`,value:p,onChange:Z=>m(Z.target.value),"aria-label":"Paste sched
|
|
|
6990
6990
|
<rect x="168" y="188" width="250" height="24" rx="12" fill="#aab5c0"/>
|
|
6991
6991
|
<rect x="168" y="232" width="220" height="24" rx="12" fill="#aab5c0"/>
|
|
6992
6992
|
</svg>
|
|
6993
|
-
`)}function zn(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 bv=e=>(e??"").trim().toLowerCase(),S_={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",piece:"each",pieces:"each",board:"sheet",bags:"bag",length:"length",lengths:"length",pallet:"pallet",pallets:"pallet"},Ed=new Set(["sheet","length","box","bag","pack","roll","set","tub","each"]),mv=new Set(["box","bag","pack","pallet","roll","set","tub"]),Md=(e,t)=>t==="ml"?e:["l","litre","litres"].includes(t)?e*1e3:null,Td=(e,t)=>t==="g"?e:["kg","kilogram","kilograms"].includes(t)?e*1e3:["t","tonne","tonnes"].includes(t)?e*1e6:null,dr=e=>{let t=bv(e);return S_[t]??t},rt=(e,t)=>{let a=dr(e),r=dr(t);return a.length>0&&a===r},fv=(e,t)=>{let a=bv(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},N_=e=>(e??"").split(",").map(t=>dr(t)).filter(Boolean),C_=(e,t)=>{let a=N_(e.requestUomsSupported);return!!(a.length===0||a.includes(t)||rt(t,"pallet")&&e.itemsPerPallet!=null&&e.itemsPerPallet>0||rt(t,"pack")&&e.itemsPerPack!=null&&e.itemsPerPack>0||rt(t,"box")&&e.itemsPerBox!=null&&e.itemsPerBox>0)},hv=(e,t)=>rt(t,"pallet")?e.itemsPerPallet??null:rt(t,"pack")?e.itemsPerPack??null:rt(t,"box")?e.itemsPerBox??null:null,gv=(e,t)=>{let a=t==="volume"?/(\d+(?:[.,]\d+)?)\s*(ml|l|ltr|ltrs|litres?|liters?)\b/i:/(\d+(?:[.,]\d+)?)\s*(kg|kgs|tonnes?)\b/i,r=e.description.match(a);if(!r)return null;let i=Number.parseFloat(r[1].replace(",","."));if(!Number.isFinite(i)||i<=0)return null;let n=r[2].toLowerCase();return t==="volume"?{ml:n==="ml"?i:i*1e3}:{g:n.startsWith("tonne")?i*1e6:i*1e3}},q_=["volume_from_description","same_unit_volume"],E_=["weight_from_description","mass_from_pack","same_unit_mass"],M_=(e,t,a)=>{if(!rt(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||!rt(r[3],a))return null;let i=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(i)&&i>0?i:null};function ic(e,t){let a=e.map(r=>It(r,t).lineTotal);return a.some(r=>r==null)?null:a.reduce((r,i)=>r+(i??0),0)}function It(e,t){let a=e.qty,r=dr(e.saleUnit??e.salesUnitSizeUom??e.uoi??e.salesUomNormalised)||"-",i=dr(e.unit)||(a>0&&Ed.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?Ed.has(r)?Math.ceil(e.sellUnitsOverride):e.sellUnitsOverride:null,p=A=>({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?`${A} Manually set to ${c} ${r}.`:A,costingMode:"review"});if(!Number.isFinite(a)||a<=0)return p("Quantity needs confirmation.");let m=Md(a,i),g=Td(a,i),d=rt(i,r)?null:m!=null&&!q_.includes(e.conversionType??"")?gv(e,"volume"):g!=null&&!E_.includes(e.conversionType??"")?gv(e,"weight"):null,b=d?.ml!=null?m:g,_=d?.ml??d?.g??null;if(b!=null&&_!=null){let A=dr(e.uoi)||r,j=d?.ml!=null?`${_/1e3} l`:`${_/1e3} kg`,ie=l?c:Math.ceil(b*(1+o)/_-1e-9);return{requestedAmount:a,requestedUnit:i,salesUnitSize:1,sellUnit:A,calculatedSellUnits:ie,requiredSellUnits:ie,unitPrice:e.price,lineTotal:e.price!=null?e.price*ie:null,calculation:`${a} ${i}${o>0?` x ${1+o}`:""} / ${j} per ${A} (from product description) = ${ie} ${A}`,costingMode:"derived"}}if(i==="sales_unit"){let A=dr(e.uoi)||r,j=l?c:fv(a*(1+o),e.roundingRule??"round_up_each");return{requestedAmount:a,requestedUnit:A,salesUnitSize:1,sellUnit:A,calculatedSellUnits:j,requiredSellUnits:j,unitPrice:e.price,lineTotal:e.price!=null?e.price*j:null,calculation:`${a} ${A}${o>0?` x ${1+o}`:""} = ${j} ${A}`,costingMode:"direct"}}if(!C_(e,i))return p("Requested unit is not supported by this catalogue conversion.");let M=null,O="review",f=e.roundingRule,u=`Quantity review required, initial request needed ${a} ${i}.`,h=1+o,w=M_(e,i,r),k=e.unitConversions?.find(A=>rt(A.requestUom,i));if(!!e.saleUnit&&(rt(i,r)||!!k||rt(i,"each")&&!mv.has(r)))if(rt(i,r))M=a*h/n,O="direct",u=`${a} ${i}${o>0?` x ${h}`:""}`;else if(k){M=a*h/k.quantityPerSaleUnit,O="derived";let A=1/k.quantityPerSaleUnit,j=Math.round(A);u=rt(r,"each")&&k.quantityPerSaleUnit<1&&Math.abs(A-j)<1e-9?`${a} ${i}${o>0?` x ${h}`:""} x ${j} per ${i}`:`${a} ${i}${o>0?` x ${h}`:""} / ${k.quantityPerSaleUnit} ${i} per ${r}`}else rt(i,"each")&&!mv.has(r)&&(M=a*h/n,O="derived",u=`${a} ${r}${o>0?` x ${h}`:""}`);else if(rt(i,r)&&n>0)M=a*h/n,O="direct",u=o>0?`${a} ${i} x ${h} / ${n} ${r} per sell unit`:`${a} ${i} / ${n} ${r} per sell unit`;else if(rt(i,"each")&&n>0&&Ed.has(r))M=a*h/n,O="derived",u=o>0?`${a} each x ${h} / ${n} each per ${r}`:`${a} each / ${n} each per ${r}`;else if(hv(e,i)!=null&&n>0){let A=hv(e,i)??0;M=a*A*h/n,O="derived";let j=`${a} ${i} x ${A} each${o>0?` x ${h}`:""}`;u=n===1&&rt(r,"each")?j:`${j} / ${n} each per ${r}`}else if(w!=null)M=a*h/w,O="derived",f??(f="round_up_each"),u=`${a} m2 x ${h} / ${w} m2 per ${r} (from product description)`;else if(e.conversionType==="basket_line_unit")n>0&&(M=a*h/n,O="derived",u=`${a} ${i}${o>0?` x ${h}`:""} / ${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 A=e.coverageQty??e.derivedCoverageM2??null;rt(i,"m2")&&A!=null&&A>0&&(M=a*h/A,O="derived",u=`${a} m2 x ${h} / ${A} m2 per ${r}`)}else if(e.conversionType==="count_per_area"){let A=e.coverageQty??null;rt(i,"m2")&&A!=null&&A>0?(M=a/A,O="derived",u=`${a} m2 / ${A} m2 per sell unit`):rt(i,"m2")&&e.itemsPerM2!=null&&e.itemsPerM2>0&&n>0&&(M=a*e.itemsPerM2*h/n,O="derived",u=`${a} m2 x ${e.itemsPerM2} ${r}/m2 x ${h} / ${n}`)}else if(e.conversionType==="length_from_dims"){let A=e.coverageQty??e.derivedLengthM??null;rt(i,"m")&&A!=null&&A>0&&(M=a*h/A,O="derived",u=`${a} m x ${h} / ${A} m per ${r}`)}else if(e.conversionType==="volume_from_description"){let A=Md(a,i),j=Md(e.coverageQty??0,dr(e.coverageUom));A!=null&&j!=null&&j>0&&(M=A*h/j,O="derived",u=`${a} ${i} x ${h} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="weight_from_description"||e.conversionType==="mass_from_pack"){let A=dr((e.coverageUom??"").split(" ")[0]),j=Td(a,i),ie=Td(e.coverageQty??0,A);j!=null&&ie!=null&&ie>0&&(M=j*h/ie,O="derived",u=`${a} ${i} x ${h} / ${e.coverageQty} ${A} per ${r}`)}else if(e.conversionType==="same_unit_volume"){let A=e.coverageQty??null;rt(i,"m3")&&A!=null&&A>0&&(M=a/A,O="derived",u=`${a} m3 / ${A} m3 per ${r}`)}}if(M==null||!Number.isFinite(M)||M<0)return p(`Quantity review required, initial request needed ${a} ${i}.`);let z=fv(M,f),U=l?c:z;return{requestedAmount:a,requestedUnit:i,salesUnitSize:n,sellUnit:r,calculatedSellUnits:z,requiredSellUnits:U,unitPrice:e.price,lineTotal:e.price!=null&&U!=null?e.price*U:null,calculation:l?`${u} = ${z} ${r} (manually set to ${U})`:`${u} = ${U} ${r}`,costingMode:O}}var wv=()=>import("./xlsx-K4MOA2QM.js"),il=["Source Line ID","Split Line ID","Description","Section","Qty","Unit","Procurement intent","Procurement aliases","Build-up type","Layer count","Total thickness (mm)","Installation clues","System clues","Component requirements","Technical classification","Include in quote","Approval required","Approval type","Missing information","Adjudicator confidence","Decision reason","Selected candidate ID","Selected candidate description","Price basis","Price","Line total","Confidence","Status"],T_=il.indexOf("Line total");function z_(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 vv(e){let t=await wv(),a=t.utils.book_new(),r=new Date().toISOString().slice(0,10),i=[il],n=0;for(let c of e){let{item:p,best:m,qty:g,band:d,unmatchable:b,decision:_}=c,M=[p.section,p.subsection,p.subheading].filter(Boolean).join(" / "),O=!b&&m?.price!=null?m.price*g:null;O!=null&&(n+=O),i.push([p.source_line_id,p.line_id,p.description_original||"(no description)",M,g,p.unit,p.procurement_intent||"-",p.procurement_aliases.join(", "),p.build_up_type,p.layer_count,p.total_required_thickness_mm,p.installation_clues.join(", "),p.system_clues.join(", "),p.component_requirements.join(", "),_?.technical_classification??"",_?.include_in_quote==null?"":_.include_in_quote?"yes":"no",_?.approval_required==null?"":_.approval_required?"yes":"no",_?.approval_type??"",_?.missing_information.join(", ")??"",_?.confidence??"",_?.reason??"",b?"-":m?.product_id??_?.selected_candidate_id??"-",b?"-":m?.description??"-",b?"-":m?.price_basis??"-",b?null:m?.price??null,O,b?"-":d,z_(c)])}i.push(Array(il.length).fill(null));let o=Array(il.length).fill(null);o[0]="Estimated total",o[T_]=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(il.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 rl=["Product ID","Description","Costing mode","Required amount","Req unit","Sell unit size","Sell unit","Required sell units","Unit price","Line total"];async function yv(e,t){let a=await wv(),r=a.utils.book_new(),i=new Date().toISOString().slice(0,10),n=t?[["Account",t.name+" ("+t.id+")"],[],rl]:[rl],o=0;for(let p of e){let m=It(p),g=m.lineTotal;g!=null&&(o+=g),n.push([p.productId,p.description,m.costingMode,m.requestedAmount,xa(m.requestedUnit),m.salesUnitSize,xa(m.sellUnit),m.requiredSellUnits,m.unitPrice,g])}n.push(Array(rl.length).fill(null));let l=Array(rl.length).fill(null);l[0]="Estimated total",l[rl.length-1]=o,n.push(l);let c=a.utils.aoa_to_sheet(n);c["!cols"]=[{wch:14},{wch:48},{wch:12},{wch:14},{wch:10},{wch:14},{wch:10},{wch:16},{wch:12},{wch:14}],a.utils.book_append_sheet(r,c,"Basket"),a.writeFile(r,t?`basket-${t.id}-${i}.xlsx`:`basket-${i}.xlsx`)}var s=X(ee()),Rd="__none__",nl=24,R_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}];function Sv(e){return e==null?"low":e>=.7?"high":e>=.5?"medium":"low"}var A_=e=>e.attrs.supply_nature==="labour_only"||e.attrs.supply_nature==="plant"||e.flags.includes("referential");function U_(e,t){if(t!==Rd){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 _v(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 D_(e){return e?e.replace(/_/g," "):"not stated"}function O_({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 An(e,t){if(e==null)return"-";let a=al(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function Ad(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 Rn(e){let t=(e??[]).map(a=>a.trim()).filter(Boolean);return t.length>0?t.join(", "):"-"}function Xr(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 L_(e,t){return t>0||e==null?null:ot(e)}var xv=[{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 H_(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:xv[i%xv.length]})}),t}function mr(e){return!1}function Un(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 zd({meta:e}){return e?(0,s.jsx)("span",{className:"results-linked-pill",style:e.bubbleStyle,children:`Link ${e.token}`}):null}function j_(e,t,a){let r=t?.rerank?.recommendedCandidateIds??[];if(r.length===0){let o=e.slice(0,6),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,6)}function nc(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 oc(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 Q_({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:oc(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:oc(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:oc(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:oc(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 G_({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:Ad(r.measurements_mm)}),(0,s.jsx)("td",{children:al(r.price_basis)||"-"}),(0,s.jsx)("td",{children:r.bm25.toFixed(2)})]},`${r.product_id}-${i}`))})]})]},`${t.query}-${a}`))]})}function kv({item:e,result:t}){let a=t?.retrieval_debug.map(i=>i.query).filter(Boolean)??[],r=[["Procurement intent",e.procurement_intent||"-"],["Procurement aliases",Rn(e.procurement_aliases)],["Retrieval queries",Rn(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)",Ad(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",Rn(e.installation_clues)],["System clues",Rn(e.system_clues)],["Component requirements",Rn(e.component_requirements)],["Linked group",Un(e)||"-"],["Flags",Rn(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)(xe.Fragment,{children:[(0,s.jsx)("dt",{children:i}),(0,s.jsx)("dd",{children:n})]},i))})]})}function Y_({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)(xe.Fragment,{children:[(0,s.jsx)("dt",{children:"Attempted"}),(0,s.jsx)("dd",{children:t.attempted?"yes":"no"})]}),(0,s.jsxs)(xe.Fragment,{children:[(0,s.jsx)("dt",{children:"Applied"}),(0,s.jsx)("dd",{children:t.applied?"yes":"no"})]}),(0,s.jsxs)(xe.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned items"}),(0,s.jsx)("dd",{children:t.returned_item_count??"-"})]}),(0,s.jsxs)(xe.Fragment,{children:[(0,s.jsx)("dt",{children:"Reason"}),(0,s.jsx)("dd",{children:t.reason||"-"})]}),(0,s.jsxs)(xe.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 $_({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)(xe.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 V_({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} - `:"",Un(e)]}):null]}):null:!t.reason&&!r?(0,s.jsx)(kv,{item:e,result:a}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(kv,{item:e,result:a}),r&&(0,s.jsx)(Y_,{item:e}),r&&(0,s.jsx)($_,{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} - `:"",Un(e)]}):null]}),r&&(0,s.jsx)(G_,{queries:a?.retrieval_debug??[]})]})}function X_({item:e,candidates:t,result:a,decision:r,unmatchable:i,selectedProductId:n,detailMode:o,onPick:l,onClear:c,showAll:p=!1,internal:m=!1,debugEnabled:g=!1,forceReviewNote:d=!1,linkedGroupMeta:b}){let _=m||o==="detailed",M=g&&o==="detailed",O=_||d?(0,s.jsx)(V_,{item:e,decision:r,result:a,showRetrievalDebug:M,reviewOnly:d&&!_,linkedGroupMeta:b}):null;if(i)return(0,s.jsxs)(s.Fragment,{children:[O,(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:[O,(0,s.jsx)("p",{className:"results-empty-hint",children:"No candidates were returned for this line item."})]});let f=p||m||o==="detailed"?t:j_(t,a,n);return(0,s.jsxs)(s.Fragment,{children:[O,(0,s.jsxs)("table",{className:"score-breakdown-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Product"}),(0,s.jsx)("th",{children:"Dims (mm)"}),(0,s.jsx)("th",{children:"Price"}),M&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("th",{children:"dimension"}),(0,s.jsx)("th",{children:"grade"}),(0,s.jsx)("th",{children:"brand"}),(0,s.jsx)("th",{children:"fuzzy"}),(0,s.jsx)("th",{children:"bm25"}),(0,s.jsx)("th",{children:"overall"})]}),(0,s.jsx)("th",{"aria-label":"Actions"})]})}),(0,s.jsx)("tbody",{children:f.map((u,h)=>{let w=u.product_id===n;return(0,s.jsxs)("tr",{className:w?"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:Ad(u.measurements_mm??u.debug?.candidate.measurements_mm)})}),(0,s.jsx)("td",{children:An(u.price,u.price_basis)}),M&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("td",{children:(u.scores?.dimension??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.grade??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.brand??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.fuzzy??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.bm25??0).toFixed(2)}),(0,s.jsx)("td",{children:(0,s.jsxs)("div",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[(0,s.jsx)(O_,{band:Sv(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:w?"Currently selected":"Use this candidate",children:[(0,s.jsx)("input",{type:"checkbox",checked:w,onChange:()=>{w?c?.():l(u)},"aria-label":w?`${u.description} selected`:`Use ${u.description}`}),(0,s.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},`${u.product_id}-${h}`)})})]})]})}function Ud({scheduleResult:e,onStartOver:t,cart:a,onAddToCart:r,onRemoveFromCart:i,onGoToBasket:n,cartSeeded:o,onCartSeeded:l,reviewGateComplete:c,onReviewGateComplete:p,internal:m=!1}){let g=!m&&Ks()==="QZA6-MRA4",d=g?"quote":"basket",{results:b,lineItems:_,parseReport:M,timings:O}=e,[f,u]=(0,xe.useState)({}),h=Nn(),[w,k]=(0,xe.useState)({}),[R,z]=(0,xe.useState)({}),[U,A]=(0,xe.useState)(""),[j,ie]=(0,xe.useState)(null),[qe,Ke]=(0,xe.useState)(1),Oe=Ot().debug===!0,[Me,ge]=(0,xe.useState)("simple"),[le,Ve]=(0,xe.useState)(m?"list":"tile"),[Te,ct]=(0,xe.useState)(!1),[Z,be]=(0,xe.useState)(null),[Re,wt]=(0,xe.useState)(""),[Gt,Ct]=(0,xe.useState)([]),[vt,we]=(0,xe.useState)(!1),[de,tt]=(0,xe.useState)(null),[T,Q]=(0,xe.useState)(!1),[ne,ue]=(0,xe.useState)(null),ve=(0,xe.useRef)(null),[Ye,Ce]=(0,xe.useState)(new Set),[S,y]=(0,xe.useState)(new Set),[E,D]=(0,xe.useState)(!1);(0,xe.useEffect)(()=>{Ke(1)},[U,j,le]);let V=new Map(b.map(x=>[x.line_id,x])),N=H_(_),L=_.map(x=>{let G=V.get(x.line_id),fe=G?.decision,ut=A_(x),Xe=f[x.line_id],ea=U_(G,Xe),Ti=a[x.line_id],d0=Xe===Rd?void 0:w[x.line_id]??(Ti&&Ti.productId!==ea?.product_id?_v(Ti):ea),wm=ut?void 0:d0,m0=x.qty??0;return{item:x,result:G,decision:fe,unmatchable:ut,best:wm,qty:m0,band:Sv(wm?.scores?.overall)}}),se=L.some(x=>!x.unmatchable&&!x.best&&!S.has(x.item.line_id))?null:ic(Object.values(a),{wasteFactorEnabled:!1,wasteFactorOverride:0}),ke=0;for(let x of L){if(x.unmatchable||x.decision?.include_in_quote!==!0||!x.best)continue;let G=a[x.item.line_id];(!G||It(G).lineTotal==null)&&(ke+=1)}ke>0&&(se=null);let yt=L_(se,ke),at=x=>!x.unmatchable&&!x.best&&x.decision?.technical_classification!=="no_suitable_candidate"&&nc(x.result).length>0,qt=x=>x.best??nc(x.result)[0],Kr=L.filter(x=>!x.unmatchable&&!x.best).filter(x=>!S.has(x.item.line_id)),Cc=L.filter(x=>S.has(x.item.line_id)),Yt=L;if(U.trim()){let x=U.trim().toLowerCase();Yt=Yt.filter(G=>G.item.description_original?.toLowerCase().includes(x)||qt(G)?.description?.toLowerCase().includes(x))}if(j){let x=j==="asc"?1:-1;Yt=[...Yt].sort((G,fe)=>x*(G.item.description_original||"").localeCompare(fe.item.description_original||""))}let hr=Math.max(1,Math.ceil(Yt.length/nl)),_t=Math.min(qe,hr),qi=Yt.slice((_t-1)*nl,_t*nl),um=qi.filter(x=>!x.unmatchable&&x.best),Dx=qi.filter(x=>at(x)),qc=qi.filter(x=>!x.unmatchable&&(x.best||at(x))),pm=qi.filter(x=>x.unmatchable||!x.best&&!at(x)),P=Z?L.find(x=>x.item.line_id===Z)??null:null,n0=!m&&!c&&!P&&Kr.length>0,$n=(0,xe.useRef)(null),Vn=()=>{let x=ve.current;if(!x)return;let{top:G,left:fe,width:ut,height:Xe}=x.getBoundingClientRect(),Ti=x.querySelector(".bom-toolbar-btn")?.closest("td")?.getBoundingClientRect().left;ue({top:G,left:fe,width:Ti?Ti-fe:ut,height:Xe})};(0,xe.useEffect)(()=>(window.addEventListener("scroll",Vn,!0),window.addEventListener("resize",Vn),()=>{window.removeEventListener("scroll",Vn,!0),window.removeEventListener("resize",Vn)})),(0,xe.useEffect)(()=>{let x=G=>{$n.current&&!G.composedPath().includes($n.current)&&$n.current.removeAttribute("open")};return document.addEventListener("click",x),()=>document.removeEventListener("click",x)},[]);let Ei=x=>{be(x),wt("")},o0=()=>{if(!Z)return;let x=a[Z];if(x){u(G=>({...G,[Z]:x.productId})),k(G=>({...G,[Z]:_v(x)}));return}u(G=>{let fe={...G};return delete fe[Z],fe}),k(G=>{let fe={...G};return delete fe[Z],fe})},Va=(x=!1)=>{let G=Z?a[Z]:void 0;!x&&G&&P?.best&&G.productId!==P.best.product_id&&!window.confirm("You have selected a new product. Leave without updating it?")||(x||o0(),be(null),D(!1))};el(T,()=>Q(!1)),el(!!P&&!T,()=>Va());let l0=x=>{if(Ce(G=>new Set(G).add(x)),Kr.some(G=>G.item.line_id!==x)){Va(!0);return}p(),Va(!0)},s0=x=>{if(Ec(x),y(G=>new Set(G).add(x)),Kr.some(G=>G.item.line_id!==x)){Va(!0);return}p(),Va(!0)},c0=()=>{y(x=>new Set([...x,...Kr.map(G=>G.item.line_id)])),p()},dm=()=>{P?.best&&(fm(P.item.line_id,P.best),r(Xn(P)),E?l0(P.item.line_id):Va(!0))},mm=pm.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:pm.map(x=>{let{item:G,qty:fe}=x;return(0,s.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>Ei(G.line_id),children:[(0,s.jsx)("span",{className:"results-unmatched-card__main",children:(0,s.jsx)("span",{className:"results-unmatched-card__title",children:Xr(G,_)})}),(0,s.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},G.line_id)})})]}):null,Ec=x=>{u(G=>({...G,[x]:Rd})),k(G=>({...G,[x]:void 0})),z(G=>({...G,[x]:void 0})),i(x)},Mc=(x,G)=>{u(fe=>({...fe,[x]:G.product_id})),k(fe=>({...fe,[x]:G}))},fm=(x,G)=>{G.method==="catalogue_search"&&z(fe=>({...fe,[x]:G}))};function Ox(){h("downloaded",{type:"schedule",lines:L.length}),vv(L.map(({item:x,best:G,qty:fe,band:ut,unmatchable:Xe,decision:ea})=>({item:x,best:G,qty:fe,band:ut,unmatchable:Xe,decision:ea})))}function Xn(x){let G=x.best??nc(x.result)[0];return zn(G,{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?_.filter(fe=>fe.linked_group_id===x.item.linked_group_id&&fe.linked_group_role==="anchor").slice(0,1).map(fe=>{let ut=a[fe.line_id];return{line_id:fe.line_id,product_id:ut?.productId??null,measurements_mm:ut?.measurementsMm??fe.attrs.measurements_mm,description:ut?.description??fe.description_original,qty:fe.qty,unit:fe.unit,role:"anchor"}}):void 0})}(0,xe.useEffect)(()=>{if(!o){for(let x of L)!x.unmatchable&&x.best&&r(Xn(x));l()}},[o]),(0,xe.useEffect)(()=>{if(!Z){Ct([]),tt(null),we(!1);return}let x=Re.trim();if(!x){Ct([]),tt(null),we(!1);return}let G=!1,fe=window.setTimeout(async()=>{try{we(!0),tt(null);let ut=await fetch(za(`/api/catalogue/search?q=${encodeURIComponent(x)}`),{headers:hi()}),Xe=await Qa(ut);if(!ut.ok)throw new Error(Xe?.error||Xe?.message||"Failed to search catalogue");G||Ct(Array.isArray(Xe?.items)?Xe.items:[])}catch(ut){G||(Ct([]),tt(ut?.message||"Failed to search catalogue"))}finally{G||we(!1)}},250);return()=>{G=!0,window.clearTimeout(fe)}},[Re,Z]);let Tc=Object.keys(a).length,qa=Re.trim(),zc=nc(P?.result),fl=P?.decision?.technical_classification==="no_suitable_candidate"||!!P&&!P.best,hm=P?.decision?.technical_classification!=null,gm=P?.decision?.reason??(fl?"No catalogue candidate found. Refine the request or search the catalogue.":null),u0=Gt.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"})),Zn=qa?u0:zc,Mi=P?R[P.item.line_id]:void 0,Kn=!qa&&Mi&&!Zn.some(x=>x.product_id===Mi.product_id)?[...Zn,Mi]:Zn,bm=(()=>{let x=Kn.slice(0,qa?12:6);return qa||!Mi||x.some(G=>G.product_id===Mi.product_id)?x:[...x,Mi]})(),hl=!!P?.best&&a[P.item.line_id]?.productId===P.best.product_id,p0=!!P?.best&&!!a[P.item.line_id]&&!hl;return(0,s.jsxs)("div",{className:"wizard-step entry-stage",children:[(0,s.jsxs)("div",{className:`quick-order-card${m?"":" quick-order-card--customer"}`,children:[(0,s.jsx)("div",{className:`quick-order-hero${m?"":" quick-order-hero--customer"}`,children:m?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,s.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,s.jsx)("h1",{children:"Your Results"}),(0,s.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,s.jsx)("strong",{children:yt??"Review quantities"})," Est. total"]})]}),(0,s.jsx)("p",{children:"Each line item from your schedule matched against your catalogue, ranked by confidence."})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{children:"Review your matched products"}),(0,s.jsxs)("p",{children:["Check you're happy with these items, then click ",g?"View Quote":"View Basket"," to continue."]})]}),(0,s.jsxs)("button",{type:"button",className:"results-total-action",onClick:n,disabled:Tc===0,"aria-label":g?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:g?"View Quote":"View Basket"}),yt!=null&&(0,s.jsx)("strong",{children:yt})]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(jt,{})})]})]})}),(0,s.jsxs)("div",{className:"quick-order-panel",style:{paddingTop:16},children:[Oe&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:12},children:(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn","aria-pressed":Te,onClick:()=>ct(x=>!x),children:Te?"Hide timings":"Show timings"})}),Oe&&Te&&(0,s.jsx)(Q_,{...O}),!g&&(0,s.jsx)("div",{className:"results-toolbar-row",children:!P&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:0},children:(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:U,onChange:x=>A(x.target.value),"aria-label":"Search line items"}),!m&&(0,s.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,s.jsx)("button",{type:"button",className:`results-view-toggle__btn${le==="tile"?" is-active":""}`,"aria-pressed":le==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>Ve("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${le==="list"?" is-active":""}`,"aria-pressed":le==="list","aria-label":"List view",title:"List view",onClick:()=>Ve("list"),children:(0,s.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,s.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,s.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,s.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),Oe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ge(x=>x==="simple"?"detailed":"simple"),children:Me==="detailed"?"Hide detailed view":"Show detailed view"}),(0,s.jsxs)("details",{ref:$n,style:{position:"relative"},children:[(0,s.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort line items",style:{fontSize:16},children:"\u21C5"}),(0,s.jsx)("div",{className:"sort-menu-panel",children:R_.map(x=>{let G=j===x.dir;return(0,s.jsxs)("button",{type:"button",className:`sort-menu-item${G?" is-active":""}`,onClick:()=>{ie(G?null:x.dir),$n.current?.removeAttribute("open")},children:[(0,s.jsx)("span",{className:"sort-menu-item__check",children:G?"\u2713":""}),x.label]},x.dir)})})]})]})})}),le==="tile"||P?(0,s.jsxs)(s.Fragment,{children:[P?(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)(Io,{})}),(0,s.jsx)("div",{className:"results-review-page",children:m?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"results-review-page__top",children:[(0,s.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:()=>Va(),children:[(0,s.jsx)(Vr,{}),"Back to results"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[Oe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ge(x=>x==="simple"?"detailed":"simple"),children:Me==="detailed"?"Hide detailed info":"Show detailed info"}),(0,s.jsx)("div",{className:"results-review-searchbar",children:(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:Re,onChange:x=>wt(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:()=>Ec(P.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(qt(P)?.description||P.item.description_original,qt(P)?.product_id,qt(P)?.pdp_photo_url),alt:""})}),(0,s.jsxs)("div",{className:"results-review-page__summary",children:[(0,s.jsx)("h2",{children:Xr(P.item,_)}),(0,s.jsxs)("p",{className:"results-review-page__meta",children:[wi(P.qty)," ",ka(P.item.unit,P.qty)]}),P.best?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:P.best.description}),P.best.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:An(P.best.price,P.best.price_basis)}):null]}):qt(P)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:qt(P)?.description}),qt(P)?.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:An(qt(P)?.price??null,qt(P)?.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(P.item)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[(0,s.jsx)(zd,{meta:N.get(P.item.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:Un(P.item)})]}):null,(0,s.jsx)("div",{className:"results-review-page__actions",children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[P.item.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[P.item.line_id]?i(P.item.line_id):(P.best&&fm(P.item.line_id,P.best),r(Xn(P)))},disabled:!P.best,"aria-label":a[P.item.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[P.item.line_id]?"\u2713 Added":m?"+ Add to selection":`Add to ${d}`})})]})]}),vt?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,!vt&&de?(0,s.jsx)("div",{className:"results-empty-card",children:de}):null,!vt&&!de&&qa&&Zn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No candidate products match this database search."}):!vt&&!de?(0,s.jsx)(X_,{item:P.item,candidates:Zn,result:P.result,decision:P.decision,unmatchable:P.unmatchable,selectedProductId:P.best?.product_id??null,detailMode:Me,linkedGroupMeta:mr(P.item)?N.get(P.item.linked_group_id):void 0,onPick:x=>Mc(P.item.line_id,x),onClear:()=>Ec(P.item.line_id),showAll:m||Oe||qa.length>0,internal:m,debugEnabled:Oe,forceReviewNote:!0}):null]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("section",{className:"customer-review-request",children:[(0,s.jsx)("span",{className:"customer-review-eyebrow",children:"Original request"}),(0,s.jsx)("strong",{children:Xr(P.item,_)||"Original request"})]}),gm?(0,s.jsxs)("section",{className:"customer-review-ai",children:[(0,s.jsx)("strong",{children:fl?"No automatic match:":"AI review:"})," ",gm]}):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:fl?zc.length>0?"Choose a product":"No suitable product found":hm?"Choose a product":"We couldn't review this item"}),(0,s.jsx)("p",{children:fl?zc.length>0?"No product was selected automatically. Review these related options before adding one.":"Search the catalogue to choose an alternative.":hm?`Select the option you want to add to your ${d}.`:"Search the catalogue to choose a product."})]})}),!qa&&Kn.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:bm.map(x=>{let G=x.product_id===P.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${G?" is-selected":""}`,onClick:()=>Mc(P.item.line_id,x),"aria-pressed":G,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${An(x.price,x.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:G?"Selected":"Choose"})]},x.product_id)})}):null,Kn.length>0&&(0,s.jsx)("div",{className:"customer-review-divider",children:(0,s.jsx)("span",{children:"or"})}),(0,s.jsxs)("label",{className:"customer-review-search",children:[(0,s.jsx)("span",{children:"Search our full catalogue"}),(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products...",value:Re,onChange:x=>wt(x.target.value),"aria-label":"Search catalogue"})]}),qa&&vt?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,qa&&!vt&&de?(0,s.jsx)("div",{className:"results-empty-card",children:de}):null,qa&&!vt&&!de&&Kn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No products match this search."}):null,qa&&!vt&&!de&&Kn.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:bm.map(x=>{let G=x.product_id===P.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${G?" is-selected":""}`,onClick:()=>Mc(P.item.line_id,x),"aria-pressed":G,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${An(x.price,x.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:G?"Selected":"Choose"})]},x.product_id)})}):null]}),P.best?p0?(0,s.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,s.jsx)("button",{type:"button",className:"cta-btn customer-review-add",onClick:()=>{dm()},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(P.item.line_id),children:(0,s.jsx)("span",{children:`Remove from ${d}`})})]}):(0,s.jsx)("button",{type:"button",className:`cta-btn customer-review-add${hl?" cta-btn-secondary":""}`,onClick:()=>{hl?i(P.item.line_id):dm()},children:(0,s.jsx)("span",{children:hl?`Remove from ${d}`:`Add selected product to ${d}`})}):null,E?(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-skip",onClick:()=>s0(P.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,qc.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:qc.map(x=>{let{item:G,best:fe,qty:ut}=x,Xe=qt(x),ea=!fe&&at(x);return(0,s.jsxs)("article",{className:"results-tile-card",children:[(0,s.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>Ei(G.line_id),"aria-label":`Review match for ${Xr(G,_)||"item"}`,children:[(0,s.jsxs)("div",{className:"results-tile-card__media",children:[ea||mr(G)?(0,s.jsxs)("div",{className:"results-tile-card__badges",children:[mr(G)?(0,s.jsx)(zd,{meta:N.get(G.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(Xe?.description||G.description_original,Xe?.product_id,Xe?.pdp_photo_url),alt:""})]}),(0,s.jsxs)("div",{className:"results-tile-card__body",children:[Xe?(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:Xe.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:Xe?(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:Xr(G,_)}),mr(G)?(0,s.jsx)("div",{className:"results-row-meta",children:Un(G)}):null]}):(0,s.jsx)("span",{className:"results-empty-hint",children:"No matched product selected."})})]}),(0,s.jsx)("span",{className:"results-tile-card__hover-prompt","aria-hidden":"true",children:"Click to view options"})]}),(0,s.jsxs)("div",{className:"results-tile-card__actions",children:[m&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ei(G.line_id),children:"Review"}),(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[G.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[G.line_id]?i(G.line_id):r(Xn(x))},disabled:!Xe,"aria-label":a[G.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[G.line_id]?"\u2713 Added":m?"+ Add":`Add to ${d}`})]})]},G.line_id)})})}):null,mm]})]}):(0,s.jsxs)(s.Fragment,{children:[ne&&(0,s.jsx)("div",{className:"results-table__hover-overlay",style:ne,"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"}}),Me==="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"}),Me==="simple"&&(0,s.jsx)("th",{style:{textAlign:"center"},children:m?"Selection":g?"Quote":"Basket"})]})}),(0,s.jsxs)("tbody",{children:[Yt.length===0&&(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:Me==="simple"?4:3,className:"results-empty-hint",style:{padding:"16px 8px"},children:"No line items match the current search/filter."})}),qc.map(x=>{let{item:G,result:fe,decision:ut,best:Xe}=x;return(0,s.jsxs)("tr",{className:"bom-row results-table__review-row",onClick:()=>Ei(G.line_id),onMouseEnter:ea=>{ve.current=ea.currentTarget,Vn()},onMouseLeave:()=>{ve.current=null,ue(null)},children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{className:"bom-component-name",children:Xr(G,_)}),mr(G)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,s.jsx)(zd,{meta:N.get(G.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:Un(G)})]}):null]}),(0,s.jsx)("td",{children:Xe?(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"results-match-cell-text",title:Xe.description,children:Xe.description}),Me==="detailed"&&ut?.technical_classification&&(0,s.jsxs)("div",{className:"results-row-meta",children:[D_(ut.technical_classification),ut.approval_required?" - approval required":""]})]}):(0,s.jsx)("span",{className:"results-empty-hint"})}),(0,s.jsx)("td",{style:{textAlign:"center"},children:Xe?.price!=null?An(Xe.price,Xe.price_basis):"-"}),Me==="simple"&&(0,s.jsx)("td",{style:{textAlign:"center"},children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[G.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,style:{width:84,justifyContent:"center"},onClick:ea=>{ea.stopPropagation(),a[G.line_id]?i(G.line_id):r(Xn(x))},"aria-label":a[G.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[G.line_id]?"\u2713 Added":m?"+ Add":`Add to ${d}`})})]},G.line_id)})]})]})}),mm]}),!P&&hr>1&&(0,s.jsxs)("div",{className:"results-pagination",children:[(0,s.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(_t-1)*nl+1,"\u2013",Math.min(_t*nl,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:()=>Ke(_t-1),disabled:_t===1,children:"Previous"}),(0,s.jsxs)("span",{className:"results-pagination-page",children:["Page ",_t," of ",hr]}),(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ke(_t+1),disabled:_t===hr,children:"Next"})]})]}),(M.itemCount!=null||M.headingCount!=null||M.skippedCount!=null)&&(0,s.jsxs)("div",{className:"results-summary",style:{marginTop:16},children:[M.itemCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.itemCount})," items parsed"]}),M.headingCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.headingCount})," headings"]}),M.skippedCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.skippedCount})," rows skipped"]})]}),(0,s.jsxs)("div",{className:"disclaimer-box",children:[(0,s.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,s.jsx)("p",{className:"disclaimer-text",children:"These matches are generated automatically and should be reviewed before purchase."})]}),!P&&(0,s.jsxs)("div",{className:"btn-row results-actions",children:[(0,s.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",gap:10,justifyContent:"center"},onClick:()=>Q(!0),"aria-label":"Start over",children:[(0,s.jsx)(Cd,{}),(0,s.jsx)("span",{children:"Start Over"})]}),(0,s.jsxs)("button",{className:"cta-btn",style:{flex:"0 1 70%"},onClick:n,disabled:Tc===0,"aria-label":m?"View selection":g?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[m?"View Selection":g?"View Quote":"View Basket"," (",Tc,")"]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(jt,{})})]})]})]})]}),n0&&(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:Kr.map(x=>{let G=Ye.has(x.item.line_id),fe=at(x);return(0,s.jsx)("div",{className:`review-gate-item${G?" is-reviewed":""}`,children:(0,s.jsxs)("button",{type:"button",className:"review-gate-item__review",onClick:()=>{D(!0),Ei(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Xr(x.item,_)}),(0,s.jsx)("span",{children:x.decision?.reason||(fe?"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:G?"Choice made":"Choose a product"})]})},x.item.line_id)})}),(0,s.jsx)("button",{type:"button",className:"review-gate-skip",onClick:c0,children:"Skip all"}),Cc.length>0?(0,s.jsxs)("div",{className:"review-gate-skipped",children:[(0,s.jsx)("strong",{children:"Skipped"}),Cc.map(x=>(0,s.jsxs)("button",{type:"button",className:"review-gate-item is-skipped",onClick:()=>{y(G=>{let fe=new Set(G);return fe.delete(x.item.line_id),fe}),D(!0),Ei(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Xr(x.item,_)}),(0,s.jsx)("span",{children:`Not added to your ${d}.`})]}),(0,s.jsx)("span",{className:"review-gate-item__action",children:"Choose a product"})]},x.item.line_id))]}):null]})}),T&&(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:()=>Q(!1),children:"Cancel"}),(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-danger",onClick:()=>{Q(!1),t()},autoFocus:!0,children:"Start Over"})]})]})})]})}var ht=X(je());var At=X(je()),Cv=X(ee());function Dn(e){return JSON.stringify([e.productId,e.qty,e.unit,e.linkedContext??[]])}function Z_(e,t){let a={...e,[t.lineId]:t};for(let[r,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 Dd=(0,At.createContext)(null);function lc({children:e,onOpenBasket:t}){let[a,r]=(0,At.useState)({}),i=(0,At.useCallback)(d=>{r(b=>Z_(b,d))},[]),n=(0,At.useCallback)(d=>{r(b=>{let _={...b};for(let M of d)_[M.lineId]=M;return _})},[]),o=(0,At.useCallback)(d=>{r(b=>{let _={...b};return delete _[d],_})},[]),l=(0,At.useCallback)((d,b)=>{r(_=>_[d]?{..._,[d]:{..._[d],qty:b,sellUnitsOverride:null}}:_)},[]),c=(0,At.useCallback)((d,b)=>{r(_=>_[d]?{..._,[d]:{..._[d],sellUnitsOverride:b}}:_)},[]),p=(0,At.useCallback)(d=>{r(b=>{let _=!1,M={...b};for(let[O,f]of Object.entries(d))M[O]&&(M[O]={...M[O],...f},_=!0);return _?M:b})},[]),m=(0,At.useCallback)(()=>r({}),[]),g=(0,At.useMemo)(()=>({cart:a,count:Object.keys(a).length,addToCart:i,addManyToCart:n,removeFromCart:o,updateCartQty:l,updateCartSellUnits:c,updateCartConversions:p,clearCart:m,openBasket:t??(()=>{})}),[a,i,n,o,l,c,p,m,t]);return(0,Cv.jsx)(Dd.Provider,{value:g,children:e})}function On(){let e=(0,At.useContext)(Dd);if(!e)throw new Error("useCart must be used inside a <CartProvider>");return e}function Nv(){return(0,At.useContext)(Dd)}var q=X(ee()),qv=.2,ol=10,Ev="Enter a valid email address so we can send your quote.",K_=(e,t)=>{let a=`${t.requestedAmount} ${xa(t.requestedUnit,t.requestedAmount)}`,r=`${t.requiredSellUnits} ${xa(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)} ${xa(t.sellUnit,2)} per ${xa(t.requestedUnit,1)})`:e.coverageQty&&/^m per /i.test(e.coverageUom??"")?`${a} requested \u2192 order ${r} (${e.coverageQty} ${e.coverageUom})`:`${a} requested \u2192 order ${r}`},P_=e=>["box","pack"].includes(e.requestedUnit)?"Pack size needed to calculate the order quantity.":`This product is sold by ${xa(e.sellUnit,1)}.`;function J_(){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 ll(){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 sl({cart:e,onUpdateQty:t,onUpdateSellUnits:a,onResolveConversions:r,onRemove:i,onBack:n,onStartNewQuote:o,onQuoteRequested:l,internal:c=!1}){let p=(0,ht.useId)(),m=!c&&Ks()==="QZA6-MRA4",g=!c,d=Object.values(e),[b,_]=(0,ht.useState)(""),[M,O]=(0,ht.useState)(!1),[f,u]=(0,ht.useState)(!1),h=Nn(),[w,k]=(0,ht.useState)(""),[R,z]=(0,ht.useState)({}),[U,A]=(0,ht.useState)({}),[j,ie]=(0,ht.useState)(1),[qe,Ke]=(0,ht.useState)({}),[Oe,Me]=(0,ht.useState)(!1),[ge,le]=(0,ht.useState)("0"),[Ve,Te]=(0,ht.useState)({}),ct=(0,ht.useRef)(new Map);(0,ht.useEffect)(()=>{if(!r)return;for(let D of Object.values(e))It(D).requiredSellUnits!=null&&ct.current.delete(D.lineId);let y=Object.values(e).filter(D=>{if(D.productId==="-"||It(D).requiredSellUnits!=null)return!1;let V=Dn(D);return ct.current.get(D.lineId)===V?!1:(ct.current.set(D.lineId,V),!0)});if(y.length===0)return;let E=new Map(y.map(D=>[D.lineId,Dn(D)]));Te(D=>({...D,...Object.fromEntries(E)})),fetch(za("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Cn()},body:JSON.stringify({lines:y.map(D=>({line_id:D.lineId,product_id:D.productId,requested_description:D.requestedDescription??D.description,requested_qty:D.qty,requested_uom:D.unit||null,linked_context:D.linkedContext??[],selected_description:D.description,selected_uoi:D.uoi,selected_uoi_count:D.uoiCount,selected_conversion:{sales_uom_normalised:D.salesUomNormalised,conversion_type:D.conversionType,sales_unit_size:D.salesUnitSize,sales_unit_size_uom:D.salesUnitSizeUom,coverage_qty:D.coverageQty,coverage_uom:D.coverageUom}}))})}).then(D=>D.ok?Qa(D):null).then(D=>{let V={},N=new Map(y.map(L=>[L.lineId,Dn(L)]));for(let L of D?.data?.items??D?.items??[]){let $=L?.conversion;if(!$||typeof L?.line_id!="string"||ct.current.get(L.line_id)!==N.get(L.line_id))continue;let se=e[L.line_id];V[L.line_id]={conversionType:$.conversion_type,requestUomsSupported:$.request_uoms_supported,salesUomNormalised:$.sales_uom_normalised,salesUnitSize:$.sales_unit_size,salesUnitSizeUom:$.sales_unit_size_uom,coverageQty:$.coverage_qty,coverageUom:$.coverage_uom,roundingRule:$.rounding_rule,conversionConfidence:$.conversion_confidence,conversionNotes:$.conversion_notes,...se?.qty===0&&Number.isFinite($.suggested_order_qty)&&$.suggested_order_qty>0?{qty:$.suggested_order_qty,unit:$.suggested_order_uom||se.unit}:{}}}Object.keys(V).length>0&&r(V)}).catch(D=>console.error("Catalogue conversion resolution failed",D)).finally(()=>{Te(D=>{let V={...D};for(let[N,L]of E)V[N]===L&&delete V[N];return V})})},[e,r]);function Z(y){z(E=>{let D={...E};return delete D[y],D})}function be(y,E){let D=parseFloat(E);!isNaN(D)&&D>=0&&t(y,Math.min(D,1e5)),Z(y)}function Re(y,E,D){t(y,Math.min(1e5,Math.max(0,E+D))),Z(y)}function wt(y){A(E=>{let D={...E};return delete D[y],D})}function Gt(y,E){let D=parseFloat(E);!isNaN(D)&&D>=0&&a(y,Math.min(D,1e5)),wt(y)}function Ct(y,E,D){a(y,Math.min(1e5,Math.max(0,E+D))),wt(y)}async function vt(){if(we.some(({pricing:E})=>E.lineTotal==null)){k(m?"Confirm the highlighted quantities before requesting a quote.":"Confirm the highlighted quantities before sending your basket.");return}let y=b.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(y)){k(Ev);return}k(""),u(!0);try{let E=await fetch(za("/api/quote-requests"),{method:"POST",headers:{"Content-Type":"application/json",...Cn()},body:JSON.stringify({email:y,items:we.map(({item:D,pricing:V})=>{let N=V.requiredSellUnits??V.requestedAmount,L=V.requiredSellUnits!=null?V.sellUnit:V.requestedUnit;return{product_id:D.productId,description:D.description,quantity:N,unit:xa(L,N),unit_price:V.requiredSellUnits!=null?V.unitPrice:null,line_total:V.lineTotal}})})});if(!E.ok){let D=await Qa(E);console.error("Quote request failed",E.status,D?.message),k(E.status===429?"You've sent a few requests already. Please try again in a few minutes.":"Your request couldn't be sent. Please try again, or contact us if it keeps happening.");return}T!=null&&h("quote_requested",{items:we.length,total:Math.round(T*100)/100}),O(!0),l?.(),window.scrollTo(0,0)}catch{k("Your request couldn't be sent. Check your connection and try again.")}finally{u(!1)}}let we=d.map(y=>({item:y,pricing:It(y,{wasteFactorEnabled:Oe,wasteFactorOverride:Math.max(0,Number.parseFloat(ge)||0)/100})})),de=ic(d,{wasteFactorEnabled:Oe,wasteFactorOverride:Math.max(0,Number.parseFloat(ge)||0)/100}),tt=de==null?null:de*qv,T=de==null?null:de*(1+qv),Q=we.filter(({pricing:y})=>y.lineTotal==null).length,ne=Object.keys(Ve).length,ue=!!r&&d.some(y=>{if(y.productId==="-"||It(y).requiredSellUnits!=null)return!1;let E=Dn(y);return ct.current.get(y.lineId)!==E||Ve[y.lineId]===E}),ve=(0,ht.useRef)({items:we.length,...T==null?{}:{total:Math.round(T*100)/100}});(0,ht.useEffect)(()=>{h("basket_viewed",ve.current)},[h]);let Ye=Math.max(1,Math.ceil(we.length/ol)),Ce=Math.min(j,Ye),S=we.slice((Ce-1)*ol,Ce*ol);return M?(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:m?"Quote requested":"Basket sent"}),m?(0,q.jsxs)("p",{children:["You're all done. We'll email your sharper price to ",(0,q.jsx)("strong",{children:b.trim()}),", usually within one working day."]}):(0,q.jsxs)("p",{children:["You're all done. We'll email ",(0,q.jsx)("strong",{children:b.trim()})," to confirm prices, availability and delivery, usually within one working day."]}),(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,q.jsx)("span",{children:m?"Start a new quote":"Start a new basket"})}),(0,q.jsx)("p",{className:"quote-request-sent-note",children:m?"Nothing is charged until you approve the quote.":"Nothing is charged until you approve the order."})]})}):!c&&d.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:m?"Your quote request is empty":"Your basket is empty"}),(0,q.jsx)("p",{children:m?"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${m?" 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:[m&&(0,q.jsxs)("button",{type:"button",className:"cta-btn cta-btn-secondary basket-hero-back",onClick:n,children:[(0,q.jsx)(Vr,{}),(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":m?"Request a quote":"Your Basket"}),c&&(0,q.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,q.jsx)("strong",{children:d.length})," ",d.length===1?"item":"items"]})]}),(0,q.jsx)("p",{children:c?"Review the items you've added before exporting them for review.":m?"Check your items and quantities below, and we'll do our best to beat list prices.":"Review your quantities and order summary, then send us your basket."})]})]}),(0,q.jsx)("div",{className:"quick-order-panel",style:{paddingTop:16},children:ue?(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"})]}):d.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":m?"Quote request items":"Basket items",children:S.map(({item:y,pricing:E})=>{let D=R[y.lineId]??String(E.requestedAmount),V=E.requestedUnit===E.sellUnit||E.costingMode==="review",N=E.requiredSellUnits==null||E.requestedAmount!==E.requiredSellUnits||E.requestedUnit!==E.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(y.description,y.productId,y.pdpPhotoUrl),alt:"",width:48,height:48}),(0,q.jsxs)("div",{className:"basket-card-info",children:[(0,q.jsx)("div",{className:"bom-component-name",children:y.description}),N&&E.costingMode!=="review"&&(0,q.jsxs)("button",{type:"button",className:"basket-calc-toggle",onClick:()=>Ke(L=>({...L,[y.lineId]:!L[y.lineId]})),"aria-expanded":!!qe[y.lineId],children:["How we calculated this",(0,q.jsx)("span",{className:`basket-calc-toggle-chevron${qe[y.lineId]?" basket-calc-toggle-chevron--open":""}`,children:(0,q.jsx)(ll,{})})]})]}),(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(y.lineId),"aria-label":`Remove ${y.description}`,children:(0,q.jsx)(J_,{})})})]}),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:y.conversionType??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Conversion confidence"}),(0,q.jsx)("dd",{children:y.conversionConfidence??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Sales unit"}),(0,q.jsx)("dd",{children:y.salesUnitSize!=null?(0,q.jsxs)(q.Fragment,{children:[y.salesUnitSize," ",ka(y.salesUnitSizeUom,y.salesUnitSize)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Coverage"}),(0,q.jsx)("dd",{children:y.coverageQty!=null?(0,q.jsxs)(q.Fragment,{children:[y.coverageQty," ",ka(y.coverageUom,y.coverageQty)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Waste factor"}),(0,q.jsx)("dd",{children:y.wasteFactorDefault??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Rounding rule"}),(0,q.jsx)("dd",{children:y.roundingRule??"-"})]})]}),y.conversionNotes&&(0,q.jsx)("p",{className:"results-rerank-note",children:y.conversionNotes})]}),E.costingMode==="review"?(0,q.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,q.jsx)("strong",{children:Ve[y.lineId]===Dn(y)?"Calculating order quantity\u2026":"Quantity needs confirmation."})," ",P_(E)]}):N&&qe[y.lineId]?(0,q.jsx)("p",{className:"basket-calc-text",children:K_(y,E)}):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:D,disabled:V,onChange:L=>z($=>({...$,[y.lineId]:L.target.value})),onBlur:L=>be(y.lineId,L.target.value),onKeyDown:L=>{L.key==="Enter"&&L.target.blur()},"aria-label":`${y.description} requested quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",disabled:V,onClick:()=>Re(y.lineId,parseFloat(D)||0,1),"aria-label":`Increase ${y.description} quantity`,children:(0,q.jsx)(ll,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",disabled:V,onClick:()=>Re(y.lineId,parseFloat(D)||0,-1),"aria-label":`Decrease ${y.description} quantity`,children:(0,q.jsx)(ll,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:ka(E.requestedUnit,parseFloat(D)||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:U[y.lineId]??String(E.requiredSellUnits??""),onChange:L=>A($=>({...$,[y.lineId]:L.target.value})),onBlur:L=>Gt(y.lineId,L.target.value),onKeyDown:L=>{L.key==="Enter"&&L.target.blur()},"aria-label":`${y.description} order quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",onClick:()=>Ct(y.lineId,parseFloat(U[y.lineId]??String(E.requiredSellUnits??"0"))||0,1),"aria-label":`Increase ${y.description} order quantity`,children:(0,q.jsx)(ll,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",onClick:()=>Ct(y.lineId,parseFloat(U[y.lineId]??String(E.requiredSellUnits??"0"))||0,-1),"aria-label":`Decrease ${y.description} order quantity`,children:(0,q.jsx)(ll,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:ka(E.sellUnit,parseFloat(U[y.lineId]??String(E.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:E.lineTotal!=null?ot(E.lineTotal):"-"}),E.lineTotal!=null&&(0,q.jsx)("span",{className:"basket-metric-unit",children:"ex. VAT"})]})]})]})]},y.lineId)})}),Ye>1&&(0,q.jsxs)("div",{className:"results-pagination",children:[(0,q.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(Ce-1)*ol+1,"\u2013",Math.min(Ce*ol,we.length)," of ",we.length]}),(0,q.jsxs)("div",{className:"results-pagination-controls",children:[(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ie(Ce-1),disabled:Ce===1,children:"Previous"}),(0,q.jsxs)("span",{className:"results-pagination-page",children:["Page ",Ce," of ",Ye]}),(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ie(Ce+1),disabled:Ce===Ye,children:"Next"})]})]})]}),(0,q.jsxs)("aside",{className:"basket-sidebar",children:[(0,q.jsx)("div",{className:"basket-sidebar-title",children:m?"Quote request summary":"Order summary"}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:m?"List price (ex. VAT)":"Subtotal (ex. VAT)"}),(0,q.jsx)("span",{children:de==null?"To confirm":ot(de)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:"VAT (20%)"}),(0,q.jsx)("span",{children:tt==null?"To confirm":ot(tt)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row basket-sidebar-row--total",children:[(0,q.jsx)("span",{children:m?"List price (inc.\xA0VAT)":"Total"}),(0,q.jsx)("span",{children:T==null?"To confirm":ot(T)})]}),!m&&(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:Oe,onChange:y=>Me(y.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:ge,onChange:y=>le(y.target.value),disabled:!Oe,"aria-label":"Waste factor percent"}),(0,q.jsx)("span",{children:"%"})]})]})}),(0,q.jsx)("label",{htmlFor:`${p}-basket-reference`,className:"basket-sidebar-label",children:m?"Enter email for your sharper quote":g?"Your email":"Your reference (optional)"}),(0,q.jsx)("input",{id:`${p}-basket-reference`,type:g?"email":"text",className:"basket-sidebar-input",value:b,onChange:y=>{_(y.target.value),g&&k("")},placeholder:g?"you@example.com":"PO number or job reference","aria-invalid":g&&w===Ev,"aria-describedby":g&&w?`${p}-basket-reference-error`:void 0}),g&&w&&(0,q.jsx)("p",{id:`${p}-basket-reference-error`,className:"basket-quote-request-error",role:"alert",children:w}),g?(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:()=>{vt()},disabled:f||Q>0||ne>0,"aria-busy":f,children:(0,q.jsx)("span",{children:f?"Sending\u2026":m?"Request our best quote":"Send basket"})}):(0,q.jsx)("button",{className:"cta-btn",onClick:()=>{h("downloaded",{type:"basket",items:d.length}),yv(d)},"aria-label":"Download selection",children:(0,q.jsx)("span",{children:"Download Quote"})}),(0,q.jsxs)("p",{className:"basket-sidebar-disclaimer",children:[(0,q.jsx)("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),m?"This is a quote request, not an order. We'll confirm our best price, availability and delivery before you approve.":g?"Sending your basket isn't an order. We'll confirm prices, availability and delivery before you approve.":"Prices and availability are estimates and should be confirmed before procurement."]})]})]}),(0,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)(Vr,{}),(0,q.jsx)("span",{children:"Back to results"})]})})]})})]})})}var Sa=X(ee()),Bd="metron-quick-quote",F_=1440*60*1e3;function sc(e){return(0,Sa.jsx)(lc,{children:(0,Sa.jsx)(I_,{...e})})}function I_({fullPage:e=!1,hideHeader:t=!1,internal:a=!1}){let[r,i]=(0,De.useState)("entry"),[n,o]=(0,De.useState)(null),[l,c]=(0,De.useState)(""),p=(0,De.useRef)(null),m=(0,De.useRef)(0),[g,d]=(0,De.useState)(0),[b,_]=(0,De.useState)(null),[M,O]=(0,De.useState)(!1),{cart:f,addToCart:u,addManyToCart:h,removeFromCart:w,updateCartQty:k,updateCartSellUnits:R,updateCartConversions:z,clearCart:U}=On(),[A,j]=(0,De.useState)(!1),[ie,qe]=(0,De.useState)(null),Ke=()=>{qe(null);try{window.sessionStorage.removeItem(rc)}catch{}},Oe=(0,De.useRef)(null),Me=Zs("quick-quote",Oe);(0,De.useEffect)(()=>{Me("viewed")},[Me]);let[ge,le]=(0,De.useState)(!1);(0,De.useEffect)(()=>{uv();let we=window.location.hash,de=null;try{de=JSON.parse(window.sessionStorage.getItem(Bd)??"null")}catch{}if(de&&!(Date.now()-(de.savedAt??0)<F_)&&(de=null),de?.scheduleResult)o("schedule"),_(de.scheduleResult),O(de.reviewGateComplete),j(de.cartSeeded),h(Object.values(de.cart)),we==="#quote-request"?i("basket"):we==="#matched-products"&&i("results");else if(we==="#matched-products"||we==="#quote-request"){let tt=new URL(window.location.href);tt.hash="",Mn("replaceState",window.history.state,tt)}le(!0)},[]),(0,De.useEffect)(()=>{if(ge)try{b?window.sessionStorage.setItem(Bd,JSON.stringify({savedAt:Date.now(),scheduleResult:b,reviewGateComplete:M,cartSeeded:A,cart:f})):window.sessionStorage.removeItem(Bd)}catch{}},[ge,b,M,A,f]);let Ve=(0,De.useCallback)(we=>{if(typeof window>"u")return;let de=new URL(window.location.href);de.hash=we==="basket"?"quote-request":"matched-products";let tt=we==="results"&&(window.location.hash==="#matched-products"||window.location.hash==="#quote-request");Mn(tt?"replaceState":"pushState",{boqQuoteStage:we},de)},[]),Te=(0,De.useRef)(!1);(0,De.useEffect)(()=>{let we=()=>{Te.current=!1;let de=window.location.hash;de==="#quote-request"?i("basket"):de==="#matched-products"&&b?(o("schedule"),i("results")):i("entry")};return window.addEventListener("popstate",we),()=>window.removeEventListener("popstate",we)},[b]);let ct=(0,De.useCallback)(()=>{Ve("basket"),i("basket")},[Ve]),Z=(0,De.useCallback)(()=>{if(window.location.hash==="#quote-request"){if(Te.current)return;Te.current=!0,ac();return}i(b?"results":"entry")},[b]),be=(0,De.useRef)(r);(0,De.useEffect)(()=>{be.current!==r&&(be.current=r,window.scrollTo(0,0))},[r]);let Re=()=>{i("entry"),o(null),c(""),d(0),_(null),O(!1),U(),j(!1),Ke()},wt=(0,De.useCallback)(async(we,de,tt=!0)=>{let T=++m.current;c(""),d(0);let Q=0,ne=()=>{Q=Math.min(Q+1,3),d(Q)};try{let{jobId:ue}=await bw(we,de,tt);if(T!==m.current)return;let{promise:ve,cancel:Ye}=vw(()=>ww(ue),5e3,ne,"schedule");p.current=Ye;let Ce=await ve;if(Ce.status==="failed"||!Ce.result)throw new Error(Ce.error||"Failed to process schedule");let S=Ce.result.lineItems.length,y=Ce.result.results.filter(E=>E.candidates.length>0).length;Me("results_shown",{lines:S,matched:y,unmatched:S-y}),U(),j(!1),O(!1),_(Ce.result),Ve("results"),i("results")}catch(ue){if(T!==m.current)return;Me("error",{stage:"matching"}),c(ue?.message||"Failed to process schedule"),i("entry")}finally{T===m.current&&(p.current?.(),p.current=null)}},[Ve,Me,U]),Gt=(0,De.useCallback)(()=>{m.current++,p.current?.(),p.current=null},[]),Ct=(0,De.useCallback)(async(we,de,tt=!0)=>{if(!we.trim())return;o("schedule");let T=new File([we],"pasted-schedule.txt",{type:"text/plain"});await wt(T,de,tt)},[wt]),vt=(0,De.useCallback)(async we=>{o("schedule"),await wt(we)},[wt]);return(0,Sa.jsx)(Fo.Provider,{value:Me,children:(0,Sa.jsx)("div",{ref:Oe,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${!e&&r==="processing"?" app-wrapper--loading":""}`,style:Ot().theme,children:(0,Sa.jsxs)("main",{className:"main-content",children:[l&&(0,Sa.jsxs)("div",{className:"error-box",role:"alert",children:[(0,Sa.jsx)("strong",{children:"Error:"})," ",l]}),r==="entry"&&(0,Sa.jsx)(Sd,{onPasteSchedule:Ct,onUploadSchedule:vt,onEntryModeChange:o,draft:ie,onSubmitDraft:qe,onCancelMatch:Gt}),r==="results"&&n==="schedule"&&b&&(0,Sa.jsx)(Ud,{scheduleResult:b,onStartOver:Re,cart:f,onAddToCart:u,onRemoveFromCart:w,onGoToBasket:ct,cartSeeded:A,onCartSeeded:()=>j(!0),reviewGateComplete:M,onReviewGateComplete:()=>O(!0),internal:a}),r==="basket"&&(0,Sa.jsx)(sl,{cart:f,onUpdateQty:k,onUpdateSellUnits:R,onResolveConversions:z,onRemove:w,onBack:Z,onStartNewQuote:Re,onQuoteRequested:()=>{_(null),O(!1),j(!1),U(),Ke()},internal:a})]})})})}var $a=X(je());var yi=X(je());var Mv={"NZ4Y-ZMSQ":{"brick-block":{"brick-common":"105499","brick-engineering-red":"1654","brick-engineering-blue":"1723",block:"501","mortar-cement":"1762 cement","mortar-sand":"564 building sand"},skirting:{"skirting-chamfered":"1525","skirting-ogee":"135 primed mdf ogee","skirting-pencil-round":"892","skirting-torus":"1941"},architrave:{"architrave-ogee":"134 primed mdf ogee","architrave-pencil-round":"1896","architrave-square-edge":"118 primed mdf square","architrave-torus":"1531"},plasterboard:{standard:"1647",moisture:"11 moisture plasterboard",fire:"14 fire plasterboard",sound:"1769",screws:"131160",tape:"1766",adhesive:"108439"},paint:{"paint-emulsion":"157217"},"concrete-aggregate":{cement:"1762 cement","sharp-sand":"563",gravel:"571",mot:"569"},insulation:{"insulation-floor":"152187","insulation-ground":"442","insulation-wall":"147","insulation-roof":"442","insulation-loft":"152180"},timber:{studs:"1213",joists:"208",battens:"1729"},fencing:{"panels-boundary-0.9":"66 lap fence panel","panels-boundary-1.2":"1450","panels-boundary-1.5":"1449","panels-boundary-1.8":"1448","panels-skyline-1.8":"1475","concrete-intermediate-8":"40197","concrete-end-8":"40198","timber-post-6":"141411","timber-post-8":"1709",postcrete:"12142","gate-boundary":"1984","gate-skyline":"40002","gravel-boards":"40200"},decking:{"boards-summit":"24322",joists:"208",screws:"131079"},paving:{"surface-council":"1669","surface-raj":"12363","surface-brindle":"304","surface-charcoal":"296","surface-pea":"431","sub-base":"569",bedding:"563"}}};function cl(e,t){let a=Mv[Ot().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 vi(e,t){let a=Mv[Ot().client??""]?.[e];return!a||t in a}function Tv(e,t){let a=t.map(r=>{let i=cl(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 W=X(ee()),zv=[{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"}],cc=e=>Number.parseFloat(e)||0,Rv=(e,t)=>cc(e)*(t==="m"?1:.3048),Ld=(e,t)=>cc(e.quantity)*(2*Rv(e.height,t)+Rv(e.width,t)),W_=()=>({quantity:"1",width:"",height:""});function ex({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 Hd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,yi.useState)("m"),[n,o]=(0,yi.useState)({quantity:"1",width:"0.76",height:"1.98"}),[l,c]=(0,yi.useState)({quantity:"0",width:"1.52",height:"1.98"}),[p,m]=(0,yi.useState)([]),[g,d]=(0,yi.useState)("ogee"),[b,_]=(0,yi.useState)("2.4"),M=(k,R,z)=>{k(U=>({...U,[R]:z}))},O=Ld(n,r)+Ld(l,r)+p.reduce((k,R)=>k+Ld(R,r),0),f=cc(b)>0?Math.ceil(O/cc(b)):0,u=zv.find(k=>k.id===g)?.label??"",h=[{key:`architrave-${g}`,label:`Architrave (${u})`,qty:O,unit:"m",query:`${u} architrave`,category:"architrave"}],w=(k,R,z,U)=>(0,W.jsxs)("div",{className:"architrave-calculator__opening-row",children:[(0,W.jsx)("span",{children:k}),(0,W.jsx)("input",{"aria-label":`${k} quantity`,type:"number",min:"0",step:"1",value:R.quantity,onChange:A=>z("quantity",A.target.value)}),(0,W.jsx)("input",{"aria-label":`${k} width`,type:"number",min:"0",step:"0.01",value:R.width,onChange:A=>z("width",A.target.value)}),(0,W.jsx)("input",{"aria-label":`${k} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:A=>z("height",A.target.value)}),U?(0,W.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:U,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",{})]}),w("Single doors",n,(k,R)=>M(o,k,R)),w("Double doors",l,(k,R)=>M(c,k,R)),p.map((k,R)=>w(`Alternative door ${R+1}`,k,(z,U)=>m(A=>A.map((j,ie)=>ie===R?{...j,[z]:U}:j)),()=>m(z=>z.filter((U,A)=>A!==R)))),(0,W.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>m(k=>[...k,W_()]),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:zv.filter(k=>vi("architrave",`architrave-${k.id}`)).map(k=>(0,W.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g===k.id?" is-selected":""}`,onClick:()=>d(k.id),children:[(0,W.jsx)(ex,{profile:k.id}),(0,W.jsx)("div",{className:"truss-estimator__option-title",children:k.label}),(0,W.jsx)("div",{className:"truss-estimator__option-copy",children:k.blurb})]},k.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:[O.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?.(h),disabled:O<=0,children:a})]})]})]})})}var _i=X(je()),ae=X(ee()),Av=60,Uv=10,tx=.02,ax=.012,Dv=1,Ov=4,rx=1.33,ix=1440,nx=1600,Bn=e=>Number.parseFloat(e)||0,ox=(e,t=2)=>e.toFixed(t);function jd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,_i.useState)("brick"),[n,o]=(0,_i.useState)("engineering-red"),[l,c]=(0,_i.useState)("metric"),[p,m]=(0,_i.useState)(""),[g,d]=(0,_i.useState)(""),[b,_]=(0,_i.useState)(!0),M=l==="metric"?Bn(p)*Bn(g):Bn(p)*Bn(g)*.092903,f=M*(r==="brick"?Av:Uv),u=Math.ceil(f),w=M*(r==="brick"?tx:ax)*rx/(Dv+Ov),k=Math.ceil(w*Dv*ix),R=Math.ceil(w*Ov*nx),z=l==="metric"?M:M*10.7639,U=[{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-cement",label:"General purpose cement",qty:k,unit:"kg",query:"general purpose cement",category:"cement"},{key:"mortar-sand",label:"Building sand",qty:R,unit:"kg",query:"building sand",category:"aggregate"}]:[]],A=j=>{if(j===l)return;let ie=j==="imperial"?3.28084:.3048;m((Bn(p)*ie).toFixed(2)),d((Bn(g)*ie).toFixed(2)),c(j)};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:"Brick and Block Calculator"}),(0,ae.jsx)("p",{children:"Estimate masonry units, sand and cement for a wall."})]}),(0,ae.jsxs)("div",{className:"truss-estimator__card brick-calculator",children:[(0,ae.jsx)("h2",{className:"truss-estimator__step-title",children:"Wall area and masonry type"}),(0,ae.jsx)("p",{className:"truss-estimator__step-sub",children:"Pick brick or block and enter the wall dimensions for unit counts plus the cement and sand for the mortar."}),(0,ae.jsxs)("div",{className:"brick-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Masonry type"}),(0,ae.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["brick","Brick"],["block","Block"]].map(([j,ie])=>(0,ae.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===j?" is-selected":""}`,onClick:()=>i(j),children:[(0,ae.jsx)("div",{className:"truss-estimator__option-title",children:ie}),(0,ae.jsxs)("div",{className:"truss-estimator__option-copy",children:["Approx. ",j==="brick"?Av:Uv," per m\xB2"]})]},j))})]}),r==="brick"&&(0,ae.jsxs)("div",{className:"brick-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Brick type"}),(0,ae.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(([j,ie,qe])=>(0,ae.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n===j?" is-selected":""}`,onClick:()=>o(j),children:[(0,ae.jsx)("div",{className:"truss-estimator__option-title",children:ie}),(0,ae.jsx)("div",{className:"truss-estimator__option-copy",children:qe})]},j))})]}),(0,ae.jsxs)("div",{className:"brick-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,ae.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,ae.jsx)("button",{type:"button",className:l==="metric"?"is-selected":"",onClick:()=>A("metric"),children:"Metric"}),(0,ae.jsx)("button",{type:"button",className:l==="imperial"?"is-selected":"",onClick:()=>A("imperial"),children:"Imperial"})]}),(0,ae.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ae.jsxs)("label",{className:"truss-estimator__field",children:[(0,ae.jsxs)("span",{children:["Height (",l==="metric"?"m":"ft",")"]}),(0,ae.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:j=>m(j.target.value)})]}),(0,ae.jsxs)("label",{className:"truss-estimator__field",children:[(0,ae.jsxs)("span",{children:["Width (",l==="metric"?"m":"ft",")"]}),(0,ae.jsx)("input",{type:"number",min:"0",step:"0.01",value:g,onChange:j=>d(j.target.value)})]})]})]}),(0,ae.jsx)("div",{className:"brick-calculator__options",children:(0,ae.jsxs)("label",{className:"brick-calculator__checkbox",children:[(0,ae.jsx)("input",{type:"checkbox",checked:b,onChange:j=>_(j.target.checked)}),(0,ae.jsx)("span",{children:"Include mortar (cement and building sand, mixed 1:4)"})]})}),(0,ae.jsxs)("div",{className:"brick-calculator__totals",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ae.jsxs)("div",{className:"brick-calculator__result-grid",children:[(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Wall area"}),(0,ae.jsxs)("strong",{children:[ox(z)," ",l==="metric"?"m\xB2":"ft\xB2"]})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:r==="brick"?"Bricks":"Blocks"}),(0,ae.jsx)("strong",{children:u.toLocaleString("en-GB")})]}),b?(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Cement"}),(0,ae.jsxs)("strong",{children:[k," kg"]})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Building sand"}),(0,ae.jsxs)("strong",{children:[R," kg"]})]})]}):null]}),(0,ae.jsx)("p",{className:"brick-calculator__note",children:"Estimate based on standard nominal sizes and 10mm joints. Mortar is a general purpose 1:4 cement and sand mix; quantities are approximate, so confirm the specification before ordering."})]}),(0,ae.jsxs)("div",{className:"brick-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?.(U),disabled:M<=0,children:a})]})]})]})})}var xi=X(je()),I=X(ee()),lx=1.54,sx=1440,Qd=e=>Number.parseFloat(e)||0,Zr={mot:{label:"MOT Type 1",blurb:"Sub-base for patios and driveways",density:1.7,query:"MOT type 1"},"sharp-sand":{label:"Sharp sand",blurb:"Bedding and general groundwork",density:1.6,query:"sharp sand"},gravel:{label:"20mm gravel",blurb:"Drainage and landscaping",density:1.6,query:"20mm gravel"}};function Gd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,xi.useState)("m"),[n,o]=(0,xi.useState)(""),[l,c]=(0,xi.useState)(""),[p,m]=(0,xi.useState)(""),[g,d]=(0,xi.useState)("concrete"),[b,_]=(0,xi.useState)("mot"),M=r==="m"?1:.3048,O=Qd(n)*M*Qd(l)*M*Qd(p)*(r==="m"?.01:.0254),f=Zr[b],u=O*lx/7,h=u*sx,w=u*2,k=u*4,R=(U,A)=>Math.ceil(U*A*1e3),z=g==="concrete"?[{key:"cement",label:"General purpose cement",qty:Math.ceil(h),unit:"kg",query:"general purpose cement"},{key:"sharp-sand",label:"Sharp sand",qty:R(w,Zr["sharp-sand"].density),unit:"kg",query:Zr["sharp-sand"].query},{key:"gravel",label:"20mm gravel",qty:R(k,Zr.gravel.density),unit:"kg",query:Zr.gravel.query}]:[{key:b,label:f.label,qty:R(O,f.density),unit:"kg",query:f.query}];return(0,I.jsx)(I.Fragment,{children:(0,I.jsxs)("div",{className:"truss-estimator",children:[(0,I.jsxs)("div",{className:"quick-order-hero",children:[(0,I.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,I.jsx)("h1",{children:"Concrete and Aggregate Calculator"}),(0,I.jsx)("p",{children:"Calculate fixed site-mix concrete ingredients or aggregate bulk bags."})]}),(0,I.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,I.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose what you need"}),(0,I.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter the area and depth. The calculator works out the materials and adds them to your basket."}),(0,I.jsxs)("div",{className:"materials-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Material type"}),(0,I.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,I.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g==="concrete"?" is-selected":""}`,onClick:()=>d("concrete"),children:[(0,I.jsx)("div",{className:"truss-estimator__option-title",children:"Site-mixed concrete"}),(0,I.jsx)("div",{className:"truss-estimator__option-copy",children:"Cement, sharp sand and 20mm aggregate"})]}),(0,I.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g==="aggregate"?" is-selected":""}`,onClick:()=>d("aggregate"),children:[(0,I.jsx)("div",{className:"truss-estimator__option-title",children:"Aggregates"}),(0,I.jsx)("div",{className:"truss-estimator__option-copy",children:"MOT Type 1, sharp sand or 20mm gravel"})]})]})]}),g==="aggregate"&&(0,I.jsxs)("div",{className:"materials-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Aggregate type"}),(0,I.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.keys(Zr).map(U=>(0,I.jsxs)("button",{type:"button",className:`truss-estimator__option-card${b===U?" is-selected":""}`,onClick:()=>_(U),children:[(0,I.jsx)("div",{className:"truss-estimator__option-title",children:Zr[U].label}),(0,I.jsx)("div",{className:"truss-estimator__option-copy",children:Zr[U].blurb})]},U))})]}),(0,I.jsxs)("div",{className:"materials-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and depth"}),(0,I.jsxs)("div",{className:"materials-calculator__unit-row",children:[(0,I.jsx)("span",{children:"Units"}),(0,I.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,I.jsx)("button",{type:"button",className:r==="m"?"is-selected":"",onClick:()=>i("m"),children:"Metric"}),(0,I.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>i("ft"),children:"Imperial"})]})]}),(0,I.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,I.jsxs)("label",{className:"truss-estimator__field",children:[(0,I.jsxs)("span",{children:["Length (",r,")"]}),(0,I.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:U=>o(U.target.value)})]}),(0,I.jsxs)("label",{className:"truss-estimator__field",children:[(0,I.jsxs)("span",{children:["Width (",r,")"]}),(0,I.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:U=>c(U.target.value)})]})]}),(0,I.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,I.jsxs)("span",{children:["Depth (",r==="m"?"cm":"inches",")"]}),(0,I.jsx)("input",{type:"number",min:"0",step:"0.1",value:p,onChange:U=>m(U.target.value)})]})]}),(0,I.jsxs)("div",{className:"materials-calculator__totals",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Materials required"}),(0,I.jsx)("div",{className:"materials-calculator__result-grid",children:g==="concrete"?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"Cement"}),(0,I.jsxs)("strong",{children:[h.toFixed(0)," kg"]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"Sharp sand"}),(0,I.jsxs)("strong",{children:[w.toFixed(2)," m\xB3"]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"20mm aggregate"}),(0,I.jsxs)("strong",{children:[k.toFixed(2)," m\xB3"]})]})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:f.label}),(0,I.jsxs)("strong",{children:[O.toFixed(2)," m\xB3"]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"Approx. weight"}),(0,I.jsxs)("strong",{children:[(O*f.density).toFixed(2)," t"]})]}),(0,I.jsx)("div",{})]})}),(0,I.jsx)("p",{className:"materials-calculator__note",children:g==="concrete"?"Based on a 1:2:4 mix. Confirm the mix design for structural work.":"Figures are estimates. Confirm the specification and supplier quantities before ordering."})]}),(0,I.jsxs)("div",{className:"materials-calculator__actions",children:[(0,I.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,I.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(z),disabled:O<=0,children:a})]})]})]})})}var Ya=X(je());var B=X(ee()),Ln=12,Hn=8,uc=.56,Bv=.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}]}},ki=["range","grid","pictureFrame","substructure"],cx={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:""}},pc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),dc=(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),ux=(e,t,a,r)=>{let i=pc(e,t,a),n=pc(e,t,r),o=pc(a,r,e),l=pc(a,r,t);return i===0&&dc(e,t,a)||n===0&&dc(e,t,r)||o===0&&dc(a,r,e)||l===0&&dc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},Yd=(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)&&ux(e[r],i,e[n],e[(n+1)%e.length]))return!0}return!1};function $d({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ya.useState)(0),[n,o]=(0,Ya.useState)(cx),[l,c]=(0,Ya.useState)(1),[p,m]=(0,Ya.useState)({x:0,y:0}),[g,d]=(0,Ya.useState)(null),b=(0,Ya.useRef)(null),_=(0,Ya.useRef)(null),M=(0,Ya.useRef)(null),O=ki[r],f=n.range?Ra.ranges[n.range]:null,u=Ln/l,h=Hn/l,w=(Ln-u)/2,k=(Hn-h)/2,R=Math.max(-Ln,Math.min(Ln*2-u,w+p.x)),z=Math.max(-Hn,Math.min(Hn*2-h,k+p.y)),U=Number.parseFloat(n.quickLengthM),A=Number.parseFloat(n.quickWidthM),j=U>0&&A>0,ie=T=>Math.abs(T.reduce((Q,ne,ue)=>{let ve=T[(ue+1)%T.length];return Q+ne.x*ve.y-ve.x*ne.y},0))/2,qe=(T,Q)=>Math.hypot(Q.x-T.x,Q.y-T.y),Ke=n.isOutlineClosed?ie(n.points):0,Oe=n.isOutlineClosed?n.points.reduce((T,Q,ne)=>T+qe(Q,n.points[(ne+1)%n.points.length]),0):0,Me=n.isOutlineClosed?n.points.reduce((T,Q,ne)=>T+(n.wallSegments.has(ne)?0:qe(Q,n.points[(ne+1)%n.points.length])),0):0,ge=n.points.reduce((T,Q)=>({x:T.x+Q.x/n.points.length,y:T.y+Q.y/n.points.length}),{x:0,y:0}),le=n.points.length>1?(()=>{let T=n.points[0],Q=n.points[1],ne=qe(T,Q),ue=ne?-(Q.y-T.y)/ne:0,ve=ne?(Q.x-T.x)/ne:0,Ye=(T.x+Q.x)/2,Ce=(T.y+Q.y)/2,S=ue*(Ye-ge.x)+ve*(Ce-ge.y)>=0?1:-1;return{x:Ye+ue*uc*S,y:Ce+ve*uc*S}})():null,Te=(()=>{let T=n.range?Ra.ranges[n.range]:Ra.ranges.meridian,Q=n.deckSizeMode==="quick"?U*A:Ke,ne=n.deckSizeMode==="quick"?2*(U+A):Me,ue=n.direction==="diagonal"?Ra.wastage.diagonal:Ra.wastage.straight,ve=n.pictureFrame==="yes"?Ra.pictureFrame.extraWastage:0,Ce=Q/(T.boardWidthM+Ra.boardGapM)/T.boardLengthM,S=Math.ceil(Ce*(1+ue+ve)),y=Math.ceil(Q*30*(1+ue+ve)/200),E=Ra.joist.spacingOptions.find(N=>N.id===n.joistSpacing)??Ra.joist.spacingOptions[1],D=Q/E.spacingM,V=Math.ceil(D);return{range:T,area:Q,boardCount:S,screwBoxes:y,joistMetres:V,spacing:E}})(),ct=Te?[{key:`boards-${n.range??"meridian"}`,label:`Deck boards (${Te.range.label})`,qty:Math.round(Te.boardCount*Te.range.boardLengthM*100)/100,unit:"m",query:"timber decking board",category:"decking",calculatorWasteIncluded:!0},{key:"joists",label:"Treated C24 joists",qty:Te.joistMetres,unit:"m",query:"treated joist",category:"timber",calculatorWasteIncluded:!0},{key:"screws",label:"Green decking screws (200/box)",qty:Te.screwBoxes,unit:"box",query:"green decking screws",category:"fixings",calculatorWasteIncluded:!0}]:[],Z=()=>O==="range"?!!n.range:O==="grid"?n.deckSizeMode==="quick"?j:n.isOutlineClosed&&Ke>0:O==="pictureFrame"?!!n.pictureFrame&&!!n.direction:O==="substructure"?!!n.joistSpacing:!0,be=r===ki.length-1?a:"Next",Re=(T,Q,ne=!1)=>{let ue=M.current?.getBoundingClientRect();if(!ue)return null;let ve=ne?1:.25;return{x:Math.round(Math.max(R,Math.min(R+u,R+(T-ue.left)/ue.width*u))/ve)*ve,y:Math.round(Math.max(z,Math.min(z+h,z+(Q-ue.top)/ue.height*h))/ve)*ve}},wt=T=>{if(n.isOutlineClosed){let ne=T.target;if(ne!==T.currentTarget&&!ne.classList.contains("deck-outline__grid"))return;_.current={startX:T.clientX,startY:T.clientY,startViewX:R,startViewY:z},T.currentTarget.setPointerCapture(T.pointerId);return}if(n.drawMode!=="outline")return;let Q=Re(T.clientX,T.clientY,!0);Q&&(d(null),o(ne=>{let ue=[...ne.points,Q];return Yd(ue,!1)?{...ne,drawError:"Edges cannot cross. Choose another corner."}:{...ne,points:ue,drawError:""}}))},Gt=(T,Q)=>{if(!n.isOutlineClosed){T.stopPropagation(),Q===0&&n.points.length>=3&&o(ne=>({...ne,isOutlineClosed:!0,drawMode:"edges"}));return}T.stopPropagation(),b.current=Q,T.currentTarget.setPointerCapture(T.pointerId)},Ct=T=>{if(_.current){let ue=M.current?.getBoundingClientRect();if(!ue)return;let ve=_.current,Ye=ve.startViewX-(T.clientX-ve.startX)/ue.width*u,Ce=ve.startViewY-(T.clientY-ve.startY)/ue.height*h;m({x:Ye-w,y:Ce-k});return}!n.isOutlineClosed&&n.drawMode==="outline"&&d(Re(T.clientX,T.clientY,!0));let Q=b.current;if(Q===null)return;let ne=Re(T.clientX,T.clientY);ne&&o(ue=>{let ve=ue.points.map((Ye,Ce)=>Ce===Q?ne:Ye);return Yd(ve,!0)?{...ue,drawError:"Edges cannot cross. Move the corner to a different position."}:{...ue,points:ve,drawError:""}})},vt=T=>{_.current=null,b.current=null,T.currentTarget.hasPointerCapture(T.pointerId)&&T.currentTarget.releasePointerCapture(T.pointerId)},we=T=>{o(Q=>{let ne=new Set(Q.wallSegments);return ne.has(T)?ne.delete(T):ne.add(T),{...Q,wallSegments:ne}})},de=()=>{r===0?e():i(T=>T-1)},tt=()=>{Z()&&(r===ki.length-1?t?.(ct):i(T=>T+1))};return(0,B.jsx)(B.Fragment,{children:(0,B.jsxs)("div",{className:"truss-estimator",children:[(0,B.jsxs)("div",{className:"quick-order-hero",children:[(0,B.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,B.jsx)("h1",{children:"Decking Calculator"}),(0,B.jsx)("p",{children:"Estimate timber boards, joists and screws for your deck."})]}),(0,B.jsxs)("div",{className:"truss-estimator__card",children:[(0,B.jsxs)("div",{className:"truss-estimator__body",children:[O==="range"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",ki.length]}),(0,B.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your timber decking"}),(0,B.jsx)("p",{className:"truss-estimator__step-sub",children:"Both options are fixed, orderable pressure-treated timber boards."}),(0,B.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Ra.ranges).filter(([T])=>vi("decking",`boards-${T}`)).map(([T,Q])=>(0,B.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===T?" is-selected":""}`,onClick:()=>o(ne=>({...ne,range:T})),children:[(0,B.jsx)("div",{className:"truss-estimator__option-title",children:Q.label}),(0,B.jsx)("div",{className:"truss-estimator__option-copy",children:Q.blurb}),(0,B.jsxs)("div",{className:"truss-estimator__option-copy",children:[Q.boardLengthM,"m boards"]})]},T))})]}):null,O==="grid"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",ki.length]}),(0,B.jsx)("h2",{className:"truss-estimator__step-title",children:"Tell us your deck size"}),(0,B.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,B.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,B.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.deckSizeMode==="quick"?" is-selected":""}`,onClick:()=>o(T=>({...T,deckSizeMode:"quick"})),children:"Quick estimate"}),(0,B.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.deckSizeMode==="draw"?" is-selected":""}`,onClick:()=>o(T=>({...T,deckSizeMode:"draw",drawMode:"outline"})),children:"Draw your space"})]}),n.deckSizeMode==="quick"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,B.jsxs)("label",{className:"truss-estimator__field",children:[(0,B.jsx)("span",{children:"Length (m)"}),(0,B.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:n.quickLengthM,onChange:T=>o(Q=>({...Q,quickLengthM:T.target.value}))})]}),(0,B.jsxs)("label",{className:"truss-estimator__field",children:[(0,B.jsx)("span",{children:"Width (m)"}),(0,B.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:n.quickWidthM,onChange:T=>o(Q=>({...Q,quickWidthM:T.target.value}))})]})]}),(0,B.jsx)("div",{className:"truss-estimator__grid-hint",children:"For L-shaped decks, cut-outs, or sides against a wall, use Draw your space."}),j?(0,B.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,B.jsxs)("div",{children:[(U*A).toFixed(2)," m\xB2 deck"]}),(0,B.jsxs)("div",{children:[(2*(U+A)).toFixed(2)," m perimeter"]})]}):null]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)("div",{className:"truss-estimator__section-heading",children:"Draw your deck"}),(0,B.jsx)("p",{className:"truss-estimator__step-sub",children:"Click to add corners, then close the outline. Drag any handle to refine it."}),(0,B.jsxs)("div",{className:"deck-outline__toolbar",children:[n.isOutlineClosed?(0,B.jsxs)("div",{className:"deck-outline__summary",children:[(0,B.jsxs)("div",{children:[(0,B.jsx)("span",{children:"Deck area"}),(0,B.jsxs)("strong",{children:[Ke.toFixed(2)," m\xB2"]})]}),(0,B.jsxs)("div",{children:[(0,B.jsx)("span",{children:"Perimeter"}),(0,B.jsxs)("strong",{children:[Oe.toFixed(2)," m"]})]}),(0,B.jsxs)("div",{children:[(0,B.jsx)("span",{children:"Wall edges"}),(0,B.jsx)("strong",{children:n.wallSegments.size>0?n.wallSegments.size:"None"})]}),(0,B.jsxs)("div",{children:[(0,B.jsx)("span",{children:"Visible edge"}),(0,B.jsxs)("strong",{children:[Me.toFixed(2)," m"]})]})]}):null,(0,B.jsxs)("div",{className:"deck-outline__actions",children:[(0,B.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(T=>({...T,points:T.points.slice(0,-1)})),disabled:n.points.length===0||n.isOutlineClosed,children:"Undo"}),(0,B.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{d(null),o(T=>({...T,points:[],isOutlineClosed:!1,wallSegments:new Set,drawMode:"outline",drawError:""}))},disabled:n.points.length===0,children:"Clear"}),(0,B.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(T=>({...T,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,B.jsx)("div",{className:"deck-editor-layout",children:(0,B.jsxs)("div",{className:"deck-editor-layout__canvas-column",children:[(0,B.jsxs)("div",{className:"deck-outline",children:[(0,B.jsxs)("svg",{ref:M,className:`deck-outline__canvas${n.isOutlineClosed?" is-pan-mode":""}`,viewBox:`${R} ${z} ${u} ${h}`,preserveAspectRatio:"none","aria-label":"Deck outline drawing area",onPointerDown:wt,onPointerMove:Ct,onPointerUp:vt,onPointerLeave:()=>{d(null),_.current||(b.current=null)},children:[(0,B.jsx)("defs",{children:(0,B.jsx)("pattern",{id:"deck-outline-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,B.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,B.jsx)("rect",{x:-Ln,y:-Hn,width:Ln*3,height:Hn*3,className:"deck-outline__grid",fill:"url(#deck-outline-grid)"}),n.points.length>1?(0,B.jsx)("polyline",{className:"deck-outline__preview",points:n.points.map(T=>`${T.x},${T.y}`).join(" ")}):null,n.isOutlineClosed?(0,B.jsx)("polygon",{className:"deck-outline__shape",points:n.points.map(T=>`${T.x},${T.y}`).join(" "),stroke:"none"}):null,n.points.length>1?n.points.slice(0,n.isOutlineClosed?void 0:-1).map((T,Q)=>{let ne=n.points[n.isOutlineClosed?(Q+1)%n.points.length:Q+1],ue=qe(T,ne),ve=ue?-(ne.y-T.y)/ue:0,Ye=ue?(ne.x-T.x)/ue:0,Ce=(T.x+ne.x)/2,S=(T.y+ne.y)/2,y=ve*(Ce-ge.x)+Ye*(S-ge.y)>=0?1:-1,E=Ce+ve*uc*y,D=S+Ye*uc*y;return(0,B.jsxs)("g",{children:[(0,B.jsx)("line",{className:"deck-outline__edge-hit",x1:T.x,y1:T.y,x2:ne.x,y2:ne.y,onClick:n.isOutlineClosed?()=>we(Q):void 0}),(0,B.jsx)("line",{className:`deck-outline__edge${n.wallSegments.has(Q)?" is-wall":""}`,x1:T.x,y1:T.y,x2:ne.x,y2:ne.y,pointerEvents:"none"}),(0,B.jsxs)("text",{className:`deck-outline__edge-label${n.wallSegments.has(Q)?" is-wall":""}`,x:E,y:D,textAnchor:"middle",dominantBaseline:"central",fontSize:Bv/l,children:[ue.toFixed(2)," m"]})]},`segment-${Q}`)}):null,!n.isOutlineClosed&&n.points.length>0&&g?(()=>{let T=n.points[n.points.length-1],Q=qe(T,g);if(!Q)return null;let ne=-(g.y-T.y)/Q,ue=(g.x-T.x)/Q,ve=(T.x+g.x)/2,Ye=(T.y+g.y)/2;return(0,B.jsxs)("g",{className:"deck-outline__live-measurement",children:[(0,B.jsx)("line",{x1:T.x,y1:T.y,x2:g.x,y2:g.y}),(0,B.jsxs)("text",{x:ve+ne*.34,y:Ye+ue*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:Bv/l,children:[Q.toFixed(2)," m"]})]})})():null,n.points.map((T,Q)=>(0,B.jsx)("circle",{className:"deck-outline__point",cx:T.x,cy:T.y,r:"0.13",onPointerDown:ne=>Gt(ne,Q)},`point-${Q}`))]}),(0,B.jsxs)("div",{className:"deck-outline__zoom","aria-label":"Zoom controls",children:[(0,B.jsx)("button",{type:"button",onClick:()=>c(T=>Math.max(.5,T-.25)),disabled:l===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,B.jsxs)("span",{children:[Math.round(l*100),"%"]}),(0,B.jsx)("button",{type:"button",onClick:()=>c(T=>Math.min(1,T+.25)),disabled:l===1,"aria-label":"Zoom in",children:"+"})]}),n.isOutlineClosed&&n.wallSegments.size===0&&le?(0,B.jsx)("div",{className:"deck-outline__edge-prompt",role:"status",style:{left:`${(le.x-R)/u*100}%`,top:`${(le.y-z)/h*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,B.jsx)("button",{type:"button",className:"deck-outline__close",onClick:()=>o(T=>Yd(T.points,!0)?{...T,drawError:"Edges cannot cross. Adjust the outline before finishing."}:{...T,isOutlineClosed:!0,drawMode:"edges",drawError:""}),children:"Finish outline"}):null]}),(0,B.jsxs)("div",{className:"deck-outline__supporting",children:[(0,B.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,B.jsx)("div",{className:"deck-outline__error",role:"alert",children:n.drawError}):null]})]})})]})]}):null,O==="pictureFrame"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",ki.length]}),(0,B.jsx)("h2",{className:"truss-estimator__step-title",children:"Picture frame border?"}),(0,B.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,B.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(T=>(0,B.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.pictureFrame===T.id?" is-selected":""}`,onClick:()=>o(Q=>({...Q,pictureFrame:T.id})),children:[(0,B.jsx)("img",{className:"truss-estimator__visual-card-img",src:Ft(T.img),alt:""}),(0,B.jsx)("span",{children:T.label})]},T.id))}),(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)("div",{className:"truss-estimator__section-heading",children:"Board direction"}),(0,B.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(T=>(0,B.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.direction===T.id?" is-selected":""}`,onClick:()=>o(Q=>({...Q,direction:T.id})),children:[(0,B.jsx)("img",{className:"truss-estimator__visual-card-img",src:Ft(T.img),alt:""}),(0,B.jsx)("span",{children:T.label})]},T.id))})]})]}):null,O==="substructure"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",ki.length]}),(0,B.jsx)("h2",{className:"truss-estimator__step-title",children:"Substructure"}),(0,B.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,B.jsx)("div",{className:"truss-estimator__section-heading",children:"Joist spacing"}),(0,B.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Ra.joist.spacingOptions.map(T=>(0,B.jsx)("button",{type:"button",className:`truss-estimator__option-card${n.joistSpacing===T.id?" is-selected":""}`,onClick:()=>o(Q=>({...Q,joistSpacing:T.id})),children:(0,B.jsx)("div",{className:"truss-estimator__option-title",children:T.label})},T.id))})]}):null]}),(0,B.jsxs)("div",{className:"truss-estimator__nav",children:[(0,B.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:de,children:"Back"}),(0,B.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:tt,disabled:!Z(),children:[(0,B.jsx)("span",{children:be}),(0,B.jsx)("span",{className:"arrow",children:(0,B.jsx)(jt,{})})]})]})]})]})})}var Ca=X(je());var Y=X(ee()),Lv=12,Hv=30,jn=12,Qn=8,jv=.56,Na={ranges:{boundary:{label:"Horizontal lap",blurb:"Traditional pressure-treated timber panels.",panelWidthM:1.83},skyline:{label:"Feather edge",blurb:"Heavier timber panels for a more solid boundary.",panelWidthM:1.83}},heights:["0.9","1.2","1.5","1.8"],gate:{single:{label:"Single gate",widthDefault:.9}},mounting:{concrete:{label:"Concrete posts",blurb:"Slotted concrete posts with matching panels."},postcrete:{label:"Postcrete bags",blurb:"Fast-set post-mix bags in a dug hole.",bagsPerPost:2}}},Si=["range","height","gate","posts"],Vd=e=>Number(e)<=1.2?"6":"8",Qv=(e,t)=>vi("fencing",`panels-${e??"boundary"}-${t}`),Gv=(e,t)=>!t||vi("fencing",e==="concrete"?`concrete-intermediate-${Vd(t)}`:`timber-post-${Vd(t)}`),px={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:""}},mc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),fc=(e,t,a)=>a.x>=Math.min(e.x,t.x)&&a.x<=Math.max(e.x,t.x)&&a.y>=Math.min(e.y,t.y)&&a.y<=Math.max(e.y,t.y),dx=(e,t,a,r)=>{let i=mc(e,t,a),n=mc(e,t,r),o=mc(a,r,e),l=mc(a,r,t);return i===0&&fc(e,t,a)||n===0&&fc(e,t,r)||o===0&&fc(a,r,e)||l===0&&fc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},hc=(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)&&dx(e[r],e[(r+1)%e.length],e[i],e[(i+1)%e.length]))return!0;return!1};function Xd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ca.useState)(0),[n,o]=(0,Ca.useState)(px),l=(0,Ca.useRef)(null),c=(0,Ca.useRef)(null),[p,m]=(0,Ca.useState)(1),[g,d]=(0,Ca.useState)({x:0,y:0}),[b,_]=(0,Ca.useState)(null),M=(0,Ca.useRef)(null),O=(0,Ca.useRef)(null),f=(0,Ca.useRef)(null),u=Si[r],h=n.range?Na.ranges[n.range]:null,w=jn/p,k=Qn/p,R=(jn-w)/2,z=(Qn-k)/2,U=Math.max(-jn,Math.min(jn*2-w,R+g.x)),A=Math.max(-Qn,Math.min(Qn*2-k,z+g.y)),j=n.boundaryPoints.reduce((S,y)=>({x:S.x+y.x/Math.max(1,n.boundaryPoints.length),y:S.y+y.y/Math.max(1,n.boundaryPoints.length)}),{x:0,y:0}),ie=S=>{let y=new Set,E=[];return S.forEach(D=>{let[V,N]=D.split(",").map(Number),L=[{key:`H,${V},${N}`,type:"H",x:V,y:N},{key:`H,${V},${N+1}`,type:"H",x:V,y:N+1},{key:`V,${V},${N}`,type:"V",x:V,y:N},{key:`V,${V+1},${N}`,type:"V",x:V+1,y:N}],$=[!S.has(`${V},${N-1}`),!S.has(`${V},${N+1}`),!S.has(`${V-1},${N}`),!S.has(`${V+1},${N}`)];L.forEach((se,ke)=>{$[ke]&&!y.has(se.key)&&(y.add(se.key),E.push(se))})}),E},qe=(S,y)=>ie(S).filter(E=>!y.has(E.key)),Ke=(S,y)=>qe(S,y).length,Oe=(S,y)=>{let E={};qe(S,y).forEach(V=>{var N,L,$,se;V.type==="H"?((E[N=`${V.x},${V.y}`]||(E[N]=[])).push("H"),(E[L=`${V.x+1},${V.y}`]||(E[L]=[])).push("H")):((E[$=`${V.x},${V.y}`]||(E[$]=[])).push("V"),(E[se=`${V.x},${V.y+1}`]||(E[se]=[])).push("V"))});let D=0;return Object.values(E).forEach(V=>{(V.length===1||V.length===2&&V[0]!==V[1]||V.length>=3)&&(D+=1)}),D},ge=(()=>{let S=n.range?Na.ranges[n.range]:Na.ranges.boundary,y=n.height??"1.8",E=n.boundaryMode==="quick"?Math.max(0,Number.parseFloat(n.quickLengthM)||0):n.boundaryClosed?n.boundaryPoints.slice(0,-1).reduce((Yt,hr,_t)=>Yt+(n.excludedBoundaryEdges.has(_t)?0:Math.hypot(n.boundaryPoints[_t+1].x-hr.x,n.boundaryPoints[_t+1].y-hr.y)),0):0,D=n.gateType&&n.gateType!=="none"?Number.parseFloat(n.gateWidthM)||Na.gate[n.gateType].widthDefault:0,V=Math.max(0,E-D),N=V>0?Math.ceil(V/S.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,$=n.boundaryMode==="quick"?V>0?2:0:n.boundaryClosed?n.boundaryPoints.slice(0,L?-1:void 0).reduce((Yt,hr,_t)=>{let qi=_t>0&&!n.excludedBoundaryEdges.has(_t-1),um=_t<n.boundaryPoints.length-1&&!n.excludedBoundaryEdges.has(_t);return Yt+(qi||um?1:0)},0):0,se=V>0?Math.ceil(V/S.panelWidthM)+1:0,ke=Math.max(0,se-$),yt=n.mountingType?Na.mounting[n.mountingType]:Na.mounting.concrete,at=n.gateType&&n.gateType!=="none"?2:0,qt=ke+$+at,cm=n.mountingType==="postcrete"?qt*Na.mounting.postcrete.bagsPerPost:0,Kr=n.gravelBoard==="yes"?N:0;return{range:S,height:y,totalEdgeM:E,fencedLengthM:V,gateWidthM:D,panelsCount:N,cornerPostCount:$,intermediatePostCount:ke,gatePostCount:at,totalPostCount:qt,bagsCount:cm,gravelCount:Kr,capCount:qt,mounting:yt}})(),le=n.gateType&&n.gateType!=="none"?Na.gate[n.gateType].label:null,Ve=Vd(ge.height),Te=ge?[{key:`panels-${n.range??"boundary"}-${ge.height}`,label:`${ge.range.label} panels (${ge.height}m)`,qty:ge.panelsCount,unit:"each",query:"fence panel",category:"fencing"},...n.mountingType==="concrete"?[{key:`concrete-intermediate-${Ve}`,label:"Intermediate concrete posts",qty:ge.intermediatePostCount,unit:"each",query:"concrete fence post",category:"fencing"},{key:`concrete-end-${Ve}`,label:"End and corner concrete posts",qty:ge.cornerPostCount+ge.gatePostCount,unit:"each",query:"concrete end post",category:"fencing"}]:[{key:`timber-post-${Ve}`,label:"Timber fence posts",qty:ge.totalPostCount,unit:"each",query:"timber fence post",category:"fencing"},{key:"postcrete",label:"Postcrete",qty:ge.bagsCount,unit:"bag",query:"postcrete",category:"cement"}],...le?[{key:`gate-${n.range??"boundary"}`,label:n.range==="skyline"?"Single feather edge gate":"Single lap gate",qty:1,unit:"each",query:n.range==="skyline"?"feather edge gate":"lap gate",category:"fencing"}]:[],...ge.gravelCount>0?[{key:"gravel-boards",label:"Concrete gravel boards",qty:ge.gravelCount,unit:"each",query:"gravel board",category:"fencing"}]:[]]:[],ct=()=>{if(u==="range"){let S=n.boundaryMode==="quick"?(Number.parseFloat(n.quickLengthM)||0)>0:n.boundaryClosed&&n.boundaryPoints.length>=2;return!!n.range&&S}return u==="height"?!!n.height&&!!n.gravelBoard:u==="gate"?!!n.gateType&&(n.gateType==="none"||n.gateWidthM.trim()!==""):u==="posts"?!!n.mountingType:!0},Z=r===Si.length-1?a:"Next",be=S=>{o(y=>{let E=S(new Set(y.grid)),D=new Set([...y.excludedEdges].filter(V=>ie(E).some(N=>N.key===V)));return{...y,grid:E,excludedEdges:D}})},Re=(S,y,E)=>{be(D=>{let V=`${S},${y}`;return E?D.add(V):D.delete(V),D})},wt=(S,y,E,D,V)=>{let N=S,L=y,$=Math.abs(E-S),se=S<E?1:-1,ke=-Math.abs(D-y),yt=y<D?1:-1,at=$+ke;for(;Re(N,L,V),!(N===E&&L===D);){let qt=2*at;qt>=ke&&(at+=ke,N+=se),qt<=$&&(at+=$,L+=yt)}},Gt=(S,y)=>{let E=c.current?.getBoundingClientRect();if(!E)return null;let D=Math.floor((S-E.left)/Hv),V=Math.floor((y-E.top)/Hv);return D<0||V<0||D>=Lv||V>=Lv?null:{x:D,y:V}},Ct=S=>{if(n.gridMode!=="draw")return;let y=Gt(S.clientX,S.clientY);if(!y)return;S.preventDefault();let E=`${y.x},${y.y}`,D=!n.grid.has(E);l.current={active:!0,paintValue:D,lastX:y.x,lastY:y.y},S.currentTarget.setPointerCapture(S.pointerId),Re(y.x,y.y,D)},vt=S=>{let y=l.current;if(!y?.active)return;let E=Gt(S.clientX,S.clientY);E&&(E.x===y.lastX&&E.y===y.lastY||(wt(y.lastX,y.lastY,E.x,E.y,y.paintValue),l.current={...y,lastX:E.x,lastY:E.y}))},we=S=>{l.current?.active&&(l.current=null,S.currentTarget.releasePointerCapture(S.pointerId))},de=(S,y,E=!1)=>{let D=f.current?.getBoundingClientRect();if(!D)return null;let V=E?1:.25;return{x:Math.round(Math.max(U,Math.min(U+w,U+(S-D.left)/D.width*w))/V)*V,y:Math.round(Math.max(A,Math.min(A+k,A+(y-D.top)/D.height*k))/V)*V}},tt=S=>{if(n.boundaryClosed){let E=S.target;if(E!==S.currentTarget&&!E.classList.contains("fence-boundary__grid"))return;O.current={startX:S.clientX,startY:S.clientY,startViewX:U,startViewY:A},S.currentTarget.setPointerCapture(S.pointerId);return}let y=de(S.clientX,S.clientY,!0);y&&(_(null),o(E=>{let D=[...E.boundaryPoints,y];return hc(D,!1)?{...E}:{...E,boundaryPoints:D}}))},T=(S,y)=>{if(S.stopPropagation(),!n.boundaryClosed){if(y!==0||n.boundaryPoints.length<3)return;o(E=>hc(E.boundaryPoints,!0)?E:{...E,boundaryPoints:[...E.boundaryPoints,E.boundaryPoints[0]],boundaryClosed:!0});return}M.current=y,S.currentTarget.setPointerCapture(S.pointerId)},Q=S=>{if(O.current){let E=f.current?.getBoundingClientRect();if(!E)return;let D=O.current,V=D.startViewX-(S.clientX-D.startX)/E.width*w,N=D.startViewY-(S.clientY-D.startY)/E.height*k;d({x:V-R,y:N-z});return}if(n.boundaryClosed||_(de(S.clientX,S.clientY,!0)),M.current===null)return;let y=de(S.clientX,S.clientY);y&&o(E=>{let D=E.boundaryPoints.length>2&&E.boundaryPoints[0].x===E.boundaryPoints[E.boundaryPoints.length-1].x&&E.boundaryPoints[0].y===E.boundaryPoints[E.boundaryPoints.length-1].y,V=E.boundaryPoints.map((N,L)=>{let $=L===M.current,se=D&&M.current===0&&L===E.boundaryPoints.length-1;return $||se?y:N});return hc(V,!1)?E:{...E,boundaryPoints:V}})},ne=S=>{O.current=null,M.current=null,S.currentTarget.hasPointerCapture(S.pointerId)&&S.currentTarget.releasePointerCapture(S.pointerId)},ue=S=>{o(y=>{let E=new Set(y.excludedBoundaryEdges);return E.has(S)?E.delete(S):E.add(S),{...y,excludedBoundaryEdges:E}})},ve=()=>{r===0?e():i(S=>S-1)},Ye=()=>{ct()&&(r===Si.length-1?t?.(Te):i(S=>S+1))},Ce=ie(n.grid);return(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsxs)("div",{className:"truss-estimator",children:[(0,Y.jsxs)("div",{className:"quick-order-hero",children:[(0,Y.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Y.jsx)("h1",{children:"Fencing Calculator"}),(0,Y.jsx)("p",{children:"Estimate panels, posts and cost for your fence line in a few steps."})]}),(0,Y.jsxs)("div",{className:"truss-estimator__card",children:[(0,Y.jsxs)("div",{className:"truss-estimator__body",children:[u==="range"?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Y.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your fence panels"}),(0,Y.jsx)("p",{className:"truss-estimator__step-sub",children:"The calculator uses fixed, orderable timber panels from the catalogue."}),(0,Y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Na.ranges).map(([S,y])=>(0,Y.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===S?" is-selected":""}`,onClick:()=>o(E=>({...E,range:S,height:E.height&&Qv(S,E.height)?E.height:null})),children:[(0,Y.jsx)("div",{className:"truss-estimator__option-title",children:y.label}),(0,Y.jsx)("div",{className:"truss-estimator__option-copy",children:y.blurb})]},S))})]}):null,u==="range"?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)("div",{className:"truss-estimator__section-heading",children:"Measure your fence line"}),(0,Y.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,Y.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,Y.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="quick"?" is-selected":""}`,onClick:()=>o(S=>({...S,boundaryMode:"quick"})),children:"Quick estimate"}),(0,Y.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="draw"?" is-selected":""}`,onClick:()=>o(S=>({...S,boundaryMode:"draw"})),children:"Draw your boundary"})]}),n.boundaryMode==="quick"?(0,Y.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact fence-boundary__quick-field",children:[(0,Y.jsx)("span",{children:"Total fence length (m)"}),(0,Y.jsx)("input",{type:"number",min:"0",step:"0.1",value:n.quickLengthM,onChange:S=>o(y=>({...y,quickLengthM:S.target.value}))})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)("div",{className:"fence-boundary__toolbar",children:(0,Y.jsxs)("div",{className:"fence-boundary__actions",children:[(0,Y.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(S=>({...S,boundaryPoints:S.boundaryPoints.slice(0,-1),boundaryClosed:!1,excludedBoundaryEdges:new Set})),disabled:n.boundaryPoints.length===0||n.boundaryClosed,children:"Undo"}),(0,Y.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{d({x:0,y:0}),_(null),o(S=>({...S,boundaryPoints:[],boundaryClosed:!1,excludedBoundaryEdges:new Set}))},disabled:n.boundaryPoints.length===0,children:"Clear"}),(0,Y.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(S=>({...S,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,Y.jsxs)("div",{className:"fence-boundary",children:[(0,Y.jsxs)("svg",{ref:f,className:`fence-boundary__canvas${n.boundaryClosed?" is-pan-mode":""}`,viewBox:`${U} ${A} ${w} ${k}`,preserveAspectRatio:"none","aria-label":"Fence boundary drawing area",onPointerDown:tt,onPointerMove:Q,onPointerUp:ne,onPointerLeave:()=>{_(null),O.current||(M.current=null)},children:[(0,Y.jsx)("defs",{children:(0,Y.jsx)("pattern",{id:"fence-boundary-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,Y.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,Y.jsx)("rect",{x:-jn,y:-Qn,width:jn*3,height:Qn*3,className:"fence-boundary__grid",fill:"url(#fence-boundary-grid)"}),n.boundaryPoints.length>1?(0,Y.jsx)("polyline",{className:"fence-boundary__preview",points:n.boundaryPoints.map(S=>`${S.x},${S.y}`).join(" ")}):null,n.boundaryPoints.length>1?n.boundaryPoints.slice(0,-1).map((S,y)=>{let E=n.boundaryPoints[y+1],D=Math.hypot(E.x-S.x,E.y-S.y),V=D?-(E.y-S.y)/D:0,N=D?(E.x-S.x)/D:0,L=(S.x+E.x)/2,$=(S.y+E.y)/2,se=V*(L-j.x)+N*($-j.y)>=0?1:-1,ke=L+V*jv*se,yt=$+N*jv*se;return(0,Y.jsxs)("g",{children:[(0,Y.jsx)("line",{className:"fence-boundary__edge-hit",x1:S.x,y1:S.y,x2:E.x,y2:E.y,onClick:n.boundaryClosed?()=>ue(y):void 0}),(0,Y.jsx)("line",{className:`fence-boundary__edge${n.excludedBoundaryEdges.has(y)?" is-excluded":""}`,x1:S.x,y1:S.y,x2:E.x,y2:E.y,pointerEvents:"none"}),(0,Y.jsxs)("text",{className:`fence-boundary__edge-label${n.excludedBoundaryEdges.has(y)?" is-excluded":""}`,x:ke,y:yt,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[D.toFixed(2)," m"]})]},`fence-edge-${y}`)}):null,!n.boundaryClosed&&n.boundaryPoints.length>0&&b?(()=>{let S=n.boundaryPoints[n.boundaryPoints.length-1],y=Math.hypot(b.x-S.x,b.y-S.y);if(!y)return null;let E=-(b.y-S.y)/y,D=(b.x-S.x)/y,V=(S.x+b.x)/2,N=(S.y+b.y)/2;return(0,Y.jsxs)("g",{className:"fence-boundary__live-measurement",children:[(0,Y.jsx)("line",{x1:S.x,y1:S.y,x2:b.x,y2:b.y}),(0,Y.jsxs)("text",{x:V+E*.34,y:N+D*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[y.toFixed(2)," m"]})]})})():null,n.boundaryPoints.map((S,y)=>y>0&&y===n.boundaryPoints.length-1&&S.x===n.boundaryPoints[0]?.x&&S.y===n.boundaryPoints[0]?.y?null:(0,Y.jsx)("circle",{className:`fence-boundary__point${!n.boundaryClosed&&y===0&&n.boundaryPoints.length>=3?" is-close-target":""}`,cx:S.x,cy:S.y,r:"0.13",onPointerDown:E=>T(E,y)},`fence-point-${y}`))]}),(0,Y.jsxs)("div",{className:"fence-boundary__zoom","aria-label":"Zoom controls",children:[(0,Y.jsx)("button",{type:"button",onClick:()=>m(S=>Math.max(.5,S-.25)),disabled:p===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,Y.jsxs)("span",{children:[Math.round(p*100),"%"]}),(0,Y.jsx)("button",{type:"button",onClick:()=>m(S=>Math.min(1,S+.25)),disabled:p===1,"aria-label":"Zoom in",children:"+"})]}),!n.boundaryClosed&&n.boundaryPoints.length>=2?(0,Y.jsx)("button",{type:"button",className:"fence-boundary__close",onClick:()=>o(S=>hc(S.boundaryPoints,!1)?S:{...S,boundaryClosed:!0}),children:"Finish fence line"}):null]}),(0,Y.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,Y.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,Y.jsx)("div",{children:n.boundaryMode==="quick"?`${(Number.parseFloat(n.quickLengthM)||0).toFixed(2)} m fence line`:`${ge.totalEdgeM.toFixed(2)} m fence line`}),n.boundaryMode==="draw"&&n.boundaryClosed?(0,Y.jsxs)("div",{children:[ge.cornerPostCount," corner/end posts"]}):null]})]}):null,null,u==="height"?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Y.jsx)("h2",{className:"truss-estimator__step-title",children:"Fence height"}),(0,Y.jsx)("p",{className:"truss-estimator__step-sub",children:"Select the nearest available panel height."}),(0,Y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:Na.heights.filter(S=>Qv(n.range,S)).map(S=>(0,Y.jsx)("button",{type:"button",className:`truss-estimator__visual-card${n.height===S?" is-selected":""}`,onClick:()=>o(y=>({...y,height:S,mountingType:y.mountingType&&Gv(y.mountingType,S)?y.mountingType:null})),children:(0,Y.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--tall",src:Ft(`/fencing/height/${S}.webp`),alt:""})},S))}),(0,Y.jsx)("div",{className:"truss-estimator__section-heading",children:"Gravel board?"}),(0,Y.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(S=>(0,Y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.gravelBoard===S.id?" is-selected":""}`,onClick:()=>o(y=>({...y,gravelBoard:S.id})),children:[(0,Y.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Ft(S.img),alt:""}),(0,Y.jsx)("span",{children:S.label})]},S.id))})]}):null,u==="gate"?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Y.jsx)("h2",{className:"truss-estimator__step-title",children:"Do you need a gate?"}),(0,Y.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,Y.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(S=>(0,Y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${n.gateType===S.id?" is-selected":""}`,onClick:()=>o(y=>({...y,gateType:S.id,gateWidthM:S.id==="none"?"":String(Na.gate[S.id].widthDefault)})),children:[(0,Y.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Ft(S.img),alt:""}),(0,Y.jsx)("span",{children:S.label})]},S.id))}),n.gateType&&n.gateType!=="none"?(0,Y.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,Y.jsx)("span",{children:"Gate width (m)"}),(0,Y.jsx)("input",{type:"text",inputMode:"decimal",value:n.gateWidthM,onChange:S=>o(y=>({...y,gateWidthM:S.target.value}))})]}):null]}):null,u==="posts"?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Y.jsx)("h2",{className:"truss-estimator__step-title",children:"Posts and fixing type"}),(0,Y.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose how the posts will be set."}),(0,Y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Na.mounting).filter(([S])=>Gv(S,n.height)).map(([S,y])=>(0,Y.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.mountingType===S?" is-selected":""}`,onClick:()=>o(E=>({...E,mountingType:S})),children:[(0,Y.jsx)("div",{className:"truss-estimator__option-title",children:y.label}),(0,Y.jsx)("div",{className:"truss-estimator__option-copy",children:y.blurb})]},S))})]}):null]}),(0,Y.jsxs)("div",{className:"truss-estimator__nav",children:[(0,Y.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:ve,children:"Back"}),(0,Y.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:Ye,disabled:!ct(),children:[(0,Y.jsx)("span",{children:Z}),(0,Y.jsx)("span",{className:"arrow",children:(0,Y.jsx)(jt,{})})]})]})]})]})})}var gc=X(je()),he=X(ee()),Yv={floor:{label:"Floor between rooms",product:"Knauf Acoustic Roll",thickness:"100mm",coverage:12.36},ground:{label:"Ground floor",product:"Rigid PIR insulation board",thickness:"100mm",coverage:2.88},wall:{label:"Cavity wall",product:"Celotex CW4100",thickness:"100mm",coverage:3.24},roof:{label:"Pitched roof",product:"Kingspan K107",thickness:"100mm",coverage:8.64},loft:{label:"Loft",product:"Knauf Loft Roll 44",thickness:"100mm",coverage:13.89}};function Zd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,gc.useState)("floor"),[n,o]=(0,gc.useState)(""),[l,c]=(0,gc.useState)(""),p=Number.parseFloat(n)*Number.parseFloat(l)||0,m=Yv[r],g=Math.ceil(p/m.coverage),d=[{key:`insulation-${r}`,label:`${m.product} ${m.thickness}`,qty:Math.round(p*100)/100,unit:"m2",query:m.product,category:"insulation"}],b=Object.entries(Yv);return(0,he.jsx)(he.Fragment,{children:(0,he.jsxs)("div",{className:"truss-estimator",children:[(0,he.jsxs)("div",{className:"quick-order-hero",children:[(0,he.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,he.jsx)("h1",{children:"Insulation Calculator"}),(0,he.jsx)("p",{children:"Estimate insulation coverage and pack quantities for floors, walls, roofs and lofts."})]}),(0,he.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,he.jsx)("h2",{className:"truss-estimator__step-title",children:"Where and what you are insulating"}),(0,he.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the application and product, and enter the area, for coverage and pack quantities."}),(0,he.jsxs)("div",{className:"materials-calculator__section",children:[(0,he.jsx)("div",{className:"truss-estimator__section-heading",children:"Application"}),(0,he.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:b.map(([_,M])=>(0,he.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===_?" is-selected":""}`,onClick:()=>i(_),children:[(0,he.jsx)("div",{className:"truss-estimator__option-title",children:M.label}),(0,he.jsxs)("div",{className:"truss-estimator__option-copy",children:[M.product,", ",M.thickness]})]},_))})]}),(0,he.jsxs)("div",{className:"materials-calculator__section",children:[(0,he.jsx)("div",{className:"truss-estimator__section-heading",children:"Area"}),(0,he.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,he.jsxs)("label",{className:"truss-estimator__field",children:[(0,he.jsx)("span",{children:"Length (m)"}),(0,he.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:_=>o(_.target.value)})]}),(0,he.jsxs)("label",{className:"truss-estimator__field",children:[(0,he.jsx)("span",{children:"Width (m)"}),(0,he.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:_=>c(_.target.value)})]})]})]}),(0,he.jsxs)("div",{className:"materials-calculator__totals",children:[(0,he.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,he.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,he.jsxs)("div",{children:[(0,he.jsx)("span",{children:"Insulated area"}),(0,he.jsxs)("strong",{children:[p.toFixed(2)," m\xB2"]})]}),(0,he.jsxs)("div",{children:[(0,he.jsx)("span",{children:m.product}),(0,he.jsxs)("strong",{children:[g," packs"]})]})]}),(0,he.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,he.jsxs)("div",{className:"materials-calculator__actions",children:[(0,he.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,he.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(d),disabled:p<=0,children:a})]})]})]})})}var Gn=X(je());var K=X(ee()),mx=10,fx=1.9*.762,hx=1.9*1.524,bc=()=>({height:"",width:""}),wc=e=>Number.parseFloat(e)||0,$v=({height:e,width:t})=>wc(e)*wc(t);function Kd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Gn.useState)([bc()]),[n,o]=(0,Gn.useState)([bc()]),[l,c]=(0,Gn.useState)("0"),[p,m]=(0,Gn.useState)("0"),[g,d]=(0,Gn.useState)(1),b=r.reduce((k,R)=>k+$v(R),0),_=n.reduce((k,R)=>k+$v(R),0),M=wc(l)*fx+wc(p)*hx,O=Math.max(0,b-_-M),f=O*g/mx,u={key:"paint-emulsion",label:"Matt emulsion, brilliant white",qty:Math.round(f*10)/10,unit:"litres",query:"matt emulsion brilliant white"},h=cl("paint",u)!=null,w=(k,R,z,U)=>{k(A=>A.map((j,ie)=>ie===R?{...j,[z]:U}:j))};return(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)("div",{className:"truss-estimator",children:[(0,K.jsxs)("div",{className:"quick-order-hero",children:[(0,K.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,K.jsx)("h1",{children:"Paint Calculator"}),(0,K.jsx)("p",{children:"Estimate how much paint you need for your walls, including multiple coats and excluded areas."})]}),(0,K.jsxs)("div",{className:"truss-estimator__card paint-calculator",children:[(0,K.jsx)("h2",{className:"truss-estimator__step-title",children:"Walls, exclusions and coats"}),(0,K.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter each wall, subtract windows and doors, and choose your number of coats. Quantities assume a coverage of 10 m\xB2 per litre."}),(0,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Enter the height and width of each wall you want to paint."}),(0,K.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,K.jsx)("span",{}),(0,K.jsx)("span",{children:"Height (m)"}),(0,K.jsx)("span",{children:"Width (m)"}),(0,K.jsx)("span",{})]}),r.map((k,R)=>(0,K.jsxs)("div",{className:"paint-calculator__row",children:[(0,K.jsxs)("span",{className:"paint-calculator__row-label",children:["Wall ",R+1]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,K.jsx)("input",{"aria-label":`Wall ${R+1} height in metres`,type:"number",min:"0",step:"0.01",value:k.height,onChange:z=>w(i,R,"height",z.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,K.jsx)("input",{"aria-label":`Wall ${R+1} width in metres`,type:"number",min:"0",step:"0.01",value:k.width,onChange:z=>w(i,R,"width",z.target.value)})]}),r.length>1?(0,K.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(z=>z.filter((U,A)=>A!==R)),children:"Remove"}):null]},`wall-${R}`)),(0,K.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(k=>[...k,bc()]),children:"+ Add another wall"})]}),(0,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Areas to exclude"}),(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Add windows, sockets, skirting boards or other areas that will not be painted."}),(0,K.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,K.jsx)("span",{}),(0,K.jsx)("span",{children:"Height (m)"}),(0,K.jsx)("span",{children:"Width (m)"}),(0,K.jsx)("span",{})]}),n.map((k,R)=>(0,K.jsxs)("div",{className:"paint-calculator__row",children:[(0,K.jsxs)("span",{className:"paint-calculator__row-label",children:["Area ",R+1]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,K.jsx)("input",{"aria-label":`Area ${R+1} height in metres`,type:"number",min:"0",step:"0.01",value:k.height,onChange:z=>w(o,R,"height",z.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,K.jsx)("input",{"aria-label":`Area ${R+1} width in metres`,type:"number",min:"0",step:"0.01",value:k.width,onChange:z=>w(o,R,"width",z.target.value)})]}),n.length>1?(0,K.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>o(z=>z.filter((U,A)=>A!==R)),children:"Remove"}):null]},`excluded-${R}`)),(0,K.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>o(k=>[...k,bc()]),children:"+ Add another area"})]}),(0,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Doors and coats"}),(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Enter the number of standard single and double doors to leave unpainted. Door sizes are estimated automatically."}),(0,K.jsxs)("div",{className:"truss-estimator__field-grid paint-calculator__small-fields",children:[(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Doors"}),(0,K.jsx)("input",{type:"number",min:"0",step:"1",value:l,onChange:k=>c(k.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Double doors"}),(0,K.jsx)("input",{type:"number",min:"0",step:"1",value:p,onChange:k=>m(k.target.value)})]})]}),(0,K.jsxs)("div",{className:"paint-calculator__coat-field",children:[(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Most walls need 2 coats for an even finish. Use 3 coats when changing colour significantly or covering a darker wall."}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Number of coats"}),(0,K.jsxs)("select",{value:g,onChange:k=>d(Number(k.target.value)),children:[(0,K.jsx)("option",{value:"1",children:"1 coat"}),(0,K.jsx)("option",{value:"2",children:"2 coats"}),(0,K.jsx)("option",{value:"3",children:"3 coats"})]})]})]})]}),(0,K.jsxs)("div",{className:"paint-calculator__totals",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,K.jsxs)("div",{className:"paint-calculator__result-grid",children:[(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Paintable area"}),(0,K.jsxs)("strong",{children:[O.toFixed(2)," m\xB2"]})]}),(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Coverage"}),(0,K.jsxs)("strong",{children:[g," ",g===1?"coat":"coats"]})]}),(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Paint required"}),(0,K.jsxs)("strong",{children:[f.toFixed(1)," litres"]})]})]}),(0,K.jsx)("p",{className:"paint-calculator__note",children:h?"Based on paint coverage of 10 m\xB2 per litre. Ordered as brilliant white matt emulsion, rounded up to whole tins.":"Based on paint coverage of 10 m\xB2 per litre. Decorative paint is not currently stocked in this catalogue, so this remains an estimate only."})]}),(0,K.jsxs)("div",{className:"paint-calculator__actions",children:[(0,K.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),h?(0,K.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.([u]),disabled:f<=0,children:a}):(0,K.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",disabled:!0,children:"Paint products unavailable"})]})]})]})})}var fr=X(je()),te=X(ee()),vc=e=>Number.parseFloat(e)||0,Pd={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 Jd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,fr.useState)("paving"),[n,o]=(0,fr.useState)("council"),[l,c]=(0,fr.useState)(""),[p,m]=(0,fr.useState)(""),[g,d]=(0,fr.useState)("100"),[b,_]=(0,fr.useState)("50"),[M,O]=(0,fr.useState)(!0),[f,u]=(0,fr.useState)(!0),h=vc(l)*vc(p),w=h,k=h*(vc(g)/1e3),R=h*.04,z=h*(vc(b)/1e3),U=Math.ceil(w/.36),A=Math.ceil(w/.1),j=Math.ceil(k*1700/800),ie=Math.ceil(R*1600/800),qe=Math.ceil(z*1600/800),Ke=r==="paving"?{qty:U,unit:"each"}:r==="block"?{qty:w,unit:"m2"}:{qty:qe,unit:"bag"},Oe={paving:"paving slab",block:"block paver",gravel:"decorative gravel"}[r],Me=[{key:`surface-${n}`,label:Pd[r].find(le=>le.id===n)?.label??"Surface material",qty:Ke.qty,unit:Ke.unit,query:Oe,category:"landscaping"},...M?[{key:"sub-base",label:"MOT Type 1 sub-base",qty:j,unit:"bag",query:"MOT Type 1 sub base",category:"aggregate"}]:[],...f?[{key:"bedding",label:"Sharp sand bedding",qty:ie,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(([le,Ve,Te])=>(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===le?" is-selected":""}`,onClick:()=>{i(le),o(Pd[le][0].id)},children:[(0,te.jsx)("div",{className:"truss-estimator__option-title",children:Ve}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:Te})]},le))}),(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:le=>o(le.target.value),children:Pd[r].map(le=>(0,te.jsx)("option",{value:le.id,children:le.label},le.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:le=>c(le.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:le=>m(le.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:le=>_(le.target.value)})]}),M&&(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:le=>d(le.target.value)})]}),(0,te.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,te.jsx)("input",{type:"checkbox",checked:M,onChange:le=>O(le.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:le=>u(le.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:[h.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"?`${U} slabs`:r==="block"?`${w.toFixed(2)} m\xB2`:`${qe} bulk bags`})]}),M&&(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"MOT Type 1"}),(0,te.jsxs)("strong",{children:[j," bulk bags"]})]}),f&&(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Sharp sand"}),(0,te.jsxs)("strong",{children:[ie," 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?.(Me),disabled:h<=0,children:a})]})]})]})})}var ul=X(je()),re=X(ee()),gx=2.88,Vv=[{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"}],Xv=()=>({length:"",height:""}),Fd=e=>Number.parseFloat(e)||0;function Id({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,ul.useState)([Xv()]),[n,o]=(0,ul.useState)(""),[l,c]=(0,ul.useState)("standard"),[p,m]=(0,ul.useState)("screws"),g=r.reduce((R,z)=>R+Fd(z.length)*Fd(z.height),0),d=Math.max(0,g-Fd(n)),b=Math.ceil(d/gx),_=Math.ceil(d*12),M=Math.ceil(_/1e3),O=Math.ceil(d*1.2),f=Math.ceil(O/90),u=Math.ceil(d/3.5),h=Vv.find(R=>R.id===l)?.label??"Standard",w=[{key:"board",label:`${h} plasterboard`,qty:b,unit:"sheet",query:`${h} plasterboard`,category:"plasterboard"},...p==="screws"?[{key:"screws",label:"Drywall screws",qty:M,unit:"box",query:"drywall screws",category:"fixings"}]:[{key:"adhesive",label:"Board adhesive",qty:u,unit:"bag",query:"drywall board adhesive",category:"plasterboard"}],{key:"tape",label:"Joint tape",qty:f,unit:"roll",query:"plasterboard joint tape",category:"plasterboard"}],k=(R,z,U)=>{i(A=>A.map((j,ie)=>ie===R?{...j,[z]:U}:j))};return(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{className:"truss-estimator",children:[(0,re.jsxs)("div",{className:"quick-order-hero",children:[(0,re.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,re.jsx)("h1",{children:"Plasterboard and Drylining Calculator"}),(0,re.jsx)("p",{children:"Estimate boards, fixings and jointing materials for walls and ceilings."})]}),(0,re.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,re.jsx)("h2",{className:"truss-estimator__step-title",children:"Boards, fixings and jointing"}),(0,re.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,re.jsxs)("div",{className:"materials-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Board type"}),(0,re.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Vv.map(R=>(0,re.jsxs)("button",{type:"button",className:`truss-estimator__option-card${l===R.id?" is-selected":""}`,onClick:()=>c(R.id),children:[(0,re.jsx)("div",{className:"truss-estimator__option-title",children:R.label}),(0,re.jsx)("div",{className:"truss-estimator__option-copy",children:R.blurb})]},R.id))})]}),(0,re.jsxs)("div",{className:"materials-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Fixing method"}),(0,re.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,U])=>(0,re.jsxs)("button",{type:"button",className:`truss-estimator__option-card${p===R?" is-selected":""}`,onClick:()=>m(R),children:[(0,re.jsx)("div",{className:"truss-estimator__option-title",children:z}),(0,re.jsx)("div",{className:"truss-estimator__option-copy",children:U})]},R))})]}),(0,re.jsxs)("div",{className:"materials-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall and ceiling areas"}),(0,re.jsx)("p",{className:"materials-calculator__hint",children:"Add each surface separately so different wall sizes are easy to measure."}),(0,re.jsxs)("div",{className:"materials-calculator__dimensions-header",children:[(0,re.jsx)("span",{children:"Surface"}),(0,re.jsx)("span",{children:"Length (m)"}),(0,re.jsx)("span",{children:"Height (m)"}),(0,re.jsx)("span",{})]}),r.map((R,z)=>(0,re.jsxs)("div",{className:"materials-calculator__surface-row",children:[(0,re.jsxs)("span",{children:["Surface ",z+1]}),(0,re.jsx)("input",{"aria-label":`Surface ${z+1} length`,type:"number",min:"0",step:"0.01",value:R.length,onChange:U=>k(z,"length",U.target.value)}),(0,re.jsx)("input",{"aria-label":`Surface ${z+1} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:U=>k(z,"height",U.target.value)}),r.length>1?(0,re.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(U=>U.filter((A,j)=>j!==z)),children:"Remove"}):null]},`surface-${z}`)),(0,re.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(R=>[...R,Xv()]),children:"+ Add another surface"}),(0,re.jsxs)("label",{className:"truss-estimator__field materials-calculator__openings",children:[(0,re.jsxs)("span",{children:["Openings to deduct (m\xB2) ",(0,re.jsx)("small",{children:"optional"})]}),(0,re.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:R=>o(R.target.value)})]})]}),(0,re.jsxs)("div",{className:"materials-calculator__totals",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,re.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Board area"}),(0,re.jsxs)("strong",{children:[d.toFixed(2)," m\xB2"]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"2.4 x 1.2 m boards"}),(0,re.jsx)("strong",{children:b})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:p==="screws"?"Drywall screws":"Board adhesive"}),(0,re.jsx)("strong",{children:p==="screws"?`${_} (${M} boxes)`:`${u} bags`})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Joint tape"}),(0,re.jsxs)("strong",{children:[O," m (",f," rolls)"]})]})]}),(0,re.jsx)("p",{className:"materials-calculator__note",children:"Figures are estimates. Confirm board specification, fixing patterns and fire or acoustic requirements before ordering."})]}),(0,re.jsxs)("div",{className:"materials-calculator__actions",children:[(0,re.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,re.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(w),disabled:d<=0,children:a})]})]})]})})}var pl=X(je());var v=X(ee()),Ut={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}}}},yc=["range","pitchAndDimensions","quantityAndGirders","bracing"],bx={range:null,pitch:null,spanMM:"",overhangMM:"",roofLengthM:"",centres:null,girderCount:0,bracing:null,treatment:null,contact:{name:"",email:""}};function wx({degrees:e}){let a=e*Math.PI/180,i=82-Math.min(58,38*Math.tan(a));return(0,v.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,v.jsx)("line",{x1:"6",y1:"82",x2:"94",y2:"82",stroke:"var(--border)",strokeWidth:"2"}),(0,v.jsx)("polygon",{points:`12,82 88,82 50,${i}`,fill:"var(--accent-light)",stroke:"var(--accent)",strokeWidth:"3",strokeLinejoin:"round"})]})}function vx({type:e}){let t="#b3835a",a="#5c3b22",r="#d9b48f",i="#d3d8de",n="#7c8494",o=(m,g,d,b,_=8,M)=>{let O=d-m,f=b-g,u=Math.hypot(O,f)||1,h=-f/u,w=O/u,k=_*.2;return(0,v.jsxs)("g",{children:[(0,v.jsx)("line",{x1:m,y1:g,x2:d,y2:b,stroke:a,strokeWidth:_+3,strokeLinecap:"square"}),(0,v.jsx)("line",{x1:m,y1:g,x2:d,y2:b,stroke:t,strokeWidth:_,strokeLinecap:"square"}),(0,v.jsx)("line",{x1:m-h*k,y1:g-w*k,x2:d-h*k,y2:b-w*k,stroke:r,strokeWidth:Math.max(1.5,_*.24),strokeLinecap:"round",opacity:"0.9"})]},M)},l=(m,g,d)=>(0,v.jsxs)("g",{children:[(0,v.jsx)("rect",{x:m-7.5,y:g-5.5,width:"15",height:"11",rx:"2",fill:i,stroke:n,strokeWidth:"1"}),(0,v.jsx)("circle",{cx:m-4,cy:g-2.5,r:"1",fill:n}),(0,v.jsx)("circle",{cx:m+4,cy:g-2.5,r:"1",fill:n}),(0,v.jsx)("circle",{cx:m-4,cy:g+2.5,r:"1",fill:n}),(0,v.jsx)("circle",{cx:m+4,cy:g+2.5,r:"1",fill:n}),(0,v.jsx)("circle",{cx:m,cy:g,r:"1",fill:n})]},d),c=(m,g)=>(0,v.jsx)("rect",{x:m-9,y:"110",width:"18",height:"10",fill:a},g),p=(0,v.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"});return e==="attic"?(0,v.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,v.jsx)("rect",{x:"90",y:"82",width:"20",height:"24",fill:"#cfe3f2",stroke:a,strokeWidth:"2"}),(0,v.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,v.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,v.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,v.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 yx({enabled:e}){return(0,v.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[(0,v.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"}),(0,v.jsx)("rect",{x:"17",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,v.jsx)("rect",{x:"165",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,v.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,v.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,v.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,v.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,v.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,v.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),e?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("line",{x1:"45",y1:"112",x2:"140",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"}),(0,v.jsx)("line",{x1:"155",y1:"112",x2:"60",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"})]}):null,(0,v.jsx)("rect",{x:"18.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,v.jsx)("rect",{x:"166.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,v.jsx)("rect",{x:"92.5",y:"28.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"})]})}function Zv({treated:e}){let t=e?"#5a7a4a":"var(--accent)";return(0,v.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,v.jsx)("rect",{x:"10",y:"22",width:"80",height:"14",rx:"2",fill:t}),(0,v.jsx)("rect",{x:"10",y:"43",width:"80",height:"14",rx:"2",fill:e?"#8faf7a":"var(--accent-light)"}),(0,v.jsx)("rect",{x:"10",y:"64",width:"80",height:"14",rx:"2",fill:t})]})}function Wd({onBack:e}){let[t,a]=(0,pl.useState)(0),[r,i]=(0,pl.useState)(bx),[n,o]=(0,pl.useState)(!1),[l,c]=(0,pl.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?Ut.ranges[r.range]:Ut.ranges.standard,u=r.pitch??"22.5",h=Ut.pitchMultipliers[u],w=(Number.parseFloat(r.spanMM)||0)/1e3,R=(Number.parseFloat(r.overhangMM)||0)>Ut.overhang.thresholdMM,z=p(),U=z+r.girderCount,A=Number.parseFloat(r.roofLengthM)||0,j=r.treatment?Ut.treatment[r.treatment]:Ut.treatment.untreated,ie=Ut.estimate.ranges[r.range??"standard"],qe=ie.supplyAt8m*Math.max(.7,w/8)*h*(1+j.surchargePct)+(R?Ut.overhang.surchargePerTruss:0),Ke=z*qe,Oe=r.girderCount*qe*Ut.estimate.girderMultiplier,Me=r.bracing==="yes"?A*Ut.estimate.bracingPerMetre:0,ge=Ke+Oe+Me+Ut.estimate.delivery,le=Ut.estimate.design+z*ie.installPerTruss+r.girderCount*40,Ve=ge+le,Te=Ve*.2;return{range:f,count:z,girderCount:r.girderCount,overhangApplies:R,overhangUnits:U,roofLengthM:A,treatment:j,trussSupply:Ke,bracingMaterials:Me,delivery:Ut.estimate.delivery,labour:le,subtotal:Ve,vat:Te,total:Ve+Te}})(),d=()=>{let f=yc[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===yc.length-1?"View truss request":"Next",_=()=>{n?o(!1):t===0?e():a(f=>f-1)},M=()=>{d()&&(t===yc.length-1?(c(!1),o(!0)):a(f=>f+1))},O=()=>{let f=yc[t];return f==="range"?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Step 1 of 4"}),(0,v.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your truss range"}),(0,v.jsx)("p",{className:"truss-estimator__step-sub",children:"Pricing shown is placeholder. Swap in your real engineering and pricing catalogue."}),(0,v.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--range",children:Object.entries(Ut.ranges).map(([u,h])=>(0,v.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r.range===u?" is-selected":""}`,onClick:()=>i(w=>({...w,range:u})),children:[(0,v.jsx)(vx,{type:u}),(0,v.jsxs)("div",{className:"truss-estimator__option-info",children:[(0,v.jsx)("div",{className:"truss-estimator__option-title",children:h.label}),(0,v.jsx)("div",{className:"truss-estimator__option-copy",children:h.blurb})]})]},u))})]}):f==="pitchAndDimensions"?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Step 2 of 4"}),(0,v.jsx)("h2",{className:"truss-estimator__step-title",children:"Span, overhang and roof pitch"}),(0,v.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,v.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,v.jsxs)("label",{className:"truss-estimator__field",children:[(0,v.jsx)("span",{children:"Span (mm)"}),(0,v.jsx)("input",{type:"text",inputMode:"numeric",value:r.spanMM,onChange:u=>i(h=>({...h,spanMM:u.target.value}))})]}),(0,v.jsxs)("label",{className:"truss-estimator__field",children:[(0,v.jsx)("span",{children:"Overhang (mm)"}),(0,v.jsx)("input",{type:"text",inputMode:"numeric",value:r.overhangMM,onChange:u=>i(h=>({...h,overhangMM:u.target.value}))}),(0,v.jsxs)("small",{children:["Overhangs beyond ",Ut.overhang.thresholdMM,"mm add a small surcharge per truss."]})]})]}),(0,v.jsx)("div",{className:"truss-estimator__section-heading",children:"Roof pitch"}),(0,v.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:Ut.pitches.map(u=>(0,v.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${r.pitch===u?" is-selected":""}`,onClick:()=>i(h=>({...h,pitch:u})),children:[(0,v.jsx)(wx,{degrees:Number.parseFloat(u)}),(0,v.jsxs)("span",{children:[u,"\xB0"]})]},u))})]}):f==="quantityAndGirders"?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Step 3 of 4"}),(0,v.jsx)("h2",{className:"truss-estimator__step-title",children:"Roof length"}),(0,v.jsx)("p",{className:"truss-estimator__step-sub",children:"Trusses are based on designs at 400mm or 600mm centres wherever possible."}),(0,v.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,v.jsx)("span",{children:"Roof length (m)"}),(0,v.jsx)("input",{type:"text",inputMode:"decimal",value:r.roofLengthM,onChange:u=>i(h=>({...h,roofLengthM:u.target.value}))})]}),(0,v.jsx)("div",{className:"truss-estimator__section-heading",children:"Truss centres"}),(0,v.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--centres",children:Ut.centresOptions.map(u=>(0,v.jsx)("button",{type:"button",className:`truss-estimator__option-card truss-estimator__option-card--compact${r.centres===u?" is-selected":""}`,onClick:()=>i(h=>({...h,centres:u})),children:(0,v.jsxs)("div",{className:"truss-estimator__option-title",children:[u,"mm centres"]})},u))}),(0,v.jsxs)("div",{className:"truss-estimator__stat",children:[p()," trusses estimated"]}),(0,v.jsx)("div",{className:"truss-estimator__section-heading",children:"Girder trusses"}),(0,v.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,v.jsxs)("div",{className:"truss-estimator__stepper",children:[(0,v.jsx)("button",{type:"button",onClick:()=>i(u=>({...u,girderCount:Math.max(0,u.girderCount-1)})),children:"\u2212"}),(0,v.jsx)("span",{children:r.girderCount}),(0,v.jsx)("button",{type:"button",onClick:()=>i(u=>({...u,girderCount:Math.min(3,u.girderCount+1)})),children:"+"})]})]}):f==="bracing"?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Step 4 of 4"}),(0,v.jsx)("h2",{className:"truss-estimator__step-title",children:"Bracing pack?"}),(0,v.jsx)("p",{className:"truss-estimator__step-sub",children:"A timber bracing pack stabilises the roof structure once trusses are erected."}),(0,v.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,v.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.bracing===u.id?" is-selected":""}`,onClick:()=>i(h=>({...h,bracing:u.id})),children:[(0,v.jsx)(yx,{enabled:u.id==="yes"}),(0,v.jsx)("span",{children:u.label})]},u.id))}),(0,v.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber treatment"}),(0,v.jsx)("p",{className:"truss-estimator__step-sub",children:"Tanalised timber protects against rot in exposed or damp locations."}),(0,v.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,v.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,v.jsx)(Zv,{treated:!1}),(0,v.jsx)("span",{children:"Untreated"})]}),(0,v.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,v.jsx)(Zv,{treated:!0}),(0,v.jsx)("span",{children:"Treated (+8% cost)"}),(0,v.jsx)("small",{children:"Applies to trusses, girders and overhang"})]})]})]}):null};return n?(0,v.jsx)(v.Fragment,{children:(0,v.jsxs)("div",{className:"truss-estimator",children:[(0,v.jsxs)("div",{className:"quick-order-hero",children:[(0,v.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,v.jsx)("h1",{children:"Your truss estimate"}),(0,v.jsx)("p",{children:"A provisional quantity and specification based on the dimensions you entered."})]}),(0,v.jsxs)("div",{className:"truss-estimator__card truss-request",style:{minHeight:0},children:[(0,v.jsxs)("div",{className:"truss-request__heading",children:[(0,v.jsxs)("div",{children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Estimated requirement"}),(0,v.jsxs)("h2",{children:[g.range.label," roof trusses"]})]}),(0,v.jsxs)("strong",{children:[g.count,(0,v.jsx)("span",{children:"trusses"})]})]}),(0,v.jsxs)("div",{className:"truss-request__grid",children:[(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Span"}),(0,v.jsxs)("strong",{children:[r.spanMM," mm"]})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Roof length"}),(0,v.jsxs)("strong",{children:[r.roofLengthM," m"]})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Pitch"}),(0,v.jsxs)("strong",{children:[r.pitch,"\xB0"]})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Centres"}),(0,v.jsxs)("strong",{children:[r.centres," mm"]})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Overhang"}),(0,v.jsxs)("strong",{children:[r.overhangMM," mm"]})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Treatment"}),(0,v.jsx)("strong",{children:g.treatment.label})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Girder trusses"}),(0,v.jsx)("strong",{children:g.girderCount||"None"})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Bracing pack"}),(0,v.jsx)("strong",{children:r.bracing==="yes"?"Included":"Not included"})]})]}),(0,v.jsxs)("div",{className:"truss-request__price",children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Indicative cost estimate"}),(0,v.jsxs)("div",{className:"truss-request__price-grid",children:[(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Truss supply allowance"}),(0,v.jsx)("strong",{children:ot(g.trussSupply)})]}),g.bracingMaterials>0&&(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Bracing materials allowance"}),(0,v.jsx)("strong",{children:ot(g.bracingMaterials)})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Delivery allowance"}),(0,v.jsx)("strong",{children:ot(g.delivery)})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Design and installation labour"}),(0,v.jsx)("strong",{children:ot(g.labour)})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Subtotal (ex. VAT)"}),(0,v.jsx)("strong",{children:ot(g.subtotal)})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"VAT (20%)"}),(0,v.jsx)("strong",{children:ot(g.vat)})]}),(0,v.jsxs)("div",{className:"truss-request__price-total",children:[(0,v.jsx)("span",{children:"Estimated total"}),(0,v.jsx)("strong",{children:ot(g.total)})]})]}),(0,v.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,v.jsxs)("div",{className:"truss-request__notice",children:[(0,v.jsx)("strong",{children:"Before ordering"}),(0,v.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,v.jsxs)("div",{className:"truss-estimator__nav",children:[(0,v.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:_,children:"Back to calculator"}),(0,v.jsx)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",justifyContent:"center",marginTop:0},onClick:()=>c(!0),children:"Request order"})]}),l&&(0,v.jsx)("p",{className:"truss-request__demo",children:"Demo only \u2014 no order has been sent."})]})]})}):(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:"Roof Truss Calculator"}),(0,v.jsx)("p",{children:"Estimate trusses, girders and cost for your roof in a few steps."})]}),(0,v.jsxs)("div",{className:"truss-estimator__card",children:[(0,v.jsx)("div",{className:"truss-estimator__body",children:O()}),(0,v.jsxs)("div",{className:"truss-estimator__nav",children:[(0,v.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:_,children:"Back"}),(0,v.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:M,disabled:!d(),children:[(0,v.jsx)("span",{children:b}),(0,v.jsx)("span",{className:"arrow",children:(0,v.jsx)(jt,{})})]})]})]})]})})}var Ni=X(je()),F=X(ee()),Jv=e=>Number.parseFloat(e)||0,_c=(e,t)=>Jv(e)*(t==="m"?1:.3048),Kv=()=>({length:"",width:""}),Pv=[{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 _x({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 em({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ni.useState)("total"),[n,o]=(0,Ni.useState)("m"),[l,c]=(0,Ni.useState)(""),[p,m]=(0,Ni.useState)([Kv()]),[g,d]=(0,Ni.useState)(""),[b,_]=(0,Ni.useState)("chamfered"),M="4.4",O=r==="total"?_c(l,n):p.reduce((k,R)=>k+2*(_c(R.length,n)+_c(R.width,n)),0),f=Math.max(0,O-_c(g,n)),u=Math.ceil(f/Jv(M)),h=[{key:`skirting-${b}`,label:`${Pv.find(k=>k.id===b)?.label} skirting board`,qty:f,unit:"m",query:"skirting board",category:"skirting"}],w=(k,R,z)=>{m(U=>U.map((A,j)=>j===k?{...A,[R]:z}:A))};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:k=>c(k.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((k,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:k.length,onChange:z=>w(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:k.width,onChange:z=>w(R,"width",z.target.value)}),p.length>1?(0,F.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>m(z=>z.filter((U,A)=>A!==R)),children:"Remove"}):null]},`room-${R}`)),(0,F.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>m(k=>[...k,Kv()]),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:k=>d(k.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:Pv.map(k=>(0,F.jsxs)("button",{type:"button",className:`truss-estimator__option-card${b===k.id?" is-selected":""}`,onClick:()=>_(k.id),children:[(0,F.jsx)(_x,{profile:k.id}),(0,F.jsx)("div",{className:"truss-estimator__option-title",children:k.label}),(0,F.jsx)("div",{className:"truss-estimator__option-copy",children:k.blurb})]},k.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?.(h),disabled:f<=0,children:a})]})]})]})})}var Yn=X(je()),oe=X(ee()),dl=e=>Number.parseFloat(e)||0;function tm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Yn.useState)("studs"),[n,o]=(0,Yn.useState)(""),[l,c]=(0,Yn.useState)(""),[p,m]=(0,Yn.useState)("600"),[g,d]=(0,Yn.useState)("2.4"),b=n&&l&&p?Math.ceil(dl(l)/(dl(p)/1e3))+1:0,_=b*dl(n),M=dl(g)>0?Math.ceil(_/dl(g)):0,O=[{key:r,label:{studs:"Stud timber",joists:"Joist timber",battens:"Batten timber"}[r],qty:_,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"]},h={studs:{member:"Wall height",overall:"Wall length",help:"Studs repeat across the wall length.",count:"Studs"},joists:{member:"Joist span",overall:"Overall width",help:"Joists repeat across the overall floor or deck width.",count:"Joists"},battens:{member:"Batten length",overall:"Overall width",help:"Battens repeat across the overall lining or cladding width.",count:"Battens"}}[r];return(0,oe.jsx)(oe.Fragment,{children:(0,oe.jsxs)("div",{className:"truss-estimator",children:[(0,oe.jsxs)("div",{className:"quick-order-hero",children:[(0,oe.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,oe.jsx)("h1",{children:"Timber Calculator"}),(0,oe.jsx)("p",{children:"Estimate studs, joists or battens from a run length, width and spacing."})]}),(0,oe.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,oe.jsx)("h2",{className:"truss-estimator__step-title",children:"Member size and spacing"}),(0,oe.jsxs)("p",{className:"truss-estimator__step-sub",children:[h.help," Enter the member length and centres to estimate the number of pieces and stock lengths."]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber use"}),(0,oe.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:Object.keys(f).map(w=>(0,oe.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===w?" is-selected":""}`,onClick:()=>i(w),children:[(0,oe.jsx)("div",{className:"truss-estimator__option-title",children:f[w][0]}),(0,oe.jsx)("div",{className:"truss-estimator__option-copy",children:f[w][1]})]},w))})]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Dimensions and spacing"}),(0,oe.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsxs)("span",{children:[h.member," (m)"]}),(0,oe.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:w=>o(w.target.value)})]}),(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsxs)("span",{children:[h.overall," (m)"]}),(0,oe.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:w=>c(w.target.value)})]})]}),(0,oe.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsx)("span",{children:"Centres (mm)"}),(0,oe.jsxs)("select",{value:p,onChange:w=>m(w.target.value),children:[(0,oe.jsx)("option",{value:"300",children:"300 mm"}),(0,oe.jsx)("option",{value:"400",children:"400 mm"}),(0,oe.jsx)("option",{value:"450",children:"450 mm"}),(0,oe.jsx)("option",{value:"600",children:"600 mm"})]})]}),(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsx)("span",{children:"Stock length (m)"}),(0,oe.jsxs)("select",{value:g,onChange:w=>d(w.target.value),children:[(0,oe.jsx)("option",{value:"2.4",children:"2.40 m"}),(0,oe.jsx)("option",{value:"3.6",children:"3.60 m"}),(0,oe.jsx)("option",{value:"4.8",children:"4.80 m"})]})]})]})]}),(0,oe.jsxs)("div",{className:"materials-calculator__totals",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,oe.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:h.count}),(0,oe.jsx)("strong",{children:b})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:"Linear metres"}),(0,oe.jsxs)("strong",{children:[_.toFixed(2)," m"]})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsxs)("span",{children:[g," m lengths"]}),(0,oe.jsx)("strong",{children:M})]})]}),(0,oe.jsx)("p",{className:"materials-calculator__note",children:"Spacing is measured centre-to-centre. Add extra timber for plates, noggins, trimming and openings where required."})]}),(0,oe.jsxs)("div",{className:"materials-calculator__actions",children:[(0,oe.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,oe.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(O),disabled:_<=0,children:a})]})]})]})})}var am=[{id:"truss",title:"Roof Truss Calculator",desc:"Estimate trusses, girders and roof structure costs.",imageUrl:"/tool-images/truss.webp",Component:Wd},{id:"fencing",title:"Fencing Calculator",desc:"Estimate fence panels, posts, gravel boards and fixings.",imageUrl:"/tool-images/fencing.webp",Component:Xd},{id:"decking",title:"Decking Calculator",desc:"Estimate boards, substructure and fixing quantities.",imageUrl:"/tool-images/decking.webp",Component:$d},{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:jd},{id:"paint",title:"Paint Calculator",desc:"Estimate paint for walls, doors and multiple coats.",imageUrl:"/tool-images/paint.webp",Component:Kd},{id:"skirting",title:"Skirting Board Calculator",desc:"Estimate skirting lengths for rooms and wall runs.",imageUrl:"/tool-images/skirting.webp",Component:em},{id:"architrave",title:"Architrave Calculator",desc:"Estimate architrave lengths for door and window openings.",imageUrl:"/tool-images/architrave.webp",Component:Hd},{id:"concrete-aggregate",title:"Concrete and Aggregate Calculator",desc:"Estimate concrete, MOT, sand and gravel quantities.",imageUrl:"/tool-images/concrete-aggregate.webp",Component:Gd},{id:"plasterboard",title:"Plasterboard Calculator",desc:"Estimate plasterboard sheets, screws, tape and adhesive.",imageUrl:"/tool-images/plasterboard.webp",Component:Id},{id:"insulation",title:"Insulation Calculator",desc:"Estimate insulation packs for floors, walls, roofs and lofts.",imageUrl:"/tool-images/insulation.webp",Component:Zd},{id:"timber",title:"Timber Calculator",desc:"Estimate studs, joists and battens from spacing and lengths.",imageUrl:"/tool-images/timber.webp",Component:tm},{id:"paving",title:"Paving and Driveway Calculator",desc:"Estimate paving, block paving, MOT and sharp sand.",imageUrl:"/tool-images/paving.webp",Component:Jd}];var kc=X(je());var He=X(je());var xx=new Set(["bag","box","roll","pack"]),kx=new Set(["each","bag","box","roll","pack","tub"]);function ml(e,t){let r=(t?.conversion?.request_uoms_supported??"").split(",").map(o=>o.trim().toLowerCase()).includes("sales_unit");if(e==="each"){let o=(t?.uoi_count??1)===1&&(t?.conversion?.sales_unit_size??1)===1;return r&&o?"sales_unit":e}if(!xx.has(e))return e;if(r)return"sales_unit";let i=t?.uoi;return i!=null&&kx.has(i.toLowerCase())&&(t?.uoi_count??1)===1?i:e}var Fv=new Map;function Sx(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 Ci(e,t,a=12,r){let i=`${Ot().client??""}||${e}||${t??""}||${a}||${r??""}`,n=Fv.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(za(`/api/catalogue/search?${o.toString()}`),{headers:hi()}),c=await Qa(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(Sx):[];return Fv.set(i,p),p}async function Iv(e,t,a){return await Promise.all(e.map(async i=>{try{let n=a?cl(a,i):null,[o,l]=await Promise.all([n?Ci(n,void 0,void 0,t).then(p=>p.find(m=>m.product_id===n.split(" ")[0]),()=>{}):void 0,Ci(i.query,i.category,void 0,t)]),c=o?[o,...l.filter(p=>p.product_id!==o.product_id)]:l;return{requirement:i,candidates:c}}catch{return{requirement:i,candidates:[]}}}))}async function Wv(){let e=await fetch(za("/api/catalogue"),{headers:hi()});if(!e.ok)return{itemCount:0,uploadedAt:null};let t=await Qa(e);return{itemCount:Number(t?.itemCount)||0,uploadedAt:t?.uploadedAt??null}}var C=X(ee()),Nx=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}],rm={wasteFactorEnabled:!0},Cx=3e3,e0=null;function xc(e,t){let a=al(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function qx(e){return e&&e.length>0?e.join(" x "):"-"}function im({toolId:e,requirements:t,ready:a,onBack:r,onTotalChange:i}){let n=Nv(),o=`${e}~${t.map(N=>`${N.key}|${N.query}|${N.category??""}|${N.qty}`).join("~")}`,l=o!==e0,[c,p]=(0,He.useState)(null),[m,g]=(0,He.useState)([]),[d,b]=(0,He.useState)(l),[_,M]=(0,He.useState)(null),[O,f]=(0,He.useState)("tile"),[u,h]=(0,He.useState)(null),[w,k]=(0,He.useState)(""),[R,z]=(0,He.useState)(null),[U,A]=(0,He.useState)(""),[j,ie]=(0,He.useState)([]),[qe,Ke]=(0,He.useState)(new Set),[Oe,Me]=(0,He.useState)(null),[ge,le]=(0,He.useState)(""),[Ve,Te]=(0,He.useState)([]),ct=(0,He.useRef)(null),Z=(0,He.useRef)(!1),be=N=>`${e}:${N}`,Re=N=>zn(N.chosen,{lineId:be(N.requirement.key),description:N.requirement.label,unit:ml(N.requirement.unit,N.chosen),qty:N.requirement.qty}),wt=(0,He.useMemo)(()=>t.map(N=>`${N.key}|${N.query}|${N.category??""}`).join("~"),[t]);(0,He.useEffect)(()=>{let N=!1;return Wv().then(L=>{N||p(L.itemCount>0)}).catch(()=>{N||p(!1)}),()=>{N=!0}},[]),(0,He.useEffect)(()=>{if(!a||!c)return;let N=!1,L;l&&b(!0),M(null);let $=Date.now();return(async()=>{let se=null;try{se=(await Iv(t,void 0,e)).map(({requirement:yt,candidates:at})=>({requirement:yt,candidates:at,chosen:at[0]??null}))}catch(ke){N||M(ke instanceof Error?ke.message:"Could not load products")}if(!N){if(e0=o,l){let ke=Cx-(Date.now()-$);ke>0&&await new Promise(yt=>{L=window.setTimeout(yt,ke)})}N||(se&&(g(se),!Z.current&&n&&(Z.current=!0,n.addManyToCart(se.filter(ke=>ke.chosen).map(Re)))),b(!1))}})(),()=>{N=!0,window.clearTimeout(L)}},[a,c,wt]),(0,He.useEffect)(()=>{if(!R)return;let N=U.trim();if(!N){ie([]);return}let L=!1,$=window.setTimeout(()=>{Ci(N).then(se=>{L||ie(se)}).catch(()=>{L||ie([])})},250);return()=>{L=!0,window.clearTimeout($)}},[R,U]),(0,He.useEffect)(()=>{if(!Oe)return;let N=ge.trim();if(!N){Te([]);return}let L=!1,$=window.setTimeout(()=>{Ci(N).then(se=>{L||Te(se)}).catch(()=>{L||Te([])})},250);return()=>{L=!0,window.clearTimeout($)}},[Oe,ge]);let Gt=(0,He.useMemo)(()=>{let N=w.trim().toLowerCase(),L=N?m.filter($=>$.requirement.label.toLowerCase().includes(N)||($.chosen?.description??"").toLowerCase().includes(N)||($.chosen?.product_id??"").toLowerCase().includes(N)):m;return u?[...L].sort(($,se)=>{let ke=$.requirement.label.localeCompare(se.requirement.label);return u==="asc"?ke:-ke}):L},[m,w,u]),Ct=Gt.filter(N=>N.chosen),vt=Gt.filter(N=>!N.chosen),we=m.filter(N=>N.chosen),de=we.filter(N=>N.chosen?.price==null).length,tt=we.reduce((N,L)=>N+(It(Re(L),rm).lineTotal??0),0);if((0,He.useEffect)(()=>{i?.(tt)},[tt,i]),!a||c===!1)return null;let T=n?we.filter(N=>n.cart[be(N.requirement.key)]).length:0,Q=Oe?m.find(N=>N.requirement.key===Oe)??null:null,ue=ge.trim()?Ve:Q?.candidates??[],ve=N=>{let L=R===N.requirement.key;z(L?null:N.requirement.key),A(L?"":N.requirement.query)},Ye=(N,L)=>{let $=m.find(se=>se.requirement.key===N);g(se=>se.map(ke=>ke.requirement.key===N?{...ke,chosen:L}:ke)),n&&$&&n.cart[be(N)]&&n.addToCart(Re({...$,chosen:L})),z(null),A("")},Ce=N=>{g(L=>L.map($=>$.requirement.key===N?{...$,chosen:null}:$)),n?.cart[be(N)]&&n.removeFromCart(be(N))},S=N=>{Me(N.requirement.key),le(""),Te([])},y=()=>{Me(null),le(""),Te([])},E=N=>{if(!n)return;let L=be(N.requirement.key);n.cart[L]?n.removeFromCart(L):n.addToCart(Re(N))},D=N=>{Ke(L=>{let $=new Set(L);return $.has(N)?$.delete(N):$.add(N),$})},V=N=>{let L=j.length>0?j:N.candidates;return(0,C.jsxs)("div",{className:"estimator-products__picker",children:[(0,C.jsx)("input",{type:"text",className:"results-search-input",value:U,autoFocus:!0,placeholder:"Search products in catalogue...",onChange:$=>A($.target.value),"aria-label":`Search a product for ${N.requirement.label}`}),(0,C.jsxs)("div",{className:"estimator-products__options",children:[L.map($=>(0,C.jsxs)("button",{type:"button",className:`estimator-products__option${$.product_id===N.chosen?.product_id?" is-selected":""}`,onClick:()=>Ye(N.requirement.key,$),children:[(0,C.jsx)("span",{children:$.description}),(0,C.jsxs)("span",{className:"results-row-meta",children:[$.product_id,$.price!=null&&` \xB7 ${ot($.price)}`]})]},$.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:[!d&&(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."})]}),!Q&&(0,C.jsx)("div",{className:"results-summary estimator-products__toolbar",children:(0,C.jsxs)("div",{className:"estimator-products__controls",children:[(0,C.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:w,onChange:N=>k(N.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${O==="tile"?" is-active":""}`,"aria-pressed":O==="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${O==="list"?" is-active":""}`,"aria-pressed":O==="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:ct,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(N=>{let L=u===N.dir;return(0,C.jsxs)("button",{type:"button",className:`sort-menu-item${L?" is-active":""}`,onClick:()=>{h(L?null:N.dir),ct.current?.removeAttribute("open")},children:[(0,C.jsx)("span",{className:"sort-menu-item__check",children:L?"\u2713":""}),N.label]},N.dir)})})]})]})})]}),Q&&(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:y,children:[(0,C.jsx)(Vr,{}),"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:ge,onChange:N=>le(N.target.value),"aria-label":`Search a product for ${Q.requirement.label}`})}),Q.chosen&&(0,C.jsx)("div",{className:"results-candidate-actions",children:(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ce(Q.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(Q.chosen?.description||Q.requirement.label,Q.chosen?.product_id,Q.chosen?.pdp_photo_url),alt:""})}),(0,C.jsxs)("div",{className:"results-review-page__summary",children:[(0,C.jsx)("h2",{children:Q.requirement.label}),(0,C.jsxs)("p",{className:"results-review-page__meta",children:[wi(Q.requirement.qty)," ",ka(Q.requirement.unit,Q.requirement.qty)]}),Q.chosen?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)("div",{className:"results-review-page__product",children:Q.chosen.description}),(0,C.jsxs)("div",{className:"results-row-meta",children:[Q.chosen.product_id,Q.chosen.price!=null?` \xB7 ${xc(Q.chosen.price,Q.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[be(Q.requirement.key)]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(Q),disabled:!Q.chosen||!n,children:n?.cart[be(Q.requirement.key)]?"\u2713 Added":"+ Add to basket"})})]})]}),ue.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:ue.map(N=>{let L=N.product_id===Q.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:N.description}),(0,C.jsx)("div",{className:"results-row-meta",children:N.product_id})]}),(0,C.jsx)("td",{children:(0,C.jsx)("span",{className:"unit-badge",children:qx(N.measurements_mm)})}),(0,C.jsx)("td",{children:N.price!=null?xc(N.price,N.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?Ce(Q.requirement.key):Ye(Q.requirement.key,N)},"aria-label":L?`${N.description} selected`:`Use ${N.description}`}),(0,C.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},N.product_id)})})]})]}),!Q&&d&&(0,C.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{padding:"32px 24px"},children:[(0,C.jsx)(gi,{}),(0,C.jsx)("p",{className:"banter-message is-visible",style:{fontSize:15,minHeight:0},children:"Matching your materials against the catalogue\u2026"})]}),!Q&&_&&(0,C.jsx)("p",{className:"results-empty-hint estimator-products__error",children:_}),!Q&&!d&&!_&&Gt.length===0&&m.length>0&&(0,C.jsx)("p",{className:"results-empty-hint",children:"No materials match the current search."}),!Q&&!d&&!_&&O==="tile"&&Ct.length>0&&(0,C.jsx)("div",{className:"results-tile-grid",children:Ct.map(N=>{let{requirement:L,chosen:$}=N,se=$?It(Re(N),rm):null,ke=n?!!n.cart[be(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:()=>S(N),"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($?.description||L.label,$?.product_id,$?.pdp_photo_url),alt:""})}),(0,C.jsxs)("div",{className:"results-tile-card__body",children:[$?(0,C.jsxs)("div",{className:"results-tile-card__heading",children:[(0,C.jsx)("div",{className:"results-tile-card__title",children:$.description}),(0,C.jsxs)("div",{className:"results-tile-card__match-meta",children:[(0,C.jsx)("span",{children:$.product_id}),$.price!=null?(0,C.jsx)("span",{children:xc($.price,$.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:[wi(L.qty)," ",ka(L.unit,L.qty)]}),se?.requiredSellUnits!=null?(0,C.jsxs)("div",{className:"results-tile-card__meta estimator-products__order",children:["Order ",se.requiredSellUnits," ",se.sellUnit,se.lineTotal!=null?` \xB7 ${ot(se.lineTotal)}`:""]}):$?(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:()=>S(N),children:"Review"}),(0,C.jsx)("button",{type:"button",className:`bom-toolbar-btn${ke?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(N),disabled:!$||!n,children:ke?"\u2713 Added":"+ Add"})]})]},L.key)})}),!Q&&!d&&!_&&O==="list"&&Ct.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:Ct.map(N=>{let{requirement:L,chosen:$}=N,se=$?It(Re(N),rm):null,ke=n?!!n.cart[be(L.key)]:!1,yt=qe.has(L.key);return(0,C.jsxs)(He.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:()=>D(L.key),"aria-expanded":yt,"aria-label":yt?"Collapse product options":"Expand product options",children:yt?"\u25BE":"\u25B8"})}),(0,C.jsxs)("td",{style:{paddingLeft:0},children:[(0,C.jsx)("div",{className:"bom-component-name",children:L.label}),se?.requiredSellUnits!=null&&(0,C.jsxs)("div",{className:"results-row-meta",children:["Order ",se.requiredSellUnits," ",se.sellUnit,se.lineTotal!=null?` \xB7 ${ot(se.lineTotal)}`:""]})]}),(0,C.jsx)("td",{className:"bom-qty col-order",style:{textAlign:"center"},children:wi(L.qty)}),(0,C.jsx)("td",{style:{textAlign:"center"},children:ka(L.unit,L.qty)}),(0,C.jsx)("td",{style:{textAlign:"center"},children:$?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)("div",{className:"bom-component-name",children:$.description}),(0,C.jsxs)("div",{className:"results-row-meta",children:[$.product_id,$.price!=null&&` \xB7 ${xc($.price,$.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${ke?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(N),disabled:!$||!n,children:ke?"\u2713 Added":"+ Add"})})]}),yt&&(0,C.jsx)("tr",{children:(0,C.jsx)("td",{colSpan:6,style:{paddingLeft:0,paddingRight:0},children:R===L.key?V(N):(0,C.jsxs)("div",{className:"estimator-products__picker",children:[(0,C.jsxs)("div",{className:"estimator-products__options",children:[N.candidates.map(at=>(0,C.jsxs)("button",{type:"button",className:`estimator-products__option${at.product_id===$?.product_id?" is-selected":""}`,onClick:()=>Ye(L.key,at),children:[(0,C.jsx)("span",{children:at.description}),(0,C.jsxs)("span",{className:"results-row-meta",children:[at.product_id,at.price!=null&&` \xB7 ${ot(at.price)}`]})]},at.product_id)),N.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:()=>ve(N),children:"Search the catalogue"})]})})})]},L.key)})})]})}),!Q&&!d&&!_&&vt.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:vt.map(N=>(0,C.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>S(N),children:[(0,C.jsxs)("span",{className:"results-unmatched-card__main",children:[(0,C.jsx)("span",{className:"results-unmatched-card__title",children:N.requirement.label}),(0,C.jsxs)("span",{className:"results-row-meta",children:[wi(N.requirement.qty)," ",ka(N.requirement.unit,N.requirement.qty)]})]}),(0,C.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},N.requirement.key))})]}),!d&&!_&&m.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."})]}),!Q&&!d&&!_&&(r||T>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"}),T>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 (",T,")"]}),(0,C.jsx)("span",{className:"arrow",children:(0,C.jsx)(jt,{})})]})]})]})}var Qt=X(ee());function nm({toolId:e,toolTitle:t,requirements:a,onBack:r}){let[i,n]=(0,kc.useState)(0),o=(0,kc.useCallback)(l=>n(l),[]);return(0,Qt.jsx)(Qt.Fragment,{children:(0,Qt.jsxs)("div",{className:"truss-estimator",children:[(0,Qt.jsxs)("div",{className:"quick-order-hero",children:[(0,Qt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Qt.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,Qt.jsx)("h1",{children:"Your Materials"}),i>0&&(0,Qt.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,Qt.jsx)("strong",{children:ot(i)})," Est. total"]})]}),(0,Qt.jsxs)("p",{children:["Quantities from the ",t,", matched against your merchant\u2019s catalogue."]})]}),(0,Qt.jsx)("div",{className:"truss-estimator__card",style:{minHeight:0},children:(0,Qt.jsx)(im,{toolId:e,requirements:a,ready:!0,onBack:r,onTotalChange:o})})]})})}var om=X(je());var Wt=X(ee()),Ex=1500;function t0(e){let{addManyToCart:t,clearCart:a,openBasket:r}=On(),[i,n]=(0,om.useState)(!1),[o,l]=(0,om.useState)(null);return{adding:i,basketError:o,addToBasket:async(p,m)=>{let g=Date.now();n(!0),l(null);try{let d=await Promise.all(p.filter(_=>_.qty>0).map(async _=>{let M=(await Ci(_.search)).find(O=>O.product_id===_.productId);if(!M)throw new Error("A selected product is no longer available in this catalogue.");return zn(M,{lineId:`${e}:${_.key}`,description:M.description,unit:ml(_.unit??"each",M),qty:_.qty,calculatorWasteIncluded:m})})),b=Ex-(Date.now()-g);b>0&&await new Promise(_=>window.setTimeout(_,b)),a(),t(d),r()}catch(d){l(d instanceof Error?d.message:"Could not add the products to your basket.")}finally{n(!1)}}}}function a0({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)(gi,{}),(0,Wt.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})})}var ze=X(ee());function Sc(e){let[t,a]=(0,$a.useState)(!1);return(0,ze.jsx)(lc,{onOpenBasket:()=>a(!0),children:(0,ze.jsx)(Mx,{...e,showBasket:t,onShowBasket:a})})}function Mx({fullPage:e=!1,hideHeader:t=!1,internal:a=!1,showBasket:r,onShowBasket:i}){let[n,o]=(0,$a.useState)(null),[l,c]=(0,$a.useState)(null),p=am.find(U=>U.id===n),{cart:m,updateCartQty:g,updateCartSellUnits:d,updateCartConversions:b,removeFromCart:_,clearCart:M}=On(),{adding:O,basketError:f,addToBasket:u}=t0(p?.title??"calculator"),h=(0,$a.useRef)(null),w=Zs("estimating-tools",h);(0,$a.useEffect)(()=>{w("viewed")},[w]);let k=r?"basket":O?"adding":l?"review":n??"list",R=(0,$a.useRef)(k);(0,$a.useEffect)(()=>{R.current!==k&&(R.current=k,window.scrollTo(0,0))},[k]);let z=U=>{if(!p)return;w("estimate_completed",{calculator:p.id,lines:U.length});let A=Tv(p.id,U);A?u(A,U[0]?.calculatorWasteIncluded??!1):c(U)};return(0,ze.jsx)(Fo.Provider,{value:w,children:(0,ze.jsx)("div",{ref:h,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${a?"":" estimating-tools--customer"}`,style:Ot().theme,children:(0,ze.jsx)("main",{className:"main-content",children:r?(0,ze.jsx)(sl,{cart:m,onUpdateQty:g,onUpdateSellUnits:d,onResolveConversions:b,onRemove:_,onBack:()=>i(!1),onStartNewQuote:()=>{M(),o(null),c(null),i(!1)},internal:a}):O&&p?(0,ze.jsx)(a0,{toolTitle:p.title}):p?(0,ze.jsxs)(ze.Fragment,{children:[(0,ze.jsx)("div",{hidden:l!==null,children:(0,ze.jsx)(p.Component,{onBack:()=>o(null),onReview:z})}),f&&(0,ze.jsx)("p",{className:"results-empty-hint estimator-products__error",children:f}),l!==null&&(0,ze.jsx)(nm,{toolId:p.id,toolTitle:p.title,requirements:l,onBack:()=>c(null)})]}):(0,ze.jsx)(ze.Fragment,{children:(0,ze.jsxs)("div",{className:"quick-order-card",children:[(0,ze.jsxs)("div",{className:"quick-order-hero",children:[(0,ze.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,ze.jsx)("h1",{children:"Estimating Tools"}),(0,ze.jsx)("p",{children:"Trade-specific calculators for trusses, fencing, decking, masonry and painting. Dial in your specs and get an instant material estimate."})]}),(0,ze.jsxs)("div",{className:"quick-order-alt",children:[(0,ze.jsx)("div",{className:"quick-order-alt-title",children:"Choose a Calculator"}),(0,ze.jsx)("div",{className:"estimator-tools-grid",children:am.map(U=>(0,ze.jsxs)("button",{type:"button",className:"estimator-tool-card",onClick:()=>{w("calculator_selected",{calculator:U.id}),o(U.id),c(null)},children:[(0,ze.jsx)("span",{className:"estimator-tool-card__image-wrap",children:(0,ze.jsx)("img",{className:"fill-img estimator-tool-card__image",src:Ft(U.imageUrl),alt:""})}),(0,ze.jsxs)("span",{className:"estimator-tool-card__content",children:[(0,ze.jsx)("span",{className:"estimator-tool-card__title",children:U.title}),(0,ze.jsx)("span",{className:"estimator-tool-card__desc",children:U.desc})]})]},U.id))})]})]})})})})})}var Nc=X(ee());function lm({config:e,children:t}){return pw(e),(0,Nc.jsx)(Nc.Fragment,{children:t})}var sm=X(ee()),Tx="https://api.metronlabs.ai",zx=["client","api-key","api-url","theme","hide-header","analytics"],Rx=["all","events-only","none"];function i0(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.64",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; }
|
|
6993
|
+
`)}function zn(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 bv=e=>(e??"").trim().toLowerCase(),S_={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",piece:"each",pieces:"each",board:"sheet",bags:"bag",length:"length",lengths:"length",pallet:"pallet",pallets:"pallet"},Ed=new Set(["sheet","length","box","bag","pack","roll","set","tub","each"]),mv=new Set(["box","bag","pack","pallet","roll","set","tub"]),Md=(e,t)=>t==="ml"?e:["l","litre","litres"].includes(t)?e*1e3:null,Td=(e,t)=>t==="g"?e:["kg","kilogram","kilograms"].includes(t)?e*1e3:["t","tonne","tonnes"].includes(t)?e*1e6:null,dr=e=>{let t=bv(e);return S_[t]??t},rt=(e,t)=>{let a=dr(e),r=dr(t);return a.length>0&&a===r},fv=(e,t)=>{let a=bv(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},N_=e=>(e??"").split(",").map(t=>dr(t)).filter(Boolean),C_=(e,t)=>{let a=N_(e.requestUomsSupported);return!!(a.length===0||a.includes(t)||rt(t,"pallet")&&e.itemsPerPallet!=null&&e.itemsPerPallet>0||rt(t,"pack")&&e.itemsPerPack!=null&&e.itemsPerPack>0||rt(t,"box")&&e.itemsPerBox!=null&&e.itemsPerBox>0)},hv=(e,t)=>rt(t,"pallet")?e.itemsPerPallet??null:rt(t,"pack")?e.itemsPerPack??null:rt(t,"box")?e.itemsPerBox??null:null,gv=(e,t)=>{let a=t==="volume"?/(\d+(?:[.,]\d+)?)\s*(ml|l|ltr|ltrs|litres?|liters?)\b/i:/(\d+(?:[.,]\d+)?)\s*(kg|kgs|tonnes?)\b/i,r=e.description.match(a);if(!r)return null;let i=Number.parseFloat(r[1].replace(",","."));if(!Number.isFinite(i)||i<=0)return null;let n=r[2].toLowerCase();return t==="volume"?{ml:n==="ml"?i:i*1e3}:{g:n.startsWith("tonne")?i*1e6:i*1e3}},q_=["volume_from_description","same_unit_volume"],E_=["weight_from_description","mass_from_pack","same_unit_mass"],M_=(e,t,a)=>{if(!rt(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||!rt(r[3],a))return null;let i=Number.parseFloat(r[1].replace(",","."));return Number.isFinite(i)&&i>0?i:null};function ic(e,t){let a=e.map(r=>It(r,t).lineTotal);return a.some(r=>r==null)?null:a.reduce((r,i)=>r+(i??0),0)}function It(e,t){let a=e.qty,r=dr(e.saleUnit??e.salesUnitSizeUom??e.uoi??e.salesUomNormalised)||"-",i=dr(e.unit)||(a>0&&Ed.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?Ed.has(r)?Math.ceil(e.sellUnitsOverride):e.sellUnitsOverride:null,p=A=>({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?`${A} Manually set to ${c} ${r}.`:A,costingMode:"review"});if(!Number.isFinite(a)||a<=0)return p("Quantity needs confirmation.");let m=Md(a,i),g=Td(a,i),d=rt(i,r)?null:m!=null&&!q_.includes(e.conversionType??"")?gv(e,"volume"):g!=null&&!E_.includes(e.conversionType??"")?gv(e,"weight"):null,b=d?.ml!=null?m:g,_=d?.ml??d?.g??null;if(b!=null&&_!=null){let A=dr(e.uoi)||r,j=d?.ml!=null?`${_/1e3} l`:`${_/1e3} kg`,ie=l?c:Math.ceil(b*(1+o)/_-1e-9);return{requestedAmount:a,requestedUnit:i,salesUnitSize:1,sellUnit:A,calculatedSellUnits:ie,requiredSellUnits:ie,unitPrice:e.price,lineTotal:e.price!=null?e.price*ie:null,calculation:`${a} ${i}${o>0?` x ${1+o}`:""} / ${j} per ${A} (from product description) = ${ie} ${A}`,costingMode:"derived"}}if(i==="sales_unit"){let A=dr(e.uoi)||r,j=l?c:fv(a*(1+o),e.roundingRule??"round_up_each");return{requestedAmount:a,requestedUnit:A,salesUnitSize:1,sellUnit:A,calculatedSellUnits:j,requiredSellUnits:j,unitPrice:e.price,lineTotal:e.price!=null?e.price*j:null,calculation:`${a} ${A}${o>0?` x ${1+o}`:""} = ${j} ${A}`,costingMode:"direct"}}if(!C_(e,i))return p("Requested unit is not supported by this catalogue conversion.");let M=null,O="review",f=e.roundingRule,u=`Quantity review required, initial request needed ${a} ${i}.`,h=1+o,w=M_(e,i,r),k=e.unitConversions?.find(A=>rt(A.requestUom,i));if(!!e.saleUnit&&(rt(i,r)||!!k||rt(i,"each")&&!mv.has(r)))if(rt(i,r))M=a*h/n,O="direct",u=`${a} ${i}${o>0?` x ${h}`:""}`;else if(k){M=a*h/k.quantityPerSaleUnit,O="derived";let A=1/k.quantityPerSaleUnit,j=Math.round(A);u=rt(r,"each")&&k.quantityPerSaleUnit<1&&Math.abs(A-j)<1e-9?`${a} ${i}${o>0?` x ${h}`:""} x ${j} per ${i}`:`${a} ${i}${o>0?` x ${h}`:""} / ${k.quantityPerSaleUnit} ${i} per ${r}`}else rt(i,"each")&&!mv.has(r)&&(M=a*h/n,O="derived",u=`${a} ${r}${o>0?` x ${h}`:""}`);else if(rt(i,r)&&n>0)M=a*h/n,O="direct",u=o>0?`${a} ${i} x ${h} / ${n} ${r} per sell unit`:`${a} ${i} / ${n} ${r} per sell unit`;else if(rt(i,"each")&&n>0&&Ed.has(r))M=a*h/n,O="derived",u=o>0?`${a} each x ${h} / ${n} each per ${r}`:`${a} each / ${n} each per ${r}`;else if(hv(e,i)!=null&&n>0){let A=hv(e,i)??0;M=a*A*h/n,O="derived";let j=`${a} ${i} x ${A} each${o>0?` x ${h}`:""}`;u=n===1&&rt(r,"each")?j:`${j} / ${n} each per ${r}`}else if(w!=null)M=a*h/w,O="derived",f??(f="round_up_each"),u=`${a} m2 x ${h} / ${w} m2 per ${r} (from product description)`;else if(e.conversionType==="basket_line_unit")n>0&&(M=a*h/n,O="derived",u=`${a} ${i}${o>0?` x ${h}`:""} / ${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 A=e.coverageQty??e.derivedCoverageM2??null;rt(i,"m2")&&A!=null&&A>0&&(M=a*h/A,O="derived",u=`${a} m2 x ${h} / ${A} m2 per ${r}`)}else if(e.conversionType==="count_per_area"){let A=e.coverageQty??null;rt(i,"m2")&&A!=null&&A>0?(M=a/A,O="derived",u=`${a} m2 / ${A} m2 per sell unit`):rt(i,"m2")&&e.itemsPerM2!=null&&e.itemsPerM2>0&&n>0&&(M=a*e.itemsPerM2*h/n,O="derived",u=`${a} m2 x ${e.itemsPerM2} ${r}/m2 x ${h} / ${n}`)}else if(e.conversionType==="length_from_dims"){let A=e.coverageQty??e.derivedLengthM??null;rt(i,"m")&&A!=null&&A>0&&(M=a*h/A,O="derived",u=`${a} m x ${h} / ${A} m per ${r}`)}else if(e.conversionType==="volume_from_description"){let A=Md(a,i),j=Md(e.coverageQty??0,dr(e.coverageUom));A!=null&&j!=null&&j>0&&(M=A*h/j,O="derived",u=`${a} ${i} x ${h} / ${e.coverageQty} ${e.coverageUom} per ${r}`)}else if(e.conversionType==="weight_from_description"||e.conversionType==="mass_from_pack"){let A=dr((e.coverageUom??"").split(" ")[0]),j=Td(a,i),ie=Td(e.coverageQty??0,A);j!=null&&ie!=null&&ie>0&&(M=j*h/ie,O="derived",u=`${a} ${i} x ${h} / ${e.coverageQty} ${A} per ${r}`)}else if(e.conversionType==="same_unit_volume"){let A=e.coverageQty??null;rt(i,"m3")&&A!=null&&A>0&&(M=a/A,O="derived",u=`${a} m3 / ${A} m3 per ${r}`)}}if(M==null||!Number.isFinite(M)||M<0)return p(`Quantity review required, initial request needed ${a} ${i}.`);let z=fv(M,f),U=l?c:z;return{requestedAmount:a,requestedUnit:i,salesUnitSize:n,sellUnit:r,calculatedSellUnits:z,requiredSellUnits:U,unitPrice:e.price,lineTotal:e.price!=null&&U!=null?e.price*U:null,calculation:l?`${u} = ${z} ${r} (manually set to ${U})`:`${u} = ${U} ${r}`,costingMode:O}}var wv=()=>import("./xlsx-K4MOA2QM.js"),il=["Source Line ID","Split Line ID","Description","Section","Qty","Unit","Procurement intent","Procurement aliases","Build-up type","Layer count","Total thickness (mm)","Installation clues","System clues","Component requirements","Technical classification","Include in quote","Approval required","Approval type","Missing information","Adjudicator confidence","Decision reason","Selected candidate ID","Selected candidate description","Price basis","Price","Line total","Confidence","Status"],T_=il.indexOf("Line total");function z_(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 vv(e){let t=await wv(),a=t.utils.book_new(),r=new Date().toISOString().slice(0,10),i=[il],n=0;for(let c of e){let{item:p,best:m,qty:g,band:d,unmatchable:b,decision:_}=c,M=[p.section,p.subsection,p.subheading].filter(Boolean).join(" / "),O=!b&&m?.price!=null?m.price*g:null;O!=null&&(n+=O),i.push([p.source_line_id,p.line_id,p.description_original||"(no description)",M,g,p.unit,p.procurement_intent||"-",p.procurement_aliases.join(", "),p.build_up_type,p.layer_count,p.total_required_thickness_mm,p.installation_clues.join(", "),p.system_clues.join(", "),p.component_requirements.join(", "),_?.technical_classification??"",_?.include_in_quote==null?"":_.include_in_quote?"yes":"no",_?.approval_required==null?"":_.approval_required?"yes":"no",_?.approval_type??"",_?.missing_information.join(", ")??"",_?.confidence??"",_?.reason??"",b?"-":m?.product_id??_?.selected_candidate_id??"-",b?"-":m?.description??"-",b?"-":m?.price_basis??"-",b?null:m?.price??null,O,b?"-":d,z_(c)])}i.push(Array(il.length).fill(null));let o=Array(il.length).fill(null);o[0]="Estimated total",o[T_]=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(il.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 rl=["Product ID","Description","Costing mode","Required amount","Req unit","Sell unit size","Sell unit","Required sell units","Unit price","Line total"];async function yv(e,t){let a=await wv(),r=a.utils.book_new(),i=new Date().toISOString().slice(0,10),n=t?[["Account",t.name+" ("+t.id+")"],[],rl]:[rl],o=0;for(let p of e){let m=It(p),g=m.lineTotal;g!=null&&(o+=g),n.push([p.productId,p.description,m.costingMode,m.requestedAmount,xa(m.requestedUnit),m.salesUnitSize,xa(m.sellUnit),m.requiredSellUnits,m.unitPrice,g])}n.push(Array(rl.length).fill(null));let l=Array(rl.length).fill(null);l[0]="Estimated total",l[rl.length-1]=o,n.push(l);let c=a.utils.aoa_to_sheet(n);c["!cols"]=[{wch:14},{wch:48},{wch:12},{wch:14},{wch:10},{wch:14},{wch:10},{wch:16},{wch:12},{wch:14}],a.utils.book_append_sheet(r,c,"Basket"),a.writeFile(r,t?`basket-${t.id}-${i}.xlsx`:`basket-${i}.xlsx`)}var s=X(ee()),Rd="__none__",nl=24,R_=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}];function Sv(e){return e==null?"low":e>=.7?"high":e>=.5?"medium":"low"}var A_=e=>e.attrs.supply_nature==="labour_only"||e.attrs.supply_nature==="plant"||e.flags.includes("referential");function U_(e,t){if(t!==Rd){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 _v(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 D_(e){return e?e.replace(/_/g," "):"not stated"}function O_({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 An(e,t){if(e==null)return"-";let a=al(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function Ad(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 Rn(e){let t=(e??[]).map(a=>a.trim()).filter(Boolean);return t.length>0?t.join(", "):"-"}function Xr(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 L_(e,t){return t>0||e==null?null:ot(e)}var xv=[{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 H_(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:xv[i%xv.length]})}),t}function mr(e){return!1}function Un(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 zd({meta:e}){return e?(0,s.jsx)("span",{className:"results-linked-pill",style:e.bubbleStyle,children:`Link ${e.token}`}):null}function j_(e,t,a){let r=t?.rerank?.recommendedCandidateIds??[];if(r.length===0){let o=e.slice(0,6),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,6)}function nc(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 oc(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 Q_({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:oc(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:oc(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:oc(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:oc(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 G_({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:Ad(r.measurements_mm)}),(0,s.jsx)("td",{children:al(r.price_basis)||"-"}),(0,s.jsx)("td",{children:r.bm25.toFixed(2)})]},`${r.product_id}-${i}`))})]})]},`${t.query}-${a}`))]})}function kv({item:e,result:t}){let a=t?.retrieval_debug.map(i=>i.query).filter(Boolean)??[],r=[["Procurement intent",e.procurement_intent||"-"],["Procurement aliases",Rn(e.procurement_aliases)],["Retrieval queries",Rn(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)",Ad(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",Rn(e.installation_clues)],["System clues",Rn(e.system_clues)],["Component requirements",Rn(e.component_requirements)],["Linked group",Un(e)||"-"],["Flags",Rn(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)(xe.Fragment,{children:[(0,s.jsx)("dt",{children:i}),(0,s.jsx)("dd",{children:n})]},i))})]})}function Y_({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)(xe.Fragment,{children:[(0,s.jsx)("dt",{children:"Attempted"}),(0,s.jsx)("dd",{children:t.attempted?"yes":"no"})]}),(0,s.jsxs)(xe.Fragment,{children:[(0,s.jsx)("dt",{children:"Applied"}),(0,s.jsx)("dd",{children:t.applied?"yes":"no"})]}),(0,s.jsxs)(xe.Fragment,{children:[(0,s.jsx)("dt",{children:"Returned items"}),(0,s.jsx)("dd",{children:t.returned_item_count??"-"})]}),(0,s.jsxs)(xe.Fragment,{children:[(0,s.jsx)("dt",{children:"Reason"}),(0,s.jsx)("dd",{children:t.reason||"-"})]}),(0,s.jsxs)(xe.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 $_({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)(xe.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 V_({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} - `:"",Un(e)]}):null]}):null:!t.reason&&!r?(0,s.jsx)(kv,{item:e,result:a}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(kv,{item:e,result:a}),r&&(0,s.jsx)(Y_,{item:e}),r&&(0,s.jsx)($_,{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} - `:"",Un(e)]}):null]}),r&&(0,s.jsx)(G_,{queries:a?.retrieval_debug??[]})]})}function X_({item:e,candidates:t,result:a,decision:r,unmatchable:i,selectedProductId:n,detailMode:o,onPick:l,onClear:c,showAll:p=!1,internal:m=!1,debugEnabled:g=!1,forceReviewNote:d=!1,linkedGroupMeta:b}){let _=m||o==="detailed",M=g&&o==="detailed",O=_||d?(0,s.jsx)(V_,{item:e,decision:r,result:a,showRetrievalDebug:M,reviewOnly:d&&!_,linkedGroupMeta:b}):null;if(i)return(0,s.jsxs)(s.Fragment,{children:[O,(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:[O,(0,s.jsx)("p",{className:"results-empty-hint",children:"No candidates were returned for this line item."})]});let f=p||m||o==="detailed"?t:j_(t,a,n);return(0,s.jsxs)(s.Fragment,{children:[O,(0,s.jsxs)("table",{className:"score-breakdown-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:"Product"}),(0,s.jsx)("th",{children:"Dims (mm)"}),(0,s.jsx)("th",{children:"Price"}),M&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("th",{children:"dimension"}),(0,s.jsx)("th",{children:"grade"}),(0,s.jsx)("th",{children:"brand"}),(0,s.jsx)("th",{children:"fuzzy"}),(0,s.jsx)("th",{children:"bm25"}),(0,s.jsx)("th",{children:"overall"})]}),(0,s.jsx)("th",{"aria-label":"Actions"})]})}),(0,s.jsx)("tbody",{children:f.map((u,h)=>{let w=u.product_id===n;return(0,s.jsxs)("tr",{className:w?"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:Ad(u.measurements_mm??u.debug?.candidate.measurements_mm)})}),(0,s.jsx)("td",{children:An(u.price,u.price_basis)}),M&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("td",{children:(u.scores?.dimension??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.grade??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.brand??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.fuzzy??0).toFixed(2)}),(0,s.jsx)("td",{children:(u.scores?.bm25??0).toFixed(2)}),(0,s.jsx)("td",{children:(0,s.jsxs)("div",{style:{display:"inline-flex",alignItems:"center",gap:6},children:[(0,s.jsx)(O_,{band:Sv(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:w?"Currently selected":"Use this candidate",children:[(0,s.jsx)("input",{type:"checkbox",checked:w,onChange:()=>{w?c?.():l(u)},"aria-label":w?`${u.description} selected`:`Use ${u.description}`}),(0,s.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},`${u.product_id}-${h}`)})})]})]})}function Ud({scheduleResult:e,onStartOver:t,cart:a,onAddToCart:r,onRemoveFromCart:i,onGoToBasket:n,cartSeeded:o,onCartSeeded:l,reviewGateComplete:c,onReviewGateComplete:p,internal:m=!1}){let g=!m&&Ks()==="QZA6-MRA4",d=g?"quote":"basket",{results:b,lineItems:_,parseReport:M,timings:O}=e,[f,u]=(0,xe.useState)({}),h=Nn(),[w,k]=(0,xe.useState)({}),[R,z]=(0,xe.useState)({}),[U,A]=(0,xe.useState)(""),[j,ie]=(0,xe.useState)(null),[qe,Ke]=(0,xe.useState)(1),Oe=Ot().debug===!0,[Me,ge]=(0,xe.useState)("simple"),[le,Ve]=(0,xe.useState)(m?"list":"tile"),[Te,ct]=(0,xe.useState)(!1),[Z,be]=(0,xe.useState)(null),[Re,wt]=(0,xe.useState)(""),[Gt,Ct]=(0,xe.useState)([]),[vt,we]=(0,xe.useState)(!1),[de,tt]=(0,xe.useState)(null),[T,Q]=(0,xe.useState)(!1),[ne,ue]=(0,xe.useState)(null),ve=(0,xe.useRef)(null),[Ye,Ce]=(0,xe.useState)(new Set),[S,y]=(0,xe.useState)(new Set),[E,D]=(0,xe.useState)(!1);(0,xe.useEffect)(()=>{Ke(1)},[U,j,le]);let V=new Map(b.map(x=>[x.line_id,x])),N=H_(_),L=_.map(x=>{let G=V.get(x.line_id),fe=G?.decision,ut=A_(x),Xe=f[x.line_id],ea=U_(G,Xe),Ti=a[x.line_id],d0=Xe===Rd?void 0:w[x.line_id]??(Ti&&Ti.productId!==ea?.product_id?_v(Ti):ea),wm=ut?void 0:d0,m0=x.qty??0;return{item:x,result:G,decision:fe,unmatchable:ut,best:wm,qty:m0,band:Sv(wm?.scores?.overall)}}),se=L.some(x=>!x.unmatchable&&!x.best&&!S.has(x.item.line_id))?null:ic(Object.values(a),{wasteFactorEnabled:!1,wasteFactorOverride:0}),ke=0;for(let x of L){if(x.unmatchable||x.decision?.include_in_quote!==!0||!x.best)continue;let G=a[x.item.line_id];(!G||It(G).lineTotal==null)&&(ke+=1)}ke>0&&(se=null);let yt=L_(se,ke),at=x=>!x.unmatchable&&!x.best&&x.decision?.technical_classification!=="no_suitable_candidate"&&nc(x.result).length>0,qt=x=>x.best??nc(x.result)[0],Kr=L.filter(x=>!x.unmatchable&&!x.best).filter(x=>!S.has(x.item.line_id)),Cc=L.filter(x=>S.has(x.item.line_id)),Yt=L;if(U.trim()){let x=U.trim().toLowerCase();Yt=Yt.filter(G=>G.item.description_original?.toLowerCase().includes(x)||qt(G)?.description?.toLowerCase().includes(x))}if(j){let x=j==="asc"?1:-1;Yt=[...Yt].sort((G,fe)=>x*(G.item.description_original||"").localeCompare(fe.item.description_original||""))}let hr=Math.max(1,Math.ceil(Yt.length/nl)),_t=Math.min(qe,hr),qi=Yt.slice((_t-1)*nl,_t*nl),um=qi.filter(x=>!x.unmatchable&&x.best),Dx=qi.filter(x=>at(x)),qc=qi.filter(x=>!x.unmatchable&&(x.best||at(x))),pm=qi.filter(x=>x.unmatchable||!x.best&&!at(x)),P=Z?L.find(x=>x.item.line_id===Z)??null:null,n0=!m&&!c&&!P&&Kr.length>0,$n=(0,xe.useRef)(null),Vn=()=>{let x=ve.current;if(!x)return;let{top:G,left:fe,width:ut,height:Xe}=x.getBoundingClientRect(),Ti=x.querySelector(".bom-toolbar-btn")?.closest("td")?.getBoundingClientRect().left;ue({top:G,left:fe,width:Ti?Ti-fe:ut,height:Xe})};(0,xe.useEffect)(()=>(window.addEventListener("scroll",Vn,!0),window.addEventListener("resize",Vn),()=>{window.removeEventListener("scroll",Vn,!0),window.removeEventListener("resize",Vn)})),(0,xe.useEffect)(()=>{let x=G=>{$n.current&&!G.composedPath().includes($n.current)&&$n.current.removeAttribute("open")};return document.addEventListener("click",x),()=>document.removeEventListener("click",x)},[]);let Ei=x=>{be(x),wt("")},o0=()=>{if(!Z)return;let x=a[Z];if(x){u(G=>({...G,[Z]:x.productId})),k(G=>({...G,[Z]:_v(x)}));return}u(G=>{let fe={...G};return delete fe[Z],fe}),k(G=>{let fe={...G};return delete fe[Z],fe})},Va=(x=!1)=>{let G=Z?a[Z]:void 0;!x&&G&&P?.best&&G.productId!==P.best.product_id&&!window.confirm("You have selected a new product. Leave without updating it?")||(x||o0(),be(null),D(!1))};el(T,()=>Q(!1)),el(!!P&&!T,()=>Va());let l0=x=>{if(Ce(G=>new Set(G).add(x)),Kr.some(G=>G.item.line_id!==x)){Va(!0);return}p(),Va(!0)},s0=x=>{if(Ec(x),y(G=>new Set(G).add(x)),Kr.some(G=>G.item.line_id!==x)){Va(!0);return}p(),Va(!0)},c0=()=>{y(x=>new Set([...x,...Kr.map(G=>G.item.line_id)])),p()},dm=()=>{P?.best&&(fm(P.item.line_id,P.best),r(Xn(P)),E?l0(P.item.line_id):Va(!0))},mm=pm.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:pm.map(x=>{let{item:G,qty:fe}=x;return(0,s.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>Ei(G.line_id),children:[(0,s.jsx)("span",{className:"results-unmatched-card__main",children:(0,s.jsx)("span",{className:"results-unmatched-card__title",children:Xr(G,_)})}),(0,s.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},G.line_id)})})]}):null,Ec=x=>{u(G=>({...G,[x]:Rd})),k(G=>({...G,[x]:void 0})),z(G=>({...G,[x]:void 0})),i(x)},Mc=(x,G)=>{u(fe=>({...fe,[x]:G.product_id})),k(fe=>({...fe,[x]:G}))},fm=(x,G)=>{G.method==="catalogue_search"&&z(fe=>({...fe,[x]:G}))};function Ox(){h("downloaded",{type:"schedule",lines:L.length}),vv(L.map(({item:x,best:G,qty:fe,band:ut,unmatchable:Xe,decision:ea})=>({item:x,best:G,qty:fe,band:ut,unmatchable:Xe,decision:ea})))}function Xn(x){let G=x.best??nc(x.result)[0];return zn(G,{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?_.filter(fe=>fe.linked_group_id===x.item.linked_group_id&&fe.linked_group_role==="anchor").slice(0,1).map(fe=>{let ut=a[fe.line_id];return{line_id:fe.line_id,product_id:ut?.productId??null,measurements_mm:ut?.measurementsMm??fe.attrs.measurements_mm,description:ut?.description??fe.description_original,qty:fe.qty,unit:fe.unit,role:"anchor"}}):void 0})}(0,xe.useEffect)(()=>{if(!o){for(let x of L)!x.unmatchable&&x.best&&r(Xn(x));l()}},[o]),(0,xe.useEffect)(()=>{if(!Z){Ct([]),tt(null),we(!1);return}let x=Re.trim();if(!x){Ct([]),tt(null),we(!1);return}let G=!1,fe=window.setTimeout(async()=>{try{we(!0),tt(null);let ut=await fetch(za(`/api/catalogue/search?q=${encodeURIComponent(x)}`),{headers:hi()}),Xe=await Qa(ut);if(!ut.ok)throw new Error(Xe?.error||Xe?.message||"Failed to search catalogue");G||Ct(Array.isArray(Xe?.items)?Xe.items:[])}catch(ut){G||(Ct([]),tt(ut?.message||"Failed to search catalogue"))}finally{G||we(!1)}},250);return()=>{G=!0,window.clearTimeout(fe)}},[Re,Z]);let Tc=Object.keys(a).length,qa=Re.trim(),zc=nc(P?.result),fl=P?.decision?.technical_classification==="no_suitable_candidate"||!!P&&!P.best,hm=P?.decision?.technical_classification!=null,gm=P?.decision?.reason??(fl?"No catalogue candidate found. Refine the request or search the catalogue.":null),u0=Gt.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"})),Zn=qa?u0:zc,Mi=P?R[P.item.line_id]:void 0,Kn=!qa&&Mi&&!Zn.some(x=>x.product_id===Mi.product_id)?[...Zn,Mi]:Zn,bm=(()=>{let x=Kn.slice(0,qa?12:6);return qa||!Mi||x.some(G=>G.product_id===Mi.product_id)?x:[...x,Mi]})(),hl=!!P?.best&&a[P.item.line_id]?.productId===P.best.product_id,p0=!!P?.best&&!!a[P.item.line_id]&&!hl;return(0,s.jsxs)("div",{className:"wizard-step entry-stage",children:[(0,s.jsxs)("div",{className:`quick-order-card${m?"":" quick-order-card--customer"}`,children:[(0,s.jsx)("div",{className:`quick-order-hero${m?"":" quick-order-hero--customer"}`,children:m?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,s.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,s.jsx)("h1",{children:"Your Results"}),(0,s.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,s.jsx)("strong",{children:yt??"Review quantities"})," Est. total"]})]}),(0,s.jsx)("p",{children:"Each line item from your schedule matched against your catalogue, ranked by confidence."})]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{children:"Review your matched products"}),(0,s.jsxs)("p",{children:["Check you're happy with these items, then click ",g?"View Quote":"View Basket"," to continue."]})]}),(0,s.jsxs)("button",{type:"button",className:"results-total-action",onClick:n,disabled:Tc===0,"aria-label":g?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[(0,s.jsx)("small",{children:g?"View Quote":"View Basket"}),yt!=null&&(0,s.jsx)("strong",{children:yt})]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(jt,{})})]})]})}),(0,s.jsxs)("div",{className:"quick-order-panel",style:{paddingTop:16},children:[Oe&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:12},children:(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn","aria-pressed":Te,onClick:()=>ct(x=>!x),children:Te?"Hide timings":"Show timings"})}),Oe&&Te&&(0,s.jsx)(Q_,{...O}),!g&&(0,s.jsx)("div",{className:"results-toolbar-row",children:!P&&(0,s.jsx)("div",{className:"results-summary",style:{marginBottom:0},children:(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap",alignItems:"center"},children:[(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:U,onChange:x=>A(x.target.value),"aria-label":"Search line items"}),!m&&(0,s.jsxs)("div",{className:"results-view-toggle","aria-label":"Results view",children:[(0,s.jsx)("button",{type:"button",className:`results-view-toggle__btn${le==="tile"?" is-active":""}`,"aria-pressed":le==="tile","aria-label":"Tile view",title:"Tile view",onClick:()=>Ve("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${le==="list"?" is-active":""}`,"aria-pressed":le==="list","aria-label":"List view",title:"List view",onClick:()=>Ve("list"),children:(0,s.jsxs)("svg",{width:"17",height:"17",viewBox:"0 0 15 15",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",children:[(0,s.jsx)("line",{x1:"0.5",y1:"2.5",x2:"14.5",y2:"2.5"}),(0,s.jsx)("line",{x1:"0.5",y1:"7.5",x2:"14.5",y2:"7.5"}),(0,s.jsx)("line",{x1:"0.5",y1:"12.5",x2:"14.5",y2:"12.5"})]})})]}),Oe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ge(x=>x==="simple"?"detailed":"simple"),children:Me==="detailed"?"Hide detailed view":"Show detailed view"}),(0,s.jsxs)("details",{ref:$n,style:{position:"relative"},children:[(0,s.jsx)("summary",{className:"bom-toolbar-btn sort-menu-summary","aria-label":"Sort line items",style:{fontSize:16},children:"\u21C5"}),(0,s.jsx)("div",{className:"sort-menu-panel",children:R_.map(x=>{let G=j===x.dir;return(0,s.jsxs)("button",{type:"button",className:`sort-menu-item${G?" is-active":""}`,onClick:()=>{ie(G?null:x.dir),$n.current?.removeAttribute("open")},children:[(0,s.jsx)("span",{className:"sort-menu-item__check",children:G?"\u2713":""}),x.label]},x.dir)})})]})]})})}),le==="tile"||P?(0,s.jsxs)(s.Fragment,{children:[P?(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)(Io,{})}),(0,s.jsx)("div",{className:"results-review-page",children:m?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"results-review-page__top",children:[(0,s.jsxs)("button",{type:"button",className:"bom-toolbar-btn bom-toolbar-btn--accent",onClick:()=>Va(),children:[(0,s.jsx)(Vr,{}),"Back to results"]}),(0,s.jsxs)("div",{style:{display:"flex",gap:8,flexWrap:"wrap"},children:[Oe&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ge(x=>x==="simple"?"detailed":"simple"),children:Me==="detailed"?"Hide detailed info":"Show detailed info"}),(0,s.jsx)("div",{className:"results-review-searchbar",children:(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products in catalogue...",value:Re,onChange:x=>wt(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:()=>Ec(P.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(qt(P)?.description||P.item.description_original,qt(P)?.product_id,qt(P)?.pdp_photo_url),alt:""})}),(0,s.jsxs)("div",{className:"results-review-page__summary",children:[(0,s.jsx)("h2",{children:Xr(P.item,_)}),(0,s.jsxs)("p",{className:"results-review-page__meta",children:[wi(P.qty)," ",ka(P.item.unit,P.qty)]}),P.best?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:P.best.description}),P.best.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:An(P.best.price,P.best.price_basis)}):null]}):qt(P)?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("div",{className:"results-review-page__product",children:qt(P)?.description}),qt(P)?.price!=null?(0,s.jsx)("div",{className:"results-row-meta",children:An(qt(P)?.price??null,qt(P)?.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(P.item)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:8},children:[(0,s.jsx)(zd,{meta:N.get(P.item.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:Un(P.item)})]}):null,(0,s.jsx)("div",{className:"results-review-page__actions",children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[P.item.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[P.item.line_id]?i(P.item.line_id):(P.best&&fm(P.item.line_id,P.best),r(Xn(P)))},disabled:!P.best,"aria-label":a[P.item.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[P.item.line_id]?"\u2713 Added":m?"+ Add to selection":`Add to ${d}`})})]})]}),vt?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,!vt&&de?(0,s.jsx)("div",{className:"results-empty-card",children:de}):null,!vt&&!de&&qa&&Zn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No candidate products match this database search."}):!vt&&!de?(0,s.jsx)(X_,{item:P.item,candidates:Zn,result:P.result,decision:P.decision,unmatchable:P.unmatchable,selectedProductId:P.best?.product_id??null,detailMode:Me,linkedGroupMeta:mr(P.item)?N.get(P.item.linked_group_id):void 0,onPick:x=>Mc(P.item.line_id,x),onClear:()=>Ec(P.item.line_id),showAll:m||Oe||qa.length>0,internal:m,debugEnabled:Oe,forceReviewNote:!0}):null]}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("section",{className:"customer-review-request",children:[(0,s.jsx)("span",{className:"customer-review-eyebrow",children:"Original request"}),(0,s.jsx)("strong",{children:Xr(P.item,_)||"Original request"})]}),gm?(0,s.jsxs)("section",{className:"customer-review-ai",children:[(0,s.jsx)("strong",{children:fl?"No automatic match:":"AI review:"})," ",gm]}):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:fl?zc.length>0?"Choose a product":"No suitable product found":hm?"Choose a product":"We couldn't review this item"}),(0,s.jsx)("p",{children:fl?zc.length>0?"No product was selected automatically. Review these related options before adding one.":"Search the catalogue to choose an alternative.":hm?`Select the option you want to add to your ${d}.`:"Search the catalogue to choose a product."})]})}),!qa&&Kn.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:bm.map(x=>{let G=x.product_id===P.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${G?" is-selected":""}`,onClick:()=>Mc(P.item.line_id,x),"aria-pressed":G,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${An(x.price,x.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:G?"Selected":"Choose"})]},x.product_id)})}):null,Kn.length>0&&(0,s.jsx)("div",{className:"customer-review-divider",children:(0,s.jsx)("span",{children:"or"})}),(0,s.jsxs)("label",{className:"customer-review-search",children:[(0,s.jsx)("span",{children:"Search our full catalogue"}),(0,s.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search products...",value:Re,onChange:x=>wt(x.target.value),"aria-label":"Search catalogue"})]}),qa&&vt?(0,s.jsx)("div",{className:"results-empty-card",children:"Searching catalogue\u2026"}):null,qa&&!vt&&de?(0,s.jsx)("div",{className:"results-empty-card",children:de}):null,qa&&!vt&&!de&&Kn.length===0?(0,s.jsx)("div",{className:"results-empty-card",children:"No products match this search."}):null,qa&&!vt&&!de&&Kn.length>0?(0,s.jsx)("div",{className:"customer-review-option-grid",children:bm.map(x=>{let G=x.product_id===P.best?.product_id;return(0,s.jsxs)("button",{type:"button",className:`customer-review-option${G?" is-selected":""}`,onClick:()=>Mc(P.item.line_id,x),"aria-pressed":G,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${An(x.price,x.price_basis)}`:"-"}),(0,s.jsx)("span",{className:"customer-review-option__state",children:G?"Selected":"Choose"})]},x.product_id)})}):null]}),P.best?p0?(0,s.jsxs)("div",{style:{display:"grid",gap:8},children:[(0,s.jsx)("button",{type:"button",className:"cta-btn customer-review-add",onClick:()=>{dm()},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(P.item.line_id),children:(0,s.jsx)("span",{children:`Remove from ${d}`})})]}):(0,s.jsx)("button",{type:"button",className:`cta-btn customer-review-add${hl?" cta-btn-secondary":""}`,onClick:()=>{hl?i(P.item.line_id):dm()},children:(0,s.jsx)("span",{children:hl?`Remove from ${d}`:`Add selected product to ${d}`})}):null,E?(0,s.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary customer-review-skip",onClick:()=>s0(P.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,qc.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:qc.map(x=>{let{item:G,best:fe,qty:ut}=x,Xe=qt(x),ea=!fe&&at(x);return(0,s.jsxs)("article",{className:"results-tile-card",children:[(0,s.jsxs)("button",{type:"button",className:"results-tile-card__surface",onClick:()=>Ei(G.line_id),"aria-label":`Review match for ${Xr(G,_)||"item"}`,children:[(0,s.jsxs)("div",{className:"results-tile-card__media",children:[ea||mr(G)?(0,s.jsxs)("div",{className:"results-tile-card__badges",children:[mr(G)?(0,s.jsx)(zd,{meta:N.get(G.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(Xe?.description||G.description_original,Xe?.product_id,Xe?.pdp_photo_url),alt:""})]}),(0,s.jsxs)("div",{className:"results-tile-card__body",children:[Xe?(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:Xe.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:Xe?(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:Xr(G,_)}),mr(G)?(0,s.jsx)("div",{className:"results-row-meta",children:Un(G)}):null]}):(0,s.jsx)("span",{className:"results-empty-hint",children:"No matched product selected."})})]}),(0,s.jsx)("span",{className:"results-tile-card__hover-prompt","aria-hidden":"true",children:"Click to view options"})]}),(0,s.jsxs)("div",{className:"results-tile-card__actions",children:[m&&(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ei(G.line_id),children:"Review"}),(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[G.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>{a[G.line_id]?i(G.line_id):r(Xn(x))},disabled:!Xe,"aria-label":a[G.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[G.line_id]?"\u2713 Added":m?"+ Add":`Add to ${d}`})]})]},G.line_id)})})}):null,mm]})]}):(0,s.jsxs)(s.Fragment,{children:[ne&&(0,s.jsx)("div",{className:"results-table__hover-overlay",style:ne,"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"}}),Me==="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"}),Me==="simple"&&(0,s.jsx)("th",{style:{textAlign:"center"},children:m?"Selection":g?"Quote":"Basket"})]})}),(0,s.jsxs)("tbody",{children:[Yt.length===0&&(0,s.jsx)("tr",{children:(0,s.jsx)("td",{colSpan:Me==="simple"?4:3,className:"results-empty-hint",style:{padding:"16px 8px"},children:"No line items match the current search/filter."})}),qc.map(x=>{let{item:G,result:fe,decision:ut,best:Xe}=x;return(0,s.jsxs)("tr",{className:"bom-row results-table__review-row",onClick:()=>Ei(G.line_id),onMouseEnter:ea=>{ve.current=ea.currentTarget,Vn()},onMouseLeave:()=>{ve.current=null,ue(null)},children:[(0,s.jsxs)("td",{children:[(0,s.jsx)("div",{className:"bom-component-name",children:Xr(G,_)}),mr(G)?(0,s.jsxs)("div",{style:{display:"flex",alignItems:"center",gap:8,marginTop:4},children:[(0,s.jsx)(zd,{meta:N.get(G.linked_group_id)}),(0,s.jsx)("div",{className:"results-row-meta",style:{marginTop:0},children:Un(G)})]}):null]}),(0,s.jsx)("td",{children:Xe?(0,s.jsxs)("div",{children:[(0,s.jsx)("div",{className:"results-match-cell-text",title:Xe.description,children:Xe.description}),Me==="detailed"&&ut?.technical_classification&&(0,s.jsxs)("div",{className:"results-row-meta",children:[D_(ut.technical_classification),ut.approval_required?" - approval required":""]})]}):(0,s.jsx)("span",{className:"results-empty-hint"})}),(0,s.jsx)("td",{style:{textAlign:"center"},children:Xe?.price!=null?An(Xe.price,Xe.price_basis):"-"}),Me==="simple"&&(0,s.jsx)("td",{style:{textAlign:"center"},children:(0,s.jsx)("button",{type:"button",className:`bom-toolbar-btn${a[G.line_id]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,style:{width:84,justifyContent:"center"},onClick:ea=>{ea.stopPropagation(),a[G.line_id]?i(G.line_id):r(Xn(x))},"aria-label":a[G.line_id]?m?"Remove from selection":`Remove from ${d}`:m?"Add to selection":`Add to ${d}`,children:a[G.line_id]?"\u2713 Added":m?"+ Add":`Add to ${d}`})})]},G.line_id)})]})]})}),mm]}),!P&&hr>1&&(0,s.jsxs)("div",{className:"results-pagination",children:[(0,s.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(_t-1)*nl+1,"\u2013",Math.min(_t*nl,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:()=>Ke(_t-1),disabled:_t===1,children:"Previous"}),(0,s.jsxs)("span",{className:"results-pagination-page",children:["Page ",_t," of ",hr]}),(0,s.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ke(_t+1),disabled:_t===hr,children:"Next"})]})]}),(M.itemCount!=null||M.headingCount!=null||M.skippedCount!=null)&&(0,s.jsxs)("div",{className:"results-summary",style:{marginTop:16},children:[M.itemCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.itemCount})," items parsed"]}),M.headingCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.headingCount})," headings"]}),M.skippedCount!=null&&(0,s.jsxs)("span",{className:"summary-chip",children:[(0,s.jsx)("strong",{children:M.skippedCount})," rows skipped"]})]}),(0,s.jsxs)("div",{className:"disclaimer-box",children:[(0,s.jsx)("span",{className:"disclaimer-icon",children:"\u26A0\uFE0F"}),(0,s.jsx)("p",{className:"disclaimer-text",children:"These matches are generated automatically and should be reviewed before purchase."})]}),!P&&(0,s.jsxs)("div",{className:"btn-row results-actions",children:[(0,s.jsxs)("button",{className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",gap:10,justifyContent:"center"},onClick:()=>Q(!0),"aria-label":"Start over",children:[(0,s.jsx)(Cd,{}),(0,s.jsx)("span",{children:"Start Over"})]}),(0,s.jsxs)("button",{className:"cta-btn",style:{flex:"0 1 70%"},onClick:n,disabled:Tc===0,"aria-label":m?"View selection":g?"View quote":"View basket",children:[(0,s.jsxs)("span",{children:[m?"View Selection":g?"View Quote":"View Basket"," (",Tc,")"]}),(0,s.jsx)("span",{className:"arrow",children:(0,s.jsx)(jt,{})})]})]})]})]}),n0&&(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:Kr.map(x=>{let G=Ye.has(x.item.line_id),fe=at(x);return(0,s.jsx)("div",{className:`review-gate-item${G?" is-reviewed":""}`,children:(0,s.jsxs)("button",{type:"button",className:"review-gate-item__review",onClick:()=>{D(!0),Ei(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Xr(x.item,_)}),(0,s.jsx)("span",{children:x.decision?.reason||(fe?"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:G?"Choice made":"Choose a product"})]})},x.item.line_id)})}),(0,s.jsx)("button",{type:"button",className:"review-gate-skip",onClick:c0,children:"Skip all"}),Cc.length>0?(0,s.jsxs)("div",{className:"review-gate-skipped",children:[(0,s.jsx)("strong",{children:"Skipped"}),Cc.map(x=>(0,s.jsxs)("button",{type:"button",className:"review-gate-item is-skipped",onClick:()=>{y(G=>{let fe=new Set(G);return fe.delete(x.item.line_id),fe}),D(!0),Ei(x.item.line_id)},children:[(0,s.jsxs)("span",{className:"review-gate-item__copy",children:[(0,s.jsx)("strong",{children:Xr(x.item,_)}),(0,s.jsx)("span",{children:`Not added to your ${d}.`})]}),(0,s.jsx)("span",{className:"review-gate-item__action",children:"Choose a product"})]},x.item.line_id))]}):null]})}),T&&(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:()=>Q(!1),children:"Cancel"}),(0,s.jsx)("button",{type:"button",className:"modal-btn modal-btn-danger",onClick:()=>{Q(!1),t()},autoFocus:!0,children:"Start Over"})]})]})})]})}var ht=X(je());var At=X(je()),Cv=X(ee());function Dn(e){return JSON.stringify([e.productId,e.qty,e.unit,e.linkedContext??[]])}function Z_(e,t){let a={...e,[t.lineId]:t};for(let[r,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 Dd=(0,At.createContext)(null);function lc({children:e,onOpenBasket:t}){let[a,r]=(0,At.useState)({}),i=(0,At.useCallback)(d=>{r(b=>Z_(b,d))},[]),n=(0,At.useCallback)(d=>{r(b=>{let _={...b};for(let M of d)_[M.lineId]=M;return _})},[]),o=(0,At.useCallback)(d=>{r(b=>{let _={...b};return delete _[d],_})},[]),l=(0,At.useCallback)((d,b)=>{r(_=>_[d]?{..._,[d]:{..._[d],qty:b,sellUnitsOverride:null}}:_)},[]),c=(0,At.useCallback)((d,b)=>{r(_=>_[d]?{..._,[d]:{..._[d],sellUnitsOverride:b}}:_)},[]),p=(0,At.useCallback)(d=>{r(b=>{let _=!1,M={...b};for(let[O,f]of Object.entries(d))M[O]&&(M[O]={...M[O],...f},_=!0);return _?M:b})},[]),m=(0,At.useCallback)(()=>r({}),[]),g=(0,At.useMemo)(()=>({cart:a,count:Object.keys(a).length,addToCart:i,addManyToCart:n,removeFromCart:o,updateCartQty:l,updateCartSellUnits:c,updateCartConversions:p,clearCart:m,openBasket:t??(()=>{})}),[a,i,n,o,l,c,p,m,t]);return(0,Cv.jsx)(Dd.Provider,{value:g,children:e})}function On(){let e=(0,At.useContext)(Dd);if(!e)throw new Error("useCart must be used inside a <CartProvider>");return e}function Nv(){return(0,At.useContext)(Dd)}var q=X(ee()),qv=.2,ol=10,Ev="Enter a valid email address so we can send your quote.",K_=(e,t)=>{let a=`${t.requestedAmount} ${xa(t.requestedUnit,t.requestedAmount)}`,r=`${t.requiredSellUnits} ${xa(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)} ${xa(t.sellUnit,2)} per ${xa(t.requestedUnit,1)})`:e.coverageQty&&/^m per /i.test(e.coverageUom??"")?`${a} requested \u2192 order ${r} (${e.coverageQty} ${e.coverageUom})`:`${a} requested \u2192 order ${r}`},P_=e=>["box","pack"].includes(e.requestedUnit)?"Pack size needed to calculate the order quantity.":`This product is sold by ${xa(e.sellUnit,1)}.`;function J_(){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 ll(){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 sl({cart:e,onUpdateQty:t,onUpdateSellUnits:a,onResolveConversions:r,onRemove:i,onBack:n,onStartNewQuote:o,onQuoteRequested:l,internal:c=!1}){let p=(0,ht.useId)(),m=!c&&Ks()==="QZA6-MRA4",g=!c,d=Object.values(e),[b,_]=(0,ht.useState)(""),[M,O]=(0,ht.useState)(!1),[f,u]=(0,ht.useState)(!1),h=Nn(),[w,k]=(0,ht.useState)(""),[R,z]=(0,ht.useState)({}),[U,A]=(0,ht.useState)({}),[j,ie]=(0,ht.useState)(1),[qe,Ke]=(0,ht.useState)({}),[Oe,Me]=(0,ht.useState)(!1),[ge,le]=(0,ht.useState)("0"),[Ve,Te]=(0,ht.useState)({}),ct=(0,ht.useRef)(new Map);(0,ht.useEffect)(()=>{if(!r)return;for(let D of Object.values(e))It(D).requiredSellUnits!=null&&ct.current.delete(D.lineId);let y=Object.values(e).filter(D=>{if(D.productId==="-"||It(D).requiredSellUnits!=null)return!1;let V=Dn(D);return ct.current.get(D.lineId)===V?!1:(ct.current.set(D.lineId,V),!0)});if(y.length===0)return;let E=new Map(y.map(D=>[D.lineId,Dn(D)]));Te(D=>({...D,...Object.fromEntries(E)})),fetch(za("/api/catalogue/resolve-conversions"),{method:"POST",headers:{"Content-Type":"application/json",...Cn()},body:JSON.stringify({lines:y.map(D=>({line_id:D.lineId,product_id:D.productId,requested_description:D.requestedDescription??D.description,requested_qty:D.qty,requested_uom:D.unit||null,linked_context:D.linkedContext??[],selected_description:D.description,selected_uoi:D.uoi,selected_uoi_count:D.uoiCount,selected_conversion:{sales_uom_normalised:D.salesUomNormalised,conversion_type:D.conversionType,sales_unit_size:D.salesUnitSize,sales_unit_size_uom:D.salesUnitSizeUom,coverage_qty:D.coverageQty,coverage_uom:D.coverageUom}}))})}).then(D=>D.ok?Qa(D):null).then(D=>{let V={},N=new Map(y.map(L=>[L.lineId,Dn(L)]));for(let L of D?.data?.items??D?.items??[]){let $=L?.conversion;if(!$||typeof L?.line_id!="string"||ct.current.get(L.line_id)!==N.get(L.line_id))continue;let se=e[L.line_id];V[L.line_id]={conversionType:$.conversion_type,requestUomsSupported:$.request_uoms_supported,salesUomNormalised:$.sales_uom_normalised,salesUnitSize:$.sales_unit_size,salesUnitSizeUom:$.sales_unit_size_uom,coverageQty:$.coverage_qty,coverageUom:$.coverage_uom,roundingRule:$.rounding_rule,conversionConfidence:$.conversion_confidence,conversionNotes:$.conversion_notes,...se?.qty===0&&Number.isFinite($.suggested_order_qty)&&$.suggested_order_qty>0?{qty:$.suggested_order_qty,unit:$.suggested_order_uom||se.unit}:{}}}Object.keys(V).length>0&&r(V)}).catch(D=>console.error("Catalogue conversion resolution failed",D)).finally(()=>{Te(D=>{let V={...D};for(let[N,L]of E)V[N]===L&&delete V[N];return V})})},[e,r]);function Z(y){z(E=>{let D={...E};return delete D[y],D})}function be(y,E){let D=parseFloat(E);!isNaN(D)&&D>=0&&t(y,Math.min(D,1e5)),Z(y)}function Re(y,E,D){t(y,Math.min(1e5,Math.max(0,E+D))),Z(y)}function wt(y){A(E=>{let D={...E};return delete D[y],D})}function Gt(y,E){let D=parseFloat(E);!isNaN(D)&&D>=0&&a(y,Math.min(D,1e5)),wt(y)}function Ct(y,E,D){a(y,Math.min(1e5,Math.max(0,E+D))),wt(y)}async function vt(){if(we.some(({pricing:E})=>E.lineTotal==null)){k(m?"Confirm the highlighted quantities before requesting a quote.":"Confirm the highlighted quantities before sending your basket.");return}let y=b.trim();if(!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(y)){k(Ev);return}k(""),u(!0);try{let E=await fetch(za("/api/quote-requests"),{method:"POST",headers:{"Content-Type":"application/json",...Cn()},body:JSON.stringify({email:y,items:we.map(({item:D,pricing:V})=>{let N=V.requiredSellUnits??V.requestedAmount,L=V.requiredSellUnits!=null?V.sellUnit:V.requestedUnit;return{product_id:D.productId,description:D.description,quantity:N,unit:xa(L,N),unit_price:V.requiredSellUnits!=null?V.unitPrice:null,line_total:V.lineTotal}})})});if(!E.ok){let D=await Qa(E);console.error("Quote request failed",E.status,D?.message),k(E.status===429?"You've sent a few requests already. Please try again in a few minutes.":"Your request couldn't be sent. Please try again, or contact us if it keeps happening.");return}T!=null&&h("quote_requested",{items:we.length,total:Math.round(T*100)/100}),O(!0),l?.(),window.scrollTo(0,0)}catch{k("Your request couldn't be sent. Check your connection and try again.")}finally{u(!1)}}let we=d.map(y=>({item:y,pricing:It(y,{wasteFactorEnabled:Oe,wasteFactorOverride:Math.max(0,Number.parseFloat(ge)||0)/100})})),de=ic(d,{wasteFactorEnabled:Oe,wasteFactorOverride:Math.max(0,Number.parseFloat(ge)||0)/100}),tt=de==null?null:de*qv,T=de==null?null:de*(1+qv),Q=we.filter(({pricing:y})=>y.lineTotal==null).length,ne=Object.keys(Ve).length,ue=!!r&&d.some(y=>{if(y.productId==="-"||It(y).requiredSellUnits!=null)return!1;let E=Dn(y);return ct.current.get(y.lineId)!==E||Ve[y.lineId]===E}),ve=(0,ht.useRef)({items:we.length,...T==null?{}:{total:Math.round(T*100)/100}});(0,ht.useEffect)(()=>{h("basket_viewed",ve.current)},[h]);let Ye=Math.max(1,Math.ceil(we.length/ol)),Ce=Math.min(j,Ye),S=we.slice((Ce-1)*ol,Ce*ol);return M?(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:m?"Quote requested":"Basket sent"}),m?(0,q.jsxs)("p",{children:["You're all done. We'll email your sharper price to ",(0,q.jsx)("strong",{children:b.trim()}),", usually within one working day."]}):(0,q.jsxs)("p",{children:["You're all done. We'll email ",(0,q.jsx)("strong",{children:b.trim()})," to confirm prices, availability and delivery, usually within one working day."]}),(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:o,children:(0,q.jsx)("span",{children:m?"Start a new quote":"Start a new basket"})}),(0,q.jsx)("p",{className:"quote-request-sent-note",children:m?"Nothing is charged until you approve the quote.":"Nothing is charged until you approve the order."})]})}):!c&&d.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:m?"Your quote request is empty":"Your basket is empty"}),(0,q.jsx)("p",{children:m?"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${m?" 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:[m&&(0,q.jsxs)("button",{type:"button",className:"cta-btn cta-btn-secondary basket-hero-back",onClick:n,children:[(0,q.jsx)(Vr,{}),(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":m?"Request a quote":"Your Basket"}),c&&(0,q.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,q.jsx)("strong",{children:d.length})," ",d.length===1?"item":"items"]})]}),(0,q.jsx)("p",{children:c?"Review the items you've added before exporting them for review.":m?"Check your items and quantities below, and we'll do our best to beat list prices.":"Review your quantities and order summary, then send us your basket."})]})]}),(0,q.jsx)("div",{className:"quick-order-panel",style:{paddingTop:16},children:ue?(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"})]}):d.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":m?"Quote request items":"Basket items",children:S.map(({item:y,pricing:E})=>{let D=R[y.lineId]??String(E.requestedAmount),V=E.requestedUnit===E.sellUnit||E.costingMode==="review",N=E.requiredSellUnits==null||E.requestedAmount!==E.requiredSellUnits||E.requestedUnit!==E.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(y.description,y.productId,y.pdpPhotoUrl),alt:"",width:48,height:48}),(0,q.jsxs)("div",{className:"basket-card-info",children:[(0,q.jsx)("div",{className:"bom-component-name",children:y.description}),N&&E.costingMode!=="review"&&(0,q.jsxs)("button",{type:"button",className:"basket-calc-toggle",onClick:()=>Ke(L=>({...L,[y.lineId]:!L[y.lineId]})),"aria-expanded":!!qe[y.lineId],children:["How we calculated this",(0,q.jsx)("span",{className:`basket-calc-toggle-chevron${qe[y.lineId]?" basket-calc-toggle-chevron--open":""}`,children:(0,q.jsx)(ll,{})})]})]}),(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(y.lineId),"aria-label":`Remove ${y.description}`,children:(0,q.jsx)(J_,{})})})]}),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:y.conversionType??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Conversion confidence"}),(0,q.jsx)("dd",{children:y.conversionConfidence??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Sales unit"}),(0,q.jsx)("dd",{children:y.salesUnitSize!=null?(0,q.jsxs)(q.Fragment,{children:[y.salesUnitSize," ",ka(y.salesUnitSizeUom,y.salesUnitSize)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Coverage"}),(0,q.jsx)("dd",{children:y.coverageQty!=null?(0,q.jsxs)(q.Fragment,{children:[y.coverageQty," ",ka(y.coverageUom,y.coverageQty)]}):"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Waste factor"}),(0,q.jsx)("dd",{children:y.wasteFactorDefault??"-"})]}),(0,q.jsxs)("div",{children:[(0,q.jsx)("dt",{children:"Rounding rule"}),(0,q.jsx)("dd",{children:y.roundingRule??"-"})]})]}),y.conversionNotes&&(0,q.jsx)("p",{className:"results-rerank-note",children:y.conversionNotes})]}),E.costingMode==="review"?(0,q.jsxs)("p",{className:"basket-calc-text basket-calc-text--review",children:[(0,q.jsx)("strong",{children:Ve[y.lineId]===Dn(y)?"Calculating order quantity\u2026":"Quantity needs confirmation."})," ",P_(E)]}):N&&qe[y.lineId]?(0,q.jsx)("p",{className:"basket-calc-text",children:K_(y,E)}):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:D,disabled:V,onChange:L=>z($=>({...$,[y.lineId]:L.target.value})),onBlur:L=>be(y.lineId,L.target.value),onKeyDown:L=>{L.key==="Enter"&&L.target.blur()},"aria-label":`${y.description} requested quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",disabled:V,onClick:()=>Re(y.lineId,parseFloat(D)||0,1),"aria-label":`Increase ${y.description} quantity`,children:(0,q.jsx)(ll,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",disabled:V,onClick:()=>Re(y.lineId,parseFloat(D)||0,-1),"aria-label":`Decrease ${y.description} quantity`,children:(0,q.jsx)(ll,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:ka(E.requestedUnit,parseFloat(D)||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:U[y.lineId]??String(E.requiredSellUnits??""),onChange:L=>A($=>({...$,[y.lineId]:L.target.value})),onBlur:L=>Gt(y.lineId,L.target.value),onKeyDown:L=>{L.key==="Enter"&&L.target.blur()},"aria-label":`${y.description} order quantity`}),(0,q.jsxs)("div",{className:"basket-qty-arrows",children:[(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow",onClick:()=>Ct(y.lineId,parseFloat(U[y.lineId]??String(E.requiredSellUnits??"0"))||0,1),"aria-label":`Increase ${y.description} order quantity`,children:(0,q.jsx)(ll,{})}),(0,q.jsx)("button",{type:"button",className:"basket-qty-arrow basket-qty-arrow--down",onClick:()=>Ct(y.lineId,parseFloat(U[y.lineId]??String(E.requiredSellUnits??"0"))||0,-1),"aria-label":`Decrease ${y.description} order quantity`,children:(0,q.jsx)(ll,{})})]})]}),(0,q.jsx)("span",{className:"basket-metric-unit",children:ka(E.sellUnit,parseFloat(U[y.lineId]??String(E.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:E.lineTotal!=null?ot(E.lineTotal):"-"}),E.lineTotal!=null&&(0,q.jsx)("span",{className:"basket-metric-unit",children:"ex. VAT"})]})]})]})]},y.lineId)})}),Ye>1&&(0,q.jsxs)("div",{className:"results-pagination",children:[(0,q.jsxs)("span",{className:"results-pagination-count",children:["Showing ",(Ce-1)*ol+1,"\u2013",Math.min(Ce*ol,we.length)," of ",we.length]}),(0,q.jsxs)("div",{className:"results-pagination-controls",children:[(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ie(Ce-1),disabled:Ce===1,children:"Previous"}),(0,q.jsxs)("span",{className:"results-pagination-page",children:["Page ",Ce," of ",Ye]}),(0,q.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>ie(Ce+1),disabled:Ce===Ye,children:"Next"})]})]})]}),(0,q.jsxs)("aside",{className:"basket-sidebar",children:[(0,q.jsx)("div",{className:"basket-sidebar-title",children:m?"Quote request summary":"Order summary"}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:m?"List price (ex. VAT)":"Subtotal (ex. VAT)"}),(0,q.jsx)("span",{children:de==null?"To confirm":ot(de)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row",children:[(0,q.jsx)("span",{children:"VAT (20%)"}),(0,q.jsx)("span",{children:tt==null?"To confirm":ot(tt)})]}),(0,q.jsxs)("div",{className:"basket-sidebar-row basket-sidebar-row--total",children:[(0,q.jsx)("span",{children:m?"List price (inc.\xA0VAT)":"Total"}),(0,q.jsx)("span",{children:T==null?"To confirm":ot(T)})]}),!m&&(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:Oe,onChange:y=>Me(y.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:ge,onChange:y=>le(y.target.value),disabled:!Oe,"aria-label":"Waste factor percent"}),(0,q.jsx)("span",{children:"%"})]})]})}),(0,q.jsx)("label",{htmlFor:`${p}-basket-reference`,className:"basket-sidebar-label",children:m?"Enter email for your sharper quote":g?"Your email":"Your reference (optional)"}),(0,q.jsx)("input",{id:`${p}-basket-reference`,type:g?"email":"text",className:"basket-sidebar-input",value:b,onChange:y=>{_(y.target.value),g&&k("")},placeholder:g?"you@example.com":"PO number or job reference","aria-invalid":g&&w===Ev,"aria-describedby":g&&w?`${p}-basket-reference-error`:void 0}),g&&w&&(0,q.jsx)("p",{id:`${p}-basket-reference-error`,className:"basket-quote-request-error",role:"alert",children:w}),g?(0,q.jsx)("button",{type:"button",className:"cta-btn",onClick:()=>{vt()},disabled:f||Q>0||ne>0,"aria-busy":f,children:(0,q.jsx)("span",{children:f?"Sending\u2026":m?"Request our best quote":"Send basket"})}):(0,q.jsx)("button",{className:"cta-btn",onClick:()=>{h("downloaded",{type:"basket",items:d.length}),yv(d)},"aria-label":"Download selection",children:(0,q.jsx)("span",{children:"Download Quote"})}),(0,q.jsxs)("p",{className:"basket-sidebar-disclaimer",children:[(0,q.jsx)("span",{"aria-hidden":"true",children:"\u26A0\uFE0F"}),m?"This is a quote request, not an order. We'll confirm our best price, availability and delivery before you approve.":g?"Sending your basket isn't an order. We'll confirm prices, availability and delivery before you approve.":"Prices and availability are estimates and should be confirmed before procurement."]})]})]}),(0,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)(Vr,{}),(0,q.jsx)("span",{children:"Back to results"})]})})]})})]})})}var Sa=X(ee()),Bd="metron-quick-quote",F_=1440*60*1e3;function sc(e){return(0,Sa.jsx)(lc,{children:(0,Sa.jsx)(I_,{...e})})}function I_({fullPage:e=!1,hideHeader:t=!1,internal:a=!1}){let[r,i]=(0,De.useState)("entry"),[n,o]=(0,De.useState)(null),[l,c]=(0,De.useState)(""),p=(0,De.useRef)(null),m=(0,De.useRef)(0),[g,d]=(0,De.useState)(0),[b,_]=(0,De.useState)(null),[M,O]=(0,De.useState)(!1),{cart:f,addToCart:u,addManyToCart:h,removeFromCart:w,updateCartQty:k,updateCartSellUnits:R,updateCartConversions:z,clearCart:U}=On(),[A,j]=(0,De.useState)(!1),[ie,qe]=(0,De.useState)(null),Ke=()=>{qe(null);try{window.sessionStorage.removeItem(rc)}catch{}},Oe=(0,De.useRef)(null),Me=Zs("quick-quote",Oe);(0,De.useEffect)(()=>{Me("viewed")},[Me]);let[ge,le]=(0,De.useState)(!1);(0,De.useEffect)(()=>{uv();let we=window.location.hash,de=null;try{de=JSON.parse(window.sessionStorage.getItem(Bd)??"null")}catch{}if(de&&!(Date.now()-(de.savedAt??0)<F_)&&(de=null),de?.scheduleResult)o("schedule"),_(de.scheduleResult),O(de.reviewGateComplete),j(de.cartSeeded),h(Object.values(de.cart)),we==="#quote-request"?i("basket"):we==="#matched-products"&&i("results");else if(we==="#matched-products"||we==="#quote-request"){let tt=new URL(window.location.href);tt.hash="",Mn("replaceState",window.history.state,tt)}le(!0)},[]),(0,De.useEffect)(()=>{if(ge)try{b?window.sessionStorage.setItem(Bd,JSON.stringify({savedAt:Date.now(),scheduleResult:b,reviewGateComplete:M,cartSeeded:A,cart:f})):window.sessionStorage.removeItem(Bd)}catch{}},[ge,b,M,A,f]);let Ve=(0,De.useCallback)(we=>{if(typeof window>"u")return;let de=new URL(window.location.href);de.hash=we==="basket"?"quote-request":"matched-products";let tt=we==="results"&&(window.location.hash==="#matched-products"||window.location.hash==="#quote-request");Mn(tt?"replaceState":"pushState",{boqQuoteStage:we},de)},[]),Te=(0,De.useRef)(!1);(0,De.useEffect)(()=>{let we=()=>{Te.current=!1;let de=window.location.hash;de==="#quote-request"?i("basket"):de==="#matched-products"&&b?(o("schedule"),i("results")):i("entry")};return window.addEventListener("popstate",we),()=>window.removeEventListener("popstate",we)},[b]);let ct=(0,De.useCallback)(()=>{Ve("basket"),i("basket")},[Ve]),Z=(0,De.useCallback)(()=>{if(window.location.hash==="#quote-request"){if(Te.current)return;Te.current=!0,ac();return}i(b?"results":"entry")},[b]),be=(0,De.useRef)(r);(0,De.useEffect)(()=>{be.current!==r&&(be.current=r,window.scrollTo(0,0))},[r]);let Re=()=>{i("entry"),o(null),c(""),d(0),_(null),O(!1),U(),j(!1),Ke()},wt=(0,De.useCallback)(async(we,de,tt=!0)=>{let T=++m.current;c(""),d(0);let Q=0,ne=()=>{Q=Math.min(Q+1,3),d(Q)};try{let{jobId:ue}=await bw(we,de,tt);if(T!==m.current)return;let{promise:ve,cancel:Ye}=vw(()=>ww(ue),5e3,ne,"schedule");p.current=Ye;let Ce=await ve;if(Ce.status==="failed"||!Ce.result)throw new Error(Ce.error||"Failed to process schedule");let S=Ce.result.lineItems.length,y=Ce.result.results.filter(E=>E.candidates.length>0).length;Me("results_shown",{lines:S,matched:y,unmatched:S-y}),U(),j(!1),O(!1),_(Ce.result),Ve("results"),i("results")}catch(ue){if(T!==m.current)return;Me("error",{stage:"matching"}),c(ue?.message||"Failed to process schedule"),i("entry")}finally{T===m.current&&(p.current?.(),p.current=null)}},[Ve,Me,U]),Gt=(0,De.useCallback)(()=>{m.current++,p.current?.(),p.current=null},[]),Ct=(0,De.useCallback)(async(we,de,tt=!0)=>{if(!we.trim())return;o("schedule");let T=new File([we],"pasted-schedule.txt",{type:"text/plain"});await wt(T,de,tt)},[wt]),vt=(0,De.useCallback)(async we=>{o("schedule"),await wt(we)},[wt]);return(0,Sa.jsx)(Fo.Provider,{value:Me,children:(0,Sa.jsx)("div",{ref:Oe,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${!e&&r==="processing"?" app-wrapper--loading":""}`,style:Ot().theme,children:(0,Sa.jsxs)("main",{className:"main-content",children:[l&&(0,Sa.jsxs)("div",{className:"error-box",role:"alert",children:[(0,Sa.jsx)("strong",{children:"Error:"})," ",l]}),r==="entry"&&(0,Sa.jsx)(Sd,{onPasteSchedule:Ct,onUploadSchedule:vt,onEntryModeChange:o,draft:ie,onSubmitDraft:qe,onCancelMatch:Gt}),r==="results"&&n==="schedule"&&b&&(0,Sa.jsx)(Ud,{scheduleResult:b,onStartOver:Re,cart:f,onAddToCart:u,onRemoveFromCart:w,onGoToBasket:ct,cartSeeded:A,onCartSeeded:()=>j(!0),reviewGateComplete:M,onReviewGateComplete:()=>O(!0),internal:a}),r==="basket"&&(0,Sa.jsx)(sl,{cart:f,onUpdateQty:k,onUpdateSellUnits:R,onResolveConversions:z,onRemove:w,onBack:Z,onStartNewQuote:Re,onQuoteRequested:()=>{_(null),O(!1),j(!1),U(),Ke()},internal:a})]})})})}var $a=X(je());var yi=X(je());var Mv={"NZ4Y-ZMSQ":{"brick-block":{"brick-common":"105499","brick-engineering-red":"1654","brick-engineering-blue":"1723",block:"501","mortar-cement":"1762 cement","mortar-sand":"564 building sand"},skirting:{"skirting-chamfered":"1525","skirting-ogee":"135 primed mdf ogee","skirting-pencil-round":"892","skirting-torus":"1941"},architrave:{"architrave-ogee":"134 primed mdf ogee","architrave-pencil-round":"1896","architrave-square-edge":"118 primed mdf square","architrave-torus":"1531"},plasterboard:{standard:"1647",moisture:"11 moisture plasterboard",fire:"14 fire plasterboard",sound:"1769",screws:"131160",tape:"1766",adhesive:"108439"},paint:{"paint-emulsion":"157217"},"concrete-aggregate":{cement:"1762 cement","sharp-sand":"563",gravel:"571",mot:"569"},insulation:{"insulation-floor":"152187","insulation-ground":"442","insulation-wall":"147","insulation-roof":"442","insulation-loft":"152180"},timber:{studs:"1213",joists:"208",battens:"1729"},fencing:{"panels-boundary-0.9":"66 lap fence panel","panels-boundary-1.2":"1450","panels-boundary-1.5":"1449","panels-boundary-1.8":"1448","panels-skyline-1.8":"1475","concrete-intermediate-8":"40197","concrete-end-8":"40198","timber-post-6":"141411","timber-post-8":"1709",postcrete:"12142","gate-boundary":"1984","gate-skyline":"40002","gravel-boards":"40200"},decking:{"boards-summit":"24322",joists:"208",screws:"131079"},paving:{"surface-council":"1669","surface-raj":"12363","surface-brindle":"304","surface-charcoal":"296","surface-pea":"431","sub-base":"569",bedding:"563"}}};function cl(e,t){let a=Mv[Ot().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 vi(e,t){let a=Mv[Ot().client??""]?.[e];return!a||t in a}function Tv(e,t){let a=t.map(r=>{let i=cl(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 W=X(ee()),zv=[{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"}],cc=e=>Number.parseFloat(e)||0,Rv=(e,t)=>cc(e)*(t==="m"?1:.3048),Ld=(e,t)=>cc(e.quantity)*(2*Rv(e.height,t)+Rv(e.width,t)),W_=()=>({quantity:"1",width:"",height:""});function ex({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 Hd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,yi.useState)("m"),[n,o]=(0,yi.useState)({quantity:"1",width:"0.76",height:"1.98"}),[l,c]=(0,yi.useState)({quantity:"0",width:"1.52",height:"1.98"}),[p,m]=(0,yi.useState)([]),[g,d]=(0,yi.useState)("ogee"),[b,_]=(0,yi.useState)("2.4"),M=(k,R,z)=>{k(U=>({...U,[R]:z}))},O=Ld(n,r)+Ld(l,r)+p.reduce((k,R)=>k+Ld(R,r),0),f=cc(b)>0?Math.ceil(O/cc(b)):0,u=zv.find(k=>k.id===g)?.label??"",h=[{key:`architrave-${g}`,label:`Architrave (${u})`,qty:O,unit:"m",query:`${u} architrave`,category:"architrave"}],w=(k,R,z,U)=>(0,W.jsxs)("div",{className:"architrave-calculator__opening-row",children:[(0,W.jsx)("span",{children:k}),(0,W.jsx)("input",{"aria-label":`${k} quantity`,type:"number",min:"0",step:"1",value:R.quantity,onChange:A=>z("quantity",A.target.value)}),(0,W.jsx)("input",{"aria-label":`${k} width`,type:"number",min:"0",step:"0.01",value:R.width,onChange:A=>z("width",A.target.value)}),(0,W.jsx)("input",{"aria-label":`${k} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:A=>z("height",A.target.value)}),U?(0,W.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:U,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",{})]}),w("Single doors",n,(k,R)=>M(o,k,R)),w("Double doors",l,(k,R)=>M(c,k,R)),p.map((k,R)=>w(`Alternative door ${R+1}`,k,(z,U)=>m(A=>A.map((j,ie)=>ie===R?{...j,[z]:U}:j)),()=>m(z=>z.filter((U,A)=>A!==R)))),(0,W.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>m(k=>[...k,W_()]),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:zv.filter(k=>vi("architrave",`architrave-${k.id}`)).map(k=>(0,W.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g===k.id?" is-selected":""}`,onClick:()=>d(k.id),children:[(0,W.jsx)(ex,{profile:k.id}),(0,W.jsx)("div",{className:"truss-estimator__option-title",children:k.label}),(0,W.jsx)("div",{className:"truss-estimator__option-copy",children:k.blurb})]},k.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:[O.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?.(h),disabled:O<=0,children:a})]})]})]})})}var _i=X(je()),ae=X(ee()),Av=60,Uv=10,tx=.02,ax=.012,Dv=1,Ov=4,rx=1.33,ix=1440,nx=1600,Bn=e=>Number.parseFloat(e)||0,ox=(e,t=2)=>e.toFixed(t);function jd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,_i.useState)("brick"),[n,o]=(0,_i.useState)("engineering-red"),[l,c]=(0,_i.useState)("metric"),[p,m]=(0,_i.useState)(""),[g,d]=(0,_i.useState)(""),[b,_]=(0,_i.useState)(!0),M=l==="metric"?Bn(p)*Bn(g):Bn(p)*Bn(g)*.092903,f=M*(r==="brick"?Av:Uv),u=Math.ceil(f),w=M*(r==="brick"?tx:ax)*rx/(Dv+Ov),k=Math.ceil(w*Dv*ix),R=Math.ceil(w*Ov*nx),z=l==="metric"?M:M*10.7639,U=[{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-cement",label:"General purpose cement",qty:k,unit:"kg",query:"general purpose cement",category:"cement"},{key:"mortar-sand",label:"Building sand",qty:R,unit:"kg",query:"building sand",category:"aggregate"}]:[]],A=j=>{if(j===l)return;let ie=j==="imperial"?3.28084:.3048;m((Bn(p)*ie).toFixed(2)),d((Bn(g)*ie).toFixed(2)),c(j)};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:"Brick and Block Calculator"}),(0,ae.jsx)("p",{children:"Estimate masonry units, sand and cement for a wall."})]}),(0,ae.jsxs)("div",{className:"truss-estimator__card brick-calculator",children:[(0,ae.jsx)("h2",{className:"truss-estimator__step-title",children:"Wall area and masonry type"}),(0,ae.jsx)("p",{className:"truss-estimator__step-sub",children:"Pick brick or block and enter the wall dimensions for unit counts plus the cement and sand for the mortar."}),(0,ae.jsxs)("div",{className:"brick-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Masonry type"}),(0,ae.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[["brick","Brick"],["block","Block"]].map(([j,ie])=>(0,ae.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===j?" is-selected":""}`,onClick:()=>i(j),children:[(0,ae.jsx)("div",{className:"truss-estimator__option-title",children:ie}),(0,ae.jsxs)("div",{className:"truss-estimator__option-copy",children:["Approx. ",j==="brick"?Av:Uv," per m\xB2"]})]},j))})]}),r==="brick"&&(0,ae.jsxs)("div",{className:"brick-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Brick type"}),(0,ae.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(([j,ie,qe])=>(0,ae.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n===j?" is-selected":""}`,onClick:()=>o(j),children:[(0,ae.jsx)("div",{className:"truss-estimator__option-title",children:ie}),(0,ae.jsx)("div",{className:"truss-estimator__option-copy",children:qe})]},j))})]}),(0,ae.jsxs)("div",{className:"brick-calculator__section",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,ae.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,ae.jsx)("button",{type:"button",className:l==="metric"?"is-selected":"",onClick:()=>A("metric"),children:"Metric"}),(0,ae.jsx)("button",{type:"button",className:l==="imperial"?"is-selected":"",onClick:()=>A("imperial"),children:"Imperial"})]}),(0,ae.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,ae.jsxs)("label",{className:"truss-estimator__field",children:[(0,ae.jsxs)("span",{children:["Height (",l==="metric"?"m":"ft",")"]}),(0,ae.jsx)("input",{type:"number",min:"0",step:"0.01",value:p,onChange:j=>m(j.target.value)})]}),(0,ae.jsxs)("label",{className:"truss-estimator__field",children:[(0,ae.jsxs)("span",{children:["Width (",l==="metric"?"m":"ft",")"]}),(0,ae.jsx)("input",{type:"number",min:"0",step:"0.01",value:g,onChange:j=>d(j.target.value)})]})]})]}),(0,ae.jsx)("div",{className:"brick-calculator__options",children:(0,ae.jsxs)("label",{className:"brick-calculator__checkbox",children:[(0,ae.jsx)("input",{type:"checkbox",checked:b,onChange:j=>_(j.target.checked)}),(0,ae.jsx)("span",{children:"Include mortar (cement and building sand, mixed 1:4)"})]})}),(0,ae.jsxs)("div",{className:"brick-calculator__totals",children:[(0,ae.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,ae.jsxs)("div",{className:"brick-calculator__result-grid",children:[(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Wall area"}),(0,ae.jsxs)("strong",{children:[ox(z)," ",l==="metric"?"m\xB2":"ft\xB2"]})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:r==="brick"?"Bricks":"Blocks"}),(0,ae.jsx)("strong",{children:u.toLocaleString("en-GB")})]}),b?(0,ae.jsxs)(ae.Fragment,{children:[(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Cement"}),(0,ae.jsxs)("strong",{children:[k," kg"]})]}),(0,ae.jsxs)("div",{children:[(0,ae.jsx)("span",{children:"Building sand"}),(0,ae.jsxs)("strong",{children:[R," kg"]})]})]}):null]}),(0,ae.jsx)("p",{className:"brick-calculator__note",children:"Estimate based on standard nominal sizes and 10mm joints. Mortar is a general purpose 1:4 cement and sand mix; quantities are approximate, so confirm the specification before ordering."})]}),(0,ae.jsxs)("div",{className:"brick-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?.(U),disabled:M<=0,children:a})]})]})]})})}var xi=X(je()),I=X(ee()),lx=1.54,sx=1440,Qd=e=>Number.parseFloat(e)||0,Zr={mot:{label:"MOT Type 1",blurb:"Sub-base for patios and driveways",density:1.7,query:"MOT type 1"},"sharp-sand":{label:"Sharp sand",blurb:"Bedding and general groundwork",density:1.6,query:"sharp sand"},gravel:{label:"20mm gravel",blurb:"Drainage and landscaping",density:1.6,query:"20mm gravel"}};function Gd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,xi.useState)("m"),[n,o]=(0,xi.useState)(""),[l,c]=(0,xi.useState)(""),[p,m]=(0,xi.useState)(""),[g,d]=(0,xi.useState)("concrete"),[b,_]=(0,xi.useState)("mot"),M=r==="m"?1:.3048,O=Qd(n)*M*Qd(l)*M*Qd(p)*(r==="m"?.01:.0254),f=Zr[b],u=O*lx/7,h=u*sx,w=u*2,k=u*4,R=(U,A)=>Math.ceil(U*A*1e3),z=g==="concrete"?[{key:"cement",label:"General purpose cement",qty:Math.ceil(h),unit:"kg",query:"general purpose cement"},{key:"sharp-sand",label:"Sharp sand",qty:R(w,Zr["sharp-sand"].density),unit:"kg",query:Zr["sharp-sand"].query},{key:"gravel",label:"20mm gravel",qty:R(k,Zr.gravel.density),unit:"kg",query:Zr.gravel.query}]:[{key:b,label:f.label,qty:R(O,f.density),unit:"kg",query:f.query}];return(0,I.jsx)(I.Fragment,{children:(0,I.jsxs)("div",{className:"truss-estimator",children:[(0,I.jsxs)("div",{className:"quick-order-hero",children:[(0,I.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,I.jsx)("h1",{children:"Concrete and Aggregate Calculator"}),(0,I.jsx)("p",{children:"Calculate fixed site-mix concrete ingredients or aggregate bulk bags."})]}),(0,I.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,I.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose what you need"}),(0,I.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter the area and depth. The calculator works out the materials and adds them to your basket."}),(0,I.jsxs)("div",{className:"materials-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Material type"}),(0,I.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,I.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g==="concrete"?" is-selected":""}`,onClick:()=>d("concrete"),children:[(0,I.jsx)("div",{className:"truss-estimator__option-title",children:"Site-mixed concrete"}),(0,I.jsx)("div",{className:"truss-estimator__option-copy",children:"Cement, sharp sand and 20mm aggregate"})]}),(0,I.jsxs)("button",{type:"button",className:`truss-estimator__option-card${g==="aggregate"?" is-selected":""}`,onClick:()=>d("aggregate"),children:[(0,I.jsx)("div",{className:"truss-estimator__option-title",children:"Aggregates"}),(0,I.jsx)("div",{className:"truss-estimator__option-copy",children:"MOT Type 1, sharp sand or 20mm gravel"})]})]})]}),g==="aggregate"&&(0,I.jsxs)("div",{className:"materials-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Aggregate type"}),(0,I.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.keys(Zr).map(U=>(0,I.jsxs)("button",{type:"button",className:`truss-estimator__option-card${b===U?" is-selected":""}`,onClick:()=>_(U),children:[(0,I.jsx)("div",{className:"truss-estimator__option-title",children:Zr[U].label}),(0,I.jsx)("div",{className:"truss-estimator__option-copy",children:Zr[U].blurb})]},U))})]}),(0,I.jsxs)("div",{className:"materials-calculator__section",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Area and depth"}),(0,I.jsxs)("div",{className:"materials-calculator__unit-row",children:[(0,I.jsx)("span",{children:"Units"}),(0,I.jsxs)("div",{className:"brick-calculator__unit-toggle",role:"group","aria-label":"Measurement units",children:[(0,I.jsx)("button",{type:"button",className:r==="m"?"is-selected":"",onClick:()=>i("m"),children:"Metric"}),(0,I.jsx)("button",{type:"button",className:r==="ft"?"is-selected":"",onClick:()=>i("ft"),children:"Imperial"})]})]}),(0,I.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,I.jsxs)("label",{className:"truss-estimator__field",children:[(0,I.jsxs)("span",{children:["Length (",r,")"]}),(0,I.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:U=>o(U.target.value)})]}),(0,I.jsxs)("label",{className:"truss-estimator__field",children:[(0,I.jsxs)("span",{children:["Width (",r,")"]}),(0,I.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:U=>c(U.target.value)})]})]}),(0,I.jsxs)("label",{className:"truss-estimator__field materials-calculator__depth",children:[(0,I.jsxs)("span",{children:["Depth (",r==="m"?"cm":"inches",")"]}),(0,I.jsx)("input",{type:"number",min:"0",step:"0.1",value:p,onChange:U=>m(U.target.value)})]})]}),(0,I.jsxs)("div",{className:"materials-calculator__totals",children:[(0,I.jsx)("div",{className:"truss-estimator__section-heading",children:"Materials required"}),(0,I.jsx)("div",{className:"materials-calculator__result-grid",children:g==="concrete"?(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"Cement"}),(0,I.jsxs)("strong",{children:[h.toFixed(0)," kg"]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"Sharp sand"}),(0,I.jsxs)("strong",{children:[w.toFixed(2)," m\xB3"]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"20mm aggregate"}),(0,I.jsxs)("strong",{children:[k.toFixed(2)," m\xB3"]})]})]}):(0,I.jsxs)(I.Fragment,{children:[(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:f.label}),(0,I.jsxs)("strong",{children:[O.toFixed(2)," m\xB3"]})]}),(0,I.jsxs)("div",{children:[(0,I.jsx)("span",{children:"Approx. weight"}),(0,I.jsxs)("strong",{children:[(O*f.density).toFixed(2)," t"]})]}),(0,I.jsx)("div",{})]})}),(0,I.jsx)("p",{className:"materials-calculator__note",children:g==="concrete"?"Based on a 1:2:4 mix. Confirm the mix design for structural work.":"Figures are estimates. Confirm the specification and supplier quantities before ordering."})]}),(0,I.jsxs)("div",{className:"materials-calculator__actions",children:[(0,I.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,I.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(z),disabled:O<=0,children:a})]})]})]})})}var Ya=X(je());var B=X(ee()),Ln=12,Hn=8,uc=.56,Bv=.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}]}},ki=["range","grid","pictureFrame","substructure"],cx={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:""}},pc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),dc=(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),ux=(e,t,a,r)=>{let i=pc(e,t,a),n=pc(e,t,r),o=pc(a,r,e),l=pc(a,r,t);return i===0&&dc(e,t,a)||n===0&&dc(e,t,r)||o===0&&dc(a,r,e)||l===0&&dc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},Yd=(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)&&ux(e[r],i,e[n],e[(n+1)%e.length]))return!0}return!1};function $d({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ya.useState)(0),[n,o]=(0,Ya.useState)(cx),[l,c]=(0,Ya.useState)(1),[p,m]=(0,Ya.useState)({x:0,y:0}),[g,d]=(0,Ya.useState)(null),b=(0,Ya.useRef)(null),_=(0,Ya.useRef)(null),M=(0,Ya.useRef)(null),O=ki[r],f=n.range?Ra.ranges[n.range]:null,u=Ln/l,h=Hn/l,w=(Ln-u)/2,k=(Hn-h)/2,R=Math.max(-Ln,Math.min(Ln*2-u,w+p.x)),z=Math.max(-Hn,Math.min(Hn*2-h,k+p.y)),U=Number.parseFloat(n.quickLengthM),A=Number.parseFloat(n.quickWidthM),j=U>0&&A>0,ie=T=>Math.abs(T.reduce((Q,ne,ue)=>{let ve=T[(ue+1)%T.length];return Q+ne.x*ve.y-ve.x*ne.y},0))/2,qe=(T,Q)=>Math.hypot(Q.x-T.x,Q.y-T.y),Ke=n.isOutlineClosed?ie(n.points):0,Oe=n.isOutlineClosed?n.points.reduce((T,Q,ne)=>T+qe(Q,n.points[(ne+1)%n.points.length]),0):0,Me=n.isOutlineClosed?n.points.reduce((T,Q,ne)=>T+(n.wallSegments.has(ne)?0:qe(Q,n.points[(ne+1)%n.points.length])),0):0,ge=n.points.reduce((T,Q)=>({x:T.x+Q.x/n.points.length,y:T.y+Q.y/n.points.length}),{x:0,y:0}),le=n.points.length>1?(()=>{let T=n.points[0],Q=n.points[1],ne=qe(T,Q),ue=ne?-(Q.y-T.y)/ne:0,ve=ne?(Q.x-T.x)/ne:0,Ye=(T.x+Q.x)/2,Ce=(T.y+Q.y)/2,S=ue*(Ye-ge.x)+ve*(Ce-ge.y)>=0?1:-1;return{x:Ye+ue*uc*S,y:Ce+ve*uc*S}})():null,Te=(()=>{let T=n.range?Ra.ranges[n.range]:Ra.ranges.meridian,Q=n.deckSizeMode==="quick"?U*A:Ke,ne=n.deckSizeMode==="quick"?2*(U+A):Me,ue=n.direction==="diagonal"?Ra.wastage.diagonal:Ra.wastage.straight,ve=n.pictureFrame==="yes"?Ra.pictureFrame.extraWastage:0,Ce=Q/(T.boardWidthM+Ra.boardGapM)/T.boardLengthM,S=Math.ceil(Ce*(1+ue+ve)),y=Math.ceil(Q*30*(1+ue+ve)/200),E=Ra.joist.spacingOptions.find(N=>N.id===n.joistSpacing)??Ra.joist.spacingOptions[1],D=Q/E.spacingM,V=Math.ceil(D);return{range:T,area:Q,boardCount:S,screwBoxes:y,joistMetres:V,spacing:E}})(),ct=Te?[{key:`boards-${n.range??"meridian"}`,label:`Deck boards (${Te.range.label})`,qty:Math.round(Te.boardCount*Te.range.boardLengthM*100)/100,unit:"m",query:"timber decking board",category:"decking",calculatorWasteIncluded:!0},{key:"joists",label:"Treated C24 joists",qty:Te.joistMetres,unit:"m",query:"treated joist",category:"timber",calculatorWasteIncluded:!0},{key:"screws",label:"Green decking screws (200/box)",qty:Te.screwBoxes,unit:"box",query:"green decking screws",category:"fixings",calculatorWasteIncluded:!0}]:[],Z=()=>O==="range"?!!n.range:O==="grid"?n.deckSizeMode==="quick"?j:n.isOutlineClosed&&Ke>0:O==="pictureFrame"?!!n.pictureFrame&&!!n.direction:O==="substructure"?!!n.joistSpacing:!0,be=r===ki.length-1?a:"Next",Re=(T,Q,ne=!1)=>{let ue=M.current?.getBoundingClientRect();if(!ue)return null;let ve=ne?1:.25;return{x:Math.round(Math.max(R,Math.min(R+u,R+(T-ue.left)/ue.width*u))/ve)*ve,y:Math.round(Math.max(z,Math.min(z+h,z+(Q-ue.top)/ue.height*h))/ve)*ve}},wt=T=>{if(n.isOutlineClosed){let ne=T.target;if(ne!==T.currentTarget&&!ne.classList.contains("deck-outline__grid"))return;_.current={startX:T.clientX,startY:T.clientY,startViewX:R,startViewY:z},T.currentTarget.setPointerCapture(T.pointerId);return}if(n.drawMode!=="outline")return;let Q=Re(T.clientX,T.clientY,!0);Q&&(d(null),o(ne=>{let ue=[...ne.points,Q];return Yd(ue,!1)?{...ne,drawError:"Edges cannot cross. Choose another corner."}:{...ne,points:ue,drawError:""}}))},Gt=(T,Q)=>{if(!n.isOutlineClosed){T.stopPropagation(),Q===0&&n.points.length>=3&&o(ne=>({...ne,isOutlineClosed:!0,drawMode:"edges"}));return}T.stopPropagation(),b.current=Q,T.currentTarget.setPointerCapture(T.pointerId)},Ct=T=>{if(_.current){let ue=M.current?.getBoundingClientRect();if(!ue)return;let ve=_.current,Ye=ve.startViewX-(T.clientX-ve.startX)/ue.width*u,Ce=ve.startViewY-(T.clientY-ve.startY)/ue.height*h;m({x:Ye-w,y:Ce-k});return}!n.isOutlineClosed&&n.drawMode==="outline"&&d(Re(T.clientX,T.clientY,!0));let Q=b.current;if(Q===null)return;let ne=Re(T.clientX,T.clientY);ne&&o(ue=>{let ve=ue.points.map((Ye,Ce)=>Ce===Q?ne:Ye);return Yd(ve,!0)?{...ue,drawError:"Edges cannot cross. Move the corner to a different position."}:{...ue,points:ve,drawError:""}})},vt=T=>{_.current=null,b.current=null,T.currentTarget.hasPointerCapture(T.pointerId)&&T.currentTarget.releasePointerCapture(T.pointerId)},we=T=>{o(Q=>{let ne=new Set(Q.wallSegments);return ne.has(T)?ne.delete(T):ne.add(T),{...Q,wallSegments:ne}})},de=()=>{r===0?e():i(T=>T-1)},tt=()=>{Z()&&(r===ki.length-1?t?.(ct):i(T=>T+1))};return(0,B.jsx)(B.Fragment,{children:(0,B.jsxs)("div",{className:"truss-estimator",children:[(0,B.jsxs)("div",{className:"quick-order-hero",children:[(0,B.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,B.jsx)("h1",{children:"Decking Calculator"}),(0,B.jsx)("p",{children:"Estimate timber boards, joists and screws for your deck."})]}),(0,B.jsxs)("div",{className:"truss-estimator__card",children:[(0,B.jsxs)("div",{className:"truss-estimator__body",children:[O==="range"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",ki.length]}),(0,B.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your timber decking"}),(0,B.jsx)("p",{className:"truss-estimator__step-sub",children:"Both options are fixed, orderable pressure-treated timber boards."}),(0,B.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Ra.ranges).filter(([T])=>vi("decking",`boards-${T}`)).map(([T,Q])=>(0,B.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===T?" is-selected":""}`,onClick:()=>o(ne=>({...ne,range:T})),children:[(0,B.jsx)("div",{className:"truss-estimator__option-title",children:Q.label}),(0,B.jsx)("div",{className:"truss-estimator__option-copy",children:Q.blurb}),(0,B.jsxs)("div",{className:"truss-estimator__option-copy",children:[Q.boardLengthM,"m boards"]})]},T))})]}):null,O==="grid"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",ki.length]}),(0,B.jsx)("h2",{className:"truss-estimator__step-title",children:"Tell us your deck size"}),(0,B.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,B.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,B.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.deckSizeMode==="quick"?" is-selected":""}`,onClick:()=>o(T=>({...T,deckSizeMode:"quick"})),children:"Quick estimate"}),(0,B.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.deckSizeMode==="draw"?" is-selected":""}`,onClick:()=>o(T=>({...T,deckSizeMode:"draw",drawMode:"outline"})),children:"Draw your space"})]}),n.deckSizeMode==="quick"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,B.jsxs)("label",{className:"truss-estimator__field",children:[(0,B.jsx)("span",{children:"Length (m)"}),(0,B.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:n.quickLengthM,onChange:T=>o(Q=>({...Q,quickLengthM:T.target.value}))})]}),(0,B.jsxs)("label",{className:"truss-estimator__field",children:[(0,B.jsx)("span",{children:"Width (m)"}),(0,B.jsx)("input",{type:"number",inputMode:"decimal",min:"0.1",step:"0.1",value:n.quickWidthM,onChange:T=>o(Q=>({...Q,quickWidthM:T.target.value}))})]})]}),(0,B.jsx)("div",{className:"truss-estimator__grid-hint",children:"For L-shaped decks, cut-outs, or sides against a wall, use Draw your space."}),j?(0,B.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,B.jsxs)("div",{children:[(U*A).toFixed(2)," m\xB2 deck"]}),(0,B.jsxs)("div",{children:[(2*(U+A)).toFixed(2)," m perimeter"]})]}):null]}):(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)("div",{className:"truss-estimator__section-heading",children:"Draw your deck"}),(0,B.jsx)("p",{className:"truss-estimator__step-sub",children:"Click to add corners, then close the outline. Drag any handle to refine it."}),(0,B.jsxs)("div",{className:"deck-outline__toolbar",children:[n.isOutlineClosed?(0,B.jsxs)("div",{className:"deck-outline__summary",children:[(0,B.jsxs)("div",{children:[(0,B.jsx)("span",{children:"Deck area"}),(0,B.jsxs)("strong",{children:[Ke.toFixed(2)," m\xB2"]})]}),(0,B.jsxs)("div",{children:[(0,B.jsx)("span",{children:"Perimeter"}),(0,B.jsxs)("strong",{children:[Oe.toFixed(2)," m"]})]}),(0,B.jsxs)("div",{children:[(0,B.jsx)("span",{children:"Wall edges"}),(0,B.jsx)("strong",{children:n.wallSegments.size>0?n.wallSegments.size:"None"})]}),(0,B.jsxs)("div",{children:[(0,B.jsx)("span",{children:"Visible edge"}),(0,B.jsxs)("strong",{children:[Me.toFixed(2)," m"]})]})]}):null,(0,B.jsxs)("div",{className:"deck-outline__actions",children:[(0,B.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(T=>({...T,points:T.points.slice(0,-1)})),disabled:n.points.length===0||n.isOutlineClosed,children:"Undo"}),(0,B.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{d(null),o(T=>({...T,points:[],isOutlineClosed:!1,wallSegments:new Set,drawMode:"outline",drawError:""}))},disabled:n.points.length===0,children:"Clear"}),(0,B.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(T=>({...T,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,B.jsx)("div",{className:"deck-editor-layout",children:(0,B.jsxs)("div",{className:"deck-editor-layout__canvas-column",children:[(0,B.jsxs)("div",{className:"deck-outline",children:[(0,B.jsxs)("svg",{ref:M,className:`deck-outline__canvas${n.isOutlineClosed?" is-pan-mode":""}`,viewBox:`${R} ${z} ${u} ${h}`,preserveAspectRatio:"none","aria-label":"Deck outline drawing area",onPointerDown:wt,onPointerMove:Ct,onPointerUp:vt,onPointerLeave:()=>{d(null),_.current||(b.current=null)},children:[(0,B.jsx)("defs",{children:(0,B.jsx)("pattern",{id:"deck-outline-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,B.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,B.jsx)("rect",{x:-Ln,y:-Hn,width:Ln*3,height:Hn*3,className:"deck-outline__grid",fill:"url(#deck-outline-grid)"}),n.points.length>1?(0,B.jsx)("polyline",{className:"deck-outline__preview",points:n.points.map(T=>`${T.x},${T.y}`).join(" ")}):null,n.isOutlineClosed?(0,B.jsx)("polygon",{className:"deck-outline__shape",points:n.points.map(T=>`${T.x},${T.y}`).join(" "),stroke:"none"}):null,n.points.length>1?n.points.slice(0,n.isOutlineClosed?void 0:-1).map((T,Q)=>{let ne=n.points[n.isOutlineClosed?(Q+1)%n.points.length:Q+1],ue=qe(T,ne),ve=ue?-(ne.y-T.y)/ue:0,Ye=ue?(ne.x-T.x)/ue:0,Ce=(T.x+ne.x)/2,S=(T.y+ne.y)/2,y=ve*(Ce-ge.x)+Ye*(S-ge.y)>=0?1:-1,E=Ce+ve*uc*y,D=S+Ye*uc*y;return(0,B.jsxs)("g",{children:[(0,B.jsx)("line",{className:"deck-outline__edge-hit",x1:T.x,y1:T.y,x2:ne.x,y2:ne.y,onClick:n.isOutlineClosed?()=>we(Q):void 0}),(0,B.jsx)("line",{className:`deck-outline__edge${n.wallSegments.has(Q)?" is-wall":""}`,x1:T.x,y1:T.y,x2:ne.x,y2:ne.y,pointerEvents:"none"}),(0,B.jsxs)("text",{className:`deck-outline__edge-label${n.wallSegments.has(Q)?" is-wall":""}`,x:E,y:D,textAnchor:"middle",dominantBaseline:"central",fontSize:Bv/l,children:[ue.toFixed(2)," m"]})]},`segment-${Q}`)}):null,!n.isOutlineClosed&&n.points.length>0&&g?(()=>{let T=n.points[n.points.length-1],Q=qe(T,g);if(!Q)return null;let ne=-(g.y-T.y)/Q,ue=(g.x-T.x)/Q,ve=(T.x+g.x)/2,Ye=(T.y+g.y)/2;return(0,B.jsxs)("g",{className:"deck-outline__live-measurement",children:[(0,B.jsx)("line",{x1:T.x,y1:T.y,x2:g.x,y2:g.y}),(0,B.jsxs)("text",{x:ve+ne*.34,y:Ye+ue*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:Bv/l,children:[Q.toFixed(2)," m"]})]})})():null,n.points.map((T,Q)=>(0,B.jsx)("circle",{className:"deck-outline__point",cx:T.x,cy:T.y,r:"0.13",onPointerDown:ne=>Gt(ne,Q)},`point-${Q}`))]}),(0,B.jsxs)("div",{className:"deck-outline__zoom","aria-label":"Zoom controls",children:[(0,B.jsx)("button",{type:"button",onClick:()=>c(T=>Math.max(.5,T-.25)),disabled:l===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,B.jsxs)("span",{children:[Math.round(l*100),"%"]}),(0,B.jsx)("button",{type:"button",onClick:()=>c(T=>Math.min(1,T+.25)),disabled:l===1,"aria-label":"Zoom in",children:"+"})]}),n.isOutlineClosed&&n.wallSegments.size===0&&le?(0,B.jsx)("div",{className:"deck-outline__edge-prompt",role:"status",style:{left:`${(le.x-R)/u*100}%`,top:`${(le.y-z)/h*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,B.jsx)("button",{type:"button",className:"deck-outline__close",onClick:()=>o(T=>Yd(T.points,!0)?{...T,drawError:"Edges cannot cross. Adjust the outline before finishing."}:{...T,isOutlineClosed:!0,drawMode:"edges",drawError:""}),children:"Finish outline"}):null]}),(0,B.jsxs)("div",{className:"deck-outline__supporting",children:[(0,B.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,B.jsx)("div",{className:"deck-outline__error",role:"alert",children:n.drawError}):null]})]})})]})]}):null,O==="pictureFrame"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",ki.length]}),(0,B.jsx)("h2",{className:"truss-estimator__step-title",children:"Picture frame border?"}),(0,B.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,B.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(T=>(0,B.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.pictureFrame===T.id?" is-selected":""}`,onClick:()=>o(Q=>({...Q,pictureFrame:T.id})),children:[(0,B.jsx)("img",{className:"truss-estimator__visual-card-img",src:Ft(T.img),alt:""}),(0,B.jsx)("span",{children:T.label})]},T.id))}),(0,B.jsxs)(B.Fragment,{children:[(0,B.jsx)("div",{className:"truss-estimator__section-heading",children:"Board direction"}),(0,B.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(T=>(0,B.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.direction===T.id?" is-selected":""}`,onClick:()=>o(Q=>({...Q,direction:T.id})),children:[(0,B.jsx)("img",{className:"truss-estimator__visual-card-img",src:Ft(T.img),alt:""}),(0,B.jsx)("span",{children:T.label})]},T.id))})]})]}):null,O==="substructure"?(0,B.jsxs)(B.Fragment,{children:[(0,B.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",ki.length]}),(0,B.jsx)("h2",{className:"truss-estimator__step-title",children:"Substructure"}),(0,B.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,B.jsx)("div",{className:"truss-estimator__section-heading",children:"Joist spacing"}),(0,B.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Ra.joist.spacingOptions.map(T=>(0,B.jsx)("button",{type:"button",className:`truss-estimator__option-card${n.joistSpacing===T.id?" is-selected":""}`,onClick:()=>o(Q=>({...Q,joistSpacing:T.id})),children:(0,B.jsx)("div",{className:"truss-estimator__option-title",children:T.label})},T.id))})]}):null]}),(0,B.jsxs)("div",{className:"truss-estimator__nav",children:[(0,B.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:de,children:"Back"}),(0,B.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:tt,disabled:!Z(),children:[(0,B.jsx)("span",{children:be}),(0,B.jsx)("span",{className:"arrow",children:(0,B.jsx)(jt,{})})]})]})]})]})})}var Ca=X(je());var Y=X(ee()),Lv=12,Hv=30,jn=12,Qn=8,jv=.56,Na={ranges:{boundary:{label:"Horizontal lap",blurb:"Traditional pressure-treated timber panels.",panelWidthM:1.83},skyline:{label:"Feather edge",blurb:"Heavier timber panels for a more solid boundary.",panelWidthM:1.83}},heights:["0.9","1.2","1.5","1.8"],gate:{single:{label:"Single gate",widthDefault:.9}},mounting:{concrete:{label:"Concrete posts",blurb:"Slotted concrete posts with matching panels."},postcrete:{label:"Postcrete bags",blurb:"Fast-set post-mix bags in a dug hole.",bagsPerPost:2}}},Si=["range","height","gate","posts"],Vd=e=>Number(e)<=1.2?"6":"8",Qv=(e,t)=>vi("fencing",`panels-${e??"boundary"}-${t}`),Gv=(e,t)=>!t||vi("fencing",e==="concrete"?`concrete-intermediate-${Vd(t)}`:`timber-post-${Vd(t)}`),px={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:""}},mc=(e,t,a)=>(t.x-e.x)*(a.y-e.y)-(t.y-e.y)*(a.x-e.x),fc=(e,t,a)=>a.x>=Math.min(e.x,t.x)&&a.x<=Math.max(e.x,t.x)&&a.y>=Math.min(e.y,t.y)&&a.y<=Math.max(e.y,t.y),dx=(e,t,a,r)=>{let i=mc(e,t,a),n=mc(e,t,r),o=mc(a,r,e),l=mc(a,r,t);return i===0&&fc(e,t,a)||n===0&&fc(e,t,r)||o===0&&fc(a,r,e)||l===0&&fc(a,r,t)?!0:i>0!=n>0&&o>0!=l>0},hc=(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)&&dx(e[r],e[(r+1)%e.length],e[i],e[(i+1)%e.length]))return!0;return!1};function Xd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ca.useState)(0),[n,o]=(0,Ca.useState)(px),l=(0,Ca.useRef)(null),c=(0,Ca.useRef)(null),[p,m]=(0,Ca.useState)(1),[g,d]=(0,Ca.useState)({x:0,y:0}),[b,_]=(0,Ca.useState)(null),M=(0,Ca.useRef)(null),O=(0,Ca.useRef)(null),f=(0,Ca.useRef)(null),u=Si[r],h=n.range?Na.ranges[n.range]:null,w=jn/p,k=Qn/p,R=(jn-w)/2,z=(Qn-k)/2,U=Math.max(-jn,Math.min(jn*2-w,R+g.x)),A=Math.max(-Qn,Math.min(Qn*2-k,z+g.y)),j=n.boundaryPoints.reduce((S,y)=>({x:S.x+y.x/Math.max(1,n.boundaryPoints.length),y:S.y+y.y/Math.max(1,n.boundaryPoints.length)}),{x:0,y:0}),ie=S=>{let y=new Set,E=[];return S.forEach(D=>{let[V,N]=D.split(",").map(Number),L=[{key:`H,${V},${N}`,type:"H",x:V,y:N},{key:`H,${V},${N+1}`,type:"H",x:V,y:N+1},{key:`V,${V},${N}`,type:"V",x:V,y:N},{key:`V,${V+1},${N}`,type:"V",x:V+1,y:N}],$=[!S.has(`${V},${N-1}`),!S.has(`${V},${N+1}`),!S.has(`${V-1},${N}`),!S.has(`${V+1},${N}`)];L.forEach((se,ke)=>{$[ke]&&!y.has(se.key)&&(y.add(se.key),E.push(se))})}),E},qe=(S,y)=>ie(S).filter(E=>!y.has(E.key)),Ke=(S,y)=>qe(S,y).length,Oe=(S,y)=>{let E={};qe(S,y).forEach(V=>{var N,L,$,se;V.type==="H"?((E[N=`${V.x},${V.y}`]||(E[N]=[])).push("H"),(E[L=`${V.x+1},${V.y}`]||(E[L]=[])).push("H")):((E[$=`${V.x},${V.y}`]||(E[$]=[])).push("V"),(E[se=`${V.x},${V.y+1}`]||(E[se]=[])).push("V"))});let D=0;return Object.values(E).forEach(V=>{(V.length===1||V.length===2&&V[0]!==V[1]||V.length>=3)&&(D+=1)}),D},ge=(()=>{let S=n.range?Na.ranges[n.range]:Na.ranges.boundary,y=n.height??"1.8",E=n.boundaryMode==="quick"?Math.max(0,Number.parseFloat(n.quickLengthM)||0):n.boundaryClosed?n.boundaryPoints.slice(0,-1).reduce((Yt,hr,_t)=>Yt+(n.excludedBoundaryEdges.has(_t)?0:Math.hypot(n.boundaryPoints[_t+1].x-hr.x,n.boundaryPoints[_t+1].y-hr.y)),0):0,D=n.gateType&&n.gateType!=="none"?Number.parseFloat(n.gateWidthM)||Na.gate[n.gateType].widthDefault:0,V=Math.max(0,E-D),N=V>0?Math.ceil(V/S.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,$=n.boundaryMode==="quick"?V>0?2:0:n.boundaryClosed?n.boundaryPoints.slice(0,L?-1:void 0).reduce((Yt,hr,_t)=>{let qi=_t>0&&!n.excludedBoundaryEdges.has(_t-1),um=_t<n.boundaryPoints.length-1&&!n.excludedBoundaryEdges.has(_t);return Yt+(qi||um?1:0)},0):0,se=V>0?Math.ceil(V/S.panelWidthM)+1:0,ke=Math.max(0,se-$),yt=n.mountingType?Na.mounting[n.mountingType]:Na.mounting.concrete,at=n.gateType&&n.gateType!=="none"?2:0,qt=ke+$+at,cm=n.mountingType==="postcrete"?qt*Na.mounting.postcrete.bagsPerPost:0,Kr=n.gravelBoard==="yes"?N:0;return{range:S,height:y,totalEdgeM:E,fencedLengthM:V,gateWidthM:D,panelsCount:N,cornerPostCount:$,intermediatePostCount:ke,gatePostCount:at,totalPostCount:qt,bagsCount:cm,gravelCount:Kr,capCount:qt,mounting:yt}})(),le=n.gateType&&n.gateType!=="none"?Na.gate[n.gateType].label:null,Ve=Vd(ge.height),Te=ge?[{key:`panels-${n.range??"boundary"}-${ge.height}`,label:`${ge.range.label} panels (${ge.height}m)`,qty:ge.panelsCount,unit:"each",query:"fence panel",category:"fencing"},...n.mountingType==="concrete"?[{key:`concrete-intermediate-${Ve}`,label:"Intermediate concrete posts",qty:ge.intermediatePostCount,unit:"each",query:"concrete fence post",category:"fencing"},{key:`concrete-end-${Ve}`,label:"End and corner concrete posts",qty:ge.cornerPostCount+ge.gatePostCount,unit:"each",query:"concrete end post",category:"fencing"}]:[{key:`timber-post-${Ve}`,label:"Timber fence posts",qty:ge.totalPostCount,unit:"each",query:"timber fence post",category:"fencing"},{key:"postcrete",label:"Postcrete",qty:ge.bagsCount,unit:"bag",query:"postcrete",category:"cement"}],...le?[{key:`gate-${n.range??"boundary"}`,label:n.range==="skyline"?"Single feather edge gate":"Single lap gate",qty:1,unit:"each",query:n.range==="skyline"?"feather edge gate":"lap gate",category:"fencing"}]:[],...ge.gravelCount>0?[{key:"gravel-boards",label:"Concrete gravel boards",qty:ge.gravelCount,unit:"each",query:"gravel board",category:"fencing"}]:[]]:[],ct=()=>{if(u==="range"){let S=n.boundaryMode==="quick"?(Number.parseFloat(n.quickLengthM)||0)>0:n.boundaryClosed&&n.boundaryPoints.length>=2;return!!n.range&&S}return u==="height"?!!n.height&&!!n.gravelBoard:u==="gate"?!!n.gateType&&(n.gateType==="none"||n.gateWidthM.trim()!==""):u==="posts"?!!n.mountingType:!0},Z=r===Si.length-1?a:"Next",be=S=>{o(y=>{let E=S(new Set(y.grid)),D=new Set([...y.excludedEdges].filter(V=>ie(E).some(N=>N.key===V)));return{...y,grid:E,excludedEdges:D}})},Re=(S,y,E)=>{be(D=>{let V=`${S},${y}`;return E?D.add(V):D.delete(V),D})},wt=(S,y,E,D,V)=>{let N=S,L=y,$=Math.abs(E-S),se=S<E?1:-1,ke=-Math.abs(D-y),yt=y<D?1:-1,at=$+ke;for(;Re(N,L,V),!(N===E&&L===D);){let qt=2*at;qt>=ke&&(at+=ke,N+=se),qt<=$&&(at+=$,L+=yt)}},Gt=(S,y)=>{let E=c.current?.getBoundingClientRect();if(!E)return null;let D=Math.floor((S-E.left)/Hv),V=Math.floor((y-E.top)/Hv);return D<0||V<0||D>=Lv||V>=Lv?null:{x:D,y:V}},Ct=S=>{if(n.gridMode!=="draw")return;let y=Gt(S.clientX,S.clientY);if(!y)return;S.preventDefault();let E=`${y.x},${y.y}`,D=!n.grid.has(E);l.current={active:!0,paintValue:D,lastX:y.x,lastY:y.y},S.currentTarget.setPointerCapture(S.pointerId),Re(y.x,y.y,D)},vt=S=>{let y=l.current;if(!y?.active)return;let E=Gt(S.clientX,S.clientY);E&&(E.x===y.lastX&&E.y===y.lastY||(wt(y.lastX,y.lastY,E.x,E.y,y.paintValue),l.current={...y,lastX:E.x,lastY:E.y}))},we=S=>{l.current?.active&&(l.current=null,S.currentTarget.releasePointerCapture(S.pointerId))},de=(S,y,E=!1)=>{let D=f.current?.getBoundingClientRect();if(!D)return null;let V=E?1:.25;return{x:Math.round(Math.max(U,Math.min(U+w,U+(S-D.left)/D.width*w))/V)*V,y:Math.round(Math.max(A,Math.min(A+k,A+(y-D.top)/D.height*k))/V)*V}},tt=S=>{if(n.boundaryClosed){let E=S.target;if(E!==S.currentTarget&&!E.classList.contains("fence-boundary__grid"))return;O.current={startX:S.clientX,startY:S.clientY,startViewX:U,startViewY:A},S.currentTarget.setPointerCapture(S.pointerId);return}let y=de(S.clientX,S.clientY,!0);y&&(_(null),o(E=>{let D=[...E.boundaryPoints,y];return hc(D,!1)?{...E}:{...E,boundaryPoints:D}}))},T=(S,y)=>{if(S.stopPropagation(),!n.boundaryClosed){if(y!==0||n.boundaryPoints.length<3)return;o(E=>hc(E.boundaryPoints,!0)?E:{...E,boundaryPoints:[...E.boundaryPoints,E.boundaryPoints[0]],boundaryClosed:!0});return}M.current=y,S.currentTarget.setPointerCapture(S.pointerId)},Q=S=>{if(O.current){let E=f.current?.getBoundingClientRect();if(!E)return;let D=O.current,V=D.startViewX-(S.clientX-D.startX)/E.width*w,N=D.startViewY-(S.clientY-D.startY)/E.height*k;d({x:V-R,y:N-z});return}if(n.boundaryClosed||_(de(S.clientX,S.clientY,!0)),M.current===null)return;let y=de(S.clientX,S.clientY);y&&o(E=>{let D=E.boundaryPoints.length>2&&E.boundaryPoints[0].x===E.boundaryPoints[E.boundaryPoints.length-1].x&&E.boundaryPoints[0].y===E.boundaryPoints[E.boundaryPoints.length-1].y,V=E.boundaryPoints.map((N,L)=>{let $=L===M.current,se=D&&M.current===0&&L===E.boundaryPoints.length-1;return $||se?y:N});return hc(V,!1)?E:{...E,boundaryPoints:V}})},ne=S=>{O.current=null,M.current=null,S.currentTarget.hasPointerCapture(S.pointerId)&&S.currentTarget.releasePointerCapture(S.pointerId)},ue=S=>{o(y=>{let E=new Set(y.excludedBoundaryEdges);return E.has(S)?E.delete(S):E.add(S),{...y,excludedBoundaryEdges:E}})},ve=()=>{r===0?e():i(S=>S-1)},Ye=()=>{ct()&&(r===Si.length-1?t?.(Te):i(S=>S+1))},Ce=ie(n.grid);return(0,Y.jsx)(Y.Fragment,{children:(0,Y.jsxs)("div",{className:"truss-estimator",children:[(0,Y.jsxs)("div",{className:"quick-order-hero",children:[(0,Y.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Y.jsx)("h1",{children:"Fencing Calculator"}),(0,Y.jsx)("p",{children:"Estimate panels, posts and cost for your fence line in a few steps."})]}),(0,Y.jsxs)("div",{className:"truss-estimator__card",children:[(0,Y.jsxs)("div",{className:"truss-estimator__body",children:[u==="range"?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Y.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your fence panels"}),(0,Y.jsx)("p",{className:"truss-estimator__step-sub",children:"The calculator uses fixed, orderable timber panels from the catalogue."}),(0,Y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Na.ranges).map(([S,y])=>(0,Y.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.range===S?" is-selected":""}`,onClick:()=>o(E=>({...E,range:S,height:E.height&&Qv(S,E.height)?E.height:null})),children:[(0,Y.jsx)("div",{className:"truss-estimator__option-title",children:y.label}),(0,Y.jsx)("div",{className:"truss-estimator__option-copy",children:y.blurb})]},S))})]}):null,u==="range"?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)("div",{className:"truss-estimator__section-heading",children:"Measure your fence line"}),(0,Y.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,Y.jsxs)("div",{className:"truss-estimator__toggle-row",children:[(0,Y.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="quick"?" is-selected":""}`,onClick:()=>o(S=>({...S,boundaryMode:"quick"})),children:"Quick estimate"}),(0,Y.jsx)("button",{type:"button",className:`truss-estimator__toggle${n.boundaryMode==="draw"?" is-selected":""}`,onClick:()=>o(S=>({...S,boundaryMode:"draw"})),children:"Draw your boundary"})]}),n.boundaryMode==="quick"?(0,Y.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact fence-boundary__quick-field",children:[(0,Y.jsx)("span",{children:"Total fence length (m)"}),(0,Y.jsx)("input",{type:"number",min:"0",step:"0.1",value:n.quickLengthM,onChange:S=>o(y=>({...y,quickLengthM:S.target.value}))})]}):(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsx)("div",{className:"fence-boundary__toolbar",children:(0,Y.jsxs)("div",{className:"fence-boundary__actions",children:[(0,Y.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(S=>({...S,boundaryPoints:S.boundaryPoints.slice(0,-1),boundaryClosed:!1,excludedBoundaryEdges:new Set})),disabled:n.boundaryPoints.length===0||n.boundaryClosed,children:"Undo"}),(0,Y.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>{d({x:0,y:0}),_(null),o(S=>({...S,boundaryPoints:[],boundaryClosed:!1,excludedBoundaryEdges:new Set}))},disabled:n.boundaryPoints.length===0,children:"Clear"}),(0,Y.jsx)("button",{type:"button",className:"deck-outline__action",onClick:()=>o(S=>({...S,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,Y.jsxs)("div",{className:"fence-boundary",children:[(0,Y.jsxs)("svg",{ref:f,className:`fence-boundary__canvas${n.boundaryClosed?" is-pan-mode":""}`,viewBox:`${U} ${A} ${w} ${k}`,preserveAspectRatio:"none","aria-label":"Fence boundary drawing area",onPointerDown:tt,onPointerMove:Q,onPointerUp:ne,onPointerLeave:()=>{_(null),O.current||(M.current=null)},children:[(0,Y.jsx)("defs",{children:(0,Y.jsx)("pattern",{id:"fence-boundary-grid",width:"1",height:"1",patternUnits:"userSpaceOnUse",children:(0,Y.jsx)("path",{d:"M 1 0 L 0 0 0 1",fill:"none",stroke:"currentColor",strokeWidth:"0.03"})})}),(0,Y.jsx)("rect",{x:-jn,y:-Qn,width:jn*3,height:Qn*3,className:"fence-boundary__grid",fill:"url(#fence-boundary-grid)"}),n.boundaryPoints.length>1?(0,Y.jsx)("polyline",{className:"fence-boundary__preview",points:n.boundaryPoints.map(S=>`${S.x},${S.y}`).join(" ")}):null,n.boundaryPoints.length>1?n.boundaryPoints.slice(0,-1).map((S,y)=>{let E=n.boundaryPoints[y+1],D=Math.hypot(E.x-S.x,E.y-S.y),V=D?-(E.y-S.y)/D:0,N=D?(E.x-S.x)/D:0,L=(S.x+E.x)/2,$=(S.y+E.y)/2,se=V*(L-j.x)+N*($-j.y)>=0?1:-1,ke=L+V*jv*se,yt=$+N*jv*se;return(0,Y.jsxs)("g",{children:[(0,Y.jsx)("line",{className:"fence-boundary__edge-hit",x1:S.x,y1:S.y,x2:E.x,y2:E.y,onClick:n.boundaryClosed?()=>ue(y):void 0}),(0,Y.jsx)("line",{className:`fence-boundary__edge${n.excludedBoundaryEdges.has(y)?" is-excluded":""}`,x1:S.x,y1:S.y,x2:E.x,y2:E.y,pointerEvents:"none"}),(0,Y.jsxs)("text",{className:`fence-boundary__edge-label${n.excludedBoundaryEdges.has(y)?" is-excluded":""}`,x:ke,y:yt,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[D.toFixed(2)," m"]})]},`fence-edge-${y}`)}):null,!n.boundaryClosed&&n.boundaryPoints.length>0&&b?(()=>{let S=n.boundaryPoints[n.boundaryPoints.length-1],y=Math.hypot(b.x-S.x,b.y-S.y);if(!y)return null;let E=-(b.y-S.y)/y,D=(b.x-S.x)/y,V=(S.x+b.x)/2,N=(S.y+b.y)/2;return(0,Y.jsxs)("g",{className:"fence-boundary__live-measurement",children:[(0,Y.jsx)("line",{x1:S.x,y1:S.y,x2:b.x,y2:b.y}),(0,Y.jsxs)("text",{x:V+E*.34,y:N+D*.34,textAnchor:"middle",dominantBaseline:"central",fontSize:.21/p,children:[y.toFixed(2)," m"]})]})})():null,n.boundaryPoints.map((S,y)=>y>0&&y===n.boundaryPoints.length-1&&S.x===n.boundaryPoints[0]?.x&&S.y===n.boundaryPoints[0]?.y?null:(0,Y.jsx)("circle",{className:`fence-boundary__point${!n.boundaryClosed&&y===0&&n.boundaryPoints.length>=3?" is-close-target":""}`,cx:S.x,cy:S.y,r:"0.13",onPointerDown:E=>T(E,y)},`fence-point-${y}`))]}),(0,Y.jsxs)("div",{className:"fence-boundary__zoom","aria-label":"Zoom controls",children:[(0,Y.jsx)("button",{type:"button",onClick:()=>m(S=>Math.max(.5,S-.25)),disabled:p===.5,"aria-label":"Zoom out",children:"\u2212"}),(0,Y.jsxs)("span",{children:[Math.round(p*100),"%"]}),(0,Y.jsx)("button",{type:"button",onClick:()=>m(S=>Math.min(1,S+.25)),disabled:p===1,"aria-label":"Zoom in",children:"+"})]}),!n.boundaryClosed&&n.boundaryPoints.length>=2?(0,Y.jsx)("button",{type:"button",className:"fence-boundary__close",onClick:()=>o(S=>hc(S.boundaryPoints,!1)?S:{...S,boundaryClosed:!0}),children:"Finish fence line"}):null]}),(0,Y.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,Y.jsxs)("div",{className:"truss-estimator__grid-stats",children:[(0,Y.jsx)("div",{children:n.boundaryMode==="quick"?`${(Number.parseFloat(n.quickLengthM)||0).toFixed(2)} m fence line`:`${ge.totalEdgeM.toFixed(2)} m fence line`}),n.boundaryMode==="draw"&&n.boundaryClosed?(0,Y.jsxs)("div",{children:[ge.cornerPostCount," corner/end posts"]}):null]})]}):null,null,u==="height"?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Y.jsx)("h2",{className:"truss-estimator__step-title",children:"Fence height"}),(0,Y.jsx)("p",{className:"truss-estimator__step-sub",children:"Select the nearest available panel height."}),(0,Y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:Na.heights.filter(S=>Qv(n.range,S)).map(S=>(0,Y.jsx)("button",{type:"button",className:`truss-estimator__visual-card${n.height===S?" is-selected":""}`,onClick:()=>o(y=>({...y,height:S,mountingType:y.mountingType&&Gv(y.mountingType,S)?y.mountingType:null})),children:(0,Y.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--tall",src:Ft(`/fencing/height/${S}.webp`),alt:""})},S))}),(0,Y.jsx)("div",{className:"truss-estimator__section-heading",children:"Gravel board?"}),(0,Y.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(S=>(0,Y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${n.gravelBoard===S.id?" is-selected":""}`,onClick:()=>o(y=>({...y,gravelBoard:S.id})),children:[(0,Y.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Ft(S.img),alt:""}),(0,Y.jsx)("span",{children:S.label})]},S.id))})]}):null,u==="gate"?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Y.jsx)("h2",{className:"truss-estimator__step-title",children:"Do you need a gate?"}),(0,Y.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,Y.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(S=>(0,Y.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${n.gateType===S.id?" is-selected":""}`,onClick:()=>o(y=>({...y,gateType:S.id,gateWidthM:S.id==="none"?"":String(Na.gate[S.id].widthDefault)})),children:[(0,Y.jsx)("img",{className:"truss-estimator__visual-card-img truss-estimator__visual-card-img--mid",src:Ft(S.img),alt:""}),(0,Y.jsx)("span",{children:S.label})]},S.id))}),n.gateType&&n.gateType!=="none"?(0,Y.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,Y.jsx)("span",{children:"Gate width (m)"}),(0,Y.jsx)("input",{type:"text",inputMode:"decimal",value:n.gateWidthM,onChange:S=>o(y=>({...y,gateWidthM:S.target.value}))})]}):null]}):null,u==="posts"?(0,Y.jsxs)(Y.Fragment,{children:[(0,Y.jsxs)("div",{className:"truss-estimator__step-label",children:["Step ",r+1," of ",Si.length]}),(0,Y.jsx)("h2",{className:"truss-estimator__step-title",children:"Posts and fixing type"}),(0,Y.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose how the posts will be set."}),(0,Y.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Object.entries(Na.mounting).filter(([S])=>Gv(S,n.height)).map(([S,y])=>(0,Y.jsxs)("button",{type:"button",className:`truss-estimator__option-card${n.mountingType===S?" is-selected":""}`,onClick:()=>o(E=>({...E,mountingType:S})),children:[(0,Y.jsx)("div",{className:"truss-estimator__option-title",children:y.label}),(0,Y.jsx)("div",{className:"truss-estimator__option-copy",children:y.blurb})]},S))})]}):null]}),(0,Y.jsxs)("div",{className:"truss-estimator__nav",children:[(0,Y.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:ve,children:"Back"}),(0,Y.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:Ye,disabled:!ct(),children:[(0,Y.jsx)("span",{children:Z}),(0,Y.jsx)("span",{className:"arrow",children:(0,Y.jsx)(jt,{})})]})]})]})]})})}var gc=X(je()),he=X(ee()),Yv={floor:{label:"Floor between rooms",product:"Knauf Acoustic Roll",thickness:"100mm",coverage:12.36},ground:{label:"Ground floor",product:"Rigid PIR insulation board",thickness:"100mm",coverage:2.88},wall:{label:"Cavity wall",product:"Celotex CW4100",thickness:"100mm",coverage:3.24},roof:{label:"Pitched roof",product:"Kingspan K107",thickness:"100mm",coverage:8.64},loft:{label:"Loft",product:"Knauf Loft Roll 44",thickness:"100mm",coverage:13.89}};function Zd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,gc.useState)("floor"),[n,o]=(0,gc.useState)(""),[l,c]=(0,gc.useState)(""),p=Number.parseFloat(n)*Number.parseFloat(l)||0,m=Yv[r],g=Math.ceil(p/m.coverage),d=[{key:`insulation-${r}`,label:`${m.product} ${m.thickness}`,qty:Math.round(p*100)/100,unit:"m2",query:m.product,category:"insulation"}],b=Object.entries(Yv);return(0,he.jsx)(he.Fragment,{children:(0,he.jsxs)("div",{className:"truss-estimator",children:[(0,he.jsxs)("div",{className:"quick-order-hero",children:[(0,he.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,he.jsx)("h1",{children:"Insulation Calculator"}),(0,he.jsx)("p",{children:"Estimate insulation coverage and pack quantities for floors, walls, roofs and lofts."})]}),(0,he.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,he.jsx)("h2",{className:"truss-estimator__step-title",children:"Where and what you are insulating"}),(0,he.jsx)("p",{className:"truss-estimator__step-sub",children:"Choose the application and product, and enter the area, for coverage and pack quantities."}),(0,he.jsxs)("div",{className:"materials-calculator__section",children:[(0,he.jsx)("div",{className:"truss-estimator__section-heading",children:"Application"}),(0,he.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:b.map(([_,M])=>(0,he.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===_?" is-selected":""}`,onClick:()=>i(_),children:[(0,he.jsx)("div",{className:"truss-estimator__option-title",children:M.label}),(0,he.jsxs)("div",{className:"truss-estimator__option-copy",children:[M.product,", ",M.thickness]})]},_))})]}),(0,he.jsxs)("div",{className:"materials-calculator__section",children:[(0,he.jsx)("div",{className:"truss-estimator__section-heading",children:"Area"}),(0,he.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,he.jsxs)("label",{className:"truss-estimator__field",children:[(0,he.jsx)("span",{children:"Length (m)"}),(0,he.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:_=>o(_.target.value)})]}),(0,he.jsxs)("label",{className:"truss-estimator__field",children:[(0,he.jsx)("span",{children:"Width (m)"}),(0,he.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:_=>c(_.target.value)})]})]})]}),(0,he.jsxs)("div",{className:"materials-calculator__totals",children:[(0,he.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,he.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,he.jsxs)("div",{children:[(0,he.jsx)("span",{children:"Insulated area"}),(0,he.jsxs)("strong",{children:[p.toFixed(2)," m\xB2"]})]}),(0,he.jsxs)("div",{children:[(0,he.jsx)("span",{children:m.product}),(0,he.jsxs)("strong",{children:[g," packs"]})]})]}),(0,he.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,he.jsxs)("div",{className:"materials-calculator__actions",children:[(0,he.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,he.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(d),disabled:p<=0,children:a})]})]})]})})}var Gn=X(je());var K=X(ee()),mx=10,fx=1.9*.762,hx=1.9*1.524,bc=()=>({height:"",width:""}),wc=e=>Number.parseFloat(e)||0,$v=({height:e,width:t})=>wc(e)*wc(t);function Kd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Gn.useState)([bc()]),[n,o]=(0,Gn.useState)([bc()]),[l,c]=(0,Gn.useState)("0"),[p,m]=(0,Gn.useState)("0"),[g,d]=(0,Gn.useState)(1),b=r.reduce((k,R)=>k+$v(R),0),_=n.reduce((k,R)=>k+$v(R),0),M=wc(l)*fx+wc(p)*hx,O=Math.max(0,b-_-M),f=O*g/mx,u={key:"paint-emulsion",label:"Matt emulsion, brilliant white",qty:Math.round(f*10)/10,unit:"litres",query:"matt emulsion brilliant white"},h=cl("paint",u)!=null,w=(k,R,z,U)=>{k(A=>A.map((j,ie)=>ie===R?{...j,[z]:U}:j))};return(0,K.jsx)(K.Fragment,{children:(0,K.jsxs)("div",{className:"truss-estimator",children:[(0,K.jsxs)("div",{className:"quick-order-hero",children:[(0,K.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,K.jsx)("h1",{children:"Paint Calculator"}),(0,K.jsx)("p",{children:"Estimate how much paint you need for your walls, including multiple coats and excluded areas."})]}),(0,K.jsxs)("div",{className:"truss-estimator__card paint-calculator",children:[(0,K.jsx)("h2",{className:"truss-estimator__step-title",children:"Walls, exclusions and coats"}),(0,K.jsx)("p",{className:"truss-estimator__step-sub",children:"Enter each wall, subtract windows and doors, and choose your number of coats. Quantities assume a coverage of 10 m\xB2 per litre."}),(0,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall dimensions"}),(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Enter the height and width of each wall you want to paint."}),(0,K.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,K.jsx)("span",{}),(0,K.jsx)("span",{children:"Height (m)"}),(0,K.jsx)("span",{children:"Width (m)"}),(0,K.jsx)("span",{})]}),r.map((k,R)=>(0,K.jsxs)("div",{className:"paint-calculator__row",children:[(0,K.jsxs)("span",{className:"paint-calculator__row-label",children:["Wall ",R+1]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,K.jsx)("input",{"aria-label":`Wall ${R+1} height in metres`,type:"number",min:"0",step:"0.01",value:k.height,onChange:z=>w(i,R,"height",z.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,K.jsx)("input",{"aria-label":`Wall ${R+1} width in metres`,type:"number",min:"0",step:"0.01",value:k.width,onChange:z=>w(i,R,"width",z.target.value)})]}),r.length>1?(0,K.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(z=>z.filter((U,A)=>A!==R)),children:"Remove"}):null]},`wall-${R}`)),(0,K.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(k=>[...k,bc()]),children:"+ Add another wall"})]}),(0,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Areas to exclude"}),(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Add windows, sockets, skirting boards or other areas that will not be painted."}),(0,K.jsxs)("div",{className:"paint-calculator__dimensions-header","aria-hidden":"true",children:[(0,K.jsx)("span",{}),(0,K.jsx)("span",{children:"Height (m)"}),(0,K.jsx)("span",{children:"Width (m)"}),(0,K.jsx)("span",{})]}),n.map((k,R)=>(0,K.jsxs)("div",{className:"paint-calculator__row",children:[(0,K.jsxs)("span",{className:"paint-calculator__row-label",children:["Area ",R+1]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Height (m)"}),(0,K.jsx)("input",{"aria-label":`Area ${R+1} height in metres`,type:"number",min:"0",step:"0.01",value:k.height,onChange:z=>w(o,R,"height",z.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{className:"sr-only",children:"Width (m)"}),(0,K.jsx)("input",{"aria-label":`Area ${R+1} width in metres`,type:"number",min:"0",step:"0.01",value:k.width,onChange:z=>w(o,R,"width",z.target.value)})]}),n.length>1?(0,K.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>o(z=>z.filter((U,A)=>A!==R)),children:"Remove"}):null]},`excluded-${R}`)),(0,K.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>o(k=>[...k,bc()]),children:"+ Add another area"})]}),(0,K.jsxs)("div",{className:"paint-calculator__section",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Doors and coats"}),(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Enter the number of standard single and double doors to leave unpainted. Door sizes are estimated automatically."}),(0,K.jsxs)("div",{className:"truss-estimator__field-grid paint-calculator__small-fields",children:[(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Doors"}),(0,K.jsx)("input",{type:"number",min:"0",step:"1",value:l,onChange:k=>c(k.target.value)})]}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Double doors"}),(0,K.jsx)("input",{type:"number",min:"0",step:"1",value:p,onChange:k=>m(k.target.value)})]})]}),(0,K.jsxs)("div",{className:"paint-calculator__coat-field",children:[(0,K.jsx)("p",{className:"paint-calculator__hint",children:"Most walls need 2 coats for an even finish. Use 3 coats when changing colour significantly or covering a darker wall."}),(0,K.jsxs)("label",{className:"truss-estimator__field",children:[(0,K.jsx)("span",{children:"Number of coats"}),(0,K.jsxs)("select",{value:g,onChange:k=>d(Number(k.target.value)),children:[(0,K.jsx)("option",{value:"1",children:"1 coat"}),(0,K.jsx)("option",{value:"2",children:"2 coats"}),(0,K.jsx)("option",{value:"3",children:"3 coats"})]})]})]})]}),(0,K.jsxs)("div",{className:"paint-calculator__totals",children:[(0,K.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,K.jsxs)("div",{className:"paint-calculator__result-grid",children:[(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Paintable area"}),(0,K.jsxs)("strong",{children:[O.toFixed(2)," m\xB2"]})]}),(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Coverage"}),(0,K.jsxs)("strong",{children:[g," ",g===1?"coat":"coats"]})]}),(0,K.jsxs)("div",{children:[(0,K.jsx)("span",{children:"Paint required"}),(0,K.jsxs)("strong",{children:[f.toFixed(1)," litres"]})]})]}),(0,K.jsx)("p",{className:"paint-calculator__note",children:h?"Based on paint coverage of 10 m\xB2 per litre. Ordered as brilliant white matt emulsion, rounded up to whole tins.":"Based on paint coverage of 10 m\xB2 per litre. Decorative paint is not currently stocked in this catalogue, so this remains an estimate only."})]}),(0,K.jsxs)("div",{className:"paint-calculator__actions",children:[(0,K.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),h?(0,K.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.([u]),disabled:f<=0,children:a}):(0,K.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",disabled:!0,children:"Paint products unavailable"})]})]})]})})}var fr=X(je()),te=X(ee()),vc=e=>Number.parseFloat(e)||0,Pd={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 Jd({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,fr.useState)("paving"),[n,o]=(0,fr.useState)("council"),[l,c]=(0,fr.useState)(""),[p,m]=(0,fr.useState)(""),[g,d]=(0,fr.useState)("100"),[b,_]=(0,fr.useState)("50"),[M,O]=(0,fr.useState)(!0),[f,u]=(0,fr.useState)(!0),h=vc(l)*vc(p),w=h,k=h*(vc(g)/1e3),R=h*.04,z=h*(vc(b)/1e3),U=Math.ceil(w/.36),A=Math.ceil(w/.1),j=Math.ceil(k*1700/800),ie=Math.ceil(R*1600/800),qe=Math.ceil(z*1600/800),Ke=r==="paving"?{qty:U,unit:"each"}:r==="block"?{qty:w,unit:"m2"}:{qty:qe,unit:"bag"},Oe={paving:"paving slab",block:"block paver",gravel:"decorative gravel"}[r],Me=[{key:`surface-${n}`,label:Pd[r].find(le=>le.id===n)?.label??"Surface material",qty:Ke.qty,unit:Ke.unit,query:Oe,category:"landscaping"},...M?[{key:"sub-base",label:"MOT Type 1 sub-base",qty:j,unit:"bag",query:"MOT Type 1 sub base",category:"aggregate"}]:[],...f?[{key:"bedding",label:"Sharp sand bedding",qty:ie,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(([le,Ve,Te])=>(0,te.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===le?" is-selected":""}`,onClick:()=>{i(le),o(Pd[le][0].id)},children:[(0,te.jsx)("div",{className:"truss-estimator__option-title",children:Ve}),(0,te.jsx)("div",{className:"truss-estimator__option-copy",children:Te})]},le))}),(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:le=>o(le.target.value),children:Pd[r].map(le=>(0,te.jsx)("option",{value:le.id,children:le.label},le.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:le=>c(le.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:le=>m(le.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:le=>_(le.target.value)})]}),M&&(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:le=>d(le.target.value)})]}),(0,te.jsxs)("label",{className:"brick-calculator__checkbox materials-calculator__waste",children:[(0,te.jsx)("input",{type:"checkbox",checked:M,onChange:le=>O(le.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:le=>u(le.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:[h.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"?`${U} slabs`:r==="block"?`${w.toFixed(2)} m\xB2`:`${qe} bulk bags`})]}),M&&(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"MOT Type 1"}),(0,te.jsxs)("strong",{children:[j," bulk bags"]})]}),f&&(0,te.jsxs)("div",{children:[(0,te.jsx)("span",{children:"Sharp sand"}),(0,te.jsxs)("strong",{children:[ie," 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?.(Me),disabled:h<=0,children:a})]})]})]})})}var ul=X(je()),re=X(ee()),gx=2.88,Vv=[{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"}],Xv=()=>({length:"",height:""}),Fd=e=>Number.parseFloat(e)||0;function Id({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,ul.useState)([Xv()]),[n,o]=(0,ul.useState)(""),[l,c]=(0,ul.useState)("standard"),[p,m]=(0,ul.useState)("screws"),g=r.reduce((R,z)=>R+Fd(z.length)*Fd(z.height),0),d=Math.max(0,g-Fd(n)),b=Math.ceil(d/gx),_=Math.ceil(d*12),M=Math.ceil(_/1e3),O=Math.ceil(d*1.2),f=Math.ceil(O/90),u=Math.ceil(d/3.5),h=Vv.find(R=>R.id===l)?.label??"Standard",w=[{key:"board",label:`${h} plasterboard`,qty:b,unit:"sheet",query:`${h} plasterboard`,category:"plasterboard"},...p==="screws"?[{key:"screws",label:"Drywall screws",qty:M,unit:"box",query:"drywall screws",category:"fixings"}]:[{key:"adhesive",label:"Board adhesive",qty:u,unit:"bag",query:"drywall board adhesive",category:"plasterboard"}],{key:"tape",label:"Joint tape",qty:f,unit:"roll",query:"plasterboard joint tape",category:"plasterboard"}],k=(R,z,U)=>{i(A=>A.map((j,ie)=>ie===R?{...j,[z]:U}:j))};return(0,re.jsx)(re.Fragment,{children:(0,re.jsxs)("div",{className:"truss-estimator",children:[(0,re.jsxs)("div",{className:"quick-order-hero",children:[(0,re.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,re.jsx)("h1",{children:"Plasterboard and Drylining Calculator"}),(0,re.jsx)("p",{children:"Estimate boards, fixings and jointing materials for walls and ceilings."})]}),(0,re.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,re.jsx)("h2",{className:"truss-estimator__step-title",children:"Boards, fixings and jointing"}),(0,re.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,re.jsxs)("div",{className:"materials-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Board type"}),(0,re.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:Vv.map(R=>(0,re.jsxs)("button",{type:"button",className:`truss-estimator__option-card${l===R.id?" is-selected":""}`,onClick:()=>c(R.id),children:[(0,re.jsx)("div",{className:"truss-estimator__option-title",children:R.label}),(0,re.jsx)("div",{className:"truss-estimator__option-copy",children:R.blurb})]},R.id))})]}),(0,re.jsxs)("div",{className:"materials-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Fixing method"}),(0,re.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,U])=>(0,re.jsxs)("button",{type:"button",className:`truss-estimator__option-card${p===R?" is-selected":""}`,onClick:()=>m(R),children:[(0,re.jsx)("div",{className:"truss-estimator__option-title",children:z}),(0,re.jsx)("div",{className:"truss-estimator__option-copy",children:U})]},R))})]}),(0,re.jsxs)("div",{className:"materials-calculator__section",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Wall and ceiling areas"}),(0,re.jsx)("p",{className:"materials-calculator__hint",children:"Add each surface separately so different wall sizes are easy to measure."}),(0,re.jsxs)("div",{className:"materials-calculator__dimensions-header",children:[(0,re.jsx)("span",{children:"Surface"}),(0,re.jsx)("span",{children:"Length (m)"}),(0,re.jsx)("span",{children:"Height (m)"}),(0,re.jsx)("span",{})]}),r.map((R,z)=>(0,re.jsxs)("div",{className:"materials-calculator__surface-row",children:[(0,re.jsxs)("span",{children:["Surface ",z+1]}),(0,re.jsx)("input",{"aria-label":`Surface ${z+1} length`,type:"number",min:"0",step:"0.01",value:R.length,onChange:U=>k(z,"length",U.target.value)}),(0,re.jsx)("input",{"aria-label":`Surface ${z+1} height`,type:"number",min:"0",step:"0.01",value:R.height,onChange:U=>k(z,"height",U.target.value)}),r.length>1?(0,re.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>i(U=>U.filter((A,j)=>j!==z)),children:"Remove"}):null]},`surface-${z}`)),(0,re.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>i(R=>[...R,Xv()]),children:"+ Add another surface"}),(0,re.jsxs)("label",{className:"truss-estimator__field materials-calculator__openings",children:[(0,re.jsxs)("span",{children:["Openings to deduct (m\xB2) ",(0,re.jsx)("small",{children:"optional"})]}),(0,re.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:R=>o(R.target.value)})]})]}),(0,re.jsxs)("div",{className:"materials-calculator__totals",children:[(0,re.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,re.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Board area"}),(0,re.jsxs)("strong",{children:[d.toFixed(2)," m\xB2"]})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"2.4 x 1.2 m boards"}),(0,re.jsx)("strong",{children:b})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:p==="screws"?"Drywall screws":"Board adhesive"}),(0,re.jsx)("strong",{children:p==="screws"?`${_} (${M} boxes)`:`${u} bags`})]}),(0,re.jsxs)("div",{children:[(0,re.jsx)("span",{children:"Joint tape"}),(0,re.jsxs)("strong",{children:[O," m (",f," rolls)"]})]})]}),(0,re.jsx)("p",{className:"materials-calculator__note",children:"Figures are estimates. Confirm board specification, fixing patterns and fire or acoustic requirements before ordering."})]}),(0,re.jsxs)("div",{className:"materials-calculator__actions",children:[(0,re.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,re.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(w),disabled:d<=0,children:a})]})]})]})})}var pl=X(je());var v=X(ee()),Ut={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}}}},yc=["range","pitchAndDimensions","quantityAndGirders","bracing"],bx={range:null,pitch:null,spanMM:"",overhangMM:"",roofLengthM:"",centres:null,girderCount:0,bracing:null,treatment:null,contact:{name:"",email:""}};function wx({degrees:e}){let a=e*Math.PI/180,i=82-Math.min(58,38*Math.tan(a));return(0,v.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,v.jsx)("line",{x1:"6",y1:"82",x2:"94",y2:"82",stroke:"var(--border)",strokeWidth:"2"}),(0,v.jsx)("polygon",{points:`12,82 88,82 50,${i}`,fill:"var(--accent-light)",stroke:"var(--accent)",strokeWidth:"3",strokeLinejoin:"round"})]})}function vx({type:e}){let t="#b3835a",a="#5c3b22",r="#d9b48f",i="#d3d8de",n="#7c8494",o=(m,g,d,b,_=8,M)=>{let O=d-m,f=b-g,u=Math.hypot(O,f)||1,h=-f/u,w=O/u,k=_*.2;return(0,v.jsxs)("g",{children:[(0,v.jsx)("line",{x1:m,y1:g,x2:d,y2:b,stroke:a,strokeWidth:_+3,strokeLinecap:"square"}),(0,v.jsx)("line",{x1:m,y1:g,x2:d,y2:b,stroke:t,strokeWidth:_,strokeLinecap:"square"}),(0,v.jsx)("line",{x1:m-h*k,y1:g-w*k,x2:d-h*k,y2:b-w*k,stroke:r,strokeWidth:Math.max(1.5,_*.24),strokeLinecap:"round",opacity:"0.9"})]},M)},l=(m,g,d)=>(0,v.jsxs)("g",{children:[(0,v.jsx)("rect",{x:m-7.5,y:g-5.5,width:"15",height:"11",rx:"2",fill:i,stroke:n,strokeWidth:"1"}),(0,v.jsx)("circle",{cx:m-4,cy:g-2.5,r:"1",fill:n}),(0,v.jsx)("circle",{cx:m+4,cy:g-2.5,r:"1",fill:n}),(0,v.jsx)("circle",{cx:m-4,cy:g+2.5,r:"1",fill:n}),(0,v.jsx)("circle",{cx:m+4,cy:g+2.5,r:"1",fill:n}),(0,v.jsx)("circle",{cx:m,cy:g,r:"1",fill:n})]},d),c=(m,g)=>(0,v.jsx)("rect",{x:m-9,y:"110",width:"18",height:"10",fill:a},g),p=(0,v.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"});return e==="attic"?(0,v.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,v.jsx)("rect",{x:"90",y:"82",width:"20",height:"24",fill:"#cfe3f2",stroke:a,strokeWidth:"2"}),(0,v.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,v.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,v.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,v.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 yx({enabled:e}){return(0,v.jsxs)("svg",{viewBox:"0 0 200 130",className:"truss-estimator__diagram","aria-hidden":"true",children:[(0,v.jsx)("line",{x1:"6",y1:"122",x2:"194",y2:"122",stroke:"var(--border)",strokeWidth:"2"}),(0,v.jsx)("rect",{x:"17",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,v.jsx)("rect",{x:"165",y:"110",width:"18",height:"10",fill:"#5c3b22"}),(0,v.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,v.jsx)("line",{x1:"26",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,v.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,v.jsx)("line",{x1:"174",y1:"112",x2:"100",y2:"34",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),(0,v.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#5c3b22",strokeWidth:"11",strokeLinecap:"square"}),(0,v.jsx)("line",{x1:"26",y1:"112",x2:"174",y2:"112",stroke:"#b3835a",strokeWidth:"8",strokeLinecap:"square"}),e?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("line",{x1:"45",y1:"112",x2:"140",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"}),(0,v.jsx)("line",{x1:"155",y1:"112",x2:"60",y2:"88",stroke:"var(--accent)",strokeWidth:"3",strokeLinecap:"round",strokeDasharray:"7 5"})]}):null,(0,v.jsx)("rect",{x:"18.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,v.jsx)("rect",{x:"166.5",y:"106.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"}),(0,v.jsx)("rect",{x:"92.5",y:"28.5",width:"15",height:"11",rx:"2",fill:"#d3d8de",stroke:"#7c8494",strokeWidth:"1"})]})}function Zv({treated:e}){let t=e?"#5a7a4a":"var(--accent)";return(0,v.jsxs)("svg",{viewBox:"0 0 100 100",className:"truss-estimator__diagram truss-estimator__diagram--small","aria-hidden":"true",children:[(0,v.jsx)("rect",{x:"10",y:"22",width:"80",height:"14",rx:"2",fill:t}),(0,v.jsx)("rect",{x:"10",y:"43",width:"80",height:"14",rx:"2",fill:e?"#8faf7a":"var(--accent-light)"}),(0,v.jsx)("rect",{x:"10",y:"64",width:"80",height:"14",rx:"2",fill:t})]})}function Wd({onBack:e}){let[t,a]=(0,pl.useState)(0),[r,i]=(0,pl.useState)(bx),[n,o]=(0,pl.useState)(!1),[l,c]=(0,pl.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?Ut.ranges[r.range]:Ut.ranges.standard,u=r.pitch??"22.5",h=Ut.pitchMultipliers[u],w=(Number.parseFloat(r.spanMM)||0)/1e3,R=(Number.parseFloat(r.overhangMM)||0)>Ut.overhang.thresholdMM,z=p(),U=z+r.girderCount,A=Number.parseFloat(r.roofLengthM)||0,j=r.treatment?Ut.treatment[r.treatment]:Ut.treatment.untreated,ie=Ut.estimate.ranges[r.range??"standard"],qe=ie.supplyAt8m*Math.max(.7,w/8)*h*(1+j.surchargePct)+(R?Ut.overhang.surchargePerTruss:0),Ke=z*qe,Oe=r.girderCount*qe*Ut.estimate.girderMultiplier,Me=r.bracing==="yes"?A*Ut.estimate.bracingPerMetre:0,ge=Ke+Oe+Me+Ut.estimate.delivery,le=Ut.estimate.design+z*ie.installPerTruss+r.girderCount*40,Ve=ge+le,Te=Ve*.2;return{range:f,count:z,girderCount:r.girderCount,overhangApplies:R,overhangUnits:U,roofLengthM:A,treatment:j,trussSupply:Ke,bracingMaterials:Me,delivery:Ut.estimate.delivery,labour:le,subtotal:Ve,vat:Te,total:Ve+Te}})(),d=()=>{let f=yc[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===yc.length-1?"View truss request":"Next",_=()=>{n?o(!1):t===0?e():a(f=>f-1)},M=()=>{d()&&(t===yc.length-1?(c(!1),o(!0)):a(f=>f+1))},O=()=>{let f=yc[t];return f==="range"?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Step 1 of 4"}),(0,v.jsx)("h2",{className:"truss-estimator__step-title",children:"Choose your truss range"}),(0,v.jsx)("p",{className:"truss-estimator__step-sub",children:"Pricing shown is placeholder. Swap in your real engineering and pricing catalogue."}),(0,v.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--range",children:Object.entries(Ut.ranges).map(([u,h])=>(0,v.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r.range===u?" is-selected":""}`,onClick:()=>i(w=>({...w,range:u})),children:[(0,v.jsx)(vx,{type:u}),(0,v.jsxs)("div",{className:"truss-estimator__option-info",children:[(0,v.jsx)("div",{className:"truss-estimator__option-title",children:h.label}),(0,v.jsx)("div",{className:"truss-estimator__option-copy",children:h.blurb})]})]},u))})]}):f==="pitchAndDimensions"?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Step 2 of 4"}),(0,v.jsx)("h2",{className:"truss-estimator__step-title",children:"Span, overhang and roof pitch"}),(0,v.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,v.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,v.jsxs)("label",{className:"truss-estimator__field",children:[(0,v.jsx)("span",{children:"Span (mm)"}),(0,v.jsx)("input",{type:"text",inputMode:"numeric",value:r.spanMM,onChange:u=>i(h=>({...h,spanMM:u.target.value}))})]}),(0,v.jsxs)("label",{className:"truss-estimator__field",children:[(0,v.jsx)("span",{children:"Overhang (mm)"}),(0,v.jsx)("input",{type:"text",inputMode:"numeric",value:r.overhangMM,onChange:u=>i(h=>({...h,overhangMM:u.target.value}))}),(0,v.jsxs)("small",{children:["Overhangs beyond ",Ut.overhang.thresholdMM,"mm add a small surcharge per truss."]})]})]}),(0,v.jsx)("div",{className:"truss-estimator__section-heading",children:"Roof pitch"}),(0,v.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--pitch",children:Ut.pitches.map(u=>(0,v.jsxs)("button",{type:"button",className:`truss-estimator__visual-card${r.pitch===u?" is-selected":""}`,onClick:()=>i(h=>({...h,pitch:u})),children:[(0,v.jsx)(wx,{degrees:Number.parseFloat(u)}),(0,v.jsxs)("span",{children:[u,"\xB0"]})]},u))})]}):f==="quantityAndGirders"?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Step 3 of 4"}),(0,v.jsx)("h2",{className:"truss-estimator__step-title",children:"Roof length"}),(0,v.jsx)("p",{className:"truss-estimator__step-sub",children:"Trusses are based on designs at 400mm or 600mm centres wherever possible."}),(0,v.jsxs)("label",{className:"truss-estimator__field truss-estimator__field--compact",children:[(0,v.jsx)("span",{children:"Roof length (m)"}),(0,v.jsx)("input",{type:"text",inputMode:"decimal",value:r.roofLengthM,onChange:u=>i(h=>({...h,roofLengthM:u.target.value}))})]}),(0,v.jsx)("div",{className:"truss-estimator__section-heading",children:"Truss centres"}),(0,v.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--centres",children:Ut.centresOptions.map(u=>(0,v.jsx)("button",{type:"button",className:`truss-estimator__option-card truss-estimator__option-card--compact${r.centres===u?" is-selected":""}`,onClick:()=>i(h=>({...h,centres:u})),children:(0,v.jsxs)("div",{className:"truss-estimator__option-title",children:[u,"mm centres"]})},u))}),(0,v.jsxs)("div",{className:"truss-estimator__stat",children:[p()," trusses estimated"]}),(0,v.jsx)("div",{className:"truss-estimator__section-heading",children:"Girder trusses"}),(0,v.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,v.jsxs)("div",{className:"truss-estimator__stepper",children:[(0,v.jsx)("button",{type:"button",onClick:()=>i(u=>({...u,girderCount:Math.max(0,u.girderCount-1)})),children:"\u2212"}),(0,v.jsx)("span",{children:r.girderCount}),(0,v.jsx)("button",{type:"button",onClick:()=>i(u=>({...u,girderCount:Math.min(3,u.girderCount+1)})),children:"+"})]})]}):f==="bracing"?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Step 4 of 4"}),(0,v.jsx)("h2",{className:"truss-estimator__step-title",children:"Bracing pack?"}),(0,v.jsx)("p",{className:"truss-estimator__step-sub",children:"A timber bracing pack stabilises the roof structure once trusses are erected."}),(0,v.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,v.jsxs)("button",{type:"button",className:`truss-estimator__visual-card truss-estimator__visual-card--wide${r.bracing===u.id?" is-selected":""}`,onClick:()=>i(h=>({...h,bracing:u.id})),children:[(0,v.jsx)(yx,{enabled:u.id==="yes"}),(0,v.jsx)("span",{children:u.label})]},u.id))}),(0,v.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber treatment"}),(0,v.jsx)("p",{className:"truss-estimator__step-sub",children:"Tanalised timber protects against rot in exposed or damp locations."}),(0,v.jsxs)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--two",children:[(0,v.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,v.jsx)(Zv,{treated:!1}),(0,v.jsx)("span",{children:"Untreated"})]}),(0,v.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,v.jsx)(Zv,{treated:!0}),(0,v.jsx)("span",{children:"Treated (+8% cost)"}),(0,v.jsx)("small",{children:"Applies to trusses, girders and overhang"})]})]})]}):null};return n?(0,v.jsx)(v.Fragment,{children:(0,v.jsxs)("div",{className:"truss-estimator",children:[(0,v.jsxs)("div",{className:"quick-order-hero",children:[(0,v.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,v.jsx)("h1",{children:"Your truss estimate"}),(0,v.jsx)("p",{children:"A provisional quantity and specification based on the dimensions you entered."})]}),(0,v.jsxs)("div",{className:"truss-estimator__card truss-request",style:{minHeight:0},children:[(0,v.jsxs)("div",{className:"truss-request__heading",children:[(0,v.jsxs)("div",{children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Estimated requirement"}),(0,v.jsxs)("h2",{children:[g.range.label," roof trusses"]})]}),(0,v.jsxs)("strong",{children:[g.count,(0,v.jsx)("span",{children:"trusses"})]})]}),(0,v.jsxs)("div",{className:"truss-request__grid",children:[(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Span"}),(0,v.jsxs)("strong",{children:[r.spanMM," mm"]})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Roof length"}),(0,v.jsxs)("strong",{children:[r.roofLengthM," m"]})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Pitch"}),(0,v.jsxs)("strong",{children:[r.pitch,"\xB0"]})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Centres"}),(0,v.jsxs)("strong",{children:[r.centres," mm"]})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Overhang"}),(0,v.jsxs)("strong",{children:[r.overhangMM," mm"]})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Treatment"}),(0,v.jsx)("strong",{children:g.treatment.label})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Girder trusses"}),(0,v.jsx)("strong",{children:g.girderCount||"None"})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Bracing pack"}),(0,v.jsx)("strong",{children:r.bracing==="yes"?"Included":"Not included"})]})]}),(0,v.jsxs)("div",{className:"truss-request__price",children:[(0,v.jsx)("div",{className:"truss-estimator__step-label",children:"Indicative cost estimate"}),(0,v.jsxs)("div",{className:"truss-request__price-grid",children:[(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Truss supply allowance"}),(0,v.jsx)("strong",{children:ot(g.trussSupply)})]}),g.bracingMaterials>0&&(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Bracing materials allowance"}),(0,v.jsx)("strong",{children:ot(g.bracingMaterials)})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Delivery allowance"}),(0,v.jsx)("strong",{children:ot(g.delivery)})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Design and installation labour"}),(0,v.jsx)("strong",{children:ot(g.labour)})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"Subtotal (ex. VAT)"}),(0,v.jsx)("strong",{children:ot(g.subtotal)})]}),(0,v.jsxs)("div",{children:[(0,v.jsx)("span",{children:"VAT (20%)"}),(0,v.jsx)("strong",{children:ot(g.vat)})]}),(0,v.jsxs)("div",{className:"truss-request__price-total",children:[(0,v.jsx)("span",{children:"Estimated total"}),(0,v.jsx)("strong",{children:ot(g.total)})]})]}),(0,v.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,v.jsxs)("div",{className:"truss-request__notice",children:[(0,v.jsx)("strong",{children:"Before ordering"}),(0,v.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,v.jsxs)("div",{className:"truss-estimator__nav",children:[(0,v.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:_,children:"Back to calculator"}),(0,v.jsx)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",justifyContent:"center",marginTop:0},onClick:()=>c(!0),children:"Request order"})]}),l&&(0,v.jsx)("p",{className:"truss-request__demo",children:"Demo only \u2014 no order has been sent."})]})]})}):(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:"Roof Truss Calculator"}),(0,v.jsx)("p",{children:"Estimate trusses, girders and cost for your roof in a few steps."})]}),(0,v.jsxs)("div",{className:"truss-estimator__card",children:[(0,v.jsx)("div",{className:"truss-estimator__body",children:O()}),(0,v.jsxs)("div",{className:"truss-estimator__nav",children:[(0,v.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary",style:{flex:"0 1 30%",justifyContent:"center",marginTop:0},onClick:_,children:"Back"}),(0,v.jsxs)("button",{type:"button",className:"cta-btn",style:{flex:"0 1 70%",marginTop:0},onClick:M,disabled:!d(),children:[(0,v.jsx)("span",{children:b}),(0,v.jsx)("span",{className:"arrow",children:(0,v.jsx)(jt,{})})]})]})]})]})})}var Ni=X(je()),F=X(ee()),Jv=e=>Number.parseFloat(e)||0,_c=(e,t)=>Jv(e)*(t==="m"?1:.3048),Kv=()=>({length:"",width:""}),Pv=[{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 _x({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 em({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Ni.useState)("total"),[n,o]=(0,Ni.useState)("m"),[l,c]=(0,Ni.useState)(""),[p,m]=(0,Ni.useState)([Kv()]),[g,d]=(0,Ni.useState)(""),[b,_]=(0,Ni.useState)("chamfered"),M="4.4",O=r==="total"?_c(l,n):p.reduce((k,R)=>k+2*(_c(R.length,n)+_c(R.width,n)),0),f=Math.max(0,O-_c(g,n)),u=Math.ceil(f/Jv(M)),h=[{key:`skirting-${b}`,label:`${Pv.find(k=>k.id===b)?.label} skirting board`,qty:f,unit:"m",query:"skirting board",category:"skirting"}],w=(k,R,z)=>{m(U=>U.map((A,j)=>j===k?{...A,[R]:z}:A))};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:k=>c(k.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((k,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:k.length,onChange:z=>w(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:k.width,onChange:z=>w(R,"width",z.target.value)}),p.length>1?(0,F.jsx)("button",{type:"button",className:"paint-calculator__remove",onClick:()=>m(z=>z.filter((U,A)=>A!==R)),children:"Remove"}):null]},`room-${R}`)),(0,F.jsx)("button",{type:"button",className:"paint-calculator__add",onClick:()=>m(k=>[...k,Kv()]),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:k=>d(k.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:Pv.map(k=>(0,F.jsxs)("button",{type:"button",className:`truss-estimator__option-card${b===k.id?" is-selected":""}`,onClick:()=>_(k.id),children:[(0,F.jsx)(_x,{profile:k.id}),(0,F.jsx)("div",{className:"truss-estimator__option-title",children:k.label}),(0,F.jsx)("div",{className:"truss-estimator__option-copy",children:k.blurb})]},k.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?.(h),disabled:f<=0,children:a})]})]})]})})}var Yn=X(je()),oe=X(ee()),dl=e=>Number.parseFloat(e)||0;function tm({onBack:e,onReview:t,submitLabel:a="Add to basket"}){let[r,i]=(0,Yn.useState)("studs"),[n,o]=(0,Yn.useState)(""),[l,c]=(0,Yn.useState)(""),[p,m]=(0,Yn.useState)("600"),[g,d]=(0,Yn.useState)("2.4"),b=n&&l&&p?Math.ceil(dl(l)/(dl(p)/1e3))+1:0,_=b*dl(n),M=dl(g)>0?Math.ceil(_/dl(g)):0,O=[{key:r,label:{studs:"Stud timber",joists:"Joist timber",battens:"Batten timber"}[r],qty:_,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"]},h={studs:{member:"Wall height",overall:"Wall length",help:"Studs repeat across the wall length.",count:"Studs"},joists:{member:"Joist span",overall:"Overall width",help:"Joists repeat across the overall floor or deck width.",count:"Joists"},battens:{member:"Batten length",overall:"Overall width",help:"Battens repeat across the overall lining or cladding width.",count:"Battens"}}[r];return(0,oe.jsx)(oe.Fragment,{children:(0,oe.jsxs)("div",{className:"truss-estimator",children:[(0,oe.jsxs)("div",{className:"quick-order-hero",children:[(0,oe.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,oe.jsx)("h1",{children:"Timber Calculator"}),(0,oe.jsx)("p",{children:"Estimate studs, joists or battens from a run length, width and spacing."})]}),(0,oe.jsxs)("div",{className:"truss-estimator__card materials-calculator",children:[(0,oe.jsx)("h2",{className:"truss-estimator__step-title",children:"Member size and spacing"}),(0,oe.jsxs)("p",{className:"truss-estimator__step-sub",children:[h.help," Enter the member length and centres to estimate the number of pieces and stock lengths."]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Timber use"}),(0,oe.jsx)("div",{className:"truss-estimator__option-grid truss-estimator__option-grid--three",children:Object.keys(f).map(w=>(0,oe.jsxs)("button",{type:"button",className:`truss-estimator__option-card${r===w?" is-selected":""}`,onClick:()=>i(w),children:[(0,oe.jsx)("div",{className:"truss-estimator__option-title",children:f[w][0]}),(0,oe.jsx)("div",{className:"truss-estimator__option-copy",children:f[w][1]})]},w))})]}),(0,oe.jsxs)("div",{className:"materials-calculator__section",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Dimensions and spacing"}),(0,oe.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsxs)("span",{children:[h.member," (m)"]}),(0,oe.jsx)("input",{type:"number",min:"0",step:"0.01",value:n,onChange:w=>o(w.target.value)})]}),(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsxs)("span",{children:[h.overall," (m)"]}),(0,oe.jsx)("input",{type:"number",min:"0",step:"0.01",value:l,onChange:w=>c(w.target.value)})]})]}),(0,oe.jsxs)("div",{className:"truss-estimator__field-grid",children:[(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsx)("span",{children:"Centres (mm)"}),(0,oe.jsxs)("select",{value:p,onChange:w=>m(w.target.value),children:[(0,oe.jsx)("option",{value:"300",children:"300 mm"}),(0,oe.jsx)("option",{value:"400",children:"400 mm"}),(0,oe.jsx)("option",{value:"450",children:"450 mm"}),(0,oe.jsx)("option",{value:"600",children:"600 mm"})]})]}),(0,oe.jsxs)("label",{className:"truss-estimator__field",children:[(0,oe.jsx)("span",{children:"Stock length (m)"}),(0,oe.jsxs)("select",{value:g,onChange:w=>d(w.target.value),children:[(0,oe.jsx)("option",{value:"2.4",children:"2.40 m"}),(0,oe.jsx)("option",{value:"3.6",children:"3.60 m"}),(0,oe.jsx)("option",{value:"4.8",children:"4.80 m"})]})]})]})]}),(0,oe.jsxs)("div",{className:"materials-calculator__totals",children:[(0,oe.jsx)("div",{className:"truss-estimator__section-heading",children:"Totals"}),(0,oe.jsxs)("div",{className:"materials-calculator__result-grid",children:[(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:h.count}),(0,oe.jsx)("strong",{children:b})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsx)("span",{children:"Linear metres"}),(0,oe.jsxs)("strong",{children:[_.toFixed(2)," m"]})]}),(0,oe.jsxs)("div",{children:[(0,oe.jsxs)("span",{children:[g," m lengths"]}),(0,oe.jsx)("strong",{children:M})]})]}),(0,oe.jsx)("p",{className:"materials-calculator__note",children:"Spacing is measured centre-to-centre. Add extra timber for plates, noggins, trimming and openings where required."})]}),(0,oe.jsxs)("div",{className:"materials-calculator__actions",children:[(0,oe.jsx)("button",{type:"button",className:"cta-btn cta-btn-secondary estimator-actions__back",onClick:e,children:"Back"}),(0,oe.jsx)("button",{type:"button",className:"cta-btn estimator-actions__calculate",onClick:()=>t?.(O),disabled:_<=0,children:a})]})]})]})})}var am=[{id:"truss",title:"Roof Truss Calculator",desc:"Estimate trusses, girders and roof structure costs.",imageUrl:"/tool-images/truss.webp",Component:Wd},{id:"fencing",title:"Fencing Calculator",desc:"Estimate fence panels, posts, gravel boards and fixings.",imageUrl:"/tool-images/fencing.webp",Component:Xd},{id:"decking",title:"Decking Calculator",desc:"Estimate boards, substructure and fixing quantities.",imageUrl:"/tool-images/decking.webp",Component:$d},{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:jd},{id:"paint",title:"Paint Calculator",desc:"Estimate paint for walls, doors and multiple coats.",imageUrl:"/tool-images/paint.webp",Component:Kd},{id:"skirting",title:"Skirting Board Calculator",desc:"Estimate skirting lengths for rooms and wall runs.",imageUrl:"/tool-images/skirting.webp",Component:em},{id:"architrave",title:"Architrave Calculator",desc:"Estimate architrave lengths for door and window openings.",imageUrl:"/tool-images/architrave.webp",Component:Hd},{id:"concrete-aggregate",title:"Concrete and Aggregate Calculator",desc:"Estimate concrete, MOT, sand and gravel quantities.",imageUrl:"/tool-images/concrete-aggregate.webp",Component:Gd},{id:"plasterboard",title:"Plasterboard Calculator",desc:"Estimate plasterboard sheets, screws, tape and adhesive.",imageUrl:"/tool-images/plasterboard.webp",Component:Id},{id:"insulation",title:"Insulation Calculator",desc:"Estimate insulation packs for floors, walls, roofs and lofts.",imageUrl:"/tool-images/insulation.webp",Component:Zd},{id:"timber",title:"Timber Calculator",desc:"Estimate studs, joists and battens from spacing and lengths.",imageUrl:"/tool-images/timber.webp",Component:tm},{id:"paving",title:"Paving and Driveway Calculator",desc:"Estimate paving, block paving, MOT and sharp sand.",imageUrl:"/tool-images/paving.webp",Component:Jd}];var kc=X(je());var He=X(je());var xx=new Set(["bag","box","roll","pack"]),kx=new Set(["each","bag","box","roll","pack","tub"]);function ml(e,t){let r=(t?.conversion?.request_uoms_supported??"").split(",").map(o=>o.trim().toLowerCase()).includes("sales_unit");if(e==="each"){let o=(t?.uoi_count??1)===1&&(t?.conversion?.sales_unit_size??1)===1;return r&&o?"sales_unit":e}if(!xx.has(e))return e;if(r)return"sales_unit";let i=t?.uoi;return i!=null&&kx.has(i.toLowerCase())&&(t?.uoi_count??1)===1?i:e}var Fv=new Map;function Sx(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 Ci(e,t,a=12,r){let i=`${Ot().client??""}||${e}||${t??""}||${a}||${r??""}`,n=Fv.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(za(`/api/catalogue/search?${o.toString()}`),{headers:hi()}),c=await Qa(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(Sx):[];return Fv.set(i,p),p}async function Iv(e,t,a){return await Promise.all(e.map(async i=>{try{let n=a?cl(a,i):null,[o,l]=await Promise.all([n?Ci(n,void 0,void 0,t).then(p=>p.find(m=>m.product_id===n.split(" ")[0]),()=>{}):void 0,Ci(i.query,i.category,void 0,t)]),c=o?[o,...l.filter(p=>p.product_id!==o.product_id)]:l;return{requirement:i,candidates:c}}catch{return{requirement:i,candidates:[]}}}))}async function Wv(){let e=await fetch(za("/api/catalogue"),{headers:hi()});if(!e.ok)return{itemCount:0,uploadedAt:null};let t=await Qa(e);return{itemCount:Number(t?.itemCount)||0,uploadedAt:t?.uploadedAt??null}}var C=X(ee()),Nx=[{dir:"asc",label:"Description (A-Z)"},{dir:"desc",label:"Description (Z-A)"}],rm={wasteFactorEnabled:!0},Cx=3e3,e0=null;function xc(e,t){let a=al(t);return a?`${e.toFixed(2)} ${a}`:e.toFixed(2)}function qx(e){return e&&e.length>0?e.join(" x "):"-"}function im({toolId:e,requirements:t,ready:a,onBack:r,onTotalChange:i}){let n=Nv(),o=`${e}~${t.map(N=>`${N.key}|${N.query}|${N.category??""}|${N.qty}`).join("~")}`,l=o!==e0,[c,p]=(0,He.useState)(null),[m,g]=(0,He.useState)([]),[d,b]=(0,He.useState)(l),[_,M]=(0,He.useState)(null),[O,f]=(0,He.useState)("tile"),[u,h]=(0,He.useState)(null),[w,k]=(0,He.useState)(""),[R,z]=(0,He.useState)(null),[U,A]=(0,He.useState)(""),[j,ie]=(0,He.useState)([]),[qe,Ke]=(0,He.useState)(new Set),[Oe,Me]=(0,He.useState)(null),[ge,le]=(0,He.useState)(""),[Ve,Te]=(0,He.useState)([]),ct=(0,He.useRef)(null),Z=(0,He.useRef)(!1),be=N=>`${e}:${N}`,Re=N=>zn(N.chosen,{lineId:be(N.requirement.key),description:N.requirement.label,unit:ml(N.requirement.unit,N.chosen),qty:N.requirement.qty}),wt=(0,He.useMemo)(()=>t.map(N=>`${N.key}|${N.query}|${N.category??""}`).join("~"),[t]);(0,He.useEffect)(()=>{let N=!1;return Wv().then(L=>{N||p(L.itemCount>0)}).catch(()=>{N||p(!1)}),()=>{N=!0}},[]),(0,He.useEffect)(()=>{if(!a||!c)return;let N=!1,L;l&&b(!0),M(null);let $=Date.now();return(async()=>{let se=null;try{se=(await Iv(t,void 0,e)).map(({requirement:yt,candidates:at})=>({requirement:yt,candidates:at,chosen:at[0]??null}))}catch(ke){N||M(ke instanceof Error?ke.message:"Could not load products")}if(!N){if(e0=o,l){let ke=Cx-(Date.now()-$);ke>0&&await new Promise(yt=>{L=window.setTimeout(yt,ke)})}N||(se&&(g(se),!Z.current&&n&&(Z.current=!0,n.addManyToCart(se.filter(ke=>ke.chosen).map(Re)))),b(!1))}})(),()=>{N=!0,window.clearTimeout(L)}},[a,c,wt]),(0,He.useEffect)(()=>{if(!R)return;let N=U.trim();if(!N){ie([]);return}let L=!1,$=window.setTimeout(()=>{Ci(N).then(se=>{L||ie(se)}).catch(()=>{L||ie([])})},250);return()=>{L=!0,window.clearTimeout($)}},[R,U]),(0,He.useEffect)(()=>{if(!Oe)return;let N=ge.trim();if(!N){Te([]);return}let L=!1,$=window.setTimeout(()=>{Ci(N).then(se=>{L||Te(se)}).catch(()=>{L||Te([])})},250);return()=>{L=!0,window.clearTimeout($)}},[Oe,ge]);let Gt=(0,He.useMemo)(()=>{let N=w.trim().toLowerCase(),L=N?m.filter($=>$.requirement.label.toLowerCase().includes(N)||($.chosen?.description??"").toLowerCase().includes(N)||($.chosen?.product_id??"").toLowerCase().includes(N)):m;return u?[...L].sort(($,se)=>{let ke=$.requirement.label.localeCompare(se.requirement.label);return u==="asc"?ke:-ke}):L},[m,w,u]),Ct=Gt.filter(N=>N.chosen),vt=Gt.filter(N=>!N.chosen),we=m.filter(N=>N.chosen),de=we.filter(N=>N.chosen?.price==null).length,tt=we.reduce((N,L)=>N+(It(Re(L),rm).lineTotal??0),0);if((0,He.useEffect)(()=>{i?.(tt)},[tt,i]),!a||c===!1)return null;let T=n?we.filter(N=>n.cart[be(N.requirement.key)]).length:0,Q=Oe?m.find(N=>N.requirement.key===Oe)??null:null,ue=ge.trim()?Ve:Q?.candidates??[],ve=N=>{let L=R===N.requirement.key;z(L?null:N.requirement.key),A(L?"":N.requirement.query)},Ye=(N,L)=>{let $=m.find(se=>se.requirement.key===N);g(se=>se.map(ke=>ke.requirement.key===N?{...ke,chosen:L}:ke)),n&&$&&n.cart[be(N)]&&n.addToCart(Re({...$,chosen:L})),z(null),A("")},Ce=N=>{g(L=>L.map($=>$.requirement.key===N?{...$,chosen:null}:$)),n?.cart[be(N)]&&n.removeFromCart(be(N))},S=N=>{Me(N.requirement.key),le(""),Te([])},y=()=>{Me(null),le(""),Te([])},E=N=>{if(!n)return;let L=be(N.requirement.key);n.cart[L]?n.removeFromCart(L):n.addToCart(Re(N))},D=N=>{Ke(L=>{let $=new Set(L);return $.has(N)?$.delete(N):$.add(N),$})},V=N=>{let L=j.length>0?j:N.candidates;return(0,C.jsxs)("div",{className:"estimator-products__picker",children:[(0,C.jsx)("input",{type:"text",className:"results-search-input",value:U,autoFocus:!0,placeholder:"Search products in catalogue...",onChange:$=>A($.target.value),"aria-label":`Search a product for ${N.requirement.label}`}),(0,C.jsxs)("div",{className:"estimator-products__options",children:[L.map($=>(0,C.jsxs)("button",{type:"button",className:`estimator-products__option${$.product_id===N.chosen?.product_id?" is-selected":""}`,onClick:()=>Ye(N.requirement.key,$),children:[(0,C.jsx)("span",{children:$.description}),(0,C.jsxs)("span",{className:"results-row-meta",children:[$.product_id,$.price!=null&&` \xB7 ${ot($.price)}`]})]},$.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:[!d&&(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."})]}),!Q&&(0,C.jsx)("div",{className:"results-summary estimator-products__toolbar",children:(0,C.jsxs)("div",{className:"estimator-products__controls",children:[(0,C.jsx)("input",{type:"text",className:"results-search-input",placeholder:"Search description...",value:w,onChange:N=>k(N.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${O==="tile"?" is-active":""}`,"aria-pressed":O==="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${O==="list"?" is-active":""}`,"aria-pressed":O==="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:ct,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(N=>{let L=u===N.dir;return(0,C.jsxs)("button",{type:"button",className:`sort-menu-item${L?" is-active":""}`,onClick:()=>{h(L?null:N.dir),ct.current?.removeAttribute("open")},children:[(0,C.jsx)("span",{className:"sort-menu-item__check",children:L?"\u2713":""}),N.label]},N.dir)})})]})]})})]}),Q&&(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:y,children:[(0,C.jsx)(Vr,{}),"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:ge,onChange:N=>le(N.target.value),"aria-label":`Search a product for ${Q.requirement.label}`})}),Q.chosen&&(0,C.jsx)("div",{className:"results-candidate-actions",children:(0,C.jsx)("button",{type:"button",className:"bom-toolbar-btn",onClick:()=>Ce(Q.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(Q.chosen?.description||Q.requirement.label,Q.chosen?.product_id,Q.chosen?.pdp_photo_url),alt:""})}),(0,C.jsxs)("div",{className:"results-review-page__summary",children:[(0,C.jsx)("h2",{children:Q.requirement.label}),(0,C.jsxs)("p",{className:"results-review-page__meta",children:[wi(Q.requirement.qty)," ",ka(Q.requirement.unit,Q.requirement.qty)]}),Q.chosen?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)("div",{className:"results-review-page__product",children:Q.chosen.description}),(0,C.jsxs)("div",{className:"results-row-meta",children:[Q.chosen.product_id,Q.chosen.price!=null?` \xB7 ${xc(Q.chosen.price,Q.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[be(Q.requirement.key)]?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(Q),disabled:!Q.chosen||!n,children:n?.cart[be(Q.requirement.key)]?"\u2713 Added":"+ Add to basket"})})]})]}),ue.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:ue.map(N=>{let L=N.product_id===Q.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:N.description}),(0,C.jsx)("div",{className:"results-row-meta",children:N.product_id})]}),(0,C.jsx)("td",{children:(0,C.jsx)("span",{className:"unit-badge",children:qx(N.measurements_mm)})}),(0,C.jsx)("td",{children:N.price!=null?xc(N.price,N.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?Ce(Q.requirement.key):Ye(Q.requirement.key,N)},"aria-label":L?`${N.description} selected`:`Use ${N.description}`}),(0,C.jsx)("span",{className:"switch-toggle-track","aria-hidden":"true"})]})})]},N.product_id)})})]})]}),!Q&&d&&(0,C.jsxs)("div",{className:"processing-container processing-variant-banter",role:"status","aria-label":"Loading",style:{padding:"32px 24px"},children:[(0,C.jsx)(gi,{}),(0,C.jsx)("p",{className:"banter-message is-visible",style:{fontSize:15,minHeight:0},children:"Matching your materials against the catalogue\u2026"})]}),!Q&&_&&(0,C.jsx)("p",{className:"results-empty-hint estimator-products__error",children:_}),!Q&&!d&&!_&&Gt.length===0&&m.length>0&&(0,C.jsx)("p",{className:"results-empty-hint",children:"No materials match the current search."}),!Q&&!d&&!_&&O==="tile"&&Ct.length>0&&(0,C.jsx)("div",{className:"results-tile-grid",children:Ct.map(N=>{let{requirement:L,chosen:$}=N,se=$?It(Re(N),rm):null,ke=n?!!n.cart[be(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:()=>S(N),"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($?.description||L.label,$?.product_id,$?.pdp_photo_url),alt:""})}),(0,C.jsxs)("div",{className:"results-tile-card__body",children:[$?(0,C.jsxs)("div",{className:"results-tile-card__heading",children:[(0,C.jsx)("div",{className:"results-tile-card__title",children:$.description}),(0,C.jsxs)("div",{className:"results-tile-card__match-meta",children:[(0,C.jsx)("span",{children:$.product_id}),$.price!=null?(0,C.jsx)("span",{children:xc($.price,$.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:[wi(L.qty)," ",ka(L.unit,L.qty)]}),se?.requiredSellUnits!=null?(0,C.jsxs)("div",{className:"results-tile-card__meta estimator-products__order",children:["Order ",se.requiredSellUnits," ",se.sellUnit,se.lineTotal!=null?` \xB7 ${ot(se.lineTotal)}`:""]}):$?(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:()=>S(N),children:"Review"}),(0,C.jsx)("button",{type:"button",className:`bom-toolbar-btn${ke?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(N),disabled:!$||!n,children:ke?"\u2713 Added":"+ Add"})]})]},L.key)})}),!Q&&!d&&!_&&O==="list"&&Ct.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:Ct.map(N=>{let{requirement:L,chosen:$}=N,se=$?It(Re(N),rm):null,ke=n?!!n.cart[be(L.key)]:!1,yt=qe.has(L.key);return(0,C.jsxs)(He.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:()=>D(L.key),"aria-expanded":yt,"aria-label":yt?"Collapse product options":"Expand product options",children:yt?"\u25BE":"\u25B8"})}),(0,C.jsxs)("td",{style:{paddingLeft:0},children:[(0,C.jsx)("div",{className:"bom-component-name",children:L.label}),se?.requiredSellUnits!=null&&(0,C.jsxs)("div",{className:"results-row-meta",children:["Order ",se.requiredSellUnits," ",se.sellUnit,se.lineTotal!=null?` \xB7 ${ot(se.lineTotal)}`:""]})]}),(0,C.jsx)("td",{className:"bom-qty col-order",style:{textAlign:"center"},children:wi(L.qty)}),(0,C.jsx)("td",{style:{textAlign:"center"},children:ka(L.unit,L.qty)}),(0,C.jsx)("td",{style:{textAlign:"center"},children:$?(0,C.jsxs)(C.Fragment,{children:[(0,C.jsx)("div",{className:"bom-component-name",children:$.description}),(0,C.jsxs)("div",{className:"results-row-meta",children:[$.product_id,$.price!=null&&` \xB7 ${xc($.price,$.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${ke?" bom-toolbar-btn--added":" bom-toolbar-btn--accent"}`,onClick:()=>E(N),disabled:!$||!n,children:ke?"\u2713 Added":"+ Add"})})]}),yt&&(0,C.jsx)("tr",{children:(0,C.jsx)("td",{colSpan:6,style:{paddingLeft:0,paddingRight:0},children:R===L.key?V(N):(0,C.jsxs)("div",{className:"estimator-products__picker",children:[(0,C.jsxs)("div",{className:"estimator-products__options",children:[N.candidates.map(at=>(0,C.jsxs)("button",{type:"button",className:`estimator-products__option${at.product_id===$?.product_id?" is-selected":""}`,onClick:()=>Ye(L.key,at),children:[(0,C.jsx)("span",{children:at.description}),(0,C.jsxs)("span",{className:"results-row-meta",children:[at.product_id,at.price!=null&&` \xB7 ${ot(at.price)}`]})]},at.product_id)),N.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:()=>ve(N),children:"Search the catalogue"})]})})})]},L.key)})})]})}),!Q&&!d&&!_&&vt.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:vt.map(N=>(0,C.jsxs)("button",{type:"button",className:"results-unmatched-card",onClick:()=>S(N),children:[(0,C.jsxs)("span",{className:"results-unmatched-card__main",children:[(0,C.jsx)("span",{className:"results-unmatched-card__title",children:N.requirement.label}),(0,C.jsxs)("span",{className:"results-row-meta",children:[wi(N.requirement.qty)," ",ka(N.requirement.unit,N.requirement.qty)]})]}),(0,C.jsx)("span",{className:"bom-toolbar-btn results-unmatched-card__prompt",children:"Review"})]},N.requirement.key))})]}),!d&&!_&&m.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."})]}),!Q&&!d&&!_&&(r||T>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"}),T>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 (",T,")"]}),(0,C.jsx)("span",{className:"arrow",children:(0,C.jsx)(jt,{})})]})]})]})}var Qt=X(ee());function nm({toolId:e,toolTitle:t,requirements:a,onBack:r}){let[i,n]=(0,kc.useState)(0),o=(0,kc.useCallback)(l=>n(l),[]);return(0,Qt.jsx)(Qt.Fragment,{children:(0,Qt.jsxs)("div",{className:"truss-estimator",children:[(0,Qt.jsxs)("div",{className:"quick-order-hero",children:[(0,Qt.jsx)("div",{className:"quick-order-eyebrow",children:"Estimating Tools"}),(0,Qt.jsxs)("div",{className:"quick-order-hero-title-row",children:[(0,Qt.jsx)("h1",{children:"Your Materials"}),i>0&&(0,Qt.jsxs)("span",{className:"summary-chip summary-chip--scope",children:[(0,Qt.jsx)("strong",{children:ot(i)})," Est. total"]})]}),(0,Qt.jsxs)("p",{children:["Quantities from the ",t,", matched against your merchant\u2019s catalogue."]})]}),(0,Qt.jsx)("div",{className:"truss-estimator__card",style:{minHeight:0},children:(0,Qt.jsx)(im,{toolId:e,requirements:a,ready:!0,onBack:r,onTotalChange:o})})]})})}var om=X(je());var Wt=X(ee()),Ex=1500;function t0(e){let{addManyToCart:t,clearCart:a,openBasket:r}=On(),[i,n]=(0,om.useState)(!1),[o,l]=(0,om.useState)(null);return{adding:i,basketError:o,addToBasket:async(p,m)=>{let g=Date.now();n(!0),l(null);try{let d=await Promise.all(p.filter(_=>_.qty>0).map(async _=>{let M=(await Ci(_.search)).find(O=>O.product_id===_.productId);if(!M)throw new Error("A selected product is no longer available in this catalogue.");return zn(M,{lineId:`${e}:${_.key}`,description:M.description,unit:ml(_.unit??"each",M),qty:_.qty,calculatorWasteIncluded:m})})),b=Ex-(Date.now()-g);b>0&&await new Promise(_=>window.setTimeout(_,b)),a(),t(d),r()}catch(d){l(d instanceof Error?d.message:"Could not add the products to your basket.")}finally{n(!1)}}}}function a0({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)(gi,{}),(0,Wt.jsx)("p",{className:"banter-message is-visible",children:"Preparing your materials\u2026"})]})})]})})}var ze=X(ee());function Sc(e){let[t,a]=(0,$a.useState)(!1);return(0,ze.jsx)(lc,{onOpenBasket:()=>a(!0),children:(0,ze.jsx)(Mx,{...e,showBasket:t,onShowBasket:a})})}function Mx({fullPage:e=!1,hideHeader:t=!1,internal:a=!1,showBasket:r,onShowBasket:i}){let[n,o]=(0,$a.useState)(null),[l,c]=(0,$a.useState)(null),p=am.find(U=>U.id===n),{cart:m,updateCartQty:g,updateCartSellUnits:d,updateCartConversions:b,removeFromCart:_,clearCart:M}=On(),{adding:O,basketError:f,addToBasket:u}=t0(p?.title??"calculator"),h=(0,$a.useRef)(null),w=Zs("estimating-tools",h);(0,$a.useEffect)(()=>{w("viewed")},[w]);let k=r?"basket":O?"adding":l?"review":n??"list",R=(0,$a.useRef)(k);(0,$a.useEffect)(()=>{R.current!==k&&(R.current=k,window.scrollTo(0,0))},[k]);let z=U=>{if(!p)return;w("estimate_completed",{calculator:p.id,lines:U.length});let A=Tv(p.id,U);A?u(A,U[0]?.calculatorWasteIncluded??!1):c(U)};return(0,ze.jsx)(Fo.Provider,{value:w,children:(0,ze.jsx)("div",{ref:h,className:`app-wrapper${e?"":" app-wrapper--embedded"}${t?" app-wrapper--no-header":""}${a?"":" estimating-tools--customer"}`,style:Ot().theme,children:(0,ze.jsx)("main",{className:"main-content",children:r?(0,ze.jsx)(sl,{cart:m,onUpdateQty:g,onUpdateSellUnits:d,onResolveConversions:b,onRemove:_,onBack:()=>i(!1),onStartNewQuote:()=>{M(),o(null),c(null),i(!1)},internal:a}):O&&p?(0,ze.jsx)(a0,{toolTitle:p.title}):p?(0,ze.jsxs)(ze.Fragment,{children:[(0,ze.jsx)("div",{hidden:l!==null,children:(0,ze.jsx)(p.Component,{onBack:()=>o(null),onReview:z})}),f&&(0,ze.jsx)("p",{className:"results-empty-hint estimator-products__error",children:f}),l!==null&&(0,ze.jsx)(nm,{toolId:p.id,toolTitle:p.title,requirements:l,onBack:()=>c(null)})]}):(0,ze.jsx)(ze.Fragment,{children:(0,ze.jsxs)("div",{className:"quick-order-card",children:[(0,ze.jsxs)("div",{className:"quick-order-hero",children:[(0,ze.jsx)("div",{className:"quick-order-eyebrow",children:"Construction Services"}),(0,ze.jsx)("h1",{children:"Estimating Tools"}),(0,ze.jsx)("p",{children:"Trade-specific calculators for trusses, fencing, decking, masonry and painting. Dial in your specs and get an instant material estimate."})]}),(0,ze.jsxs)("div",{className:"quick-order-alt",children:[(0,ze.jsx)("div",{className:"quick-order-alt-title",children:"Choose a Calculator"}),(0,ze.jsx)("div",{className:"estimator-tools-grid",children:am.map(U=>(0,ze.jsxs)("button",{type:"button",className:"estimator-tool-card",onClick:()=>{w("calculator_selected",{calculator:U.id}),o(U.id),c(null)},children:[(0,ze.jsx)("span",{className:"estimator-tool-card__image-wrap",children:(0,ze.jsx)("img",{className:"fill-img estimator-tool-card__image",src:Ft(U.imageUrl),alt:""})}),(0,ze.jsxs)("span",{className:"estimator-tool-card__content",children:[(0,ze.jsx)("span",{className:"estimator-tool-card__title",children:U.title}),(0,ze.jsx)("span",{className:"estimator-tool-card__desc",children:U.desc})]})]},U.id))})]})]})})})})})}var Nc=X(ee());function lm({config:e,children:t}){return pw(e),(0,Nc.jsx)(Nc.Fragment,{children:t})}var sm=X(ee()),Tx="https://api.metronlabs.ai",zx=["client","api-key","api-url","theme","hide-header","analytics"],Rx=["all","events-only","none"];function i0(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.65",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; }
|
|
6994
6994
|
:host > div { all: initial; display: block; }
|
|
6995
6995
|
${uw}`,this.shadowRoot.replaceChildren(n,i),this.root=(0,r0.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")||Tx,client:i,apiKey:n,theme:Ux(e,this.getAttribute("theme")),analytics:Ax(this.getAttribute("analytics"))};this.root.render((0,sm.jsx)(lm,{config:o,children:(0,sm.jsx)(t,{hideHeader:this.hasAttribute("hide-header")})}))}},a.observedAttributes=zx,a))}function Ax(e){return Rx.find(t=>t===e)??"all"}function Ux(e,t){if(t)try{return JSON.parse(t)}catch{console.error(`<${e}> theme attribute isn't valid JSON; using the default colours.`);return}}i0("metron-labs-quick-quote",sc);i0("metron-labs-estimating-tools",Sc);
|
|
6996
6996
|
/*! Bundled license information:
|