function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
/** 设备列表默认分页大小。 */
export var DEFAULT_PAGE_SIZE = 10;

/** 设备短号规则：店内唯一，允许大写字母和数字，长度 1-10。 */
export var DEVICE_SHORT_NUMBER_MAX_LENGTH = 10;
export var DEVICE_SHORT_NUMBER_PATTERN = /^[A-Z0-9]+$/;

/** 工作区域弹窗模式：创建或编辑。 */

/** 搜索关键字标准化，避免大小写和首尾空格影响匹配。 */
export var normalizeText = function normalizeText(text) {
  return text.toLowerCase().trim();
};

/** 设备短号输入态标准化：用户输入小写时立即转为大写。 */
export var normalizeDeviceShortNumberInput = function normalizeDeviceShortNumberInput(value) {
  return (value || '').toUpperCase();
};

/** 设备短号提交态标准化：去掉首尾空格后提交给接口。 */
export var normalizeDeviceShortNumberPayload = function normalizeDeviceShortNumberPayload(value) {
  return normalizeDeviceShortNumberInput(value).trim();
};

/** 校验设备短号格式；占用校验由接口返回。 */
export var validateDeviceShortNumber = function validateDeviceShortNumber(messages) {
  return function (_rule, value) {
    var shortNumber = normalizeDeviceShortNumberPayload(value);
    if (!shortNumber) {
      return Promise.reject(new Error(messages.required));
    }
    if (shortNumber === '0' || shortNumber === '00') {
      return Promise.reject(new Error(messages.reserved));
    }
    if (shortNumber.length > DEVICE_SHORT_NUMBER_MAX_LENGTH || !DEVICE_SHORT_NUMBER_PATTERN.test(shortNumber)) {
      return Promise.reject(new Error(messages.format));
    }
    return Promise.resolve();
  };
};

/** 替换文案模板中的 {token}，用于删除确认等动态文案。 */
export var formatToken = function formatToken(text, values) {
  return Object.entries(values).reduce(function (result, _ref) {
    var _ref2 = _slicedToArray(_ref, 2),
      key = _ref2[0],
      value = _ref2[1];
    return result.replace(new RegExp("\\{".concat(key, "\\}"), 'g'), String(value));
  }, text);
};

/** 按后端 sort 字段排序工作区域，避免直接修改原数组。 */
export var sortWorkAreaList = function sortWorkAreaList(list) {
  return _toConsumableArray(list).sort(function (a, b) {
    return (a.sort || 0) - (b.sort || 0);
  });
};