import { defineStore } from 'pinia';
import { flowDeploymentListApi } from '@/api/sop';

const useAppStore = defineStore('app', {
  state: () => ({
    // old
    menuCollapse: false,
    menuWidth: 220,
    collapseWidth: 64,
    language: 'zh_CN',
    flowParams: null,
    // new
    showSubmenu: true,
    isFullscreen: false,
  }),
  getters: {
    appCurrentSetting(state) {
      return { ...state };
    },
  },
  actions: {
    updateSettings(partial) {
      this.$patch(partial);
    },
    toggleMenu() {
      this.menuCollapse = !this.menuCollapse;
    },
    changeLanguage(language) {
      this.language = language;
    },
    async getFlowParams() {
      let res = await flowDeploymentListApi();
      this.flowParams = res;
    },
    getFlowDetailByType(type) {
      return this.flowParams
        ? this.flowParams.find((item) => item.type == type)
        : null;
    },
    // new
    toggleSubMenu() {
      this.showSubmenu = !this.showSubmenu;
    },
    setIsFullScreen(isFullscreen) {
      this.isFullscreen = isFullscreen;
    },
  },
});

export default useAppStore;
