// data.jsx — seed lists + suggestion catalogs.
// window.SHOP_SEED  → array of lists
// window.SHOP_SUGGEST → { key: [ {name, cat, unit} ] } used for quick-type
//   suggestions AND category/unit inference for free-typed items.

window.SHOP_SUGGEST = {
  groceries: [
    { name: 'Milk', cat: 'Dairy & Eggs', unit: '', emoji: '\uD83E\uDD5B' },
    { name: 'Greek yogurt', cat: 'Dairy & Eggs', unit: '', emoji: '\uD83C\uDF66' },
    { name: 'Butter', cat: 'Dairy & Eggs', unit: '', emoji: '\uD83E\uDDC8' },
    { name: 'Cheddar', cat: 'Dairy & Eggs', unit: '', emoji: '\uD83E\uDDC0' },
    { name: 'Eggs', cat: 'Dairy & Eggs', unit: 'dozen', emoji: '\uD83E\uDD5A' },
    { name: 'Bananas', cat: 'Produce', unit: 'bunch', emoji: '\uD83C\uDF4C' },
    { name: 'Avocados', cat: 'Produce', unit: '', emoji: '\uD83E\uDD51' },
    { name: 'Baby spinach', cat: 'Produce', unit: 'bag', emoji: '\uD83E\uDD6C' },
    { name: 'Tomatoes', cat: 'Produce', unit: '', emoji: '\uD83C\uDF45' },
    { name: 'Lemons', cat: 'Produce', unit: '', emoji: '\uD83C\uDF4B' },
    { name: 'Onions', cat: 'Produce', unit: '', emoji: '\uD83E\uDDC5' },
    { name: 'Garlic', cat: 'Produce', unit: '', emoji: '\uD83E\uDDC4' },
    { name: 'Apples', cat: 'Produce', unit: '', emoji: '\uD83C\uDF4E' },
    { name: 'Carrots', cat: 'Produce', unit: 'bag', emoji: '\uD83E\uDD55' },
    { name: 'Sourdough', cat: 'Bakery', unit: 'loaf', emoji: '\uD83C\uDF5E' },
    { name: 'Bagels', cat: 'Bakery', unit: 'pack', emoji: '\uD83E\uDD6F' },
    { name: 'Tortillas', cat: 'Bakery', unit: 'pack', emoji: '\uD83E\uDDC8' },
    { name: 'Chicken thighs', cat: 'Meat & Seafood', unit: 'lb', emoji: '\uD83C\uDF57' },
    { name: 'Ground beef', cat: 'Meat & Seafood', unit: 'lb', emoji: '\uD83E\uDD69' },
    { name: 'Salmon', cat: 'Meat & Seafood', unit: 'lb', emoji: '\uD83D\uDC1F' },
    { name: 'Bacon', cat: 'Meat & Seafood', unit: 'pack', emoji: '\uD83E\uDD53' },
    { name: 'Olive oil', cat: 'Pantry', unit: '', emoji: '\uD83E\uDED2' },
    { name: 'Pasta', cat: 'Pantry', unit: 'box', emoji: '\uD83C\uDF5D' },
    { name: 'Rice', cat: 'Pantry', unit: 'bag', emoji: '\uD83C\uDF5A' },
    { name: 'Diced tomatoes', cat: 'Pantry', unit: 'can', emoji: '\uD83E\uDD6B' },
    { name: 'Black beans', cat: 'Pantry', unit: 'can', emoji: '\uD83E\uDD6B' },
    { name: 'Peanut butter', cat: 'Pantry', unit: '', emoji: '\uD83E\uDD5C' },
    { name: 'Coffee', cat: 'Pantry', unit: 'bag', emoji: '\u2615' },
    { name: 'Cereal', cat: 'Pantry', unit: 'box', emoji: '\uD83E\uDD63' },
    { name: 'Frozen peas', cat: 'Frozen', unit: 'bag', emoji: '\uD83D\uDFE2' },
    { name: 'Ice cream', cat: 'Frozen', unit: '', emoji: '\uD83C\uDF68' },
    { name: 'Frozen berries', cat: 'Frozen', unit: 'bag', emoji: '\uD83E\uDED0' },
    { name: 'Tortilla chips', cat: 'Snacks', unit: 'bag', emoji: '\uD83C\uDF2E' },
    { name: 'Dark chocolate', cat: 'Snacks', unit: 'bar', emoji: '\uD83C\uDF6B' },
    { name: 'Hummus', cat: 'Snacks', unit: '', emoji: '\uD83E\uDDC6' },
    { name: 'Sparkling water', cat: 'Drinks', unit: 'pack', emoji: '\uD83E\uDD64' },
    { name: 'Orange juice', cat: 'Drinks', unit: '', emoji: '\uD83E\uDDC3' },
    { name: 'Paper towels', cat: 'Household', unit: 'pack', emoji: '\uD83E\uDDFB' },
    { name: 'Dish soap', cat: 'Household', unit: '', emoji: '\uD83E\uDDF4' },
    { name: 'Trash bags', cat: 'Household', unit: 'box', emoji: '\uD83D\uDDD1\uFE0F' },
  ],
  packing: [
    { name: 'T-shirts', cat: 'Clothes', unit: '', emoji: '\uD83D\uDC55' },
    { name: 'Swimsuit', cat: 'Clothes', unit: '', emoji: '\uD83E\uDE71' },
    { name: 'Shorts', cat: 'Clothes', unit: '', emoji: '\uD83E\uDE73' },
    { name: 'Sandals', cat: 'Clothes', unit: '', emoji: '\uD83E\uDE74' },
    { name: 'Sun hat', cat: 'Clothes', unit: '', emoji: '\uD83D\uDC52' },
    { name: 'Light jacket', cat: 'Clothes', unit: '', emoji: '\uD83E\uDDE5' },
    { name: 'Sunscreen', cat: 'Toiletries', unit: '', emoji: '\uD83E\uDDF4' },
    { name: 'Toothbrush', cat: 'Toiletries', unit: '', emoji: '\uD83E\uDEA5' },
    { name: 'Toothpaste', cat: 'Toiletries', unit: '', emoji: '\uD83E\uDD8B' },
    { name: 'Deodorant', cat: 'Toiletries', unit: '', emoji: '\uD83E\uDDF4' },
    { name: 'Aloe vera', cat: 'Toiletries', unit: '', emoji: '\uD83C\uDF3F' },
    { name: 'Beach towels', cat: 'Beach', unit: '', emoji: '\uD83C\uDFD6\uFE0F' },
    { name: 'Umbrella', cat: 'Beach', unit: '', emoji: '\u26F1\uFE0F' },
    { name: 'Cooler', cat: 'Beach', unit: '', emoji: '\uD83E\uDDCA' },
    { name: 'Snorkel set', cat: 'Beach', unit: '', emoji: '\uD83E\uDD3F' },
    { name: 'Passports', cat: 'Docs & Money', unit: '', emoji: '\uD83D\uDEC2' },
    { name: 'Boarding passes', cat: 'Docs & Money', unit: '', emoji: '\uD83C\uDFAB' },
    { name: 'Cash', cat: 'Docs & Money', unit: '', emoji: '\uD83D\uDCB5' },
    { name: 'Phone charger', cat: 'Tech', unit: '', emoji: '\uD83D\uDD0C' },
    { name: 'Power bank', cat: 'Tech', unit: '', emoji: '\uD83D\uDD0B' },
    { name: 'Headphones', cat: 'Tech', unit: '', emoji: '\uD83C\uDFA7' },
    { name: 'Camera', cat: 'Tech', unit: '', emoji: '\uD83D\uDCF7' },
  ],
  todo: [
    { name: 'Book dentist appointment', cat: 'Other', unit: '', emoji: '\uD83E\uDD8B' },
    { name: 'Reply to Sam\u2019s email', cat: 'Other', unit: '', emoji: '\uD83D\uDCE7' },
    { name: 'Renew library books', cat: 'Other', unit: '', emoji: '\uD83D\uDCDA' },
    { name: 'Plan Sunday hike', cat: 'Other', unit: '', emoji: '\uD83E\uDD7E' },
    { name: 'Pick up dry cleaning', cat: 'Other', unit: '', emoji: '\uD83D\uDC54' },
    { name: 'Call the plumber', cat: 'Other', unit: '', emoji: '\uD83D\uDD27' },
    { name: 'Pay credit card', cat: 'Other', unit: '', emoji: '\uD83D\uDCB3' },
    { name: 'Back up laptop', cat: 'Other', unit: '', emoji: '\uD83D\uDCBB' },
    { name: 'Water the plants', cat: 'Other', unit: '', emoji: '\uD83E\uDEB4' },
    { name: 'Schedule car service', cat: 'Other', unit: '', emoji: '\uD83D\uDE97' },
  ],
};

const it = (name, qty, unit, cat, checked) => ({
  id: 'i_' + Math.random().toString(36).slice(2, 9),
  name, qty: qty || 1, unit: unit || '', cat: cat || 'Other', checked: !!checked, emoji: '', note: '',
});

window.SHOP_SEED = [
  {
    id: 'groceries',
    name: 'Groceries',
    emoji: '\uD83D\uDED2',
    grouped: true,
    showQty: true,
    checkedLabel: 'In cart',
    suggestKey: 'groceries',
    defaultCat: 'Other',
    catOrder: ['Produce', 'Bakery', 'Dairy & Eggs', 'Meat & Seafood', 'Pantry', 'Frozen', 'Snacks', 'Drinks', 'Household', 'Other'],
    items: [
      it('Bananas', 1, 'bunch', 'Produce'),
      it('Avocados', 3, '', 'Produce'),
      it('Baby spinach', 1, 'bag', 'Produce'),
      it('Lemons', 4, '', 'Produce', true),
      it('Sourdough', 1, 'loaf', 'Bakery'),
      it('Greek yogurt', 2, '', 'Dairy & Eggs'),
      it('Eggs', 1, 'dozen', 'Dairy & Eggs'),
      it('Butter', 1, '', 'Dairy & Eggs', true),
      it('Chicken thighs', 2, 'lb', 'Meat & Seafood'),
      it('Salmon', 1, 'lb', 'Meat & Seafood'),
      it('Olive oil', 1, '', 'Pantry'),
      it('Pasta', 2, 'box', 'Pantry'),
      it('Diced tomatoes', 3, 'can', 'Pantry'),
      it('Frozen peas', 1, 'bag', 'Frozen'),
      it('Tortilla chips', 1, 'bag', 'Snacks', true),
      it('Paper towels', 1, 'pack', 'Household'),
    ],
  },
  {
    id: 'packing',
    name: 'Beach Trip',
    emoji: '\uD83C\uDFD6\uFE0F',
    grouped: true,
    showQty: true,
    checkedLabel: 'Packed',
    suggestKey: 'packing',
    defaultCat: 'Other',
    catOrder: ['Clothes', 'Toiletries', 'Beach', 'Docs & Money', 'Tech', 'Other'],
    items: [
      it('T-shirts', 4, '', 'Clothes'),
      it('Swimsuit', 2, '', 'Clothes'),
      it('Shorts', 3, '', 'Clothes'),
      it('Sun hat', 1, '', 'Clothes', true),
      it('Sunscreen', 1, '', 'Toiletries'),
      it('Toothbrush', 2, '', 'Toiletries'),
      it('Beach towels', 4, '', 'Beach'),
      it('Umbrella', 1, '', 'Beach'),
      it('Cooler', 1, '', 'Beach'),
      it('Passports', 2, '', 'Docs & Money', true),
      it('Phone charger', 2, '', 'Tech'),
      it('Power bank', 1, '', 'Tech'),
    ],
  },
  {
    id: 'todo',
    name: 'Weekend To-Do',
    emoji: '\u2705',
    grouped: false,
    showQty: false,
    checkedLabel: 'Done',
    suggestKey: 'todo',
    defaultCat: 'Other',
    catOrder: ['Other'],
    items: [
      it('Book dentist appointment', 1, '', 'Other'),
      it('Reply to Sam\u2019s email', 1, '', 'Other'),
      it('Renew library books', 1, '', 'Other'),
      it('Plan Sunday hike', 1, '', 'Other'),
      it('Water the plants', 1, '', 'Other', true),
      it('Pick up dry cleaning', 1, '', 'Other'),
    ],
  },
];

// Backfill each seed item's emoji from its list's suggestion catalog (by name).
window.SHOP_SEED.forEach((list) => {
  const cat = window.SHOP_SUGGEST[list.suggestKey] || [];
  list.items.forEach((item) => {
    if (item.emoji) return;
    const hit = cat.find((c) => c.name.toLowerCase() === item.name.trim().toLowerCase());
    if (hit && hit.emoji) item.emoji = hit.emoji;
  });
});

// Sharing (mock): members per list + who added a few items.
window.LIST_MEMBERS = {
  you: { name: 'You', color: '#7b8bff', me: true },
  maria: { name: 'Maria', color: '#e0723e' },
  jonas: { name: 'Jonas', color: '#1f9d6b' },
};
(function () {
  const M = window.LIST_MEMBERS;
  const g = window.SHOP_SEED.find((l) => l.id === 'groceries');
  const p = window.SHOP_SEED.find((l) => l.id === 'packing');
  const t = window.SHOP_SEED.find((l) => l.id === 'todo');
  if (g) { g.members = [M.you, M.maria]; ['Greek yogurt', 'Salmon', 'Diced tomatoes'].forEach((n) => { const it = g.items.find((i) => i.name === n); if (it) it.by = 'Maria'; }); }
  if (p) { p.members = [M.you, M.jonas]; ['Cooler', 'Umbrella'].forEach((n) => { const it = p.items.find((i) => i.name === n); if (it) it.by = 'Jonas'; }); }
  if (t) { t.members = [M.you]; }
})();

// Keyword → {emoji, cat} map for inferring emoji/category from free-typed
// items that aren't literal catalog entries (e.g. "cheese", "soda", "shampoo").
// `kw` are substrings tested against the lowercased item name. First hit wins,
// so list more-specific terms before generic ones.
window.SHOP_KEYWORDS = [
  // produce
  { kw: ['lettuce', 'kale', 'arugula', 'salad', 'greens'], emoji: '\uD83E\uDD6C', cat: 'Produce' },
  { kw: ['broccoli'], emoji: '\uD83E\uDD66', cat: 'Produce' },
  { kw: ['pepper', 'capsicum'], emoji: '\uD83E\uDED1', cat: 'Produce' },
  { kw: ['cucumber', 'pickle'], emoji: '\uD83E\uDD52', cat: 'Produce' },
  { kw: ['mushroom'], emoji: '\uD83C\uDF44', cat: 'Produce' },
  { kw: ['potato'], emoji: '\uD83E\uDD54', cat: 'Produce' },
  { kw: ['corn'], emoji: '\uD83C\uDF3D', cat: 'Produce' },
  { kw: ['strawberr', 'berry', 'berries'], emoji: '\uD83C\uDF53', cat: 'Produce' },
  { kw: ['grape'], emoji: '\uD83C\uDF47', cat: 'Produce' },
  { kw: ['orange', 'mandarin', 'clementine'], emoji: '\uD83C\uDF4A', cat: 'Produce' },
  { kw: ['peach'], emoji: '\uD83C\uDF51', cat: 'Produce' },
  { kw: ['pear'], emoji: '\uD83C\uDF50', cat: 'Produce' },
  { kw: ['melon', 'cantaloupe'], emoji: '\uD83C\uDF48', cat: 'Produce' },
  { kw: ['watermelon'], emoji: '\uD83C\uDF49', cat: 'Produce' },
  { kw: ['pineapple'], emoji: '\uD83C\uDF4D', cat: 'Produce' },
  { kw: ['mango'], emoji: '\uD83E\uDD6D', cat: 'Produce' },
  { kw: ['cherr'], emoji: '\uD83C\uDF52', cat: 'Produce' },
  { kw: ['ginger', 'herb', 'basil', 'cilantro', 'parsley', 'mint'], emoji: '\uD83C\uDF3F', cat: 'Produce' },
  { kw: ['chili', 'jalapeno', 'hot pepper'], emoji: '\uD83C\uDF36\uFE0F', cat: 'Produce' },
  // dairy & eggs
  { kw: ['cheese', 'cheddar', 'mozzarella', 'parmesan', 'brie', 'feta', 'gouda'], emoji: '\uD83E\uDDC0', cat: 'Dairy & Eggs' },
  { kw: ['milk', 'cream', 'half and half'], emoji: '\uD83E\uDD5B', cat: 'Dairy & Eggs' },
  { kw: ['yogurt', 'yoghurt'], emoji: '\uD83C\uDF66', cat: 'Dairy & Eggs' },
  { kw: ['egg'], emoji: '\uD83E\uDD5A', cat: 'Dairy & Eggs' },
  { kw: ['butter', 'margarine'], emoji: '\uD83E\uDDC8', cat: 'Dairy & Eggs' },
  // bakery
  { kw: ['bread', 'baguette', 'loaf', 'bun', 'roll'], emoji: '\uD83C\uDF5E', cat: 'Bakery' },
  { kw: ['bagel'], emoji: '\uD83E\uDD6F', cat: 'Bakery' },
  { kw: ['croissant'], emoji: '\uD83E\uDD50', cat: 'Bakery' },
  { kw: ['donut', 'doughnut'], emoji: '\uD83C\uDF69', cat: 'Bakery' },
  { kw: ['cake', 'muffin', 'cupcake'], emoji: '\uD83E\uDDC1', cat: 'Bakery' },
  { kw: ['cookie', 'biscuit'], emoji: '\uD83C\uDF6A', cat: 'Bakery' },
  { kw: ['pretzel'], emoji: '\uD83E\uDD68', cat: 'Bakery' },
  { kw: ['pancake', 'waffle'], emoji: '\uD83E\uDD5E', cat: 'Bakery' },
  // meat & seafood
  { kw: ['chicken', 'poultry', 'turkey'], emoji: '\uD83C\uDF57', cat: 'Meat & Seafood' },
  { kw: ['beef', 'steak', 'mince'], emoji: '\uD83E\uDD69', cat: 'Meat & Seafood' },
  { kw: ['pork', 'ham', 'sausage', 'chop'], emoji: '\uD83E\uDD53', cat: 'Meat & Seafood' },
  { kw: ['bacon'], emoji: '\uD83E\uDD53', cat: 'Meat & Seafood' },
  { kw: ['fish', 'salmon', 'tuna', 'cod', 'tilapia'], emoji: '\uD83D\uDC1F', cat: 'Meat & Seafood' },
  { kw: ['shrimp', 'prawn'], emoji: '\uD83E\uDD90', cat: 'Meat & Seafood' },
  { kw: ['crab'], emoji: '\uD83E\uDD80', cat: 'Meat & Seafood' },
  { kw: ['lobster'], emoji: '\uD83E\uDD9E', cat: 'Meat & Seafood' },
  { kw: ['tofu'], emoji: '\u2B1C', cat: 'Meat & Seafood' },
  // pantry
  { kw: ['pasta', 'spaghetti', 'noodle', 'macaroni', 'penne'], emoji: '\uD83C\uDF5D', cat: 'Pantry' },
  { kw: ['rice'], emoji: '\uD83C\uDF5A', cat: 'Pantry' },
  { kw: ['oil', 'olive oil', 'vinegar'], emoji: '\uD83E\uDED2', cat: 'Pantry' },
  { kw: ['flour', 'sugar', 'baking'], emoji: '\uD83E\uDDC2', cat: 'Pantry' },
  { kw: ['salt', 'spice', 'seasoning'], emoji: '\uD83E\uDDC2', cat: 'Pantry' },
  { kw: ['honey', 'syrup'], emoji: '\uD83C\uDF6F', cat: 'Pantry' },
  { kw: ['jam', 'jelly', 'preserve'], emoji: '\uD83C\uDF53', cat: 'Pantry' },
  { kw: ['peanut butter', 'nutella'], emoji: '\uD83E\uDD5C', cat: 'Pantry' },
  { kw: ['cereal', 'granola', 'oat'], emoji: '\uD83E\uDD63', cat: 'Pantry' },
  { kw: ['soup', 'broth', 'stock'], emoji: '\uD83C\uDF72', cat: 'Pantry' },
  { kw: ['bean', 'lentil', 'chickpea'], emoji: '\uD83E\uDD6B', cat: 'Pantry' },
  { kw: ['tomato sauce', 'ketchup', 'salsa', 'can'], emoji: '\uD83E\uDD6B', cat: 'Pantry' },
  { kw: ['coffee', 'espresso'], emoji: '\u2615', cat: 'Pantry' },
  { kw: ['tea'], emoji: '\uD83C\uDF75', cat: 'Pantry' },
  { kw: ['nut', 'almond', 'cashew', 'walnut'], emoji: '\uD83E\uDD5C', cat: 'Pantry' },
  { kw: ['taco', 'tortilla', 'wrap'], emoji: '\uD83C\uDF2E', cat: 'Pantry' },
  // frozen
  { kw: ['ice cream', 'gelato'], emoji: '\uD83C\uDF68', cat: 'Frozen' },
  { kw: ['frozen', 'popsicle', 'ice'], emoji: '\uD83E\uDDCA', cat: 'Frozen' },
  { kw: ['pizza'], emoji: '\uD83C\uDF55', cat: 'Frozen' },
  // snacks
  { kw: ['chip', 'crisp', 'crackers', 'popcorn'], emoji: '\uD83C\uDF7F', cat: 'Snacks' },
  { kw: ['chocolate', 'candy', 'sweet'], emoji: '\uD83C\uDF6B', cat: 'Snacks' },
  { kw: ['hummus', 'dip'], emoji: '\uD83E\uDDC6', cat: 'Snacks' },
  { kw: ['granola bar', 'protein bar'], emoji: '\uD83C\uDF6B', cat: 'Snacks' },
  // drinks
  { kw: ['soda', 'cola', 'pop', 'soft drink'], emoji: '\uD83E\uDD64', cat: 'Drinks' },
  { kw: ['water', 'sparkling'], emoji: '\uD83D\uDCA7', cat: 'Drinks' },
  { kw: ['juice'], emoji: '\uD83E\uDDC3', cat: 'Drinks' },
  { kw: ['beer'], emoji: '\uD83C\uDF7A', cat: 'Drinks' },
  { kw: ['wine'], emoji: '\uD83C\uDF77', cat: 'Drinks' },
  { kw: ['soda water', 'seltzer'], emoji: '\uD83E\uDD64', cat: 'Drinks' },
  // household
  { kw: ['paper towel', 'napkin', 'tissue'], emoji: '\uD83E\uDDFB', cat: 'Household' },
  { kw: ['toilet paper', 'tp'], emoji: '\uD83E\uDDFB', cat: 'Household' },
  { kw: ['soap', 'detergent', 'cleaner', 'bleach'], emoji: '\uD83E\uDDF4', cat: 'Household' },
  { kw: ['trash', 'garbage', 'bin bag'], emoji: '\uD83D\uDDD1\uFE0F', cat: 'Household' },
  { kw: ['sponge', 'scrub'], emoji: '\uD83E\uDDFD', cat: 'Household' },
  { kw: ['battery', 'batteries'], emoji: '\uD83D\uDD0B', cat: 'Household' },
  { kw: ['light bulb', 'bulb'], emoji: '\uD83D\uDCA1', cat: 'Household' },
  { kw: ['foil', 'wrap', 'ziploc', 'baggie'], emoji: '\uD83D\uDCE6', cat: 'Household' },
  // toiletries / personal
  { kw: ['shampoo', 'conditioner'], emoji: '\uD83E\uDDF4', cat: 'Household' },
  { kw: ['toothpaste', 'toothbrush'], emoji: '\uD83E\uDEA5', cat: 'Household' },
  { kw: ['sunscreen', 'lotion'], emoji: '\uD83E\uDDF4', cat: 'Household' },
  { kw: ['medicine', 'pill', 'vitamin', 'advil', 'tylenol'], emoji: '\uD83D\uDC8A', cat: 'Household' },
  // packing
  { kw: ['shirt', 'tee', 'top'], emoji: '\uD83D\uDC55', cat: 'Clothes' },
  { kw: ['pants', 'jeans', 'trouser'], emoji: '\uD83D\uDC56', cat: 'Clothes' },
  { kw: ['short'], emoji: '\uD83E\uDE73', cat: 'Clothes' },
  { kw: ['dress'], emoji: '\uD83D\uDC57', cat: 'Clothes' },
  { kw: ['sock'], emoji: '\uD83E\uDDE6', cat: 'Clothes' },
  { kw: ['shoe', 'sneaker', 'boot'], emoji: '\uD83D\uDC5F', cat: 'Clothes' },
  { kw: ['jacket', 'coat', 'sweater', 'hoodie'], emoji: '\uD83E\uDDE5', cat: 'Clothes' },
  { kw: ['hat', 'cap'], emoji: '\uD83D\uDC52', cat: 'Clothes' },
  { kw: ['sunglass', 'glasses'], emoji: '\uD83D\uDD76\uFE0F', cat: 'Clothes' },
  { kw: ['charger', 'cable', 'cord'], emoji: '\uD83D\uDD0C', cat: 'Tech' },
  { kw: ['laptop', 'computer'], emoji: '\uD83D\uDCBB', cat: 'Tech' },
  { kw: ['phone'], emoji: '\uD83D\uDCF1', cat: 'Tech' },
  { kw: ['headphone', 'earbud', 'airpod'], emoji: '\uD83C\uDFA7', cat: 'Tech' },
  { kw: ['camera'], emoji: '\uD83D\uDCF7', cat: 'Tech' },
  { kw: ['passport', 'ticket', 'visa'], emoji: '\uD83D\uDEC2', cat: 'Docs & Money' },
  { kw: ['cash', 'money', 'wallet'], emoji: '\uD83D\uDCB5', cat: 'Docs & Money' },
  { kw: ['towel'], emoji: '\uD83C\uDFD6\uFE0F', cat: 'Beach' },
  // to-do verbs
  { kw: ['email', 'reply', 'message'], emoji: '\uD83D\uDCE7', cat: 'Other' },
  { kw: ['call', 'phone', 'ring'], emoji: '\uD83D\uDCDE', cat: 'Other' },
  { kw: ['pay', 'bill', 'invoice', 'rent'], emoji: '\uD83D\uDCB3', cat: 'Other' },
  { kw: ['book', 'appointment', 'schedule', 'reserve'], emoji: '\uD83D\uDCC5', cat: 'Other' },
  { kw: ['clean', 'tidy', 'vacuum', 'laundry'], emoji: '\uD83E\uDDF9', cat: 'Other' },
  { kw: ['water the', 'plant', 'garden'], emoji: '\uD83E\uDEB4', cat: 'Other' },
  { kw: ['gym', 'workout', 'run', 'exercise'], emoji: '\uD83C\uDFCB\uFE0F', cat: 'Other' },
  { kw: ['gift', 'present', 'birthday'], emoji: '\uD83C\uDF81', cat: 'Other' },
  { kw: ['car', 'gas', 'fuel', 'oil change'], emoji: '\uD83D\uDE97', cat: 'Other' },
  { kw: ['dog', 'cat', 'pet', 'vet'], emoji: '\uD83D\uDC36', cat: 'Other' },
];

// List type presets — used when the user creates a new list.
window.LIST_TYPES = [
  {
    key: 'shopping', label: 'Shopping', emoji: '\uD83D\uDED2',
    grouped: true, showQty: true, checkedLabel: 'In cart', suggestKey: 'groceries',
    defaultCat: 'Other',
    catOrder: ['Produce', 'Bakery', 'Dairy & Eggs', 'Meat & Seafood', 'Pantry', 'Frozen', 'Snacks', 'Drinks', 'Household', 'Other'],
  },
  {
    key: 'packing', label: 'Packing', emoji: '\uD83E\uDDF3',
    grouped: true, showQty: true, checkedLabel: 'Packed', suggestKey: 'packing',
    defaultCat: 'Other',
    catOrder: ['Clothes', 'Toiletries', 'Beach', 'Docs & Money', 'Tech', 'Other'],
  },
  {
    key: 'todo', label: 'To-do', emoji: '\u2705',
    grouped: false, showQty: false, checkedLabel: 'Done', suggestKey: 'todo',
    defaultCat: 'Other', catOrder: ['Other'],
  },
];

window.makeList = function (typeKey, name, emoji) {
  const p = window.LIST_TYPES.find((x) => x.key === typeKey) || window.LIST_TYPES[0];
  return {
    id: 'l_' + Math.random().toString(36).slice(2, 9),
    name: (name || '').trim() || p.label,
    emoji: emoji || p.emoji,
    grouped: p.grouped, showQty: p.showQty, checkedLabel: p.checkedLabel,
    suggestKey: p.suggestKey, defaultCat: p.defaultCat, catOrder: p.catOrder.slice(),
    custom: true, members: [{ name: 'You', color: '#7b8bff', me: true }], items: [],
  };
};

// Curated emoji set offered when naming a list.
window.LIST_EMOJIS = [
  '\uD83D\uDED2', '\uD83E\uDDF3', '\u2705', '\uD83C\uDFE0', '\uD83C\uDF7D\uFE0F', '\uD83C\uDF89', '\uD83C\uDF81', '\uD83D\uDCBC',
  '\uD83C\uDFCB\uFE0F', '\uD83D\uDC36', '\uD83C\uDF31', '\uD83D\uDD27', '\uD83C\uDF84', '\uD83C\uDF82', '\uD83D\uDCDA', '\u2708\uFE0F',
  '\uD83C\uDFD5\uFE0F', '\uD83C\uDFA8', '\uD83C\uDFB5', '\u2615', '\uD83C\uDF77', '\uD83D\uDC8A', '\uD83E\uDDF9', '\uD83D\uDEB2',
];
window.EMOJI_PICKER = [
  '\uD83C\uDF4C', '\uD83C\uDF4E', '\uD83C\uDF4A', '\uD83C\uDF53', '\uD83C\uDF47', '\uD83C\uDF49', '\uD83C\uDF51', '\uD83E\uDD6D',
  '\uD83C\uDF45', '\uD83E\uDD51', '\uD83E\uDD55', '\uD83E\uDD66', '\uD83E\uDD6C', '\uD83C\uDF36\uFE0F', '\uD83C\uDF44', '\uD83E\uDDC5',
  '\uD83C\uDF5E', '\uD83E\uDD6F', '\uD83E\uDD50', '\uD83E\uDDC1', '\uD83C\uDF6A', '\uD83E\uDD5A', '\uD83E\uDDC0', '\uD83E\uDD5B',
  '\uD83C\uDF66', '\uD83E\uDDC8', '\uD83C\uDF57', '\uD83E\uDD69', '\uD83E\uDD53', '\uD83D\uDC1F', '\uD83E\uDD90', '\uD83C\uDF5D',
  '\uD83C\uDF5A', '\uD83E\uDED2', '\uD83E\uDDC2', '\uD83C\uDF6F', '\uD83E\uDD5C', '\uD83E\uDD63', '\uD83C\uDF72', '\uD83E\uDD6B',
  '\u2615', '\uD83C\uDF75', '\uD83C\uDF55', '\uD83C\uDF2E', '\uD83C\uDF68', '\uD83C\uDF7F', '\uD83C\uDF6B', '\uD83E\uDDC6',
  '\uD83E\uDD64', '\uD83D\uDCA7', '\uD83E\uDDC3', '\uD83C\uDF7A', '\uD83C\uDF77', '\uD83E\uDDFB', '\uD83E\uDDF4', '\uD83D\uDDD1\uFE0F',
  '\uD83D\uDD0B', '\uD83D\uDCA1', '\uD83D\uDC8A', '\uD83E\uDEA5', '\uD83D\uDC55', '\uD83D\uDC56', '\uD83E\uDDE5', '\uD83D\uDC52',
  '\uD83D\uDC5F', '\uD83E\uDDE6', '\uD83D\uDD76\uFE0F', '\uD83C\uDFD6\uFE0F', '\u26F1\uFE0F', '\uD83E\uDDCA', '\uD83E\uDD3F', '\uD83D\uDEC2',
  '\uD83C\uDFAB', '\uD83D\uDCB5', '\uD83D\uDD0C', '\uD83D\uDCBB', '\uD83D\uDCF1', '\uD83C\uDFA7', '\uD83D\uDCF7', '\uD83D\uDCE7',
  '\uD83D\uDCDE', '\uD83D\uDCB3', '\uD83D\uDCC5', '\uD83E\uDDF9', '\uD83E\uDEB4', '\uD83C\uDF81', '\uD83D\uDE97', '\uD83D\uDC36',
  '\u2705', '\u2B50', '\u2764\uFE0F', '\uD83D\uDD25', '\uD83D\uDCA1', '\uD83D\uDCCC', '\uD83D\uDCDA', '\uD83D\uDED2',
];

// Search index: emoji → [terms], aggregated from the keyword map + catalogs.
// Powers the picker's search field. Extra hand terms cover common synonyms.
window.EMOJI_SEARCH = (function () {
  const idx = {};
  const add = (emoji, words) => {
    if (!emoji) return;
    idx[emoji] = idx[emoji] || new Set();
    words.forEach((w) => { if (w) String(w).toLowerCase().split(/[\s/&]+/).forEach((tok) => tok && idx[emoji].add(tok)); });
  };
  (window.SHOP_KEYWORDS || []).forEach((k) => add(k.emoji, [...k.kw, k.cat]));
  Object.values(window.SHOP_SUGGEST || {}).forEach((arr) => arr.forEach((c) => add(c.emoji, [c.name, c.cat])));
  // a few picker-only icons + extra synonyms
  const extra = {
    '\u2705': ['done', 'check', 'task', 'complete', 'tick'],
    '\u2B50': ['star', 'favorite', 'important'],
    '\u2764\uFE0F': ['heart', 'love', 'like'],
    '\uD83D\uDD25': ['fire', 'hot', 'trending'],
    '\uD83D\uDCCC': ['pin', 'note', 'reminder'],
    '\uD83D\uDED2': ['cart', 'shopping', 'groceries'],
    '\uD83D\uDCDA': ['books', 'library', 'reading', 'study'],
    '\uD83D\uDCA1': ['idea', 'bulb', 'light'],
    '\uD83C\uDF7A': ['beer', 'drink', 'alcohol'],
    '\uD83C\uDF77': ['wine', 'drink', 'alcohol'],
    '\uD83E\uDDC3': ['juice', 'drink'],
  };
  Object.keys(extra).forEach((e) => add(e, extra[e]));
  const out = {};
  Object.keys(idx).forEach((e) => { out[e] = Array.from(idx[e]); });
  return out;
})();
