import { defineComponent as E, useSlots as F, ref as c, computed as u, watch as L, createElementBlock as p, openBlock as l, normalizeClass as P, createCommentVNode as v, createVNode as d, createElementVNode as b, createBlock as S, toDisplayString as m, unref as r, withCtx as i, renderSlot as R, createTextVNode as T } from "vue";
import h from "../PlIcon24/PlIcon24.vue.js";
/* empty css                 */
import { okOptional as $, tapIf as I } from "@milaboratories/helpers";
import { useLogHandle as O } from "./useLogHandle.js";
import { useLabelNotch as j } from "../../utils/useLabelNotch.js";
import q from "../../utils/DoubleContour.vue2.js";
/* empty css                            */
import y from "../PlTooltip/PlTooltip.vue.js";
import { downloadContent as z } from "../../helpers/downloadContent.js";
const M = { key: 0 }, G = { class: "pl-log-view__copy" }, J = {
  key: 1,
  class: "pl-log-view__error"
}, K = {
  name: "PlLogView"
}, ro = /* @__PURE__ */ E({
  ...K,
  props: {
    value: {},
    valueToCopy: {},
    logHandle: {},
    progressPrefix: {},
    error: {},
    output: {},
    maxRetries: {},
    mockPlatforma: {},
    label: {},
    disableAutoScroll: { type: Boolean },
    downloadFilename: {}
  },
  setup(n) {
    const x = (o) => {
      if (o && o.ok === !1)
        return o.errors.join(`
`);
    }, V = F(), t = n, g = O(t), k = c(!0), w = c(), _ = c(), f = u(() => {
      var o;
      return ((o = g.value) == null ? void 0 : o.error) ?? t.error ?? x(t.output);
    }), a = u(() => {
      var o;
      return ((o = g.value) == null ? void 0 : o.lines) ?? t.value ?? $(t.output);
    }), C = u(() => {
      if (t.valueToCopy)
        return t.valueToCopy;
      if (a.value && typeof a.value == "string")
        return a.value;
    }), s = c(!1);
    j(_);
    const N = u(() => s.value ? "clipboard-copied" : "clipboard"), A = () => {
      s.value = !0, setTimeout(() => {
        s.value = !1;
      }, 1200);
      const o = C.value;
      o !== void 0 && navigator.clipboard.writeText(o);
    }, H = (o) => {
      const e = C.value;
      e !== void 0 && z([e, "text/plain"], o);
    }, B = () => {
      t.disableAutoScroll || I(w.value, (o) => {
        k.value && o.scrollTo(o.scrollLeft, o.scrollHeight);
      });
    };
    L(
      a,
      () => {
        requestAnimationFrame(() => {
          B();
        });
      },
      { immediate: !0 }
    );
    const D = (o) => {
      const e = o.target;
      k.value = e.scrollTop + 20 >= e.scrollHeight - e.offsetHeight;
    };
    return (o, e) => (l(), p("div", {
      ref_key: "root",
      ref: _,
      class: P(["pl-log-view", { "has-error": f.value }])
    }, [
      n.label ? (l(), p("label", M, [
        b("span", null, m(n.label), 1),
        r(V).tooltip ? (l(), S(r(y), {
          key: 0,
          class: "info",
          position: "top"
        }, {
          tooltip: i(() => [
            R(o.$slots, "tooltip")
          ]),
          _: 3
        })) : v("", !0)
      ])) : v("", !0),
      d(q, { class: "pl-log-view__contour" }),
      b("div", G, [
        d(r(y), {
          "close-delay": 800,
          position: "top"
        }, {
          tooltip: i(() => [
            T(m(s.value ? "copied" : "copy"), 1)
          ]),
          default: i(() => [
            d(r(h), {
              title: "Copy content",
              name: N.value,
              onClick: A
            }, null, 8, ["name"])
          ]),
          _: 1
        }),
        n.downloadFilename ? (l(), S(r(y), {
          key: 0,
          "close-delay": 800,
          position: "top"
        }, {
          tooltip: i(() => [...e[1] || (e[1] = [
            T("download", -1)
          ])]),
          default: i(() => [
            d(r(h), {
              name: "download",
              onClick: e[0] || (e[0] = () => H(n.downloadFilename))
            })
          ]),
          _: 1
        })) : v("", !0)
      ]),
      f.value ? (l(), p("div", J, m(f.value), 1)) : (l(), p("div", {
        key: 2,
        ref_key: "contentRef",
        ref: w,
        class: "pl-log-view__content",
        onScroll: D
      }, m(a.value), 545))
    ], 2));
  }
});
export {
  ro as default
};
//# sourceMappingURL=PlLogView.vue.js.map
