// Mock data for Saddle Alert prototype
// Mock model names are deliberately generic to avoid brand or retailer affinity.

const REGIONS = [
  {
    code: 'AU',
    displayCode: 'AU',
    name: 'Australia',
    hint: 'AU storefront. It also serves New Zealand; NZ delivery eligibility is confirmed at checkout.',
    flag: 'au',
    currency: 'AUD',
  },
  {
    code: 'SG',
    displayCode: 'SG',
    name: 'Singapore',
    hint: 'Singapore storefront. Prices are shown in SGD.',
    flag: 'sg',
    currency: 'SGD',
  },
  { code: 'US', name: 'United States', flag: '🇺🇸', currency: 'USD' },
  { code: 'UK', name: 'United Kingdom', flag: '🇬🇧', currency: 'GBP' },
];

const MODELS = [
  { id: 'bucket_bag', name: 'Bucket Bag', sizes: ['18', '22'], category: 'bags' },
  { id: 'soft_satchel', name: 'Soft Satchel', sizes: ['mini', '26', '30'], category: 'bags' },
  { id: 'crossbody_bag', name: 'Crossbody Bag', sizes: ['16', '29', '33'], category: 'bags' },
  { id: 'canvas_tote', name: 'Canvas Tote', sizes: ['30', '36'], category: 'bags' },
  { id: 'box_shoulder', name: 'Box Shoulder', sizes: ['18', '24'], category: 'bags' },
  { id: 'heritage_tote', name: 'Heritage Tote', sizes: ['25', '41'], category: 'bags' },
  { id: 'top_handle', name: 'Top Handle', sizes: ['mini', '27'], category: 'bags' },
  { id: 'slim_wallet', name: 'Slim Wallet', sizes: [], category: 'slg' },
  { id: 'card_holder', name: 'Card Holder', sizes: [], category: 'slg' },
  { id: 'coin_purse', name: 'Coin Purse', sizes: [], category: 'slg' },
  { id: 'long_wallet', name: 'Long Wallet', sizes: [], category: 'slg' },
  { id: 'key_charm', name: 'Key Charm', sizes: [], category: 'charms' },
  { id: 'bag_charm', name: 'Bag Charm', sizes: ['small', 'medium'], category: 'charms' },
  { id: 'tassel_charm', name: 'Tassel Charm', sizes: [], category: 'charms' },
];

const LEATHERS = ['Togo', 'Epsom', 'Clemence', 'Swift', 'Chèvre', 'Box', 'Barenia', 'Canvas'];
const COLORS = [
  { name: 'Black', swatch: '#111111' },
  { name: 'Beige/Natural', swatch: '#d8c7aa' },
  { name: 'Beige', swatch: '#c9b28f' },
  { name: 'Natural', swatch: '#e2d4bc' },
  { name: 'Blue', swatch: '#244f8f' },
  { name: 'Grey', swatch: '#7f8588' },
  { name: 'White', swatch: '#f3f0e8' },
  { name: 'Green', swatch: '#3f5f45' },
  { name: 'Red', swatch: '#8d1f22' },
  { name: 'Brown', swatch: '#6f4d35' },
  { name: 'Noir', swatch: '#1a1a1a' },
  { name: 'Étoupe', swatch: '#9a8a78' },
  { name: 'Gold', swatch: '#a8784a' },
  { name: 'Rouge H', swatch: '#7a1f1f' },
  { name: 'Vert Cypress', swatch: '#3a4a3a' },
  { name: 'Bleu Nuit', swatch: '#1f2a4a' },
  { name: 'Craie', swatch: '#e8dfce' },
  { name: 'Nata', swatch: '#f0e6d2' },
  { name: 'Rose Sakura', swatch: '#e8b5b8' },
  { name: 'Bleu France', swatch: '#2a4a8a' },
];
const HARDWARE = ['Palladium', 'Gold', 'Rose Gold'];

// Generate a stock feed of recent listings
function rid() { return Math.random().toString(36).slice(2, 8).toUpperCase(); }
function pick(arr) { return arr[Math.floor(Math.random() * arr.length)]; }
function ago(mins) {
  const d = new Date(Date.now() - mins * 60000);
  return d.toISOString();
}

// rarity: 'common' | 'uncommon' | 'rare' | 'unicorn'
const STOCK_FEED = [
  { id: 'S' + rid(), model: 'Bucket Bag', size: '18', leather: 'Clemence', color: 'Nata', hw: 'Palladium', region: 'US', price: 4250, currency: 'USD', ago: 3, status: 'live', match: true, rarity: 'common' },
  { id: 'S' + rid(), model: 'Crossbody Bag', size: '29', leather: 'Clemence', color: 'Étoupe', hw: 'Palladium', region: 'UK', price: 3100, currency: 'GBP', ago: 8, status: 'live', match: false, rarity: 'common' },
  { id: 'S' + rid(), model: 'Canvas Tote', size: '30', leather: 'Canvas', color: 'Noir', hw: 'Palladium', region: 'AU', price: 4900, currency: 'AUD', ago: 14, status: 'live', match: false, rarity: 'common' },
  { id: 'S' + rid(), model: 'Box Shoulder', size: '18', leather: 'Epsom', color: 'Rouge H', hw: 'Gold', region: 'US', price: 12300, currency: 'USD', ago: 27, status: 'sold', match: true, rarity: 'rare' },
  { id: 'S' + rid(), model: 'Bucket Bag', size: '22', leather: 'Clemence', color: 'Gold', hw: 'Palladium', region: 'NZ', price: 5400, currency: 'NZD', ago: 41, status: 'live', match: false, rarity: 'uncommon' },
  { id: 'S' + rid(), model: 'Crossbody Bag', size: '16', leather: 'Clemence', color: 'Bleu France', hw: 'Palladium', region: 'US', price: 2950, currency: 'USD', ago: 52, status: 'live', match: false, rarity: 'common' },
  { id: 'S' + rid(), model: 'Structured Satchel', size: '28', leather: 'Togo', color: 'Noir', hw: 'Gold', region: 'UK', price: 12800, currency: 'GBP', ago: 73, status: 'sold', match: true, rarity: 'unicorn' },
  { id: 'S' + rid(), model: 'Heritage Tote', size: '25', leather: 'Togo', color: 'Étoupe', hw: 'Palladium', region: 'US', price: 13400, currency: 'USD', ago: 88, status: 'sold', match: true, rarity: 'unicorn' },
  { id: 'S' + rid(), model: 'Soft Satchel', size: '26', leather: 'Clemence', color: 'Vert Cypress', hw: 'Palladium', region: 'AU', price: 11200, currency: 'AUD', ago: 102, status: 'live', match: false, rarity: 'uncommon' },
  { id: 'S' + rid(), model: 'Top Handle', size: '27', leather: 'Epsom', color: 'Bleu Nuit', hw: 'Palladium', region: 'UK', price: 7900, currency: 'GBP', ago: 134, status: 'live', match: false, rarity: 'uncommon' },
  { id: 'S' + rid(), model: 'Canvas Tote', size: '36', leather: 'Canvas', color: 'Étoupe', hw: 'Palladium', region: 'US', price: 3550, currency: 'USD', ago: 156, status: 'live', match: false, rarity: 'common' },
  { id: 'S' + rid(), model: 'Bucket Bag', size: '18', leather: 'Clemence', color: 'Craie', hw: 'Palladium', region: 'UK', price: 3400, currency: 'GBP', ago: 188, status: 'live', match: true, rarity: 'common' },
  { id: 'S' + rid(), model: 'Crossbody Bag', size: '33', leather: 'Clemence', color: 'Noir', hw: 'Palladium', region: 'AU', price: 5200, currency: 'AUD', ago: 220, status: 'sold', match: false, rarity: 'common' },
  { id: 'S' + rid(), model: 'Box Shoulder', size: '24', leather: 'Epsom', color: 'Rose Sakura', hw: 'Rose Gold', region: 'US', price: 14200, currency: 'USD', ago: 245, status: 'sold', match: false, rarity: 'rare' },
];

// Synthetic price history for stock detail view — last 12 months for each model spec.
// Returns array of {month, price, stockEvents} where stockEvents = times spotted that month.
function genPriceHistory(model, basePrice, region) {
  const months = ['Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar', 'Apr', 'May'];
  // Stable pseudo-random based on model name
  let seed = (model + region).split('').reduce((a, c) => a + c.charCodeAt(0), 0);
  const rand = () => { seed = (seed * 9301 + 49297) % 233280; return seed / 233280; };
  // Long-term trend: gentle rise of 4-7% over 12 months
  return months.map((m, i) => {
    const trend = 1 + (i / 11) * (0.04 + rand() * 0.03);
    const noise = 1 + (rand() - 0.5) * 0.015;
    return {
      month: m,
      price: Math.round((basePrice * trend * noise) / 50) * 50,
      events: Math.floor(rand() * 5),
    };
  });
}

window.DW_genPriceHistory = genPriceHistory;

// Notification inbox
const NOTIFICATIONS = [
  {
    id: 'N001',
    type: 'match',
    alertName: 'Bucket Bag 18 — neutrals',
    item: { model: 'Bucket Bag', size: '18', color: 'Nata', leather: 'Clemence', hw: 'Palladium', region: 'US', price: 4250, currency: 'USD' },
    ago: 3,
    read: false,
    priority: false,
  },
  {
    id: 'N002',
    type: 'match',
    alertName: 'Box Shoulder 18 — any red',
    item: { model: 'Box Shoulder', size: '18', color: 'Rouge H', leather: 'Epsom', hw: 'Gold', region: 'US', price: 12300, currency: 'USD' },
    ago: 27,
    read: false,
    priority: true,
  },
  {
    id: 'N003',
    type: 'match',
    alertName: 'Bucket Bag 18 — neutrals',
    item: { model: 'Bucket Bag', size: '18', color: 'Craie', leather: 'Clemence', hw: 'Palladium', region: 'UK', price: 3400, currency: 'GBP' },
    ago: 188,
    read: false,
    priority: false,
  },
  {
    id: 'N004',
    type: 'match',
    alertName: 'Structured Satchel 25 Structured — black, gold hw',
    item: { model: 'Structured Satchel', size: '28', color: 'Noir', leather: 'Togo', hw: 'Gold', region: 'UK', price: 12800, currency: 'GBP' },
    ago: 60 * 24 * 2,
    read: true,
    priority: true,
  },
  {
    id: 'N005',
    type: 'price-drop',
    alertName: 'Box Shoulder 18 — any red',
    item: { model: 'Box Shoulder', size: '18', color: 'Rouge H', leather: 'Epsom', hw: 'Gold', region: 'US', price: 11800, currency: 'USD' },
    delta: -500,
    ago: 60 * 24 * 5,
    read: true,
    priority: false,
  },
  {
    id: 'N006',
    type: 'system',
    title: 'Weekly digest',
    body: '8 matches across your 3 active alerts last week. Top model: Bucket Bag.',
    ago: 60 * 24 * 7,
    read: true,
  },
];

// priority: 'standard' (push + email) | 'priority' (push + email + SMS, instant)
const ALERTS = [
  {
    id: 'A001',
    name: 'Canvas Tote',
    model: 'Canvas Tote',
    sizes: [],
    colors: [],
    hardware: [],
    regions: ['AU'],
    maxPrice: 25000,
    priority: 'standard',
    active: true,
    created: 'Apr 28',
    hits: 0,
    lastHit: '—',
  },
  {
    id: 'A002',
    name: 'Soft Satchel',
    model: 'Soft Satchel',
    sizes: [],
    colors: [],
    hardware: [],
    regions: ['AU'],
    maxPrice: 25000,
    priority: 'priority',
    active: true,
    created: 'Mar 12',
    hits: 0,
    lastHit: '—',
  },
  {
    id: 'A003',
    name: 'Crossbody Bag',
    model: 'Crossbody Bag',
    sizes: [],
    colors: [],
    hardware: [],
    regions: ['AU'],
    maxPrice: 25000,
    priority: 'priority',
    active: true,
    created: 'Feb 03',
    hits: 0,
    lastHit: '—',
  },
  {
    id: 'A004',
    name: 'Bucket Bag',
    model: 'Bucket Bag',
    sizes: [],
    colors: [],
    hardware: [],
    regions: ['AU'],
    maxPrice: 25000,
    priority: 'standard',
    active: false,
    created: 'Jan 17',
    hits: 0,
    lastHit: '—',
  },
];

window.DW_DATA = { REGIONS, MODELS, LEATHERS, COLORS, HARDWARE, STOCK_FEED, ALERTS, NOTIFICATIONS };
