import 'package:flutter/material.dart';

import '../../../../api/marianumconnect/queries/timetable_get_subjects/timetable_get_subjects_response.dart';
import '../../../../widget/centered_leading.dart';
import '../data/subject_color_palette.dart';
import 'subject_color_filter.dart';
import 'subject_color_picker.dart';

/// Listeneintrag eines Fachs mit Farb-Vorschau; Tap öffnet den Farbpicker.
/// Von der Verwaltungsseite und der Suche gemeinsam genutzt.
class SubjectColorTile extends StatelessWidget {
  final McSubject subject;

  const SubjectColorTile(this.subject, {super.key});

  @override
  Widget build(BuildContext context) {
    final color = SubjectColorPalette.colorFromName(subject.color);
    final label = subjectDisplayLabel(subject);
    return ListTile(
      leading: CenteredLeading(
        color == null
            ? Icon(
                Icons.circle_outlined,
                color: Theme.of(context).colorScheme.outline,
              )
            : Icon(Icons.circle, color: color),
      ),
      title: Text(label),
      subtitle: Text(subject.shortName),
      trailing: const Icon(Icons.chevron_right),
      onTap: () => showSubjectColorPicker(
        context,
        subjectShort: subject.shortName,
        subjectLabel: label,
        currentColorName: subject.color,
      ),
    );
  }
}
