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 { _ as _sliced_to_array } from "@swc/helpers/_/_sliced_to_array";
import React, { useEffect, useState } from "react";
import classNames from "classnames";
import { View, Image } from "@tarojs/components";
import { ComponentDefaults } from "../../utils/typings";
import { Button } from "../button/button";
var defaultStatus = {
    empty: 'https://storage.360buyimg.com/imgtools/30186cfda0-0d3eee40-c0ac-11ee-9382-9125782aa3b8.png',
    error: 'https://storage.360buyimg.com/imgtools/f3278d0ebb-0ce360c0-c0ac-11ee-8375-193101bb1a46.png',
    network: 'https://storage.360buyimg.com/imgtools/43c30f7e29-0d483d10-c0ac-11ee-bec4-eb4d2a09a51d.png'
};
var defaultProps = _object_spread_props(_object_spread({}, ComponentDefaults), {
    title: '',
    description: '',
    imageSize: '',
    size: 'base',
    status: 'empty',
    actions: []
});
var classPrefix = "nut-empty";
export var Empty = function(props) {
    var _$_object_spread = _object_spread({}, defaultProps, props), image = _$_object_spread.image, imageSize = _$_object_spread.imageSize, title = _$_object_spread.title, description = _$_object_spread.description, children = _$_object_spread.children, className = _$_object_spread.className, size = _$_object_spread.size, status = _$_object_spread.status, actions = _$_object_spread.actions, style = _$_object_spread.style;
    var _useState = _sliced_to_array(useState({}), 2), imgStyle = _useState[0], setImgStyle = _useState[1];
    var imageUrl = image || defaultStatus[status];
    var imageNode = typeof imageUrl === 'string' ? /*#__PURE__*/ React.createElement(Image, {
        style: {
            width: '100%',
            height: '100%'
        },
        src: imageUrl
    }) : imageUrl;
    useEffect(function() {
        setImgStyle(function() {
            if (!imageSize) {
                return {};
            }
            if (typeof imageSize !== 'number') {
                return {
                    width: imageSize,
                    height: imageSize
                };
            }
            return {
                width: "".concat(imageSize, "px"),
                height: "".concat(imageSize, "px")
            };
        });
    }, [
        imageSize
    ]);
    var cls = classNames(classPrefix, className);
    return /*#__PURE__*/ React.createElement(View, {
        className: cls,
        style: style
    }, /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-").concat(size),
        style: imgStyle
    }, imageNode), typeof title === 'string' && title ? /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-title")
    }, title) : title, typeof description === 'string' ? /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-description")
    }, description) : description, actions.length ? /*#__PURE__*/ React.createElement(View, {
        className: "".concat(classPrefix, "-actions-").concat(size)
    }, actions.map(function(action, index) {
        var text = action.text, rest = _object_without_properties(action, [
            "text"
        ]);
        return /*#__PURE__*/ React.createElement(View, {
            className: "".concat(classPrefix, "-action"),
            key: index
        }, /*#__PURE__*/ React.createElement(Button, rest, action === null || action === void 0 ? void 0 : action.text));
    })) : null, children);
};
Empty.displayName = 'NutEmpty';
