import 'package:flutter/material.dart';
import 'package:syncfusion_flutter_calendar/calendar.dart';

const String kTimeRegionCenterIcon = 'centerIcon';
const String kTimeRegionHolidayPrefix = 'holiday:';

class TimeRegionTile extends StatelessWidget {
  final TimeRegion region;

  const TimeRegionTile({super.key, required this.region});

  @override
  Widget build(BuildContext context) {
    final text = region.text ?? '';
    final color = region.color;

    if (text == kTimeRegionCenterIcon) {
      return Container(
        color: color,
        alignment: Alignment.center,
        child: Icon(
          region.iconData,
          size: 17,
          color: Theme.of(context).colorScheme.primary,
        ),
      );
    }

    if (text.startsWith(kTimeRegionHolidayPrefix)) {
      return Container(
        color: color,
        alignment: Alignment.center,
        child: Column(
          children: [
            const SizedBox(height: 15),
            Icon(region.iconData ?? Icons.event_outlined),
            const SizedBox(height: 5),
            const Text('Schulfrei'),
            const SizedBox(height: 15),
            RotatedBox(
              quarterTurns: 1,
              child: Text(
                text.substring(kTimeRegionHolidayPrefix.length),
                maxLines: 2,
                softWrap: true,
                overflow: TextOverflow.ellipsis,
                textAlign: TextAlign.center,
                style: const TextStyle(
                  fontWeight: FontWeight.bold,
                  fontSize: 15,
                  decorationStyle: TextDecorationStyle.dashed,
                  letterSpacing: 2,
                ),
              ),
            ),
          ],
        ),
      );
    }

    return const SizedBox.shrink();
  }
}
