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

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

class SpecimenTableWidget extends HookConsumerWidget {
  const SpecimenTableWidget({
    super.key,
    required this.specimenLoading,
    required this.tempRegistrationData,
    required this.addOrderLoading,
  });

  final ValueNotifier<bool> specimenLoading;
  final RegistrationModel tempRegistrationData;
  final bool addOrderLoading;

  @override
  Widget build(BuildContext context, WidgetRef ref) {
    return Column(
      children: [
        Row(
          children: [
            Container(
              alignment: Alignment.centerLeft,
              padding: EdgeInsets.symmetric(
                  horizontal: Constant.getActualX(context: context, x: 20)),
              width: Constant.getActualX(context: context, x: 1160) * 0.13,
              height: Constant.getActualY(context: context, y: 64),
              color: Constant.grey_200,
              child: Text('Specimen',
                  style: Constant.body3_600(context: context)
                      .copyWith(color: Constant.textGrey)),
            ),
            Container(
              alignment: Alignment.centerLeft,
              padding: EdgeInsets.symmetric(
                  horizontal: Constant.getActualX(context: context, x: 20)),
              width: Constant.getActualX(context: context, x: 1160) * 0.11,
              height: Constant.getActualY(context: context, y: 64),
              color: Constant.grey_200,
              child: Text('Jumlah',
                  style: Constant.body3_600(context: context)
                      .copyWith(color: Constant.textGrey)),
            ),
          ],
        ),
        SizedBox(
          height: Constant.getActualY(context: context, y: 300),
          child: specimenLoading.value
              ? Center(
                  child: LoadingAnimationWidget.discreteCircle(
                      color: Constant.primaryBlue, size: 30),
                )
              : ListView(children: [
                  ...?tempRegistrationData.specimens?.map((e) => SizedBox(
                        height: Constant.getActualY(context: context, y: 64),
                        child: Row(
                          children: [
                            Container(
                                alignment: Alignment.centerLeft,
                                padding: EdgeInsets.symmetric(
                                    horizontal: Constant.getActualX(
                                        context: context, x: 20)),
                                width: Constant.getActualX(
                                        context: context, x: 1160) *
                                    0.13,
                                color: Colors.white,
                                child: Chip(
                                  shape: RoundedRectangleBorder(
                                    borderRadius:
                                        BorderRadius.all(Radius.circular(6)),
                                  ),
                                  backgroundColor: Constant.yellow_016,
                                  label: Text(
                                      '${e.name}'.replaceAll(' ', '\u00A0'),
                                      style: Constant.caption1_600(
                                              context: context)
                                          .copyWith(
                                              color: Constant.textYellow)),
                                )),
                            Container(
                                height: Constant.getActualY(
                                    context: context, y: 52),
                                padding: EdgeInsets.symmetric(
                                    horizontal: Constant.getActualX(
                                        context: context, x: 20)),
                                width: Constant.getActualX(
                                        context: context, x: 1160) *
                                    0.11,
                                child: TextField(
                                  enabled: !addOrderLoading,
                                  controller: e.ctr,
                                  onChanged: (value) {
                                    print(value);
                                  },
                                  decoration: InputDecoration(
                                    border: OutlineInputBorder(
                                        borderRadius: BorderRadius.all(
                                            Radius.circular(8))),
                                  ),
                                ))
                          ],
                        ),
                      )),
                ]),
        ),
      ],
    );
  }
}
