import 'package:doctor_app_flutter/models/patient/vital_sign/vital_sign_res_model.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:doctor_app_flutter/widgets/shared/Text.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:hexcolor/hexcolor.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) {
    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(),
            ),
          ],
        ),
      ),
    );
  }

  List<TableRow>  fullData(){
    List<TableRow> tableRow = [];
    tableRow.add(TableRow(children: [
      Container(
        child: Container(
          decoration: BoxDecoration(
            color: HexColor('#515B5D'),
            borderRadius: BorderRadius.only(
              topLeft: Radius.circular(10.0),
            ),
          ),
          child: Center(
            child: Texts(
              widget.title1,
              color: Colors.white,
            ),
          ),
          height: 60,
        ),
      ),
      Container(
        child: Container(
            decoration: BoxDecoration(
              color: HexColor('#515B5D'),
              borderRadius: BorderRadius.only(
                topRight: Radius.circular(10.0),
              ),
            ),
            child: Center(
              child: Texts(widget.title2, color: Colors.white),
            ),
            height: 60),
      )
    ]));
    widget.vitalList.forEach((vital) {
      tableRow.add(TableRow(children: [
        Container(
          child: Container(
            padding: EdgeInsets.all(10),
            color: Colors.white,
            child: Center(
              child: Texts(
                '${Helpers.getWeekDay(vital.vitalSignDate.weekday)}, ${vital.vitalSignDate.day} ${Helpers.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;
  }

}
