var l = Object.defineProperty;
var p = (r, a, t) => a in r ? l(r, a, { enumerable: !0, configurable: !0, writable: !0, value: t }) : r[a] = t;
var i = (r, a, t) => p(r, typeof a != "symbol" ? a + "" : a, t);
import { ContentType as d } from "./index-Document.types.js";
import { MediaItemProcessor as h } from "./index-MediaItemProcessor.js";
class u extends h {
  constructor(t) {
    super();
    i(this, "applicableFileTypes", [d.IMAGE_ANY, d.IMAGE_JPEG, d.IMAGE_JPG, d.IMAGE_PNG]);
    i(this, "resolveProcessorPromise");
    i(this, "process", (t) => new Promise((s) => {
      this.resolveProcessorPromise = s, this.extractMetadataForMediaItems(t);
    }));
    i(this, "extractMetadataForMediaItems", async (t) => {
      var n, o;
      const s = [];
      for (const e of t) {
        const {
          file: c
        } = e;
        if (!c || e.fileType && !this.applicableFileTypes.includes(e.fileType)) {
          s.push(e);
          continue;
        }
        const m = await this.extractImageMetadata(c);
        if (!m) {
          s.push(e);
          continue;
        }
        s.push({
          ...e,
          metadata: {
            ...e.metadata,
            imageMetadata: {
              ...(n = e.metadata) == null ? void 0 : n.imageMetadata,
              ...m
            }
          }
        });
      }
      (o = this.resolveProcessorPromise) == null || o.call(this, s), this.resolveProcessorPromise = void 0;
    });
    i(this, "extractImageMetadata", async (t) => new Promise((s, n) => {
      const o = new Image(), e = URL.createObjectURL(t);
      o.onload = () => {
        const c = o.width, m = o.height;
        URL.revokeObjectURL(e), s({
          width: c,
          height: m
        });
      }, o.onerror = (c) => {
        URL.revokeObjectURL(e), n(new Error("Failed to load the image."));
      }, o.src = e;
    }));
  }
}
export {
  u as ImageMetadataProcessor
};
