import { reactive } from "vue";
import EventEmitter from "eventemitter3";
const UPLOADKEY = "task-upload-music";

export const eventGlobal = new EventEmitter();
// type UploadType = {
//   id: string;
//   musicSheetCreationId: string;
//   fileName: string;
//   fileUrl: string;
//   status: string;
// };
// 等待中 WAITING 转换中：CONVERSION，转换成功：SUCCESS，转换失败：FAIL
export const uploadState = reactive({
  uploadList: [] as any[],
});

/** 保存缓存 */
export const saveUploadCatch = (list?: any[]) => {
  // const tempList: any = uploadState.uploadList
  // if(list && list.length > 0) {
  //   tempList.forEach((item: any) => {
  //     const findItem = list.find((l: any) => l.id === item.id)

  //   })
  // }
  sessionStorage.setItem(UPLOADKEY, JSON.stringify(list || uploadState.uploadList));
};

/** 获取缓存 */
export const getUploadCatch = () => {
  const taskUploadMusicJson = sessionStorage.getItem(UPLOADKEY);
  if (taskUploadMusicJson) {
    const taskUploadMusic = JSON.parse(taskUploadMusicJson);
    return taskUploadMusic;
  } else {
    return [];
  }
};

/** 删除缓存 */
export const deleteUploadCatch = () => {
  sessionStorage.removeItem(UPLOADKEY);
};
