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