var p = Object.defineProperty;
var l = (a, r, e) => r in a ? p(a, r, { enumerable: !0, configurable: !0, writable: !0, value: e }) : a[r] = e;
var i = (a, r, e) => l(a, typeof r != "symbol" ? r + "" : r, e);
import { LocationMediaItemContentObjectType as d } from "./index-LocationMediaItemContent.js";
import { ContentType as c } from "./index-Document.types.js";
import { MediaItemProcessor as f } from "./index-MediaItemProcessor.js";
class C extends f {
  constructor(e) {
    super();
    i(this, "applicableFileTypes", [c.IMAGE_ANY, c.IMAGE_JPEG, c.IMAGE_JPG, c.IMAGE_PNG]);
    i(this, "resolveProcessorPromise");
    i(this, "process", (e) => new Promise((t) => {
      this.resolveProcessorPromise = t, this.extractContentForMediaItems(e);
    }));
    i(this, "extractContentForMediaItems", async (e) => {
      var n;
      const t = [];
      for (const s of e) {
        const {
          file: o
        } = s;
        if (!o || s.fileType && !this.applicableFileTypes.includes(s.fileType)) {
          t.push(s);
          continue;
        }
        const m = await this.extractImageContent(o);
        if (!m) {
          t.push(s);
          continue;
        }
        t.push({
          ...s,
          mediaItemContent: {
            base64EncodedContent: m,
            objectType: d.App_Domain_Presence_Entities_Locations_MediaItems_LocationMediaItemContent
          }
        });
      }
      (n = this.resolveProcessorPromise) == null || n.call(this, t), this.resolveProcessorPromise = void 0;
    });
    i(this, "arrayBufferToBase64", (e) => {
      if (typeof e == "string")
        return e;
      let t = "";
      const n = new Uint8Array(e), s = n.byteLength;
      for (let o = 0; o < s; o++)
        t += String.fromCharCode(n[o]);
      return window.btoa(t);
    });
    i(this, "extractImageContent", async (e) => {
      const t = this;
      return new Promise((n, s) => {
        const o = new FileReader();
        o.onload = function() {
          o.result && n(t.arrayBufferToBase64(o.result));
        }, e && o.readAsDataURL(e);
      });
    });
  }
}
export {
  C as ImageContentProcessor
};
