{"version":3,"file":"accordion-C2XMZ08c.js","sources":["../../src/js/components/accordion.ts"],"sourcesContent":["export function initAccordion() {\n // Select all the accordions on the page\n const accordions = document.querySelectorAll('[data-accordion]');\n\n accordions.forEach((accordion) => {\n const accordionItems = accordion.querySelectorAll(\n '[data-accordion-item]',\n );\n const enableMultiple =\n accordion.getAttribute('data-enable-multiple')?.toLowerCase() === 'true';\n\n accordionItems.forEach((item) => {\n const accordionTrigger = item.querySelector(\n '[data-accordion-trigger]',\n );\n\n accordionTrigger?.addEventListener('click', () => {\n toggleAccordionItem(item, accordion, enableMultiple);\n });\n });\n });\n}\n\nfunction toggleAccordionItem(\n item: HTMLElement,\n accordion: Element,\n enableMultiple: boolean,\n) {\n const isOpen = item.dataset.state === 'open';\n\n if (isOpen) {\n closeAccordion(item);\n } else {\n openAccordion(item);\n\n if (!enableMultiple) {\n // Close other open items\n const otherItems = accordion.querySelectorAll(\n '[data-accordion-item]',\n );\n otherItems.forEach((otherItem) => {\n if (otherItem !== item && otherItem.dataset.state === 'open') {\n closeAccordion(otherItem);\n }\n });\n }\n }\n}\n\nfunction closeAccordion(accordionItem: HTMLElement) {\n const accordionTrigger = accordionItem.querySelector(\n '[data-accordion-trigger]',\n );\n const accordionContent = accordionItem.querySelector(\n '[data-accordion-content]',\n );\n\n if (!accordionTrigger || !accordionContent) return;\n\n const svgIcons = accordionTrigger.querySelectorAll('svg');\n\n // Update ARIA attributes and data-state on both item and trigger\n accordionItem.setAttribute('data-state', 'closed');\n accordionTrigger.setAttribute('aria-expanded', 'false');\n accordionTrigger.setAttribute('data-state', 'closed');\n\n // Update data-state on content\n accordionContent.setAttribute('data-state', 'closed');\n\n // Update SVG icons\n svgIcons.forEach((svg) => svg.setAttribute('data-state', 'closed'));\n\n // Disable trigger during animation\n accordionTrigger.disabled = true;\n\n // Start close animation\n accordionContent.style.height = `${accordionContent.scrollHeight}px`;\n\n requestAnimationFrame(() => {\n accordionContent.style.height = '0px';\n });\n\n // Remove 'data-[state=open]:my-4' class if necessary\n accordionContent.classList.remove('my-4');\n\n // After animation completes\n accordionContent.addEventListener(\n 'transitionend',\n function handler() {\n accordionContent.classList.add('h-0');\n accordionContent.style.height = '';\n accordionTrigger.disabled = false;\n accordionContent.removeEventListener('transitionend', handler);\n },\n { once: true },\n );\n}\n\nfunction openAccordion(accordionItem: HTMLElement) {\n const accordionTrigger = accordionItem.querySelector(\n '[data-accordion-trigger]',\n );\n const accordionContent = accordionItem.querySelector(\n '[data-accordion-content]',\n );\n\n if (!accordionTrigger || !accordionContent) return;\n\n const svgIcons = accordionTrigger.querySelectorAll('svg');\n\n // Update ARIA attributes and data-state on both item and trigger\n accordionItem.setAttribute('data-state', 'open');\n accordionTrigger.setAttribute('aria-expanded', 'true');\n accordionTrigger.setAttribute('data-state', 'open');\n\n // Update data-state on content\n accordionContent.setAttribute('data-state', 'open');\n\n // Update SVG icons\n svgIcons.forEach((svg) => svg.setAttribute('data-state', 'open'));\n\n // Disable trigger during animation\n accordionTrigger.disabled = true;\n\n // Remove 'h-0' class to allow expansion\n accordionContent.classList.remove('h-0');\n\n // Add 'my-4' class if necessary\n accordionContent.classList.add('my-4');\n\n // Start open animation\n accordionContent.style.height = '0px';\n\n // Force reflow to apply the height change\n accordionContent.getBoundingClientRect();\n\n const contentHeight = accordionContent.scrollHeight;\n accordionContent.style.height = `${contentHeight}px`;\n\n // After animation completes\n accordionContent.addEventListener(\n 'transitionend',\n function handler() {\n accordionContent.style.height = '';\n accordionTrigger.disabled = false;\n accordionContent.removeEventListener('transitionend', handler);\n },\n { once: true },\n );\n}\n"],"names":["initAccordion","accordion","_a","accordionItems","enableMultiple","item","accordionTrigger","toggleAccordionItem","closeAccordion","openAccordion","otherItem","accordionItem","accordionContent","svgIcons","svg","handler","contentHeight"],"mappings":"AAAO,SAASA,GAAgB,CAEX,SAAS,iBAAiB,kBAAkB,EAEpD,QAASC,GAAc,CAJ7B,IAAAC,EAKH,MAAMC,EAAiBF,EAAU,iBAC/B,uBACF,E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