import 'package:doctor_app_flutter/core/viewModel/referral_view_model.dart';
import 'package:doctor_app_flutter/screens/base/base_view.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/doctor/my_referral_patient_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/material.dart';

import '../../widgets/shared/app_scaffold_widget.dart';

class MyReferralPatient extends StatefulWidget {
  int expandedItemIndex = -1;

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

class _MyReferralPatientState extends State<MyReferralPatient> {
  @override
  Widget build(BuildContext context) {
    return BaseView<ReferralPatientViewModel>(
        onModelReady: (model) => model.getMyReferralPatient(),
        builder: (_, model, w) => AppScaffold(
              baseViewModel: model,
              appBarTitle: TranslationBase.of(context).myReferralPatient,
              body: model.listMyReferralPatientModel.length == 0
                  ? Center(
                      child: AppText(
                        TranslationBase.of(context).errorNoSchedule,
                        color: Theme.of(context).errorColor,
                      ),
                    )
                  : Container(
                      padding: EdgeInsetsDirectional.fromSTEB(20, 0, 20, 0),
                      child: ListView(
                        children: <Widget>[
                          Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              SizedBox(
                                height: 10,
                              ),
                              Container(
                                child: Column(
                                  children: [
                                    ...List.generate(
                                      model.listMyReferralPatientModel.length,
                                      (index) => MyReferralPatientWidget(
                                        myReferralPatientModel: model
                                            .listMyReferralPatientModel[index],
                                        model: model,
                                        expandClick: () {
                                          setState(() {
                                            if (widget.expandedItemIndex ==
                                                index) {
                                              widget.expandedItemIndex = -1;
                                            } else {
                                              widget.expandedItemIndex = index;
                                            }
                                          });
                                        },
                                        isExpand:
                                            widget.expandedItemIndex == index,
                                      ),
                                    )
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ],
                      ),
                    ),
            ));
  }
}
