// 秒转化为时间的格式化字符串
export function secondToFormatTime(times) {
  if (times <= 0) return '--';
  var timeStr = '';
  var remain = times;
  var days = Math.floor(remain / (24 * 60 * 60));
  if (days) timeStr += "".concat(days, "\u5929");
  remain = remain % (24 * 60 * 60);
  var hours = Math.floor(remain / (60 * 60));
  if (hours) timeStr += "".concat(hours, "h");
  remain = remain % (60 * 60);
  var minutes = Math.floor(remain / 60);
  if (minutes) timeStr += "".concat(minutes, "min");
  remain = remain % 60;
  var seconds = Math.floor(remain);
  if (seconds) timeStr += "".concat(seconds, "s");
  return timeStr;
}

/**
 * 将时间戳格式化为x.xh形式
 * @param {number} timestamp - 时间戳（毫秒）
 * @returns {string} 格式化后的小时字符串，例如 "10h" 或 "1.5h"
 */
export function formatTimestampToHours(timestamp) {
  // 计算小时数
  var hours = timestamp / (1000 * 60 * 60);

  // 格式化输出
  if (hours === Math.floor(hours)) {
    // 整数小时，如 10h
    return "".concat(Math.floor(hours), "h");
  } else {
    // 小数小时，保留2位小数，如 1.5h
    return "".concat(hours.toFixed(2), "h");
  }
}
export function secondToFormatTimeArray(times) {
  if (times <= 0) return '--';
  var timeList = [];
  var remain = times;
  var days = Math.floor(remain / (24 * 60 * 60));
  if (days) timeList.push({
    value: days,
    unit: '天'
  });
  remain = remain % (24 * 60 * 60);
  var hours = Math.floor(remain / (60 * 60));
  if (hours) timeList.push({
    value: hours,
    unit: 'h'
  });
  remain = remain % (60 * 60);
  var minutes = Math.floor(remain / 60);
  if (minutes) timeList.push({
    value: minutes,
    unit: 'min'
  });
  remain = remain % 60;
  var seconds = Math.floor(remain);
  if (seconds) timeList.push({
    value: seconds,
    unit: 's'
  });
  return timeList;
}
export var getFieldRender = function getFieldRender(fields, info) {
  var list = [];
  fields.forEach(function (item) {
    if ((info !== null && info !== void 0 && info[item.showKey] || item.showKey === 'tenderName') && !['address', 'divisionName', 'accUnitName', 'manageUnitName', 'description', 'panoramaLinkAddress'].includes(item.showKey)) {
      list.push({
        label: item.name,
        key: item.showKey,
        value: info === null || info === void 0 ? void 0 : info[item.showKey],
        componentType: item.component.type
      });
    }
  });
  fields.forEach(function (item) {
    var _info$dataJson;
    if (['address', 'divisionName', 'accUnitName', 'manageUnitName', 'description', 'panoramaLinkAddress'].includes(item.showKey)) {
      list.push({
        label: item.name,
        key: item.showKey,
        value: info === null || info === void 0 ? void 0 : info[item.showKey],
        componentType: item.component.type
      });
    } else if (info !== null && info !== void 0 && (_info$dataJson = info.dataJson) !== null && _info$dataJson !== void 0 && _info$dataJson[item.showKey]) {
      var _info$dataJson2;
      list.push({
        label: item.name,
        key: item.showKey,
        value: info === null || info === void 0 || (_info$dataJson2 = info.dataJson) === null || _info$dataJson2 === void 0 ? void 0 : _info$dataJson2[item.showKey],
        componentType: item.component.type
      });
    }
  });
  return list;
};
export var transformRgb = function transformRgb(color) {
  var n = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1;
  // 16进制颜色值的正则
  var reg = /^#([0-9a-fA-f]{3}|[0-9a-fA-f]{6})$/;
  // 把颜色值变成小写
  var newColor = color.toLowerCase();
  if (reg.test(newColor)) {
    // 如果只有三位的值，需变成六位，如：#fff => #ffffff
    if (newColor.length === 4) {
      var colorNew = '#';
      for (var i = 1; i < 4; i += 1) {
        colorNew += newColor.slice(i, i + 1).concat(newColor.slice(i, i + 1));
      }
      newColor = colorNew;
    }
    // 处理六位的颜色值，转为RGB
    var colorChange = [];
    for (var _i = 1; _i < 7; _i += 2) {
      colorChange.push(parseInt("0x".concat(newColor.slice(_i, _i + 2))));
    }
    var _rgb = "rgba(".concat(colorChange.join(','), ",").concat(n, ")");
    return _rgb;
  } else {
    return newColor;
  }
};
export var getPercentValue = function getPercentValue(valueList, index, precision) {
  // 判断是否为空
  if (!valueList[index]) {
    return 0;
  }
  // 求和
  var sum = valueList.reduce(function (acc, val) {
    return acc + (isNaN(val) ? 0 : val);
  }, 0);
  if (sum === 0) {
    return 0;
  }
  // 10的2次幂是100，用于计算精度。
  var digits = Math.pow(10, precision);
  // 扩大比例100，
  var votesPerQuota = valueList.map(function (val) {
    return (isNaN(val) ? 0 : val) / sum * digits * 100;
  });
  // 总数，扩大比例意味的总数要扩大
  var targetSeats = digits * 100;
  // 再向下取值，组成数组
  var seats = votesPerQuota.map(function (votes) {
    return Math.floor(votes);
  });
  // 再新计算合计，用于判断与总数量是否相同，相同则占比会100%
  var currentSum = seats.reduce(function (acc, val) {
    return acc + val;
  }, 0);
  // 余数部分的数组：原先数组减去向下取值的数组，得到余数部分的数组
  var remainder = votesPerQuota.map(function (votes, index) {
    return votes - seats[index];
  });
  // 给最大最大的余额加1，凑个占比100%；
  while (currentSum < targetSeats) {
    //  找到下一个最大的余额，给其加1
    var max = Number.NEGATIVE_INFINITY;
    var maxId = null;
    for (var i = 0, len = remainder.length; i < len; ++i) {
      if (remainder[i] > max) {
        max = remainder[i];
        maxId = i;
      }
    }
    // 对最大项余额加1
    ++seats[maxId];
    // 已经增加最大余数加1，则下次判断就可以不需要再判断这个余额数。
    remainder[maxId] = 0;
    // 总的也要加1，为了判断是否总数是否相同，跳出循环。
    ++currentSum;
  }
  // 这时候的seats就会总数占比会100%
  return seats[index] / digits;
};
var isUndefined = function isUndefined(value) {
  return typeof value === 'undefined';
};
var isArray = Array.isArray;
export var paramSerializer = function paramSerializer(params) {
  if (!params) return '';
  var urlPart = [];
  for (var k in params) {
    var value = params[k];
    if (value === null || isUndefined(value)) continue;
    if (isArray(value)) {
      for (var i = 0, l = value.length; i < l; i++) {
        urlPart.push("".concat(k, "=").concat(value[i]));
      }
    } else {
      urlPart.push("".concat(k, "=").concat(value));
    }
  }
  return urlPart.join('&');
};