/**
 * Mock tiers — run the paywall in a simulator BEFORE wiring RevenueCat.
 *
 * Drop this in, render `<PaywallScreen {...mockProps('full')} />`, and the screen works end to end:
 * tier selection, dock re-pricing, timeline binding, all three states. QA can start immediately and
 * you can check layout against the spec without touching the store.
 *
 * ⚠️ FIXTURES ONLY. Nothing here may reach a build. Every string below exists in production as
 * `product.priceString` or a value derived from `product.price` — never as a literal.
 */

import type {ComponentProps} from 'react';

// US price points, matching the spec's figures table.
const LIST = {annual: 159.99, quarter: 49.99};
const money = (n: number) => `$${n.toFixed(2)}`;

// per-day 365 / 91 · per-week 52 / 13 — the same denominators the wiring layer must use
const perDay = (price: number, days: number) => `$${(price / days).toFixed(2)}`;
const perWeek = (price: number, weeks: number) => `$${(price / weeks).toFixed(2)}`;

function tier(key: 'annual' | 'quarterly', price: number, promoPrice?: number, pct?: number) {
  const isYear = key === 'annual';
  return {
    key,
    pkg: {identifier: `mock_${key}`} as any,
    label: isYear ? '12-Month plan' : '3-Month plan',
    priceString: money(price),
    perDay: perDay(promoPrice ?? price, isYear ? 365 : 91),
    perWeek: perWeek(promoPrice ?? price, isYear ? 52 : 13),
    perMonth: money((promoPrice ?? price) / (isYear ? 12 : 3)),
    billedLine: isYear ? `${money(price)} billed once a year` : `${money(price)} every 3 months`,
    zeroPriceString: '$0.00',
    ...(promoPrice != null && pct != null
      ? {promo: {priceString: money(promoPrice), pct}}
      : {}),
  };
}

const VARIANTS = {
  full:  {pct: 0,  annual: undefined,  quarter: undefined},
  off50: {pct: 50, annual: 79.99,      quarter: 24.99},
  off30: {pct: 30, annual: 111.99,     quarter: 34.99},
} as const;

/** Ready-to-spread props for any of the three states. */
export function mockProps(variant: keyof typeof VARIANTS) {
  const v = VARIANTS[variant];
  const promo = variant !== 'full';

  const annual  = tier('annual',    LIST.annual,  v.annual,  promo ? v.pct : undefined);
  const quarter = tier('quarterly', LIST.quarter, v.quarter, promo ? v.pct : undefined);

  return {
    variant,
    tiers: [annual, quarter],
    trialDays: 7,                                   // production: read the intro-offer period
    // SAVE chip inputs — both computed, never typed
    promoSaving: promo ? money(LIST.annual - v.annual!) : undefined,           // vs list
    annualVsRampSaving: money(LIST.quarter * 4 - LIST.annual),                 // vs 4 × quarterly
    onPurchase: (pkg: any) => console.log('[mock] purchase', pkg?.identifier),
    onRestore:  () => console.log('[mock] restore'),
    onTerms:    () => console.log('[mock] terms'),
    onPrivacy:  () => console.log('[mock] privacy'),
    track: (e: string, props?: object) => console.log('[mock]', e, props ?? ''),
  };
}

// Sanity: these should print the spec's figures table exactly.
// full  → annual $159.99 · $0.44/day · $3.08/wk · saving vs quarterly $39.97
// off50 → annual  $79.99 · $0.22/day · $1.54/wk · saving vs list      $80.00
// off30 → annual $111.99 · $0.31/day · $2.15/wk · saving vs list      $48.00
