import { Link } from 'react-router-dom'
import { RECURRING_STATUS_LABELS } from '../constants/status.js'
import { EmptyState } from './EmptyState.jsx'
import { scopedPath } from '../utils/routes.js'
function formatDueAt(iso) {
if (!iso) return null
try {
return new Date(iso).toLocaleString('de-DE')
} catch {
return iso
}
}
function activeMaturityStage(roadmapItems = []) {
return [...roadmapItems]
.filter((item) => item.item_type === 'maturity_stage' && item.status === 'active')
.sort((a, b) => (a.sort_order ?? 0) - (b.sort_order ?? 0))[0]
}
function practicesForStage(recurringItems = [], stageId) {
if (!stageId) {
return (recurringItems || []).filter((item) => item.roadmap_item_id)
}
return (recurringItems || []).filter((item) => item.roadmap_item_id === stageId)
}
export function RecurringRhythmPanel({
initiativeId,
roadmapItems = [],
recurringItems = [],
canManage = false,
embedded = true,
}) {
const stage = activeMaturityStage(roadmapItems)
const stagePractices = practicesForStage(recurringItems, stage?.id)
const active = stagePractices.filter((item) => item.status === 'active')
const paused = stagePractices.filter((item) => item.status === 'paused')
const body =
!stage ? (
Stufe {stage.title} — {active.length} aktiv {paused.length > 0 ? `, ${paused.length} pausiert` : ''}.
{canManage ? 'Übungen anlegen, pausieren oder löschen unter ' : 'Rhythmen pflegen unter '} Kontrolle → Journey → Wiederkehrend .
> ) if (!embedded) return body return (Activity Set der aktiven Reifegrad-Stufe — nicht die Gates selbst (A1).