import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/enum/patient_type.dart';
import 'package:doctor_app_flutter/core/model/PatientSearchRequestModel.dart';
import 'package:doctor_app_flutter/core/viewModel/PatientSearchViewModel.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';
import 'package:doctor_app_flutter/widgets/shared/loader/gif_loader_dialog_utils.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';

class TimeBar extends StatefulWidget {
  final PatientSearchViewModel model;
  final PatientType selectedPatientType;
  final PatientSearchRequestModel patientSearchRequestModel;
  final bool isSearchWithKeyInfo;


  const TimeBar({Key key, this.model, this.selectedPatientType, this.patientSearchRequestModel, this.isSearchWithKeyInfo}) : super(key: key);
  @override
  _TimeBarState createState() => _TimeBarState();
}

class _TimeBarState extends State<TimeBar> {
  

  @override
  Widget build(BuildContext context) {
    List _locations = [
      TranslationBase.of(context).today,
      TranslationBase.of(context).tomorrow,
      TranslationBase.of(context).nextWeek,
    ];
    int _activeLocation = 0;
    return Container(
      height: MediaQuery.of(context).size.height * 0.0619,
      width: SizeConfig.screenWidth * 0.94,
      decoration: BoxDecoration(
        color: Color(0Xffffffff),
        borderRadius: BorderRadius.circular(12.5),
        // border: Border.all(
        //   width: 0.5,
        // ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: _locations.map((item) {
          bool _isActive = _locations[_activeLocation] == item ? true : false;
          return Column(mainAxisSize: MainAxisSize.min, children: <Widget>[
            InkWell(
                child: Center(
                  child: Container(
                      height: MediaQuery.of(context).size.height * 0.058,
                      width: SizeConfig.screenWidth * 0.2334,
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.only(
                            bottomRight: Radius.circular(12.5),
                            topRight: Radius.circular(12.5),
                            topLeft: Radius.circular(9.5),
                            bottomLeft: Radius.circular(9.5)),
                        color: _isActive ? HexColor("#B8382B") : Colors.white,
                      ),
                      child: Center(
                        child: Text(
                          item,
                          style: TextStyle(
                            fontSize: 12,
                            color: _isActive
                                ? Colors.white
                                : Colors.black, //Colors.black,

                            fontWeight: FontWeight.normal,
                          ),
                        ),
                      )),
                ),
                onTap: () async{
                  setState(() {
                    _activeLocation = _locations.indexOf(item);
                  });
                  GifLoaderDialogUtils.showMyDialog(context);
                  await widget.model.getPatientBasedOnDate(item:item,selectedPatientType:widget.selectedPatientType, patientSearchRequestModel:widget.patientSearchRequestModel, isSearchWithKeyInfo:widget.isSearchWithKeyInfo);
                  GifLoaderDialogUtils.hideDialog(context);
                }),
            _isActive
                ? Container(
              decoration: BoxDecoration(
                  borderRadius: BorderRadius.only(
                      bottomRight: Radius.circular(10),
                      topRight: Radius.circular(10)),
                  color: Colors.white),
              alignment: Alignment.center,
              height: 1,
              width: SizeConfig.screenWidth * 0.23,
            )
                : Container()
          ]);
        }).toList(),
      ),
    );
  }
}
