// quotes.ts - Curated quotes collection and utility functions

export interface LocalQuote {
  text: string;
  author: string;
  language: "de" | "en" | "fr" | "es" | "it";
  tags: string[];
}

export const PRESET_QUOTE_SOURCES = [
  {
    name: "ZenQuotes",
    url: "https://zenquotes.io/api/random",
    language: "en",
    tags: ["motivation", "wisdom", "life"],
  },
  {
    name: "Quotable",
    url: "https://api.quotable.io/random",
    language: "en",
    tags: ["motivation", "wisdom", "success", "life"],
  },
  {
    name: "Forismatic",
    url: "https://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=de",
    language: "de",
    tags: ["motivation", "wisdom", "life"],
  },
  {
    name: "Type.fit",
    url: "https://type.fit/api/quotes",
    language: "en",
    tags: ["motivation", "wisdom"],
  },
] as const;

export const LOCAL_QUOTES: LocalQuote[] = [
  // --- German Quotes ---
  {
    text: "Es ist nicht genug zu wissen, man muss auch anwenden; es ist nicht genug zu wollen, man muss auch tun.",
    author: "Johann Wolfgang von Goethe",
    language: "de",
    tags: ["motivation", "work", "perseverance"],
  },
  {
    text: "Wer immer tut, was er schon kann, bleibt immer das, was er schon ist.",
    author: "Henry Ford",
    language: "de",
    tags: ["motivation", "success", "perseverance"],
  },
  {
    text: "Der Zweck des Lebens ist das Leben selbst.",
    author: "Johann Wolfgang von Goethe",
    language: "de",
    tags: ["life", "wisdom"],
  },
  {
    text: "Man muss das Unmogliche versuchen, um das Mogliche zu erreichen.",
    author: "Hermann Hesse",
    language: "de",
    tags: ["motivation", "perseverance"],
  },
  {
    text: "Wer nicht kann, was er will, muss wollen, was er kann.",
    author: "Friedrich Schiller",
    language: "de",
    tags: ["wisdom", "perseverance", "life"],
  },
  {
    text: "Es hort doch jeder nur, was er versteht.",
    author: "Johann Wolfgang von Goethe",
    language: "de",
    tags: ["wisdom", "life"],
  },
  {
    text: "Ohne Musik ware das Leben ein Irrtum.",
    author: "Friedrich Nietzsche",
    language: "de",
    tags: ["life", "creativity"],
  },
  {
    text: "Wege entstehen dadurch, dass man sie geht.",
    author: "Franz Kafka",
    language: "de",
    tags: ["motivation", "perseverance", "life"],
  },
  {
    text: "Der Mensch ist nichts anderes als wozu er sich macht.",
    author: "Jean-Paul Sartre",
    language: "de",
    tags: ["wisdom", "life", "motivation"],
  },
  {
    text: "Wer kampft, kann verlieren. Wer nicht kampft, hat schon verloren.",
    author: "Bertolt Brecht",
    language: "de",
    tags: ["motivation", "perseverance", "success"],
  },
  {
    text: "Die Grenzen meiner Sprache bedeuten die Grenzen meiner Welt.",
    author: "Ludwig Wittgenstein",
    language: "de",
    tags: ["wisdom", "creativity"],
  },
  {
    text: "Was mich nicht umbringt, macht mich starker.",
    author: "Friedrich Nietzsche",
    language: "de",
    tags: ["perseverance", "motivation"],
  },
  {
    text: "Phantasie ist wichtiger als Wissen, denn Wissen ist begrenzt.",
    author: "Albert Einstein",
    language: "de",
    tags: ["creativity", "wisdom"],
  },
  {
    text: "Nur wer sein Ziel kennt, findet den Weg.",
    author: "Laozi",
    language: "de",
    tags: ["wisdom", "motivation", "success"],
  },
  {
    text: "Die beste Zeit einen Baum zu pflanzen war vor zwanzig Jahren. Die zweitbeste Zeit ist jetzt.",
    author: "Konfuzius",
    language: "de",
    tags: ["wisdom", "motivation", "work"],
  },
  {
    text: "Auch aus Steinen, die einem in den Weg gelegt werden, kann man Schones bauen.",
    author: "Johann Wolfgang von Goethe",
    language: "de",
    tags: ["perseverance", "creativity", "life"],
  },
  {
    text: "Handle, ehe du gehandelt wirst.",
    author: "Friedrich Schiller",
    language: "de",
    tags: ["motivation", "work"],
  },
  {
    text: "Geduld ist das Vertrauen, dass alles kommt, wenn die Zeit reif ist.",
    author: "Konfuzius",
    language: "de",
    tags: ["wisdom", "perseverance", "life"],
  },
  {
    text: "Im Wesen der Musik liegt es, Freude zu machen.",
    author: "Aristoteles",
    language: "de",
    tags: ["creativity", "life", "humor"],
  },
  {
    text: "Lache nie uber die Dummheit der anderen. Sie ist deine Chance.",
    author: "Winston Churchill",
    language: "de",
    tags: ["humor", "success", "wisdom"],
  },
  {
    text: "Leben ist das, was passiert, wahrend du eifrig dabei bist, andere Plane zu machen.",
    author: "John Lennon",
    language: "de",
    tags: ["life", "humor", "wisdom"],
  },
  {
    text: "Der Langsamste, der sein Ziel nicht aus den Augen verliert, geht noch immer geschwinder als jener, der ohne Ziel umherirrt.",
    author: "Gotthold Ephraim Lessing",
    language: "de",
    tags: ["perseverance", "motivation", "work"],
  },
  {
    text: "Ein Tropfen Humor auf einen Zentner Verstand.",
    author: "Friedrich Nietzsche",
    language: "de",
    tags: ["humor", "wisdom"],
  },
  // --- English Quotes ---
  {
    text: "The only way to do great work is to love what you do.",
    author: "Steve Jobs",
    language: "en",
    tags: ["work", "motivation", "success"],
  },
  {
    text: "Stay hungry, stay foolish.",
    author: "Steve Jobs",
    language: "en",
    tags: ["motivation", "creativity"],
  },
  {
    text: "Life is what happens when you are busy making other plans.",
    author: "John Lennon",
    language: "en",
    tags: ["life", "wisdom"],
  },
  {
    text: "In the middle of difficulty lies opportunity.",
    author: "Albert Einstein",
    language: "en",
    tags: ["perseverance", "motivation", "success"],
  },
  {
    text: "The unexamined life is not worth living.",
    author: "Socrates",
    language: "en",
    tags: ["wisdom", "life"],
  },
  {
    text: "Be yourself; everyone else is already taken.",
    author: "Oscar Wilde",
    language: "en",
    tags: ["life", "wisdom", "humor"],
  },
  {
    text: "To live is the rarest thing in the world. Most people exist, that is all.",
    author: "Oscar Wilde",
    language: "en",
    tags: ["life", "wisdom"],
  },
  {
    text: "The man who moves a mountain begins by carrying away small stones.",
    author: "Konfuzius",
    language: "en",
    tags: ["perseverance", "motivation", "work"],
  },
  {
    text: "It is not because things are difficult that we do not dare; it is because we do not dare that they are difficult.",
    author: "Seneca",
    language: "en",
    tags: ["motivation", "perseverance", "wisdom"],
  },
  {
    text: "The happiness of your life depends upon the quality of your thoughts.",
    author: "Marcus Aurelius",
    language: "en",
    tags: ["wisdom", "life"],
  },
  {
    text: "Waste no more time arguing about what a good man should be. Be one.",
    author: "Marcus Aurelius",
    language: "en",
    tags: ["wisdom", "motivation", "work"],
  },
  {
    text: "If you want to lift yourself up, lift up someone else.",
    author: "Booker T. Washington",
    language: "en",
    tags: ["motivation", "wisdom", "life"],
  },
  {
    text: "Darkness cannot drive out darkness; only light can do that.",
    author: "Martin Luther King Jr.",
    language: "en",
    tags: ["wisdom", "life", "motivation"],
  },
  {
    text: "The time is always right to do what is right.",
    author: "Martin Luther King Jr.",
    language: "en",
    tags: ["motivation", "wisdom", "work"],
  },
  {
    text: "There is no greater agony than bearing an untold story inside you.",
    author: "Maya Angelou",
    language: "en",
    tags: ["creativity", "life"],
  },
  {
    text: "We delight in the beauty of the butterfly, but rarely admit the changes it has gone through to achieve that beauty.",
    author: "Maya Angelou",
    language: "en",
    tags: ["perseverance", "life", "wisdom"],
  },
  {
    text: "The secret of getting ahead is getting started.",
    author: "Mark Twain",
    language: "en",
    tags: ["motivation", "work", "success"],
  },
  {
    text: "Whenever you find yourself on the side of the majority, it is time to pause and reflect.",
    author: "Mark Twain",
    language: "en",
    tags: ["wisdom", "creativity"],
  },
  {
    text: "Twenty years from now you will be more disappointed by the things you did not do than by the ones you did.",
    author: "Mark Twain",
    language: "en",
    tags: ["motivation", "life", "perseverance"],
  },
  {
    text: "It does not matter how slowly you go as long as you do not stop.",
    author: "Konfuzius",
    language: "en",
    tags: ["perseverance", "motivation"],
  },
  {
    text: "Success is not final, failure is not fatal: it is the courage to continue that counts.",
    author: "Winston Churchill",
    language: "en",
    tags: ["perseverance", "success", "motivation"],
  },
  {
    text: "The best time to plant a tree was 20 years ago. The second best time is now.",
    author: "Chinese Proverb",
    language: "en",
    tags: ["motivation", "wisdom", "work"],
  },
  {
    text: "Do what you can, with what you have, where you are.",
    author: "Theodore Roosevelt",
    language: "en",
    tags: ["motivation", "work", "perseverance"],
  },
  {
    text: "Creativity is intelligence having fun.",
    author: "Albert Einstein",
    language: "en",
    tags: ["creativity", "humor", "wisdom"],
  },
  {
    text: "Everything you can imagine is real.",
    author: "Pablo Picasso",
    language: "en",
    tags: ["creativity", "motivation"],
  },
  {
    text: "I have not failed. I have just found 10,000 ways that will not work.",
    author: "Thomas Edison",
    language: "en",
    tags: ["perseverance", "humor", "success"],
  },
  {
    text: "Well done is better than well said.",
    author: "Benjamin Franklin",
    language: "en",
    tags: ["work", "motivation", "success"],
  },
  {
    text: "You miss 100% of the shots you do not take.",
    author: "Wayne Gretzky",
    language: "en",
    tags: ["motivation", "success"],
  },
  // --- Additional German Quotes ---
  {
    text: "Das Geheimnis des Vorwartskommens besteht darin, den ersten Schritt zu tun.",
    author: "Mark Twain",
    language: "de",
    tags: ["motivation", "work"],
  },
  {
    text: "Nicht der Wind, sondern das Segel bestimmt die Richtung.",
    author: "Chinesisches Sprichwort",
    language: "de",
    tags: ["wisdom", "life", "motivation"],
  },
  {
    text: "Erfolg hat drei Buchstaben: T-U-N.",
    author: "Johann Wolfgang von Goethe",
    language: "de",
    tags: ["motivation", "work", "success"],
  },
  {
    text: "Die Zukunft gehort denen, die an die Schonheit ihrer Traume glauben.",
    author: "Eleanor Roosevelt",
    language: "de",
    tags: ["motivation", "life", "creativity"],
  },
  {
    text: "Sei du selbst die Veranderung, die du dir wunschst fur diese Welt.",
    author: "Mahatma Gandhi",
    language: "de",
    tags: ["wisdom", "life", "motivation"],
  },
  {
    text: "Jeder Tag ist ein neuer Anfang.",
    author: "T.S. Eliot",
    language: "de",
    tags: ["motivation", "life"],
  },
  {
    text: "Wer aufhort besser zu werden, hat aufgehort gut zu sein.",
    author: "Philip Rosenthal",
    language: "de",
    tags: ["perseverance", "work", "success"],
  },
  {
    text: "Ordnung braucht nur der Dumme, das Genie beherrscht das Chaos.",
    author: "Albert Einstein",
    language: "de",
    tags: ["humor", "creativity", "wisdom"],
  },
  {
    text: "In der Mitte von Schwierigkeiten liegen die Moglichkeiten.",
    author: "Albert Einstein",
    language: "de",
    tags: ["perseverance", "motivation"],
  },
  {
    text: "Es gibt keine Abkurzung zu einem Ort, der es wert ist, erreicht zu werden.",
    author: "Beverly Sills",
    language: "de",
    tags: ["perseverance", "success", "work"],
  },
  {
    text: "Wer das Ziel kennt, kann entscheiden; wer entscheidet, findet Ruhe.",
    author: "Konfuzius",
    language: "de",
    tags: ["wisdom", "life"],
  },
  {
    text: "Kreativitat ist Intelligenz, die Spass hat.",
    author: "Albert Einstein",
    language: "de",
    tags: ["creativity", "humor"],
  },
  {
    text: "Der beste Weg, die Zukunft vorherzusagen, ist sie zu gestalten.",
    author: "Peter Drucker",
    language: "de",
    tags: ["motivation", "work", "success"],
  },
  {
    text: "Anfangen ist leicht, beharren eine Kunst.",
    author: "Deutsches Sprichwort",
    language: "de",
    tags: ["perseverance", "work"],
  },
  {
    text: "Alles, was du dir vorstellen kannst, ist real.",
    author: "Pablo Picasso",
    language: "de",
    tags: ["creativity", "motivation"],
  },
  // --- Additional English Quotes ---
  {
    text: "Don't watch the clock; do what it does. Keep going.",
    author: "Sam Levenson",
    language: "en",
    tags: ["motivation", "perseverance", "work"],
  },
  {
    text: "The only impossible journey is the one you never begin.",
    author: "Tony Robbins",
    language: "en",
    tags: ["motivation", "perseverance"],
  },
  {
    text: "What you get by achieving your goals is not as important as what you become by achieving your goals.",
    author: "Zig Ziglar",
    language: "en",
    tags: ["success", "wisdom", "motivation"],
  },
  {
    text: "Act as if what you do makes a difference. It does.",
    author: "William James",
    language: "en",
    tags: ["motivation", "work"],
  },
  {
    text: "The future belongs to those who believe in the beauty of their dreams.",
    author: "Eleanor Roosevelt",
    language: "en",
    tags: ["motivation", "life", "creativity"],
  },
  {
    text: "Be the change that you wish to see in the world.",
    author: "Mahatma Gandhi",
    language: "en",
    tags: ["wisdom", "life", "motivation"],
  },
  {
    text: "Start where you are. Use what you have. Do what you can.",
    author: "Arthur Ashe",
    language: "en",
    tags: ["motivation", "work", "perseverance"],
  },
  {
    text: "What lies behind us and what lies before us are tiny matters compared to what lies within us.",
    author: "Ralph Waldo Emerson",
    language: "en",
    tags: ["wisdom", "motivation", "life"],
  },
  {
    text: "The best way to predict the future is to create it.",
    author: "Peter Drucker",
    language: "en",
    tags: ["motivation", "work", "success"],
  },
  {
    text: "Small daily improvements over time lead to stunning results.",
    author: "Robin Sharma",
    language: "en",
    tags: ["perseverance", "success", "work"],
  },
  {
    text: "Your limitation—it's only your imagination.",
    author: "Unknown",
    language: "en",
    tags: ["motivation", "creativity"],
  },
  {
    text: "Great things never come from comfort zones.",
    author: "Unknown",
    language: "en",
    tags: ["motivation", "perseverance", "success"],
  },
  {
    text: "Dream it. Wish it. Do it.",
    author: "Unknown",
    language: "en",
    tags: ["motivation", "work"],
  },
  {
    text: "Don't stop when you are tired. Stop when you are done.",
    author: "Unknown",
    language: "en",
    tags: ["perseverance", "motivation", "work"],
  },
  {
    text: "Hard work beats talent when talent doesn't work hard.",
    author: "Tim Notke",
    language: "en",
    tags: ["work", "perseverance", "success"],
  },
  // --- French Quotes ---
  {
    text: "Il n'y a qu'une façon d'échouer, c'est d'abandonner avant d'avoir réussi.",
    author: "Olivier Lockert",
    language: "fr",
    tags: ["perseverance", "motivation"],
  },
  {
    text: "Le succès n'est pas final, l'échec n'est pas fatal : c'est le courage de continuer qui compte.",
    author: "Winston Churchill",
    language: "fr",
    tags: ["perseverance", "success", "motivation"],
  },
  {
    text: "La vie, ce n'est pas d'attendre que les orages passent, c'est d'apprendre à danser sous la pluie.",
    author: "Sénèque",
    language: "fr",
    tags: ["life", "wisdom", "perseverance"],
  },
  {
    text: "Ce n'est pas parce que les choses sont difficiles que nous n'osons pas, c'est parce que nous n'osons pas qu'elles sont difficiles.",
    author: "Sénèque",
    language: "fr",
    tags: ["motivation", "wisdom"],
  },
  {
    text: "Le meilleur moment pour planter un arbre était il y a vingt ans. Le deuxième meilleur moment est maintenant.",
    author: "Proverbe chinois",
    language: "fr",
    tags: ["motivation", "wisdom", "work"],
  },
  {
    text: "Celui qui déplace une montagne commence par déplacer de petites pierres.",
    author: "Confucius",
    language: "fr",
    tags: ["perseverance", "motivation", "work"],
  },
  {
    text: "La simplicité est la sophistication suprême.",
    author: "Léonard de Vinci",
    language: "fr",
    tags: ["wisdom", "creativity"],
  },
  {
    text: "Rien n'est permanent, sauf le changement.",
    author: "Héraclite",
    language: "fr",
    tags: ["wisdom", "life"],
  },
  {
    text: "Fais de ta vie un rêve, et d'un rêve, une réalité.",
    author: "Antoine de Saint-Exupéry",
    language: "fr",
    tags: ["motivation", "life", "creativity"],
  },
  {
    text: "L'imagination est plus importante que le savoir.",
    author: "Albert Einstein",
    language: "fr",
    tags: ["creativity", "wisdom"],
  },
  {
    text: "On ne voit bien qu'avec le cœur. L'essentiel est invisible pour les yeux.",
    author: "Antoine de Saint-Exupéry",
    language: "fr",
    tags: ["wisdom", "life"],
  },
  {
    text: "Le bonheur n'est pas quelque chose de prêt à l'emploi. Il vient de vos propres actions.",
    author: "Dalaï Lama",
    language: "fr",
    tags: ["wisdom", "life", "motivation"],
  },
  {
    text: "Chaque jour est une nouvelle chance de changer ta vie.",
    author: "Inconnu",
    language: "fr",
    tags: ["motivation", "life"],
  },
  {
    text: "Il faut toujours viser la lune, car même en cas d'échec, on atterrit dans les étoiles.",
    author: "Oscar Wilde",
    language: "fr",
    tags: ["motivation", "success"],
  },
  {
    text: "La créativité, c'est l'intelligence qui s'amuse.",
    author: "Albert Einstein",
    language: "fr",
    tags: ["creativity", "humor"],
  },
  // --- Spanish Quotes ---
  {
    text: "No es la especie más fuerte la que sobrevive, sino la que mejor se adapta al cambio.",
    author: "Charles Darwin",
    language: "es",
    tags: ["wisdom", "perseverance", "life"],
  },
  {
    text: "El único modo de hacer un gran trabajo es amar lo que haces.",
    author: "Steve Jobs",
    language: "es",
    tags: ["work", "motivation", "success"],
  },
  {
    text: "La vida es lo que pasa mientras estás ocupado haciendo otros planes.",
    author: "John Lennon",
    language: "es",
    tags: ["life", "wisdom"],
  },
  {
    text: "Sé tú mismo; todos los demás ya están ocupados.",
    author: "Oscar Wilde",
    language: "es",
    tags: ["life", "wisdom", "humor"],
  },
  {
    text: "El mejor momento para plantar un árbol fue hace veinte años. El segundo mejor momento es ahora.",
    author: "Proverbio chino",
    language: "es",
    tags: ["motivation", "wisdom", "work"],
  },
  {
    text: "La imaginación es más importante que el conocimiento.",
    author: "Albert Einstein",
    language: "es",
    tags: ["creativity", "wisdom"],
  },
  {
    text: "No importa lo lento que vayas, siempre y cuando no te detengas.",
    author: "Confucio",
    language: "es",
    tags: ["perseverance", "motivation"],
  },
  {
    text: "El secreto de ir adelante es empezar.",
    author: "Mark Twain",
    language: "es",
    tags: ["motivation", "work", "success"],
  },
  {
    text: "La felicidad de tu vida depende de la calidad de tus pensamientos.",
    author: "Marco Aurelio",
    language: "es",
    tags: ["wisdom", "life"],
  },
  {
    text: "Sé el cambio que deseas ver en el mundo.",
    author: "Mahatma Gandhi",
    language: "es",
    tags: ["wisdom", "life", "motivation"],
  },
  {
    text: "La creatividad es la inteligencia divirtiéndose.",
    author: "Albert Einstein",
    language: "es",
    tags: ["creativity", "humor"],
  },
  {
    text: "Cada día es una nueva oportunidad para cambiar tu vida.",
    author: "Desconocido",
    language: "es",
    tags: ["motivation", "life"],
  },
  {
    text: "Lo que no te mata, te hace más fuerte.",
    author: "Friedrich Nietzsche",
    language: "es",
    tags: ["perseverance", "motivation"],
  },
  {
    text: "Haz lo que puedas, con lo que tengas, donde estés.",
    author: "Theodore Roosevelt",
    language: "es",
    tags: ["motivation", "work", "perseverance"],
  },
  {
    text: "Grandes cosas nunca vienen de la zona de confort.",
    author: "Desconocido",
    language: "es",
    tags: ["motivation", "perseverance", "success"],
  },
  // --- Italian Quotes ---
  {
    text: "La semplicità è la raffinatezza suprema.",
    author: "Leonardo da Vinci",
    language: "it",
    tags: ["wisdom", "creativity"],
  },
  {
    text: "Nel mezzo delle difficoltà nascono le opportunità.",
    author: "Albert Einstein",
    language: "it",
    tags: ["perseverance", "motivation", "success"],
  },
  {
    text: "L'unico modo di fare un ottimo lavoro è amare quello che fai.",
    author: "Steve Jobs",
    language: "it",
    tags: ["work", "motivation", "success"],
  },
  {
    text: "Chi non osa nulla, non speri nulla.",
    author: "Friedrich Schiller",
    language: "it",
    tags: ["motivation", "perseverance"],
  },
  {
    text: "La vita è quello che ti accade mentre sei impegnato a fare altri progetti.",
    author: "John Lennon",
    language: "it",
    tags: ["life", "wisdom"],
  },
  {
    text: "Sii il cambiamento che vuoi vedere nel mondo.",
    author: "Mahatma Gandhi",
    language: "it",
    tags: ["wisdom", "life", "motivation"],
  },
  {
    text: "Il miglior momento per piantare un albero era vent'anni fa. Il secondo miglior momento è adesso.",
    author: "Proverbio cinese",
    language: "it",
    tags: ["motivation", "wisdom", "work"],
  },
  {
    text: "Non importa quanto vai piano, l'importante è non fermarsi.",
    author: "Confucio",
    language: "it",
    tags: ["perseverance", "motivation"],
  },
  {
    text: "Il segreto per andare avanti è iniziare.",
    author: "Mark Twain",
    language: "it",
    tags: ["motivation", "work", "success"],
  },
  {
    text: "La fantasia è più importante del sapere.",
    author: "Albert Einstein",
    language: "it",
    tags: ["creativity", "wisdom"],
  },
  {
    text: "Quello che non ti uccide ti rende più forte.",
    author: "Friedrich Nietzsche",
    language: "it",
    tags: ["perseverance", "motivation"],
  },
  {
    text: "La creatività è l'intelligenza che si diverte.",
    author: "Albert Einstein",
    language: "it",
    tags: ["creativity", "humor"],
  },
  {
    text: "Ogni giorno è un nuovo inizio.",
    author: "T.S. Eliot",
    language: "it",
    tags: ["motivation", "life"],
  },
  {
    text: "Fai quel che puoi, con quel che hai, dove sei.",
    author: "Theodore Roosevelt",
    language: "it",
    tags: ["motivation", "work", "perseverance"],
  },
  {
    text: "Le grandi cose non vengono mai dalla zona di comfort.",
    author: "Sconosciuto",
    language: "it",
    tags: ["motivation", "perseverance", "success"],
  },
];

/**
 * All unique tags available across the local quotes collection.
 */
export const AVAILABLE_QUOTE_TAGS: string[] = Array.from(
  new Set(LOCAL_QUOTES.flatMap((q) => q.tags))
).sort();

/**
 * Returns a random quote from the local collection, optionally filtered
 * by language and/or tag.
 *
 * @param language - Filter by "de" or "en". If omitted, picks from all.
 * @param tag - Filter by a specific tag (e.g. "motivation"). If omitted, no tag filter.
 * @returns A random LocalQuote matching the filters, or a fallback if no match found.
 */
export function getRandomLocalQuote(
  language?: string,
  tag?: string
): LocalQuote {
  let pool = LOCAL_QUOTES;

  if (language) {
    pool = pool.filter((q) => q.language === language);
  }

  if (tag) {
    pool = pool.filter((q) => q.tags.includes(tag));
  }

  if (pool.length === 0) {
    // Fallback: return a random quote from the full collection
    return LOCAL_QUOTES[Math.floor(Math.random() * LOCAL_QUOTES.length)];
  }

  return pool[Math.floor(Math.random() * pool.length)];
}
