import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/models/patient/prescription/prescription_report_for_in_patient.dart';
import 'package:doctor_app_flutter/util/helpers.dart';
import 'package:doctor_app_flutter/widgets/shared/app_scaffold_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:doctor_app_flutter/widgets/shared/card_with_bgNew_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:doctor_app_flutter/util/translations_delegate_base.dart';

class InpatientPrescriptionDetailsScreen extends StatefulWidget {
  @override
  _InpatientPrescriptionDetailsScreenState createState() =>
      _InpatientPrescriptionDetailsScreenState();
}

class _InpatientPrescriptionDetailsScreenState
    extends State<InpatientPrescriptionDetailsScreen> {
  bool _showDetails = false;
  String error;
  TextEditingController answerController;
  bool _isInit = true;
  PrescriptionReportForInPatient prescription;

  @override
  void initState() {
    super.initState();
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    if (_isInit) {
      final routeArgs = ModalRoute.of(context).settings.arguments as Map;
      prescription = routeArgs['prescription'];
    }
    _isInit = false;
  }

  @override
  Widget build(BuildContext context) {
    return AppScaffold(
      appBarTitle: TranslationBase.of(context).prescriptionInfo,
      body: CardWithBgWidgetNew(
        widget: Container(
          child: ListView(
            children: <Widget>[
              Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  AppText(
                    prescription.itemDescription,
                    fontSize: 2.5 * SizeConfig.textMultiplier,
                    fontWeight: FontWeight.bold,
                  ),
                  InkWell(
                      onTap: () {
                        setState(() {
                          _showDetails = !_showDetails;
                        });
                      },
                      child: Icon(_showDetails
                          ? Icons.keyboard_arrow_up
                          : Icons.keyboard_arrow_down)),
                ],
              ),
              !_showDetails
                  ? Container()
                  : AnimatedContainer(
                      duration: Duration(milliseconds: 200),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: <Widget>[
                          SizedBox(
                            height: 5,
                          ),
                          Divider(
                            color: Color(0xFF000000),
                            height: 0.5,
                          ),
                          Table(
                            border: TableBorder.symmetric(
                              inside: BorderSide(width: 0.5),
                            ),
                            children: [
                              buildTableRow(
                                  des: '${prescription.direction}',
                                  key: 'Direction'),
                              buildTableRow(
                                  des: '${prescription.refillID}',
                                  key: 'Refill'),
                              buildTableRow(
                                  des: '${prescription.dose}', key: 'Dose'),
                              buildTableRow(
                                  des: '${prescription.unitofMeasurement}',
                                  key: 'UOM'),
                              buildTableRow(
                                  des:
                                      '${Helpers.getDate(prescription.startDatetime)}',
                                  key: 'Start Date'),
                              buildTableRow(
                                  des:
                                      '${Helpers.getDate(prescription.stopDatetime)}',
                                  key: 'Stop Date'),
                              buildTableRow(
                                  des: '${prescription.noOfDoses}',
                                  key: 'No of Doses'),
                              buildTableRow(
                                  des: '${prescription.route}', key: 'Route'),
                              buildTableRow(
                                  des: '${prescription.comments}',
                                  key: 'Comments'),
                              buildTableRow(
                                  des: '${prescription.pharmacyRemarks}',
                                  key: 'Pharmacy Remarks'),
                              buildTableRow(
                                  des:
                                      '${Helpers.getDate(prescription.prescriptionDatetime)}',
                                  key: 'Prescription Date'),
                              buildTableRow(
                                  des: '${prescription.refillID}',
                                  key: 'Status'),
                              buildTableRow(
                                  des: '${prescription.refillID}',
                                  key: 'Created By'),
                              buildTableRow(
                                  des: '${prescription.refillID}',
                                  key: 'Processed By'),
                              buildTableRow(
                                  des: '${prescription.refillID}',
                                  key: 'Authorized By'),
                            ],
                          ),
                          Divider(
                            color: Color(0xFF000000),
                            height: 0.5,
                          ),
                          SizedBox(
                            height: 5,
                          ),
                        ],
                      ),
                    )
            ],
          ),
        ),
      ),
    );
  }

  TableRow buildTableRow({des, key}) {
    print('$key: $des');
    return TableRow(children: [
      Container(
        margin: EdgeInsets.all(2.5),
        padding: EdgeInsets.all(5),
        child: Row(
          children: <Widget>[
            Expanded(
              child: Container(
                child: AppText(
                  key,
                  fontSize: 1.7 * SizeConfig.textMultiplier,
                  fontWeight: FontWeight.bold,
                  textAlign: TextAlign.start,
                ),
              ),
            ),
            Expanded(
              child: Container(
                margin:
                    EdgeInsets.only(left: 4, top: 2.5, right: 2.5, bottom: 2.5),
                padding: EdgeInsets.all(5),
                child: Column(
                  crossAxisAlignment: CrossAxisAlignment.center,
                  children: <Widget>[
                    AppText(
                      '${des}',
                      fontSize: 1.7 * SizeConfig.textMultiplier,
                      fontWeight: FontWeight.w300,
                      textAlign: TextAlign.center,
                    )
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    ]);
  }
}
