var l = Object.defineProperty;
var u = (o, i, s) => i in o ? l(o, i, { enumerable: !0, configurable: !0, writable: !0, value: s }) : o[i] = s;
var r = (o, i, s) => u(o, typeof i != "symbol" ? i + "" : i, s);
import { ContentType as a } from "./index-Document.types.js";
import { MediaItemProcessor as d } from "./index-MediaItemProcessor.js";
class b extends d {
  constructor(s) {
    super();
    r(this, "applicableFileTypes", [a.VIDEO_ANY, a.VIDEO_MP4, a.VIDEO_MOV]);
    r(this, "resolveProcessorPromise");
    r(this, "process", (s) => new Promise((e) => {
      this.resolveProcessorPromise = e, this.generateThumbnails(s);
    }));
    /**
     * Generates thumbnails for the provided media items.
     *
     * This method processes an array of media items, generating a thumbnail for each item
     * if applicable. If a media item does not have a file or its file type is not supported,
     * it is added to the processed media items array without modification. If a thumbnail
     * is successfully generated, the media item is updated with the public thumbnail URL.
     *
     * @param mediaItems - An array of media items to process.
     * @returns A promise that resolves with the processed media items, each potentially
     *          updated with a public thumbnail URL.
     */
    r(this, "generateThumbnails", async (s) => {
      var n;
      const e = [];
      for (const t of s) {
        const {
          file: c
        } = t;
        if (!c || t.fileType && !this.applicableFileTypes.includes(t.fileType)) {
          e.push(t);
          continue;
        }
        const m = await this.getThumbnail(c);
        if (!m) {
          e.push(t);
          continue;
        }
        e.push({
          ...t,
          publicThumbnailUrl: m
        });
      }
      (n = this.resolveProcessorPromise) == null || n.call(this, e), this.resolveProcessorPromise = void 0;
    });
    /**
     * Generates a thumbnail image from a video file or blob.
     *
     * @param file - The video file or blob from which to generate the thumbnail.
     * @returns A promise that resolves to a data URL string representing the thumbnail image, or null if the thumbnail could not be generated.
     */
    r(this, "getThumbnail", async (s) => {
      const e = document.createElement("video");
      return e.src = URL.createObjectURL(s), e.currentTime = 1, e.width = 128, e.height = 128, e.muted = !0, e.setAttribute("crossOrigin", "anonymous"), new Promise((n) => {
        e.addEventListener("loadeddata", () => {
          const t = document.createElement("canvas");
          t.width = e.videoWidth, t.height = e.videoHeight;
          const c = t.getContext("2d");
          if (!c) {
            n(null);
            return;
          }
          c.drawImage(e, 0, 0, t.width, t.height), n(t.toDataURL());
        });
      });
    });
  }
}
export {
  b as VideoThumbnailProcessor
};
