"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var ModelBounds_exports = {};
__export(ModelBounds_exports, {
  ModelBounds: () => ModelBounds,
  extractApplicableConstraint: () => extractApplicableConstraint
});
module.exports = __toCommonJS(ModelBounds_exports);
var import_general = require("#general");
var import_model = require("#model");
/**
 * @license
 * Copyright 2022-2026 Matter.js Authors
 * SPDX-License-Identifier: Apache-2.0
 */
var ModelBounds;
((ModelBounds2) => {
  function createLengthBounds(model) {
    const constraint = extractApplicableConstraint(model);
    const value = import_model.FieldValue.numericValue(constraint.value, model.type);
    if (value !== void 0) {
      return { length: value };
    }
    return createRangeBounds(constraint, "minLength", "maxLength");
  }
  ModelBounds2.createLengthBounds = createLengthBounds;
  function createNumberBounds(model) {
    const constraint = model.effectiveConstraint;
    const value = import_model.FieldValue.numericValue(constraint.value, model.type);
    if (value !== void 0) {
      return { min: value, max: value };
    }
    return createRangeBounds(constraint, "min", "max", model.type);
  }
  ModelBounds2.createNumberBounds = createNumberBounds;
  ModelBounds2.NumericRanges = {
    uint8: { min: 0, max: import_general.UINT8_MAX },
    uint16: { min: 0, max: import_general.UINT16_MAX },
    uint24: { min: 0, max: import_general.UINT24_MAX },
    uint32: { min: 0, max: import_general.UINT32_MAX },
    uint64: { min: 0, max: import_general.UINT64_MAX },
    int8: { min: import_general.INT8_MIN, max: import_general.INT8_MAX },
    int16: { min: import_general.INT16_MIN, max: import_general.INT16_MAX },
    int32: { min: import_general.INT32_MIN, max: import_general.INT32_MAX },
    int64: { min: import_general.INT64_MIN, max: import_general.INT64_MAX },
    float32: { min: import_general.FLOAT32_MIN, max: import_general.FLOAT32_MAX },
    percent: { min: 0, max: 100 },
    percent100ths: { min: 0, max: 1e4 }
  };
})(ModelBounds || (ModelBounds = {}));
function createRangeBounds(constraint, minKey, maxKey, type) {
  let min = import_model.FieldValue.numericValue(constraint.min, type);
  let max = import_model.FieldValue.numericValue(constraint.max, type);
  if (min === ModelBounds.NumericRanges[type]?.min) {
    min = void 0;
  }
  if (max === ModelBounds.NumericRanges[type]?.max) {
    max = void 0;
  }
  if (min === void 0 && max === void 0) {
    return;
  }
  const bounds = {};
  if (min !== void 0) {
    bounds[minKey] = min;
  }
  if (max !== void 0) {
    bounds[maxKey] = max;
  }
  return bounds;
}
function extractApplicableConstraint(model) {
  let constraint = model.effectiveConstraint;
  if (constraint.in) {
    const siblingName = import_model.FieldValue.referenced(constraint.in);
    if (siblingName) {
      const sibling = model.parent?.member((0, import_general.camelize)(siblingName, true));
      const siblingConstraint = sibling.effectiveConstraint;
      if (siblingConstraint.entry) {
        constraint = siblingConstraint.entry;
      }
    }
  }
  return constraint;
}
//# sourceMappingURL=ModelBounds.js.map
