<script setup lang="ts">
import { computed, onMounted, ref } from 'vue';
import Button from 'primevue/button';
import Tab from 'primevue/tab';
import TabList from 'primevue/tablist';
import TabPanel from 'primevue/tabpanel';
import TabPanels from 'primevue/tabpanels';
import Tabs from 'primevue/tabs';
import { onOpenUrl } from '@tauri-apps/plugin-deep-link';
import ModList from './ModList.vue';
import ModStore from './ModStore.vue';
import Options from './Options.vue';
import ProfileList from './ProfileList.vue';
import StartButton from './StartButton.vue';
import { usePkgStore, usePrfStore } from '../stores';

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

pkg.setupListeners();
prf.setupListeners();

const currentTab = ref('3');

const isProfileDisabled = computed(() => prf.current === null);

onMounted(async () => {
    await prf.reloadList();
    await prf.reload();

    if (prf.current !== null) {
        await pkg.reloadAll();
        currentTab.value = '0';
    }
});
</script>

<template>
    <main>
        <Tabs lazy :value="currentTab" class="h-screen">
            <div class="fixed w-full flex z-100">
                <TabList class="grow">
                    <Tab :disabled="isProfileDisabled" value="0"
                        ><div class="pi pi-list-check"></div
                    ></Tab>
                    <Tab :disabled="isProfileDisabled" value="1"
                        ><div class="pi pi-download"></div
                    ></Tab>
                    <Tab :disabled="isProfileDisabled" value="2"
                        ><div class="pi pi-cog"></div
                    ></Tab>
                    <Tab value="3"
                        ><div class="pi pi-question-circle"></div
                    ></Tab>
                    <div class="grow"></div>
                    <StartButton />
                </TabList>
            </div>
            <TabPanels class="w-full grow mt-[3rem]">
                <TabPanel value="0">
                    <ModList />
                </TabPanel>
                <TabPanel value="1">
                    <ModStore />
                </TabPanel>
                <TabPanel value="2">
                    <Options />
                </TabPanel>
                <TabPanel value="3">
                    <strong>UNDER CONSTRUCTION</strong><br />Many features are
                    missing.<br />Existing features are expected to break any
                    time.
                    <div v-if="isProfileDisabled">
                        <br />Select <code>mu3.exe</code> to create a profile:
                    </div>
                    <ProfileList />
                    <div v-if="isProfileDisabled">
                        <div
                            style="
                                margin-top: 5px;
                                font-weight: bolder;
                                font-size: 3em;
                                color: red;
                                line-height: 1.1em;
                            "
                        >
                            segatools 2024-12-23 or later has to be installed
                        </div>
                        (this will change in the future)
                    </div>
                    <img
                        v-if="prf.current?.game === 'ongeki'"
                        src="/sticker-ongeki.svg"
                        class="fixed bottom-0 right-0"
                    />
                    <img
                        v-else-if="prf.current?.game === 'chunithm'"
                        src="/sticker-chunithm.svg"
                        class="fixed bottom-0 right-0"
                    />
                    <br /><br /><br />
                    <Button
                        style="position: fixed; left: 10px; bottom: 10px"
                        icon="pi pi-discord"
                        as="a"
                        target="_blank"
                        href="https://discord.gg/jxvzHjjEmc"
                    />
                </TabPanel>
            </TabPanels>
        </Tabs>
    </main>
</template>

<style lang="css">
@import 'tailwindcss';

.p-tablist-tab-list {
    height: 3rem;
}

html,
body {
    margin: 0;
    padding: 0;
}
</style>
