"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const tslib_1 = require("tslib");
const react_core_1 = require("@patternfly/react-core");
const React = tslib_1.__importStar(require("react"));
const common_1 = require("../../../common");
const toAssisted_1 = require("../helpers/toAssisted");
const status_1 = require("../helpers/status");
require("@patternfly/react-styles/css/utilities/Text/text.css");
const components_1 = require("../ClusterDeployment/components");
const use_translation_wrapper_1 = require("../../../common/hooks/use-translation-wrapper");
const ValidationsRunningAlert_1 = tslib_1.__importDefault(require("../common/ValidationsRunningAlert"));
const agentStatus_1 = require("../helpers/agentStatus");
const SpecSyncErrAlert_1 = tslib_1.__importDefault(require("../common/SpecSyncErrAlert"));
const AgentStatus = ({ agent, onApprove, onEditHostname, zIndex, wizardStepId, isDay2, additionalBMHInfo, }) => {
    var _a;
    const { t } = (0, use_translation_wrapper_1.useTranslation)();
    const [host] = (0, toAssisted_1.getAIHosts)([agent]);
    const editHostname = onEditHostname ? () => onEditHostname(agent) : undefined;
    const pendingApproval = !agent.spec.approved;
    const hostname = (0, common_1.getHostname)(host, ((_a = agent.status) === null || _a === void 0 ? void 0 : _a.inventory) || {});
    const agentStatuses = (0, agentStatus_1.agentStatus)(t);
    const status = wizardStepId
        ? (0, status_1.getWizardStepAgentStatus)(agent, wizardStepId, t)
        : (0, status_1.getAgentStatus)(agent, agentStatuses, false);
    const showValidationsRunning = isDay2 &&
        Object.values(status.validationsInfo).some((valInfo) => valInfo.some((v) => ['pending', 'error', 'failure'].includes(v.status)));
    return (React.createElement(common_1.HostStatus, Object.assign({ host: host, onEditHostname: editHostname, zIndex: zIndex, AdditionalNTPSourcesDialogToggleComponent: components_1.AdditionalNTPSourcesDialogToggle, autoCSR: true, additionalPopoverContent: status.status.key === 'specSyncErr' ? (React.createElement(react_core_1.StackItem, null,
            React.createElement(SpecSyncErrAlert_1.default, { agent: agent }))) : showValidationsRunning ? (React.createElement(react_core_1.StackItem, null,
            React.createElement(ValidationsRunningAlert_1.default, null))) : undefined, additionalBMHInfo: additionalBMHInfo }, status), pendingApproval && onApprove && (React.createElement(react_core_1.Popover, { "aria-label": t('ai:Approve host popover'), minWidth: "30rem", maxWidth: "50rem", headerContent: React.createElement("div", null, t('ai:Approve host to join infrastructure environment')), bodyContent: React.createElement(react_core_1.Stack, { hasGutter: true },
            React.createElement(react_core_1.StackItem, null, t('ai:Make sure that you expect and recognize the host before approving.')),
            React.createElement(react_core_1.StackItem, null, hostname && React.createElement(React.Fragment, null, t('ai:Hostname: {{hostname}}', { hostname })))), footerContent: 
        // eslint-disable-next-line @typescript-eslint/no-misused-promises
        React.createElement(react_core_1.Button, { variant: "link", onClick: () => onApprove(agent), isInline: true }, t('ai:Approve host')) },
        React.createElement(react_core_1.Button, { variant: "link", isInline: true, className: "pf-v6-u-font-size-xs" }, t('ai:Approve host'))))));
};
exports.default = AgentStatus;
//# sourceMappingURL=AgentStatus.js.map