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

part of '../timeline_axis.dart';

/// Private implementation type for `_TimelineGridPainter` 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 _TimelineGridPainter extends CustomPainter {
  /// Creates a `_TimelineGridPainter` 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 _TimelineGridPainter({required this.geometry, required this.topInset});

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

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

  /// Performs the `paint` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  @override
  void paint(Canvas canvas, Size size) {
    final paint = Paint()
      ..color = FocusFlowTokens.gridLine
      ..strokeWidth = 1;
    for (final tick in geometry.ticks()) {
      canvas.drawLine(
        Offset(0, tick.y + topInset),
        Offset(size.width, tick.y + topInset),
        paint
          ..color = tick.major
              ? FocusFlowTokens.gridLine.withValues(alpha: 0.72)
              : FocusFlowTokens.gridLine,
      );
    }
  }

  /// Performs the `shouldRepaint` behavior for this scheduler component.
  /// The method provides a named entry point for this operation so callers do not need to know the lower-level state or persistence steps involved.
  @override
  bool shouldRepaint(covariant _TimelineGridPainter oldDelegate) {
    return oldDelegate.geometry != geometry || oldDelegate.topInset != topInset;
  }
}
