/**
 * Solutions library — maps every issue type to a fix explanation
 * Used by the dashboard to show developers exactly what to do
 */
const solutions = {
  'server-error': {
    title: 'Fix server error (HTTP 5xx)',
    steps: [
      'Check your server error logs immediately',
      'On WordPress: go to WP Admin → Tools → Site Health',
      'On CodeIgniter/Laravel: check application/logs/ folder',
      'On Node.js: run pm2 logs to see crash output',
      'Common causes: database connection failed, missing config file, out of memory'
    ],
    links: []
  },
  'not-found': {
    title: 'Fix 404 — page not found',
    steps: [
      'Check if the page was deleted or the URL changed',
      'Set up a 301 redirect from the old URL to the new one',
      'On WordPress: Settings → Permalinks → Save Changes (rebuilds .htaccess)',
      'On Apache: add "Redirect 301 /old-page /new-page" to .htaccess',
      'On Nginx: add "return 301 /new-page;" inside the location block',
      'On Node.js/Express: add a redirect route before your 404 handler'
    ],
    links: []
  },
  'http-error': {
    title: 'Fix HTTP error (4xx)',
    steps: [
      'Check the exact status code — 401 means login required, 403 means permission denied',
      'For 403: check folder/file permissions (should be 755 for folders, 644 for files)',
      'For 401: ensure authentication is set up correctly or remove the auth requirement',
      'Check your .htaccess file for any deny rules that may be too broad'
    ],
    links: []
  },
  'very-slow-load': {
    title: 'Fix critically slow page (>6s)',
    steps: [
      'Install a caching plugin immediately — on WordPress use WP Rocket or W3 Total Cache',
      'Enable Gzip compression on your server',
      'Optimize and compress all images on this page (use TinyPNG or ShortPixel)',
      'Check if database queries are slow — look for N+1 query problems',
      'Enable a CDN (Cloudflare free plan works well)',
      'Check if any external scripts are blocking page load (Google Fonts, analytics, etc.)'
    ],
    links: []
  },
  'slow-load': {
    title: 'Fix slow page load (>3s)',
    steps: [
      'Enable browser caching — add Cache-Control headers to your server config',
      'Compress images — aim for under 200KB per image',
      'Minify CSS and JavaScript files',
      'On WordPress: use WP Rocket, Autoptimize, or similar caching plugin',
      'Lazy load images that are below the fold',
      'Remove unused CSS/JS plugins'
    ],
    links: []
  },
  'console-error': {
    title: 'Fix browser console error',
    steps: [
      'Open Chrome DevTools (F12) → Console tab and reproduce the exact error',
      'If it says "Failed to load resource": check if the file path/URL is correct',
      'If it says "is not defined": a JavaScript file is missing or loading in wrong order',
      'If it says "CORS error": the server needs to allow cross-origin requests',
      'Fix the specific file or script mentioned in the error message',
      'After fixing, reload the page and confirm the error is gone from console'
    ],
    links: []
  },
  'js-error': {
    title: 'Fix JavaScript crash',
    steps: [
      'This is a critical bug — JavaScript has crashed on this page',
      'Open Chrome DevTools (F12) → Console tab and look for the red error',
      'Common cause: trying to use a variable or element that does not exist yet',
      'Wrap the code in a null check: if (element) { element.doSomething(); }',
      'Check if all required JS libraries are loaded before your custom scripts',
      'Look at the line number in the error — go directly to that line in your code'
    ],
    links: []
  },
  'failed-resource': {
    title: 'Fix failed resource load',
    steps: [
      'The file (CSS/JS/image) URL is wrong or the file does not exist',
      'Check the exact URL in the error — open it directly in a browser tab',
      'If it is a missing file: re-upload it to the correct location',
      'If the path is wrong: update the link in your HTML/template',
      'On WordPress: deactivate plugins one by one to find which one is causing it',
      'Clear all caches after fixing'
    ],
    links: []
  },
  'broken-image': {
    title: 'Fix broken image',
    steps: [
      'The image file is missing, deleted, or the path is wrong',
      'Open the image URL directly in a browser — if you see a 404 the file is gone',
      'Re-upload the image to the correct folder on your server',
      'Check the img src path in your HTML/template and correct it',
      'On WordPress: go to Media Library and re-upload the missing image',
      'Use Find & Replace in your database to fix wrong image paths in bulk'
    ],
    links: []
  },
  'missing-title': {
    title: 'Fix missing page title',
    steps: [
      'Add a unique <title> tag inside the <head> section of your HTML',
      'Example: <title>About Us — Your Company Name</title>',
      'On WordPress: install Yoast SEO or RankMath and set the title for this page',
      'On CodeIgniter/Laravel: add title to your view or master layout',
      'Each page should have a unique, descriptive title (50–60 characters)'
    ],
    links: []
  },
  'missing-meta-desc': {
    title: 'Add meta description',
    steps: [
      'Add inside <head>: <meta name="description" content="Your page description here">',
      'Keep it between 120–160 characters',
      'On WordPress: use Yoast SEO plugin — it adds a meta description field to every page',
      'Write a unique description for each page that describes the content clearly',
      'This improves Google click-through rates significantly'
    ],
    links: []
  },
  'missing-viewport': {
    title: 'Fix missing viewport tag (mobile unfriendly)',
    steps: [
      'Add this line inside your <head> section on every page:',
      '<meta name="viewport" content="width=device-width, initial-scale=1.0">',
      'On WordPress: this should be in your theme header.php — check if your theme supports it',
      'On CodeIgniter/Laravel: add it to your master layout file',
      'Without this tag your site will appear zoomed out on all mobile devices'
    ],
    links: []
  },
  'desktop-overflow': {
    title: 'Fix horizontal scroll on desktop',
    steps: [
      'Open Chrome DevTools (F12) and use the Inspector to find the overflowing element',
      'Add this CSS temporarily to find the culprit: * { border: 1px solid red; }',
      'Common causes: an element with a fixed pixel width wider than the screen',
      'Fix: replace fixed widths with max-width: 100% or use percentage widths',
      'Check for any element with overflow: visible that is wider than its container',
      'Also check for long unbreakable text — add word-wrap: break-word to fix it'
    ],
    links: []
  },
  'mobile-overflow': {
    title: 'Fix horizontal scroll on mobile',
    steps: [
      'Open Chrome DevTools → Toggle device toolbar (Ctrl+Shift+M) and set width to 375px',
      'Add overflow-x: hidden to the body tag as a quick fix',
      'Find the element causing overflow — check images, tables, and fixed-width divs',
      'Make images responsive: img { max-width: 100%; height: auto; }',
      'Check your navigation menu — it often breaks on mobile if not properly handled',
      'Use a CSS media query to adjust widths for screens below 768px'
    ],
    links: []
  },
  'form-no-submit': {
    title: 'Fix form with no submit button',
    steps: [
      'Add a submit button inside the form element',
      'Example: <button type="submit">Send Message</button>',
      'Or use: <input type="submit" value="Send Message">',
      'Make sure the button is inside the <form> tags, not outside',
      'Check if a button exists but has an incorrect type attribute'
    ],
    links: []
  },
  'form-accessibility': {
    title: 'Fix form fields with no labels',
    steps: [
      'Every input field must have a visible label connected to it',
      'Example: <label for="email">Email address</label><input id="email" type="email">',
      'The "for" attribute on label must match the "id" attribute on the input',
      'If you cannot show a visible label, at minimum add a placeholder attribute',
      'This is also required for accessibility (screen readers) and Google ranking'
    ],
    links: []
  },
  'insecure-form': {
    title: 'Fix password field on non-HTTPS page — URGENT',
    steps: [
      'This is a serious security issue — passwords are being sent unencrypted',
      'Install an SSL certificate on your server immediately',
      'GoDaddy provides free SSL — go to your GoDaddy hosting dashboard and enable it',
      'Or use a free Let\'s Encrypt certificate: sudo certbot --nginx',
      'After SSL is active, redirect all HTTP traffic to HTTPS in your .htaccess or Nginx config',
      'Never collect passwords, credit cards, or personal data over HTTP'
    ],
    links: []
  },
  'mixed-content': {
    title: 'Fix mixed content (HTTP resources on HTTPS page)',
    steps: [
      'Your page is HTTPS but loading some resources over HTTP — browsers block these',
      'Find all http:// URLs in your HTML, CSS, and JS and change them to https://',
      'On WordPress: go to Settings → General and update both URLs to https://',
      'Install the "Really Simple SSL" plugin on WordPress for automatic fixing',
      'Use Chrome DevTools → Console to see exactly which resources are blocked',
      'If an external resource does not support HTTPS, find an alternative that does'
    ],
    links: []
  },
  'empty-section': {
    title: 'Fix empty visible section',
    steps: [
      'A section/block on this page appears to have no content',
      'Check if dynamic content (from a CMS or database) failed to load',
      'On WordPress: check if the widget or block has content in the editor',
      'Check if the content is hidden by a CSS error (color same as background, etc.)',
      'If the section is not needed, remove it from the template to avoid blank space'
    ],
    links: []
  },
  'load-failed': {
    title: 'Fix page that could not be loaded',
    steps: [
      'The page timed out or refused connection entirely',
      'Check if the URL is correct and the page exists',
      'Check if your server is running and not overloaded',
      'Check your firewall — the port may be blocked',
      'Try opening the URL manually in a browser to confirm'
    ],
    links: []
  }
};

module.exports = solutions;

// Append new solution types
const newSolutions = {
  'invisible-button': {
    title: 'Fix hidden or zero-size button',
    steps: ['Open Chrome DevTools (F12) and inspect the button element','Check if display:none, visibility:hidden or opacity:0 is applied','Check if width or height is set to 0','Remove the hiding CSS or fix the dimensions','Test the button is visible and clickable on all screen sizes']
  },
  'dead-link': {
    title: 'Fix dead link (href="#")',
    steps: ['Find the link in your HTML/template','Replace href="#" with the actual destination URL','If it is a button that runs JavaScript, use a button element instead of an anchor tag','If the page does not exist yet, either remove the link or add a coming soon page']
  },
  'non-clickable-phone': {
    title: 'Make phone number clickable',
    steps: ['Wrap the phone number in a tel: link','Example: <a href="tel:+919876543210">+91 98765 43210</a>','This allows mobile users to tap and call directly','Do this for every phone number visible on the page']
  },
  'non-clickable-email': {
    title: 'Make email address clickable',
    steps: ['Wrap the email in a mailto: link','Example: <a href="mailto:hello@example.com">hello@example.com</a>','This allows users to click and open their email client directly','Do this for every email address visible on the page']
  },
  'missing-alt': {
    title: 'Add alt text to images',
    steps: ['Add an alt attribute to every img tag','Example: <img src="photo.jpg" alt="Team photo at office">','Alt text describes the image for screen readers and when image fails to load','For decorative images use empty alt: <img src="divider.png" alt="">','Keep alt text concise and descriptive (under 125 characters)']
  },
  'duplicate-id': {
    title: 'Fix duplicate element IDs',
    steps: ['Search your HTML/template for the duplicate ID','Each ID must be unique across the entire page','Change duplicates to use classes instead if multiple elements need the same style','Example: change id="header" to class="header" for repeated elements','Duplicate IDs break JavaScript, CSS targeting and accessibility']
  },
  'placeholder-text': {
    title: 'Remove placeholder/dummy text — URGENT',
    steps: ['Find and replace all placeholder text on this page immediately','Search your CMS or codebase for "Lorem ipsum" and similar text','Replace with real content from the client','Check all pages, widgets, footers and sidebars','Never send a site live with placeholder text visible to visitors']
  },
  'spelling-error': {
    title: 'Fix spelling error',
    steps: ['Find the misspelled word on the page','Correct it in your CMS, HTML or template file','Use a spell checker tool like Grammarly to proofread all content','Ask the client to review all text content before final delivery','Consider using browser spell check during content entry']
  },
  'test-email': {
    title: 'Remove test email address — URGENT',
    steps: ['Find and remove or replace the test email address immediately','Search your CMS for test@, example@, sample@ addresses','Replace with the client real email address','Check contact forms, footer, about page and header','Test the contact form to ensure real emails are delivered correctly']
  },
  'test-phone': {
    title: 'Remove test phone number — URGENT',
    steps: ['Find and remove or replace the test phone number immediately','Search your template and CMS for 000-000, 123-456, 555- patterns','Replace with the client real phone number','Check header, footer, contact page and about page','Call the number after replacing to confirm it works']
  },
  'broken-external-link': {
    title: 'Fix broken external link (404)',
    steps: ['The linked external website or page no longer exists','Find this link in your HTML/template and either remove it or update it','Search for an alternative URL for the same resource','If it is a social media link, verify the profile still exists','Use a redirect or archive link if the content has moved']
  },
  'external-link-error': {
    title: 'Fix external link error',
    steps: ['The external link is returning an error','Open the link in a browser to confirm the issue','Remove the link if the external site is permanently down','Find an alternative source for the same content','Consider linking to the Wayback Machine archive if needed']
  },
  'external-link-unreachable': {
    title: 'Fix unreachable external link',
    steps: ['The external website is not responding','Check if the site is temporarily down or permanently gone','Try opening the URL in a browser to confirm','Remove or replace the link if the site is gone','Check again in 24 hours as it may be a temporary outage']
  }
};

// Merge with existing solutions
Object.assign(solutions, newSolutions);
