import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import '/widget/chip_type.dart';

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

showConfirmCourierDialog(
    {required BuildContext context,
    required int tipeid,
    required String tipe,
    required String tipee,
    required String tujuann,
    required String penerimaa,
    required TextEditingController noteKurir,
    required VoidCallback okCallback}) {
  return showDialog(
      context: context,
      builder: (BuildContext context) {
        return AlertDialog(
          insetPadding: EdgeInsets.symmetric(
            horizontal: Constant.getActualX(context: context, x: 35),
          ),
          title: const Text(
            "Konfirmasi Pekerjaan",
            style: TextStyle(fontWeight: FontWeight.bold),
          ),
          content: tipe == "Tolak"
              ? TolakDialog(
                  tipeid: tipeid,
                  tipee: tipee,
                  tujuann: tujuann,
                  penerimaa: penerimaa,
                  noteKurir: noteKurir,
                )
              : TerimaDialog(
                  tipeid: tipeid,
                  tipee: tipee,
                  tujuann: tujuann,
                  penerimaa: penerimaa),
          actions: [
            Container(
              padding: EdgeInsets.symmetric(
                  horizontal: Constant.getActualX(context: context, x: 15),
                  vertical: Constant.getActualY(context: context, y: 8)),
              child: Column(
                children: [
                  Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        OutlinedButton(
                            onPressed: () => Navigator.pop(context, 'Cancel'),
                            style: OutlinedButton.styleFrom(
                              side: BorderSide(
                                  style: BorderStyle.solid,
                                  color: Constant.textGrey),
                              shape: RoundedRectangleBorder(
                                side: BorderSide(
                                    style: BorderStyle.solid,
                                    color: Constant.textPrimary),
                                borderRadius: BorderRadius.circular(8),
                              ),
                            ),
                            child: const Text(
                              "Batal",
                              style: TextStyle(
                                  fontWeight: FontWeight.bold,
                                  color: Colors.black),
                            )),
                        tipe == "Tolak"
                            ? ElevatedButton(
                                onPressed: () {
                                  okCallback();
                                  Navigator.of(context).pop();
                                },
                                // onPressed: {} () => Navigator.pop(context, 'OK'),
                                style: ElevatedButton.styleFrom(
                                  backgroundColor: Colors.red,
                                  shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(8),
                                  ),
                                ),
                                child: const Text(
                                  "Tolak",
                                  style: TextStyle(fontWeight: FontWeight.bold),
                                ),
                              )
                            : ElevatedButton(
                                onPressed: () {
                                  okCallback();
                                  Navigator.pop(context);
                                },
                                style: ElevatedButton.styleFrom(
                                  shape: RoundedRectangleBorder(
                                    borderRadius: BorderRadius.circular(8),
                                  ),
                                ),
                                child: const Text(
                                  "Terima",
                                  style: TextStyle(fontWeight: FontWeight.bold),
                                ),
                              ),
                      ]),
                ],
              ),
            )
          ],
          shape: RoundedRectangleBorder(
            side: BorderSide(
              color: Theme.of(context).colorScheme.outline,
            ),
            borderRadius: const BorderRadius.all(Radius.circular(12)),
          ),
        );
      });
}

class TerimaDialog extends StatelessWidget {
  const TerimaDialog({
    super.key,
    required this.tipeid,
    required this.tipee,
    required this.tujuann,
    required this.penerimaa,
  });
  final int tipeid;
  final String tipee;
  final String tujuann;
  final String penerimaa;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: SingleChildScrollView(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: [
            Text(
              "Anda menerima pekerjaan ini ?",
              style: Constant.body2(context: context).copyWith(
                  fontWeight: FontWeight.w400, color: Constant.textPrimary),
            ),
            Container(
              margin: const EdgeInsets.fromLTRB(0, 16, 0, 0),
              width: double.infinity,
              child: Card(
                elevation: 2,
                shape: RoundedRectangleBorder(
                  side: BorderSide(
                    color: Theme.of(context).colorScheme.outline,
                  ),
                  borderRadius: const BorderRadius.all(Radius.circular(12)),
                ),
                child: Container(
                  padding: const EdgeInsets.all(16),
                  child: Column(
                    children: [
                      Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Expanded(
                              flex: 3,
                              child: Text("Tipe",
                                  style: Constant.caption1(context: context))),
                          Expanded(
                            flex: 5,
                            child: ChipType(
                              tipe: tipeid,
                              name: tipee,
                              isDetailHistory: false,
                            ),
                          )
                        ],
                      ),
                      SizedBox(
                        height: Constant.getActualY(context: context, y: 5),
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Expanded(
                              flex: 3,
                              child: Text("Tujuan",
                                  style: Constant.caption1(context: context))),
                          Expanded(
                              flex: 5,
                              child: Text(tujuann,
                                  style: TextStyle(
                                      color: Constant.textGrey, fontSize: 12)))
                        ],
                      ),
                      SizedBox(
                        height: Constant.getActualY(context: context, y: 5),
                      ),
                      Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Expanded(
                              flex: 3,
                              child: Text("Penerima",
                                  style: Constant.caption1(context: context))),
                          Expanded(
                              flex: 5,
                              child: Text(penerimaa,
                                  style: TextStyle(
                                      color: Constant.textGrey, fontSize: 12)))
                        ],
                      ),
                    ],
                  ),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

class TolakDialog extends StatelessWidget {
  const TolakDialog({
    super.key,
    required this.tipeid,
    required this.tipee,
    required this.tujuann,
    required this.penerimaa,
    required this.noteKurir,
  });
  final int tipeid;
  final String tipee;
  final String tujuann;
  final String penerimaa;
  final TextEditingController noteKurir;

  @override
  Widget build(BuildContext context) {
    return Container(
        child: SingleChildScrollView(
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Text(
            "Anda menolak pekerjaan ini ?",
            style: Constant.body2(context: context).copyWith(
                fontWeight: FontWeight.w400, color: Constant.textPrimary),
          ),
          Container(
            margin: const EdgeInsets.fromLTRB(0, 16, 0, 25),
            width: double.infinity,
            child: Card(
              elevation: 2,
              shape: RoundedRectangleBorder(
                side: BorderSide(
                  color: Theme.of(context).colorScheme.outline,
                ),
                borderRadius: const BorderRadius.all(Radius.circular(12)),
              ),
              child: Container(
                padding: const EdgeInsets.all(16),
                child: Column(
                  children: [
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                            flex: 3,
                            child: Text("Tipe",
                                style: Constant.caption1(context: context))),
                        Expanded(
                          flex: 5,
                          child: ChipType(
                            tipe: tipeid,
                            name: tipee,
                            isDetailHistory: false,
                          ),
                        )
                      ],
                    ),
                    SizedBox(
                      height: Constant.getActualY(context: context, y: 5),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                            flex: 3,
                            child: Text("Tujuan",
                                style: Constant.caption1(context: context))),
                        Expanded(
                            flex: 5,
                            child: Text(tujuann,
                                style: TextStyle(
                                    color: Constant.textGrey, fontSize: 12)))
                      ],
                    ),
                    SizedBox(
                      height: Constant.getActualY(context: context, y: 5),
                    ),
                    Row(
                      mainAxisAlignment: MainAxisAlignment.start,
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Expanded(
                            flex: 3,
                            child: Text("Penerima",
                                style: Constant.caption1(context: context))),
                        Expanded(
                            flex: 5,
                            child: Text(penerimaa,
                                style: TextStyle(
                                    color: Constant.textGrey, fontSize: 12)))
                      ],
                    ),
                  ],
                ),
              ),
            ),
          ),
          TextField(
            controller: noteKurir,
            maxLines: 1,
            decoration: const InputDecoration(
              labelStyle: TextStyle(color: Colors.grey),
              border: OutlineInputBorder(
                  borderSide: BorderSide(color: Colors.grey),
                  borderRadius: BorderRadius.all(Radius.circular(12))),
              labelText: 'Alasan',
            ),
          )
        ],
      ),
    ));
  }
}
