import { defineComponent, inject, useAttrs, createBlock, openBlock, unref, mergeProps, withCtx, createElementBlock, createCommentVNode, createElementVNode, renderSlot, resolveDynamicComponent, createVNode } from "vue";
import "../config-provider/index.mjs";
import { defaultSize } from "../_utils/global.mjs";
import { IconLoading, IconLinkArrow } from "../_utils/icons.mjs";
import HtmlTag from "../_components/html-tag.mjs";
import { linkProps } from "./types.mjs";
import { configProviderInjectKey } from "../config-provider/provide.mjs";
const _hoisted_1 = {
  key: 0,
  class: "o-link-prefix"
};
const _hoisted_2 = { class: "o-link-main" };
const _hoisted_3 = {
  key: 0,
  class: "o-link-label"
};
const _hoisted_4 = {
  key: 1,
  class: "o-link-suffix"
};
const _sfc_main = /* @__PURE__ */ defineComponent({
  __name: "OLink",
  props: linkProps,
  emits: ["click"],
  setup(__props, { emit: __emit }) {
    const props = __props;
    const configProvider = inject(configProviderInjectKey, {});
    const $attr = useAttrs();
    const emits = __emit;
    const onClick = (e) => {
      var _a;
      if (props.disabled || props.loading) {
        e.preventDefault();
        return;
      }
      emits("click", e);
      if (props.global) {
        (_a = configProvider.link) == null ? void 0 : _a.click(e, props, $attr);
      }
    };
    return (_ctx, _cache) => {
      return openBlock(), createBlock(unref(HtmlTag), mergeProps({
        tag: props.tag,
        class: ["o-link", [
          {
            "o-link-disabled": props.disabled,
            "o-link-hover-bg": props.hoverBg,
            "o-link-hover-underline": props.hoverUnderline
          },
          `o-link-${props.color}`,
          `o-link-${props.size || unref(defaultSize)}`
        ]],
        href: props.href,
        target: props.target
      }, _ctx.$attrs, { onClick }), {
        default: withCtx(() => [
          _ctx.$slots.icon || props.icon || props.loading ? (openBlock(), createElementBlock("span", _hoisted_1, [
            props.loading ? (openBlock(), createBlock(unref(IconLoading), {
              key: 0,
              class: "o-rotating"
            })) : renderSlot(_ctx.$slots, "icon", { key: 1 }, () => [
              (openBlock(), createBlock(resolveDynamicComponent(props.icon)))
            ])
          ])) : createCommentVNode("v-if", true),
          createElementVNode("span", _hoisted_2, [
            props.hoverUnderline ? (openBlock(), createElementBlock("span", _hoisted_3, [
              renderSlot(_ctx.$slots, "default")
            ])) : renderSlot(_ctx.$slots, "default", { key: 1 })
          ]),
          _ctx.$slots.suffix || props.suffix ? (openBlock(), createElementBlock("span", _hoisted_4, [
            renderSlot(_ctx.$slots, "suffix", {}, () => [
              createVNode(unref(IconLinkArrow), { class: "o-link-icon-arrow" })
            ])
          ])) : createCommentVNode("v-if", true)
        ]),
        _: 3
        /* FORWARDED */
      }, 16, ["tag", "href", "target", "class"]);
    };
  }
});
export {
  _sfc_main as default
};
