import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart';
import 'package:diplomaticquarterapp/core/viewModels/insurance_card_View_model.dart';
import 'package:diplomaticquarterapp/theme/colors.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../base/base_view.dart';
import 'insurance_page.dart';

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

class _InsuranceUpdateState extends State<InsuranceUpdate> with SingleTickerProviderStateMixin {
  TabController _tabController;
  List<ImagesInfo> imagesInfo = List();

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

    imagesInfo.add(ImagesInfo(
        imageEn: 'https://hmgwebservices.com/Images/MobileApp/imges-info/insurance-card/en/0.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/imges-info/insurance-card/ar/0.png'));
  }

  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: TranslationBase.of(context).updateInsurCards,
        description: TranslationBase.of(context).infoInsurCards,
        infoList: TranslationBase.of(context).infoPrescriptionsPoints,
        imagesInfo: imagesInfo,
        isShowAppBar: true,
        isShowDecPage: true,
        baseViewModel: model,
        showNewAppBarTitle: true,
        showNewAppBar: true,
        backgroundColor: CustomColors.appBackgroudGreyColor,
        body: Column(
          children: <Widget>[
            Container(
              height: 45,
              child: TabBar(
                controller: _tabController,
                isScrollable: false,
                indicatorWeight: 3.0,
                indicatorColor: CustomColors.accentColor,
                labelColor: Theme.of(context).primaryColor,
                labelPadding: EdgeInsets.symmetric(horizontal: 13.0, vertical: 2.0),
                unselectedLabelColor: Colors.grey,
                tabs: <Widget>[
                  Container(
                    child: Center(
                      child: Text(
                        TranslationBase.of(context).updateInsuranceSubtitle,
                        style: TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.w600,
                          letterSpacing: -0.48,
                        ),
                      ),
                    ),
                  ),
                  Container(
                    child: Center(
                      child: Text(
                        TranslationBase.of(context).history,
                        style: TextStyle(
                          fontSize: 16,
                          fontWeight: FontWeight.w600,
                          letterSpacing: -0.48,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
            Expanded(
                child: TabBarView(
              physics: BouncingScrollPhysics(),
              controller: _tabController,
              children: <Widget>[
                InsurancePage(model: model),
                Container(
                  child: Padding(
                    padding: const EdgeInsets.all(12.0),
                    child: ListView.builder(
                        itemCount: model.insuranceUpdate == null ? 0 : model.insuranceUpdate.length,
                        itemBuilder: (BuildContext context, int index) {
                          return Container(
                            child: Card(
                              color: Colors.white,
                              elevation: 2,
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(12),
                              ),
                              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(
                                                  model.user.firstName + " " + model.user.lastName,
                                                  style: TextStyle(
                                                    fontSize: 14,
                                                    fontWeight: FontWeight.w600,
                                                    letterSpacing: -0.46,
                                                  ),
                                                ),
                                                SizedBox(
                                                  height: 4,
                                                ),
                                                Text(
                                                  TranslationBase.of(context).fileno + ": " + model.insuranceUpdate[index].patientID.toString(),
                                                  style: TextStyle(
                                                    fontSize: 14,
                                                    fontWeight: FontWeight.w600,
                                                    letterSpacing: -0.46,
                                                  ),
                                                ),

                                                Text(
                                                  model.insuranceUpdate[index].createdOn,
                                                  style: TextStyle(
                                                    fontSize: 14,
                                                    fontWeight: FontWeight.w600,
                                                    letterSpacing: -0.46,
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                        ),
                                        Expanded(
                                          flex: 1,
                                          child: Container(
                                            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: 6.5, left: 2.0),
                                                  child: Text(
                                                    model.insuranceUpdate[index].statusDescription,
                                                    style: TextStyle(
                                                      fontSize: 10,
                                                      fontWeight: FontWeight.w600,
                                                      letterSpacing: -0.46,
                                                    ),
                                                  ),
                                                ),
                                              ],
                                            ),
                                          ),
                                        )
                                      ],
                                    ),
                                  ],
                                ),
                              ),
                            ),
                          );
                        }),
                  ),
                ),
              ],
            ))
          ],
        ),
      ),
    );
  }
}
