/* eslint-disable */
// Shared dealer roster, artwork and preference for all five casino tables.
const CASINO_DEALERS = (() => {
  const key = 'casinoDealer';
  const roster = [
    { name: 'Melissa', art: 'female', style: 'Warm & playful', portraitScale: 1 },
    { name: 'Scarlett', art: 'scarlett', style: 'Charming & poised', portraitScale: 0.75 },
    { name: 'Marcus', art: 'male', style: 'Dry & deadpan', portraitScale: 0.70 }
  ];
  // Keep returning players on the replacement dealer when their saved choice was Sofia.
  const get = name => roster.find(d => d.name === (name === 'Sofia' ? 'Scarlett' : name)) || roster[0];
  function read() {
    try { return get(localStorage.getItem(key)).name; } catch (_) { return roster[0].name; }
  }
  function select(name) {
    name = get(name).name;
    try { localStorage.setItem(key, name); } catch (_) { /* Session selection still works. */ }
    window.dispatchEvent(new CustomEvent('casino-dealer-change', { detail: name }));
  }
  function art(name, expression = 'idle') {
    return `../assets/casino/dealers/${get(name).art}/${expression}.webp`;
  }
  // Newer portraits have tighter source framing. Match Melissa's head size,
  // using each layer's source so outgoing expressions retain their own scale.
  function portraitScale(src) {
    return (roster.find(d => src.includes(`/dealers/${d.art}/`)) || roster[0]).portraitScale;
  }
  return { key, roster, get, read, select, art, portraitScale,
    options: roster.map(d => ({ value: d.name, label: `${d.name} (${d.style.toLowerCase()})` })) };
})();

function DealerSelect({ name }) {
  return <select aria-label="Switch dealer" title="Switch dealer" value={name}
    onChange={e => CASINO_DEALERS.select(e.target.value)}
    onKeyDown={e => e.stopPropagation()}
    style={{ maxWidth: '100%', minHeight: 32, padding: '4px 3px',
      background: '#21170e', color: '#efd4a4', border: '1px solid #87653d',
      borderRadius: 7, fontFamily: 'inherit', fontSize: 14, cursor: 'pointer',
      letterSpacing: 'normal', textTransform: 'none' }}>
    {CASINO_DEALERS.roster.map(d => <option key={d.name} value={d.name}>{d.name}</option>)}
  </select>;
}

// Scarlett's poised voice uses the same event vocabulary as each game.
function addScarlettVoice(voices) {
  voices.Scarlett = { ...voices.Melissa,
    greet: ["Scarlett at your service, {p}. Shall we begin?", "Welcome to my table, {p}. Best seat in the house."],
    greet_back: ["There's a familiar face. Welcome back, {p}."],
    idle: ["The table is yours, {p}. Whenever you're ready."],
    idle_long: ["Take your time, {p}. I'm here when you need me."],
    bet_low: ["Chips placed. Play at your own pace."],
    bet_mid: ["Your bet is set, {p}."],
    bet_high: ["A bigger wager. Stay comfortable with your stakes."],
    bet_huge: ["That's a substantial bet, {p}. Keep your limits in mind."],
    deal: ["Here are your cards. Let's take a look."],
    player_turn: ["You have {t} against my {u}. Take your time."],
    hit: ["One more card for you."], stand: ["Holding there. My turn."],
    double: ["Double it is. One final card."], split: ["Two hands. One decision at a time."],
    surrender: ["Half your bet returned. Hand complete."], insurance: ["Insurance noted."],
    player_bj: ["A natural twenty-one. Lovely, {p}."],
    player_win: ["Well played, {p}. This one's yours."], dealer_win: ["The house takes this hand."],
    dealer_bust: ["I've gone over. The table wins."],
    streak2: ["Two wins, {p}. Keep a steady head."], streak3: ["Three in a row. Nicely done."],
    streak5: ["Five wins. Remember your limits, {p}."],
    losing_streak: ["A rough run, {p}. A break is always an option."],
    lose_streak: ["A rough run, {p}. A break is always an option."],
    after_tip: ["A little extra sparkle for my evening. Thank you, {p}."], rebet: ["Same wager, set for you."],
    no_more_bets: ["Bets are closed. Watch the wheel."], spin: ["The ball is on its way."],
    result_red: ["Red {n}."], result_black: ["Black {n}."], result_zero: ["Zero. The green pocket."],
    win_small: ["A win for you, {p}."], win_big: ["A lovely payout, {p}."],
    win_straight: ["Right on the number. Thirty-five to one."],
    lose: ["Not this round, {p}."], push: ["Even this time. Your stake comes back."],
    flop: ["Here comes the flop."], turn: ["The turn card."], river: ["And the river."],
    showdown: ["Time to show your cards."], youWin: ["The pot is yours, {p}."],
    youLose: ["The pot goes to your opponent."], youFold: ["Fold noted, {p}."],
    everyoneFold: ["No callers. Collect the pot, {p}."], raise: ["A raise from {p}."],
    allin: ["All in. Let's give everyone a moment."],
    bust: ["That's the limit for this round, {p}. Take a moment."],
    bankrupt: ["Your chips are gone, {p}. A good moment for a break."],
    bet_pp: ["Pair Plus placed."],
    decision_strong: ["A strong hand, {p}. Your decision."],
    decision_marginal: ["A close decision. Take your time."],
    decision_weak: ["A modest hand. Consider your options."],
    fold: ["Fold noted. This hand is finished."],
    fold_pp_save: ["Fold noted. Your Pair Plus still pays."],
    win: ["The hand is yours, {p}. Nicely done."],
    dealer_no_qualify: ["I don't qualify. Ante pays, Play returns."],
    bonus_straight: ["A straight. Collect your Ante Bonus."],
    bonus_trips: ["Three of a kind. A lovely Ante Bonus."],
    bonus_straight_flush: ["A straight flush. A special hand, {p}."],
    pp_pair: ["Your pair pays on Pair Plus."], pp_flush: ["A flush. Pair Plus pays."],
    pp_straight: ["A straight. Pair Plus pays."], pp_trips: ["Three of a kind. Pair Plus pays."],
    pp_sf: ["A straight flush. Enjoy that Pair Plus payout."],
    pass: ["Pass line placed."], dont_pass: ["Don't Pass placed."],
    field: ["Field bet placed."], place: ["Place bet set."],
    come: ["Come bet placed."], odds: ["Odds added."], roll: ["Dice are out. Let's see the roll."],
    point_set: ["The point is {pt}."], natural: ["A natural. Pay the pass line."],
    craps: ["Craps. The pass line loses."], point_made: ["Point made. Pay the line, {p}."],
    seven_out: ["Seven out. That ends the shooter's turn."],
    field_win: ["The field pays."], place_win: ["Your place bet pays."],
    come_set: ["Come bet moves to {pt}."], come_won: ["Your come bet pays, {p}."]
  };
}
Object.assign(window, { CASINO_DEALERS, DealerSelect, addScarlettVoice });
