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

part of '../task_timeline_card.dart';

/// Private implementation type for `_QuickActions` in this library.
/// It keeps supporting state and behavior scoped to the owning file so the public API stays focused on the scheduler concepts that callers use directly.
class _QuickActions extends StatelessWidget {
  /// Creates a `_QuickActions` 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 _QuickActions({
    required this.card,
    required this.color,
    required this.backgroundColor,
    required this.metrics,
    required this.visible,
    required this.pushRunning,
    this.onPushToNext,
    this.onPushToTomorrow,
    this.onPushToBacklog,
  });

  /// Stores the `card` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final TimelineCardModel card;

  /// Stores the `color` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Color color;

  /// Stores the `backgroundColor` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final Color backgroundColor;

  /// Stores the `metrics` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final _CardMetrics metrics;

  /// Stores the `visible` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final bool visible;

  /// Stores the `pushRunning` value for this object.
  /// This field is part of the explicit state that downstream scheduling, persistence, or UI code reads when composing behavior.
  final bool pushRunning;

  /// Callback invoked when Push to next is selected.
  final Future<void> Function()? onPushToNext;

  /// Callback invoked when Push to tomorrow is selected.
  final Future<void> Function()? onPushToTomorrow;

  /// Callback invoked when Push to backlog is selected.
  final Future<void> Function()? onPushToBacklog;

  /// Builds the widget subtree for this component.
  /// The method translates the current widget configuration and state into Flutter UI without mutating scheduler domain data.
  @override
  Widget build(BuildContext context) {
    return ExcludeSemantics(
      excluding: !visible,
      child: IgnorePointer(
        ignoring: !visible,
        child: ClipRect(
          child: AnimatedContainer(
            key: ValueKey('${card.id}-quick-actions-background'),
            width: visible ? metrics.actionsWidth : 0,
            height: metrics.actionButtonSize,
            decoration: BoxDecoration(color: backgroundColor),
            duration: const Duration(milliseconds: 120),
            curve: Curves.easeOut,
            child: OverflowBox(
              minWidth: metrics.actionsWidth,
              maxWidth: metrics.actionsWidth,
              alignment: Alignment.centerRight,
              child: AnimatedOpacity(
                key: ValueKey('${card.id}-quick-actions-opacity'),
                opacity: visible ? 1 : 0,
                duration: const Duration(milliseconds: 90),
                curve: Curves.easeOut,
                child: Row(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    _QuickPushIcon(
                      card: card,
                      color: color,
                      metrics: metrics,
                      isRunning: pushRunning,
                      onPushToNext: onPushToNext,
                      onPushToTomorrow: onPushToTomorrow,
                      onPushToBacklog: onPushToBacklog,
                    ),
                    _NoOpIcon(
                      icon: Icons.calendar_today,
                      tooltip: 'Schedule',
                      color: color,
                      metrics: metrics,
                    ),
                    _NoOpIcon(
                      icon: Icons.wb_sunny_outlined,
                      tooltip: 'Protect time',
                      color: color,
                      metrics: metrics,
                    ),
                    SizedBox(width: metrics.actionGap),
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
