(function () { "use strict"; function renderSummary(form, target) { var data = new FormData(form); var groups = [ [ "01", "PROPERTY DETAILS", "房屋资料", [ ["Property Type / 房屋类型", "property_type"], ["Property Status / 房屋状态", "property_status"], ["Location / 项目地点", "project_location"], ["Built-up Area / 建筑面积", "built_up", "sq ft"], ["Services Required / 所需服务", "services[]"], ], ], [ "02", "BUDGET & SCOPE", "预算与工程", [ ["Estimated Budget / 预计预算", "budget"], ["Custom Furniture / 定制家具", "custom_furniture"], ["Budget Flexibility / 预算弹性", "budget_flexibility"], ["Expected Start Date / 预计开工时间", "start_date"], ["Renovation Scope / 装修项目", "renovation_scope[]"], ], ], [ "03", "DESIGN PREFERENCES", "设计偏好", [ ["Preferred Styles / 喜好风格", "design_style[]"], ["Colour Palette / 色彩偏好", "palette"], ["Top Priorities / 设计重点", "priorities[]"], ["Furniture Requirements / 家具需求", "furniture_items[]"], ["Additional Requirements / 其他需求", "requirements"], ["Uploaded Files / 上传附件", "attachments[]", "files"], ], ], [ "04", "CONTACT DETAILS", "联系资料", [ ["Full Name / 姓名", "name"], ["Mobile Number / 手机号码", "phone"], ["Email Address / 邮箱", "email"], ["Preferred Contact Method / 联系方式", "contact_method"], ["Preferred Contact Time / 联系时间", "contact_time"], ["Site Visit / 现场勘查", "site_visit"], ], ], ]; target.textContent = ""; groups.forEach(function (group) { var section = document.createElement("section"); section.className = "q-summary-group"; var heading = document.createElement("h4"); heading.textContent = group[0] + " / " + group[1] + " · " + group[2]; section.appendChild(heading); var grid = document.createElement("div"); grid.className = "q-summary-grid"; group[3].forEach(function (field) { var cell = document.createElement("div"); cell.className = "q-summary-item"; var label = document.createElement("span"); label.className = "q-summary-label"; label.textContent = field[0]; var value = document.createElement("strong"); value.className = "q-summary-value"; var vals = field[2] === "files" ? form.querySelector('input[name="attachments[]"]') ? Array.from( form.querySelector('input[name="attachments[]"]').files, ).map(function (f) { return f.name; }) : [] : data.getAll(field[1]).filter(function (v) { return typeof v === "string" && v.trim(); }); value.textContent = vals.length ? vals.join(", ") + (field[2] === "sq ft" ? " sq ft" : "") : "Not provided / 未填写"; cell.appendChild(label); cell.appendChild(value); grid.appendChild(cell); }); section.appendChild(grid); target.appendChild(section); }); } var form = document.getElementById("quoteEnquiry"); if (!form) return; var steps = [].slice.call(form.querySelectorAll(".q-step")); var tabs = [].slice.call(document.querySelectorAll(".q-tabs>span")); var current = 0; var error = document.getElementById("qError"); function show(n) { current = n; steps.forEach(function (s, i) { s.hidden = i !== n; }); tabs.forEach(function (t, i) { t.classList.toggle("is-active", i === n); }); document.getElementById("stepCount").textContent = ("0" + (n + 1)).slice(-2) + " / 04"; document.getElementById("qProgress").style.width = (n + 1) * 25 + "%"; error.textContent = ""; document .getElementById("quoteForm") .scrollIntoView({ behavior: "smooth", block: "start" }); } function valid(s) { var fields = [].slice.call(s.querySelectorAll("input,select,textarea")); for (var i = 0; i < fields.length; i++) { var f = fields[i]; if (f.disabled || !f.required) continue; if (f.type === "radio") { if (!s.querySelector('input[name="' + f.name + '"]:checked')) { f.focus(); return false; } } else if (!f.checkValidity()) { f.reportValidity(); return false; } } return true; } form.querySelectorAll(".q-next").forEach(function (b) { b.addEventListener("click", function () { if (valid(steps[current])) show(current + 1); else error.textContent = "Please complete the required fields. 请填写必填项目。"; }); }); form.querySelectorAll(".q-back").forEach(function (b) { b.addEventListener("click", function () { show(Math.max(0, current - 1)); }); }); var files = document.getElementById("quoteFiles"); files.addEventListener("change", function () { var f = [].slice.call(files.files); var ok = f.length <= 3 && f.every(function (x) { return ( x.size <= 5 * 1024 * 1024 && ["image/jpeg", "image/png", "application/pdf"].indexOf(x.type) !== -1 ); }); document.getElementById("fileNote").textContent = ok ? f.length + " file(s) selected" : "Maximum 3 JPG/PNG/PDF files, 5MB each."; if (!ok) files.value = ""; }); form.addEventListener("submit", function (e) { e.preventDefault(); if (!valid(steps[current])) return; var btn = form.querySelector(".q-submit"); btn.disabled = true; btn.textContent = "Sending..."; error.textContent = ""; var testData = new FormData(form); console.log("Design Styles:", testData.getAll("design_style[]")); console.log("Requirements:", testData.get("requirements")); fetch(form.action, { method: "POST", body: new FormData(form), headers: { Accept: "application/json" }, }) .then(function (r) { return r.text().then(function (raw) { var d; try { d = JSON.parse(raw); } catch (e) { throw new Error( "Server returned an invalid response (HTTP " + r.status + "). Check PHP error logs and quote-submit.php path", ); } if (!r.ok || !d.ok) throw new Error(d.message || "Submission failed"); return d; }); }) .then(function () { form.hidden = true; document.querySelector(".q-tabs").hidden = true; document.querySelector(".q-progress").hidden = true; document.querySelector(".q-top").hidden = true; renderSummary(form, document.getElementById("qSummary")); document.getElementById("qSuccess").hidden = false; document .getElementById("quoteForm") .scrollIntoView({ behavior: "smooth" }); }) .catch(function (ex) { error.textContent = ex.message + " — Please try again or email sales@taedesign.com.my."; }) .finally(function () { btn.disabled = false; btn.textContent = "Submit Enquiry →"; }); }); })();