import { defineComponent as B, useSlots as W, ref as z, computed as o, openBlock as L, createBlock as w, unref as a, mergeProps as P, createSlots as S, renderList as T, withCtx as _, renderSlot as $, normalizeProps as x, guardReactiveProps as M } from "vue";
import { Button as N } from "@aplus-frontend/antdv";
import { wait as A } from "@aplus-frontend/utils";
import { omit as D } from "lodash-unified";
import "../config-provider/index.mjs";
import I from "./style/index.mjs";
import { transferOpacityColor as O, isAsynchronous as j } from "./utils/index.mjs";
import { useNamespace as R } from "../config-provider/hooks/use-namespace.mjs";
const q = 72, E = 300, X = /* @__PURE__ */ B({
  __name: "ap-button",
  props: {
    prefixCls: {},
    htmlType: {},
    shape: {},
    size: {},
    loading: { type: [Boolean, Object], default: void 0 },
    disabled: { type: Boolean },
    ghost: { type: Boolean },
    block: { type: Boolean },
    danger: { type: Boolean },
    icon: {},
    href: {},
    target: {},
    title: {},
    onMousedown: {},
    autoInsertSpace: { type: Boolean },
    iconPosition: {},
    color: {},
    variant: {},
    type: { default: "default" },
    borderLinkColor: {},
    minWidth: { type: [Boolean, Number, String], default: !1 },
    lazy: { type: [Boolean, Number], default: !0 },
    onClick: {}
  },
  setup(f) {
    const m = W(), e = f, { b: i } = R("ap-action-button"), y = I("ap-action-button"), l = z(!1), b = o(
      () => e.borderLinkColor || "var(--ap-button-border-link-color)"
    ), s = o(
      () => e.type === "borderLink" && !e.disabled ? b.value : void 0
    ), u = o(
      () => O(s.value)
    ), h = o(() => e.minWidth === !0 ? `${q}px` : typeof e.minWidth == "number" ? `${e.minWidth}px` : typeof e.minWidth == "string" ? e.minWidth : void 0), v = o(
      () => (e.type === "borderLink" ? "default" : e.type) || "default"
    ), c = o(() => e.loading ?? l.value ?? !1), d = o(() => e.lazy === !0 ? E : typeof e.lazy == "number" && e.lazy >= 0 ? e.lazy : 0);
    function k() {
      const t = D(e, [
        "type",
        "borderLinkColor",
        "minWidth",
        "onClick",
        "loading"
      ]);
      return t ? {
        ...t,
        type: v.value,
        onclick: g
      } : {};
    }
    async function g(t) {
      if (c.value) return;
      const r = j(e.onClick, t), p = Date.now();
      try {
        r && (l.value = !0, await r);
      } finally {
        if (r) {
          const n = Date.now() - p;
          n < d.value && await A(d.value - n), l.value = !1;
        }
      }
    }
    return (t, r) => (L(), w(a(N), P({
      class: {
        [a(i)()]: !0,
        [`${a(i)()}-border-link`]: u.value,
        [`${a(y)}`]: !0
      }
    }, {
      ...t.$attrs,
      ...k()
    }, {
      style: {
        color: s.value,
        minWidth: h.value,
        "--button-border-color": u.value
      },
      loading: c.value
    }), S({ _: 2 }, [
      T(m, (p, n) => ({
        name: n,
        fn: _((C) => [
          $(t.$slots, n, x(M(C || {})))
        ])
      }))
    ]), 1040, ["class", "style", "loading"]));
  }
});
export {
  X as default
};
