import 'package:flutter/material.dart';
import '../halo_tokens.dart';

/// A soft gradient circle used as an avatar/identity glyph.
///
/// `seed` deterministically picks a hue blend from the warm palette.
class HaloOrb extends StatelessWidget {
  const HaloOrb({
    super.key,
    required this.seed,
    this.size = 64,
    this.label,
  });

  final int seed;
  final double size;
  final String? label;

  static const List<List<Color>> _gradients = [
    [HaloTokens.brand, HaloTokens.brandDark],
    [HaloTokens.accent, HaloTokens.brand],
    [HaloTokens.lilac, HaloTokens.brand],
    [HaloTokens.mint, HaloTokens.accent],
    [HaloTokens.brandSoft, HaloTokens.brand],
    [HaloTokens.accentSoft, HaloTokens.accent],
  ];

  @override
  Widget build(BuildContext context) {
    final colors = _gradients[seed.abs() % _gradients.length];
    final initial = (label ?? '').isNotEmpty
        ? label!.substring(0, 1).toUpperCase()
        : null;

    return Container(
      width: size,
      height: size,
      decoration: BoxDecoration(
        shape: BoxShape.circle,
        gradient: LinearGradient(
          colors: colors,
          begin: Alignment.topLeft,
          end: Alignment.bottomRight,
        ),
        boxShadow: HaloShadows.soft,
      ),
      alignment: Alignment.center,
      child: initial == null
          ? null
          : Text(
              initial,
              style: TextStyle(
                fontFamily: HaloTokens.fontDisplay,
                fontSize: size * 0.42,
                fontWeight: FontWeight.w700,
                color: Colors.white,
              ),
            ),
    );
  }
}
