import 'package:diplomaticquarterapp/models/LiveCare/ClinicsServiceTimingsResponse.dart';
import 'package:diplomaticquarterapp/models/LiveCare/LiveCareClinicsListResponse.dart';
import 'package:diplomaticquarterapp/services/livecare_services/livecare_provider.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:flutter/material.dart';
import 'package:smart_progress_bar/smart_progress_bar.dart';

import 'ClinicTimingsDialog.dart';

// ignore: must_be_immutable
class ClinicCard extends StatefulWidget {
  bool isSelected;
  final PatientERGetClinicsList patientERGetClinicsList;
  var languageID;

  ClinicCard(
      {this.isSelected,
      this.languageID,
      @required this.patientERGetClinicsList});

  @override
  _State createState() => _State();
}

class _State extends State<ClinicCard> {
  ClinicsServiceTimingsResponse clinicsServiceTimingsResponse;

  @override
  void initState() {
    clinicsServiceTimingsResponse = new ClinicsServiceTimingsResponse();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Row(
      children: <Widget>[
        Card(
          margin: EdgeInsets.fromLTRB(13.0, 10.0, 8.0, 8.0),
          color: widget.isSelected ? Colors.blue : Colors.white,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(10),
          ),
          child: Container(
            width: MediaQuery.of(context).size.width * 0.8,
            padding: EdgeInsets.all(12.0),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              children: <Widget>[
                Container(
                  child: Text(
                      widget.languageID == 'ar'
                          ? widget.patientERGetClinicsList.serviceNameN
                          : widget.patientERGetClinicsList.serviceName,
                      style: TextStyle(
                          fontSize: 16.0,
                          color:
                              widget.isSelected ? Colors.white : Colors.black)),
                ),
              ],
            ),
          ),
        ),
        InkWell(
          onTap: () {
            getClinicTimings(widget.patientERGetClinicsList);
          },
          child: Card(
            margin: EdgeInsets.fromLTRB(8.0, 10.0, 8.0, 8.0),
            color: Colors.white,
            shape: RoundedRectangleBorder(
              borderRadius: BorderRadius.circular(8),
            ),
            child: Container(
              padding: EdgeInsets.all(8.0),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisSize: MainAxisSize.max,
                children: <Widget>[
                  Icon(Icons.access_time, size: 26.0, color: Colors.red[800]),
                ],
              ),
            ),
          ),
        ),
      ],
    );
  }

  getClinicTimings(PatientERGetClinicsList patientERGetClinicsList) {
    LiveCareService service = new LiveCareService();
    service
        .getLivecareClinicTiming(patientERGetClinicsList.serviceID, context)
        .then((res) {
      if (res['MessageStatus'] == 1) {
        setState(() {
          clinicsServiceTimingsResponse =
              ClinicsServiceTimingsResponse.fromJson(res);
          print(clinicsServiceTimingsResponse
              .patientERGetClinicsServiceTimingsList.length);

          showGeneralDialog(
              barrierColor: Colors.black.withOpacity(0.5),
              transitionBuilder: (context, a1, a2, widget) {
                final curvedValue =
                    Curves.easeInOutBack.transform(a1.value) - 1.0;
                return Transform(
                  transform:
                      Matrix4.translationValues(0.0, curvedValue * 200, 0.0),
                  child: Opacity(
                    opacity: a1.value,
                    child: ClinicTimingsDialog(
                      clinicName: patientERGetClinicsList.serviceName,
                      patientERGetClinicsServiceTimingsList:
                          clinicsServiceTimingsResponse
                              .patientERGetClinicsServiceTimingsList,
                    ),
                  ),
                );
              },
              transitionDuration: Duration(milliseconds: 500),
              barrierDismissible: true,
              barrierLabel: '',
              context: context,
              pageBuilder: (context, animation1, animation2) {});
        });
      } else {
        AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
      }
    }).catchError((err) {
      print(err);
    }).showProgressBar(
            text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6));
  }
}
