"use strict";
Object.defineProperty(exports, "__esModule", {
    value: true
});
Object.defineProperty(exports, "Preview", {
    enumerable: true,
    get: function() {
        return Preview;
    }
});
var _interop_require_default = require("@swc/helpers/_/_interop_require_default");
var _react = /*#__PURE__*/ _interop_require_default._(require("react"));
var _iconsreacttaro = require("@nutui/icons-react-taro");
var _components = require("@tarojs/components");
var _image = require("../image/image");
var _progress = require("../progress/progress");
var Preview = function Preview(param) {
    var fileList = param.fileList, previewType = param.previewType, deletable = param.deletable, onDeleteItem = param.onDeleteItem, handleItemClick = param.handleItemClick, previewUrl = param.previewUrl, deleteIcon = param.deleteIcon, children = param.children;
    var renderIcon = function renderIcon(item) {
        if (item.status === 'error') {
            return item.failIcon || /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.Failure, {
                color: "#fff"
            });
        }
        return item.loadingIcon || /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.Loading, {
            className: "nut-icon-loading",
            color: "#fff"
        });
    };
    return /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, fileList.length !== 0 && fileList.map(function(item, index) {
        var _item_status = item.status, status = _item_status === void 0 ? 'success' : _item_status, _item_uid = item.uid, uid = _item_uid === void 0 ? index : _item_uid, url = item.url, _item_message = item.message, message = _item_message === void 0 ? '' : _item_message, _item_name = item.name, name = _item_name === void 0 ? '' : _item_name, _item_type = item.type, type = _item_type === void 0 ? 'image' : _item_type;
        return /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "nut-uploader-preview ".concat(previewType),
            key: uid
        }, previewType === 'picture' && !children && deletable && /*#__PURE__*/ _react.default.createElement(_components.View, {
            onClick: function onClick() {
                return onDeleteItem(item, index);
            },
            className: "close"
        }, deleteIcon), previewType === 'picture' && !children && /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "nut-uploader-preview-img"
        }, status === 'ready' ? /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "nut-uploader-preview-progress"
        }, /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "nut-uploader-preview-progress-msg"
        }, message)) : status !== 'success' && /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "nut-uploader-preview-progress",
            style: {
                zIndex: 10
            }
        }, renderIcon(item), /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "nut-uploader-preview-progress-msg"
        }, message)), type.includes('image') ? /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, url && /*#__PURE__*/ _react.default.createElement(_image.Image, {
            className: "nut-uploader-preview-img-c",
            src: url,
            mode: "aspectFill",
            onClick: function onClick() {
                return handleItemClick(item, index);
            }
        })) : /*#__PURE__*/ _react.default.createElement(_react.default.Fragment, null, previewUrl ? /*#__PURE__*/ _react.default.createElement(_image.Image, {
            className: "nut-uploader-preview-img-c",
            src: previewUrl,
            onClick: function onClick() {
                return handleItemClick(item, index);
            }
        }) : /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "nut-uploader-preview-img-file"
        }, /*#__PURE__*/ _react.default.createElement(_components.View, {
            onClick: function onClick() {
                return handleItemClick(item, index);
            },
            className: "nut-uploader-preview-img-file-name"
        }, /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.Link, {
            color: "#808080"
        }), /*#__PURE__*/ _react.default.createElement("span", null, "\xa0", name)))), status === 'success' && name ? /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "tips"
        }, name) : null), previewType === 'list' && /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "nut-uploader-preview-list"
        }, /*#__PURE__*/ _react.default.createElement(_components.View, {
            className: "nut-uploader-preview-img-file-name ".concat(status),
            onClick: function onClick() {
                return handleItemClick(item, index);
            }
        }, /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.Link, null), /*#__PURE__*/ _react.default.createElement("span", {
            className: "nut-uploader-preview-img-file-name ".concat(status)
        }, "\xa0", name)), deletable && /*#__PURE__*/ _react.default.createElement(_iconsreacttaro.Del, {
            color: "#808080",
            className: "nut-uploader-preview-img-file-del",
            onClick: function onClick() {
                return onDeleteItem(item, index);
            }
        }), item.status === 'uploading' && item.percentage && /*#__PURE__*/ _react.default.createElement(_progress.Progress, {
            percent: item.percentage,
            color: "linear-gradient(270deg, rgba(18,126,255,1) 0%,rgba(32,147,255,1) 32.815625%,rgba(13,242,204,1) 100%)",
            showText: false
        })));
    }));
};
