"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.selectClusterNames = exports.selectClusterTableRows = exports.getClusterTableStatusCell = exports.selectClustersUIState = void 0;
const tslib_1 = require("tslib");
const react_1 = tslib_1.__importDefault(require("react"));
const toolkit_1 = require("@reduxjs/toolkit");
const react_router_dom_v5_compat_1 = require("react-router-dom-v5-compat");
const common_1 = require("../../../../common");
const ClusterStatus_1 = tslib_1.__importStar(require("../../../components/clusters/ClusterStatus"));
const selectClusters = (state) => state.clusters.data.filter((c) => c.kind !== 'DisconnectedCluster');
const clustersUIState = (state) => state.clusters.uiState;
exports.selectClustersUIState = (0, toolkit_1.createSelector)([selectClusters, clustersUIState], (clusters, uiState) => {
    const { LOADED, EMPTY } = common_1.ResourceUIState;
    return !clusters.length && uiState === LOADED ? EMPTY : uiState;
});
const clusterToClusterTableRow = (cluster, t) => {
    const { id, name = '', baseDnsDomain, createdAt } = cluster;
    const dateTimeCell = (0, common_1.getDateTimeCell)(createdAt);
    const versionText = (0, common_1.getOpenshiftVersionText)({
        openshiftVersion: cluster.openshiftVersion || '',
        cpuArchitecture: cluster.cpuArchitecture,
        withMultiText: true,
    });
    const props = {
        name,
        id,
        baseDnsDomain,
    };
    return {
        cells: [
            {
                title: (react_1.default.createElement(react_router_dom_v5_compat_1.Link, { key: name, to: id, id: `cluster-link-${id}` }, name)),
                props: { 'data-testid': `cluster-name-${name}` },
                sortableValue: name,
            },
            {
                title: baseDnsDomain || common_1.DASH,
                props: { 'data-testid': `cluster-base-domain-${name}` },
                sortableValue: baseDnsDomain,
            },
            {
                title: versionText,
                props: { 'data-testid': `cluster-version-${name}` },
                sortableValue: versionText,
            },
            {
                title: react_1.default.createElement(ClusterStatus_1.default, { status: cluster.status }),
                props: { 'data-testid': `cluster-status-${name}` },
                sortableValue: (0, ClusterStatus_1.getClusterStatusText)(t, cluster.status),
            },
            {
                title: react_1.default.createElement(common_1.HostsCount, { cluster: cluster }),
                props: { 'data-testid': `cluster-hosts-count-${name}` },
                sortableValue: 'enabledHostCount' in cluster ? (0, common_1.getEnabledHostCount)(cluster) : (0, common_1.getTotalHostCount)(cluster),
            },
            {
                title: dateTimeCell.title,
                props: { 'data-testid': `cluster-created-time-${name}` },
                sortableValue: dateTimeCell.sortableValue,
            },
        ],
        props,
    };
};
const getClusterTableStatusCell = (rowData) => { var _a; return (_a = rowData === null || rowData === void 0 ? void 0 : rowData.cells) === null || _a === void 0 ? void 0 : _a[3]; };
exports.getClusterTableStatusCell = getClusterTableStatusCell;
const selectClusterTableRows = (t) => {
    return (0, toolkit_1.createSelector)(selectClusters, (clusters) => clusters.map((c) => clusterToClusterTableRow(c, t)));
};
exports.selectClusterTableRows = selectClusterTableRows;
exports.selectClusterNames = (0, toolkit_1.createSelector)(selectClusters, (clusters) => clusters.map((c) => c.name));
//# sourceMappingURL=selectors.js.map