import 'package:flutter/material.dart';
import 'package:gap/gap.dart';
import 'package:jiffy/jiffy.dart';
import 'package:tp5/core/core.dart';
import 'package:tp5/roster/models/crewlist_leg.dart';
import 'package:tp5/roster/widgets/w_citypair.dart';
import 'package:tp5/roster/widgets/w_fnum.dart';
import 'package:tp5/roster/widgets/w_hour.dart';

class WCrewlist extends StatelessWidget {
  const WCrewlist({super.key, required this.leg, this.date, this.onTap});
  final CrewlistLeg leg;
  final String? date;
  final dynamic onTap;

  @override
  Widget build(BuildContext context) {
    return Row(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        Container(
          width: 120,
          color: Colors.grey[900],
          child: Column(
            children: [
              Card(
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(6.0),
                ),
                elevation: 8.0,
                margin:
                    const EdgeInsets.symmetric(horizontal: 5.0, vertical: 3.0),
                child: Column(children: [
                  Row(
                      mainAxisSize: MainAxisSize.max,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        const Gap(2),
                        WHour(jiffy: leg.jdep),
                        const Gap(20),
                        WHour(
                            jiffy: leg.jdes,
                            color: leg.jdes.format(pattern: "yyyy-MM-dd") ==
                                    leg.date
                                ? null
                                : Colors.yellow[800]),
                        const Gap(2),
                      ]),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [WCitypair(iata1: leg.dep, iata2: leg.des)],
                  ),
                  WFnum(al: leg.al, fnum: leg.fnum),
                ]),
              ),
              Text(
                  Jiffy.parse(leg.date, pattern: "yyyy-MM-dd", isUtc: true)
                      .format(pattern: "EEE dd MMM'yy"),
                  style: const TextStyle(
                      fontSize: 10,
                      color: Colors.blueGrey,
                      letterSpacing: 2,
                      fontWeight: FontWeight.w700))
            ],
          ),
        ),
        const Gap(5),
        Container(
          width: 130,
          color: Colors.grey[900],
          child:
              Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                const Gap(20),
                const Text(
                  "<Cockpit>",
                  style:
                      TextStyle(fontWeight: FontWeight.w600, letterSpacing: 2),
                ),
                Text("${leg.cockpit.length}",
                    style: const TextStyle(
                        fontWeight: FontWeight.w900, color: Colors.amber)),
              ],
            ),
            const Gap(5),
            ...leg.cockpit.map(
              (e) => Text(
                "+ ${e.capitalizeword()}",
                overflow: TextOverflow.ellipsis,
                style: const TextStyle(fontSize: 12),
              ),
            ),
            const Gap(10)
          ]),
        ),
        const Gap(5),
        Container(
          width: 130,
          color: Colors.grey[900],
          child:
              Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                const Gap(20),
                const Text(
                  "<Cabin>",
                  style:
                      TextStyle(fontWeight: FontWeight.w600, letterSpacing: 2),
                ),
                Text("${leg.cabin.length}",
                    style: const TextStyle(
                        fontWeight: FontWeight.w900, color: Colors.amber)),
              ],
            ),
            const Gap(5),
            ...leg.cabin.map(
              (e) => Text(
                "+ ${e.capitalizeword()}",
                overflow: TextOverflow.ellipsis,
                style: const TextStyle(fontSize: 12),
              ),
            ),
            const Gap(10)
          ]),
        ),
        const Gap(5),
        Container(
          width: 130,
          color: Colors.grey[900],
          child:
              Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                const Gap(20),
                const Text(
                  "<DH>",
                  style:
                      TextStyle(fontWeight: FontWeight.w600, letterSpacing: 2),
                ),
                Text("${leg.dh.length}",
                    style: const TextStyle(
                        fontWeight: FontWeight.w900, color: Colors.amber)),
              ],
            ),
            const Gap(5),
            ...leg.dh.map(
              (e) => Text(
                "+ ${e.capitalizeword()}",
                overflow: TextOverflow.ellipsis,
                style: const TextStyle(fontSize: 12),
              ),
            ),
            const Gap(10)
          ]),
        )
      ],
    );
  }

  // Widget _text(String? msg) => Flexible(
  //     child: Tooltip(
  //         message: msg ?? "",
  //         child: Text(msg ?? "",
  //             overflow: TextOverflow.ellipsis,
  //             style: const TextStyle(color: Colors.white38, fontSize: 12))));
}
