/* ============================================================
   Төрмен — real product photography map
   Curated, stable food / farm photos (Unsplash CDN). Each
   product gets an ordered gallery; loremflickr is the runtime
   fallback, the warm gradient is the last resort (see Ph).
   ============================================================ */
const U = (id, w=1100) =>
  `https://images.unsplash.com/photo-${id}?auto=format&fit=crop&w=${w}&q=72`;

/* photo pools by visual subject ---------------------------------- */
const POOL = {
  // raw red meat / butcher cuts / qazy-zhaya
  rawred: ['1607623814075-e51df1bdc82f','1603048719539-9ecb4aa395e3','1588347818036-558601350947'].map(id=>U(id)),
  // skewers, mangal, grilled meat
  grill:  ['1555939594-58d7cb561ad1','1544025162-d76694265947','1603360946369-dc9bb6258143','1529193591184-b1d58069ecdd'].map(id=>U(id)),
  // stewed / казан dishes, kuyrdak, plov
  stew:   ['1604908176997-125f25cc6f3d','1633945274405-b6c8069047b0','1547928576-b822bc410bdf'].map(id=>U(id)),
  // broth / soup bowls
  broth:  ['1547592180-85f173990554','1604152135912-04a022e23696','1543339494-b4cd4f7ba686','1620200423727-8127f75d7f53'].map(id=>U(id)),
  // farm / cattle / steppe
  farm:   ['1500595046743-cd271d694d30','1516467508483-a7212febe31a'].map(id=>U(id)),
  // cooking / kitchen (video thumbnails)
  cook:   ['1556909212-d5b604d0c90d','1466637574441-749b8f19452f','1514986888952-8cd320577b68'].map(id=>U(id)),
};

/* compose a gallery from "pool:index" specs --------------------- */
function g(...specs){
  return specs.map(s=>{ const [k,i]=s.split(':'); return (POOL[k]||POOL.rawred)[+i]; }).filter(Boolean);
}

const PHOTO = {
  // ---- family meat sets ----
  'beshbarmak-toi':   g('rawred:0','stew:0','rawred:1','broth:0'),
  'beshbarmak-dala':  g('rawred:1','stew:1','rawred:2','broth:1'),
  'grill-otbasy':     g('grill:0','grill:1','grill:2','grill:3'),
  'kazan-zharkop':    g('stew:0','stew:2','grill:1','rawred:0'),
  'sogym-lux':        g('rawred:2','rawred:0','stew:0','rawred:1'),
  'syrne-set':        g('grill:2','grill:0','stew:2','rawred:1'),
  // ---- broths ----
  'broth-bone':        g('broth:0','broth:1'),
  'broth-lamb':        g('broth:1','broth:2'),
  'broth-chicken':     g('broth:3','broth:0'),
  'broth-concentrate': g('broth:2','broth:3'),
  // ---- generic subject fallbacks ----
  cut: POOL.rawred, grill: POOL.grill, kazan: POOL.stew,
  broth: POOL.broth, farm: POOL.farm, video: POOL.cook,
  // ---- hero / about ----
  hero: g('rawred:0'), 'hero-grill': g('grill:0'),
};

/* video thumbnail by editorial category */
const VIDEO_IMG = { recipe:'stew', farm:'farm', cut:'rawred', story:'cook' };

function imgFor(key, idx=0){
  const arr = PHOTO[key] || POOL[key] || POOL.rawred;
  return arr[((idx % arr.length) + arr.length) % arr.length];
}

Object.assign(window, { PHOTO, PHOTO_POOL: POOL, VIDEO_IMG, imgFor });
