// ─────────────────────────────────────────────────────────────────
// data.jsx — translations + bootstrap (carrega GIFTS via API)
// ─────────────────────────────────────────────────────────────────

const I18N = {
  pt: {
    'nav.home': 'Início',
    'nav.story': 'O Casal',
    'nav.program': 'Programação',
    'nav.info': 'Informações',
    'nav.rsvp': 'Confirmar',
    'nav.gifts': 'Presentes',
    'nav.gallery': 'Galeria',
    'nav.messages': 'Recados',
    'nav.cta': 'Confirmar Presença',
    'hero.eyebrow': 'Ivory After Dark',
    'hero.subtitle': 'Casamento de Aura & Marcel',
    'hero.date': '27 · Março · 2027',
    'hero.location': 'Suryaa Hotel Pinhais',
    'hero.lede': 'Do silêncio da capela ao brilho íntimo de um rooftop noturno. Convidamos você para celebrar conosco em três atos, um único entardecer que vira noite.',
    'hero.countTo': 'Faltam',
    'hero.days': 'dias',
    'hero.hours': 'horas',
    'hero.mins': 'min',
    'hero.secs': 'seg',
    'story.eyebrow': '01 · O Casal',
    'story.title': 'De um encontro silencioso até <em>aqui</em>',
    'story.badge': 'Aura & Marcel · 2022',
    'story.p1': 'Aura e Marcel se conheceram em uma noite de inverno em Curitiba, num bar de hotel onde nenhum dos dois deveria estar. Conversaram até as luzes baixarem. Foi assim que tudo começou — sem pressa, sem ruído, com uma certeza muito quieta.',
    'story.p2': 'Quatro anos depois, voltamos para o lugar exato onde tudo aconteceu para casar. O Suryaa Hotel Pinhais não é só uma escolha estética: é onde a nossa história tem endereço.',
    'story.sig': '— escrito por nós dois',
    'program.eyebrow': '02 · Programação',
    'program.title': 'Três <em>atos</em>, um único entardecer',
    'program.sub': 'A celebração acontece em três momentos distintos, ligados por uma mesma direção estética. Cada ato tem sua própria luz, paleta e ritmo.',
    'act1.name': 'Capela',
    'act1.time': '16h00',
    'act1.desc': 'Cerimônia religiosa. Silêncio, bênção, flores brancas e luz natural de fim de tarde.',
    'act2.name': 'Recepção',
    'act2.time': '17h30',
    'act2.desc': 'Restaurante do hotel. Piano, champanhe, antepastos e coquetel volante. Acolhedor, sofisticado e iluminado por velas.',
    'act3.name': 'Rooftop',
    'act3.time': '21h00',
    'act3.desc': 'Virada noturna. Bar de hotel boutique, pista, azul-noite, ouro velho e luz âmbar. A festa começa quando o céu escurece.',
    'info.eyebrow': '01 · Informações',
    'info.title': 'Como aproveitar <em>cada</em> momento',
    'info.sub': 'Um manual pequeno para que tudo seja confortável. Se faltar alguma informação, basta nos escrever.',
    'rsvp.eyebrow': '02 · RSVP',
    'rsvp.title': 'Confirme sua <em>presença</em>',
    'rsvp.sub': 'Por favor, confirme até 27 de fevereiro de 2027. Digite seu nome no campo abaixo — ele estará na nossa lista de convidados.',
    'rsvp.placeholder': 'Digite seu nome para localizar...',
    'rsvp.label': 'Nome do convidado',
    'rsvp.notFound': 'Nome não encontrado em nossa lista. Verifique a grafia ou nos contate.',
    'rsvp.companions': 'Acompanhante(s) pré-registrado(s)',
    'rsvp.confirm': 'Confirmar',
    'rsvp.yes': 'Sim, irei',
    'rsvp.no': 'Não poderei',
    'rsvp.success': 'Recebemos sua confirmação',
    'rsvp.successMsg': 'Obrigado por confirmar. Estamos muito felizes em te receber em 27 de março.',
    'rsvp.again': 'Confirmar outro convidado',
    'gifts.eyebrow': '03 · Lista de Presentes',
    'gifts.title': 'Presentes & <em>Lua de Mel</em>',
    'gifts.sub': 'Sua presença já é o nosso maior presente. Mas, se quiser nos ajudar a montar a casa ou a desenhar a lua de mel em Turks and Caicos, escolha um item abaixo — todo pagamento é direto, via Pix ou cartão.',
    'gifts.tabAll': 'Tudo',
    'gifts.tabHome': 'Casa',
    'gifts.tabHoney': 'Lua de Mel',
    'gifts.gift': 'Presentear',
    'gifts.purchased': 'Já presenteado · obrigado',
    'gifts.count': 'itens disponíveis',
    'gallery.eyebrow': '04 · Galeria',
    'gallery.title': 'Pré-<em>wedding</em>',
    'gallery.sub': 'O ensaio que orientou toda a direção estética do casamento — feito no próprio Suryaa.',
    'msg.eyebrow': '05 · Recados',
    'msg.title': 'Deixe um <em>recado</em>',
    'msg.sub': 'Suas palavras serão lidas por nós nos dias que antecedem o casamento — e algumas podem aparecer no nosso álbum.',
    'msg.name': 'Seu nome',
    'msg.from': 'De onde escreve',
    'msg.body': 'Sua mensagem',
    'msg.send': 'Enviar recado',
    'msg.pending': 'Recebemos seu recado — aparecerá aqui após aprovação.',
    'checkout.title': 'Finalizar presente',
    'checkout.pix': 'Pix',
    'checkout.pixSub': 'Instantâneo',
    'checkout.card': 'Cartão de Crédito',
    'checkout.cardSub': 'Até 6× sem juros',
    'checkout.pixCode': 'Código Pix Copia e Cola',
    'checkout.copy': 'Copiar',
    'checkout.copied': 'Copiado!',
    'checkout.cardNumber': 'Número do cartão',
    'checkout.cardName': 'Nome impresso',
    'checkout.cardExpiry': 'Validade',
    'checkout.cardCvv': 'CVV',
    'checkout.installments': 'Parcelamento',
    'checkout.confirm': 'Finalizar Pagamento',
    'checkout.processing': 'Processando...',
    'checkout.waiting': 'Aguardando pagamento...',
    'checkout.success': 'Presente recebido · obrigado',
    'checkout.successMsg': 'Seu pagamento foi confirmado. Em breve enviaremos um e-mail de agradecimento personalizado.',
    'checkout.payerName': 'Seu nome',
    'checkout.payerEmail': 'E-mail (opcional)',
    'checkout.error': 'Não foi possível processar. Tente novamente.',
    'common.close': 'Fechar',
    'common.viewMore': 'Ver mais',
    'common.continue': 'Continuar',
    'common.loading': 'Carregando...',
    'footer.tag': 'Ivory After Dark · 27.03.2027',
    'footer.credit': 'Aura & Marcel · Suryaa Hotel Pinhais',
  },
  en: {
    'nav.home': 'Home',
    'nav.story': 'The Couple',
    'nav.program': 'Programme',
    'nav.info': 'Information',
    'nav.rsvp': 'RSVP',
    'nav.gifts': 'Registry',
    'nav.gallery': 'Gallery',
    'nav.messages': 'Notes',
    'nav.cta': 'RSVP Now',
    'hero.eyebrow': 'Ivory After Dark',
    'hero.subtitle': 'Aura & Marcel · Wedding',
    'hero.date': '27 · March · 2027',
    'hero.location': 'Suryaa Hotel Pinhais',
    'hero.lede': 'From the silence of the chapel to the intimate glow of a night rooftop. We invite you to celebrate with us — three acts within a single fading afternoon.',
    'hero.countTo': 'Counting',
    'hero.days': 'days',
    'hero.hours': 'hours',
    'hero.mins': 'min',
    'hero.secs': 'sec',
    'story.eyebrow': '01 · The Couple',
    'story.title': 'From a quiet meeting to <em>here</em>',
    'story.badge': 'Aura & Marcel · 2022',
    'story.p1': 'Aura and Marcel met on a winter night in Curitiba, at a hotel bar where neither was supposed to be. They talked until the lights went low. That is how everything began — without hurry, without noise, with a very quiet certainty.',
    'story.p2': 'Four years later, we return to the exact place where it all happened to get married. Suryaa Hotel Pinhais is not just an aesthetic choice — it is where our story has an address.',
    'story.sig': '— written by us',
    'program.eyebrow': '02 · Programme',
    'program.title': 'Three <em>acts</em>, one fading afternoon',
    'program.sub': 'The celebration unfolds in three distinct moments, bound by a single aesthetic direction. Each act has its own light, palette and rhythm.',
    'act1.name': 'Chapel',
    'act1.time': '4:00 PM',
    'act1.desc': 'Religious ceremony. Silence, blessing, white florals and the soft natural light of late afternoon.',
    'act2.name': 'Reception',
    'act2.time': '5:30 PM',
    'act2.desc': 'Hotel restaurant. Piano, champagne, antipasti and roaming cocktails. Warm, refined and candlelit.',
    'act3.name': 'Rooftop',
    'act3.time': '9:00 PM',
    'act3.desc': 'After dark. Boutique hotel bar, dancefloor, midnight blue, antique gold and amber light. The party starts when the sky turns.',
    'info.eyebrow': '01 · Information',
    'info.title': 'How to enjoy <em>each</em> moment',
    'info.sub': 'A small handbook so everything is comfortable. If anything is missing, just write to us.',
    'rsvp.eyebrow': '02 · RSVP',
    'rsvp.title': 'Confirm your <em>attendance</em>',
    'rsvp.sub': 'Please confirm by February 27th, 2027. Type your name below — you will find yourself in our guest list.',
    'rsvp.placeholder': 'Type your name to find it...',
    'rsvp.label': 'Guest name',
    'rsvp.notFound': 'Name not found in our list. Please check the spelling or reach out.',
    'rsvp.companions': 'Pre-registered companion(s)',
    'rsvp.confirm': 'Confirm',
    'rsvp.yes': 'Yes, I will',
    'rsvp.no': 'I cannot',
    'rsvp.success': 'Your RSVP was received',
    'rsvp.successMsg': 'Thank you for confirming. We are very happy to host you on March 27.',
    'rsvp.again': 'Confirm another guest',
    'gifts.eyebrow': '03 · Registry',
    'gifts.title': 'Gifts & <em>Honeymoon</em>',
    'gifts.sub': 'Your presence is already our greatest gift. But if you wish to help us furnish our home or design our honeymoon in Turks and Caicos, choose an item below — payment is direct, via Pix or card.',
    'gifts.tabAll': 'All',
    'gifts.tabHome': 'Home',
    'gifts.tabHoney': 'Honeymoon',
    'gifts.gift': 'Gift this',
    'gifts.purchased': 'Already gifted · thank you',
    'gifts.count': 'items available',
    'gallery.eyebrow': '04 · Gallery',
    'gallery.title': 'Pre-<em>wedding</em>',
    'gallery.sub': 'The editorial shoot that set the visual direction for the entire wedding — shot at Suryaa itself.',
    'msg.eyebrow': '05 · Notes',
    'msg.title': 'Leave a <em>note</em>',
    'msg.sub': 'Your words will be read by us in the days leading up to the wedding — and some may appear in our album.',
    'msg.name': 'Your name',
    'msg.from': 'Writing from',
    'msg.body': 'Your message',
    'msg.send': 'Send note',
    'msg.pending': 'Note received — will appear here after approval.',
    'checkout.title': 'Complete gift',
    'checkout.pix': 'Pix',
    'checkout.pixSub': 'Instant',
    'checkout.card': 'Credit Card',
    'checkout.cardSub': 'Up to 6× interest-free',
    'checkout.pixCode': 'Pix Copy & Paste code',
    'checkout.copy': 'Copy',
    'checkout.copied': 'Copied!',
    'checkout.cardNumber': 'Card number',
    'checkout.cardName': 'Cardholder name',
    'checkout.cardExpiry': 'Expiry',
    'checkout.cardCvv': 'CVV',
    'checkout.installments': 'Instalments',
    'checkout.confirm': 'Complete Payment',
    'checkout.processing': 'Processing...',
    'checkout.waiting': 'Waiting for payment...',
    'checkout.success': 'Gift received · thank you',
    'checkout.successMsg': 'Your payment was confirmed. We will send a personalised thank-you note soon.',
    'checkout.payerName': 'Your name',
    'checkout.payerEmail': 'Email (optional)',
    'checkout.error': 'Could not process. Please try again.',
    'common.close': 'Close',
    'common.viewMore': 'View more',
    'common.continue': 'Continue',
    'common.loading': 'Loading...',
    'footer.tag': 'Ivory After Dark · 03.27.2027',
    'footer.credit': 'Aura & Marcel · Suryaa Hotel Pinhais',
  }
};

// ─── API helper ───
const API = {
  base: '',  // relative
  async json(path, opts = {}) {
    const res = await fetch(this.base + path, {
      headers: { 'Content-Type': 'application/json', ...(opts.headers || {}) },
      ...opts
    });
    if (!res.ok) {
      const err = await res.json().catch(() => ({ error: res.statusText }));
      throw new Error(err.error || 'request failed');
    }
    return res.json();
  },
  gifts: () => API.json('/api/gifts'),
  searchGuests: (q) => API.json('/api/guests/search?q=' + encodeURIComponent(q)),
  rsvp: (payload) => API.json('/api/rsvp', { method: 'POST', body: JSON.stringify(payload) }),
  messages: () => API.json('/api/messages'),
  postMessage: (payload) => API.json('/api/messages', { method: 'POST', body: JSON.stringify(payload) }),
  createPayment: (payload) => API.json('/api/payments/create', { method: 'POST', body: JSON.stringify(payload) }),
  paymentStatus: (id) => API.json('/api/payments/status?id=' + encodeURIComponent(id)),
};

// ─── Bootstrap: carrega GIFTS antes de o App renderizar ───
window.GIFTS = [];
window.__dataReady = (async () => {
  try {
    const { gifts } = await API.gifts();
    window.GIFTS = gifts || [];
  } catch (e) {
    console.error('Falha ao carregar presentes:', e);
    window.GIFTS = [];
  }
})();

Object.assign(window, { I18N, API });
