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 _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React, { useMemo, useState } from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import { ComponentDefaults } from "../../utils/typings";
import { harmony } from "../../utils/taro/platform";
import { getIcon } from "./utils";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    icon: null,
    onClick: function(value) {}
});
var classPrefix = 'nut-hoverbutton-item';
var isHarmony = harmony();
export var HoverButtonItem = function(props) {
    var _$_object_spread = _object_spread({}, defaultProps, props), className = _$_object_spread.className, style = _$_object_spread.style, icon = _$_object_spread.icon, onClick = _$_object_spread.onClick, children = _$_object_spread.children;
    var _useState = _sliced_to_array(useState(false), 2), isTouchStart = _useState[0], setTouchStart = _useState[1];
    // @TODO 待添加暗黑模式及样式变量功能
    var nativeProps = useMemo(function() {
        return isHarmony ? {
            color: isTouchStart ? 'var(--nutui-color-text, #595959)' : 'var(--nutui-color-title, #1A1A1A)'
        } : {};
    }, [
        isTouchStart
    ]);
    var handleClick = function(event) {
        onClick && onClick(event);
    };
    var handleActiveStart = function(event) {
        isHarmony && setTouchStart(true);
    };
    var handleActiveEnd = function(event) {
        isHarmony && setTouchStart(false);
    };
    var renderBody = function() {
        if (icon && !children) return /*#__PURE__*/ React.createElement(View, {
            className: "".concat(classPrefix, "-icon")
        }, getIcon(icon));
        if (icon && children) {
            return /*#__PURE__*/ React.createElement(React.Fragment, null, /*#__PURE__*/ React.createElement(View, {
                className: classNames(_define_property({}, "".concat(classPrefix, "-text-icon"), true))
            }), getIcon(icon), /*#__PURE__*/ React.createElement(View, {
                className: classNames(_define_property({}, "".concat(classPrefix, "-text"), true))
            }, children));
        }
    };
    var _obj;
    return /*#__PURE__*/ React.createElement(View, {
        className: classNames([
            "".concat(classPrefix, "-container"),
            className
        ], (_obj = {}, _define_property(_obj, "".concat(classPrefix, "-container-active"), isHarmony && isTouchStart), _define_property(_obj, "".concat(classPrefix, "-container-harmony"), isHarmony), _define_property(_obj, "".concat(classPrefix, "-container-icontext"), icon && children), _obj)),
        style: style,
        onTouchStart: handleActiveStart,
        onTouchEnd: handleActiveEnd,
        onTouchCancel: handleActiveEnd,
        onClick: handleClick
    }, renderBody());
};
HoverButtonItem.displayName = 'NutHoverButtonItem';
