/**
 * i18n string catalog for the vanilla embed SDK cookie banner.
 *
 * Phase 4: extracted from embed.ts.
 */

import type { ConsentPurpose } from '@breakpilot/compliance-sdk-types'

export type BannerLanguage = 'de' | 'en'

export interface CategoryCopy {
  name: string
  description: string
}

export interface BannerCopy {
  title: string
  description: string
  acceptAll: string
  rejectAll: string
  settings: string
  save: string
  privacy: string
  imprint: string
  categories: Record<ConsentPurpose, CategoryCopy>
}

export const TRANSLATIONS: Record<BannerLanguage, BannerCopy> = {
  de: {
    title: 'Cookie-Einwilligung',
    description:
      'Wir verwenden Cookies, um Ihre Erfahrung zu verbessern. Weitere Informationen finden Sie in unserer Datenschutzerklärung.',
    acceptAll: 'Alle akzeptieren',
    rejectAll: 'Nur notwendige',
    settings: 'Einstellungen',
    save: 'Speichern',
    privacy: 'Datenschutz',
    imprint: 'Impressum',
    categories: {
      ESSENTIAL: { name: 'Notwendig', description: 'Erforderlich für die Grundfunktionen' },
      FUNCTIONAL: { name: 'Funktional', description: 'Verbesserte Funktionen' },
      ANALYTICS: { name: 'Analyse', description: 'Nutzungsstatistiken' },
      MARKETING: { name: 'Marketing', description: 'Personalisierte Werbung' },
      PERSONALIZATION: { name: 'Personalisierung', description: 'Angepasste Inhalte' },
      THIRD_PARTY: { name: 'Drittanbieter', description: 'Externe Dienste' },
    },
  },
  en: {
    title: 'Cookie Consent',
    description:
      'We use cookies to improve your experience. For more information, please see our privacy policy.',
    acceptAll: 'Accept All',
    rejectAll: 'Reject Non-Essential',
    settings: 'Settings',
    save: 'Save',
    privacy: 'Privacy Policy',
    imprint: 'Imprint',
    categories: {
      ESSENTIAL: { name: 'Essential', description: 'Required for basic functionality' },
      FUNCTIONAL: { name: 'Functional', description: 'Enhanced features' },
      ANALYTICS: { name: 'Analytics', description: 'Usage statistics' },
      MARKETING: { name: 'Marketing', description: 'Personalized advertising' },
      PERSONALIZATION: { name: 'Personalization', description: 'Customized content' },
      THIRD_PARTY: { name: 'Third Party', description: 'External services' },
    },
  },
}

export function createElement<K extends keyof HTMLElementTagNameMap>(
  tag: K,
  styles: Partial<CSSStyleDeclaration> = {},
  attributes: Record<string, string> = {}
): HTMLElementTagNameMap[K] {
  const el = document.createElement(tag)
  Object.assign(el.style, styles)
  Object.entries(attributes).forEach(([key, value]) => el.setAttribute(key, value))
  return el
}
