// ignore_for_file: no_leading_underscores_for_local_identifiers

import 'package:fis_ui/index.dart';
import 'package:flutter/material.dart';
import 'package:flyinsono/architecture/define.dart';
import 'package:flyinsono/managers/interfaces/entities/patient_Info.dart';
import 'package:flyinsono/pages/remedical/consultation_record_view/controller.dart';
import 'package:fis_ui/base_define/page.dart';

class CheckListSelectPatientCard
    extends FisView<ConsultationRecordViewController> implements FPage {
  final PatientInfo? patientInfos;
  final String? selectPatientCode;
  CheckListSelectPatientCard({
    this.patientInfos,
    this.selectPatientCode,
  });
  @override
  String get pageName => 'CheckListSelectPatientCard';
  get isSelectPatient => selectPatientCode == patientInfos?.patientCode;
  @override
  FWidget build(BuildContext context) {
    ImageProvider<Object> _buildUserAvatarProvider(int index) {
      ImageProvider child;
      String headImgUrl = '';
      headImgUrl = patientInfos!.headImgUrl ?? "";
      headImgUrl.isEmpty
          ? child = const AssetImage("assets/images/avatar_man.png")
          : child = NetworkImage(headImgUrl);
      return child;
    }

    FWidget _buildPatientTemplate(int index) {
      return FColumn(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          FText(
            patientInfos?.name ?? '',
            style: const TextStyle(
              fontWeight: FontWeight.bold,
            ),
          ),
          const FSizedBox(
            height: 8,
          ),
          FText(patientInfos?.phone ?? ''),
        ],
      );
    }

    FWidget _itemSelectedTemplate(int index) {
      return isSelectPatient
          ? FContainer(
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(20),
                color: Theme.of(context).primaryColor,
              ),
              child: FCenter(
                child: FContainer(
                  child: const FIcon(
                    Icons.check,
                    size: 15,
                    color: Colors.white,
                  ),
                ),
              ),
            ) as FWidget
          : const FText('');
    }

    FWidget _buildPatientItem(int index) {
      return FContainer(
        margin: const EdgeInsets.symmetric(horizontal: 10),
        decoration: const BoxDecoration(
          border: Border(
            bottom: BorderSide(
              color: Color.fromRGBO(235, 235, 235, 1),
              width: 1,
            ),
          ),
        ),
        padding: const EdgeInsets.all(10),
        child: FRow(
          mainAxisAlignment: MainAxisAlignment.spaceBetween,
          children: [
            FExpanded(
              child: FRow(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: [
                  FRow(
                    children: [
                      const FSizedBox(
                        width: 15,
                      ),
                      FCircleAvatar(
                        radius: 25,
                        backgroundImage: _buildUserAvatarProvider(index),
                      ),
                      const FSizedBox(
                        width: 20,
                      ),
                      _buildPatientTemplate(index),
                    ],
                  ),
                  FContainer(
                    width: 20,
                    height: 20,
                    decoration: BoxDecoration(
                      border: Border.all(
                        color: const Color.fromRGBO(141, 141, 141, 1),
                        width: 0.5,
                      ),
                      borderRadius: BorderRadius.circular(20),
                    ),
                    child: _itemSelectedTemplate(index),
                  ),
                ],
              ),
            ),
            const FSizedBox(
              width: 15,
            ),
          ],
        ),
      );
    }

    return _buildPatientItem(1);
  }
}
