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MAAM,kBAAmB,EAAK,QAhEhD,SAAuB,GAErB,MAAM,EAAW,EAAK,QAAQ,kBAC9B,GAAI,EAEF,YADA,OAAO,SAAS,KAAO,GAKzB,MAAM,EAAY,EAAK,QAAQ,gBAC/B,GAAI,EAAW,CACb,MAAM,EAAK,SAAS,cAAc,GAIlC,OAHI,IAAI,EAAG,MAAM,QAAU,SACY,UAAnC,EAAK,QAAQ,oBACf,EAAK,MAAM,QAAU,QAEzB,CAGA,MAAM,EACJ,EAAK,QAAQ,kBAAoB,oCAC7B,EAAM,EAAK,QAAQ,gBAAkB,oBACrC,EAAI,SAAS,cAAc,KACjC,EAAE,UAAY,EACd,EAAE,YAAc,EAChB,EAAK,YAAY,EACnB,CAoCU,CAAc,EAIlB,CAAE,MAAO,GACP,QAAQ,MAAM,oBAAqB,EACrC,KAGN,CAG4B,YAAxB,SAAS,WACX,SAAS,iBAAiB,mBAAoB,GAE9C,GAEH,CAxHD","file":"/gh/orangestudio-co/os-code-blocks@301bede/hubspot-submit/os-hubspot-submit.js","sourceRoot":"","sourcesContent":["/**\n * Minified by jsDelivr using Terser v5.48.0.\n * Original file: /gh/orangestudio-co/os-code-blocks@301bede/hubspot-submit/os-hubspot-submit.js\n *\n * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files\n */\n","(function () {\n  const PORTAL_ID =\n    document.currentScript?.dataset.portalId || window.HS_PORTAL_ID;\n\n  function getValue(el, form, fieldName) {\n    const type = (el.type || \"\").toLowerCase();\n\n    // Radio group: find the checked one among same-named fields in this form\n    if (type === \"radio\") {\n      const checked = form.querySelector(\n        `[data-os-form-field=\"${fieldName}\"]:checked`,\n      );\n      return checked ? checked.value : \"\";\n    }\n\n    // Checkbox: single = boolean, multiple sharing a name = multi-select\n    if (type === \"checkbox\") {\n      const group = form.querySelectorAll(\n        `[data-os-form-field=\"${fieldName}\"]`,\n      );\n      if (group.length > 1) {\n        return [...group]\n          .filter((c) => c.checked)\n          .map((c) => c.value)\n          .join(\";\");\n      }\n      return el.checked\n        ? el.value && el.value !== \"on\"\n          ? el.value\n          : \"true\"\n        : \"false\";\n    }\n\n    // Multi-select dropdown\n    if (el.multiple) {\n      return [...el.selectedOptions].map((o) => o.value).join(\";\");\n    }\n\n    return el.value ?? \"\";\n  }\n\n  function handleSuccess(form) {\n    // 1. Redirect wins if present\n    const redirect = form.dataset.osSuccessRedirect;\n    if (redirect) {\n      window.location.href = redirect;\n      return;\n    }\n\n    // 2. Reveal an existing element (by selector) instead of replacing\n    const revealSel = form.dataset.osSuccessReveal;\n    if (revealSel) {\n      const el = document.querySelector(revealSel);\n      if (el) el.style.display = \"\";\n      if (form.dataset.osSuccessHideForm !== \"false\")\n        form.style.display = \"none\";\n      return;\n    }\n\n    // 3. Default: replace form with a message\n    const msg =\n      form.dataset.osSuccessMessage || \"Your submission has been received\";\n    const cls = form.dataset.osSuccessClass || \"form_success_text\";\n    const p = document.createElement(\"p\");\n    p.className = cls;\n    p.textContent = msg;\n    form.replaceWith(p);\n  }\n\n  function bindForms() {\n    document.querySelectorAll(\"[data-os-form]\").forEach((form) => {\n      const FORM_ID = form.dataset.osForm;\n\n      form.addEventListener(\"submit\", async (e) => {\n        e.preventDefault();\n        if (!form.checkValidity()) return form.reportValidity();\n\n        // Dedupe by field name so radio/checkbox groups produce one payload entry\n        const seen = new Set();\n        const fields = [];\n\n        form.querySelectorAll(\"[data-os-form-field]\").forEach((el) => {\n          const name = el.dataset.osFormField;\n          if (seen.has(name)) return;\n          seen.add(name);\n          fields.push({\n            objectTypeId: el.dataset.osFormObject || \"0-1\",\n            name,\n            value: getValue(el, form, name),\n          });\n        });\n\n        try {\n          const res = await fetch(\n            `https://api.hsforms.com/submissions/v3/integration/submit/${PORTAL_ID}/${FORM_ID}`,\n            {\n              method: \"POST\",\n              headers: { \"Content-Type\": \"application/json\" },\n              body: JSON.stringify({ fields }),\n            },\n          );\n          const data = await res.json();\n          if (!data.errors) {\n            handleSuccess(form);\n          } else {\n            console.error(\"HubSpot errors:\", data.errors);\n          }\n        } catch (err) {\n          console.error(\"Submission error:\", err);\n        }\n      });\n    });\n  }\n\n  // Bind whenever the script runs — <head>, defer, or end of <body>\n  if (document.readyState === \"loading\") {\n    document.addEventListener(\"DOMContentLoaded\", bindForms);\n  } else {\n    bindForms();\n  }\n})();\n"]}