// ─── Global config injected by wp_localize_script ────────────────────────────

export interface NoonAuditConfig {
  rootId: string;
  auditSlug: string;
  auditId: string;
  restUrl: string;
  nonce: string;
  accentColor: string;
  consultantName: string;
  bookingUrl: string;
  privacyUrl: string;
  termsUrl: string;
  logoUrl: string;
  hideTitle: boolean;
  glassMode: boolean;
  showWatermark: boolean;
  watermarkText?: string;
  watermarkUrl?: string;
  themeMode: string;
  turnstileSiteKey?: string;
}

declare global {
  interface Window {
    noon_audit_config: NoonAuditConfig;
  }
}

// ─── Audit Data Types ────────────────────────────────────────────────────────

export interface Category {
  id: string;
  name: string;
  color: string;
}

export interface Answer {
  text: string;
  points: number;
}

export interface Question {
  id: string;
  categoryId: string;
  text: string;
  answers: Answer[];
}

export interface BandHeadline {
  title: string;
  text: string;
}

export interface BandHeadlines {
  critical: BandHeadline;
  high: BandHeadline;
  moderate: BandHeadline;
  low: BandHeadline;
}

export interface AuditSettings {
  [key: string]: unknown;
}

export interface Audit {
  id: number;
  title: string;
  slug: string;
  hook_text: string;
  categories: Category[];
  questions: Question[];
  band_headlines: BandHeadlines;
  settings: AuditSettings;
  status: string;
}

// ─── Scoring Types ───────────────────────────────────────────────────────────

export type RiskBand = 'critical' | 'high' | 'moderate' | 'low';

export interface CategoryScore {
  id: string;
  name: string;
  color: string;
  score: number;       // 0–100 (percentage)
  rawScore: number;    // actual points
  maxScore: number;    // max possible
}

export interface ScoreResult {
  rawScore: number;          // 0–100
  percentage: number;        // 0–100
  riskBand: RiskBand;
  headline: BandHeadline;
  categoryScores: CategoryScore[];
  weakestCategories: CategoryScore[];
}

// ─── User Answer Tracking ────────────────────────────────────────────────────

export interface UserAnswer {
  questionId: string;
  categoryId: string;
  answerIndex: number;
  points: number;
}

// ─── Quiz State ──────────────────────────────────────────────────────────────

export type QuizStep = 'landing' | 'quiz' | 'email-gate' | 'results';

// ─── Lead Submission ─────────────────────────────────────────────────────────

export interface LeadPayload {
  audit_id: number;
  email: string;
  name: string;
  company: string;
  score: number;
  risk_band: string;
  category_scores: CategoryScore[];
  answers: UserAnswer[];
  website_url?: string;
  turnstile_token?: string;
  consented_at: string;
  marketing_optin: boolean;
}
