import React from "react";
import { SpanStatus } from "../../../Models/AnalyticsModels/Span";
import LogSeverity from "../../../Types/Log/LogSeverity";
const SPAN_STATUS_LABEL = {
    [SpanStatus.Unset]: "Unset",
    [SpanStatus.Ok]: "Ok",
    [SpanStatus.Error]: "Error",
};
const LOG_SEVERITY_ORDER = [
    LogSeverity.Fatal,
    LogSeverity.Error,
    LogSeverity.Warning,
    LogSeverity.Information,
    LogSeverity.Debug,
    LogSeverity.Trace,
    LogSeverity.Unspecified,
];
const SPAN_STATUS_ORDER = [
    SpanStatus.Error,
    SpanStatus.Ok,
    SpanStatus.Unset,
];
const formatDays = (days) => {
    return days === 1 ? "1 day" : `${days} days`;
};
const pickPositive = (value) => {
    return typeof value === "number" && value > 0 ? value : null;
};
const PillarCard = (props) => {
    const { title, hint, defaultDays, overrides } = props.pillar;
    const hasDefault = defaultDays !== null;
    const hasOverrides = overrides.length > 0;
    const isCustomized = hasDefault || hasOverrides;
    return (React.createElement("div", { className: "rounded-lg border border-gray-200 dark:border-slate-700 bg-white dark:bg-slate-900 p-4" },
        React.createElement("div", { className: "flex items-start justify-between gap-3" },
            React.createElement("div", { className: "min-w-0" },
                React.createElement("div", { className: "flex items-center gap-2" },
                    React.createElement("h4", { className: "text-sm font-semibold text-gray-900 dark:text-slate-100" }, title),
                    React.createElement("span", { className: isCustomized
                            ? "inline-flex items-center rounded-full bg-indigo-50 dark:bg-indigo-950/40 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-indigo-700 dark:text-indigo-300 border border-indigo-100 dark:border-indigo-900"
                            : "inline-flex items-center rounded-full bg-gray-100 dark:bg-slate-800 px-2 py-0.5 text-[10px] font-semibold uppercase tracking-wide text-gray-500 dark:text-slate-400 border border-gray-200 dark:border-slate-700" }, isCustomized ? "Custom" : "Default")),
                React.createElement("p", { className: "mt-1 text-xs text-gray-500 dark:text-slate-400" }, hint)),
            React.createElement("div", { className: "text-right whitespace-nowrap shrink-0" }, hasDefault ? (React.createElement(React.Fragment, null,
                React.createElement("div", { className: "text-lg font-semibold text-gray-900 dark:text-slate-100 leading-tight" },
                    defaultDays,
                    " ",
                    React.createElement("span", { className: "text-sm font-normal text-gray-500 dark:text-slate-400" }, defaultDays === 1 ? "day" : "days")),
                React.createElement("div", { className: "text-[10px] uppercase tracking-wide text-gray-400 dark:text-slate-500" }, "Default"))) : (React.createElement("div", { className: "text-xs italic text-gray-400 dark:text-slate-500" },
                "Uses default",
                React.createElement("br", null),
                "retention")))),
        hasOverrides ? (React.createElement("div", { className: "mt-3 border-t border-gray-100 dark:border-slate-800 pt-3" },
            React.createElement("p", { className: "text-[10px] font-semibold uppercase tracking-wide text-gray-400 dark:text-slate-500 mb-2" }, "Specific overrides"),
            React.createElement("div", { className: "flex flex-wrap gap-1.5" }, overrides.map((o) => {
                return (React.createElement("span", { key: o.label, className: "inline-flex items-center gap-1.5 rounded-full border border-indigo-100 dark:border-indigo-900 bg-indigo-50 dark:bg-indigo-950/40 px-2.5 py-0.5 text-xs font-medium text-indigo-700 dark:text-indigo-300" },
                    React.createElement("span", null, o.label),
                    React.createElement("span", { "aria-hidden": "true", className: "text-indigo-300 dark:text-indigo-700" }, "\u00B7"),
                    React.createElement("span", { className: "font-normal" }, formatDays(o.days))));
            })))) : null));
};
const sortOverridesByDaysDesc = (list) => {
    return [...list].sort((a, b) => {
        return b.days - a.days;
    });
};
const TelemetryRetentionConfigSummary = (props) => {
    var _a, _b, _c, _d;
    const config = props.config;
    const logsOverrides = LOG_SEVERITY_ORDER.flatMap((severity) => {
        var _a, _b;
        const days = pickPositive((_b = (_a = config === null || config === void 0 ? void 0 : config.logs) === null || _a === void 0 ? void 0 : _a.bySeverity) === null || _b === void 0 ? void 0 : _b[severity]);
        return days === null ? [] : [{ label: severity, days: days }];
    });
    const tracesOverrides = SPAN_STATUS_ORDER.flatMap((status) => {
        var _a, _b;
        const days = pickPositive((_b = (_a = config === null || config === void 0 ? void 0 : config.traces) === null || _a === void 0 ? void 0 : _a.byStatus) === null || _b === void 0 ? void 0 : _b[status]);
        return days === null
            ? []
            : [{ label: SPAN_STATUS_LABEL[status], days: days }];
    });
    const pillars = [
        {
            title: "Logs",
            hint: "Log records, with optional per-severity overrides.",
            defaultDays: pickPositive((_a = config === null || config === void 0 ? void 0 : config.logs) === null || _a === void 0 ? void 0 : _a.default),
            overrides: sortOverridesByDaysDesc(logsOverrides),
        },
        {
            title: "Traces",
            hint: "Spans and exceptions, with optional per-status overrides.",
            defaultDays: pickPositive((_b = config === null || config === void 0 ? void 0 : config.traces) === null || _b === void 0 ? void 0 : _b.default),
            overrides: sortOverridesByDaysDesc(tracesOverrides),
        },
        {
            title: "Metrics",
            hint: "Metric data points and aggregates.",
            defaultDays: pickPositive((_c = config === null || config === void 0 ? void 0 : config.metrics) === null || _c === void 0 ? void 0 : _c.default),
            overrides: [],
        },
        {
            title: "Profiles",
            hint: "Profile samples and stack traces.",
            defaultDays: pickPositive((_d = config === null || config === void 0 ? void 0 : config.profiles) === null || _d === void 0 ? void 0 : _d.default),
            overrides: [],
        },
    ];
    const anyConfigured = pillars.some((p) => {
        return p.defaultDays !== null || p.overrides.length > 0;
    });
    return (React.createElement("div", { className: "space-y-3" },
        !anyConfigured ? (React.createElement("div", { className: "rounded-md border border-dashed border-gray-200 dark:border-slate-700 bg-gray-50 dark:bg-slate-900/40 px-4 py-3" },
            React.createElement("p", { className: "text-sm font-medium text-gray-700 dark:text-slate-200" }, "No overrides set."),
            React.createElement("p", { className: "text-xs text-gray-500 dark:text-slate-400 mt-0.5" }, "Every telemetry type uses the default retention shown above."))) : null,
        React.createElement("div", { className: "grid grid-cols-1 sm:grid-cols-2 gap-3" }, pillars.map((pillar) => {
            return React.createElement(PillarCard, { key: pillar.title, pillar: pillar });
        }))));
};
export default TelemetryRetentionConfigSummary;
//# sourceMappingURL=TelemetryRetentionConfigSummary.js.map