// ignore_for_file: always_specify_types

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_countdown_timer/flutter_countdown_timer.dart';
import 'package:mohem_flutter_app/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/classes/date_uitl.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/main.dart';
import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart';
import 'package:mohem_flutter_app/ui/marathon/marathon_provider.dart';
import 'package:mohem_flutter_app/ui/marathon/widgets/countdown_timer_main_screen.dart';
import 'package:mohem_flutter_app/widgets/button/default_button.dart';
import 'package:provider/provider.dart';
import 'package:url_launcher/url_launcher.dart';

class ActivityEventFooter extends StatelessWidget {
  final DashboardProviderModel provider;

  const ActivityEventFooter({
    Key? key,
    required this.provider,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {

     int remainingTime =  DateTime.now().millisecondsSinceEpoch  +  DateUtil.convertStringToDateMarathon(provider.eventActivity!.startOn!).difference(DateTime.now()).inMilliseconds;

    return Column(children: [
      CountdownTimer(
        endTime: remainingTime,
        widgetBuilder: (context, time) {
          if (time == null) {
            return  DefaultButton(
              LocaleKeys.start.tr(),
                  () => launchUrl(Uri.parse(provider.eventActivity!.url!)),
              color: MyColors.greenColor,
            ).insideContainer;
          }
      return Container(
          height: 58,
          padding: const EdgeInsets.only(
              top: 15, bottom: 15, right: 30, left: 30),
          margin: const EdgeInsets.only(top: 5, bottom: 5),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(6.0),
            gradient:
            const LinearGradient(
              transform: GradientRotation(.83),
              begin: Alignment.topRight,
              end: Alignment.bottomLeft,
              colors: <Color>[
                MyColors.gradiantEndColor,
                MyColors.gradiantStartColor
              ],
            ),
          ),
          child: CountdownTimerForMainScreen(
            timeToMarathon: DateUtil
                .convertStringToDateMarathon(provider.eventActivity!.startOn!)
                .millisecondsSinceEpoch,
            provider: context.read<MarathonProvider>(),
            isEvent: true,
          ));

        },
        onEnd: (){

        },
        endWidget:  DefaultButton(
        LocaleKeys.start.tr(),
            () => launchUrl(Uri.parse(provider.eventActivity!.url!)),
        color: MyColors.greenColor,
      ).insideContainer,

      )
    // if (remainingTimeInMinutes  < 0)
    //
    //  else
    //
    //
    // ,

    ]);

  }


}
