import Link from "next/link"; import { getTranslations } from "next-intl/server"; import { Info, Lightbulb, MapPin } from "lucide-react"; import { formatDistance } from "@/lib/geo/distance"; import { wallClock } from "@/lib/planning/days"; import { formatDayShort, formatMinutes } from "@/lib/planning/text"; import { buttonCls } from "@/components/work-orders/button-cls"; import { Section } from "@/components/work-orders/ui"; import type { ServiceCtx } from "@/server/services/context"; import { findNearbyUnplanned, recommendAssignments } from "@/server/services/planning/recommend"; /** * "Einsatz-Vorschläge" in the backoffice work order detail (L13, additive). Never breaks the page: * any error hides the section. "Übernehmen" opens the planning board with a prefilled popover. */ export async function PlanningSuggestions({ ctx, workOrderId, locale, tz }: { ctx: ServiceCtx; workOrderId: string; locale: string; tz: string }) { let rec: Awaited>; let nearby: Awaited>; try { [rec, nearby] = await Promise.all([recommendAssignments(ctx, { workOrderId, locale: locale === "en" ? "en" : "de" }), findNearbyUnplanned(ctx, { workOrderId })]); } catch { return null; } if (rec.status === "not_schedulable") return null; const t = await getTranslations("planning"); const boardLink = (day: string | null, teamId: string | null, time: string | null, id = workOrderId) => { const qs = new URLSearchParams({ schedule: id }); if (day) { qs.set("date", day); qs.set("day", day); } if (teamId) qs.set("scheduleTeam", teamId); if (time) qs.set("time", time); return `/planning?${qs}`; }; return (
{t("recommend.openBoard")} } >

{t("recommend.sub")}

{rec.hint && (

{rec.hint}

)} {rec.recommendations.length > 0 && (
    {rec.recommendations.map((r) => (
  • {t("recommend.card", { day: formatDayShort(r.day, locale), team: r.teamName, distance: formatDistance(r.distanceKm, locale), number: r.nearOrder.number, free: formatMinutes(r.freeMinutes, locale) })}

    {r.tight &&

    {t("recommend.tight")}

    } {t("recommend.take")}
  • ))}
)} {nearby.status === "ok" && nearby.items.length > 0 && (

{t("recommend.nearbyTitle")}

{t("recommend.nearbyQuestion", { radius: nearby.radiusKm })}

    {nearby.items.map((o) => { const first = rec.recommendations[0]; return (
  • {o.number} {o.customerName} · {formatDistance(o.distanceKm, locale)} {t("recommend.planTogether")}
  • ); })}
)}
); }