{
  "version": 3,
  "sources": ["/cdn/shop/t/3/assets/linked-products.js"],
  "sourcesContent": ["import { r as register, x, u, k } from \"./preact-core.js\";\nimport { C as CustomSelect } from \"./custom-select.js\";\nconst _LinkedProducts = class _LinkedProducts extends x {\n  constructor(props) {\n    var _a;\n    super(props);\n    this.handleProductSelection = (data) => {\n      if (data.value) {\n        const product = data.value;\n        this.setState({\n          selectedProductLabel: product.label\n        });\n        if (product.url) {\n          _LinkedProducts.navigateToProduct(product.url);\n        }\n      }\n    };\n    this.parsedLinkedProducts = JSON.parse(this.props.products);\n    this.products = this.initializeProducts();\n    this.state = {\n      selectedProductLabel: ((_a = this.parsedLinkedProducts[0]) == null ? void 0 : _a.label) || _LinkedProducts.DEFAULT_LABEL\n    };\n  }\n  /**\n   * Initializes products through the complete processing pipeline\n   */\n  initializeProducts() {\n    if (_LinkedProducts.DEBUG_DUPLICATES) {\n      console.log(\n        \"LinkedProducts: Raw parsed data:\",\n        this.parsedLinkedProducts.map((p) => ({\n          label: p.label,\n          id: p.id,\n          labelLength: p.label.length,\n          charCodes: Array.from(p.label).map((c) => c.charCodeAt(0))\n        }))\n      );\n    }\n    const decoded = this.decodeHtmlEntities(this.parsedLinkedProducts);\n    if (_LinkedProducts.DEBUG_DUPLICATES) {\n      console.log(\n        \"LinkedProducts: After HTML decoding:\",\n        decoded.map((p) => {\n          var _a;\n          return {\n            label: p.label,\n            id: p.id,\n            labelLength: p.label.length,\n            changed: p.label !== ((_a = this.parsedLinkedProducts.find((orig) => orig.id === p.id)) == null ? void 0 : _a.label)\n          };\n        })\n      );\n    }\n    const deduplicated = this.removeDuplicates(decoded);\n    const sorted = _LinkedProducts.sortProducts(deduplicated);\n    if (_LinkedProducts.DEBUG_DUPLICATES) {\n      console.log(\n        \"LinkedProducts: Final processed products:\",\n        sorted.map((p) => ({ label: p.label, id: p.id }))\n      );\n    }\n    return sorted;\n  }\n  componentDidMount() {\n    const savedScrollPosition = sessionStorage.getItem(\n      _LinkedProducts.STORAGE_KEY\n    );\n    if (savedScrollPosition) {\n      requestAnimationFrame(() => {\n        window.scrollTo(0, parseInt(savedScrollPosition, 10));\n        sessionStorage.removeItem(_LinkedProducts.STORAGE_KEY);\n      });\n    }\n  }\n  static decodeHtmlEntity(text) {\n    if (!text || typeof text !== \"string\") return text;\n    const decoder = document.createElement(\"div\");\n    decoder.innerHTML = text;\n    const decoded = decoder.textContent || decoder.innerText || text;\n    return decoded.replace(/\\u00A0/g, \" \").replace(/\\u2000-\\u200F/g, \" \").replace(/\\u2028|\\u2029/g, \" \");\n  }\n  static navigateToProduct(url) {\n    sessionStorage.setItem(\n      _LinkedProducts.STORAGE_KEY,\n      window.scrollY.toString()\n    );\n    window.location.href = url;\n  }\n  /**\n   * Custom sort function for products: samples last, partial matches prioritize shorter labels,\n   * numeric labels sorted numerically, fallback to alphabetical\n   */\n  static sortProducts(products) {\n    if (products.length <= 1) return products;\n    return products.sort((a, b) => {\n      const labelA = a.label.trim().toLowerCase();\n      const labelB = b.label.trim().toLowerCase();\n      const isSampleA = /\\bsample\\b/.test(labelA);\n      const isSampleB = /\\bsample\\b/.test(labelB);\n      if (isSampleA && !isSampleB) return 1;\n      if (isSampleB && !isSampleA) return -1;\n      if (labelA.startsWith(labelB) && labelA !== labelB) return 1;\n      if (labelB.startsWith(labelA) && labelA !== labelB) return -1;\n      const numA = labelA.match(/^(\\d+)/);\n      const numB = labelB.match(/^(\\d+)/);\n      if (numA && numB) {\n        return parseInt(numA[1] || numA[0], 10) - parseInt(numB[1] || numB[0], 10);\n      } else if (numA) {\n        return -1;\n      } else if (numB) {\n        return 1;\n      } else {\n        return labelA.localeCompare(labelB);\n      }\n    });\n  }\n  /**\n   * Decodes HTML entity references in product data\n   * @param products Array of product options\n   * @returns Processed array with decoded HTML entities\n   */\n  decodeHtmlEntities(products) {\n    return products.map((product) => ({\n      ...product,\n      label: product.label ? _LinkedProducts.decodeHtmlEntity(product.label) : product.label,\n      value: product.value ? _LinkedProducts.decodeHtmlEntity(product.value) : product.value\n    }));\n  }\n  /**\n   * Normalizes a label for comparison by removing extra whitespace,\n   * converting to lowercase, and handling Unicode normalization\n   */\n  static normalizeLabel(label) {\n    return label.trim().toLowerCase().replace(/\\s+/g, \" \").replace(/\\s*&\\s*/g, \" & \").replace(/\\s+/g, \" \").normalize(\"NFD\").replace(/[\\u0300-\\u036f]/g, \"\");\n  }\n  /**\n   * Removes duplicate product options based on normalized label comparison\n   */\n  removeDuplicates(products) {\n    if (products.length <= 1) return products;\n    const seen = /* @__PURE__ */ new Map();\n    const uniqueProducts = [];\n    const duplicateGroups = [];\n    for (const product of products) {\n      const normalizedLabel = _LinkedProducts.normalizeLabel(product.label);\n      if (!seen.has(normalizedLabel)) {\n        seen.set(normalizedLabel, product);\n        uniqueProducts.push(product);\n      } else {\n        const keptProduct = seen.get(normalizedLabel);\n        let duplicateGroup = duplicateGroups.find(\n          (g) => g.normalized === normalizedLabel\n        );\n        if (!duplicateGroup) {\n          duplicateGroup = {\n            normalized: normalizedLabel,\n            kept: keptProduct,\n            duplicates: []\n          };\n          duplicateGroups.push(duplicateGroup);\n        }\n        duplicateGroup.duplicates.push(product);\n      }\n    }\n    if (_LinkedProducts.DEBUG_DUPLICATES) {\n      if (duplicateGroups.length > 0) {\n        console.log(\n          \"LinkedProducts: Duplicate groups detected:\",\n          duplicateGroups.map((group) => ({\n            normalizedLabel: group.normalized,\n            keptItem: { label: group.kept.label, id: group.kept.id },\n            removedItems: group.duplicates.map((d) => ({\n              label: d.label,\n              id: d.id\n            })),\n            totalDuplicates: group.duplicates.length\n          }))\n        );\n      }\n      console.log(\n        `LinkedProducts: Processed ${products.length} products, kept ${uniqueProducts.length} unique items`\n      );\n    }\n    return uniqueProducts;\n  }\n  renderProductButton(product) {\n    const isCurrentProduct = _LinkedProducts.normalizeLabel(product.label) === _LinkedProducts.normalizeLabel(\n      _LinkedProducts.decodeHtmlEntity(this.state.selectedProductLabel)\n    );\n    return /* @__PURE__ */ u(\n      \"button\",\n      {\n        class: `ease leading-50 transition-opacity duration-200 hover:opacity-100 ${isCurrentProduct ? \"font-medium opacity-100\" : \"opacity-40\"}`,\n        disabled: isCurrentProduct,\n        onClick: () => {\n          if (product.url && !isCurrentProduct) {\n            _LinkedProducts.navigateToProduct(product.url);\n          }\n        },\n        children: product.label\n      }\n    );\n  }\n  renderButtonsView() {\n    const allProducts = this.products;\n    if (allProducts.length === 0) {\n      return /* @__PURE__ */ u(\"div\", { class: \"linked-products-buttons\", children: \"No products available\" });\n    }\n    return /* @__PURE__ */ u(\"div\", { class: \"linked-products-buttons flex w-full justify-between gap-x-20 gap-y-10\", children: [\n      allProducts.map((product) => this.renderProductButton(product)),\n      allProducts.length === 2 && /* @__PURE__ */ u(\"span\", { class: \"spacer block min-w-[40px]\" })\n    ] });\n  }\n  renderSelectView() {\n    const currentProduct = this.products.find((p) => p.isCurrent) || this.products[0];\n    return /* @__PURE__ */ u(\"div\", { class: \"linked-products-select\", children: /* @__PURE__ */ u(\n      CustomSelect,\n      {\n        title: this.state.selectedProductLabel,\n        options: this.products,\n        default: currentProduct,\n        direction: \"down\",\n        onSelected: this.handleProductSelection\n      }\n    ) });\n  }\n  render() {\n    return /* @__PURE__ */ u(k, { children: this.props.type === \"buttons\" ? this.renderButtonsView() : this.renderSelectView() });\n  }\n};\n_LinkedProducts.STORAGE_KEY = \"linkedProductsScrollPosition\";\n_LinkedProducts.DEFAULT_LABEL = \"Select Product\";\n_LinkedProducts.DEBUG_DUPLICATES = false;\nlet LinkedProducts = _LinkedProducts;\nfunction LinkedProducts$1() {\n  register(LinkedProducts, \"linked-products\", [\"products\", \"type\"]);\n}\nLinkedProducts$1();\n"],
  "mappings": "AAAA,OAAS,KAAK,SAAU,EAAG,EAAG,MAAS,mBACvC,OAAS,KAAK,iBAAoB,qBAClC,MAAM,gBAAkB,MAAMA,yBAAwB,CAAE,CACtD,YAAY,MAAO,CACjB,IAAI,GACJ,MAAM,KAAK,EACX,KAAK,uBAA0B,MAAS,CACtC,GA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