import { defineComponent, computed, openBlock, createBlock, unref, mergeProps, withCtx, renderSlot, createTextVNode, toDisplayString } from 'vue';
import { P as Primitive } from '../Primitive/Primitive.js';
import { i as injectEditableRootContext } from './EditableRoot.js';

const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "EditablePreview",
  props: {
    asChild: { type: Boolean },
    as: { default: "span" }
  },
  setup(__props) {
    const props = __props;
    const context = injectEditableRootContext();
    const placeholder = computed(() => context.placeholder.value?.preview);
    function handleFocus() {
      if (context.activationMode.value === "focus")
        context.edit();
    }
    function handleDoubleClick() {
      if (context.activationMode.value === "dblclick")
        context.edit();
    }
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(Primitive), mergeProps(props, {
        tabindex: "0",
        "data-placeholder-shown": unref(context).isEditing.value ? undefined : "",
        hidden: unref(context).autoResize.value ? undefined : unref(context).isEditing.value,
        style: unref(context).autoResize.value ? {
          whiteSpace: "pre",
          userSelect: "none",
          gridArea: "1 / 1 / auto / auto",
          visibility: unref(context).isEditing.value ? "hidden" : undefined,
          overflow: "hidden",
          textOverflow: "ellipsis"
        } : undefined,
        onFocusin: handleFocus,
        onDblclick: handleDoubleClick
      }), {
        default: withCtx(() => [
          renderSlot(_ctx.$slots, "default", {}, () => [
            createTextVNode(toDisplayString(unref(context).modelValue.value || placeholder.value), 1)
          ])
        ]),
        _: 3
      }, 16, ["data-placeholder-shown", "hidden", "style"]);
    };
  }
});

export { _sfc_main as _ };
//# sourceMappingURL=EditablePreview.js.map
