import 'dart:ui';

import 'package:eva_icons_flutter/eva_icons_flutter.dart';
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:mitra_corporate/model/order_model.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';

import '../../app/constant.dart';

class ListPasienTerpilih extends HookConsumerWidget {
  const ListPasienTerpilih(
      {super.key,
      required this.orders,
      required this.loading,
      required this.unselect});
  final List<OrderModel> orders;
  final bool loading;
  final Function unselect;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    final scrollCtr = useScrollController();
    return Material(
        child: Container(
            width: Constant.getActualX(context: context, x: 585),
            height: Constant.getActualY(context: context, y: 410),
            color: Colors.white,
            child: Column(
              children: [
                Row(
                  children: [
                    Container(
                      padding: EdgeInsets.only(
                          left: Constant.getActualX(context: context, x: 12)),
                      alignment: Alignment.centerLeft,
                      width: Constant.getActualX(context: context, x: 180),
                      height: Constant.getActualY(context: context, y: 64),
                      color: Constant.grey_200,
                      child: Text('No Registrasi / Nama',
                          style: Constant.body3_600(context: context)
                              .copyWith(color: Constant.textGrey)),
                    ),
                    Container(
                      padding: EdgeInsets.only(
                          left: Constant.getActualX(context: context, x: 12)),
                      alignment: Alignment.centerLeft,
                      width: Constant.getActualX(context: context, x: 325),
                      height: Constant.getActualY(context: context, y: 64),
                      color: Constant.grey_200,
                      child: Text('Pemeriksaan',
                          style: Constant.body3_600(context: context)
                              .copyWith(color: Constant.textGrey)),
                    ),
                    // Container(
                    //   padding: EdgeInsets.only(
                    //       left: Constant.getActualX(context: context, x: 12)),
                    //   alignment: Alignment.centerLeft,
                    //   width: Constant.getActualX(context: context, x: 200),
                    //   height: Constant.getActualY(context: context, y: 64),
                    //   color: Constant.grey_200,
                    //   child: Text('Jenis Specimen',
                    //       style: Constant.body3_600(context: context)
                    //           .copyWith(color: Constant.textGrey)),
                    // ),
                    Container(
                      padding: EdgeInsets.only(
                          left: Constant.getActualX(context: context, x: 12)),
                      alignment: Alignment.centerLeft,
                      width: Constant.getActualX(context: context, x: 80),
                      height: Constant.getActualY(context: context, y: 64),
                      color: Constant.grey_200,
                      child: Text('Aksi',
                          style: Constant.body3_600(context: context)
                              .copyWith(color: Constant.textGrey)),
                    ),
                  ],
                ),
                SizedBox(
                  height: Constant.getActualY(context: context, y: 340),
                  // color: Colors.red,
                  child: loading
                      ? Center(
                          child: LoadingAnimationWidget.discreteCircle(
                              color: Constant.primaryBlue, size: 40),
                        )
                      : Scrollbar(
                          thickness: 5,
                          interactive: true,
                          thumbVisibility: true,
                          trackVisibility: true,
                          scrollbarOrientation: ScrollbarOrientation.right,
                          controller: scrollCtr,
                          child: ScrollConfiguration(
                            behavior: ScrollConfiguration.of(context)
                                .copyWith(dragDevices: {
                              PointerDeviceKind.mouse,
                              PointerDeviceKind.touch,
                              PointerDeviceKind.trackpad,
                              PointerDeviceKind.stylus,
                              PointerDeviceKind.unknown
                            }),
                            child: ListView(
                              controller: scrollCtr,
                              scrollDirection: Axis.vertical,
                              children: orders
                                  .asMap()
                                  .entries
                                  .map(
                                    (e) => Container(
                                      padding: EdgeInsets.only(
                                          top: Constant.getActualY(
                                              context: context, y: 10),
                                          bottom: Constant.getActualY(
                                              context: context, y: 10)),
                                      color: e.key.isOdd
                                          ? Constant.primaryBlue
                                              .withOpacity(0.05)
                                          : Colors.white,
                                      margin: EdgeInsets.only(
                                          top: Constant.getActualY(
                                              context: context, y: 5),
                                          bottom: Constant.getActualY(
                                              context: context, y: 5)),
                                      child: Row(
                                        children: [
                                          Container(
                                            padding: EdgeInsets.only(
                                                left: Constant.getActualX(
                                                    context: context, x: 12)),
                                            alignment: Alignment.centerLeft,
                                            width: Constant.getActualX(
                                                context: context, x: 180),
                                            height: Constant.getActualY(
                                                context: context, y: 64),
                                            child: Column(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                              children: [
                                                Text(e.value.orderNumber ?? "",
                                                    style: Constant.body3_600(
                                                            context: context)
                                                        .copyWith(
                                                            color: Constant
                                                                .textBlack)),
                                                Text(e.value.patientName ?? "",
                                                    style: Constant.body3_600(
                                                            context: context)
                                                        .copyWith(
                                                            color: Constant
                                                                .textBlack))
                                              ],
                                            ),
                                          ),
                                          // Container(
                                          //   padding: EdgeInsets.only(
                                          //       left: Constant.getActualX(
                                          //           context: context, x: 12)),
                                          //   alignment: Alignment.centerLeft,
                                          //   width: Constant.getActualX(
                                          //       context: context, x: 195),
                                          //   height: Constant.getActualY(
                                          //       context: context, y: 64),
                                          //   color: Colors.white,
                                          //   child: Text(e.patientName ?? "",
                                          //       style: Constant.body3_600(
                                          //               context: context)
                                          //           .copyWith(
                                          //               color: Constant
                                          //                   .textBlack)),
                                          // ),
                                          SizedBox(
                                            width: Constant.getActualX(
                                                context: context, x: 325),
                                            child: Wrap(
                                              alignment: WrapAlignment.start,
                                              spacing: 10,
                                              children: [
                                                if (e.value.tests!.isNotEmpty)
                                                  ...e.value.tests!
                                                      .map((k) => Container(
                                                            margin: EdgeInsets.only(
                                                                bottom: Constant
                                                                    .getActualX(
                                                                        context:
                                                                            context,
                                                                        x: 10)),
                                                            child: Chip(
                                                              shape:
                                                                  RoundedRectangleBorder(
                                                                borderRadius: BorderRadius
                                                                    .all(Radius
                                                                        .circular(
                                                                            6)),
                                                              ),
                                                              // backgroundColor:
                                                              //     Constant
                                                              //         .blue_016,
                                                              label: Text(
                                                                  '$k '.replaceAll(
                                                                      ' ',
                                                                      '\u00A0'),
                                                                  overflow:
                                                                      TextOverflow
                                                                          .ellipsis,
                                                                  style: Constant.caption2_600(
                                                                          context:
                                                                              context)
                                                                      .copyWith(
                                                                          color:
                                                                              Constant.textBlack)),
                                                            ),
                                                          ))
                                              ],
                                            ),
                                          ),
                                          Container(
                                            alignment: Alignment.centerLeft,
                                            width: Constant.getActualX(
                                                context: context, x: 80),
                                            child: IconButton(
                                                onPressed: () {
                                                  // print(e.orderNumber);
                                                  unselect(e.value);
                                                },
                                                icon: Icon(
                                                    EvaIcons.arrowCircleLeft,
                                                    size: 24,
                                                    color:
                                                        Constant.primaryRed)),
                                          )
                                        ],
                                      ),
                                    ),
                                  )
                                  .toList(),
                            ),
                          ),
                        ),
                ),
              ],
            )
            //
            ));
  }
}
