import 'package:diplomaticquarterapp/config/size_config.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/vaccine_view_model.dart';
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/widgets/data_display/text.dart';
import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

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

class MyVaccinesItemPage extends StatefulWidget {
  @override
  _MyVaccinesItemPageState createState() => _MyVaccinesItemPageState();
}

class _MyVaccinesItemPageState extends State<MyVaccinesItemPage> {
  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<VaccineViewModel>(
      onModelReady: (model) => model.getMyVaccinationItem(),
      builder: (BuildContext context, VaccineViewModel model, Widget child) =>
          AppScaffold(
        isShowAppBar: true,
        appBarTitle: TranslationBase.of(context).myVaccinesAvailability,
        baseViewModel: model,
        body: Container(
          margin: EdgeInsets.only(
            left: SizeConfig.screenWidth * 0.004,
            right: SizeConfig.screenWidth * 0.004,
            top: SizeConfig.screenWidth * 0.04,
          ),
          child: ListView.builder(
            itemCount: model.vaccinationItemList.length,
            itemBuilder: (context, index) => InkWell(
              onTap: () async {
                await model.getMyVaccinationOnHand(
                    pItemCode: model.vaccinationItemList[index].iTEMCODE);
                if (model.hasError) {
                  AppToast.showErrorToast(message: model.error);
                } else {
                  //TODO show dialog

                }
              },
              child: Container(
                margin: EdgeInsets.all(5),
                padding: EdgeInsets.all(10),
                decoration: BoxDecoration(
                  shape: BoxShape.rectangle,
                  borderRadius: BorderRadius.circular(7),
                  color: Colors.white,
                ),
                child: Row(
                  children: [
                    Expanded(
                        child: Texts(
                            model.vaccinationItemList[index].dESCRIPTION)),
                    Icon(projectViewModel.isArabic
                        ? Icons.arrow_forward
                        : Icons.arrow_back_ios)
                  ],
                ),
              ),
            ),
          ),
        ),
      ),
    );
  }
}
