"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;
