import { getStorageString, setStorageString } from "../../util/storage";
import { v4 as uuid } from 'uuid';
/**
 * @author 谦彧 <zhangmian.zm@alipay.com>
 * @date 2024/9/18
 */
export function getGrayscaleId() {
  try {
    var cachedGrayScaleId = getStorageString('AntomDefaultGrayScaleId', '');
    if (cachedGrayScaleId) {
      return parseInt(cachedGrayScaleId);
    }
    var seed = uuid();
    // 取倒数2、3位
    var sub = seed.substring(seed.length - 3, seed.length - 1);
    // 将16进制转成10进制值
    var decimal = parseInt(sub, 16);
    var grayScaleId = Math.floor(decimal * 100 / 255);
    setStorageString('AntomDefaultGrayScaleId', '' + grayScaleId);
    return grayScaleId;
  } catch (error) {
    console.error('Get gray scale ID failed', error);
    return 0;
  }
}
export function isGreyscaleMatch(configEntry, grayScaleId) {
  if (!(configEntry !== null && configEntry !== void 0 && configEntry.greyscale)) {
    return true;
  }
  try {
    var greyscale = parseInt(configEntry === null || configEntry === void 0 ? void 0 : configEntry.greyscale);
    if (greyscale === 0) {
      return false;
    }
    return greyscale >= grayScaleId;
  } catch (error) {
    console.error('Match gray scale ID failed', error);
    return false;
  }
}