import { defineStore } from 'pinia';
import { store } from '/@/store';
import { getStDetailInfo } from '/@/api/swHome/index';

interface basicState {
  stDetailInfo: Array;
  stDetailArrStore: Array;
}
export const useBasicStore = defineStore({
  id: 'basic',
  state: (): basicState => ({
    stDetailInfo: [],
    stDetailArrStore: [],
  }),
  getters: {
    getStDetailInfo(): Array {
      return this.stDetailInfo;
    },
    getStDetailArrStore(): Array {
      return this.stDetailArrStore;
    },
  },
  actions: {
    getStDetailInfoAxios(): void {
      getStDetailInfo().then((res) => {
        this.stDetailInfo = res.data;
        const Obj = JSON.parse(JSON.stringify(res.data));
        this.stDetailArrStore = [];
        let objArr = [];
        for (const i in Obj) {
          objArr = [...objArr, ...Obj[i]];
        }
        objArr.forEach((element) => {
          this.stDetailArrStore.push(element);
        });
        return true;
      });
    },
  },
});
// Need to be used outside the setup
export function useBasicData() {
  return useBasicStore(store);
}
