import 'dart:ui';

import 'package:diplomaticquarterapp/core/model/ImagesInfo.dart';
import 'package:diplomaticquarterapp/core/viewModels/medical/reports_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/extensions/string_extensions.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/pages/medical/reports/report_list_widget.dart';
import 'package:diplomaticquarterapp/pages/medical/reports/reports_page.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/buttons/defaultButton.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class HomeReportPage extends StatefulWidget {
  @override
  _HomeReportPageState createState() => _HomeReportPageState();
}

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

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

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

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    imagesInfo.add(ImagesInfo(
        imageEn: 'https://hmgwebservices.com/Images/MobileApp/imges-info/medical-reorts/en/0.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/imges-info/medical-reorts/ar/0.png'));
    imagesInfo.add(ImagesInfo(
        imageEn: 'https://hmgwebservices.com/Images/MobileApp/imges-info/medical-reorts/en/1.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/imges-info/medical-reorts/ar/1.png'));
    imagesInfo.add(ImagesInfo(
        imageEn: 'https://hmgwebservices.com/Images/MobileApp/imges-info/medical-reorts/en/2.png', imageAr: 'https://hmgwebservices.com/Images/MobileApp/imges-info/medical-reorts/ar/2.png'));
    return BaseView<ReportsViewModel>(
      onModelReady: (model) => model.getReports(), //model.getPrescriptions(),
      builder: (_, model, widget) => AppScaffold(
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).newMedReport,
        title: TranslationBase.of(context).medReport,
        description: TranslationBase.of(context).infoMonthReport,
        baseViewModel: model,
        showNewAppBar: true,
        showNewAppBarTitle: true,
        backgroundColor: Color(0xffF7F7F7),
        imagesInfo: imagesInfo,
        body: Column(
          children: [
            TabBar(
              isScrollable: true,
              controller: _tabController,
              indicatorWeight: 3.0,
              indicatorSize: TabBarIndicatorSize.tab,
              labelColor: Color(0xff2B353E),
              unselectedLabelColor: Color(0xff575757),
              labelPadding: EdgeInsets.only(top: 15, bottom: 13, left: 20, right: 20),
              labelStyle: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w600,
                letterSpacing: -0.48,
              ),
              unselectedLabelStyle: TextStyle(
                fontSize: 16,
                fontWeight: FontWeight.w600,
                letterSpacing: -0.48,
              ),
              tabs: [
                Text(
                  TranslationBase.of(context).requested,
                  style: TextStyle(fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins'),
                ),
                Text(
                  TranslationBase.of(context).ready,
                  style: TextStyle(fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins'),
                ),
                Text(
                  TranslationBase.of(context).completed,
                  style: TextStyle(fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins'),
                ),
                Text(
                  TranslationBase.of(context).cancelled,
                  style: TextStyle(fontFamily: projectViewModel.isArabic ? 'Cairo' : 'Poppins'),
                ),
              ],
            ),
            if (model.user != null)
              Expanded(
                child: TabBarView(
                  physics: BouncingScrollPhysics(),
                  controller: _tabController,
                  children: <Widget>[
                    ReportListWidget(reportList: model.reportsOrderRequestList, emailAddress: model.user.emailAddress),
                    ReportListWidget(reportList: model.reportsOrderReadyList, emailAddress: model.user.emailAddress),
                    ReportListWidget(reportList: model.reportsOrderCompletedList, emailAddress: model.user.emailAddress),
                    ReportListWidget(reportList: model.reportsOrderCanceledList, emailAddress: model.user.emailAddress),
                  ],
                ),
              ),
            if (projectViewModel.havePrivilege(21))
              Padding(
                padding: EdgeInsets.only(top: 16, bottom: 16, right: 21, left: 21),
                child: DefaultButton(
                  TranslationBase.of(context).requestMedicalReport.toLowerCase().capitalizeFirstofEach,
                  () => Navigator.push(
                    context,
                    FadePage(
                      page: MedicalReports(),
                    ),
                  ),
                ),
              )
          ],
        ),
      ),
    );
  }
}
