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, { useState } from "react";
import classNames from "classnames";
import { View } from "@tarojs/components";
import { ComponentDefaults } from "../../utils/typings";
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    type: 'shake',
    action: 'initial',
    loop: false,
    onClick: function(event) {}
});
var classPrefix = 'nut-animate';
export var Animate = function(props) {
    var _$_object_spread = _object_spread({}, defaultProps, props), className = _$_object_spread.className, type = _$_object_spread.type, action = _$_object_spread.action, loop = _$_object_spread.loop, onClick = _$_object_spread.onClick, children = _$_object_spread.children, style = _$_object_spread.style;
    var _useState = _sliced_to_array(useState(false), 2), clicked = _useState[0], setClicked = _useState[1];
    var _obj;
    var classes = classNames((_obj = {
        'nut-ani-container': true
    }, _define_property(_obj, "".concat(classPrefix, "-").concat(type), action === 'initial' || clicked), _define_property(_obj, "loop", loop), _obj), className);
    var handleClick = function(event) {
        setClicked(true);
        // 如果不是无限循环，清除类名
        if (!loop) {
            setTimeout(function() {
                return setClicked(false);
            }, 1000);
        }
        onClick(event);
    };
    return /*#__PURE__*/ React.createElement(View, {
        className: "nut-animate"
    }, /*#__PURE__*/ React.createElement(View, {
        className: classes,
        onClick: handleClick,
        style: style
    }, children));
};
Animate.displayName = 'NutAnimate';
