import { _ as _define_property } from "@swc/helpers/_/_define_property";
import { _ as _object_spread } from "@swc/helpers/_/_object_spread";
import { _ as _object_spread_props } from "@swc/helpers/_/_object_spread_props";
import { _ as _object_without_properties } from "@swc/helpers/_/_object_without_properties";
import React, { useCallback, useMemo } from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import { Loading } from "@nutui/icons-react-taro";
import { ComponentDefaults } from "../../utils/typings";
import { harmony } from "../../utils/taro/platform";
var prefixCls = 'nut-button';
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    color: '',
    type: 'default',
    size: 'normal',
    shape: 'round',
    fill: 'outline',
    loading: false,
    disabled: false,
    block: false,
    icon: null,
    rightIcon: null,
    onClick: function(e) {}
});
export var Button = /*#__PURE__*/ React.forwardRef(function(props, ref) {
    var _ref = _object_spread({}, defaultProps, props), color = _ref.color, shape = _ref.shape, fill = _ref.fill, loading = _ref.loading, disabled = _ref.disabled, type = _ref.type, size = _ref.size, block = _ref.block, icon = _ref.icon, rightIcon = _ref.rightIcon, children = _ref.children, className = _ref.className, style = _ref.style, // formType,
    nativeType = _ref.nativeType, description = _ref.description, onClick = _ref.onClick, rest = _object_without_properties(_ref, [
        "color",
        "shape",
        "fill",
        "loading",
        "disabled",
        "type",
        "size",
        "block",
        "icon",
        "rightIcon",
        "children",
        "className",
        "style",
        "nativeType",
        "description",
        "onClick"
    ]);
    var mappedSize = useMemo(function() {
        if (!size) return 'normal';
        var sizeMap = {
            '48': 'xlarge',
            '40': 'large',
            '32': 'normal',
            '28': 'small',
            '24': 'mini'
        };
        return sizeMap[size] || size;
    }, [
        size
    ]);
    var getStyle = useMemo(function() {
        var style = {};
        if (color) {
            if (props.fill === 'outline' || props.fill === 'dashed') {
                style.color = color;
                if (!(color === null || color === void 0 ? void 0 : color.includes('gradient'))) {
                    style.borderColor = color;
                }
            } else {
                style.color = 'var(--nutui-color-primary-text, #fff)';
                if (harmony()) {
                    style.backgroundColor = color;
                }
                style.background = color;
                style.borderColor = 'transparent';
            }
        }
        return style;
    }, [
        color,
        props.fill
    ]);
    var getContStyle = useMemo(function() {
        var style = {};
        if (props.color) {
            if (props.fill === 'outline' || props.fill === 'dashed') {
                style.color = color;
            } else {
                style.color = 'var(--nutui-color-primary-text, #fff)';
                style.background = 'transparent';
                style.borderColor = 'transparent';
            }
        }
        return style;
    }, [
        color,
        props.fill,
        props.color
    ]);
    var handleClick = useCallback(function(e) {
        if (!loading && !disabled && onClick) {
            onClick(e);
        }
    }, [
        loading,
        disabled,
        onClick
    ]);
    var _obj;
    var buttonClassNames = classNames(prefixCls, "".concat(prefixCls, "-").concat(type), (_obj = {}, _define_property(_obj, "".concat(prefixCls, "-").concat(type, "-solid"), type === 'primary' && !props.fill), _define_property(_obj, "".concat(prefixCls, "-").concat(fill), props.fill), _define_property(_obj, "".concat(prefixCls, "-").concat(type, "-").concat(fill), props.fill), _define_property(_obj, "".concat(prefixCls, "-").concat(mappedSize), mappedSize), _define_property(_obj, "".concat(prefixCls, "-has-desc"), !!description), _define_property(_obj, "".concat(prefixCls, "-").concat(shape), shape), _define_property(_obj, "".concat(prefixCls, "-block"), block), _define_property(_obj, "".concat(prefixCls, "-disabled"), disabled || loading), _define_property(_obj, "".concat(prefixCls, "-").concat(type).concat(props.fill ? "-".concat(fill) : '', "-disabled"), disabled || loading), _define_property(_obj, "".concat(prefixCls, "-loading"), loading), _define_property(_obj, "".concat(prefixCls, "-icononly"), !children), _obj), className);
    // if (getEnv() === 'WEB') {
    //   ;(rest as any).type = formType
    // }
    return (
        // <TaroButton>
        // @ts-ignore
        /*#__PURE__*/ (React.createElement(View, _object_spread_props(_object_spread({}, rest), {
            ref: ref,
            // formType={formType || nativeType}
            className: buttonClassNames,
            style: _object_spread({}, getStyle, style),
            ariaRole: "button",
            role: "button",
            ariaDisabled: disabled || loading,
            "aria-disabled": disabled || loading,
            ariaBusy: loading,
            "aria-busy": loading,
            onClick: function(e) {
                return handleClick(e);
            }
        }), /*#__PURE__*/ React.createElement(View, {
            className: "nut-button-wrap"
        }, loading && /*#__PURE__*/ React.createElement(Loading, {
            className: "nut-icon-loading",
            ariaHidden: true,
            "aria-hidden": true
        }), !loading && icon, children && /*#__PURE__*/ React.createElement(View, {
            className: classNames('nut-button-children', "nut-button-".concat(mappedSize, "-children"), "nut-button-".concat(type, "-children"), {
                'nut-button-text': icon || loading,
                'nut-button-text-right': rightIcon
            }),
            style: harmony() ? getContStyle : {}
        }, description ? /*#__PURE__*/ React.createElement(View, {
            className: "nut-button-title"
        }, children) : children, description && /*#__PURE__*/ React.createElement(View, {
            className: "nut-button-desc"
        }, description)), rightIcon)))
    );
});
Button.displayName = 'NutButton';
