/** Sensor prediction section renderer. */
import { html, nothing } from "lit";
import { t, formatDate, fireMoreInfo } from "../styles";
import type { MaintenanceTask, AdvancedFeatures } from "../types";
export function renderPredictionSection(task: MaintenanceTask, lang: string, features: AdvancedFeatures) {
const hasDegradation = task.degradation_trend != null && task.degradation_trend !== "insufficient_data";
const hasThreshold = task.days_until_threshold != null;
const hasEnv = task.environmental_factor != null && task.environmental_factor !== 1.0;
if (!hasDegradation && !hasThreshold && !hasEnv) return nothing;
const trendIcon = task.degradation_trend === "rising"
? "M16,6L18.29,8.29L13.41,13.17L9.41,9.17L2,16.59L3.41,18L9.41,12L13.41,16L19.71,9.71L22,12V6H16Z"
: task.degradation_trend === "falling"
? "M16,18L18.29,15.71L13.41,10.83L9.41,14.83L2,7.41L3.41,6L9.41,12L13.41,8L19.71,14.29L22,12V18H16Z"
: "M22,12L18,8V11H3V13H18V16L22,12Z";
return html`
${task.sensor_prediction_urgency ? html`
${t("sensor_prediction_urgency", lang).replace("{days}", String(Math.round(task.days_until_threshold || 0)))}
` : nothing}
${t("sensor_prediction", lang)}
${hasDegradation ? html`
${t("degradation_trend", lang)}
${t("trend_" + task.degradation_trend, lang)}
${task.degradation_rate != null ? html`${task.degradation_rate > 0 ? "+" : ""}${Math.abs(task.degradation_rate) >= 10 ? Math.round(task.degradation_rate).toLocaleString() : task.degradation_rate.toFixed(1)} ${task.trigger_entity_info?.unit_of_measurement || ""}/${t("day_short", lang)}` : nothing}
` : nothing}
${hasThreshold ? html`
${t("days_until_threshold", lang)}
${task.days_until_threshold === 0 ? t("threshold_exceeded", lang) : "~" + Math.round(task.days_until_threshold!) + " " + t("days", lang)}
${task.threshold_prediction_date ? html`${formatDate(task.threshold_prediction_date, lang)}` : nothing}
${task.threshold_prediction_confidence ? html`` : nothing}
` : nothing}
${hasEnv && features.environmental ? html`
${t("environmental_adjustment", lang)}
${task.environmental_factor!.toFixed(2)}x
${task.environmental_entity ? html` fireMoreInfo(ev, task.environmental_entity!)}>${task.environmental_entity}` : nothing}
` : nothing}
`;
}