import 'package:diplomaticquarterapp/core/model/vital_sign/vital_sign_res_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/uitl/date_uitl.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.dart';
import 'package:provider/provider.dart';

class VitalSignDetailsWidget extends StatefulWidget {
  final List<VitalSignResModel> vitalList;
  final String title1;
  final String title2;
  final String viewKey;

  VitalSignDetailsWidget(
      {Key key, this.vitalList, this.title1, this.title2, this.viewKey});

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

class _VitalSignDetailsWidgetState extends State<VitalSignDetailsWidget> {
  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return Container(
      decoration: BoxDecoration(
        color: Colors.transparent,
        borderRadius: BorderRadius.only(
            topLeft: Radius.circular(10.0), topRight: Radius.circular(10.0)),
        border: Border.all(color: Colors.grey, width: 1),
      ),
      margin: EdgeInsets.all(20),
      child: Container(
        color: Colors.transparent,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Table(
              border: TableBorder.symmetric(
                inside: BorderSide(width: 2.0, color: Colors.grey[300]),
              ),
              children: fullData(projectViewModel),
            ),
          ],
        ),
      ),
    );
  }

  List<TableRow> fullData(ProjectViewModel projectViewModel) {
    List<TableRow> tableRow = [];
    tableRow.add(TableRow(children: [
      Container(
        child: Container(
          decoration: BoxDecoration(
            color: Theme.of(context).primaryColor,
            borderRadius: BorderRadius.only(
              topLeft:projectViewModel.isArabic? Radius.circular(0.0):Radius.circular(10.0),
              topRight: projectViewModel.isArabic? Radius.circular(10.0):Radius.circular(0.0)
            ),
          ),
          child: Center(
            child: Texts(
              TranslationBase.of(context).date,
              color: Colors.white,
            ),
          ),
          height: 60,
        ),
      ),
      Container(
        child: Container(
            decoration: BoxDecoration(
              color: Theme.of(context).primaryColor,
              borderRadius: BorderRadius.only(
                topRight: projectViewModel.isArabic? Radius.circular(0.0):Radius.circular(10.0),
                topLeft: projectViewModel.isArabic? Radius.circular(10.0):Radius.circular(0.0)
              ),
            ),
            child: Center(
              child: Texts(widget.title2, color: Colors.white),
            ),
            height: 60),
      )
    ]));
    widget.vitalList.forEach((vital) {
      var data = vital.toJson()[widget.viewKey];
      if (data != 0)
        tableRow.add(TableRow(children: [
          Container(
            child: Container(
              padding: EdgeInsets.all(10),
              color: Colors.white,
              child: Center(
                child: Texts(
                  '${projectViewModel.isArabic ? DateUtil.getWeekDayArabic(vital.vitalSignDate.weekday) : DateUtil.getWeekDay(vital.vitalSignDate.weekday)}, ${vital.vitalSignDate.day} ${projectViewModel.isArabic ? DateUtil.getMonthArabic(vital.vitalSignDate.month) : DateUtil.getMonth(vital.vitalSignDate.month)}, ${vital.vitalSignDate.year} ',
                  textAlign: TextAlign.center,
                ),
              ),
            ),
          ),
          Container(
            child: Container(
              padding: EdgeInsets.all(10),
              color: Colors.white,
              child: Center(
                child: Texts(
                  '${vital.toJson()[widget.viewKey]}',
                  textAlign: TextAlign.center,
                ),
              ),
            ),
          ),
        ]));
    });
    return tableRow;
  }
}
