'use client';
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";

interface LanguageSelectionComponentProps {
    activePage: string;
    onlineData: any;
    onlineLoading: boolean;
    onlineError: any;
    refreshOnline: () => Promise<void>;
    updateOnline: (newOnline: any) => Promise<boolean>;
}

const LanguageSelectionComponent: React.FC<LanguageSelectionComponentProps> = ({ activePage, onlineData, onlineLoading, onlineError, refreshOnline, updateOnline }) => {
    const lang = onlineData?.lang as LanguageTypes || 'en';
    const translations = langGet(lang, languageSelectionTranslation);
    const languageButtons = [
        { activeLang: lang, buttonsLang: "en", refUrl: "en", innerText: langGetKey(translations, "english") },
        { activeLang: lang, buttonsLang: "tr", refUrl: "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>
                <DropdownMenuContent>
                    {languageButtons.map((props, index) => (
                        <LanguageSelectionItem key={props.buttonsLang} {...props}
                            onlineData={onlineData} onlineLoading={onlineLoading} onlineError={onlineError} refreshOnline={refreshOnline} updateOnline={updateOnline} />
                    ))}
                </DropdownMenuContent>
            </DropdownMenu>
        </div>
    );
};

export default LanguageSelectionComponent;
