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

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

class DialogDeletePatient extends StatelessWidget {
  const DialogDeletePatient(
      {super.key,
      required this.NIK,
      required this.delete,
      required this.patientID,
      required this.loading,
      required this.name});

  final String name;
  final String NIK;
  final Function delete;
  final String patientID;
  final bool loading;

  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      titlePadding: EdgeInsets.symmetric(
          horizontal: Constant.getActualX(context: context, x: 24),
          vertical: Constant.getActualY(context: context, y: 24)),
      actionsPadding: EdgeInsets.symmetric(
          horizontal: Constant.getActualX(context: context, x: 24),
          vertical: Constant.getActualY(context: context, y: 24)),
      contentPadding: EdgeInsets.symmetric(
          horizontal: Constant.getActualX(context: context, x: 24),
          vertical: Constant.getActualY(context: context, y: 24)),
      shape: RoundedRectangleBorder(
          borderRadius: BorderRadius.all(Radius.circular(8))),
      title: Text(
        'Konfirmasi hapus',
        style: Constant.h4_600(context: context),
      ),
      content: Container(
          constraints: BoxConstraints(
            minHeight: Constant.getActualY(context: context, y: 100),
            maxHeight: Constant.getActualY(context: context, y: 362),
          ),
          height: Constant.getActualY(context: context, y: 240),
          child: Column(
            children: [
              Text(
                'Anda yakin menghapus pasien berikut ?',
                style: Constant.body1_600(context: context),
              ),
              SizedBox(
                height: Constant.getActualY(context: context, y: 24),
              ),
              SizedBox(
                width: Constant.getActualX(context: context, x: 416),
                child: Card(
                  elevation: 1,
                  shape: RoundedRectangleBorder(
                      side: BorderSide(color: Constant.grey_200),
                      borderRadius: BorderRadius.circular(12)),
                  child: Container(
                      padding: EdgeInsets.symmetric(
                          horizontal:
                              Constant.getActualX(context: context, x: 24),
                          vertical:
                              Constant.getActualY(context: context, y: 24)),
                      child: Column(
                        children: [
                          Row(
                            children: [
                              Expanded(
                                flex: 5,
                                child: Text(
                                  "NIK",
                                  style: Constant.body3_600(context: context)
                                      .copyWith(color: Constant.textGrey),
                                ),
                              ),
                              Expanded(
                                flex: 7,
                                child: Text(
                                  NIK,
                                  style: Constant.body3_600(context: context)
                                      .copyWith(color: Constant.textBlack),
                                ),
                              )
                            ],
                          ),
                          SizedBox(
                            height:
                                Constant.getActualY(context: context, y: 12),
                          ),
                          Row(
                            children: [
                              Expanded(
                                flex: 5,
                                child: Text(
                                  "Nama",
                                  style: Constant.body3_600(context: context)
                                      .copyWith(color: Constant.textGrey),
                                ),
                              ),
                              Expanded(
                                flex: 7,
                                child: Text(
                                  name,
                                  style: Constant.body3_600(context: context)
                                      .copyWith(color: Constant.textBlack),
                                ),
                              )
                            ],
                          ),
                        ],
                      )),
                ),
              )
            ],
          )),
      actions: <Widget>[
        OutlinedButton(
          style: OutlinedButton.styleFrom(
              surfaceTintColor: Constant.primaryBlue,
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(8))),
          onPressed: !loading ? () => Navigator.pop(context, 'Batal') : null,
          child: Padding(
            padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
            child: loading
                ? LoadingAnimationWidget.staggeredDotsWave(
                    color: Constant.primaryBlue, size: 20)
                : Text('Batal',
                    style: Constant.button_medium(context: context)
                        .copyWith(color: Constant.textBlack)),
          ),
        ),
        ElevatedButton(
          style: ElevatedButton.styleFrom(
              backgroundColor: Colors.red,
              shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(8))),
          onPressed: !loading ? () => delete(patientID) : null,
          child: Padding(
            padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
            child: loading
                ? LoadingAnimationWidget.staggeredDotsWave(
                    color: Colors.white, size: 20)
                : Text(
                    'Yakin',
                    style: Constant.button_medium(context: context),
                  ),
          ),
        ),
      ],
    );
  }
}
