"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ExpandComponent = ExpandComponent;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const react_core_1 = require("@patternfly/react-core");
const common_1 = require("../../../common");
const StorageUtils_1 = require("../../../common/components/storage/StorageUtils");
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const usePagination_1 = require("../../../common/components/hosts/usePagination");
const StorageTable_1 = tslib_1.__importDefault(require("../../../common/components/storage/StorageTable"));
const StorageDetail_1 = tslib_1.__importDefault(require("../../../common/components/storage/StorageDetail"));
const StorageAlerts_1 = tslib_1.__importDefault(require("./StorageAlerts"));
const use_hosts_table_1 = require("./use-hosts-table");
const HostsTableDetailContext_1 = require("../../../common/components/hosts/HostsTableDetailContext");
const HardwareStatus_1 = require("./HardwareStatus");
const ClusterWizardContext_1 = require("../clusterWizard/ClusterWizardContext");
function ExpandComponent({ obj: host }) {
    const { onDiskRole, canEditDisks, updateDiskSkipFormatting } = (0, HostsTableDetailContext_1.useHostsTableDetailContext)();
    return (react_1.default.createElement(StorageDetail_1.default, { key: host.id, host: host, onDiskRole: onDiskRole, canEditDisks: canEditDisks, updateDiskSkipFormatting: updateDiskSkipFormatting }));
}
const HostsStorageTable = ({ cluster }) => {
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const _a = (0, use_hosts_table_1.useHostsTable)(cluster), { onEditHost, actionChecks, onDiskRole, actionResolver, updateDiskSkipFormatting } = _a, modalProps = tslib_1.__rest(_a, ["onEditHost", "actionChecks", "onDiskRole", "actionResolver", "updateDiskSkipFormatting"]);
    const { wizardPerPage, setWizardPerPage } = (0, ClusterWizardContext_1.useClusterWizardContext)();
    const content = react_1.default.useMemo(() => {
        const columns = [
            (0, common_1.hostnameColumn)(t, onEditHost, undefined, actionChecks.canEditHostname),
            (0, common_1.roleColumn)(t, undefined, undefined, (0, common_1.selectSchedulableMasters)(cluster)),
            (0, HardwareStatus_1.hardwareStatusColumn)({}),
            (0, common_1.disksColumn)(t),
            StorageUtils_1.numberOfDisksColumn,
        ];
        if ((0, common_1.hasEnabledOperators)(cluster.monitoredOperators, common_1.OPERATOR_NAME_ODF)) {
            const excludeODfForMasters = !(0, common_1.isCompact)(cluster);
            columns.push((0, StorageUtils_1.odfUsageColumn)(excludeODfForMasters));
        }
        columns.push((0, common_1.countColumn)(cluster));
        return columns;
    }, [actionChecks.canEditHostname, cluster, onEditHost, t]);
    const hosts = cluster.hosts || [];
    const paginationProps = (0, usePagination_1.usePagination)(hosts.length, wizardPerPage, setWizardPerPage);
    return (react_1.default.createElement(react_1.default.Fragment, null,
        react_1.default.createElement(react_core_1.Stack, { hasGutter: true },
            react_1.default.createElement(react_core_1.StackItem, null,
                react_1.default.createElement(HostsTableDetailContext_1.HostsTableDetailContextProvider, { canEditDisks: actionChecks.canEditDisks, onDiskRole: onDiskRole, updateDiskSkipFormatting: updateDiskSkipFormatting },
                    react_1.default.createElement(StorageTable_1.default, Object.assign({ testId: "storage-table", hosts: hosts, content: content, actionResolver: actionResolver, ExpandComponent: ExpandComponent }, paginationProps)))),
            react_1.default.createElement(react_core_1.StackItem, null,
                react_1.default.createElement(StorageAlerts_1.default, { cluster: cluster }))),
        react_1.default.createElement(use_hosts_table_1.HostsTableModals, Object.assign({ cluster: cluster }, modalProps))));
};
exports.default = HostsStorageTable;
//# sourceMappingURL=HostsStorageTable.js.map