import 'package:dotted_line/dotted_line.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import '../models/work_list_model.dart';
import '/screen/work_process_screen/work_process_screen.dart';

import '../../app/constant.dart';
import '../../app/route.dart';
import '../../models/pending_work_model.dart';
import '../provider/current_user_provider.dart';
import 'chip_type.dart';

class PendingCardWidget extends HookConsumerWidget {
  const PendingCardWidget({super.key, required this.data});

  final PendingWorkModel data;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    Widget cardValue(String name, String value) {
      return Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Expanded(
            child: Text(
              name,
              style: Constant.caption1(context: context).copyWith(
                  fontWeight: FontWeight.w400, color: Constant.textPrimary),
            ),
          ),
          Text(
            ":  ",
            style: Constant.caption2(context: context).copyWith(
                fontWeight: FontWeight.w400, color: Constant.textPrimary),
          ),
          Expanded(
            child: Text(
              "${value}",
              style: Constant.caption1(context: context).copyWith(
                  fontWeight: FontWeight.w400, color: Constant.textPrimary),
            ),
          ),
        ],
      );
    }

    return Container(
      margin: EdgeInsets.symmetric(
          vertical: Constant.getActualY(context: context, y: 4)),
      // color: Colors.blue,
      // height: Constant.getActualY(context: context, y: 170),
      width: double.infinity,
      child: Card(
        shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
        child: Container(
          decoration: BoxDecoration(
              color: Colors.white,
              border: Border.all(color: Colors.grey, width: 0.1),
              boxShadow: [
                BoxShadow(
                    color: Color(0XFF919EAB).withOpacity(0.12),
                    offset: Offset(0.0, 12), //(x,y)
                    blurRadius: 24,
                    spreadRadius: -4),
                BoxShadow(
                  color: Color(0XFF919EAB).withOpacity(0.2),
                  offset: Offset(0.0, 0), //(x,y)
                  blurRadius: 2,
                ),
              ],
              borderRadius: BorderRadius.circular(12)),
          child: ElevatedButton(
            style: ElevatedButton.styleFrom(
                elevation: 0.2,
                shape: RoundedRectangleBorder(
                  side: BorderSide(width: 0.1, color: Colors.grey),
                  borderRadius: BorderRadius.circular(12),
                ),
                backgroundColor: Colors.white,
                foregroundColor: Colors.grey),
            onPressed: () {
              if (data.supervisor == "Dikonfirmasi") {
                Navigator.pushNamed(
                  context,
                  workProcessRoute,
                  arguments: DetailWorkProp(
                      data.tipeid!,
                      ref.watch(currentUserProvider)?.model.user?.mCourierID ??
                          "0",
                      data.id.toString(),
                      data.noLab.toString(),
                      data.nama.toString(),
                      data.note.toString()),
                );
              }
            },
            child: Padding(
              padding: EdgeInsets.symmetric(
                  horizontal: Constant.getActualX(context: context, x: 18),
                  vertical: Constant.getActualY(context: context, y: 20)),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.start,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      ChipType(
                          tipe: data.tipeid!,
                          name: data.tipe!,
                          isDetailHistory: false),
                      if (data.supervisor == "Dikonfirmasi")
                        Icon(
                          Icons.check_circle_outline_rounded,
                          color: Constant.primaryGreen,
                          size: 15,
                        ),
                      if (data.supervisor == "Belum dikonfirmasi")
                        Icon(
                          Icons.help_outline_rounded,
                          color: Constant.primaryOrange,
                          size: 15,
                        ),
                      if (data.supervisor == "Ditoalk")
                        Icon(
                          Icons.cancel_outlined,
                          color: Constant.primaryRed,
                          size: 15,
                        ),
                    ],
                  ),
                  SizedBox(
                    height: Constant.getActualY(context: context, y: 12),
                  ),
                  if (data.tipeid == 1)
                    Column(
                      children: [
                        cardValue("Nomot Lab", data.noLab ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Nama", data.nama ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Cabang Pengirim", data.branchname ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Alamat Pengantaran", data.alamat ?? ""),
                      ],
                    ),
                  if (data.tipeid == 2)
                    Column(
                      children: [
                        cardValue("Nomot Surat Jalan", data.noSuratJalan ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Nama", data.nama ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Cabang Pengirim", data.branchname ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Alamat Pengantaran", data.alamat ?? ""),
                      ],
                    ),
                  if (data.tipeid == 3)
                    Column(
                      children: [
                        cardValue("Nomot Surat Jalan", data.noSuratJalan ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Nama", data.nama ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Cabang Pengirim", data.branchname ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Alamat Pengantaran", data.alamat ?? ""),
                      ],
                    ),
                  if (data.tipeid == 4)
                    Column(
                      children: [
                        cardValue("Catatan", data.note ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Pengirim", data.branchaddress ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Penerima", data.alamat ?? ""),
                      ],
                    ),
                  if (data.tipeid == 5)
                    Column(
                      children: [
                        cardValue("Tujuan", data.nama ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Alamat", data.branchaddress ?? ""),
                        SizedBox(
                          height: Constant.getActualY(context: context, y: 5),
                        ),
                        cardValue("Cabang penerima", data.branchname ?? ""),
                      ],
                    ),
                  SizedBox(
                    height: Constant.getActualY(context: context, y: 16),
                  ),
                  Row(
                    children: [
                      Icon(
                        Icons.circle_outlined,
                        color: Colors.grey.shade300,
                        size: 15,
                      ),
                      SizedBox(
                        width: Constant.getActualX(context: context, x: 12),
                      ),
                      Expanded(
                          flex: 5,
                          child: DottedLine(
                            dashColor: Colors.grey.shade300,
                          )),
                      SizedBox(
                        width: Constant.getActualX(context: context, x: 12),
                      ),
                      if (data.statusTransaksi == "Baru")
                        Icon(
                          Icons.circle_outlined,
                          color: Constant.primaryBlue,
                          size: 15,
                        ),
                      if (data.statusTransaksi == "Proses")
                        Icon(
                          Icons.circle_outlined,
                          color: Constant.primaryYellow,
                          size: 15,
                        ),
                      if (data.statusTransaksi == "Done" ||
                          data.statusTransaksi == "Selesai")
                        Icon(
                          Icons.circle_outlined,
                          color: Constant.primaryGreen,
                          size: 15,
                        ),
                      SizedBox(
                        width: Constant.getActualX(context: context, x: 4),
                      ),
                      Text(
                        "${data.statusTransaksi}",
                        style: Constant.caption2(context: context)
                            .copyWith(color: Constant.textPrimary),
                      ),
                    ],
                  )
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }
}
