'use client'
// Removed Next.js Link import for Electron
import {FontAwesomeIcon} from "@fortawesome/react-fontawesome";
import {
    faBook,
    faDownload,
    faGlobe,
    faHatWizard,
    faListAlt,
    faMapMarkedAlt,
    faPencilAlt,
    faUser,
    faWandMagicSparkles
} from "@fortawesome/free-solid-svg-icons";
import {Dispatch, SetStateAction, useContext} from "react";
import {IconDefinition} from "@fortawesome/fontawesome-svg-core";
import {useTranslations} from "next-intl";
import OfflineContext, {OfflineContextType} from "@/context/OfflineContext";

interface BookSettingOption {
    id: string;
    name: string;
    icon: IconDefinition;
}

export default function BookSettingSidebar(
    {
        selectedSetting,
        setSelectedSetting
    }: {
        selectedSetting: string,
        setSelectedSetting: Dispatch<SetStateAction<string>>
    }) {
    const t = useTranslations();
    const {isCurrentlyOffline} = useContext<OfflineContextType>(OfflineContext);

    const settings: BookSettingOption[] = [
        {
            id: 'basic-information',
            name: 'bookSetting.basicInformation',
            icon: faPencilAlt
        },
        {
            id: 'guide-line',
            name: 'bookSetting.guideLine',
            icon: faListAlt
        },
        {
            id: 'story',
            name: 'bookSetting.story',
            icon: faBook
        },
        {
            id: 'world',
            name: 'bookSetting.world',
            icon: faGlobe
        },
        {
            id: 'locations',
            name: 'bookSetting.locations',
            icon: faMapMarkedAlt
        },
        {
            id: 'characters',
            name: 'bookSetting.characters',
            icon: faUser
        },
        {
            id: 'spells',
            name: 'bookSetting.spells',
            icon: faHatWizard
        },
        {
            id: 'quillsense',
            name: 'bookSetting.quillsense',
            icon: faWandMagicSparkles
        },
        {
            id: 'export',
            name: 'bookSetting.export',
            icon: faDownload
        },
        // {
        //     id: 'objects',
        //     name: t('bookSetting.objects'),
        //     icon: faLocationArrow
        // },
        // {
        //     id: 'goals',
        //     name: t('bookSetting.goals'),
        //     icon: faCogs
        // },
    ]

    // Filter out QuillSense when offline (requires server connection)
    const availableSettings: BookSettingOption[] = isCurrentlyOffline()
        ? settings.filter((s: BookSettingOption) => s.id !== 'quillsense')
        : settings;

    return (
        <div className="py-6 px-3">
            <nav className="space-y-1">
                {
                    availableSettings.map((setting: BookSettingOption) => (
                        <button
                            key={setting.id}
                            onClick={(): void => setSelectedSetting(setting.id)}
                            type="button"
                            className={`flex items-center text-base rounded-xl transition-all duration-200 w-full ${
                                selectedSetting === setting.id
                                    ? 'bg-primary/20 text-text-primary border-l-4 border-primary font-semibold shadow-md scale-105'
                                    : 'text-text-secondary hover:bg-secondary/50 hover:text-text-primary hover:scale-102'
                            } p-3 mb-1`}>
                            <FontAwesomeIcon icon={setting.icon}
                                             className={`mr-3 ${selectedSetting === setting.id ? 'text-primary w-5 h-5' : 'text-text-secondary w-5 h-5'}`}/>
                            {t(setting.name)}
                        </button>
                    ))
                }
            </nav>
        </div>
    )
}
