// ChainCard — flat card with subtle accent gradient on the top
// border. Replaces Material's default Card for the Ch∆In look.

import 'package:flutter/material.dart';

import '../theme/tokens.dart';

class ChainCard extends StatelessWidget {
  /// Card body. Padding is applied internally; pass plain content.
  final Widget child;

  /// When true, paint a 2px accent-coloured stripe along the top
  /// edge. Used by foreground / "this matters" cards (a pending
  /// approval, a failed step).
  final bool accentTop;

  /// When true, paint a faint vertical accent stripe on the left.
  /// Used by status rows (live event, healthy service).
  final Color? accentLeft;

  /// Internal padding. Defaults to [ChainSpace.lg].
  final EdgeInsetsGeometry padding;

  const ChainCard({
    super.key,
    required this.child,
    this.accentTop = false,
    this.accentLeft,
    this.padding = const EdgeInsets.all(ChainSpace.lg),
  });

  @override
  Widget build(BuildContext context) {
    final theme = Theme.of(context);
    return Container(
      decoration: BoxDecoration(
        color: theme.colorScheme.surfaceContainer,
        borderRadius: BorderRadius.circular(ChainRadius.md),
        border: Border.all(color: theme.colorScheme.outlineVariant),
      ),
      clipBehavior: Clip.antiAlias,
      child: Stack(
        children: [
          if (accentTop)
            Positioned(
              top: 0,
              left: 0,
              right: 0,
              height: 2,
              child: DecoratedBox(
                decoration: BoxDecoration(
                  gradient: LinearGradient(
                    colors: [
                      theme.colorScheme.primary.withValues(alpha: 0.0),
                      theme.colorScheme.primary,
                      theme.colorScheme.primary.withValues(alpha: 0.0),
                    ],
                  ),
                ),
              ),
            ),
          if (accentLeft != null)
            Positioned(
              top: ChainSpace.md,
              bottom: ChainSpace.md,
              left: 0,
              width: 3,
              child: DecoratedBox(
                decoration: BoxDecoration(
                  color: accentLeft,
                  borderRadius: const BorderRadius.only(
                    topRight: Radius.circular(2),
                    bottomRight: Radius.circular(2),
                  ),
                ),
              ),
            ),
          Padding(padding: padding, child: child),
        ],
      ),
    );
  }
}
