import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/models/patient/prescription/prescription_report.dart';
import 'package:doctor_app_flutter/widgets/shared/app_texts_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

class OutPatientPrescriptionDetailsItem extends StatefulWidget {
  final PrescriptionReport prescriptionReport;

  OutPatientPrescriptionDetailsItem({Key key, this.prescriptionReport});

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

class _OutPatientPrescriptionDetailsItemState
    extends State<OutPatientPrescriptionDetailsItem> {
  bool _showDetails = false;

  @override
  Widget build(BuildContext context) {
    return Container(
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Row(
            children: <Widget>[
              Expanded(
                flex: 5,
                child: AppText(
                  '${widget.prescriptionReport.itemDescription} ',
                  fontSize: 2.5 * SizeConfig.textMultiplier,
                  fontWeight: FontWeight.bold,
                ),
              ),
              Expanded(
                flex: 1,
                child: 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(
                        key: 'Route',
                        des: widget.prescriptionReport.route),
                    buildTableRow(
                        key: 'Frequency Timing',
                        des: widget.prescriptionReport.frequency),
                    buildTableRow(key: 'Insurance Covered', des: ''),
                    buildTableRow(
                        key: 'Duration Days',
                        des: widget.prescriptionReport.days),
                    buildTableRow(
                        key: 'IDoctor Remarks',
                        des: widget.prescriptionReport.remarks),
                  ],
                ),
                Divider(
                  color: Color(0xFF000000),
                  height: 0.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,
                    )
                  ],
                ),
              ),
            ),
          ],
        ),
      ),
    ]);
  }
}