/**
 * Two-locale dictionary (design D13). English is the project default; Bangla is available
 * through the toggle. No i18n framework — two locales do not justify the tooling.
 */
import type { Locale } from "./view-models";

export type { Locale };

const en = {
  youAreInvited: "You are invited",
  dear: "Dear",
  accept: "Accept Invitation",
  decline: "Sorry, I can't make it",
  getDirections: "Get Directions",
  addToCalendar: "Add to Calendar",
  countdownDays: "days",
  countdownHours: "hours",
  countdownMinutes: "minutes",
  venue: "Venue",
  dressCode: "Dress code",
  yourName: "Your name",
  phone: "Phone number",
  email: "Email",
  emailHelp: "So we can send your confirmation and reminders",
  guestsAttending: "Number of guests attending",
  messageToCouple: "Message to the couple",
  dietaryNotes: "Dietary notes",
  optional: "optional",
  required: "required",
  confirm: "Confirm",
  submitting: "Sending…",
  formError: "Something went wrong. Please try again.",
  tooManyRequests: "Too many submissions. Please try again in a few minutes.",
  whichEvents: "Which events are you responding to?",
  selectAtLeastOneEvent: "Please select at least one event",
  verifying: "Checking you're not a robot…",
  verificationFailed: "That check didn't pass. Please try the box above once more.",
  thankYou: "Thank you!",
  seeYouOn: "See you on",
  alreadyAccepted: "You have confirmed your attendance",
  guestsConfirmed: "Guests confirmed",
  updateResponse: "Update my response",
  cancelRsvp: "Cancel my RSVP",
  weWillMissYou: "We'll miss you",
  changedYourMind: "Changed your mind?",
  reAccept: "Re-accept",
  rsvpClosed: "RSVP has closed",
  rsvpClosedHelp: "Please contact the host directly:",
  skipIntro: "Skip",
  unmute: "Play music",
  mute: "Mute music",
  cancelConfirmTitle: "Cancel this RSVP?",
  cancelConfirmBody: "You are confirmed for",
  yesCancel: "Yes, cancel",
  keepRsvp: "Keep my RSVP",
  // `{event}` is substituted by the caller. Suppression is per event, so every one of
  // these strings names the event rather than saying "these emails" (task 3.6).
  unsubscribeTitle: "Stop emails about {event}?",
  unsubscribeScope:
    "This covers {event} only. If you are on the guest list for another event, you will still receive emails about that one.",
  unsubscribeKeepsLink:
    "Your invitation link keeps working — you can still update or cancel your RSVP.",
  unsubscribeConfirm: "Stop these emails",
  rsvpTitle: "Confirm your attendance",
  viewCard: "View the card full screen",
  close: "Close",
  discardChanges: "Close without sending your answer? What you typed will be lost.",
  unsubscribeDoneTitle: "You're unsubscribed from {event}",
  unsubscribeAlready: "You had already unsubscribed from {event}.",
  backToInvitation: "Back to my invitation",
  privacyNotice:
    "Your details will be used only for this wedding and deleted afterwards.",
  /**
   * The host block at the foot of the invitation (design D11).
   *
   * Both live here rather than in the component because they are guest-facing copy like
   * every other string in this file. The host *names* are never translated — they are data
   * an admin types, and a person's name is not translated — but the label and the word
   * joining two of them are chrome, and chrome translates.
   */
  invitedBy: "Invited By",
  hostNameJoin: "And",
};

const bn: Dictionary = {
  youAreInvited: "আপনি আমন্ত্রিত",
  dear: "প্রিয়",
  accept: "আমন্ত্রণ গ্রহণ করুন",
  decline: "দুঃখিত, আমি আসতে পারব না",
  getDirections: "পথের নির্দেশনা",
  addToCalendar: "ক্যালেন্ডারে যোগ করুন",
  countdownDays: "দিন",
  countdownHours: "ঘণ্টা",
  countdownMinutes: "মিনিট",
  venue: "স্থান",
  dressCode: "পোশাক",
  yourName: "আপনার নাম",
  phone: "ফোন নম্বর",
  email: "ইমেইল",
  emailHelp: "নিশ্চিতকরণ ও রিমাইন্ডার পাঠানোর জন্য",
  guestsAttending: "কতজন আসছেন",
  messageToCouple: "বর-কনের জন্য বার্তা",
  dietaryNotes: "খাবার সংক্রান্ত তথ্য",
  optional: "ঐচ্ছিক",
  required: "আবশ্যক",
  confirm: "নিশ্চিত করুন",
  submitting: "পাঠানো হচ্ছে…",
  formError: "কিছু একটা সমস্যা হয়েছে। আবার চেষ্টা করুন।",
  tooManyRequests: "অনেকবার চেষ্টা করা হয়েছে। কিছুক্ষণ পর আবার চেষ্টা করুন।",
  whichEvents: "আপনি কোন অনুষ্ঠানে আসছেন?",
  selectAtLeastOneEvent: "অন্তত একটি অনুষ্ঠান নির্বাচন করুন",
  verifying: "আপনি রোবট নন তা যাচাই করা হচ্ছে…",
  verificationFailed: "যাচাই সম্পূর্ণ হয়নি। উপরের ঘরটি আবার চেষ্টা করুন।",
  thankYou: "ধন্যবাদ!",
  seeYouOn: "দেখা হবে",
  alreadyAccepted: "আপনি উপস্থিতি নিশ্চিত করেছেন",
  guestsConfirmed: "নিশ্চিত অতিথি",
  updateResponse: "উত্তর পরিবর্তন করুন",
  cancelRsvp: "আমার উপস্থিতি বাতিল করুন",
  weWillMissYou: "আপনাকে মিস করব",
  changedYourMind: "মত পরিবর্তন করেছেন?",
  reAccept: "পুনরায় গ্রহণ করুন",
  rsvpClosed: "উত্তর দেওয়ার সময় শেষ",
  rsvpClosedHelp: "অনুগ্রহ করে সরাসরি যোগাযোগ করুন:",
  skipIntro: "এড়িয়ে যান",
  unmute: "গান চালু করুন",
  mute: "গান বন্ধ করুন",
  cancelConfirmTitle: "উপস্থিতি বাতিল করবেন?",
  cancelConfirmBody: "আপনি নিশ্চিত করেছেন",
  yesCancel: "হ্যাঁ, বাতিল করুন",
  keepRsvp: "থাক, বাতিল করব না",
  unsubscribeTitle: "{event} সংক্রান্ত ইমেইল বন্ধ করবেন?",
  unsubscribeScope:
    "এটি শুধু {event}-এর জন্য প্রযোজ্য। অন্য কোনো অনুষ্ঠানের অতিথি তালিকায় আপনার নাম থাকলে সেটির ইমেইল আসতে থাকবে।",
  unsubscribeKeepsLink:
    "আপনার আমন্ত্রণ লিংক সচল থাকবে — উপস্থিতি পরিবর্তন বা বাতিল করতে পারবেন।",
  unsubscribeConfirm: "ইমেইল বন্ধ করুন",
  rsvpTitle: "উপস্থিতি নিশ্চিত করুন",
  viewCard: "কার্ডটি পূর্ণ পর্দায় দেখুন",
  close: "বন্ধ করুন",
  discardChanges: "উত্তর না পাঠিয়ে বন্ধ করবেন? আপনার লেখা তথ্য মুছে যাবে।",
  unsubscribeDoneTitle: "{event}-এর ইমেইল বন্ধ করা হয়েছে",
  unsubscribeAlready: "আপনি আগেই {event}-এর ইমেইল বন্ধ করেছেন।",
  backToInvitation: "আমন্ত্রণে ফিরে যান",
  privacyNotice:
    "আপনার তথ্য শুধুমাত্র এই বিবাহ অনুষ্ঠানের জন্য ব্যবহৃত হবে এবং পরে মুছে ফেলা হবে।",
  invitedBy: "আমন্ত্রণে",
  hostNameJoin: "এবং",
};

/** Derived from the English dictionary, so a key missing from `bn` fails the build. */
export type Dictionary = typeof en;

export const dictionaries: Record<Locale, Dictionary> = { en, bn };

export function getDictionary(locale: Locale): Dictionary {
  return dictionaries[locale] ?? dictionaries.en;
}

export function eventTitle(
  locale: Locale,
  titles: { titleBn: string; titleEn: string },
): string {
  return locale === "bn" ? titles.titleBn : titles.titleEn;
}

/**
 * The host name line for the invitation's footer block (design D6).
 *
 * One host renders alone; two render joined by the dictionary's joining word, primary first.
 * Composed here rather than in the API because it is presentation — the API returns the two
 * names separately so a locale that joins them differently can do so without a schema change.
 */
export function hostNameLine(
  dict: Dictionary,
  host: { hostName1: string; hostName2: string | null },
): string {
  // `hostName2` is NULL rather than "" when there is no second host, but trim anyway: this
  // renders to guests, and a stray space would leave a dangling "And" on the card.
  const second = host.hostName2?.trim();
  return second ? `${host.hostName1} ${dict.hostNameJoin} ${second}` : host.hostName1;
}

/** Dates render in the event's timezone, not the reader's — the wedding is in Dhaka. */
export function formatEventDate(iso: string, locale: Locale): string {
  return new Date(iso).toLocaleDateString(locale === "bn" ? "bn-BD" : "en-GB", {
    weekday: "long",
    day: "numeric",
    month: "long",
    year: "numeric",
    timeZone: "Asia/Dhaka",
  });
}

export function formatEventTime(iso: string, locale: Locale): string {
  return new Date(iso).toLocaleTimeString(locale === "bn" ? "bn-BD" : "en-GB", {
    hour: "numeric",
    minute: "2-digit",
    timeZone: "Asia/Dhaka",
  });
}
