import { Color } from "cesium";
import { maxBy, minBy, map } from "lodash-es";
import { notification } from "antd";

export function feedback(message) {
  if (
    Object.prototype.toString.call(message) === "[object Object]" &&
    message !== null
  ) {
    Object.keys(message).forEach((key) => {
      message[key].forEach((item) => {
        notification.error({ message: key, description: item });
      });
    });
  } else if (Array.isArray(message)) {
    message.forEach((item) => {
      notification.error({ message: "错误", description: item });
    });
  } else {
    notification.error({ message: "错误", description: message });
  }
}

export function generateYearsFromRange(start, end) {
  const years = [];
  for (let i = start; i <= end; i++) {
    years.push(i);
  }
  return years;
}

export function getStep(features, column) {
  const max = maxBy(features, (feature) => {
    return parseFloat(feature.properties[column]);
  });
  const min = minBy(features, (feature) => {
    return parseFloat(feature.properties[column]);
  });
  const step = (max.properties[column] - min.properties[column]) / 10;

  return {
    max: parseFloat(max.properties[column]),
    min: parseFloat(min.properties[column]),
    step,
  };
}

export function getValue(features, column) {
  const results = map(features, (feature) => {
    return feature.properties[column];
  });
  return [...new Set(results)].sort((a, b) => a - b);
}

export const COLORS = {
  "Color.ALICEBLUE": Color.ALICEBLUE,
  "Color.ANTIQUEWHITE": Color.ANTIQUEWHITE,
  "Color.AQUA": Color.AQUA,
  "Color.AQUAMARINE": Color.AQUAMARINE,
  "Color.AZURE": Color.AZURE,
  "Color.BEIGE": Color.BEIGE,
  "Color.BISQUE": Color.BISQUE,
  "Color.BLACK": Color.BLACK,
  "Color.BLANCHEDALMOND": Color.BLANCHEDALMOND,
  "Color.BLUE": Color.BLUE,
  "Color.BLUEVIOLET": Color.BLUEVIOLET,
  "Color.BROWN": Color.BROWN,
  "Color.BURLYWOOD": Color.BURLYWOOD,
  "Color.CADETBLUE": Color.CADETBLUE,
  "Color.CHARTREUSE": Color.CHARTREUSE,
  "Color.CHOCOLATE": Color.CHOCOLATE,
  "Color.CORAL": Color.CORAL,
  "Color.CORNFLOWERBLUE": Color.CORNFLOWERBLUE,
  "Color.CORNSILK": Color.CORNSILK,
  "Color.CRIMSON": Color.CRIMSON,
  "Color.CYAN": Color.CYAN,
  "Color.DARKBLUE": Color.DARKBLUE,
  "Color.DARKCYAN": Color.DARKCYAN,
  "Color.DARKGOLDENROD": Color.DARKGOLDENROD,
  "Color.DARKGRAY": Color.DARKGRAY,
  "Color.DARKGREEN": Color.DARKGREEN,
  "Color.DARKGREY": Color.DARKGREY,
  "Color.DARKKHAKI": Color.DARKKHAKI,
  "Color.DARKMAGENTA": Color.DARKMAGENTA,
  "Color.DARKOLIVEGREEN": Color.DARKOLIVEGREEN,
  "Color.DARKORANGE": Color.DARKORANGE,
  "Color.DARKORCHID": Color.DARKORCHID,
  "Color.DARKRED": Color.DARKRED,
  "Color.DARKSALMON": Color.DARKSALMON,
  "Color.DARKSEAGREEN": Color.DARKSEAGREEN,
  "Color.DARKSLATEBLUE": Color.DARKSLATEBLUE,
  "Color.DARKSLATEGRAY": Color.DARKSLATEGRAY,
  "Color.DARKSLATEGREY": Color.DARKSLATEGREY,
  "Color.DARKTURQUOISE": Color.DARKTURQUOISE,
  "Color.DARKVIOLET": Color.DARKVIOLET,
  "Color.DEEPPINK": Color.DEEPPINK,
  "Color.DEEPSKYBLUE": Color.DEEPSKYBLUE,
  "Color.DIMGRAY": Color.DIMGRAY,
  "Color.DIMGREY": Color.DIMGREY,
  "Color.DODGERBLUE": Color.DODGERBLUE,
  "Color.FIREBRICK": Color.FIREBRICK,
  "Color.FLORALWHITE": Color.FLORALWHITE,
  "Color.FORESTGREEN": Color.FORESTGREEN,
  "Color.FUCHSIA": Color.FUCHSIA,
  "Color.GAINSBORO": Color.GAINSBORO,
  "Color.GHOSTWHITE": Color.GHOSTWHITE,
  "Color.GOLD": Color.GOLD,
  "Color.GOLDENROD": Color.GOLDENROD,
  "Color.GRAY": Color.GRAY,
  "Color.GREEN": Color.GREEN,
  "Color.GREENYELLOW": Color.GREENYELLOW,
  "Color.GREY": Color.GREY,
  "Color.HONEYDEW": Color.HONEYDEW,
  "Color.HOTPINK": Color.HOTPINK,
  "Color.INDIANRED": Color.INDIANRED,
  "Color.INDIGO": Color.INDIGO,
  "Color.IVORY": Color.IVORY,
  "Color.KHAKI": Color.KHAKI,
  "Color.LAVENDER": Color.LAVENDER,
  "Color.LAVENDAR_BLUSH": Color.LAVENDAR_BLUSH,
  "Color.LAWNGREEN": Color.LAWNGREEN,
  "Color.LEMONCHIFFON": Color.LEMONCHIFFON,
  "Color.LIGHTBLUE": Color.LIGHTBLUE,
  "Color.LIGHTCORAL": Color.LIGHTCORAL,
  "Color.LIGHTCYAN": Color.LIGHTCYAN,
  "Color.LIGHTGOLDENRODYELLOW": Color.LIGHTGOLDENRODYELLOW,
  "Color.LIGHTGRAY": Color.LIGHTGRAY,
  "Color.LIGHTGREEN": Color.LIGHTGREEN,
  "Color.LIGHTGREY": Color.LIGHTGREY,
  "Color.LIGHTPINK": Color.LIGHTPINK,
  "Color.LIGHTSEAGREEN": Color.LIGHTSEAGREEN,
  "Color.LIGHTSKYBLUE": Color.LIGHTSKYBLUE,
  "Color.LIGHTSLATEGRAY": Color.LIGHTSLATEGRAY,
  "Color.LIGHTSLATEGREY": Color.LIGHTSLATEGREY,
  "Color.LIGHTSTEELBLUE": Color.LIGHTSTEELBLUE,
  "Color.LIGHTYELLOW": Color.LIGHTYELLOW,
  "Color.LIME": Color.LIME,
  "Color.LIMEGREEN": Color.LIMEGREEN,
  "Color.LINEN": Color.LINEN,
  "Color.MAGENTA": Color.MAGENTA,
  "Color.MAROON": Color.MAROON,
  "Color.MEDIUMAQUAMARINE": Color.MEDIUMAQUAMARINE,
  "Color.MEDIUMBLUE": Color.MEDIUMBLUE,
  "Color.MEDIUMORCHID": Color.MEDIUMORCHID,
  "Color.MEDIUMPURPLE": Color.MEDIUMPURPLE,
  "Color.MEDIUMSEAGREEN": Color.MEDIUMSEAGREEN,
  "Color.MEDIUMSLATEBLUE": Color.MEDIUMSLATEBLUE,
  "Color.MEDIUMSPRINGGREEN": Color.MEDIUMSPRINGGREEN,
  "Color.MEDIUMTURQUOISE": Color.MEDIUMTURQUOISE,
  "Color.MEDIUMVIOLETRED": Color.MEDIUMVIOLETRED,
  "Color.MIDNIGHTBLUE": Color.MIDNIGHTBLUE,
  "Color.MINTCREAM": Color.MINTCREAM,
  "Color.MISTYROSE": Color.MISTYROSE,
  "Color.MOCCASIN": Color.MOCCASIN,
  "Color.NAVAJOWHITE": Color.NAVAJOWHITE,
  "Color.NAVY": Color.NAVY,
  "Color.OLDLACE": Color.OLDLACE,
  "Color.OLIVE": Color.OLIVE,
  "Color.OLIVEDRAB": Color.OLIVEDRAB,
  "Color.ORANGE": Color.ORANGE,
  "Color.ORANGERED": Color.ORANGERED,
  "Color.ORCHID": Color.ORCHID,
  "Color.PALEGOLDENROD": Color.PALEGOLDENROD,
  "Color.PALEGREEN": Color.PALEGREEN,
  "Color.PALETURQUOISE": Color.PALETURQUOISE,
  "Color.PALEVIOLETRED": Color.PALEVIOLETRED,
  "Color.PAPAYAWHIP": Color.PAPAYAWHIP,
  "Color.PEACHPUFF": Color.PEACHPUFF,
  "Color.PERU": Color.PERU,
  "Color.PINK": Color.PINK,
  "Color.PLUM": Color.PLUM,
  "Color.POWDERBLUE": Color.POWDERBLUE,
  "Color.PURPLE": Color.PURPLE,
  "Color.RED": Color.RED,
  "Color.ROSYBROWN": Color.ROSYBROWN,
  "Color.ROYALBLUE": Color.ROYALBLUE,
  "Color.SADDLEBROWN": Color.SADDLEBROWN,
  "Color.SALMON": Color.SALMON,
  "Color.SANDYBROWN": Color.SANDYBROWN,
  "Color.SEAGREEN": Color.SEAGREEN,
  "Color.SEASHELL": Color.SEASHELL,
  "Color.SIENNA": Color.SIENNA,
  "Color.SILVER": Color.SILVER,
  "Color.SKYBLUE": Color.SKYBLUE,
  "Color.SLATEBLUE": Color.SLATEBLUE,
  "Color.SLATEGRAY": Color.SLATEGRAY,
  "Color.SLATEGREY": Color.SLATEGREY,
  "Color.SNOW": Color.SNOW,
  "Color.SPRINGGREEN": Color.SPRINGGREEN,
  "Color.STEELBLUE": Color.STEELBLUE,
  "Color.TAN": Color.TAN,
  "Color.TEAL": Color.TEAL,
  "Color.THISTLE": Color.THISTLE,
  "Color.TOMATO": Color.TOMATO,
  "Color.TURQUOISE": Color.TURQUOISE,
  "Color.VIOLET": Color.VIOLET,
  "Color.WHEAT": Color.WHEAT,
  "Color.WHITE": Color.WHITE,
  "Color.WHITESMOKE": Color.WHITESMOKE,
  "Color.YELLOW": Color.YELLOW,
  "Color.YELLOWGREEN": Color.YELLOWGREEN,
  "Color.TRANSPARENT": Color.TRANSPARENT,
};

export const PATH = {
  实时视频: "/台站数据/实时视频",
  实时监测: "http://chinare.hbaa.cn/iot/yulong.php",
  在线数据: "/台站数据/在线数据",
  数据申请: "/数据申请",
  离线数据: "/manage/offlinedata",
  申请审核: "/manage/applydata",
  数据分类: "/manage/datatype",
  用户管理: "/manage/user",
};
