{"version":3,"file":"catalog.js","sources":["../../../../../Flow.Showcase.Static.Bundler/Root/entrypoints/catalog.ts"],"sourcesContent":["// @ts-nocheck\n\nimport eventBus from \"../modules/event-bus.module.ts\";\n\nconst errorContainer = document.getElementById(\"error-message\");\nif (errorContainer) {\n errorContainer.style.display = \"none\";\n\n // Отобразить ошибку\n eventBus.subscribe(\"update-cart-error\", ({ error }) => {\n errorContainer.textContent = error;\n errorContainer.style.display = \"block\";\n setTimeout(() => {\n errorContainer.style.display = \"none\";\n }, 5000);\n });\n}\n\nconst filterTooltipContainer = document.querySelector(\n \".js-filter-tooltip-container\"\n);\nif (filterTooltipContainer instanceof HTMLElement) {\n try {\n const filterTooltip = /** @type {HTMLElement} */ (\n document.querySelector(\".js-filter-tooltip\")\n );\n\n // Применить фильтры\n const tooltipApplyBtn = /** @type {HTMLElement} */ (\n filterTooltip.querySelector(\".js-filter-tooltip-apply\")\n );\n tooltipApplyBtn.addEventListener(\"click\", () => {\n hideFilterTooltip();\n loadProducts();\n });\n\n // Закрыть тултип\n const tooltipCloseBtn = /** @type {HTMLElement} */ (\n filterTooltip.querySelector(\".js-filter-tooltip-close\")\n );\n tooltipCloseBtn.addEventListener(\"click\", () => {\n hideFilterTooltip();\n });\n\n const rootStyle = getComputedStyle(document.documentElement);\n\n // Показать тултип при нажатии на чекбокс\n document\n .querySelectorAll(\".js-filter-list .js-filter-list__item\")\n .forEach((listItem) => {\n const checkbox = /** @type {HTMLInputElement} */ (\n listItem.querySelector('input[type=\"checkbox\"]')\n );\n checkbox.addEventListener(\"click\", () => {\n // Не показывать тултип в мобильной версии\n if (rootStyle.getPropertyValue(\"--mobile\") === \"true\") {\n return;\n }\n\n window.addEventListener(\"resize\", hideFilterTooltip);\n filterTooltipContainer.hidden = false;\n const parent = getOffsetParent(filterTooltipContainer);\n const listItemRect = listItem.getBoundingClientRect();\n const parentRect = parent.getBoundingClientRect();\n const left = listItemRect.left - parentRect.left;\n const top = listItemRect.top - parentRect.top;\n filterTooltipContainer.style.left = left + \"px\";\n filterTooltipContainer.style.top = top + \"px\";\n filterTooltipContainer.style.width =\n listItemRect.width + \"px\";\n filterTooltipContainer.style.height =\n listItemRect.height + \"px\";\n });\n });\n } catch (error) {\n console.error(error);\n }\n}\n\nfunction hideFilterTooltip() {\n if (filterTooltipContainer instanceof HTMLElement) {\n filterTooltipContainer.hidden = true;\n window.removeEventListener(\"resize\", hideFilterTooltip);\n }\n}\n\n/**\n * Получить родительский элемент, относительно которого происходит позиционирование.\n * Если такой элемент отсутствует, возвращается documentElement.\n * @param {HTMLElement} el\n * @returns\n */\nfunction getOffsetParent(el) {\n if (el.offsetParent === null) {\n throw new Error(\"offsetParent === null\");\n }\n if (\n el.offsetParent === document.body &&\n window.getComputedStyle(el.offsetParent).position === \"static\"\n ) {\n return document.documentElement;\n }\n return el.offsetParent;\n}\n\n// Обработка выбора минимальной и максимальной цены\n/** @type {number} */\nlet priceMin = NaN;\n/** @type {number} */\nlet priceMax = NaN;\n/** @type {Element | null} */\nlet priceFromInput;\n/** @type {Element | null} */\nlet priceToInput;\nconst priceFilter = document.querySelector(\"#price .js-price-range\");\nif (priceFilter instanceof HTMLElement) {\n priceMin = parseFloat(priceFilter.dataset.priceMin || \"\");\n priceMax = parseFloat(priceFilter.dataset.priceMax || \"\");\n priceFromInput = priceFilter.querySelector(\"input.js-price-from\");\n if (priceFromInput) {\n priceFromInput.addEventListener(\"keydown\", priceRangeChangeHandler);\n }\n priceToInput = priceFilter.querySelector(\"input.js-price-to\");\n if (priceToInput) {\n priceToInput.addEventListener(\"keydown\", priceRangeChangeHandler);\n }\n}\nif (!Number.isFinite(priceMin)) {\n priceMin = 0;\n}\nif (!Number.isFinite(priceMax)) {\n priceMax = Infinity;\n}\n\nfunction priceRangeChangeHandler(event) {\n if (event.key === \"Enter\") {\n loadProducts(true);\n }\n}\n\n// Обработка нажатия кнопки Применить\nconst applyButton = document.querySelector(\".js-filter-apply\");\nif (applyButton instanceof HTMLButtonElement) {\n applyButton.addEventListener(\"click\", () => loadProducts());\n}\n\n// Обработка нажатия кнопки Сбросить фильтры\nconst clearButton = document.querySelector(\".js-filter-clear\");\nif (clearButton instanceof HTMLButtonElement) {\n clearButton.addEventListener(\"click\", () => clearFilters());\n}\n\n//Загрузка отфильтрованных продуктов\nfunction loadProducts(applyPriceRange = false) {\n const filters = [];\n const urlParams = new URLSearchParams(window.location.search);\n\n // Поиск\n if (window.location.pathname.includes(\"search\")) {\n const searchQuery = urlParams.get(\"search\");\n filters.push(`search=${searchQuery}`);\n }\n\n // Бренды\n const brandCheckboxes = document.querySelectorAll(\n '#brands-list input[type=\"checkbox\"]:checked'\n );\n const brandFilterValues = Array.from(brandCheckboxes).map((checkbox) =>\n checkbox instanceof HTMLElement ? checkbox.dataset.id : \"\"\n );\n if (brandFilterValues.length > 0) {\n filters.push(`brand-filter=${brandFilterValues.join(\",\")}`);\n }\n\n // Производители\n const manufacturerCheckboxes = document.querySelectorAll(\n '#manufacturers-list input[type=\"checkbox\"]:checked'\n );\n const manufacturerFilterValues = Array.from(manufacturerCheckboxes).map(\n (checkbox) =>\n checkbox instanceof HTMLElement ? checkbox.dataset.id : \"\"\n );\n if (manufacturerFilterValues.length > 0) {\n filters.push(\n `manufacturer-filter=${manufacturerFilterValues.join(\",\")}`\n );\n }\n\n // Цена\n if (applyPriceRange) {\n let priceFrom = NaN;\n if (priceFromInput instanceof HTMLInputElement) {\n priceFrom = priceFromInput.valueAsNumber;\n }\n let priceTo = NaN;\n if (priceToInput instanceof HTMLInputElement) {\n priceTo = priceToInput.valueAsNumber;\n }\n priceTo = clamp(priceTo, priceMin, priceMax);\n priceFrom = clamp(priceFrom, priceMin, priceTo);\n if (Number.isFinite(priceFrom)) {\n filters.push(`price-min=${priceFrom.toFixed(2)}`);\n }\n if (Number.isFinite(priceTo)) {\n filters.push(`price-max=${priceTo.toFixed(2)}`);\n }\n }\n\n // Варианты\n const variantsFilters = document.querySelectorAll(\n \".js-variants-filter-list\"\n );\n const keysObj = {};\n variantsFilters.forEach((filter) => {\n if (!(filter instanceof HTMLElement)) {\n return;\n }\n const key = filter.dataset.id;\n const checkboxes = filter.querySelectorAll(\n 'input[type=\"checkbox\"]:checked'\n );\n const values = Array.from(checkboxes).map((checkbox) =>\n checkbox instanceof HTMLElement ? checkbox.dataset.id : \"\"\n );\n if (values.length > 0) {\n keysObj[key] = values;\n }\n });\n if (Object.keys(keysObj).length > 0) {\n filters.push(`keys=${encodeURI(JSON.stringify(keysObj))}`);\n }\n\n // Пагинация\n if (urlParams.has(\"page\")) {\n filters.push(`page=${urlParams.get(\"page\")}`);\n }\n if (urlParams.has(\"limit\")) {\n filters.push(`limit=${urlParams.get(\"limit\")}`);\n }\n\n window.location.search = filters.join(\"&\");\n}\n\n/**\n * Убрать все query параметры, кроме поиска и пагинации\n */\nfunction clearFilters() {\n const filters = [];\n const urlParams = new URLSearchParams(window.location.search);\n\n // Поиск\n if (window.location.pathname.includes(\"search\")) {\n const searchQuery = urlParams.get(\"search\");\n filters.push(`search=${searchQuery}`);\n }\n\n // Пагинация\n if (urlParams.has(\"page\")) {\n filters.push(`page=${urlParams.get(\"page\")}`);\n }\n if (urlParams.has(\"limit\")) {\n filters.push(`limit=${urlParams.get(\"limit\")}`);\n }\n\n window.location.search = filters.join(\"&\");\n}\n\n/**\n * @param {number} value\n * @param {number} min\n * @param {number} max\n */\nfunction clamp(value, min, max) {\n if (value > max) {\n value = max;\n }\n if (value < min) {\n value = min;\n }\n return value;\n}\n\nconst SortSelect = (element: HTMLElement) => {\n const sortByElements = Array.from(element.querySelectorAll(\"[data-sort-by]\"));\n const sortDirectionElements = Array.from(element.querySelectorAll(\"[data-sort-direction]\"));\n\n const selectedByValue = sortByElements\n .find(elem => elem.attributes.getNamedItem(\"data-sort-active\") !== null)\n ?.attributes?.getNamedItem(\"data-sort-by\")?.value\n const selectedDirectionValue = sortDirectionElements\n .find(elem => elem.attributes.getNamedItem(\"data-sort-active\") !== null)\n ?.attributes?.getNamedItem(\"data-sort-direction\")?.value\n\n sortByElements.forEach(elem => {\n elem.addEventListener(\"click\", () => {\n const url = new URL(window.location);\n const elemValue = elem.attributes.getNamedItem(\"data-sort-by\").value;\n\n if (elemValue !== selectedByValue) {\n url.searchParams.set(\"sort-by\", elemValue);\n url.searchParams.set(\"sort-dir\", selectedDirectionValue ?? sortDirectionElements[0].attributes.getNamedItem(\"data-sort-direction\").value);\n } else {\n url.searchParams.delete(\"sort-by\");\n url.searchParams.delete(\"sort-dir\");\n }\n\n url.searchParams.delete(\"page\");\n\n window.location = url.toString();\n })\n })\n\n sortDirectionElements.forEach(elem => {\n elem.addEventListener(\"click\", () => {\n const url = new URL(window.location);\n const elemValue = elem.attributes.getNamedItem(\"data-sort-direction\").value;\n\n if (elemValue !== selectedDirectionValue) {\n url.searchParams.set(\"sort-by\", selectedByValue ?? sortByElements[0].attributes.getNamedItem(\"data-sort-by\").value);\n url.searchParams.set(\"sort-dir\", elemValue);\n } else {\n url.searchParams.delete(\"sort-by\");\n url.searchParams.delete(\"sort-dir\");\n }\n\n url.searchParams.delete(\"page\");\n\n window.location = url.toString();\n })\n })\n}\n\nSortSelect(document.querySelector('[data-catalog-sort]'))\n"],"names":["errorContainer","eventBus","error","filterTooltipContainer","filterTooltip","hideFilterTooltip","loadProducts","rootStyle","listItem","parent","getOffsetParent","listItemRect","parentRect","left","top","el","priceMin","priceMax","priceFromInput","priceToInput","priceFilter","priceRangeChangeHandler","event","applyButton","clearButton","clearFilters","applyPriceRange","filters","urlParams","searchQuery","brandCheckboxes","brandFilterValues","checkbox","manufacturerCheckboxes","manufacturerFilterValues","priceFrom","priceTo","clamp","variantsFilters","keysObj","filter","key","checkboxes","values","value","min","max","SortSelect","element","sortByElements","sortDirectionElements","selectedByValue","_c","_b","_a","elem","selectedDirectionValue","_f","_e","_d","url","elemValue"],"mappings":"2DAIA,MAAMA,EAAiB,SAAS,eAAe,eAAe,EAC1DA,IACAA,EAAe,MAAM,QAAU,OAG/BC,EAAS,UAAU,o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