<script setup lang="ts">
import { ref } from 'vue';
import ToggleSwitch from 'primevue/toggleswitch';
import FileEditor from '../FileEditor.vue';
import OptionCategory from '../OptionCategory.vue';
import OptionRow from '../OptionRow.vue';
import { invoke } from '../../invoke';
import { usePrfStore } from '../../stores';
import { useI18n } from 'vue-i18n';

const { t } = useI18n();

const extension = ref('');

invoke('list_platform_capabilities').then(async (v: unknown) => {
    if (Array.isArray(v)) {
        if (v.includes('preload-sh')) {
            extension.value = 'sh';
        } else if (v.includes('preload-bat')) {
            extension.value = 'bat';
        }
    }
});

const prf = usePrfStore();
</script>

<template>
    <OptionCategory :title="t('cfg.misc.title')">
        <OptionRow
            :title="t('cfg.misc.intel')"
            :dangerous-tooltip="t('cfg.misc.intelTooltip')"
        >
            <ToggleSwitch v-model="prf.current!.data.sgt.intel" />
        </OptionRow>
        <OptionRow
            :title="t('cfg.misc.other')"
            :tooltip="t('cfg.misc.otherTooltip')"
        >
            <!-- <Button icon="pi pi-refresh" size="small" /> -->
            <FileEditor filename="segatools-base.ini" />
        </OptionRow>
        <OptionRow
            :title="t('cfg.misc.prescript')"
            :tooltip="t('cfg.misc.prescriptTooltip')"
        >
            <FileEditor
                v-if="extension === 'bat'"
                filename="pre.bat"
                :defaultValue="`@echo off\n\nREM This script will launch before (and alongside) the game\n`"
            />
            <FileEditor
                v-else-if="extension === 'sh'"
                filename="pre.sh"
                :defaultValue="`#!/bin/sh\n\n# This script will launch before (and alongside) the game\n`"
            />
        </OptionRow>
        <OptionRow
            :title="t('cfg.misc.postscript')"
            :tooltip="t('cfg.misc.postscriptTooltip')"
        >
            <FileEditor
                v-if="extension === 'bat'"
                filename="post.bat"
                :defaultValue="`@echo off\n\nREM This script will launch after the game has died\n`"
            />
            <FileEditor
                v-else-if="extension === 'sh'"
                filename="post.sh"
                :defaultValue="`#!/bin/sh\n\n# This script will launch after the game has died\n`"
            />
        </OptionRow>
    </OptionCategory>
</template>
