import { ref } from 'vue'
import { defineStore } from 'pinia'

export const useSettingsStore = defineStore('settingsStore', () => {
    /**
     * Stores the loading status for the settings form.
     * Used to persist loading status when switching between tabs.
     */
    const isLoading = ref<boolean>(false);
    /**
     * Stores the show popup status for the settings form.
     * Used to persist show popup status when switching between tabs.
     */
    const showPopup = ref<boolean>(false);
    /**
     * Stores the popup title for the settings form.
     * Used to persist popup title when switching between tabs.
     */
    const popupTitle = ref<string>('');
    /**
     * Stores the selected condition key for the settings form.
     * Used to persist selected condition key when switching between tabs.
     */
    const selectedConditionKey = ref<string>('');
    /**
     * Stores the selected condition value for the settings form.
     * Used to persist selected condition value when switching between tabs.
     */
    const selectedConditionValue = ref<string>('');
    /**
     * Stores the component upgrade status for the settings form.
     * Used to persist component upgrade status when switching between tabs.
     */
    const componentUpgrade = ref<string>('upgrade_suffix');
    /**
     * Stores the external links for the settings form.
     * Used to persist external links when switching between tabs.
     */
    const externalLinks = ref<any>([]);
    /**
     * Stores the edited row key for the settings form.
     * Used to persist edited row key when switching between tabs.
     */
    const editedRowKey = ref<any>(null);
    /**
     * Stores the open drawer status for the settings form.
     * Used to persist open drawer status when switching between tabs.
     */
    const openDrawer = ref<boolean>(false);
    /**
     * Stores the inline mapping edit status for the settings form.
     * Used to persist inline mapping edit status when switching between tabs.
     */
    const inlineMappingEdit = ref<boolean>(true);
    /**
     * Stores the dynamic options for the settings form.
     * Used to persist dynamic options when switching between tabs.
     */
    const dynamicOptions = ref<any>([]);
    /**
     * Stores the group data for the settings form.
     * Used to persist group data when switching between tabs.
     */
    const groupData = ref<any>([]);
    /**
     * Stores the current input values from settings form fields.
     * Used to persist field values when switching between tabs.
     */
    const inputValues = ref<any>({});

    return {
        isLoading,
        showPopup,
        popupTitle,
        selectedConditionKey,
        selectedConditionValue,
        componentUpgrade,
        externalLinks,
        editedRowKey,
        openDrawer,
        inlineMappingEdit,
        dynamicOptions,
        groupData,
        inputValues,
    }
});
