import { inject as p, ref as c, watch as g, onMounted as h, onUnmounted as v, createElementBlock as y, openBlock as w, withKeys as x, normalizeClass as k, unref as E, toDisplayString as F, nextTick as B } from "vue";
/* empty css                          */
import _ from "../../../_virtual/_plugin-vue_export-helper.js";
const b = ["id"], I = {
  __name: "PlaceholderComponent",
  props: {
    index: {
      type: Number,
      required: !0
    },
    value: {
      type: String,
      required: !0
    },
    isFilled: {
      type: Boolean,
      required: !0
    }
  },
  emits: ["edit"],
  setup(l, { emit: u }) {
    const i = p("chatAppId"), e = l, s = u, n = c(e.value), r = c();
    g(
      () => e.isFilled,
      () => {
        e.isFilled || (n.value = "Заполнить");
      },
      { immediate: !0 }
    );
    const f = (t) => {
      if (!e.isFilled) {
        n.value = "";
        const o = window.getSelection();
        o.getRangeAt && o.rangeCount && o.getRangeAt(0).selectNodeContents(t.target);
      }
    };
    function a() {
      n.value = r.value.innerText.trim(), e.value != n.value && (n.value != "" ? s("edit", [n.value, e.index]) : e.isFilled ? B(() => {
        n.value = e.value;
      }) : n.value = "Заполнить");
    }
    function m(t) {
      t.target.blur(), a();
    }
    function d(t) {
      t.target == document.getElementById("placeholder" + i + e.index) && (t.key === "Escape" && t.target.blur(), t.key == "Tab" && (t.target.blur(), document.getElementById("placeholder" + i + (e.index + 1)) && (t.preventDefault(), document.getElementById("placeholder" + i + (e.index + 1)).focus())));
    }
    return h(() => {
      window.addEventListener("keydown", d);
    }), v(() => {
      window.removeEventListener("keydown", d);
    }), (t, o) => (w(), y("span", {
      id: "placeholder" + E(i) + l.index,
      ref_key: "refPlaceholder",
      ref: r,
      contenteditable: "",
      class: k([{ filled: l.isFilled, empty: !l.isFilled }, "placeholder"]),
      onKeydown: x(m, ["enter"]),
      onFocus: f,
      onBlur: a
    }, F(n.value), 43, b));
  }
}, K = /* @__PURE__ */ _(I, [["__scopeId", "data-v-558891d3"]]);
export {
  K as default
};
