/**
 * HTML Report Footer Module
 * Generates footer with metadata, timing information, and resources
 */
import { formatDuration } from '../../utils/formatters.js';
import { TOOL_METADATA } from '../../utils/constants.js';
/**
 * Generate the HTML footer section
 *
 * @param {number} analysisTime - Analysis execution time in milliseconds
 * @param {string} toolVersion - Version of the tool
 * @returns {string} HTML footer element
 *
 * @description
 * Creates a footer containing:
 * - Analysis execution time
 * - Tool version information
 * - Metadata
 * - Generation timestamp
 */
export function generateFooter(analysisTime, toolVersion) {
    const formattedTime = formatDuration(analysisTime);
    return `<footer class="footer">
  <p>Analysis completed in ${formattedTime} | Tool v${toolVersion}</p>
  <div class="footer-meta">
    <small>This report was generated by Quality Validator</small>
  </div>
</footer>`;
}
/**
 * Generate metadata section
 *
 * @param {string} timestamp - ISO timestamp of generation
 * @param {string} projectPath - Path to analyzed project
 * @param {string} nodeVersion - Node.js version used
 * @returns {string} HTML metadata section
 *
 * @description
 * Creates a metadata display with:
 * - Generation timestamp
 * - Project path
 * - Node.js version
 * - Environment information
 */
export function generateMetadataSection(timestamp, projectPath, nodeVersion) {
    const date = new Date(timestamp);
    const formattedDate = date.toLocaleString();
    return `<section class="section">
  <h2>Report Metadata</h2>
  <div class="metrics-grid">
    <div class="metric">
      <div class="metric-label">Generated</div>
      <div class="metric-value">${formattedDate}</div>
    </div>
    <div class="metric">
      <div class="metric-label">Project Path</div>
      <div class="metric-value"><code>${projectPath}</code></div>
    </div>
    <div class="metric">
      <div class="metric-label">Node Version</div>
      <div class="metric-value"><code>${nodeVersion}</code></div>
    </div>
    <div class="metric">
      <div class="metric-label">Tool Version</div>
      <div class="metric-value">v${TOOL_METADATA.VERSION}</div>
    </div>
  </div>
</section>`;
}
/**
 * Generate script section for interactivity
 *
 * @returns {string} JavaScript code as script tag content
 *
 * @description
 * Provides:
 * - DOM ready logging
 * - Click handlers for expandable sections
 * - Print stylesheet support
 */
export function generateScript() {
    return `
// Report initialization
document.addEventListener('DOMContentLoaded', function() {
  console.log('Quality Validation Report loaded');

  // Add print support
  if (window.print) {
    const printStyle = document.createElement('style');
    printStyle.textContent = '@media print { .header { page-break-after: avoid; } .section { page-break-inside: avoid; } }';
    document.head.appendChild(printStyle);
  }

  // Add collapse functionality to findings groups
  const groups = document.querySelectorAll('.findings-group');
  groups.forEach(group => {
    const title = group.querySelector('h3');
    if (title) {
      title.style.cursor = 'pointer';
      title.addEventListener('click', function() {
        const items = group.querySelectorAll('.finding');
        items.forEach(item => {
          item.style.display = item.style.display === 'none' ? 'block' : 'none';
        });
      });
    }
  });
});
  `;
}
/**
 * Generate a resources/links section
 *
 * @returns {string} HTML section with helpful resources
 *
 * @description
 * Provides:
 * - Link to tool documentation
 * - Link to configuration guide
 * - Suggestion for next steps
 */
export function generateResourcesSection() {
    return `<section class="section">
  <h2>Resources & Next Steps</h2>
  <div class="card">
    <h3>For More Information</h3>
    <ul>
      <li>Review findings and prioritize remediation efforts</li>
      <li>Follow recommendations to improve code quality</li>
      <li>Increase test coverage to improve reliability</li>
      <li>Refactor complex functions for better maintainability</li>
      <li>Address security issues immediately</li>
    </ul>

    <h3>Configuration</h3>
    <p>Create a <code>.qualityrc.json</code> file in your project root to customize quality checks.</p>

    <h3>Continuous Integration</h3>
    <p>Integrate this tool into your CI/CD pipeline to catch issues early and maintain code quality over time.</p>
  </div>
</section>`;
}
/**
 * Generate legend/help section explaining report elements
 *
 * @returns {string} HTML section with legend information
 *
 * @description
 * Explains:
 * - Grading system (A-F)
 * - Severity levels
 * - Score ranges
 */
export function generateLegendSection() {
    return `<section class="section">
  <h2>Report Legend</h2>
  <div class="card">
    <h3>Grades</h3>
    <ul>
      <li><strong>A (90-100):</strong> Excellent code quality - exceeds expectations</li>
      <li><strong>B (80-89):</strong> Good code quality - meets expectations</li>
      <li><strong>C (70-79):</strong> Acceptable code quality - areas for improvement</li>
      <li><strong>D (60-69):</strong> Poor code quality - significant issues</li>
      <li><strong>F (&lt;60):</strong> Failing code quality - critical issues</li>
    </ul>

    <h3>Finding Severity Levels</h3>
    <ul>
      <li><strong>Critical:</strong> Immediate action required - security or major issues</li>
      <li><strong>High:</strong> Should be fixed soon - significant impact on code quality</li>
      <li><strong>Medium:</strong> Should be addressed - moderate impact</li>
      <li><strong>Low:</strong> Nice to fix - minor impact</li>
      <li><strong>Info:</strong> Informational - notes and suggestions</li>
    </ul>

    <h3>Recommendation Priority</h3>
    <ul>
      <li><strong>Critical:</strong> Must implement immediately</li>
      <li><strong>High:</strong> Should implement in next sprint</li>
      <li><strong>Medium:</strong> Can be planned for later</li>
      <li><strong>Low:</strong> Nice to have improvements</li>
    </ul>
  </div>
</section>`;
}
