<commit_before><script>
let next_tab = null;
let first_load = true;

export default {
    data: () => ({
        w: window,

        tabs: {
            home: 'Home',
            explore: 'Explore',
            develop: 'Development'
        },

        search_text: '',
        tab: 'explore',
        page: 'modlist',
        show_filter: false,
        mods: [],
        mod_table: {},

        // details page
        detail_mod: null,

        popup_visible: false,
        popup_title: 'Popup',
        popup_mode: '',
        popup_content: null,

        popup_progress_message: null,
        popup_progress: {},

        popup_mod_name: '',
        popup_mod_id: '',
        popup_mod_version: '1.0.0',
        popup_mod_type: 'mod',
        popup_mod_parent: 'FS2',
        popup_mod_tcs: [],

        popup_mod_new_version: '',
        popup_mod_method: 'copy',

        popup_mod_message: '',

        popup_mod_exes: [],
        popup_mod_flag: [],
        popup_mod_sel_exe: null,
        popup_mod_flag_map: {},

        popup_pkg_name: '',
        popup_pkg_folder: '',

        popup_ini_path: '',

        popup_sure_question: '',
        sureCallback: null,

        // retail prompt
        retail_searching: true,
        retail_found: false,
        retail_data_path: ''
    }),

    watch: {
        search_text(phrase) {
            fs2mod.triggerSearch(phrase);
        }
    },

    methods: {
        openLink(url) {
            fs2mod.openExternal(url);
        },

        openScreenshotFolder() {
            fs2mod.openScreenshotFolder();
        },

        showHelp() {
            alert('Not yet implemented! Sorry.');
        },

        updateList() {
            fs2mod.fetchModlist();
        },

        showSettings() {
            this.tab = null;
            this.page = 'settings';
        },

        showTab(tab) {
            next_tab = tab;

            if(window.qt) {
                fs2mod.showTab(tab);
            } else {
                setTimeout(() => { fs2mod.showTab(tab); }, 100);
            }
        },

        updateModlist(mods) {
            this.mods = mods;

            if(next_tab) {
                this.tab = next_tab;
                this.page = next_tab === 'develop' ? 'develop' : 'modlist';
                next_tab = null;
            } else if(first_load) {
                first_load = false;

                if(this.page !== 'welcome') {
                    next_tab = mods.length === 0 ? 'explore' : 'home';
                    fs2mod.showTab(next_tab);
                }
            }
        },

        exitDetails() {
            this.page = 'modlist';
        },

        createMod() {
            if(this.popup_mod_id === '') {
                alert('You need to enter a mod ID!');
                return;
            }


            if(this.popup_mod_name === '') {
                alert('You need to enter a mod name!');
                return;
            }

            call(fs2mod.createMod, this.popup_ini_path, this.popup_mod_name, this.popup_mod_id, this.popup_mod_version,
                this.popup_mod_type, this.popup_mod_parent,
                (result) => {
                    if(result) {
                        this.popup_visible = false;
                    }
                }
            );
        },

        addPackage() {
            if(this.popup_pkg_name === '') {<commit_msg>Fix #110: Exit the details tab if the mod is gone<commit_after><script>
let next_tab = null;
let first_load = true;

export default {
    data: () => ({
        w: window,

        tabs: {
            home: 'Home',
            explore: 'Explore',
            develop: 'Development'
        },

        search_text: '',
        tab: 'explore',
        page: 'modlist',
        show_filter: false,
        mods: [],
        mod_table: {},

        // details page
        detail_mod: null,

        popup_visible: false,
        popup_title: 'Popup',
        popup_mode: '',
        popup_content: null,

        popup_progress_message: null,
        popup_progress: {},

        popup_mod_name: '',
        popup_mod_id: '',
        popup_mod_version: '1.0.0',
        popup_mod_type: 'mod',
        popup_mod_parent: 'FS2',
        popup_mod_tcs: [],

        popup_mod_new_version: '',
        popup_mod_method: 'copy',

        popup_mod_message: '',

        popup_mod_exes: [],
        popup_mod_flag: [],
        popup_mod_sel_exe: null,
        popup_mod_flag_map: {},

        popup_pkg_name: '',
        popup_pkg_folder: '',

        popup_ini_path: '',

        popup_sure_question: '',
        sureCallback: null,

        // retail prompt
        retail_searching: true,
        retail_found: false,
        retail_data_path: ''
    }),

    watch: {
        search_text(phrase) {
            fs2mod.triggerSearch(phrase);
        }
    },

    methods: {
        openLink(url) {
            fs2mod.openExternal(url);
        },

        openScreenshotFolder() {
            fs2mod.openScreenshotFolder();
        },

        showHelp() {
            alert('Not yet implemented! Sorry.');
        },

        updateList() {
            fs2mod.fetchModlist();
        },

        showSettings() {
            this.tab = null;
            this.page = 'settings';
        },

        showTab(tab) {
            next_tab = tab;

            if(window.qt) {
                fs2mod.showTab(tab);
            } else {
                setTimeout(() => { fs2mod.showTab(tab); }, 100);
            }
        },

        updateModlist(mods) {
            this.mods = mods;

            if(next_tab) {
                this.tab = next_tab;
                this.page = next_tab === 'develop' ? 'develop' : 'modlist';
                next_tab = null;
            } else if(first_load) {
                first_load = false;

                if(this.page !== 'welcome') {
                    next_tab = mods.length === 0 ? 'explore' : 'home';
                    fs2mod.showTab(next_tab);
                }
            } else if(this.page === 'details' && !mod_table[this.detail_mod]) {
                // The currently visible mod has been uninstalled thus making displaying this page impossible.
                // Switch to the tab instead
                this.exitDetails();
            }
        },

        exitDetails() {
            this.page = 'modlist';
        },

        createMod() {
            if(this.popup_mod_id === '') {
                alert('You need to enter a mod ID!');
                return;
            }


            if(this.popup_mod_name === '') {
                alert('You need to enter a mod name!');
                return;
            }

            call(fs2mod.createMod, this.popup_ini_path, this.popup_mod_name, this.popup_mod_id, this.popup_mod_version,
                this.popup_mod_type, this.popup_mod_parent,
                (result) => {
                    if(result) {
                        this.popup_visible = false;
                    }
                }
            );
        },

        addPackage() {
            if(this.popup_pkg_name === '') {
{'fraction_non_alphanumeric': 0.12002820874471086, 'fraction_numerical': 0.004936530324400564, 'mean_word_length': 1.3067664281067013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4899718', 'n_tokens_mistral': 2172, 'n_tokens_neox': 2007, 'n_words': 357}