import { alarmLevelStatusEnum } from '@/enums/status';
import { localStorageKeyEnums } from '@/enums/storage';

/*
 * @Author: zhoux zhouxia@supervision.ltd
 * @Date: 2023-12-22 16:39:33
 * @LastEditors: zhoux zhouxia@supervision.ltd
 * @LastEditTime: 2023-12-22 16:49:36
 * @FilePath: \general-ai-platform-web\src\hooks\useAlarmSettingLevel.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
type selectAlarmLevel = {
  label: string;
  value: string;
};

interface useAlarmSettingLevelProps {
  fetchAlarmSettingLevel: () => selectAlarmLevel[];
}

export const useAlarmSettingLevel = (): useAlarmSettingLevelProps => {
  function fetchAlarmSettingLevel() {
    const finalArr: selectAlarmLevel[] = [];
    const currData = localStorage.getItem(
      localStorageKeyEnums.alarmSetting_model_alarmStatusSetting,
    );
    if (currData) {
      const currFormData = JSON.parse(currData) as Record<string, any>;
      // eslint-disable-next-line guard-for-in
      for (let key in currFormData) {
        finalArr.push({
          label: currFormData[key],
          value: key,
        });
      }
    } else {
      // eslint-disable-next-line array-callback-return
      alarmLevelStatusEnum.map((item) => {
        if (['1', '2', '3'].includes(item.value)) {
          finalArr.push({
            label: item.label,
            value: item.value,
          });
        }
      });
    }
    return finalArr;
  }
  return {
    fetchAlarmSettingLevel,
  };
};
