"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importStar(require("react"));
const react_core_1 = require("@patternfly/react-core");
const exclamation_triangle_icon_1 = tslib_1.__importDefault(require("@patternfly/react-icons/dist/js/icons/exclamation-triangle-icon"));
const common_1 = require("../../../common");
const ClusterHostsTable_1 = tslib_1.__importDefault(require("../hosts/ClusterHostsTable"));
const utils_1 = require("./utils");
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
require("./HostInventoryExpandable.css");
const ExpandableSectionTitle = ({ hostsCount, icon, }) => (react_1.default.createElement("span", null,
    `Host inventory ${hostsCount > 0 ? `(${hostsCount})` : ''}`,
    icon && react_1.default.createElement("span", { className: "pf-v6-u-ml-sm" }, icon)));
const HostInventoryExpandable = ({ cluster }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const [isExpanded, setIsExpanded] = (0, react_1.useState)(false);
    const hosts = cluster.hosts || [];
    // eslint-disable-next-line @typescript-eslint/no-unsafe-call,@typescript-eslint/no-unsafe-assignment
    const mostSevereHostStatus = (0, utils_1.getMostSevereHostStatus)(hosts);
    const hostStatusDef = mostSevereHostStatus ? (0, common_1.hostStatus)(t)[mostSevereHostStatus] : null;
    const someHostHasTimeout = (0, utils_1.getHostsWithTimeout)(hosts);
    const warningIcon = (react_1.default.createElement(react_core_1.Icon, { size: "sm", status: "warning" },
        react_1.default.createElement(exclamation_triangle_icon_1.default, null)));
    return (react_1.default.createElement(react_core_1.ExpandableSection, { toggleContent: react_1.default.createElement(ExpandableSectionTitle, { hostsCount: hosts.length, icon: someHostHasTimeout ? warningIcon : hostStatusDef === null || hostStatusDef === void 0 ? void 0 : hostStatusDef.icon }), onToggle: () => setIsExpanded(!isExpanded), isExpanded: isExpanded, className: "host-inventory-expandable", id: "host-inventory-expandable" },
        react_1.default.createElement(ClusterHostsTable_1.default, { cluster: cluster, skipDisabled: true })));
};
exports.default = HostInventoryExpandable;
//# sourceMappingURL=HostInventoryExpandable.js.map