"use strict";
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
const vue = require("vue");
const comp = require("../../ui/src/comp.js");
const XEUtils = require("xe-utils");
require("../../ui/index.js");
const util = require("./util.js");
const index_esm = require("../../../../@vxe-ui/core/es/index.esm.js");
const VxeAnchorLinkComponent = comp.defineVxeComponent({
  name: "VxeAnchorLink",
  props: {
    content: [String, Number],
    title: [String, Number],
    href: String
  },
  emits: [],
  setup(props, context) {
    const { slots } = context;
    const $xeAnchor = vue.inject("$xeAnchor", null);
    const $xeParentAnchorLink = vue.inject("$xeAnchorLink", null);
    const xID = XEUtils.uniqueId();
    const refElem = vue.ref();
    const reactData = vue.reactive({});
    const linkConfig = vue.reactive({
      id: xID,
      href: props.href,
      children: []
    });
    const refMaps = {
      refElem
    };
    const computeIsActive = vue.computed(() => {
      const { href } = props;
      if ($xeAnchor) {
        return $xeAnchor.reactData.activeHref === href;
      }
      return null;
    });
    const computeMaps = {};
    const $xeAnchorLink = {
      xID,
      props,
      context,
      reactData,
      linkConfig,
      getRefMaps: () => refMaps,
      getComputeMaps: () => computeMaps
    };
    const clickEvent = (event) => {
      const { href } = props;
      if ($xeAnchor) {
        $xeAnchor.handleClickLink(event, href);
      }
    };
    vue.watch(() => props.href, (val) => {
      linkConfig.href = val;
    });
    vue.onMounted(() => {
      const elem = refElem.value;
      if ($xeAnchor && elem) {
        util.assembleAnchorLink($xeAnchor, elem, linkConfig, $xeParentAnchorLink);
      }
    });
    vue.onUnmounted(() => {
      if ($xeAnchor) {
        util.destroyAnchorLink($xeAnchor, linkConfig);
      }
    });
    const renderVN = () => {
      const { href, content, title } = props;
      const defaultSlot = slots.default;
      const subSlot = slots.sub;
      const isActive = computeIsActive.value;
      return vue.h("div", {
        ref: refElem,
        class: ["vxe-anchor-link", {
          "is--active": isActive
        }]
      }, [
        vue.h("a", {
          class: "vxe-anchor-link--item",
          href,
          title,
          onClick: clickEvent
        }, defaultSlot ? defaultSlot({}) : XEUtils.toValueString(content)),
        subSlot ? vue.h("div", {
          class: "vxe-anchor-link--sub-items"
        }, subSlot({})) : index_esm.renderEmptyElement()
      ]);
    };
    vue.provide("$xeAnchorLink", $xeAnchorLink);
    $xeAnchorLink.renderVN = renderVN;
    return $xeAnchorLink;
  },
  render() {
    return this.renderVN();
  }
});
exports.default = VxeAnchorLinkComponent;
