/**
 * ldesign v0.4.6
 * (c) 2023 ldesign
 * @license MIT
 */

import _defineProperty from '@babel/runtime/helpers/defineProperty';
import Vue from 'vue';
import { getClassPrefixMixins } from '../config-provider/config-receiver.js';
import mixins from '../utils/mixins.js';
import { ANCHOR_SHARP_REGEXP } from './utils.js';
import props from './anchor-item-props.js';
import 'lodash/mergeWith';
import '../config-provider/context.js';
import 'lodash/merge';
import '../_common/js/global-config/default-config.js';
import '../_common/js/global-config/locale/zh_CN.js';
import '@babel/runtime/helpers/typeof';
import '../_chunks/dep-2cb61c79.js';
import 'dayjs';

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
var classPrefixMixins = getClassPrefixMixins("anchor");
var _AnchorItem = mixins(Vue, classPrefixMixins).extend({
  name: "TAnchorItem",
  props: _objectSpread(_objectSpread({}, props), {}, {
    href: {
      type: String,
      required: true,
      validator: function validator(v) {
        return ANCHOR_SHARP_REGEXP.test(v);
      }
    }
  }),
  inject: {
    tAnchor: {
      "default": void 0
    }
  },
  watch: {
    href: {
      immediate: true,
      handler: function handler() {
        this.unregister();
        this.register();
      }
    }
  },
  destroyed: function destroyed() {
    this.unregister();
  },
  methods: {
    register: function register() {
      this.tAnchor.registerLink(this.href);
    },
    unregister: function unregister() {
      var href = this.href;
      if (!href) return;
      this.tAnchor.unregisterLink(href);
    },
    handleClick: function handleClick(e) {
      var href = this.href,
        tAnchor = this.tAnchor,
        title = this.title;
      tAnchor.handleScrollTo(href);
      tAnchor.handleLinkClick({
        href: href,
        title: typeof title === "string" ? title : void 0,
        e: e
      });
    },
    renderTitle: function renderTitle() {
      var title = this.title,
        $scopedSlots = this.$scopedSlots;
      var titleSlot = $scopedSlots.title;
      var titleVal;
      if (typeof title === "string") titleVal = title;else if (typeof title === "function") titleVal = title(this.$createElement);else if (titleSlot) titleVal = titleSlot(null);
      return titleVal;
    }
  },
  render: function render() {
    var _wrapperClass;
    var h = arguments[0];
    var href = this.href,
      target = this.target,
      $scopedSlots = this.$scopedSlots,
      tAnchor = this.tAnchor;
    var children = $scopedSlots["default"],
      titleSlot = $scopedSlots.title;
    var title = this.renderTitle();
    var titleAttr = typeof title === "string" ? title : null;
    var isActive = tAnchor.active === href;
    var wrapperClass = (_wrapperClass = {}, _defineProperty(_wrapperClass, "".concat(this.componentName, "__item"), true), _defineProperty(_wrapperClass, this.commonStatusClassName.active, isActive), _wrapperClass);
    var titleClass = _defineProperty({}, "".concat(this.componentName, "__item-link"), true);
    return h("div", {
      "class": wrapperClass
    }, [h("a", {
      "attrs": {
        "href": href,
        "title": titleAttr,
        "target": target
      },
      "class": titleClass,
      "on": {
        "click": this.handleClick
      }
    }, [titleSlot ? titleSlot(null) : title]), children && children(null)]);
  }
});

export { _AnchorItem as default };
//# sourceMappingURL=anchor-item.js.map
