/** Cost/duration chart renderers (task detail).
*
* Completions are plotted on a true time axis (a completion 8 months ago sits
* visibly further away than one from last week), with round y-ticks per axis
* and year-aware date labels once the span crosses years — "Jun 3 '25" cannot
* be misread as coming after "Feb 21 '26".
*/
import { html, svg, nothing } from "lit";
import { t, formatCost } from "../styles";
import { niceTicks, fmtNum, fmtDateTick, timeTicks, needsYear, px } from "./chart-utils";
import type { MaintenanceTask } from "../types";
import { entrySpend } from "../helpers/parts-cost";
import { stampMs } from "../helpers/ha-time";
const COST_CHART_H = 200;
const PAD_T = 10;
const PAD_B = 22;
export function renderCostDurationCard(
task: MaintenanceTask,
lang: string,
toggle: "cost" | "duration" | "both",
setToggle: (val: "cost" | "duration" | "both") => void,
currencySymbol: string,
) {
// Cost = what the entry counts (#104: parts booked when used, a purchase
// moved into stock) — the same number as the totals.
const completedEntries = task.history.filter((h) => h.type === "completed" && (entrySpend(h) != null || h.duration != null));
if (completedEntries.length < 2) return nothing;
// A credit (#200) is a cost too: a bar below the zero line.
const anyCost = completedEntries.some((h) => (entrySpend(h) ?? 0) !== 0);
const anyDuration = completedEntries.some((h) => (h.duration ?? 0) > 0);
if (!anyCost && !anyDuration) return nothing;
return html`