{"version":3,"file":"language_dropdown_controller-CSvoj3_y.js","names":[],"sources":["../../../app/javascript/entrypoints/controllers/language_dropdown_controller.js"],"sourcesContent":["// app/javascript/controllers/language_dropdown_controller.js\nimport { Controller } from \"@hotwired/stimulus\";\n\nexport default class extends Controller {\n static targets = [\"menu\", \"arrow\", \"currentFlag\"];\n static values = { language: String };\n\n connect() {\n console.log(\"Language dropdown controller connected\");\n // Fermer le menu si on clique ailleurs\n document.addEventListener(\"click\", this.closeOnClickOutside.bind(this));\n }\n\n disconnect() {\n document.removeEventListener(\"click\", this.closeOnClickOutside.bind(this));\n }\n\n closeOnClickOutside(event) {\n if (\n !this.element.contains(event.target) &&\n !this.menuTarget.classList.contains(\"hidden\")\n ) {\n this.closeMenu();\n }\n }\n\n toggle(event) {\n event.stopPropagation();\n\n if (this.menuTarget.classList.contains(\"hidden\")) {\n this.openMenu();\n } else {\n this.closeMenu();\n }\n }\n\n openMenu() {\n this.menuTarget.classList.remove(\"hidden\");\n this.arrowTarget.classList.add(\"rotate-180\");\n this.arrowTarget.classList.add(\"transform\");\n this.arrowTarget.classList.add(\"transition-transform\");\n }\n\n closeMenu() {\n this.menuTarget.classList.add(\"hidden\");\n this.arrowTarget.classList.remove(\"rotate-180\");\n }\n\n changeLanguage(event) {\n const selectedLanguage =\n event.currentTarget.dataset.languageDropdownLanguageValue;\n\n // 1. Changer le drapeau affiché dans le bouton principal\n const selectedFlag = event.currentTarget\n .querySelector(\"img\")\n .cloneNode(true);\n this.currentFlagTarget.replaceWith(selectedFlag);\n this.currentFlagTarget = selectedFlag;\n this.currentFlagTarget.classList.add(\"fr\"); // Garder la classe fr pour le style\n\n // 2. Fermer le menu après sélection\n this.closeMenu();\n\n // 3. Mettre à jour la locale dans l'application\n // (Si intégration avec I18n est souhaitée)\n const url = new URL(window.location);\n url.searchParams.set(\"locale\", selectedLanguage);\n window.location.href = url.toString();\n\n // Vous pouvez aussi envoyer une requête AJAX à la place pour éviter de recharger la page\n // fetch(`/set_locale?locale=${selectedLanguage}`, { method: 'POST', headers: { 'X-CSRF-Token': document.querySelector('meta[name=\"csrf-token\"]').content } })\n }\n}\n"],"mappings":"4GAGA,EAAA,cAA6B,CAAW,CACtC,OAAO,QAAU,CAAC,OAAQ,QAAS,cAAc,CACjD,OAAO,OAAS,CAAE,SAAU,OAAQ,CAEpC,SAAU,CACR,QAAQ,IAAI,yCAAyC,CAErD,SAAS,iBAAiB,QAAS,KAAK,oBAAoB,KAAK,KAAK,CAAC,CAGzE,YAAa,CACX,SAAS,oBAAoB,QAAS,KAAK,oBAAoB,KAAK,KAAK,CAAC,CAG5E,oBAAoB,EAAO,CAEvB,CAAC,KAAK,QAAQ,SAAS,EAAM,OAAO,EACpC,CAAC,KAAK,WAAW,UAAU,SAAS,SAAS,EAE7C,KAAK,WAAW,CAIpB,OAAO,EAAO,CACZ,EAAM,iBAAiB,CAEnB,KAAK,WAAW,UAAU,SAAS,SAAS,CAC9C,KAAK,UAAU,CAEf,KAAK,WAAW,CAIpB,UAAW,CACT,KAAK,WAAW,UAAU,OAAO,SAAS,CAC1C,KAAK,YAAY,UAAU,IAAI,aAAa,CAC5C,KAAK,YAAY,UAAU,IAAI,YAAY,CAC3C,KAAK,YAAY,UAAU,IAAI,uBAAuB,CAGxD,WAAY,CACV,KAAK,WAAW,UAAU,IAAI,SAAS,CACvC,KAAK,YAAY,UAAU,OAAO,aAAa,CAGjD,eAAe,EAAO,CACpB,IAAM,EACJ,EAAM,cAAc,QAAQ,8BAGxB,EAAe,EAAM,cACxB,cAAc,MAAM,CACpB,UAAU,GAAK,CAClB,KAAK,kBAAkB,YAAY,EAAa,CAChD,KAAK,kBAAoB,EACzB,KAAK,kBAAkB,UAAU,IAAI,KAAK,CAG1C,KAAK,WAAW,CAIhB,IAAM,EAAM,IAAI,IAAI,OAAO,SAAS,CACpC,EAAI,aAAa,IAAI,SAAU,EAAiB,CAChD,OAAO,SAAS,KAAO,EAAI,UAAU"}