<script setup lang="ts">
import { computed } from 'vue';
import Select from 'primevue/select';
import FilePicker from '../FilePicker.vue';
import OptionCategory from '../OptionCategory.vue';
import OptionRow from '../OptionRow.vue';
import { usePkgStore, usePrfStore } from '../../stores';
import { Feature } from '../../types';
import { pkgKey } from '../../util';

const prf = usePrfStore();
const pkgs = usePkgStore();

const names = computed(() => {
    switch (prf.current?.meta.game) {
        case 'ongeki': {
            return {
                exe: 'mu3.exe',
                hook: 'mu3hook',
                io: 'mu3io',
            };
        }
        case 'chunithm': {
            return {
                exe: 'chusanApp.exe',
                hook: 'chusanhook',
                io: 'chuniio',
            };
        }
        case undefined:
            throw new Error('Option tab without a profile');
    }
});
</script>

<template>
    <OptionCategory title="General">
        <OptionRow
            :title="names.exe"
            tooltip="STARTLINER expects unpacked executables put into otherwise clean data."
        >
            <FilePicker
                :directory="false"
                :promptname="names.exe"
                extension="exe"
                :value="prf.current!.data.sgt.target"
                :callback="
                    (value: string) => (prf.current!.data.sgt.target = value)
                "
            ></FilePicker>
        </OptionRow>

        <OptionRow title="amfs">
            <FilePicker
                :directory="true"
                placeholder="amfs"
                :value="prf.current!.data.sgt.amfs"
                :callback="
                    (value: string) => (prf.current!.data.sgt.amfs = value)
                "
            ></FilePicker>
        </OptionRow>
        <OptionRow title="option">
            <FilePicker
                :directory="true"
                placeholder="option"
                :value="prf.current!.data.sgt.option"
                :callback="
                    (value: string) => (prf.current!.data.sgt.option = value)
                "
            ></FilePicker>
        </OptionRow>
        <OptionRow title="appdata">
            <FilePicker
                :directory="true"
                :value="prf.current!.data.sgt.appdata"
                :callback="
                    (value: string) => (prf.current!.data.sgt.appdata = value)
                "
            ></FilePicker>
        </OptionRow>
        <OptionRow
            :title="names.hook"
            tooltip="Hooks can be downloaded from the package store."
        >
            <Select
                v-model="prf.current!.data.sgt.hook"
                :options="
                    pkgs
                        .byFeature(
                            prf.current?.meta.game === 'ongeki'
                                ? Feature.Mu3Hook
                                : Feature.ChusanHook
                        )
                        .map((p) => {
                            return { title: pkgKey(p), value: pkgKey(p) };
                        })
                "
                option-label="title"
                option-value="value"
            ></Select>
        </OptionRow>
        <OptionRow
            :title="names.io"
            v-if="prf.current?.meta.game === 'ongeki'"
            tooltip="IO plugins can be downloaded from the package store."
        >
            <Select
                v-model="prf.current!.data.sgt.io"
                placeholder="segatools built-in"
                :options="[
                    { title: 'segatools built-in', value: null },
                    ...pkgs.byFeature(Feature.Mu3IO).map((p) => {
                        return { title: pkgKey(p), value: pkgKey(p) };
                    }),
                ]"
                option-label="title"
                option-value="value"
            ></Select>
        </OptionRow>
    </OptionCategory>
</template>
