/* data.jsx — sample catalog + import scenarios for the bulk CSV import/export prototype.
   A boutique apparel store, "Wander & Wool". Numbers chosen so every count is backed
   by a concrete row the merchant can drill into. Exported to window.IEData. */

const STOREFRONT = {
  name: 'Wander & Wool',
  handle: 'wander-and-wool',
  email: 'mara@wanderandwool.com',
  productCount: 412,
  imageProblemCount: 9,
  latestRunId: 'run-0007',
};

/* ---- Import history (newest first). Statuses mirror §5.2 ---- */
const HISTORY = [
  {
    id: 'run-0007', date: '2026-06-11T12:40:00', rel: 'just now',
    file: 'spring-2026-pricing.csv', dialect: 'Canonical',
    added: 8, updated: 14, errors: 3,
    images: { fetched: 18, rejected: 2, failed: 1 },
    status: 'complete_with_problems',
  },
  {
    id: 'run-0006', date: '2026-05-02T09:12:00', rel: '5 weeks ago',
    file: 'shopify-store-export.csv', dialect: 'Shopify product CSV',
    added: 286, updated: 0, errors: 4,
    images: { fetched: 511, rejected: 6, failed: 2 },
    status: 'complete_with_problems',
  },
  {
    id: 'run-0005', date: '2026-04-18T16:30:00', rel: '8 weeks ago',
    file: 'restock-april.csv', dialect: 'Canonical',
    added: 0, updated: 63, errors: 0,
    images: { fetched: 0, rejected: 0, failed: 0 },
    status: 'complete',
  },
  {
    id: 'run-0004', date: '2026-03-30T11:05:00', rel: '10 weeks ago',
    file: 'initial-catalog.csv', dialect: 'Canonical',
    added: 118, updated: 0, errors: 0,
    images: { fetched: 402, rejected: 0, failed: 0 },
    status: 'complete',
  },
];

/* =====================================================================
   SCENARIO A — canonical seasonal pricing file (the default happy path).
   8 to add · 14 to update · 26 unchanged · 3 errors.  (48 product rows.)
   ===================================================================== */

const A_ADDS = [
  {
    handle: 'alpine-fleece-pullover', title: 'Alpine Fleece Pullover', kind: 'add', variants: 8,
    detail: {
      product: [
        ['Title', 'Alpine Fleece Pullover'],
        ['Vendor', 'Wander & Wool'],
        ['Type', 'standalone'],
        ['Tags', 'outerwear, fleece, spring-26'],
        ['Status', 'active'],
        ['Options', 'Size (S·M·L·XL) × Color (Heather Grey · Forest)'],
      ],
      variantsPreview: [
        ['S / Heather Grey', 'SKU AFP-S-HG', '$88.00'],
        ['M / Heather Grey', 'SKU AFP-M-HG', '$88.00'],
        ['L / Forest', 'SKU AFP-L-FO', '$88.00'],
      ],
      images: 2,
    },
  },
  {
    handle: 'coastal-linen-shirt', title: 'Coastal Linen Shirt', kind: 'add', variants: 6,
    detail: {
      product: [
        ['Title', 'Coastal Linen Shirt'],
        ['Vendor', 'Wander & Wool'],
        ['Type', 'standalone'],
        ['Tags', 'shirts, linen, spring-26'],
        ['Status', 'active'],
        ['Options', 'Size (S·M·L) × Color (Sand · Sky)'],
      ],
      variantsPreview: [
        ['S / Sand', 'SKU CLS-S-SA', '$72.00'],
        ['M / Sky', 'SKU CLS-M-SK', '$72.00'],
      ],
      images: 3,
    },
  },
  {
    handle: 'trailhead-cap', title: 'Trailhead Cap', kind: 'add', variants: 3,
    detail: {
      product: [
        ['Title', 'Trailhead Cap'],
        ['Vendor', 'Wander & Wool'],
        ['Type', 'standalone'],
        ['Tags', 'accessories, hats, spring-26'],
        ['Status', 'active'],
        ['Options', 'Color (Black · Olive · Rust)'],
      ],
      variantsPreview: [
        ['Black', 'SKU THC-BK', '$34.00'],
        ['Olive', 'SKU THC-OL', '$34.00'],
        ['Rust', 'SKU THC-RU', '$34.00'],
      ],
      images: 1,
    },
  },
  {
    handle: 'merino-base-tee', title: 'Merino Base Tee', kind: 'add', variants: 8,
    detail: {
      product: [
        ['Title', 'Merino Base Tee'],
        ['Vendor', 'Wander & Wool'],
        ['Type', 'standalone'],
        ['Tags', 'base-layer, merino, spring-26'],
        ['Status', 'active'],
        ['Options', 'Size (XS·S·M·L) × Color (Charcoal · Bone)'],
      ],
      variantsPreview: [
        ['XS / Charcoal', 'SKU MBT-XS-CH', '$58.00'],
        ['M / Bone', 'SKU MBT-M-BO', '$58.00'],
      ],
      images: 2,
    },
  },
  {
    handle: 'dune-chino-short', title: 'Dune Chino Short', kind: 'add', variants: 5,
    detail: {
      product: [
        ['Title', 'Dune Chino Short'],
        ['Vendor', 'Wander & Wool'],
        ['Type', 'standalone'],
        ['Tags', 'shorts, spring-26'],
        ['Status', 'draft'],
        ['Options', 'Size (28·30·32·34·36)'],
      ],
      variantsPreview: [
        ['28', 'SKU DCS-28', '$64.00'],
        ['34', 'SKU DCS-34', '$64.00'],
      ],
      images: 1,
    },
  },
  {
    handle: 'harbor-tote', title: 'Harbor Canvas Tote', kind: 'add', variants: 1,
    detail: {
      product: [
        ['Title', 'Harbor Canvas Tote'],
        ['Vendor', 'Wander & Wool'],
        ['Type', 'standalone'],
        ['Tags', 'bags, accessories, spring-26'],
        ['Status', 'active'],
        ['Options', '— (single variant)'],
      ],
      variantsPreview: [
        ['Default', 'SKU HCT-01', '$48.00'],
      ],
      images: 2,
    },
  },
  {
    handle: 'cirrus-rain-shell', title: 'Cirrus Rain Shell', kind: 'add', variants: 6,
    detail: {
      product: [
        ['Title', 'Cirrus Rain Shell'],
        ['Vendor', 'Wander & Wool'],
        ['Type', 'standalone'],
        ['Tags', 'outerwear, rain, spring-26'],
        ['Status', 'active'],
        ['Options', 'Size (S·M·L) × Color (Slate · Marigold)'],
      ],
      variantsPreview: [
        ['S / Slate', 'SKU CRS-S-SL', '$186.00'],
        ['L / Marigold', 'SKU CRS-L-MA', '$186.00'],
      ],
      images: 3,
    },
  },
  {
    handle: 'wildflower-scarf', title: 'Wildflower Wool Scarf', kind: 'add', variants: 2,
    detail: {
      product: [
        ['Title', 'Wildflower Wool Scarf'],
        ['Vendor', 'Wander & Wool'],
        ['Type', 'standalone'],
        ['Tags', 'accessories, wool, spring-26'],
        ['Status', 'active'],
        ['Options', 'Color (Meadow · Dusk)'],
      ],
      variantsPreview: [
        ['Meadow', 'SKU WWS-ME', '$42.00'],
        ['Dusk', 'SKU WWS-DU', '$42.00'],
      ],
      images: 1,
    },
  },
];

const A_UPDATES = [
  {
    handle: 'meadow-wrap-dress', title: 'Meadow Wrap Dress', kind: 'update', variants: 6,
    detail: {
      changes: [
        { field: 'Variant Price', scope: 'all 6 variants', before: '$118.00', after: '$98.00' },
        { field: 'Tags', scope: 'product', before: 'dresses, summer', after: 'dresses, summer, sale' },
        { field: 'Status', scope: 'product', before: 'active', after: 'active', noop: true },
      ],
    },
  },
  {
    handle: 'summit-rain-jacket', title: 'Summit Rain Jacket', kind: 'update', variants: 9,
    detail: {
      changes: [
        { field: 'Variant Price', scope: 'all 9 variants', before: '$240.00', after: '$264.00' },
        { field: 'Variant Cost', scope: 'all 9 variants', before: '$96.00', after: '$112.00' },
        { field: 'Variant Inventory Qty', scope: 'S / Slate', before: '4', after: '22' },
      ],
    },
  },
  {
    handle: 'field-canvas-pant', title: 'Field Canvas Pant', kind: 'update', variants: 10,
    detail: {
      changes: [
        { field: 'Variant Price', scope: 'all 10 variants', before: '$92.00', after: '$84.00' },
        { field: 'Description', scope: 'product', before: 'Durable canvas work pant.', after: 'Durable organic-canvas work pant, garment-dyed.' },
      ],
    },
  },
  {
    handle: 'aspen-knit-sweater', title: 'Aspen Knit Sweater', kind: 'update', variants: 8,
    detail: {
      changes: [
        { field: 'Variant Price', scope: 'all 8 variants', before: '$134.00', after: '$118.00' },
        { field: 'Status', scope: 'product', before: 'draft', after: 'active' },
        { field: 'Tags', scope: 'product', before: 'knitwear, fall', after: 'knitwear, fall, spring-26' },
      ],
    },
  },
  {
    handle: 'river-stone-belt', title: 'River Stone Belt', kind: 'update', variants: 4,
    detail: {
      changes: [
        { field: 'Variant Cost', scope: 'all 4 variants', before: '$11.00', after: '$14.50' },
        { field: 'Variant Barcode', scope: 'M / Tan', before: '— (empty)', after: '7 290 1148 22 901' },
      ],
    },
  },
  {
    handle: 'lantern-flannel', title: 'Lantern Flannel', kind: 'update', variants: 12,
    detail: {
      changes: [
        { field: 'Variant Price', scope: 'all 12 variants', before: '$78.00', after: '$68.00' },
        { field: 'Tags', scope: 'product', before: 'shirts, flannel', after: 'shirts, flannel, sale' },
      ],
    },
  },
];

const A_UPDATES_EXTRA = 8; // 14 total updates; 6 shown above, 8 more collapsed into the count

const A_UNCHANGED = [
  { handle: 'sandpiper-sock-3pk', title: 'Sandpiper Sock 3-Pack', kind: 'unchanged', variants: 3 },
  { handle: 'cedar-beanie', title: 'Cedar Ribbed Beanie', kind: 'unchanged', variants: 4 },
  { handle: 'driftwood-henley', title: 'Driftwood Henley', kind: 'unchanged', variants: 8 },
];
const A_UNCHANGED_EXTRA = 23; // 26 total

const A_ERRORS = [
  {
    handle: 'gardenia-sundress', title: 'Gardenia Sundress', kind: 'error', variants: 5,
    line: 214, column: 'Variant Price',
    message: "'12,50' is not a price — use a dot for decimals (12.50), no thousands separators.",
  },
  {
    handle: 'pathfinder-vest', title: 'Pathfinder Vest', kind: 'error', variants: 6,
    line: 327, column: 'Option1 Value',
    message: "Variant has value 'Medium' but the product never declares 'Option1 Name'. Add the option name, or remove the value.",
  },
  {
    handle: 'trail-kit-starter', title: 'Trail Starter Kit', kind: 'error', variants: 1,
    line: 402, column: 'Type',
    message: "'kit_assembled' is reserved — bundled kits arrive in a coming release. Use 'standalone' for now.",
  },
];

const SCENARIO_CANONICAL = {
  key: 'canonical',
  file: 'spring-2026-pricing.csv',
  dialect: 'Canonical format',
  dialectKind: 'canonical',
  rows: 48,
  summary: { add: 8, update: 14, unchanged: 26, error: 3 },
  unknownColumns: ['Season Note', 'Internal Ref'],
  records: { add: A_ADDS, update: A_UPDATES, unchanged: A_UNCHANGED, error: A_ERRORS },
  extra: { update: A_UPDATES_EXTRA, unchanged: A_UNCHANGED_EXTRA },
  noop: false,
};

/* =====================================================================
   SCENARIO B — an unmodified Shopify product export (the migration path).
   Recognized + mapped. Big add, many not-imported columns warned.
   ===================================================================== */

const B_ADDS = [
  {
    handle: 'oxford-button-down', title: 'Oxford Button-Down', kind: 'add', variants: 8, mapped: true,
    detail: {
      product: [
        ['Title', 'Oxford Button-Down'],
        ['Vendor', 'Northfield Supply'],
        ['Type', 'standalone', 'mapped from Shopify "Shirts" → warned, see below'],
        ['Tags', 'shirts, oxford'],
        ['Status', 'active'],
        ['Options', 'Size (S·M·L·XL) × Fit (Slim · Classic)'],
      ],
      variantsPreview: [
        ['S / Slim', 'SKU OBD-S-SL', '$74.00'],
        ['L / Classic', 'SKU OBD-L-CL', '$74.00'],
      ],
      images: 4,
    },
  },
  {
    handle: 'weekender-duffel', title: 'Weekender Duffel', kind: 'add', variants: 2, mapped: true,
    detail: {
      product: [
        ['Title', 'Weekender Duffel'],
        ['Vendor', 'Northfield Supply'],
        ['Type', 'standalone'],
        ['Tags', 'bags, travel'],
        ['Status', 'active'],
        ['Options', 'Color (Tan · Charcoal)'],
      ],
      variantsPreview: [
        ['Tan', 'SKU WKD-TN', '$148.00'],
        ['Charcoal', 'SKU WKD-CH', '$148.00'],
      ],
      images: 5,
    },
  },
  {
    handle: 'camp-mug-enamel', title: 'Enamel Camp Mug', kind: 'add', variants: 3, mapped: true,
    detail: {
      product: [
        ['Title', 'Enamel Camp Mug'],
        ['Vendor', 'Northfield Supply'],
        ['Type', 'standalone'],
        ['Tags', 'home, camp'],
        ['Status', 'active'],
        ['Options', 'Color (Red · Navy · Cream)'],
      ],
      variantsPreview: [
        ['Red', 'SKU ECM-RD', '$18.00'],
        ['Navy', 'SKU ECM-NV', '$18.00'],
      ],
      images: 2,
    },
  },
];
const B_ADDS_EXTRA = 283; // 286 total adds

const B_ERRORS = [
  {
    handle: 'gift-card', title: 'Gift Card', kind: 'error', variants: 4,
    line: 88, column: 'Type',
    message: "Shopify 'Gift Card' products aren't catalog products here — this row is skipped, not imported.",
  },
  {
    handle: 'bundle-essentials', title: 'Essentials Bundle', kind: 'error', variants: 1,
    line: 1042, column: 'Type',
    message: "Looks like a Shopify bundle — bundled kits arrive in a coming release. Skipped for now.",
  },
];
const B_ERRORS_EXTRA = 2; // 4 total

const SCENARIO_SHOPIFY = {
  key: 'shopify',
  file: 'shopify-store-export.csv',
  dialect: 'Shopify product CSV — mapped to canonical',
  dialectKind: 'shopify',
  rows: 1894,
  summary: { add: 286, update: 0, unchanged: 0, error: 4 },
  unknownColumns: [
    'Compare At Price', 'SEO Title', 'SEO Description', 'Google Shopping / Condition',
    'Google Shopping / Gender', 'Variant Fulfillment Service', 'Variant Tax Code', 'Gift Card',
  ],
  records: { add: B_ADDS, update: [], unchanged: [], error: B_ERRORS },
  extra: { add: B_ADDS_EXTRA, error: B_ERRORS_EXTRA },
  noop: false,
};

/* =====================================================================
   SCENARIO C — re-importing our own export (the round-trip no-op).
   Everything unchanged → the import action is disabled (PUC-10).
   ===================================================================== */

const C_UNCHANGED = [
  { handle: 'alpine-fleece-pullover', title: 'Alpine Fleece Pullover', kind: 'unchanged', variants: 8 },
  { handle: 'meadow-wrap-dress', title: 'Meadow Wrap Dress', kind: 'unchanged', variants: 6 },
  { handle: 'summit-rain-jacket', title: 'Summit Rain Jacket', kind: 'unchanged', variants: 9 },
  { handle: 'driftwood-henley', title: 'Driftwood Henley', kind: 'unchanged', variants: 8 },
];
const C_UNCHANGED_EXTRA = 408; // 412 total

const SCENARIO_ROUNDTRIP = {
  key: 'roundtrip',
  file: 'wander-wool-catalog-export.csv',
  dialect: 'Canonical format',
  dialectKind: 'canonical',
  rows: 1620,
  summary: { add: 0, update: 0, unchanged: 412, error: 0 },
  unknownColumns: [],
  records: { add: [], update: [], unchanged: C_UNCHANGED, error: [] },
  extra: { unchanged: C_UNCHANGED_EXTRA },
  noop: true,
};

/* ---- Image outcomes for the canonical run's post-commit phase (PUC-7) ---- */
const IMAGE_OUTCOMES = {
  total: 21,
  fetched: 18,
  problems: [
    { handle: 'cirrus-rain-shell', variant: 'L / Marigold', url: 'https://cdn.northfield.example/cirrus-marigold-detail.jpg', outcome: 'rejected', reason: 'Below the resolution bar (320 × 480) — needs at least 800 × 800.' },
    { handle: 'coastal-linen-shirt', variant: 'M / Sky', url: 'https://images.example.org/linen/sky.gif', outcome: 'rejected', reason: 'Not an image we can host (animated GIF).' },
    { handle: 'harbor-tote', variant: '—', url: 'https://oldhost.example/harbor-tote-2.jpg', outcome: 'failed', reason: 'Unreachable — host returned 404.' },
  ],
};

const SCENARIOS = {
  canonical: SCENARIO_CANONICAL,
  shopify: SCENARIO_SHOPIFY,
  roundtrip: SCENARIO_ROUNDTRIP,
};

window.IEData = { STOREFRONT, HISTORY, SCENARIOS, IMAGE_OUTCOMES };
