import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/models/LiveCare/ClinicsServiceTimingsResponse.dart';
import 'package:diplomaticquarterapp/models/LiveCare/ERAppointmentFeesResponse.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils_new.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:provider/provider.dart';

class ClinicTimingsPage extends StatefulWidget {
  final clinicName;
  final List<PatientERGetClinicsServiceTimingsList> patientERGetClinicsServiceTimingsList;

  ClinicTimingsPage({@required this.clinicName, @required this.patientERGetClinicsServiceTimingsList});

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

class _LiveCarePatmentPageState extends State<ClinicTimingsPage> {
  ProjectViewModel projectViewModel;

  @override
  Widget build(BuildContext context) {
    projectViewModel = Provider.of(context);
    return AppScaffold(
      appBarTitle: TranslationBase.of(context).clinicSchedule,
      isShowAppBar: true,
      showNewAppBarTitle: true,
      showNewAppBar: true,
      description: TranslationBase.of(context).erConsultation,
      body: Container(
        width: double.infinity,
        height: double.infinity,
        child: Column(
          children: [
            Expanded(
              child: ListView.separated(
                itemBuilder: (context, index) {
                  return Padding(
                    padding: EdgeInsets.only(top: index == 0 ? 12 : 0, bottom: (index == widget.patientERGetClinicsServiceTimingsList.length - 1) ? 12 : 0),
                    child: showItem(widget.patientERGetClinicsServiceTimingsList[index]),
                  );
                },
                separatorBuilder: (context, index) {
                  return mHeight(12);
                },
                itemCount: widget.patientERGetClinicsServiceTimingsList.length,
              ),
            ),
            Container(
              width: double.infinity,
              padding: EdgeInsets.all(12),
              color: Colors.white,
              child: DefaultButton(
                TranslationBase.of(context).back,
                () {
                  Navigator.pop(context);
                },
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget showItem(PatientERGetClinicsServiceTimingsList item) {
    return Container(
      width: double.infinity,
      padding: EdgeInsets.only(left: 12, right: 12),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          Expanded(
            flex: 2,
            child: Text(
              item.dayOfWeekStr,
              style: TextStyle(
                fontSize: 18,
                letterSpacing: -0.72,
                fontWeight: FontWeight.bold,
              ),
            ),
          ),
          Expanded(
            flex: 4,
            child: Container(
              width: double.infinity,
              decoration: cardRadius(12),
              padding: EdgeInsets.all(12),
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                mainAxisAlignment: MainAxisAlignment.start,
                children: [
                  for (int i = 0; i < item.shiftTimings.length; i++)
                    Text(
                      TranslationBase.of(context).from + " " + item.shiftTimings[i].startTime + " " + TranslationBase.of(context).to + " " + item.shiftTimings[i].endTime,
                      style: TextStyle(
                        fontSize: 13,
                        letterSpacing: -0.42,
                        fontWeight: FontWeight.w600,
                      ),
                    )
                ],
              ),
            ),
          ),
        ],
      ),
    );
  }
}
