document.addEventListener("DOMContentLoaded", function () { const questions = { 1: [ { text: "Durée d'exercice professionnel avant retraite supérieure à 7 ans ?", next: 1, stop: 'stop' }, { text: "Bénéfice en BNC supérieur à 60 000 € ?", next: 2, stop: 'stop' }, { text: "Votre impôt sur le revenu annuel est supérieur à 7 000 € ?", next: 'contact', stop: 'stop' } ], 2: [ { text: "Votre société est-elle en capacité de verser un dividende?", next: 1, stop: 'stop' }, { text: "Quelle stratégie poursuivez-vous?", options: [ { text: "Vente à soi-même pour récupérer du cash", next: 'contact' }, { text: "Acquisition de parts sociales d'une SEL", next: 'contact' }, { text: "Préparation de l'avenir pour une vente-réinstallation", next: 'contact' }, { text: "Autre", next: 'stop' } ] } ], 3: [ { text: "Première question du troisième questionnaire?", next: 1, stop: 'stop' }, { text: "Deuxième question du troisième questionnaire?", next: 2, stop: 'stop' }, { text: "Troisième question du troisième questionnaire?", next: 'contact', stop: 'stop' } ] }; function displayQuestion(section, questionIndex) { const questionnaireContainer = document.getElementById(`questionnaire${section}`); questionnaireContainer.innerHTML = ""; if (questionIndex < questions[section].length) { const questionData = questions[section][questionIndex]; const questionText = document.createElement('p'); questionText.textContent = questionData.text; questionnaireContainer.appendChild(questionText); if (questionData.options) { questionData.options.forEach((option) => { const button = document.createElement('button'); button.textContent = option.text; button.onclick = () => handleResponse(section, option.next); questionnaireContainer.appendChild(button); }); } else { const yesButton = document.createElement('button'); yesButton.textContent = "Oui"; yesButton.onclick = () => handleResponse(section, questionData.next); questionnaireContainer.appendChild(yesButton); const noButton = document.createElement('button'); noButton.textContent = "Non"; noButton.onclick = () => handleResponse(section, questionData.stop); questionnaireContainer.appendChild(noButton); } } } function handleResponse(section, nextStep) { console.log(`Handling response for section ${section}, next step: ${nextStep}`); if (nextStep === 'contact') { showContactForm(section); } else if (nextStep === 'stop') { showThankYouMessage(section); } else { displayQuestion(section, nextStep); } } function showContactForm(section) { console.log(`Showing contact form for section ${section}`); const formElement = document.getElementById(`form${section}`); const questionnaireContainer = document.getElementById(`questionnaire${section}`); if (formElement) { formElement.style.display = 'block'; questionnaireContainer.style.display = 'none'; } else { console.error(`Form element with id form${section} not found`); } } function showThankYouMessage(section) { const questionnaireContainer = document.getElementById(`questionnaire${section}`); if (section == 1) { questionnaireContainer.innerHTML = "

Non concerné par le passage en société

"; } else { questionnaireContainer.innerHTML = "

Non concerné par la création d'une holding

"; } } function startQuestionnaire(section) { console.log(`Starting questionnaire for section ${section}`); const formElement = document.getElementById(`form${section}`); const questionnaireContainer = document.getElementById(`questionnaire${section}`); if (formElement) { questionnaireContainer.style.display = 'block'; formElement.style.display = 'none'; } else { console.error(`Form element with id form${section} not found`); } displayQuestion(section, 0); } document.querySelectorAll('.accordion-button').forEach((button, index) => { button.addEventListener('click', () => { const section = index + 1; const collapseElement = document.getElementById(`collapse${section}`); collapseElement.addEventListener('shown.bs.collapse', () => startQuestionnaire(section), { once: true }); }); }); startQuestionnaire(1); });