import 'package:doctor_app_flutter/config/size_config.dart';
import 'package:doctor_app_flutter/core/viewModel/dashboard_view_model.dart';
import 'package:doctor_app_flutter/models/dashboard/dashboard_model.dart';
import 'package:doctor_app_flutter/widgets/dashboard/out_patient_stack.dart';
import 'package:doctor_app_flutter/widgets/dashboard/swiper_rounded_pagination.dart';
import 'package:doctor_app_flutter/widgets/shared/rounded_container_widget.dart';
import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';

import 'dashboard_referral_patient.dart';

class DashboardSwipeWidget extends StatefulWidget {
  final List<DashboardModel> dashboardItemList;
  final DashboardViewModel model;
  final Function(int) sliderChange;

  DashboardSwipeWidget(this.dashboardItemList, this.model, this.sliderChange);

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

class _DashboardSwipeWidgetState extends State<DashboardSwipeWidget> {
  int sliderActiveIndex = 0;

  @override
  Widget build(BuildContext context) {
    double height  = SizeConfig.heightMultiplier *
        (SizeConfig.isHeightVeryShort ? 40 : SizeConfig.isHeightLarge?33:31);
    return Container(
      height: height,
      // height: 230,
      child: Swiper(
        onIndexChanged: (index) {
          if (mounted) {
            setState(() {
              sliderActiveIndex = index;
              widget.sliderChange(index);
            });
          }
        },
        itemBuilder: (BuildContext context, int index) {
          return getSwipeWidget(widget.dashboardItemList, index, height);
        },
        itemCount: 3,

        pagination: new SwiperCustomPagination(builder: (BuildContext context, SwiperPluginConfig config) {
          return new Stack(
            alignment: Alignment.bottomCenter,
            children: [
              Positioned(
                bottom: 0,
                child: Center(
                  child: InkWell(
                    onTap: () {},
                    child: Container(
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          config.activeIndex == 0 ? SwiperRoundedPagination(true) : SwiperRoundedPagination(false),
                          config.activeIndex == 1 ? SwiperRoundedPagination(true) : SwiperRoundedPagination(false),
                          config.activeIndex == 2 ? SwiperRoundedPagination(true) : SwiperRoundedPagination(false),
                        ],
                      ),
                    ),
                  ),
                ),
              )
            ],
          );
        }),
        viewportFraction: 0.9,
        // scale: 0.9,
        // control: new SwiperControl(),
      ),
    );
  }

  Widget getSwipeWidget(List<DashboardModel> dashboardItemList, int index, double height) {
    if (index == 1)
      return RoundedContainer(
        raduis: 16,
        showBorder: false,
          borderColor: Colors.white,
          shadowWidth: 0.1,
          shadowSpreadRadius: 2,
          shadowDy: 1,
          margin: EdgeInsets.only(top: 15, bottom: 15, left: 10, right: 10),
          child: Padding(padding: const EdgeInsets.all(5.0), child: GetOutPatientStack(dashboardItemList[1],
          ),
        ),
      );
    if (index == 0)
      return RoundedContainer(
          raduis: 16,
          showBorder: false,
          borderColor: Colors.white,
          shadowWidth: 0.1,
          shadowSpreadRadius: 2,
          shadowDy: 1,
          margin: EdgeInsets.only(top: 15, bottom: 15, left: 10, right: 10),
          child: Padding(padding: const EdgeInsets.all(5.0), child: GetOutPatientStack(dashboardItemList[0])));
    if (index == 2)
      return DashboardReferralPatient(dashboardItemList: widget.dashboardItemList,height: height,model: widget.model,);
    return Container();
  }



}


