import 'package:flutter/material.dart';

import '../../../../../consts/consts.dart';
import '../../../../../packages/ambito_theme/ambito_theme.dart';

class SublevelMonthsCard extends StatelessWidget {
  const SublevelMonthsCard({
    super.key,
    required this.title,
    required this.items,
  });

  final String title;
  final List<String>? items;

  @override
  Widget build(BuildContext context) {
    if (items == null) {
      return const SizedBox();
    }

    final AmbitoTheme theme = getTheme(context);

    Chip buildChip(String label, [active = false]) {
      return Chip(
        labelPadding: EdgeInsets.zero,
        backgroundColor: active
            ? theme.currentColorScheme.secondary
            : theme.currentColorScheme.outline
          ..withValues(alpha: .1),
        label: Text(
          label,
          style: theme.currentThemeData.textTheme.bodyLarge?.copyWith(
            color: active
                ? theme.currentColorScheme.onSecondary
                : theme.currentColorScheme.onSurface,
          ),
        ),
      );
    }

    List<Chip> buildChips(List<String?>? items) =>
        months.map((item) => buildChip(item, items?.contains(item))).toList();

    final chips = buildChips(items);

    return Align(
      alignment: Alignment.topLeft,
      child: Padding(
        padding: const EdgeInsets.only(right: 20, bottom: 20),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              title,
              style: theme.currentThemeData.textTheme.labelMedium,
            ),
            theme.verticalSpacerSmall,
            Wrap(
              runSpacing: 8,
              spacing: 8,
              children: chips,
            ),
          ],
        ),
      ),
    );
  }
}
