"use strict";

exports.__esModule = true;
exports.cellKey = cellKey;
exports.noBorder = void 0;
exports.parseCellKey = parseCellKey;
exports.runCellValidation = runCellValidation;
exports.validResult = void 0;
function cellKey(rowKey, columnId) {
  return `${rowKey}:${columnId}`;
}
function parseCellKey(key) {
  const idx = key.indexOf(':');
  if (idx === -1) {
    return null;
  }
  return {
    rowKey: key.slice(0, idx),
    columnId: key.slice(idx + 1)
  };
}
const noBorder = exports.noBorder = {
  top: false,
  bottom: false,
  left: false,
  right: false
};
const validResult = exports.validResult = {
  valid: true
};
function checkValidationRule(rule, value) {
  switch (rule.type) {
    case 'required':
      return value != null && value !== '';
    case 'min':
      return typeof value === 'number' && value >= rule.value;
    case 'max':
      return typeof value === 'number' && value <= rule.value;
    case 'minLength':
      return typeof value === 'string' && value.length >= rule.value;
    case 'maxLength':
      return typeof value === 'string' && value.length <= rule.value;
    case 'pattern':
      return typeof value === 'string' && rule.value.test(value);
    case 'custom':
      return rule.validate(value);
    default:
      return true;
  }
}
function runCellValidation(value, rules, typeValidate) {
  const errors = [];
  if (rules) {
    for (const rule of rules) {
      if (!checkValidationRule(rule, value)) {
        errors.push(rule.message);
      }
    }
  }
  if (typeValidate) {
    const typeError = typeValidate(value, rules);
    if (typeError) {
      errors.push(typeError);
    }
  }
  return errors.length === 0 ? validResult : {
    valid: false,
    errors
  };
}
//# sourceMappingURL=utils.js.map