import { Check, CircleDashed, OctagonX } from "@sofa-design/icons";
import { ConfigProvider } from "antd";
import classNames from "classnames";
import React, { useContext } from "react";
import { LoadingEffect } from "../../Components/effects";
import { useTaskStyle } from "./style";
var StatusIcon = function(param) {
    var status = param.status;
    switch(status){
        case 'success':
            return /*#__PURE__*/ React.createElement(Check, {
                style: {
                    color: 'var(--color-green-control-fill-primary)'
                }
            });
        case 'error':
            return /*#__PURE__*/ React.createElement(OctagonX, {
                style: {
                    color: 'var(--color-red-control-fill-primary)'
                }
            });
        case 'loading':
            return /*#__PURE__*/ React.createElement(LoadingEffect, {
                style: {
                    color: 'var(--color-gray-text-disabled)',
                    transform: 'scale(1.1)'
                }
            });
        case 'pending':
        default:
            return /*#__PURE__*/ React.createElement(CircleDashed, {
                style: {
                    color: 'var(--color-gray-text-disabled)'
                }
            });
    }
};
export var TaskList = function(param) {
    var data = param.data, onItemClick = param.onItemClick;
    var getPrefixCls = useContext(ConfigProvider.ConfigContext).getPrefixCls;
    var prefixCls = getPrefixCls('agentic-workspace-task');
    var _useTaskStyle = useTaskStyle(prefixCls), wrapSSR = _useTaskStyle.wrapSSR, hashId = _useTaskStyle.hashId;
    var handleItemClick = function(item) {
        onItemClick === null || onItemClick === void 0 ? void 0 : onItemClick(item);
    };
    return wrapSSR(/*#__PURE__*/ React.createElement("div", {
        className: classNames(prefixCls, hashId),
        "data-testid": "task-list"
    }, data.items.map(function(item) {
        return /*#__PURE__*/ React.createElement("div", {
            key: item.key,
            className: classNames("".concat(prefixCls, "-item"), "".concat(prefixCls, "-item-").concat(item.status), hashId),
            role: onItemClick ? 'button' : undefined,
            tabIndex: onItemClick ? 0 : undefined,
            onClick: onItemClick ? function() {
                return handleItemClick(item);
            } : undefined,
            onKeyDown: onItemClick ? function(e) {
                if (e.key === 'Enter' || e.key === ' ') {
                    e.preventDefault();
                    handleItemClick(item);
                }
            } : undefined,
            style: {
                cursor: onItemClick ? 'pointer' : undefined
            }
        }, /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-status"), hashId)
        }, /*#__PURE__*/ React.createElement(StatusIcon, {
            status: item.status
        })), /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-content"), hashId)
        }, /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-title"), hashId)
        }, item.title), item.content && /*#__PURE__*/ React.createElement("div", {
            className: classNames("".concat(prefixCls, "-description"), hashId)
        }, item.content)));
    })));
};
