/*
 * @Author: nxy
 * @Date: 2024-08-07 13:48:32
 */
import { defineStore } from 'pinia';
import { setSessionStorage, getSessionStorage } from '@/views/echart-design/utils/storage';
import { packagesList } from '@/views/echart-design/components/echart/index';

// 组件 packages
export const usePackagesStore = defineStore({
  id: 'usePackagesStore',
  state: () => ({
    packagesList: Object.freeze(packagesList),
    newPhoto: undefined
  }),
  getters: {
    getPackagesList() {
      return this.packagesList;
    }
  },
  actions: {
    addPhotos(newPhoto, index) {
      this.newPhoto = newPhoto;
      this.packagesList.Photos.splice(index, 0, newPhoto);
    },
    deletePhotos(photoInfo, index) {
      this.packagesList.Photos.splice(index, 1);
      const StoreKey = 'USER_MEDIA_PHOTOS';
      const userPhotosList = getSessionStorage(StoreKey);
      userPhotosList.splice(index - 1, 1);
      setSessionStorage(StoreKey, userPhotosList);
    }
  }
});
