"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const constants = require("./constants.js");
const anchorLink = require("./anchor-link.js");
const Vue = require("vue");
const _hoisted_1 = ["href"];
var anchor_link_vue_vue_type_script_setup_true_lang_default = /* @__PURE__ */ Vue.defineComponent({
  name: "ElAnchorLink",
  __name: "anchor-link",
  props: anchorLink.anchorLinkProps,
  setup(__props) {
    const props = __props;
    const linkRef = Vue.ref(null);
    const { ns, direction, currentAnchor, addLink, removeLink, handleClick: contextHandleClick } = Vue.inject(constants.anchorKey);
    const cls = Vue.computed(() => [ns.e("link"), ns.is("active", currentAnchor.value === props.href)]);
    const handleClick = (e) => {
      contextHandleClick(e, props.href);
    };
    Vue.watch(() => props.href, (val, oldVal) => {
      Vue.nextTick(() => {
        if (oldVal) removeLink(oldVal);
        if (val) addLink({
          href: val,
          el: linkRef.value
        });
      });
    });
    Vue.onMounted(() => {
      const { href } = props;
      if (href) addLink({
        href,
        el: linkRef.value
      });
    });
    Vue.onBeforeUnmount(() => {
      const { href } = props;
      if (href) removeLink(href);
    });
    return (_ctx, _cache) => {
      return Vue.openBlock(), Vue.createElementBlock("div", { class: Vue.normalizeClass(Vue.unref(ns).e("item")) }, [Vue.createElementVNode("a", {
        ref_key: "linkRef",
        ref: linkRef,
        class: Vue.normalizeClass(cls.value),
        href: __props.href,
        onClick: handleClick
      }, [Vue.renderSlot(_ctx.$slots, "default", {}, () => [Vue.createTextVNode(Vue.toDisplayString(__props.title), 1)])], 10, _hoisted_1), _ctx.$slots["sub-link"] && Vue.unref(direction) === "vertical" ? (Vue.openBlock(), Vue.createElementBlock("div", {
        key: 0,
        class: Vue.normalizeClass(Vue.unref(ns).e("list"))
      }, [Vue.renderSlot(_ctx.$slots, "sub-link")], 2)) : Vue.createCommentVNode("v-if", true)], 2);
    };
  }
});
exports.default = anchor_link_vue_vue_type_script_setup_true_lang_default;
