import 'package:diplomaticquarterapp/config/shared_pref_kay.dart';
import 'package:diplomaticquarterapp/core/viewModels/project_view_model.dart';
import 'package:diplomaticquarterapp/core/viewModels/weather/weather_view_model.dart';
import 'package:diplomaticquarterapp/pages/base/base_view.dart';
import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart';
import 'package:diplomaticquarterapp/uitl/location_util.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:diplomaticquarterapp/widgets/text/app_texts_widget.dart';
import 'package:diplomaticquarterapp/widgets/weather_slider/weather_slider.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:diplomaticquarterapp/widgets/progress_indicator/app_circular_progress_Indeicator.dart';

class HealthWeatherIndicator extends StatefulWidget {
  @override
  _HospitalsPageState createState() => _HospitalsPageState();
}

class _HospitalsPageState extends State<HealthWeatherIndicator> {
  var data;
  AppSharedPreferences sharedPref = AppSharedPreferences();
  LocationUtils locationUtils;
  var weather = '--';
  @override
  void initState() {
    locationUtils =
        new LocationUtils(isShowConfirmDialog: true, context: context);
    WidgetsBinding.instance
        .addPostFrameCallback((_) => locationUtils.getCurrentLocation());
    getWeather();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    ProjectViewModel projectViewModel = Provider.of(context);
    return BaseView<WeatherViewModel>(
      onModelReady: (model) => model.getWeatherData(),
      allowAny: true,
      builder: (_, mode, widget) => AppScaffold(
          isShowDecPage: false,
          appBarTitle: TranslationBase.of(context).healthWeatherIndicators,
          isShowAppBar: true,
          body: mode.weatherIndicatorData.length > 0
              ? SingleChildScrollView(
                  child: Column(children: [
                  Container(
                    margin: EdgeInsets.all(8),
                    width: double.infinity,
                    height: 150,
                    decoration: BoxDecoration(
                        image: DecorationImage(
                          image:
                              ExactAssetImage('assets/images/Weather_img.png'),
                          fit: BoxFit.cover,
                        ),
                        borderRadius: BorderRadius.circular(8.0)),
                    child: Padding(
                      padding: EdgeInsets.symmetric(horizontal: 10.0),
                      child: Row(
                        children: [
                          Expanded(
                              flex: 3,
                              child: Column(
                                mainAxisAlignment: MainAxisAlignment.center,
                                crossAxisAlignment: CrossAxisAlignment.start,
                                children: [
                                  AppText(
                                    TranslationBase.of(context)
                                        .healthWeatherIndicators,
                                    color: Colors.white,
                                    fontWeight: FontWeight.w600,
                                  ),
                                  AppText(
                                    TranslationBase.of(context)
                                        .healthTipsBasedOnCurrentWeather,
                                    color: Colors.white,
                                    fontSize: 14,
                                  ),
                                ],
                              )),
                          Expanded(
                            flex: 2,
                            child: InkWell(
                                onTap: () {},
                                child: Column(
                                  mainAxisAlignment: MainAxisAlignment.center,
                                  children: [
                                    Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.center,
                                      children: [
                                        Image.asset(
                                          'assets/images/Weather_ico.png',
                                          width: 60,
                                          height: 60,
                                        ),
                                        Directionality(
                                            textDirection: TextDirection.ltr,
                                            child: AppText(weather,
                                                fontSize: 22,
                                                color: Colors.white))
                                      ],
                                    ),
                                  ],
                                )),
                          )
                        ],
                      ),
                    ),
                  ),
                  Padding(
                      padding: EdgeInsets.all(15),
                      child: AppText(
                        projectViewModel.isArabic
                            ? mode.weatherIndicatorData[0].cityNameN
                            : mode.weatherIndicatorData[0].cityName,
                        fontSize: 24,
                        fontWeight: FontWeight.bold,
                      )),
                  Padding(
                      padding: EdgeInsets.all(15),
                      child: Column(
                          children: mode.weatherIndicatorData.map((data) {
                        return WeatherSlider(data);
                      }).toList()))
                ]))
              : Center(child: AppCircularProgressIndicator())),
    );
  }

  getWeather() async {
    var data = await this.sharedPref.getObject(WEATHER);
    setState(() {
      weather = data['Temperature'].toString() + '\u2103' ?? '--';
    });
  }
}
