import { defineComponent, ref, computed, resolveComponent, createBlock, createElementBlock, openBlock, withCtx, createElementVNode, normalizeStyle, unref, normalizeClass, createCommentVNode, renderSlot, createTextVNode, toDisplayString, createVNode } from 'vue';
import '../../../utils/index.mjs';
import { linkColorMap, linkProps } from './link.mjs';
import { createNamespace } from '../../../utils/create-namespace.mjs';
import { addUnit } from '../../../utils/add-unit.mjs';

"use strict";
const _hoisted_1 = { style: { "width": "240px", "height": "135px", "overflow": "hidden", "background": "#f0f2f5", "display": "flex", "align-items": "center", "justify-content": "center", "position": "relative" } };
const _hoisted_2 = ["src"];
const _hoisted_3 = ["href", "target"];
const _hoisted_4 = ["href", "target"];
var _sfc_main = /* @__PURE__ */ defineComponent({
  ...{
    name: "LlLink"
  },
  __name: "link",
  props: linkProps,
  emits: ["click"],
  setup(__props, { emit: __emit }) {
    const bem = createNamespace("link");
    const props = __props;
    const emits = __emit;
    const isImgLoaded = ref(false);
    const computedHref = computed(() => {
      if (props.disabled) return "javascript:;";
      return props.href || "javascript:;";
    });
    const computedLinkColor = computed(() => {
      return props.typeChange ? {
        "--a-color": linkColorMap[props.colorType]?.["link"] || props.linkColor || "#005ce5",
        "--a-link-color": linkColorMap[props.colorType]?.["link"] || props.linkColor,
        "--a-hover-color": linkColorMap[props.colorType]?.["hover"] || props.hoverColor,
        "--a-active-color": linkColorMap[props.colorType]?.["active"] || props.activeColor
      } : {
        "--a-color": linkColorMap[props.colorType]?.["link"] || props.linkColor || "#005ce5"
      };
    });
    const handleClick = (event) => {
      if (props.disabled || !props.href) {
        event.preventDefault();
        return;
      }
      emits("click", event);
    };
    const handleImgLoad = () => {
      isImgLoaded.value = true;
    };
    return (_ctx, _cache) => {
      const _component_a_spin = resolveComponent("a-spin");
      const _component_ll_icon = resolveComponent("ll-icon");
      const _component_ll_tooltip = resolveComponent("ll-tooltip");
      return props.preview && props.href && !props.disabled ? (openBlock(), createBlock(_component_ll_tooltip, {
        key: 0,
        placement: "top",
        "max-width": 600,
        "overlay-style": { maxWidth: "none" },
        "is-white-bg": "",
        "container-style": { display: "inline-block" }
      }, {
        title: withCtx(() => [
          createElementVNode("div", _hoisted_1, [
            createVNode(_component_a_spin, {
              spinning: !isImgLoaded.value
            }, {
              default: withCtx(() => [
                createElementVNode("img", {
                  src: `https://s0.wp.com/mshots/v1/${encodeURIComponent(
                    props.href
                  )}?w=480&h=270`,
                  style: { "width": "100%", "height": "100%", "object-fit": "cover" },
                  alt: "Link Preview",
                  onLoad: handleImgLoad
                }, null, 40, _hoisted_2)
              ]),
              _: 1
              /* STABLE */
            }, 8, ["spinning"])
          ])
        ]),
        default: withCtx(() => [
          createElementVNode("a", {
            class: normalizeClass([
              unref(bem).b(),
              props.disabled ? unref(bem).is("disabled") : "",
              props.colorType ? unref(bem).is(props.colorType) : "",
              props.typeChange ? unref(bem).is("type-change") : "",
              props.underlineStatus === "fixed" ? unref(bem).is("fixed-underline") : props.underlineStatus === "hover" ? unref(bem).is("underline") : "",
              ,
            ]),
            style: normalizeStyle({ gap: unref(addUnit)(props.gap), ...computedLinkColor.value }),
            href: computedHref.value,
            target: props.target,
            onClick: handleClick
          }, [
            props.prefixIcon ? (openBlock(), createBlock(_component_ll_icon, {
              key: 0,
              "icon-name": `icon-${props.prefixIcon}`,
              size: props.iconSize,
              class: normalizeClass(unref(bem).e("prefix-icon"))
            }, null, 8, ["icon-name", "size", "class"])) : createCommentVNode("v-if", true),
            createElementVNode(
              "span",
              {
                class: normalizeClass(unref(bem).e("text"))
              },
              [
                renderSlot(_ctx.$slots, "default", {}, () => [
                  createTextVNode(
                    toDisplayString(props.value),
                    1
                    /* TEXT */
                  )
                ])
              ],
              2
              /* CLASS */
            ),
            props.suffixIcon ? (openBlock(), createBlock(_component_ll_icon, {
              key: 1,
              "icon-name": `icon-${props.suffixIcon}`,
              size: props.iconSize,
              class: normalizeClass(unref(bem).e("suffix-icon"))
            }, null, 8, ["icon-name", "size", "class"])) : createCommentVNode("v-if", true)
          ], 14, _hoisted_3)
        ]),
        _: 3
        /* FORWARDED */
      })) : (openBlock(), createElementBlock("a", {
        key: 1,
        class: normalizeClass([
          unref(bem).b(),
          props.disabled ? unref(bem).is("disabled") : "",
          props.typeChange ? unref(bem).is("type-change") : "",
          props.underlineStatus === "fixed" ? unref(bem).is("fixed-underline") : props.underlineStatus === "hover" ? unref(bem).is("underline") : ""
        ]),
        style: normalizeStyle({ gap: unref(addUnit)(props.gap), ...computedLinkColor.value }),
        href: computedHref.value,
        target: props.target,
        onClick: handleClick
      }, [
        props.prefixIcon ? (openBlock(), createBlock(_component_ll_icon, {
          key: 0,
          "icon-name": `icon-${props.prefixIcon}`,
          size: props.iconSize,
          class: normalizeClass(unref(bem).e("prefix-icon"))
        }, null, 8, ["icon-name", "size", "class"])) : createCommentVNode("v-if", true),
        createElementVNode(
          "span",
          {
            class: normalizeClass(unref(bem).e("text"))
          },
          [
            renderSlot(_ctx.$slots, "default", {}, () => [
              createTextVNode(
                toDisplayString(props.value),
                1
                /* TEXT */
              )
            ])
          ],
          2
          /* CLASS */
        ),
        props.suffixIcon ? (openBlock(), createBlock(_component_ll_icon, {
          key: 1,
          "icon-name": `icon-${props.suffixIcon}`,
          size: props.iconSize,
          class: normalizeClass(unref(bem).e("suffix-icon"))
        }, null, 8, ["icon-name", "size", "class"])) : createCommentVNode("v-if", true)
      ], 14, _hoisted_4));
    };
  }
});

export { _sfc_main as default };
//# sourceMappingURL=link.vue2.mjs.map
