import 'package:cached_network_image/cached_network_image.dart';
import 'package:carousel_slider/carousel_slider.dart';
import 'package:diplomaticquarterapp/core/viewModels/pharmacyModule/pharmacy_module_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/pages/landing/home_page.dart';
import 'package:diplomaticquarterapp/pages/offers_categorise_page.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/screens/lacum-activitaion-vida-page.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/screens/lacum-registration-page.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/screens/lakum-main-page.dart';
import 'package:diplomaticquarterapp/pages/pharmacies/widgets/home/GridViewCard.dart';
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
import 'package:diplomaticquarterapp/uitl/utils.dart';
import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class BannerPager extends StatefulWidget {
  final PharmacyModuleViewModel _model;

  BannerPager(this._model);

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

class _BannerPagerState extends State<BannerPager> {
  int _current = 0;

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return Container(
        child: Column(
      children: [
        CarouselSlider(
          options: CarouselOptions(
            aspectRatio: 5 / 2,
            enlargeCenterPage: true,
            enableInfiniteScroll: false,
            viewportFraction: 1.0,
            initialPage: 0,
            autoPlay: true,
            autoPlayInterval: Duration(seconds: 3),
            autoPlayAnimationDuration: Duration(milliseconds: 800),
            autoPlayCurve: Curves.decelerate,
            onPageChanged: (index, reason) {
              setState(() {
                _current = index;
              });
            },
          ),
          items: widget._model.getBannerImagesUrl(projectViewModel).mapIndexed(
            (item, index) {
              return InkWell(
                onTap: () {
                  bannerNavigator(index);
                },
                child: Container(
                  margin: EdgeInsets.symmetric(horizontal: 1.0),
                  child: ClipRRect(
                    borderRadius: BorderRadius.all(Radius.circular(5.0)),
                    child: Center(
                      child: index == 0 || index == 1
                          ? Image.asset(
                              item,
                              fit: BoxFit.cover,
                            )
                          : CachedNetworkImage(imageUrl: item, fit: BoxFit.fitWidth, errorWidget: (context, url, error) => SizedBox()),
                    ),
                  ),
                ),
              );
            },
          ).toList(),
        ),
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: widget._model
                .getBannerImagesUrl(projectViewModel)
                .mapIndexed(
                  (item, index) => Container(
                    width: 12.0,
                    height: 4.0,
                    margin: EdgeInsets.symmetric(vertical: 0.0, horizontal: 2.0),
                    decoration: BoxDecoration(
                      shape: BoxShape.rectangle,
                      color: _current == index ? Color.fromRGBO(0, 250, 0, 0.9) : Color.fromRGBO(0, 0, 0, 0.4),
                    ),
                  ),
                )
                .toList(),
          ),
        )
      ],
    ));
  }

  bannerNavigator(index){
    switch(index) {
      case 1: {
        Navigator.push(context, FadePage(page: OffersCategorisePage()));
      }
      break;
      case 2: {
        // Navigator.push(context, FadePage(page: LakumActivationVidaPage()));
        Navigator.push(context, FadePage(page: LakumMainPage()));
      }
      break;
      case 5: {
        Navigator.push(context, FadePage(page: OffersCategorisePage()));
      }
      break;

      default: {

      }
      break;
    }

  }
}
