// cqi 状态样式
export const getCqiStatusStyle = (data: string | number) => {
  const value = Number(data);
  let style = {
    color: '#F24F4F',
    background: 'rgba(242, 79, 79, 0.2)',
  };
  if (value > 95) {
    style = {
      color: '#57EF58',
      background: 'rgba(39, 211, 134, 0.2)',
    };
  } else if (85 < value && value < 95) {
    style = {
      color: '#447FF0',
      background: 'rgba(130, 173, 255, 0.2)',
    };
  } else if (60 < value && value < 85) {
    style = {
      color: '#FFA81A',
      background: 'rgba(255, 188, 130, 0.2)',
    };
  }
  return style;
};

/**
 * 指数状态颜色
 */
export const getColorByIndex = (val: number) => {
  if (val > 95) {
    return 'rgb(87, 239, 88)';
  }
  if (val < 95 && val > 85) {
    return '#0680f4';
  }
  if (val < 85) {
    return '#ffa250';
  }
};

// cqi 状态文本
export const getCqiStatusTexts = (data: string | number) => {
  const value = Number(data);

  let obj = {
    text: '应急态',
    desc: '发生重大应急事件',
  };
  if (value > 95) {
    obj = {
      text: '理想态',
      desc: '运行良好',
    };
  } else if (85 < value && value < 95) {
    obj = {
      text: '标准态',
      desc: '运行基本正常',
    };
  } else if (60 < value && value < 85) {
    obj = {
      text: '预警态',
      desc: '运行随时会出现问题',
    };
  }
  return obj;
};

// cqi lineCharts

export const getCqiLineChartStyles = (data: string | number) => {
  const value = Number(data);
  let style = {
    lineColor: '#F24F4F',
    areaColorOffset: 'rgba(242, 79, 79, 0)',
    areaColorOffset1: 'rgba(242, 79, 79, 0.36)',
  };
  if (value > 95) {
    style = {
      lineColor: '#57EF58',
      areaColorOffset: 'rgba(87, 239, 88, 0)',
      areaColorOffset1: 'rgba(87, 239, 88, 0.36)',
    };
  } else if (85 < value && value < 95) {
    style = {
      lineColor: '#447FF0',
      areaColorOffset: 'rgba(130, 173, 255, 0)',
      areaColorOffset1: 'rgba(130, 173, 255, 0.36)',
    };
  } else if (60 < value && value < 85) {
    style = {
      lineColor: '#FFA81A',
      areaColorOffset: 'rgba(255, 188, 130, 0)',
      areaColorOffset1: 'rgba(255, 188, 130, 0.36)',
    };
  }
  return style;
};

const document: any = window.document;
// 展开/全屏
export function requestFullScreen(element: any) {
  let requestMethod =
    element.requestFullscreen ||
    element.webkitRequestFullscreen ||
    element.msRequestFullscreen ||
    element.mozRequestFullScreen;
  if (requestMethod) {
    requestMethod.call(element);
  }
}
// 退出/全屏
export function exitFullScreen() {
  let exitMethod =
    document.exitFullscreen ||
    document.webkitExitFullscreen ||
    document.msExitFullscreen ||
    document.mozCancelFullScreen;
  if (exitMethod) {
    exitMethod.call(document);
  }
}
// 判断是否全屏
export function isFullscreenElement() {
  let isFull =
    document.fullscreenElement ||
    document.webkitFullscreenElement ||
    document.msFullscreenElement ||
    document.mozFullScreenElement;
  return !!isFull;
}
export const getWarnTotal = (data: any) => {
  if (!data) return;
  const ycz = data?.find((item) => item?.status === '已解除')?.num;
  const czz = data?.find((item) => item?.status === '未处理')?.num;
  return {
    ycz,
    czz,
    total: ycz + czz,
  };
};
