/* ============================================================
   WPSiteBeam — Global Constants (Single Source of Truth)
   ============================================================
   Path: design/_constants.jsx
   Load order: MUST load BEFORE any tab module in index.html.
   Pattern: IIFE that attaches frozen objects to window.WPSB.CONSTANTS.

   Why this file exists:
   - Compliance posture (WCAG version, legal citations) appears in 20+ places
     across the codebase. Drift between those occurrences has historically
     caused liability exposure (see _PREFLIGHT-MANIFEST.md §2 history).
   - Editing this file once → all consumers update on next deploy.
   - Object.freeze() prevents accidental runtime mutation.

   When to update:
   - WCAG version change → review _WPSITEBEAM-LEGAL-NOTICES.md first.
   - Compliance deadline change → log in _PREFLIGHT-MANIFEST.md §7.
   - Anything else → ASK Jordan, do not edit without explicit OK.

   Consumers (refactor target files — Patch 6):
   - design/ADAReport.jsx  (done — reference implementation)
   - design/scanner/tab-ada.jsx
   - design/scanner/core.jsx
   - design/scanner/tab-files.jsx
   - design/ScannerData.jsx
   - design/Estimator.jsx
   - design/SiteBuilder.jsx
   - design/KitBuilder.jsx
   - design/BrainsRelay.jsx
   ============================================================ */

(function() {
  'use strict';

  if (typeof window === 'undefined') return;
  window.WPSB = window.WPSB || {};

  /* Helper: safe freeze that survives missing Object.freeze polyfills */
  var freeze = (typeof Object.freeze === 'function')
    ? function(o) { return Object.freeze(o); }
    : function(o) { return o; };

  window.WPSB.CONSTANTS = freeze({

    /* ────────────────────────────────────────────────────────
       WCAG TESTING POSTURE — LOCKED AT 2.1 AA
       ────────────────────────────────────────────────────────
       Why 2.1 AA and not 2.2:
       - HHS Section 504 (45 CFR 84.84) codifies WCAG 2.1 AA
       - DOJ ADA Title II (28 CFR 35.200) codifies WCAG 2.1 AA
       - Of 7 new WCAG 2.2 AA criteria, only 1-2 are reliably automatable
         by axe-core (Target Size 2.5.8 + partial Focus Not Obscured 2.4.11)
       - Per FTC accessiBe Settlement (2024, $1M civil penalty), claiming
         "WCAG 2.2 AA" while auto-testing 1-2 of 7 criteria replicates
         the actionable misrepresentation fact pattern
       - All client deliverables MUST cite 2.1 AA exclusively
       ──────────────────────────────────────────────────────── */
    WCAG: freeze({
      VERSION: '2.1',
      LEVEL: 'AA',
      DISPLAY: 'WCAG 2.1 AA',
      DISPLAY_LONG: 'WCAG 2.1 Level AA',
      DISPLAY_LONG_AAA: 'WCAG 2.1 Level AAA',

      /* axe-core runOnly tag arrays — DO NOT add wcag22* without legal review */
      AXE_TAGS_BROWSER: freeze(['wcag2a','wcag2aa','wcag21a','wcag21aa','best-practice']),
      AXE_TAGS_SERVER_AA: freeze(['wcag2a','wcag2aa','wcag21a','wcag21aa','best-practice']),
      AXE_TAGS_SERVER_AAA: freeze(['wcag2a','wcag2aa','wcag2aaa','wcag21a','wcag21aa','best-practice']),

      /* Detection rate cited from peer-reviewed research — must include
         in any disclaimer that claims to test against WCAG */
      AUTO_DETECTION_RATE: '30-57%',
      AUTO_DETECTION_SOURCES: 'Vigo et al. 2013; Acosta-Vargas et al. 2019',
    }),

    /* ────────────────────────────────────────────────────────
       LEGAL & REGULATORY FRAMEWORK
       ──────────────────────────────────────────────────────── */
    LEGAL: freeze({
      /* Authority citations — use the canonical short forms below in UI;
         use AUTHORITIES_LONG in legal documents and reports */
      AUTHORITIES_SHORT: 'Section 504 · ADA Title II/III · Section 508 · EN 301 549',
      AUTHORITIES_LONG: 'HHS Section 504 (45 CFR 84.84) and DOJ ADA Title II (28 CFR 35.200)',

      /* HHS Section 504 deadlines per Interim Final Rule
         Federal Register doc 2026-09266, effective May 7, 2026 */
      HHS: freeze({
        REGULATION: '45 CFR 84.84',
        IFR_REF: 'HHS Interim Final Rule, RIN 0945-AA30',
        IFR_EFFECTIVE: 'May 7, 2026',
        DEADLINE_LARGE_DATE: 'May 11, 2027',
        DEADLINE_LARGE_THRESHOLD: '15 or more employees',
        DEADLINE_SMALL_DATE: 'May 10, 2028',
        DEADLINE_SMALL_THRESHOLD: 'fewer than 15 employees',
      }),

      /* DOJ ADA Title II deadlines per April 2026 IFR */
      DOJ: freeze({
        REGULATION: '28 CFR 35.200',
        IFR_REF: 'DOJ IFR, 91 FR 20902',
        IFR_EFFECTIVE: 'April 20, 2026',
      }),

      /* Ongoing obligations unchanged by the IFR delays */
      ONGOING: freeze({
        SECTION_504_MODIFICATIONS: '45 CFR 84.68(b)(7)',
        ADA_TITLE_III: '42 USC §12182',
      }),

      /* FTC precedent — why we never claim full compliance */
      FTC_PRECEDENT: 'accessiBe FTC Settlement (2024)',
      FTC_PRECEDENT_DETAIL: '$1M civil penalty for overstating automated scanner coverage of ADA compliance',
    }),

    /* ────────────────────────────────────────────────────────
       SCAN ENGINE METADATA — surfaced in report footers
       ──────────────────────────────────────────────────────── */
    ENGINE: freeze({
      AXE_CORE_VERSION: '4.10',
      LIGHTHOUSE_VERSION: '12',
      PLAYWRIGHT_VERSION: '1.47',
      CHROMIUM_PACKAGE: '@sparticuz/chromium 131.0.0',
      PDF_PARSER: 'pdfjs-dist 4.0',
    }),

    /* ────────────────────────────────────────────────────────
       DISCLAIMER PHRASES — reusable building blocks
       ──────────────────────────────────────────────────────── */
    DISCLAIMER: freeze({
      NOT_LEGAL_ADVICE: 'This report is an automated accessibility scan, not a compliance certification or legal opinion.',
      MANUAL_REVIEW_REQUIRED: 'Substantial conformance requires manual expert review by a CPACC/WAS-certified accessibility professional, keyboard-only testing, and assistive-tech walkthroughs (NVDA, JAWS, VoiceOver).',
      NO_GUARANTEE: 'No automated tool — including this one — can determine ADA, Section 504, Section 508, or EN 301 549 legal compliance.',
      STARTING_POINT: 'Address findings in this report as a starting point, not a complete remediation plan.',
      CONSULT_COUNSEL: 'Consult qualified legal counsel regarding compliance obligations.',
    }),

    /* ────────────────────────────────────────────────────────
       PRODUCT METADATA
       ──────────────────────────────────────────────────────── */
    PRODUCT: freeze({
      NAME: 'WPSiteBeam',
      MARKETING_TAGLINE: 'Agency time-saver platform for WordPress',
      LEGAL_ENTITY: 'Conceptualized Design LLC',  /* until WPSiteBeam LLC formation */
    }),
  });

  /* ────────────────────────────────────────────────────────
     HELPER FUNCTIONS — convenience accessors for common
     combinations consumers need to render
     ──────────────────────────────────────────────────────── */
  window.WPSB.CONSTANTS_HELPERS = freeze({
    /* Returns the full compliance disclaimer block (string).
       Use in PDF reports and accessibility statements. */
    fullDisclaimer: function() {
      var C = window.WPSB.CONSTANTS;
      return [
        C.DISCLAIMER.NOT_LEGAL_ADVICE,
        C.DISCLAIMER.NO_GUARANTEE,
        'Per peer-reviewed research (' + C.WCAG.AUTO_DETECTION_SOURCES + '), automated tools detect approximately ' + C.WCAG.AUTO_DETECTION_RATE + ' of WCAG violations.',
        C.DISCLAIMER.MANUAL_REVIEW_REQUIRED,
        C.DISCLAIMER.STARTING_POINT,
        C.DISCLAIMER.CONSULT_COUNSEL,
      ].join(' ');
    },

    /* Returns regulatory framework citation as a single sentence.
       Use in compliance statements and report introductions. */
    regulatoryCitation: function() {
      var L = window.WPSB.CONSTANTS.LEGAL;
      return L.AUTHORITIES_LONG + '. Compliance deadlines: ' + L.HHS.DEADLINE_LARGE_DATE + ' (' + L.HHS.DEADLINE_LARGE_THRESHOLD + ') and ' + L.HHS.DEADLINE_SMALL_DATE + ' (' + L.HHS.DEADLINE_SMALL_THRESHOLD + ') per ' + L.HHS.IFR_REF + ', effective ' + L.HHS.IFR_EFFECTIVE + '. DOJ Title II deadlines extended by ' + L.DOJ.IFR_REF + ' (' + L.DOJ.IFR_EFFECTIVE + ').';
    },

    /* Returns engine attribution line for report footers */
    engineAttribution: function() {
      var C = window.WPSB.CONSTANTS;
      return 'Powered by ' + C.PRODUCT.NAME + ' · ' + C.ENGINE.AXE_CORE_VERSION + ' (' + C.WCAG.DISPLAY + ' engine)';
    },
  });

})();
