import { defineStore } from 'pinia';
import { AppState } from './types';

const useAppStore = defineStore('app', {
  state: (): AppState => ({
    version: '1.0.1',
    domain: '',
    device: 'desktop',
    trackConfig: {
      pictureType: ['track'],
      outputDir: '',
      curOutputDir: '',
      outputDirIsDefault: true,
      trackColorType: 'DEFAULT',
      studentFileRule: 'CODE',
    },
    downloadTaskRunning: false,
    // auto download task
    actionSession: '',
    downloadSet: null,
  }),

  getters: {
    appInfo(state: AppState): AppState {
      return { ...state };
    },
  },

  actions: {
    resetInfo() {
      this.$reset();
    },
    setInfo(partial: Partial<AppState>) {
      this.$patch(partial);
    },
    toggleDevice(device: string) {
      this.device = device;
    },
  },
  persist: {
    storage: sessionStorage,
  },
});

export default useAppStore;
