var W = Object.defineProperty;
var b = (e, t, i) => t in e ? W(e, t, { enumerable: !0, configurable: !0, writable: !0, value: i }) : e[t] = i;
var a = (e, t, i) => b(e, typeof t != "symbol" ? t + "" : t, i);
import { getAspectRatioFormatted as l } from "./index-format-aspect-ratio.js";
import { ContentType as g } from "./index-Document.types.js";
import { IMAGE_VALIDATION_ERRORS as s } from "./index-media-items-validations.js";
import { MediaItemValidator as y } from "./index-MediaItemValidator.js";
class H extends y {
  constructor(i) {
    super();
    a(this, "applicableFileTypes", [g.IMAGE_ANY, g.IMAGE_JPEG, g.IMAGE_JPG, g.IMAGE_PNG]);
    a(this, "imageResolutionConfig");
    a(this, "resolveValidatePromise");
    a(this, "validate", (i) => new Promise((o) => {
      this.resolveValidatePromise = o, this.validateImageFiles(i);
    }));
    a(this, "validateImageFiles", (i) => {
      var n;
      const o = [];
      for (const r of i)
        o.push(this.validateImage(r));
      (n = this.resolveValidatePromise) == null || n.call(this, o), this.resolveValidatePromise = void 0;
    });
    a(this, "validateImage", (i) => {
      var r, h, p, u, R, f, _, d, m, A, c, v, E, O, T, x, M, C, L, S, N, G, P, V, I, U;
      const {
        file: o
      } = i;
      if (i.isInvalid = i.isInvalid ?? !1, i.validationErrors = i.validationErrors ?? [], !o || i.fileType && !this.applicableFileTypes.includes(i.fileType))
        return i;
      (((h = (r = i.metadata) == null ? void 0 : r.imageMetadata) == null ? void 0 : h.width) ?? 0) > (((p = this.imageResolutionConfig) == null ? void 0 : p.maxWidth) ?? Number.MAX_VALUE) && (i.isInvalid = !0, i.validationErrors.push({
        text: s.RESOLUTION_TOO_LARGE,
        replacements: {
          imageSize: `${(u = this.imageResolutionConfig) == null ? void 0 : u.maxWidth}px`
        }
      })), (((f = (R = i.metadata) == null ? void 0 : R.imageMetadata) == null ? void 0 : f.width) ?? 0) < (((_ = this.imageResolutionConfig) == null ? void 0 : _.minWidth) ?? 0) && (i.isInvalid = !0, i.validationErrors.push({
        text: s.RESOLUTION_TOO_SMALL,
        replacements: {
          imageSize: `${(d = this.imageResolutionConfig) == null ? void 0 : d.minWidth}px`
        }
      })), (((A = (m = i.metadata) == null ? void 0 : m.imageMetadata) == null ? void 0 : A.height) ?? 0) > (((c = this.imageResolutionConfig) == null ? void 0 : c.maxHeight) ?? Number.MAX_VALUE) && (i.isInvalid = !0, i.validationErrors.push({
        text: s.RESOLUTION_TOO_LARGE,
        replacements: {
          imageSize: `${(v = this.imageResolutionConfig) == null ? void 0 : v.maxWidth}px`
        }
      })), (((O = (E = i.metadata) == null ? void 0 : E.imageMetadata) == null ? void 0 : O.height) ?? 0) < (((T = this.imageResolutionConfig) == null ? void 0 : T.minHeight) ?? 0) && (i.isInvalid = !0, i.validationErrors.push({
        text: s.RESOLUTION_TOO_SMALL,
        replacements: {
          imageSize: `${(x = this.imageResolutionConfig) == null ? void 0 : x.minWidth}px`
        }
      }));
      const n = (((C = (M = i.metadata) == null ? void 0 : M.imageMetadata) == null ? void 0 : C.width) ?? 0) / (((S = (L = i.metadata) == null ? void 0 : L.imageMetadata) == null ? void 0 : S.height) ?? 1);
      return n > (((N = this.imageResolutionConfig) == null ? void 0 : N.maxAspectRatio) ?? Number.MAX_VALUE) && (i.isInvalid = !0, i.validationErrors.push({
        text: s.ASPECT_RATIO_NOT_IN_LIMITS,
        replacements: {
          min_aspect_ratio: l(((G = this.imageResolutionConfig) == null ? void 0 : G.minAspectRatio) ?? 1) ?? "",
          max_aspect_ratio: l(((P = this.imageResolutionConfig) == null ? void 0 : P.maxAspectRatio) ?? 1) ?? ""
        }
      })), n < (((V = this.imageResolutionConfig) == null ? void 0 : V.minAspectRatio) ?? 0) && (i.isInvalid = !0, i.validationErrors.push({
        text: s.ASPECT_RATIO_NOT_IN_LIMITS,
        replacements: {
          min_aspect_ratio: l(((I = this.imageResolutionConfig) == null ? void 0 : I.minAspectRatio) ?? 1) ?? "",
          max_aspect_ratio: l(((U = this.imageResolutionConfig) == null ? void 0 : U.maxAspectRatio) ?? 1) ?? ""
        }
      })), i;
    });
    this.imageResolutionConfig = i;
  }
}
export {
  H as ImageResolutionValidator
};
