var p = Object.defineProperty;
var l = (s, o, e) => o in s ? p(s, o, { enumerable: !0, configurable: !0, writable: !0, value: e }) : s[o] = e;
var i = (s, o, e) => l(s, typeof o != "symbol" ? o + "" : o, e);
import { ContentType as c } from "./index-Document.types.js";
import { MediaItemProcessor as h } from "./index-MediaItemProcessor.js";
class P extends h {
  constructor(e) {
    super();
    i(this, "applicableFileTypes", [c.VIDEO_ANY, c.VIDEO_MP4, c.VIDEO_MOV]);
    i(this, "resolveProcessorPromise");
    i(this, "process", (e) => new Promise((r) => {
      this.resolveProcessorPromise = r, this.extractMetadataForMediaItems(e);
    }));
    i(this, "extractMetadataForMediaItems", async (e) => {
      var d, t;
      const r = [];
      for (const a of e) {
        const {
          file: n
        } = a;
        if (!n || a.fileType && !this.applicableFileTypes.includes(a.fileType)) {
          r.push(a);
          continue;
        }
        const m = await this.extractVideoMetadata(n);
        if (!m) {
          r.push(a);
          continue;
        }
        r.push({
          ...a,
          metadata: {
            ...a.metadata,
            videoMetadata: {
              ...(d = a.metadata) == null ? void 0 : d.videoMetadata,
              ...m
            }
          }
        });
      }
      (t = this.resolveProcessorPromise) == null || t.call(this, r), this.resolveProcessorPromise = void 0;
    });
    i(this, "extractVideoMetadata", async (e) => new Promise((r, d) => {
      const t = document.createElement("video");
      t.preload = "metadata", t.onloadedmetadata = () => {
        const a = {
          duration: t.duration,
          width: t.videoWidth,
          height: t.videoHeight
        };
        URL.revokeObjectURL(t.src), r(a);
      }, t.onerror = (a) => {
        d(new Error("Error reading video metadata"));
      }, t.src = URL.createObjectURL(e);
    }));
  }
}
export {
  P as VideoMetadataProcessor
};
