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