"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const event = require("../../../constants/event.js");
const types = require("../../../utils/types.js");
const index$3 = require("../../teleport/index.js");
const index = require("../../../hooks/use-namespace/index.js");
const index$2 = require("../../../hooks/use-z-index/index.js");
const tour = require("./tour.js");
const helper = require("./helper.js");
const mask2 = require("./mask2.js");
const content2 = require("./content2.js");
const steps = require("./steps.js");
const index$1 = require("../../../../node_modules/@vueuse/core/index.js");
const vue = require("vue");
var tour_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ vue.defineComponent({
  name: "ElTour",
  inheritAttrs: false,
  __name: "tour",
  props: tour.tourProps,
  emits: tour.tourEmits,
  setup(__props, { emit: __emit }) {
    const props = __props;
    const emit = __emit;
    const ns = index.useNamespace("tour");
    const total = vue.ref(0);
    const currentStep = vue.ref();
    const current = index$1.useVModel(props, "current", emit, { passive: true });
    const currentTarget = vue.computed(() => {
      var _a;
      return (_a = currentStep.value) == null ? void 0 : _a.target;
    });
    const kls = vue.computed(() => [ns.b(), mergedType.value === "primary" ? ns.m("primary") : ""]);
    const mergedPlacement = vue.computed(() => {
      var _a;
      return ((_a = currentStep.value) == null ? void 0 : _a.placement) || props.placement;
    });
    const mergedContentStyle = vue.computed(() => {
      var _a;
      return ((_a = currentStep.value) == null ? void 0 : _a.contentStyle) ?? props.contentStyle;
    });
    const mergedMask = vue.computed(() => {
      var _a;
      return ((_a = currentStep.value) == null ? void 0 : _a.mask) ?? props.mask;
    });
    const mergedShowMask = vue.computed(() => !!mergedMask.value && props.modelValue);
    const mergedMaskStyle = vue.computed(() => types.isBoolean(mergedMask.value) ? void 0 : mergedMask.value);
    const mergedShowArrow = vue.computed(() => {
      var _a;
      return !!currentTarget.value && (((_a = currentStep.value) == null ? void 0 : _a.showArrow) ?? props.showArrow);
    });
    const mergedScrollIntoViewOptions = vue.computed(() => {
      var _a;
      return ((_a = currentStep.value) == null ? void 0 : _a.scrollIntoViewOptions) ?? props.scrollIntoViewOptions;
    });
    const mergedType = vue.computed(() => {
      var _a;
      return ((_a = currentStep.value) == null ? void 0 : _a.type) ?? props.type;
    });
    const { nextZIndex } = index$2.useZIndex();
    const nowZIndex = nextZIndex();
    const mergedZIndex = vue.computed(() => props.zIndex ?? nowZIndex);
    const { mergedPosInfo: pos, triggerTarget } = helper.useTarget(currentTarget, vue.toRef(props, "modelValue"), vue.toRef(props, "gap"), mergedMask, mergedScrollIntoViewOptions);
    vue.watch(() => props.modelValue, (val) => {
      if (!val) current.value = 0;
    });
    const onEscClose = () => {
      if (props.closeOnPressEscape) {
        emit(event.UPDATE_MODEL_EVENT, false);
        emit("close", current.value);
      }
    };
    const onUpdateTotal = (val) => {
      total.value = val;
    };
    const slots = vue.useSlots();
    vue.provide(helper.tourKey, {
      currentStep,
      current,
      total,
      showClose: vue.toRef(props, "showClose"),
      closeIcon: vue.toRef(props, "closeIcon"),
      mergedType,
      ns,
      slots,
      updateModelValue(modelValue) {
        emit(event.UPDATE_MODEL_EVENT, modelValue);
      },
      onClose() {
        emit("close", current.value);
      },
      onFinish() {
        emit("finish");
      },
      onChange() {
        emit(event.CHANGE_EVENT, current.value);
      }
    });
    return (_ctx, _cache) => {
      return vue.openBlock(), vue.createElementBlock(vue.Fragment, null, [
        vue.createVNode(vue.unref(index$3.ElTeleport), { to: __props.appendTo }, {
          default: vue.withCtx(() => {
            var _a, _b;
            return [vue.createElementVNode("div", vue.mergeProps({ class: kls.value }, _ctx.$attrs), [vue.createVNode(mask2.default, {
              visible: mergedShowMask.value,
              fill: (_a = mergedMaskStyle.value) == null ? void 0 : _a.color,
              style: vue.normalizeStyle((_b = mergedMaskStyle.value) == null ? void 0 : _b.style),
              pos: vue.unref(pos),
              "z-index": mergedZIndex.value,
              "target-area-clickable": __props.targetAreaClickable
            }, null, 8, [
              "visible",
              "fill",
              "style",
              "pos",
              "z-index",
              "target-area-clickable"
            ]), __props.modelValue ? (vue.openBlock(), vue.createBlock(content2.default, {
              key: vue.unref(current),
              reference: vue.unref(triggerTarget),
              placement: mergedPlacement.value,
              "show-arrow": mergedShowArrow.value,
              "z-index": mergedZIndex.value,
              style: vue.normalizeStyle(mergedContentStyle.value),
              onClose: onEscClose
            }, {
              default: vue.withCtx(() => [vue.createVNode(vue.unref(steps.default), {
                current: vue.unref(current),
                onUpdateTotal
              }, {
                default: vue.withCtx(() => [vue.renderSlot(_ctx.$slots, "default")]),
                _: 3
              }, 8, ["current"])]),
              _: 3
            }, 8, [
              "reference",
              "placement",
              "show-arrow",
              "z-index",
              "style"
            ])) : vue.createCommentVNode("v-if", true)], 16)];
          }),
          _: 3
        }, 8, ["to"]),
        vue.createCommentVNode(" just for IDE "),
        vue.createCommentVNode("v-if", true)
      ], 64);
    };
  }
});
exports.default = tour_vue_vue_type_script_setup_true_lang_default;
