"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Animate", {
    enumerable: true,
    get: function() {
        return Animate;
    }
});
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 defaultProps = (0, _object_spread_props._)((0, _object_spread._)({}, _typings.ComponentDefaults), {
    type: 'shake',
    action: 'initial',
    loop: false,
    onClick: function onClick(event) {}
});
var classPrefix = 'nut-animate';
var Animate = function Animate(props) {
    var _$_object_spread = (0, _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 = (0, _sliced_to_array._)((0, _react.useState)(false), 2), clicked = _useState[0], setClicked = _useState[1];
    var _obj;
    var classes = (0, _classnames.default)((_obj = {
        'nut-ani-container': true
    }, (0, _define_property._)(_obj, "".concat(classPrefix, "-").concat(type), action === 'initial' || clicked), (0, _define_property._)(_obj, "loop", loop), _obj), className);
    var handleClick = function handleClick(event) {
        setClicked(true);
        // 如果不是无限循环，清除类名
        if (!loop) {
            setTimeout(function() {
                return setClicked(false);
            }, 1000);
        }
        onClick(event);
    };
    return /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: "nut-animate"
    }, /*#__PURE__*/ _react.default.createElement(_components.View, {
        className: classes,
        onClick: handleClick,
        style: style
    }, children));
};
Animate.displayName = 'NutAnimate';
