// Shared price list — a euro amount isn't copy, so it only lives once,
// looked up by slug from both language dictionaries below.
const menuPrices = {
  espressoSingle: '1,70 €', espressoDouble: '2,00 €', macchiato: '2,00 €', americano: '2,10 €',
  cortado: '2,20 €', flatWhite: '2,70 €', latte: '2,80 €', cappuccino: '2,90 €', chocoLatte: '2,90 €',
  matchaLatte: '3,50 €', specialtyTea: '1,90 €',
  icedLatte: '3,90 €', icedMatchaLatte: '4,90 €', icedProteinLatte: '5,90 €', icedProteinMatchaLatte: '5,90 €',
  espressoTonic: '4,90 €', icedChocoLatte: '3,90 €',
  caramelExtra: '0,50 €', vanillaExtra: '0,50 €', roomTempExtra: '0,20 €', coconutMilkExtra: '0,50 €',
  medialunaArgentina: '2,95 €', croissant: '2,45 €', alfajores: '3,95 €', cookies: '2,70 €', budines: '2,95 €',
  croissantHamCheese: '3,50 €', medialunaHamCheese: '3,95 €', croissantSerranoBrie: '3,95 €', medialunaSerranoBrie: '4,95 €',
  tostaTomato: '2,90 €', tostaJamButter: '2,90 €', tostaPeanut: '4,90 €', tostaAvocado: '4,90 €',
  focacciaMortadella: '6,90 €', focacciaSerrano: '6,90 €', bagelHam: '5,90 €',
  kombucha: '3,50 €', water: '1,80 €', sparklingWater: '2,40 €', juice: '2,40 €', softDrink: '2,40 €', beerTercio: '2,40 €',
  coldBrew: '3,90 €', v60One: '4,50 €', v60Two: '7,00 €', vermouth: '3,50 €', wineGlass: '3,50 €',
};

function buildMenuGroups(lang) {
  const es = lang === 'es';
  return {
    cafe: {
      label: es ? 'Café' : 'Coffee',
      sections: [
        { title: null, items: [
          { name: 'Espresso Single', price: menuPrices.espressoSingle },
          { name: 'Espresso Double', price: menuPrices.espressoDouble },
          { name: 'Macchiato', price: menuPrices.macchiato },
          { name: 'Americano', price: menuPrices.americano },
          { name: 'Cortado', price: menuPrices.cortado },
          { name: 'Flat White', price: menuPrices.flatWhite },
          { name: 'Latte', price: menuPrices.latte },
          { name: 'Cappuccino', price: menuPrices.cappuccino },
          { name: 'Choco Latte', price: menuPrices.chocoLatte },
        ]},
        { title: 'Non Coffee', items: [
          { name: 'Matcha Latte', price: menuPrices.matchaLatte },
          { name: es ? 'Té de especialidad' : 'Specialty Tea', price: menuPrices.specialtyTea },
        ]},
      ],
    },
    frio: {
      label: es ? 'Frío' : 'Cold drinks',
      sections: [
        { title: null, items: [
          { name: 'Iced Latte', price: menuPrices.icedLatte },
          { name: 'Iced Matcha Latte', price: menuPrices.icedMatchaLatte },
          { name: 'Iced Protein Latte', price: menuPrices.icedProteinLatte },
          { name: 'Iced Protein Matcha Latte', price: menuPrices.icedProteinMatchaLatte },
          { name: 'Espresso Tonic', price: menuPrices.espressoTonic },
          { name: 'Iced Choco Latte', price: menuPrices.icedChocoLatte },
        ]},
        { title: 'Extras', items: [
          { name: 'Caramel', price: menuPrices.caramelExtra },
          { name: es ? 'Vainilla' : 'Vanilla', price: menuPrices.vanillaExtra },
          { name: es ? 'Del tiempo' : 'Room temperature', price: menuPrices.roomTempExtra },
          { name: es ? 'Bebida de coco' : 'Coconut milk', price: menuPrices.coconutMilkExtra },
        ]},
      ],
    },
    picar: {
      label: es ? 'Para picar' : 'Bites',
      sections: [
        { title: es ? 'Pastelería' : 'Pastries', items: [
          { name: es ? 'Medialuna argentina' : 'Argentine Medialuna', price: menuPrices.medialunaArgentina },
          { name: 'Croissant', price: menuPrices.croissant },
          { name: es ? 'Alfajores artesanales' : 'Artisan Alfajores', price: menuPrices.alfajores },
          { name: 'Cookies', price: menuPrices.cookies },
          { name: es ? 'Budines artesanales' : 'Artisan Budines', price: menuPrices.budines },
          { name: es ? 'Croissant jamón york y queso' : 'Ham and Cheese Croissant', price: menuPrices.croissantHamCheese },
          { name: es ? 'Medialuna jamón york y queso' : 'Ham and Cheese Medialuna', price: menuPrices.medialunaHamCheese },
          { name: es ? 'Croissant serrano, rúcula y brie' : 'Croissant with Serrano Ham, Arugula and Brie', price: menuPrices.croissantSerranoBrie },
          { name: es ? 'Medialuna serrano, rúcula y brie' : 'Medialuna with Serrano Ham, Arugula and Brie', price: menuPrices.medialunaSerranoBrie },
        ]},
        { title: es ? 'Tostas · pan de masa madre y cereales' : 'Toasts · sourdough and whole-grain bread', items: [
          { name: es ? 'Tosta Tomate y Aceite' : 'Tomato and Olive Oil Toast', description: es ? 'Tomate, aceite y sal' : 'Tomato, olive oil and salt', price: menuPrices.tostaTomato },
          { name: es ? 'Tosta Mermelada y Mantequilla' : 'Jam and Butter Toast', price: menuPrices.tostaJamButter },
          { name: es ? 'Tosta Cacahuete' : 'Peanut Butter Toast', description: es ? 'Pasta de cacahuete, plátano, canela, miel y chía' : 'Peanut butter, banana, cinnamon, honey and chia seeds', price: menuPrices.tostaPeanut },
          { name: es ? 'Tosta Aguacate' : 'Avocado Toast', description: es ? 'Queso crema, aguacate y huevo duro rallado' : 'Cream cheese, avocado and grated hard-boiled egg', price: menuPrices.tostaAvocado },
        ]},
        { title: es ? 'Focaccias y bagel' : 'Focaccias and Bagel', items: [
          { name: 'Focaccia Mortadella', description: es ? 'Mortadella, mozzarella, rúcula y pesto alla genovese' : 'Mortadella, mozzarella, arugula and pesto alla genovese', price: menuPrices.focacciaMortadella },
          { name: es ? 'Focaccia Jamón Serrano' : 'Serrano Ham Focaccia', description: es ? 'Jamón serrano, queso brie, rúcula y pesto rosso' : 'Serrano ham, brie cheese, arugula and pesto rosso', price: menuPrices.focacciaSerrano },
          { name: es ? 'Bagel Jamón York' : 'Ham and Cheese Bagel', description: es ? 'Jamón york, queso untable y rúcula' : 'Cooked ham, spreadable cheese and arugula', price: menuPrices.bagelHam },
        ]},
      ],
    },
    mas: {
      label: es ? 'Más' : 'More',
      sections: [
        { title: 'Soft drinks', items: [
          { name: 'Kombucha', price: menuPrices.kombucha },
          { name: es ? 'Agua' : 'Water', price: menuPrices.water },
          { name: es ? 'Agua con gas' : 'Sparkling water', price: menuPrices.sparklingWater },
          { name: es ? 'Zumo' : 'Juice', price: menuPrices.juice },
          { name: es ? 'Refresco' : 'Soft drink', price: menuPrices.softDrink },
          { name: es ? 'Tercio' : 'Beer (1/3 L)', price: menuPrices.beerTercio },
        ]},
        { title: 'Specials', items: [
          { name: 'Cold Brew', price: menuPrices.coldBrew },
          { name: es ? 'Filtrado V60 (1 persona)' : 'V60 Filter (1 person)', price: menuPrices.v60One },
          { name: es ? 'Filtrado V60 (2 personas)' : 'V60 Filter (2 people)', price: menuPrices.v60Two },
          { name: es ? 'Vermut artesanal' : 'Craft vermouth', price: menuPrices.vermouth },
          { name: es ? 'Copa de vino' : 'Glass of wine', price: menuPrices.wineGlass },
        ]},
      ],
    },
  };
}

const translations = {
  es: {
    nav: { menu: 'Carta', historia: 'Historia', espacio: 'Espacio', contacto: 'Contacto', openMenu: 'Abrir menú', closeMenu: 'Cerrar menú' },
    hero: {
      eyebrow: 'Social Coffee · Picanya',
      h1Line1: 'Café de', h1Line2: 'especialidad,', h1Line3: 'con calma.',
      paragraph: 'La primera cafetería de especialidad de Picanya. Un rincón para desconectar del ritmo de cada día.',
      ctaMenu: 'Ver menú', ctaDirections: 'Cómo llegar →',
      meta: [
        { label: 'Origen', value: 'Café de especialidad' },
        { label: 'Abierto', value: 'Martes a domingo' },
        { label: 'Dónde', value: 'Picanya, Valencia' },
      ],
      caption: 'El espacio · Picanya',
      imageAlt: 'Interior de Calmaeta, Picanya',
    },
    features: {
      intro: 'Calmaeta es un rincón de café de especialidad en Picanya, pensado para tomarse un buen café, comer algo sencillo y desconectar un rato.',
      items: [
        { label: 'Café de especialidad', desc: 'Seleccionamos cada grano con criterio y lo preparamos con cuidado, en espresso o en filtro, cuidando cada taza del día.' },
        { label: 'Desayunos y almuerzos', desc: 'Tostas, focaccias y platos sencillos con producto de calidad, para desayunar o almorzar sin prisa.' },
        { label: 'Un rincón en Picanya', desc: 'Un espacio pensado para quedarse un rato: buena compañía y el ritmo tranquilo del barrio.' },
      ],
    },
    menu: {
      eyebrow: 'La carta', heading: 'Menu',
      intro: 'Café de especialidad, opciones frías, para picar y algún especial — nuestra carta completa, siempre a mano.',
      footnote: 'Pregúntanos por las especialidades de hoy · Leche entera, sin lactosa o bebida vegetal de avena o coco · Haz tu pedido en la barra, gracias.',
      featureEyebrow: 'Nuestro café', featureName: 'Rebeldes Coffee Roasters',
      featureDescription: 'Trabajamos con Rebeldes Coffee Roasters, con distintos orígenes en cada taza — cada lote se elige y se tuesta con criterio, para que cada café tenga su propio carácter.',
      featureImageAlt: 'Café de Rebeldes Coffee Roasters',
      groups: buildMenuGroups('es'),
    },
    about: {
      eyebrow: 'Nuestra historia',
      paragraphs: [
        'Somos Agustín y Carolina. Llegamos de Argentina a Valencia a finales de 2022, sin conocer a nadie, y nos enamoramos de la calma de Picanya. Nos gustaba el café de especialidad, pero para tomar uno de verdad había que ir hasta Valencia — así que decidimos traerlo aquí.',
        'A finales de 2025 se unió Kike como socio, y todo empezó a encajar. Así nació Calmaeta: la primera cafetería de especialidad de Picanya, y un espacio para compartir un buen café y desconectar del ritmo de cada día.',
      ],
      quote: 'Porque creemos que un buen café siempre sabe mejor cuando se disfruta con calma.',
      founderAgustinRole: 'cofundador', founderCarolinaRole: 'cofundadora',
      agustinAlt: 'Agustín, cofundador de Calmaeta', carolinaAlt: 'Carolina, cofundadora de Calmaeta',
    },
    space: {
      eyebrow: 'El espacio', heading: 'Un rincón en Picanya para quedarse.',
      intro: 'Madera cálida, luz suave y tonos tierra. Un espacio pensado para sentarse, charlar y bajar el ritmo.',
      creditsEyebrow: 'Detrás del espacio',
      designRole: 'Diseño de espacio', designDescription: 'Dieron forma a cada rincón de Calmaeta: madera cálida, luz suave y tonos tierra, pensados para quedarse.',
      photoRole: 'Fotografía', photoDescription: 'Retrató el espacio, el café y cada instante de Calmaeta con luz natural y calma.',
      orangeWallAlt: 'Zona de mesas de Calmaeta, con pared terracota', counterAlt: 'Barra de Calmaeta',
      lampAlt: 'Detalle de mesa', tileAlt: 'Detalle de la barra de azulejos', carouselAlt: 'El espacio de Calmaeta',
    },
    moments: {
      eyebrow: 'Momentos', heading: 'Cada taza, hecha con cuidado.',
      espressoAlt: 'Extracción de espresso', latteArtAlt: 'Latte art en Calmaeta', menuBoardAlt: 'Carta y mostrador de Calmaeta',
    },
    contact: {
      eyebrow: 'Contacto', heading: 'Encuéntranos.',
      addressLabel: 'Dirección', hoursLabel: 'Horario', whatsappLabel: 'WhatsApp', instagramLabel: 'Instagram',
      hours: ['Lun · Cerrado', 'Mar–Vie · 8:30–13:30, 16:00–20:00', 'Sáb · 9:00–13:30, 17:00–20:00', 'Dom · 9:00–14:00'],
      visitUs: 'Visítanos', ctaWhatsapp: 'Escribir por WhatsApp', ctaDirections: 'Cómo llegar', ctaInstagram: 'Ver Instagram',
    },
    footer: {
      tagline: ["Café de especialidad.", "Av. l'Horta, 27, Picanya, Valencia."],
      menuColumnHeader: 'Carta',
      ourStory: 'Nuestra historia', theSpace: 'El espacio', hoursLink: 'Horarios', directionsLink: 'Cómo llegar',
      hoursColumnHeader: 'Horario',
      days: [
        ['Lunes', 'Cerrado'],
        ['Martes', '8:30–13:30, 16:00–20:00'],
        ['Miércoles', '8:30–13:30, 16:00–20:00'],
        ['Jueves', '8:30–13:30, 16:00–20:00'],
        ['Viernes', '8:30–13:30, 16:00–20:00'],
        ['Sábado', '9:00–13:30, 17:00–20:00'],
        ['Domingo', '9:00–14:00'],
      ],
      designCredit: 'Diseño del espacio:', photoCredit: 'Fotografía:',
    },
  },
  en: {
    nav: { menu: 'Menu', historia: 'Story', espacio: 'Space', contacto: 'Contact', openMenu: 'Open menu', closeMenu: 'Close menu' },
    hero: {
      eyebrow: 'Social Coffee · Picanya',
      h1Line1: 'Specialty', h1Line2: 'coffee,', h1Line3: 'at your own pace.',
      paragraph: "Picanya's first specialty coffee shop. A quiet corner to slow down.",
      ctaMenu: 'View menu', ctaDirections: 'Get directions →',
      meta: [
        { label: 'Origin', value: 'Specialty coffee' },
        { label: 'Open', value: 'Tuesday to Sunday' },
        { label: 'Where', value: 'Picanya, Valencia' },
      ],
      caption: 'The space · Picanya',
      imageAlt: 'Interior of Calmaeta, Picanya',
    },
    features: {
      intro: 'Calmaeta is a calm specialty coffee and lunch spot in Picanya, made for good coffee, simple food and a quiet moment.',
      items: [
        { label: 'Specialty coffee', desc: 'We choose every bean with care and prepare it thoughtfully, in espresso or filter, treating every cup of the day the same way.' },
        { label: 'Breakfast and lunch', desc: 'Toasts, focaccias and simple dishes made with good ingredients — for a relaxed breakfast or lunch.' },
        { label: 'A corner of Picanya', desc: "A space made for staying a while: good company and the neighborhood's calm pace." },
      ],
    },
    menu: {
      eyebrow: 'The menu', heading: 'Menu',
      intro: 'Specialty coffee, cold drinks, small bites and daily specials — our full menu, always at hand.',
      footnote: "Ask us about today's specials · Whole milk, lactose-free or oat/coconut milk available · Please order at the counter, thank you.",
      featureEyebrow: 'Our coffee', featureName: 'Rebeldes Coffee Roasters',
      featureDescription: 'We work with Rebeldes Coffee Roasters, featuring different origins in every cup — each batch is carefully selected and roasted so every coffee has its own character.',
      featureImageAlt: 'Coffee from Rebeldes Coffee Roasters',
      groups: buildMenuGroups('en'),
    },
    about: {
      eyebrow: 'Our story',
      paragraphs: [
        "We're Agustín and Carolina. We moved from Argentina to Valencia at the end of 2022, not knowing anyone here, and fell in love with the calm of Picanya. We loved specialty coffee, but getting a proper cup meant going all the way to Valencia — so we decided to bring it here instead.",
        "At the end of 2025, Kike joined as a partner, and everything started to fall into place. That's how Calmaeta was born: Picanya's first specialty coffee shop, and a space to share a good coffee and step away from the rhythm of everyday life.",
      ],
      quote: 'Because we believe a good coffee always tastes better when you take your time to enjoy it.',
      founderAgustinRole: 'co-founder', founderCarolinaRole: 'co-founder',
      agustinAlt: 'Agustín, co-founder of Calmaeta', carolinaAlt: 'Carolina, co-founder of Calmaeta',
    },
    space: {
      eyebrow: 'The space', heading: 'A corner of Picanya worth staying in.',
      intro: 'Warm wood, soft light and earthy tones. A space made for sitting down, talking and slowing down.',
      creditsEyebrow: 'Behind the space',
      designRole: 'Space design', designDescription: 'They shaped every corner of Calmaeta: warm wood, soft light and earthy tones, designed to make you want to stay.',
      photoRole: 'Photography', photoDescription: 'She captured the space, the coffee and every moment of Calmaeta with natural light and calm.',
      orangeWallAlt: 'Seating area at Calmaeta, with terracotta wall', counterAlt: 'Counter at Calmaeta',
      lampAlt: 'Table detail', tileAlt: 'Detail of the tiled counter', carouselAlt: 'The space at Calmaeta',
    },
    moments: {
      eyebrow: 'Moments', heading: 'Every cup, made with care.',
      espressoAlt: 'Espresso extraction', latteArtAlt: 'Latte art at Calmaeta', menuBoardAlt: 'Menu and counter at Calmaeta',
    },
    contact: {
      eyebrow: 'Contact', heading: 'Find us.',
      addressLabel: 'Address', hoursLabel: 'Hours', whatsappLabel: 'WhatsApp', instagramLabel: 'Instagram',
      hours: ['Mon · Closed', 'Tue–Fri · 8:30–13:30, 16:00–20:00', 'Sat · 9:00–13:30, 17:00–20:00', 'Sun · 9:00–14:00'],
      visitUs: 'Visit us', ctaWhatsapp: 'Message on WhatsApp', ctaDirections: 'Get directions', ctaInstagram: 'View Instagram',
    },
    footer: {
      tagline: ['Specialty coffee.', "Av. l'Horta, 27, Picanya, Valencia."],
      menuColumnHeader: 'Menu',
      ourStory: 'Our story', theSpace: 'The space', hoursLink: 'Hours', directionsLink: 'Get directions',
      hoursColumnHeader: 'Hours',
      days: [
        ['Monday', 'Closed'],
        ['Tuesday', '8:30–13:30, 16:00–20:00'],
        ['Wednesday', '8:30–13:30, 16:00–20:00'],
        ['Thursday', '8:30–13:30, 16:00–20:00'],
        ['Friday', '8:30–13:30, 16:00–20:00'],
        ['Saturday', '9:00–13:30, 17:00–20:00'],
        ['Sunday', '9:00–14:00'],
      ],
      designCredit: 'Space design:', photoCredit: 'Photography:',
    },
  },
};

const LangContext = React.createContext(null);

function LangProvider({ children }) {
  const [lang, setLang] = React.useState(() => localStorage.getItem('calmaeta-lang') || 'es');

  React.useEffect(() => {
    localStorage.setItem('calmaeta-lang', lang);
    document.documentElement.lang = lang;
  }, [lang]);

  return (
    <LangContext.Provider value={{ lang, setLang, t: translations[lang] }}>
      {children}
    </LangContext.Provider>
  );
}

function useLang() {
  return React.useContext(LangContext);
}

Object.assign(window, { translations, LangContext, LangProvider, useLang });
