import 'package:doctor_app_flutter/config/config.dart';
import 'package:doctor_app_flutter/core/viewModel/project_view_model.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';

class PriorityBar extends StatefulWidget {
  final Function onTap;

  const PriorityBar({Key key, this.onTap}) : super(key: key);

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

class _PriorityBarState extends State<PriorityBar> {
  int _activePriority = 0;
  int index = -1;
  List<String> _priorities = [
    "Family",
    "Surgical/Sports",
    "Medical",
  ];
  List<String> _prioritiesAr = [
    "أسرة",
    "جراحي / رياضي",
    "طبي",
  ];

  BoxDecoration containerBorderDecoration(
      Color containerColor, Color borderColor) {
    return BoxDecoration();
  }

  @override
  Widget build(BuildContext context) {
    final screenSize = MediaQuery.of(context).size;
    ProjectViewModel projectViewModel = Provider.of(context);

    return Container(
      height: screenSize.height * 0.080,
      child: Row(
        mainAxisSize: MainAxisSize.max,
        crossAxisAlignment: CrossAxisAlignment.center,
        children: _priorities.map((
          item,
        ) {
          bool _isActive = _priorities[_activePriority] == item ? true : false;
          if (index < 2) {
            index++;
          }
          return Expanded(
            child: InkWell(
                child: Center(
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: [
                      Container(
                        height: screenSize.height * 0.070,
                        decoration: containerBorderDecoration(
                            _isActive ? HexColor("#B8382B") : Colors.white,
                            _isActive ? HexColor("#B8382B") : Colors.white),
                        child: Center(
                          child: Text(
                            (projectViewModel.isArabic)
                                ? _prioritiesAr[index]
                                : item,
                            textAlign: TextAlign.center,
                            style: TextStyle(
                              fontSize: 14,

                              color: Colors.black,
                              fontWeight: FontWeight.bold,
                            ),
                          ),
                        ),
                      ),
                      if(_isActive)
                      Container(width: 120,height: 4,color: AppGlobal.appPrimaryColor,)
                    ],
                  ),
                ),
                onTap: () {
                  widget.onTap(_priorities.indexOf(item));

                  setState(() {
                    _activePriority = _priorities.indexOf(item);
                  });
                }),
          );
        }).toList(),
      ),
    );
  }
}
