document.addEventListener('DOMContentLoaded', function() { const form = document.getElementById('troubleshootForm'); const resultsContainer = document.getElementById('resultsContainer'); const solutionsList = document.getElementById('solutionsList'); // Database of solutions and PDF documents const solutionsDatabase = { "pdf": [ { title: "User Manual", description: "Complete user manual for your coffee machine", pdfUrl: "/manuals/user-manual.pdf", difficulty: "Easy", time: "Varies" }, { title: "Installation Guide", description: "Step-by-step installation instructions", pdfUrl: "/manuals/installation-guide.pdf", difficulty: "Medium", time: "30 minutes" }, { title: "Troubleshooting Guide", description: "Comprehensive troubleshooting reference", pdfUrl: "/manuals/troubleshooting-guide.pdf", difficulty: "Easy", time: "Varies" }, { title: "Cleaning Instructions", description: "Detailed cleaning and maintenance procedures", pdfUrl: "/manuals/cleaning-instructions.pdf", difficulty: "Medium", time: "20 minutes" } ], "no power": [ { title: "Check Power Connection", description: "Ensure the machine is properly plugged into a working power outlet. Try a different outlet to rule out electrical issues.", steps: [ "Unplug the machine from the power source", "Check the power cord for any visible damage", "Plug into a different outlet", "Try turning the machine on again" ], difficulty: "Easy", time: "2 minutes" }, { title: "Reset Circuit Breaker", description: "The machine may have tripped an internal circuit breaker. Locate and reset the breaker switch.", steps: [ "Locate the circuit breaker (usually at the back or bottom of the machine)", "Press the reset button if available", "Wait 30 seconds before turning the machine back on" ], difficulty: "Medium", time: "5 minutes" } ], "no water flow": [ { title: "Check Water Tank", description: "Ensure the water tank is properly seated and filled with fresh water.", steps: [ "Remove and reinsert the water tank", "Fill with fresh, cold water", "Ensure tank is properly seated in its position" ], difficulty: "Easy", time: "1 minute" }, { title: "Descale the Machine", description: "Mineral buildup may be blocking water flow. Perform a descaling cycle.", steps: [ "Prepare descaling solution as per manufacturer instructions", "Run descaling cycle", "Rinse thoroughly with fresh water" ], difficulty: "Medium", time: "20 minutes" } ], "weak coffee": [ { title: "Adjust Grind Size", description: "If using fresh beans, try a finer grind setting for stronger extraction.", steps: [ "Access grind settings (consult your manual for location)", "Adjust to a finer setting", "Brew a test shot and adjust further if needed" ], difficulty: "Easy", time: "3 minutes" }, { title: "Clean Brew Group", description: "Coffee oils and residue can affect flavor. Clean the brew group thoroughly.", steps: [ "Remove brew group according to manual instructions", "Clean with warm water and soft brush", "Dry completely before reinserting" ], difficulty: "Medium", time: "10 minutes" } ] }; form.addEventListener('submit', function(e) { e.preventDefault(); const machineModel = document.getElementById('machineModel').value; const issueDescription = document.getElementById('issueDescription').value.toLowerCase(); // Simple keyword matching (in a real app, this would be more sophisticated) let matchedSolutions = []; if (issueDescription.includes('power') || issueDescription.includes('turn on')) { matchedSolutions = matchedSolutions.concat(solutionsDatabase['no power']); } if (issueDescription.includes('water') || issueDescription.includes('flow')) { matchedSolutions = matchedSolutions.concat(solutionsDatabase['no water flow']); } if (issueDescription.includes('weak') || issueDescription.includes('taste') || issueDescription.includes('flavor')) { matchedSolutions = matchedSolutions.concat(solutionsDatabase['weak coffee']); } // Enhanced PDF guide search const pdfKeywords = ['manual', 'guide', 'document', 'pdf', 'instructions', 'reference', 'tutorial', 'quick fix', 'troubleshoot', 'how to', 'help', 'support', 'fix', 'solution']; if (pdfKeywords.some(keyword => issueDescription.includes(keyword))) { matchedSolutions = matchedSolutions.concat(solutionsDatabase['pdf']); } else { // Also show PDF guides for any technical issue const technicalKeywords = ['power', 'water', 'flow', 'weak', 'taste', 'flavor', 'leak', 'noise', 'error', 'code', 'not working', 'broken', 'issue', 'problem']; if (technicalKeywords.some(keyword => issueDescription.includes(keyword))) { matchedSolutions = matchedSolutions.concat(solutionsDatabase['pdf'].filter(pdf => pdf.title.toLowerCase().includes('troubleshooting') || pdf.title.toLowerCase().includes('guide') )); } } // If no matches, show a generic message if (matchedSolutions.length === 0) { matchedSolutions.push({ title: "No Exact Match Found", description: "We couldn't find an exact match for your issue, but here are some general troubleshooting steps:", steps: [ "Turn the machine off and unplug it for 2 minutes, then restart", "Check all connections and water reservoirs", "Consult your user manual for model-specific guidance", "Contact our support team for further assistance" ], difficulty: "Varies", time: "Varies" }); } // Display solutions displaySolutions(matchedSolutions); }); function displaySolutions(solutions) { solutionsList.innerHTML = ''; solutions.forEach((solution, index) => { const solutionElement = document.createElement('div'); solutionElement.className = `solution-card bg-gray-50 rounded-lg p-6 border border-gray-200`; solutionElement.style.animationDelay = `${index * 0.1}s`; solutionElement.innerHTML = `

${solution.title}

${solution.difficulty} ${solution.time}

${solution.description}

Steps:

    ${solution.steps.map(step => `
  1. ${step}
  2. `).join('')}
${solution.pdfUrl ? `

Quick Fix Guide:

${solution.title}
Open Full Screen Download
` : ''} ${index < solutions.length - 1 ? '
' : ''} `; solutionsList.appendChild(solutionElement); }); resultsContainer.classList.remove('hidden'); resultsContainer.scrollIntoView({ behavior: 'smooth' }); } });