import React, { useMemo, useState } from 'react' function newRuleKey() { if (typeof crypto !== 'undefined' && crypto.randomUUID) return crypto.randomUUID() return `fr-${Date.now()}-${Math.random().toString(36).slice(2, 9)}` } /** * Fokusbereiche mit „+“ (muss haben) und „−“ (darf nicht haben); optional nur Übungen ohne Fokus-Zuordnung. */ export default function ExerciseFocusRulePicker({ focusOptions, focusRules, focusOnlyWithout, excludeWithoutFocus, legacyFocusAreaIds = [], onPatch, }) { const [pendingId, setPendingId] = useState('') const legacyWarning = useMemo( () => Array.isArray(legacyFocusAreaIds) && legacyFocusAreaIds.length > 0, [legacyFocusAreaIds] ) const addRule = (mode) => { const id = String(pendingId || '').trim() if (!id || focusOnlyWithout) return const dup = (focusRules || []).some( (r) => String(r.focus_area_id) === id && r.mode === mode ) if (dup) return onPatch({ focus_rules: [...(focusRules || []), { key: newRuleKey(), focus_area_id: id, mode }], }) setPendingId('') } const removeRule = (key) => { onPatch({ focus_rules: (focusRules || []).filter((r) => r.key !== key), }) } const setFocusOnly = (on) => { if (on) { onPatch({ focus_only_without: true, exclude_without_focus: false, focus_rules: [], focus_area_ids: [], }) setPendingId('') return } onPatch({ focus_only_without: false }) } return (
{!focusOnlyWithout ? ( <> {legacyWarning ? (

Es sind noch ältere Fokusfilter (ODER-Liste) aktiv — bitte über die Chips entfernen oder durch Regeln ersetzen.

) : null}

Mehrere „+“: alle müssen gesetzt sein (UND). Mehrere „−“: keiner davon darf gesetzt sein. Kombination z. B. „+ Karate“ und „− Fitness“ = hat Karate, aber nicht zusätzlich Fitness.

{(focusRules || []).length > 0 ? ( ) : null} ) : (

Solange diese Option aktiv ist, sind Fokus-Regeln und die ODER-Fokusliste deaktiviert.

)}
) }