import { defineComponent as F, inject as R, ref as y, watch as V, createElementBlock as d, openBlock as o, Fragment as C, createCommentVNode as n, createBlock as w, unref as p, normalizeClass as I, createElementVNode as c, Teleport as M } from "vue";
import { uploadFile as z } from "../../../hooks/uploadFile/uploadFile.js";
import { useMessageDraft as A } from "../../../hooks/useMessageDraft.js";
import "../../../hooks/useSearchModel.js";
import { useTheme as B } from "../../../hooks/useTheme.js";
/* empty css                              */
/* empty css                                              */
import { useModalVideoRecorder as S } from "../../../hooks/modals/useVideoRecorder.js";
import "../../../node_modules/linkifyjs/dist/linkify.js";
import "../../../node_modules/linkify-string/dist/linkify-string.js";
import "../../../functions/parseMarkdown.js";
import E from "../../2_chatinput_elements/FilePreview/FilePreview.vue.js";
const U = {
  key: 0,
  class: "video-recorder__container"
}, N = {
  key: 1,
  class: "video-recorder__container"
}, Q = /* @__PURE__ */ F({
  __name: "VideoRecorder",
  props: {
    state: {
      type: String,
      default: "active"
    },
    filebumpUrl: {
      type: String,
      default: null
    }
  },
  setup(m) {
    const r = R("chatAppId"), { getMessage: t, setMessageFile: _, setRecordingMessage: u, resetMessageFile: h } = A(r), { getTheme: f } = B(r), a = y(""), s = y(), v = m, k = async () => {
      if (!t().file && v.state == "active") {
        const l = f().theme ? f().theme : "";
        await S(l).then(async (i) => {
          i.videoFile && (a.value = "uploading", u(!0), await z(v.filebumpUrl, i.videoFile).then((e) => {
            if (u(!1), a.value = e.status, e.status == "success") {
              _({
                url: e.url,
                name: e.name,
                size: e.size,
                type: e.type
              });
              const g = document.getElementById("chat-input-file-line-" + r);
              g && (g.style.display = "inherit"), e.preview && (s.value = {
                previewUrl: e.preview.previewUrl,
                isImage: e.preview.isImage,
                isVideo: e.preview.isVideo,
                isAudio: e.preview.isAudio,
                fileName: e.name,
                fileSize: e.preview.fileSize
              });
            }
          }));
        });
      }
    }, b = () => {
      h();
      const l = document.getElementById("chat-input-file-line-" + r);
      l && (l.style.display = "none"), s.value = void 0;
    };
    return V(
      () => t().file,
      () => {
        t().file || (s.value = void 0);
      }
    ), (l, i) => (o(), d(C, null, [
      p(t)().isRecording ? n("", !0) : (o(), d("div", U, [
        a.value != "uploading" ? (o(), d("button", {
          key: 0,
          class: I(["video-recorder__button", { "video-recorder__button-disabled": m.state == "disabled" || p(t)().file }]),
          onClick: k
        }, [...i[0] || (i[0] = [
          c("span", { class: "pi pi-video" }, null, -1)
        ])], 2)) : n("", !0)
      ])),
      a.value === "uploading" ? (o(), d("div", N, [...i[1] || (i[1] = [
        c("div", { class: "video-recorder__status" }, [
          c("span", null, "Загрузка файла...")
        ], -1)
      ])])) : n("", !0),
      p(t)().file ? (o(), w(M, {
        key: 2,
        to: "#chat-input-file-line-" + p(r)
      }, [
        s.value ? (o(), w(E, {
          key: 0,
          "file-info": s.value,
          onReset: b
        }, null, 8, ["file-info"])) : n("", !0)
      ], 8, ["to"])) : n("", !0)
    ], 64));
  }
});
export {
  Q as default
};
