/**
 * Translation system for IntelSight website
 * Supports German (de) and English (en)
 */

// Translation strings
const translations = {
    de: {
        // Page meta
        pageTitle: 'IntelSight - Sicherheit Made in Germany',
        
        // Navigation
        skipNav: 'Zum Hauptinhalt springen',
        navHome: 'Startseite',
        navAbout: 'Über uns',
        navProducts: 'Produkte & Lösungen',
        navContact: 'Kontakt',
        langSwitch: 'DE | EN',
        
        // Hero Section
        heroTitle: 'SICHERHEIT MADE IN GERMANY',
        heroSubtitle: 'Spezialist für hochsichere, maßgeschneiderte IT-Lösungen für Behörden',
        
        // Trust Indicators
        indicatorAvailability: 'Verfügbarkeit',
        indicatorTrust: 'Behörden vertrauen uns',
        indicatorSupport: 'Support',
        
        // Scroll Indicator
        scrollToExplore: 'Nach unten scrollen',
        
        // About Section
        aboutTitle: 'ÜBER UNS',
        aboutSubtitle: 'Ihr Partner für sichere Behördensoftware',
        
        // About Tabs
        tabWhoWeAre: 'Unternehmen',
        tabMission: 'Mission & Werte',
        tabCompetencies: 'Kernkompetenzen',
        tabWhyUs: 'Unser Versprechen',
        
        // Who We Are
        whoWeAreTitle: 'Unternehmen',
        whoWeArePara1: 'IntelSight UG ist Ihr <strong>Spezialist für hochsichere, maßgeschneiderte IT-Lösungen</strong> aus Nordrhein-Westfalen. Wir entwickeln innovative Software speziell für staatliche Sicherheits- und Ermittlungsbehörden.',
        whoWeArePara2: 'Unser Ansatz vereint modernste Technologie mit einem tiefen Verständnis für die besonderen Anforderungen von Behörden. Dabei steht die Balance zwischen Sicherheit, Effizienz und rechtskonformer Umsetzung im Mittelpunkt unserer Arbeit.',
        locationBadge: 'Nordrhein-Westfalen, Deutschland',
        nrwLabel: 'Nordrhein-Westfalen',
        headquartersLabel: 'Unser Standort: Langenfeld',
        
        // Mission & Values
        missionTitle: 'Unsere Mission',
        missionStatement: 'Wir schaffen <strong>effiziente, sichere und datenschutzkonforme Lösungen</strong> für moderne Strafverfolgung und Sicherheitsbehörden.',
        valueIntegrityTitle: 'Integrität',
        valueIntegrityDesc: 'Höchste ethische Standards in allem was wir tun',
        valueTransparencyTitle: 'Transparenz',
        valueTransparencyDesc: 'Offene Kommunikation und nachvollziehbare Prozesse',
        valueDemocracyTitle: 'Demokratische Prinzipien',
        valueDemocracyDesc: 'Kooperation nur mit Behörden im Einklang mit der freiheitlich demokratischen Grundordnung',
        principleNote: '<strong>Unser Ziel:</strong> Technologie, die Recht und Sicherheit stärkt und die freiheitlich demokratische Grundordnung schützt.',
        
        // Competencies
        competenciesTitle: 'Unsere Kernkompetenzen',
        comp1Title: 'Behördenspezifische Software',
        comp1Desc: 'Entwicklung mit höchsten Sicherheitsstandards, maßgeschneidert für staatliche Anforderungen',
        comp2Title: 'Intuitive Bedienkonzepte',
        comp2Desc: 'Benutzerfreundliche Oberflächen trotz komplexer Funktionen für effizientes Arbeiten',
        comp3Title: 'Langzeit-Support',
        comp3Desc: 'Kontinuierliche Sicherheitsupdates und zuverlässige Wartung über den gesamten Lebenszyklus',
        
        // Why Us
        whyUsTitle: 'Warum IntelSight UG?',
        why1Title: 'Enge Zusammenarbeit',
        why1Desc: 'Wir arbeiten Hand in Hand mit unseren Kunden für maßgeschneiderte Lösungen',
        why2Title: 'Made in Germany',
        why2Desc: 'Klare, robuste und sichere Software nach deutschen Qualitätsstandards',
        why3Title: 'Verlässliche Partnerschaft',
        why3Desc: 'Basierend auf gemeinsamen Werten und langfristigem Vertrauen',
        why4Title: 'Nachhaltigkeit',
        why4Desc: 'Fokus auf Sicherheit, Professionalität & zukunftssichere Lösungen',
        
        // Products Section
        productsTitle: 'PRODUKTE & LÖSUNGEN',
        productsSubtitle: 'Professionelle Werkzeuge für moderne Ermittlungsarbeit',
        
        // Professional Toolbox
        productToolboxTitle: 'Professional Toolbox',
        productToolboxDesc: 'Eine leistungsstarke Desktop-Anwendung mit fünf essentiellen Tools für behördliche OSINT-Ermittler und Analysten. Modernes Design, intuitive Bedienung, professionelle Funktionen.',
        expandDetails: 'Details anzeigen',
        hideDetails: 'Details verbergen',
        
        // Tools
        tool1Title: 'Metadata Analyzer',
        tool1Feature1: 'Extrahiert versteckte Informationen (EXIF, GPS, Erstellungsdaten)',
        tool1Feature2: 'Forensische Analyse von Dokumenten & Bildern',
        tool1Feature3: 'Export als JSON',
        
        tool2Title: 'Screen Recorder',
        tool2Feature1: 'Bildschirmaufnahme mit Audio (System & Mikrofon)',
        tool2Feature2: 'Bereichsauswahl oder Vollbild',
        tool2Feature3: 'Wählbare Qualitätsstufen',
        
        tool3Title: 'Video Crawler',
        tool3Feature1: 'Download von Videos aus 1000+ Plattformen',
        tool3Feature2: 'Automatischer Untertitel-Download',
        tool3Feature3: 'Qualitätsauswahl',
        
        tool4Title: 'Website Crawler',
        tool4Feature1: 'Archiviert Webseiten offline',
        tool4Feature2: 'Einstellbare Crawling-Tiefe',
        tool4Feature3: 'Erhält Originalstruktur inkl. CSS, JS & Medien',
        
        tool5Title: 'Multimedia Converter',
        tool5Feature1: 'Konvertierung von Bildern, Videos, Audio',
        tool5Feature2: 'Batch-Verarbeitung',
        tool5Feature3: 'Drag & Drop Unterstützung',
        
        // AccountForger
        productAccountForgerTitle: 'AccountForger',
        accessRestricted: 'Zugang nur mit Berechtigung',
        protectedProductDesc: 'Dieses Produkt ist speziell für autorisierte Behörden entwickelt und erfordert eine Authentifizierung.',
        loginForAccess: 'Anmelden für Zugriff',
        
        // Footer
        footerCompanyTitle: 'IntelSight UG (haftungsbeschränkt)',
        footerCompanyAddress1: 'Gladbacher Strasse 3-5',
        footerCompanyAddress2: '40764 Langenfeld',
        footerNavTitle: 'Navigation',
        footerNavHome: 'Startseite',
        footerNavAbout: 'Über uns',
        footerNavProducts: 'Produkte',
        footerNavContact: 'Kontakt',
        
        footerLegalTitle: 'Rechtliches',
        footerImprint: 'Impressum',
        footerPrivacy: 'Datenschutz',
        footerTerms: 'AGB',
        
        footerContactTitle: 'Kontakt',
        copyright: '© 2025 IntelSight UG (haftungsbeschränkt). Alle Rechte vorbehalten.',
        
        // Modal texts
        authRequired: 'Authentifizierung erforderlich',
        authDescription: 'Dieser Bereich ist nur für autorisierte Behörden zugänglich.',
        accessCode: 'Zugangscode',
        accessCodePlaceholder: 'Bitte Zugangscode eingeben',
        grantAccess: 'Zugang gewähren',
        noAccess: 'Noch keinen Zugang?',
        contactUs: 'Kontaktieren Sie uns',
        accessGranted: 'Zugang gewährt! AccountForger wird geladen...',
        wrongCode: 'Falscher Zugangscode. Bitte versuchen Sie es erneut.',
        demoRequestAlert: 'Demo-Anfrage-Funktion würde hier implementiert werden',
        contactFormSuccess: 'Vielen Dank für Ihre Nachricht! Wir werden uns schnellstmöglich bei Ihnen melden.'
    },
    
    en: {
        // Page meta
        pageTitle: 'IntelSight - Security Made in Germany',
        
        // Navigation
        skipNav: 'Skip to main content',
        navHome: 'Home',
        navAbout: 'About Us',
        navProducts: 'Products & Solutions',
        navContact: 'Contact',
        langSwitch: 'EN | DE',
        
        // Hero Section
        heroTitle: 'SECURITY MADE IN GERMANY',
        heroSubtitle: 'Specialist for highly secure, customized IT solutions for government agencies',
        
        // Trust Indicators
        indicatorAvailability: 'Availability',
        indicatorTrust: 'Government agencies trust us',
        indicatorSupport: 'Support',
        
        // Scroll Indicator
        scrollToExplore: 'Scroll to Explore',
        
        // About Section
        aboutTitle: 'About Us',
        aboutSubtitle: 'Your Partner for Secure Government Software',
        
        // About Tabs
        tabWhoWeAre: 'Company',
        tabMission: 'Mission & Values',
        tabCompetencies: 'Core Competencies',
        tabWhyUs: 'Our Promise',
        
        // Who We Are
        whoWeAreTitle: 'Company',
        whoWeArePara1: 'IntelSight UG is your <strong>specialist for highly secure, customized IT solutions</strong> from North Rhine-Westphalia. We develop innovative software specifically for government security and law enforcement agencies.',
        whoWeArePara2: 'Our approach combines cutting-edge technology with a deep understanding of the special requirements of government agencies. The balance between security, efficiency and legally compliant implementation is at the center of our work.',
        locationBadge: 'North Rhine-Westphalia, Germany',
        nrwLabel: 'North Rhine-Westphalia',
        headquartersLabel: 'Our Location: Langenfeld',
        
        // Mission & Values
        missionTitle: 'Our Mission',
        missionStatement: 'We create <strong>efficient, secure and data protection compliant solutions</strong> for modern law enforcement and security agencies.',
        valueIntegrityTitle: 'Integrity',
        valueIntegrityDesc: 'Highest ethical standards in everything we do',
        valueTransparencyTitle: 'Transparency',
        valueTransparencyDesc: 'Open communication and comprehensible processes',
        valueDemocracyTitle: 'Democratic Principles',
        valueDemocracyDesc: 'Cooperation only with agencies in accordance with the liberal democratic basic order',
        principleNote: '<strong>Our Goal:</strong> Technology that strengthens law and security and protects the liberal democratic basic order.',
        
        // Competencies
        competenciesTitle: 'Our Core Competencies',
        comp1Title: 'Agency-Specific Software',
        comp1Desc: 'Development with highest security standards, tailored for government requirements',
        comp2Title: 'Intuitive Operating Concepts',
        comp2Desc: 'User-friendly interfaces despite complex functions for efficient work',
        comp3Title: 'Long-term Support',
        comp3Desc: 'Continuous security updates and reliable maintenance throughout the entire lifecycle',
        
        // Why Us
        whyUsTitle: 'Why IntelSight UG?',
        why1Title: 'Close Collaboration',
        why1Desc: 'We work hand in hand with our customers for customized solutions',
        why2Title: 'Made in Germany',
        why2Desc: 'Clear, robust and secure software according to German quality standards',
        why3Title: 'Reliable Partnership',
        why3Desc: 'Based on shared values and long-term trust',
        why4Title: 'Sustainability',
        why4Desc: 'Focus on security, professionalism & future-proof solutions',
        
        // Products Section
        productsTitle: 'Products & Solutions',
        productsSubtitle: 'Professional Tools for Modern Investigation Work',
        
        // Professional Toolbox
        productToolboxTitle: 'Professional Toolbox',
        productToolboxDesc: 'A powerful desktop application with five essential tools for government OSINT investigators and analysts. Modern design, intuitive operation, professional functions.',
        expandDetails: 'Show Details',
        hideDetails: 'Hide Details',
        
        // Tools
        tool1Title: 'Metadata Analyzer',
        tool1Feature1: 'Extracts hidden information (EXIF, GPS, creation dates)',
        tool1Feature2: 'Forensic analysis of documents & images',
        tool1Feature3: 'Export as JSON',
        
        tool2Title: 'Screen Recorder',
        tool2Feature1: 'Screen recording with audio (system & microphone)',
        tool2Feature2: 'Area selection or full screen',
        tool2Feature3: 'Selectable quality levels',
        
        tool3Title: 'Video Crawler',
        tool3Feature1: 'Download videos from 1000+ platforms',
        tool3Feature2: 'Automatic subtitle download',
        tool3Feature3: 'Quality selection',
        
        tool4Title: 'Website Crawler',
        tool4Feature1: 'Archives websites offline',
        tool4Feature2: 'Adjustable crawling depth',
        tool4Feature3: 'Preserves original structure incl. CSS, JS & media',
        
        tool5Title: 'Multimedia Converter',
        tool5Feature1: 'Conversion of images, videos, audio',
        tool5Feature2: 'Batch processing',
        tool5Feature3: 'Drag & Drop support',
        
        // AccountForger
        productAccountForgerTitle: 'AccountForger',
        accessRestricted: 'Access by authorization only',
        protectedProductDesc: 'This product is specifically developed for authorized agencies and requires authentication.',
        loginForAccess: 'Login for Access',
        
        // Footer
        footerCompanyTitle: 'IntelSight UG (haftungsbeschränkt)',
        footerCompanyAddress1: 'Gladbacher Strasse 3-5',
        footerCompanyAddress2: '40764 Langenfeld',
        footerNavTitle: 'Navigation',
        footerNavHome: 'Home',
        footerNavAbout: 'About Us',
        footerNavProducts: 'Products',
        footerNavContact: 'Contact',
        
        footerLegalTitle: 'Legal',
        footerImprint: 'Imprint',
        footerPrivacy: 'Privacy Policy',
        footerTerms: 'Terms & Conditions',
        
        footerContactTitle: 'Contact',
        copyright: '© 2025 IntelSight UG (haftungsbeschränkt). All rights reserved.',
        
        // Modal texts
        authRequired: 'Authentication Required',
        authDescription: 'This area is only accessible to authorized agencies.',
        accessCode: 'Access Code',
        accessCodePlaceholder: 'Please enter access code',
        grantAccess: 'Grant Access',
        noAccess: 'No access yet?',
        contactUs: 'Contact Us',
        accessGranted: 'Access granted! AccountForger is loading...',
        wrongCode: 'Wrong access code. Please try again.',
        demoRequestAlert: 'Demo request function would be implemented here',
        contactFormSuccess: 'Thank you for your message! We will get back to you as soon as possible.'
    }
};

// Current language state
let currentLanguage = CONFIG.I18N.DEFAULT_LANGUAGE;

/**
 * Initialize the translation system
 */
function initTranslations() {
    // Try to get saved language from localStorage
    const savedLanguage = localStorage.getItem(CONFIG.I18N.STORAGE_KEY);
    if (savedLanguage && CONFIG.I18N.SUPPORTED_LANGUAGES.includes(savedLanguage)) {
        currentLanguage = savedLanguage;
    }
    
    // Apply initial translations
    applyTranslations(currentLanguage);
}

/**
 * Switch to a different language
 * @param {string} language - Language code ('de' or 'en')
 */
function switchLanguage(language) {
    if (!CONFIG.I18N.SUPPORTED_LANGUAGES.includes(language)) {
        console.error(`Language '${language}' is not supported`);
        return;
    }
    
    currentLanguage = language;
    localStorage.setItem(CONFIG.I18N.STORAGE_KEY, language);
    applyTranslations(language);
}

/**
 * Apply translations to all elements with data-translate attribute
 * @param {string} language - Language code to apply
 */
function applyTranslations(language) {
    const t = translations[language];
    
    if (!t) {
        console.error(`Translations for language '${language}' not found`);
        return;
    }
    
    // Update page title
    document.title = t.pageTitle;
    
    // Update HTML lang attribute
    document.documentElement.lang = language;
    
    // Update all translatable elements
    document.querySelectorAll(SELECTORS.TRANSLATABLE).forEach(element => {
        const key = element.getAttribute(DATA_ATTRS.TRANSLATE);
        
        if (t[key]) {
            // Check if content contains HTML tags
            if (t[key].includes('<strong>') || t[key].includes('<em>')) {
                element.innerHTML = t[key];
            } else {
                element.textContent = t[key];
            }
        }
    });
    
    // Update language toggle button
    const langToggle = document.querySelector(SELECTORS.LANG_TOGGLE);
    if (langToggle) {
        langToggle.textContent = t.langSwitch;
        langToggle.setAttribute(DATA_ATTRS.LANG, language);
    }
    
    // Update expand button text if it exists
    updateExpandButtonText(language);
}

/**
 * Update expand button text based on current state
 * @param {string} language - Current language
 */
function updateExpandButtonText(language) {
    const expandButton = document.querySelector(SELECTORS.EXPAND_BUTTON);
    if (expandButton) {
        const expandText = expandButton.querySelector('.expand-text');
        const isExpanded = expandButton.getAttribute(DATA_ATTRS.EXPANDED) === 'true';
        const t = translations[language];
        
        if (expandText && t) {
            expandText.textContent = isExpanded ? t.hideDetails : t.expandDetails;
        }
    }
}

/**
 * Get a specific translation string
 * @param {string} key - Translation key
 * @returns {string} Translated text
 */
function getTranslation(key) {
    return translations[currentLanguage][key] || key;
}

/**
 * Get current language
 * @returns {string} Current language code
 */
function getCurrentLanguage() {
    return currentLanguage;
}