// SPDX-FileCopyrightText: 2026 FocusFlow contributors
// SPDX-License-Identifier: AGPL-3.0-only

part of '../../today_state.dart';

/// Compact projection derived from the same Today item list.
class TodayCompactState {
  /// Creates a `TodayCompactState` instance with the values required by its invariants.
  /// Callers should pass already-normalized scheduler data because validation and defaulting belong at the model or service boundary, not in arbitrary UI code.
  const TodayCompactState({
    required this.manualCompactModeEnabled,
    required this.fullTimelineExpanded,
    this.currentItem,
    this.nextRequiredItem,
    this.nextFlexibleItem,
  });

  /// User-controlled compact mode flag.
  final bool manualCompactModeEnabled;

  /// Whether the full timeline is expanded while compact mode is active.
  final bool fullTimelineExpanded;

  /// Current visible item, if one occupies the read instant.
  final TodayTimelineItem? currentItem;

  /// Next critical or inflexible item.
  final TodayTimelineItem? nextRequiredItem;

  /// Optional next flexible item.
  final TodayTimelineItem? nextFlexibleItem;

  /// Whether callers should show the full timeline.
  bool get fullTimelineVisible {
    return !manualCompactModeEnabled || fullTimelineExpanded;
  }

  /// Items selected for compact rendering.
  List<TodayTimelineItem> get compactItems {
    if (!manualCompactModeEnabled) {
      return const [];
    }

    return [
      if (currentItem != null) currentItem!,
      if (nextRequiredItem != null && nextRequiredItem!.id != currentItem?.id)
        nextRequiredItem!,
      if (nextFlexibleItem != null &&
          nextFlexibleItem!.id != currentItem?.id &&
          nextFlexibleItem!.id != nextRequiredItem?.id)
        nextFlexibleItem!,
    ];
  }
}
