// ignore: must_be_immutable
import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class ClinicList extends StatelessWidget {

  ProjectViewModel projectsProvider;
  final int clinicId;
  final Function (int value) onClinicChange;

  ClinicList({Key key, this.clinicId, this.onClinicChange}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // authProvider = Provider.of(context);

    projectsProvider = Provider.of(context);
    return Container(
      child:
      projectsProvider
          .doctorClinicsList.length >
          0
          ? FractionallySizedBox(
        widthFactor: 0.9,
        child: Column(
          children: [
            Container(
              width: MediaQuery.of(context).size.width *0.8,
              child: Center(
                child: DropdownButtonHideUnderline(
                    child: DropdownButton(
                      dropdownColor:
                      Colors.white,
                      iconEnabledColor:
                      Colors.black,
                      isExpanded: true,
                      value: clinicId == null
                          ? projectsProvider
                          .doctorClinicsList[
                      0]
                          .clinicID
                          : clinicId,
                      iconSize: 25,
                      elevation: 16,
                      selectedItemBuilder:
                          (BuildContext
                      context) {
                        return projectsProvider
                            .doctorClinicsList
                            .map((item) {
                          return Row(
                            mainAxisSize:
                            MainAxisSize
                                .max,
                            children: <Widget>[
                              AppText(
                                item.clinicName,
                                fontSize: SizeConfig
                                    .textMultiplier *
                                    2.1,
                                color: Colors
                                    .black,
                              ),
                            ],
                          );
                        }).toList();
                      },
                      onChanged: (newValue){
                        onClinicChange(newValue);
                      },
                      items: projectsProvider
                          .doctorClinicsList
                          .map((item) {
                        return DropdownMenuItem(
                          child: Text(
                            item.clinicName,
                            textAlign:
                            TextAlign.end,
                          ),
                          value: item.clinicID,
                        );
                      }).toList(),
                    )),
              ),
            ),
          ],
        ),
      )
          : AppText(
          TranslationBase
              .of(context)
              .noClinic),
    );
  }
}