'use server';
import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent } from "@/components/mutual/shadcnui/dropdown-menu";
import { Button } from "@/components/mutual/shadcnui/button";
import { languageSelectionTranslation } from "@/languages/mutual/languageSelection";
import { langGetKey, langGet } from "@/lib/langGet";
import { LanguageTypes } from "@/validations/mutual/language/validations";

import LanguageSelectionItem from "./languageItem";

const LanguageSelectionComponent: React.FC<{ lang: LanguageTypes, activePage: string }> = ({ lang, activePage }) => {
    const translations = langGet(lang, languageSelectionTranslation);
    const getPageWithLocale = (locale: LanguageTypes): string => { return `/${locale}/${activePage}` }

    const englishButtonProps = {
        activeLang: lang,
        buttonsLang: "en",
        refUrl: getPageWithLocale("en"),
        innerText: langGetKey(translations, "english")
    }
    const turkishButtonProps = {
        activeLang: lang,
        buttonsLang: "tr",
        refUrl: getPageWithLocale("tr"),
        innerText: langGetKey(translations, "turkish")
    }

    return (
        <div className="flex items-end justify-end">
            <DropdownMenu>
                <DropdownMenuTrigger asChild>
                    <Button className="w-48 h-12 text-center text-md">{langGetKey(translations, "title")}</Button>
                </DropdownMenuTrigger>
                <LanguageSelectionItem {...englishButtonProps} />
                <LanguageSelectionItem {...turkishButtonProps} />
            </DropdownMenu>
        </div>
    );
};

export default LanguageSelectionComponent;
