{"version":3,"file":"countdown_controller-DiFLBQAe.js","names":[],"sources":["../../../app/javascript/entrypoints/controllers/countdown_controller.js"],"sourcesContent":["import { Controller } from \"@hotwired/stimulus\"\n\nexport default class extends Controller {\n static targets = [\"days\", \"hours\", \"minutes\", \"seconds\"]\n static values = { launchDate: String }\n\n connect() {\n console.log(\"Countdown controller connected\")\n\n // Utiliser une date fixe (par défaut le 31 mars 2025 si non spécifiée)\n let targetDate;\n\n if (this.hasLaunchDateValue && this.launchDateValue) {\n // Utiliser la date fournie via l'attribut data-countdown-launch-date-value\n targetDate = new Date(this.launchDateValue);\n console.log(\"Using provided launch date:\", targetDate);\n } else {\n // Date fixe par défaut (31 mars 2025)\n targetDate = new Date(2025, 3, 5, 12, 0, 0); // 31 mars 2025 à midi\n console.log(\"Using default launch date:\", targetDate);\n }\n\n // Vérifier que la date est valide\n if (isNaN(targetDate.getTime())) {\n console.error(\"Invalid date format. Using fallback date.\");\n targetDate = new Date();\n targetDate.setMonth(targetDate.getMonth() + 1);\n }\n\n this.targetDate = targetDate;\n\n // Démarrer immédiatement\n this.updateCountdown();\n\n // Puis toutes les secondes\n this.interval = setInterval(() => this.updateCountdown(), 1000);\n }\n\n disconnect() {\n if (this.interval) clearInterval(this.interval);\n }\n\n updateCountdown() {\n const now = new Date();\n const diff = this.targetDate - now;\n\n // Si la date est déjà passée\n if (diff < 0) {\n this.daysTarget.textContent = \"00\";\n this.hoursTarget.textContent = \"00\";\n this.minutesTarget.textContent = \"00\";\n this.secondsTarget.textContent = \"00\";\n\n // Arrêter le compte à rebours\n if (this.interval) {\n clearInterval(this.interval);\n this.interval = null;\n }\n return;\n }\n\n const days = Math.floor(diff / (1000 * 60 * 60 * 24));\n const hours = Math.floor((diff % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));\n const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));\n const seconds = Math.floor((diff % (1000 * 60)) / 1000);\n\n this.daysTarget.textContent = String(days).padStart(2, '0');\n this.hoursTarget.textContent = String(hours).padStart(2, '0');\n this.minutesTarget.textContent = String(minutes).padStart(2, '0');\n this.secondsTarget.textContent = String(seconds).padStart(2, '0');\n }\n}\n"],"mappings":"4GAEA,EAAA,cAA6B,CAAW,CACpC,OAAO,QAAU,CAAC,OAAQ,QAAS,UAAW,UAAU,CACxD,OAAO,OAAS,CAAE,WAAY,OAAQ,CAEtC,SAAU,CACN,QAAQ,IAAI,iCAAiC,CAG7C,IAAI,EAEA,KAAK,oBAAsB,KAAK,iBAEhC,EAAa,IAAI,KAAK,KAAK,gBAAgB,CAC3C,QAAQ,IAAI,8BAA+B,EAAW,GAGtD,EAAa,IAAI,KAAK,KAAM,EAAG,EAAG,GAAI,EAAG,EAAE,CAC3C,QAAQ,IAAI,6BAA8B,EAAW,EAIrD,MAAM,EAAW,SAAS,CAAC,GAC3B,QAAQ,MAAM,4CAA4C,CAC1D,EAAa,IAAI,KACjB,EAAW,SAAS,EAAW,UAAU,CAAG,EAAE,EAGlD,KAAK,WAAa,EAGlB,KAAK,iBAAiB,CAGtB,KAAK,SAAW,gBAAkB,KAAK,iBAAiB,CAAE,IAAK,CAGnE,YAAa,CACL,KAAK,UAAU,cAAc,KAAK,SAAS,CAGnD,iBAAkB,CACd,IAAM,EAAM,IAAI,KACV,EAAO,KAAK,WAAa,EAG/B,GAAI,EAAO,EAAG,CACV,KAAK,WAAW,YAAc,KAC9B,KAAK,YAAY,YAAc,KAC/B,KAAK,cAAc,YAAc,KACjC,KAAK,cAAc,YAAc,KAGjC,AAEI,KAAK,YADL,cAAc,KAAK,SAAS,CACZ,MAEpB,OAGJ,IAAM,EAAO,KAAK,MAAM,GAAQ,IAAO,GAAK,GAAK,IAAI,CAC/C,EAAQ,KAAK,MAAO,GAAQ,IAAO,GAAK,GAAK,KAAQ,IAAO,GAAK,IAAI,CACrE,EAAU,KAAK,MAAO,GAAQ,IAAO,GAAK,KAAQ,IAAO,IAAI,CAC7D,EAAU,KAAK,MAAO,GAAQ,IAAO,IAAO,IAAK,CAEvD,KAAK,WAAW,YAAc,OAAO,EAAK,CAAC,SAAS,EAAG,IAAI,CAC3D,KAAK,YAAY,YAAc,OAAO,EAAM,CAAC,SAAS,EAAG,IAAI,CAC7D,KAAK,cAAc,YAAc,OAAO,EAAQ,CAAC,SAAS,EAAG,IAAI,CACjE,KAAK,cAAc,YAAc,OAAO,EAAQ,CAAC,SAAS,EAAG,IAAI"}