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

class WDay extends StatelessWidget {
  const WDay(
      {super.key, required this.date, this.highlight = false, this.onTap});
  final Jiffy date;
  final bool highlight;
  final Function()? onTap;

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.only(top: 10, bottom: 10),
      height: 50,
      child: Align(
        alignment: Alignment.center,
        child: InkWell(
          onTap: onTap,
          child: Container(
            width: 150,
            decoration: highlight
                ? colorsdays("today")
                : ([1, 7].contains(date.dayOfWeek)
                    ? colorsdays("weekend")
                    : colorsdays("anyday")),
            child: Padding(
              padding: const EdgeInsets.all(8.0),
              child: Text(
                date.format(pattern: "EEE dd MMM y"),
                style: const TextStyle(fontWeight: FontWeight.w700),
                textAlign: TextAlign.center,
              ),
            ),
          ),
        ),
      ),
    );
  }
}

BoxDecoration colorsdays(String day) {
  switch (day) {
    case "weekend":
      return BoxDecoration(
        gradient: const LinearGradient(
          colors: [Color.fromRGBO(44, 45, 116, 1), Color.fromRGBO(0, 2, 67, 1)],
          begin: Alignment.centerLeft,
          end: Alignment.centerRight,
        ),
        border: Border.all(
          color: Colors.yellow,
        ),
        borderRadius: const BorderRadius.all(Radius.circular(20.0)),
      );
    case "today":
      return BoxDecoration(
        gradient: const LinearGradient(
          colors: [
            Color.fromRGBO(225, 57, 57, 1),
            Color.fromRGBO(84, 1, 1, 1),
          ],
          begin: Alignment.centerLeft,
          end: Alignment.centerRight,
        ),
        border: Border.all(
          color: Colors.transparent,
        ),
        borderRadius: const BorderRadius.all(Radius.circular(20.0)),
      );
    default:
      return BoxDecoration(
        gradient: const LinearGradient(
          colors: [Color.fromRGBO(44, 45, 116, 1), Color.fromRGBO(0, 2, 67, 1)],
          begin: Alignment.centerLeft,
          end: Alignment.centerRight,
        ),
        border: Border.all(
          color: Colors.transparent,
        ),
        borderRadius: const BorderRadius.all(Radius.circular(20.0)),
      );
  }
}
