import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
import * as React from "react";
import { cn, readableFileSize } from "@utils";
import { ADPIcon } from "../adpIcon";
import { Progress } from "../progress";
import { Tooltip } from "../tooltip";
import { Button } from "../button";
import { statusCardVariants } from "./statusCardVariants";
export const StatusCard = React.forwardRef(({ fileEntry, uploadState, maxFileSize, disabled, acceptedExtensions, removeFile }, ref) => {
    var _a, _b, _c, _d, _e;
    const { file, state } = fileEntry;
    const { progress = null, helperText = "", error = false } = (_a = uploadState === null || uploadState === void 0 ? void 0 : uploadState[file.name]) !== null && _a !== void 0 ? _a : {};
    // Determine file state for icon and progress
    const fileState = React.useMemo(() => {
        const statusObj = uploadState === null || uploadState === void 0 ? void 0 : uploadState[file.name];
        if (!statusObj) {
            return state;
        }
        if (statusObj.error) {
            return "error";
        }
        if (statusObj.progress === 100) {
            return "success";
        }
        return state;
    }, [file.name, state, uploadState]);
    // Map primary to default variant
    const cardState = fileState === "primary"
        ? "default"
        : fileState;
    const iconTypes = {
        default: "document-upload",
        primary: "document-upload",
        success: "check-circle-filled",
        error: "times-circle-filled",
        warning: "danger"
    };
    const helperMessage = (_jsxs(_Fragment, { children: [!helperText && (_jsx(ADPIcon, { icon: !acceptedExtensions.includes(`.${(_b = file.name.split(".").pop()) === null || _b === void 0 ? void 0 : _b.toLowerCase()}`) || (maxFileSize && file.size > maxFileSize)
                    ? "alert-filled"
                    : error
                        ? "times-circle-filled"
                        : progress === 100
                            ? "check-circle-filled"
                            : "spinner", className: cn(!acceptedExtensions.includes(`.${(_c = file.name.split(".").pop()) === null || _c === void 0 ? void 0 : _c.toLowerCase()}`) || (maxFileSize && file.size > maxFileSize)
                    ? "text-warning-500 dark:text-warning-400"
                    : progress === 100
                        ? "text-success-400 dark:text-success-400"
                        : error
                            ? "text-error-400 dark:text-error-400"
                            : ""), size: "xs", spin: !acceptedExtensions.includes(`.${(_d = file.name.split(".").pop()) === null || _d === void 0 ? void 0 : _d.toLowerCase()}`) || (maxFileSize && file.size > maxFileSize)
                    ? false
                    : progress !== 100 })), _jsx("span", { children: !acceptedExtensions.includes(`.${(_e = file.name.split(".").pop()) === null || _e === void 0 ? void 0 : _e.toLowerCase()}`)
                    ? "The file type is not accepted"
                    : maxFileSize && file.size > maxFileSize
                        ? `The size of the file is more than ${readableFileSize(maxFileSize)}`
                        : progress === 100
                            ? "File uploaded successfully"
                            : error
                                ? helperText
                                : (progress !== null && progress !== void 0 ? progress : 0) < 100
                                    ? "Uploading file..."
                                    : helperText })] }));
    return (_jsxs("div", { ref: ref, children: [_jsxs("div", { className: cn(statusCardVariants({ state: cardState })), children: [_jsx("div", { className: cn("w-8 h-8 flex items-center justify-center rounded-full shrink-0 dark:bg-secondary-600", fileState === "primary" && "bg-primary-50", fileState === "success" && "bg-success-50", fileState === "warning" && "bg-warning-50", fileState === "error" && "bg-error-50"), children: _jsx(ADPIcon, { className: cn("cursor-pointer", {
                                "text-primary-500 dark:text-primary-400": fileState === "primary",
                                "text-success-500 dark:text-success-400": fileState === "success",
                                "text-error-500 dark:text-error-400": fileState === "error",
                                "text-warning-500 dark:text-warning-400": fileState === "warning",
                                "text-secondary-300 cursor-not-allowed hover:text-secondary-300 dark:text-secondary-400": disabled
                            }), size: "xs", icon: iconTypes[fileState] }) }), _jsxs("div", { className: "flex flex-col w-full me-4 md:me-8", children: [_jsx("div", { className: "flex gap-1 text-sm mb-1", children: _jsx(Tooltip, { title: "File Name", trigger: _jsx("span", { className: "text-sm font-medium text-secondary-500 dark:text-secondary-50", children: file.name.length > 30
                                            ? `${file.name.substring(0, 30)}...`
                                            : file.name }), children: file.name }) }), fileState !== "error" && (!maxFileSize || file.size <= maxFileSize) && fileState !== "warning" && (_jsx(Progress, { variant: "linear", value: progress !== null && progress !== void 0 ? progress : 0, color: error
                                    ? "error"
                                    : state === "warning"
                                        ? "primary"
                                        : progress === 100
                                            ? "success"
                                            : "primary", showPercentage: true }))] }), _jsx(Button, { variant: "text", prefixIcon: "cross", size: "xs", className: "text-gray-800 dark:text-gray-300", title: `Remove ${file.name}`, onClick: () => removeFile(file.name) })] }), _jsx("p", { className: "text-secondary-400 text-sm mt-2 flex items-center gap-2 dark:text-secondary-50", children: helperMessage })] }));
});
StatusCard.displayName = "StatusCard";
//# sourceMappingURL=statusCard.js.map