import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart';
import 'package:flutter/material.dart';
import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:flutter/cupertino.dart';
import '../base/base_view.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/core/viewModels/insurance_card_View_model.dart';
import 'package:diplomaticquarterapp/widgets/others/rounded_container.dart';
import 'package:rating_bar/rating_bar.dart';
import 'package:diplomaticquarterapp/widgets/buttons/button.dart';

class InsuranceUpdate extends StatefulWidget {
  @override
  _InsuranceUpdateState createState() => _InsuranceUpdateState();
}

class _InsuranceUpdateState extends State<InsuranceUpdate>
    with SingleTickerProviderStateMixin {
  TabController _tabController;

  @override
  void initState() {
    super.initState();
    _tabController = TabController(length: 2, vsync: this);
  }

  void dispose() {
    super.dispose();
    _tabController.dispose();
  }

  Widget build(BuildContext context) {
    return BaseView<InsuranceViewModel>(
      onModelReady: (model) => model.getInsuranceUpdated(),
      builder: (BuildContext context, InsuranceViewModel model, Widget child) =>
          AppScaffold(
        appBarTitle: 'Insurance Cards',
        isShowAppBar: true,
        baseViewModel: model,
        body: Scaffold(
          extendBodyBehindAppBar: true,
          appBar: PreferredSize(
            preferredSize: Size.fromHeight(70.0),
            child: Stack(
              children: <Widget>[
                Center(
                  child: Container(
                    height: 60.0,
                    margin: EdgeInsets.only(top: 10.0),
                    width: MediaQuery.of(context).size.width * 1.9,
                    decoration: BoxDecoration(
                      border: Border(
                        bottom: BorderSide(
                          color: Theme.of(context).dividerColor,
                          width: 5.7,
                        ),
                      ),
                      color: Colors.white,
                    ),
                    child: Center(
                      child: TabBar(
                        controller: _tabController,
                        isScrollable: true,
                        indicatorWeight: 4.0,
                        indicatorColor: Colors.red,
                        labelColor: Theme.of(context).primaryColor,
                        labelPadding: EdgeInsets.symmetric(
                            horizontal: 13.0, vertical: 2.0),
                        unselectedLabelColor: Colors.grey,
                        tabs: <Widget>[
                          Container(
                            width: MediaQuery.of(context).size.width * 0.35,
                            child: Center(
                              child: Texts('Card'),
                            ),
                          ),
                          Container(
                            width: MediaQuery.of(context).size.width * 0.35,
                            child: Center(
                              child: Texts('History'),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                )
              ],
            ),
          ),
          body: Column(
            children: <Widget>[
              Expanded(
                  child: TabBarView(
                physics: BouncingScrollPhysics(),
                controller: _tabController,
                children: <Widget>[
                  Container(
                    child: ListView.builder(
                        itemCount: model.getAllSharedRecordsByStatusResponse
                                    .getAllSharedRecordsByStatusList ==
                                null
                            ? 0
                            : model.getAllSharedRecordsByStatusResponse
                                .getAllSharedRecordsByStatusList.length,
                        itemBuilder: (BuildContext context, int index) {
                          return Container(
                            margin: EdgeInsets.all(10.0),
                            child: Card(
                              margin: EdgeInsets.fromLTRB(8.0, 16.0, 8.0, 8.0),
                              color: Colors.white,
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(10),
                              ),
                              child: Container(
                                width: MediaQuery.of(context).size.width,
                                padding: EdgeInsets.all(10.0),
                                child: Row(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  mainAxisSize: MainAxisSize.max,
                                  children: <Widget>[
                                    Expanded(
                                      flex: 3,
                                      child: Container(
                                        margin: EdgeInsets.only(
                                            top: 2.0, left: 10.0, right: 20.0),
                                        child: Column(
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: <Widget>[
                                            Text(
                                                model.getAllSharedRecordsByStatusResponse
                                                        .getAllSharedRecordsByStatusList[
                                                    index].patientName,
                                                style: TextStyle(
                                                    fontSize: 14.0,
                                                    color: Colors.black,
                                                    fontWeight: FontWeight.w500,
                                                    letterSpacing: 1.0)),
                                            Text(
                                                'File No.' +
                                                    model.getAllSharedRecordsByStatusResponse
                                                        .getAllSharedRecordsByStatusList[
                                                    index].patientID.toString(),
                                                style: TextStyle(
                                                    fontSize: 14.0,
                                                    color: Colors.black,
                                                    fontWeight: FontWeight.w500,
                                                    letterSpacing: 1.0)),
                                          ],
                                        ),
                                      ),
                                    ),
                                    Expanded(
                                      flex: 2,
                                      child: Container(
                                        // height: MediaQuery.of(context).size.height * 0.12,
                                        margin: EdgeInsets.only(top: 2.0),
                                        child: Column(
                                          children: <Widget>[
                                            Container(
                                              child: SecondaryButton(
                                                label: 'Update',
                                                small: true,
                                                textColor: Colors.white,
                                                // color: Colors.grey,
                                              ),
                                              //height: 45,
                                              // width:90
                                            ),
                                          ],
                                        ),
                                      ),
                                    )
                                  ],
                                ),
                              ),
                            ),
                          );
                        }),
                  ),
                  Container(
                    child: ListView.builder(
                        itemCount: model.insuranceUpdate == null
                            ? 0
                            : model.insuranceUpdate.length,
                        itemBuilder: (BuildContext context, int index) {
                          return Container(
                            margin: EdgeInsets.all(10.0),
                            child: Card(
                              margin: EdgeInsets.fromLTRB(8.0, 16.0, 8.0, 8.0),
                              color: Colors.white,
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(10),
                              ),
                              child: Container(
                                width: MediaQuery.of(context).size.width,
                                padding: EdgeInsets.all(10.0),
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  mainAxisSize: MainAxisSize.max,
                                  children: <Widget>[
                                    Flex(
                                      direction: Axis.horizontal,
                                      children: <Widget>[
                                        Expanded(
                                          flex: 3,
                                          child: Container(
                                            margin: EdgeInsets.only(
                                                top: 2.0,
                                                left: 10.0,
                                                right: 20.0),
                                            child: Column(
                                              crossAxisAlignment:
                                                  CrossAxisAlignment.start,
                                              children: <Widget>[
                                                Text("TAMER FANASHEH ",
                                                    style: TextStyle(
                                                        fontSize: 14.0,
                                                        color: Colors.black,
                                                        fontWeight:
                                                            FontWeight.w500,
                                                        letterSpacing: 1.0)),
                                                Text(
                                                    'File No.' +
                                                        model
                                                            .insuranceUpdate[
                                                                index]
                                                            .patientID
                                                            .toString(),
                                                    style: TextStyle(
                                                        fontSize: 14.0,
                                                        color: Colors.black,
                                                        fontWeight:
                                                            FontWeight.w500,
                                                        letterSpacing: 1.0)),
                                                Text(
                                                    model.insuranceUpdate[index]
                                                        .createdOn,
                                                    style: TextStyle(
                                                        fontSize: 14.0,
                                                        color: Colors.black,
                                                        fontWeight:
                                                            FontWeight.w500,
                                                        letterSpacing: 1.0)),
                                              ],
                                            ),
                                          ),
                                        ),
                                        Expanded(
                                          flex: 1,
                                          child: Container(
//                      height: MediaQuery.of(context).size.height * 0.12,
                                            margin: EdgeInsets.only(top: 20.0),
                                            child: Column(
                                              children: <Widget>[
                                                Image.asset(
                                                    "assets/images/new-design/confirm_button.png",
                                                    width: 30.0,
                                                    height: 30.0),
                                                Container(
                                                  margin: EdgeInsets.only(
                                                      top: 13.5, left: 2.0),
                                                  child: Text(
                                                      model
                                                          .insuranceUpdate[
                                                              index]
                                                          .statusDescription,
                                                      textAlign:
                                                          TextAlign.center,
                                                      style: TextStyle(
                                                          fontSize: 12.0)),
                                                ),
                                              ],
                                            ),
                                          ),
                                        )
                                      ],
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          );
                        }),
                  ),
                ],
              ))
            ],
          ),
        ),
      ),
    );
  }
}
