// ignore_for_file: always_specify_types

import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/classes/colors.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/ui/marathon/marathon_provider.dart';
import 'package:mohem_flutter_app/widgets/button/default_button.dart';

class MarathonFooter extends StatelessWidget {
  final MarathonProvider provider;

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

  Widget buildNoteForDemo() {
    return RichText(
      text: TextSpan(
        children: <InlineSpan>[
          TextSpan(
            text: LocaleKeys.note.tr(),
            style: const TextStyle(color: MyColors.darkTextColor, fontSize: 17, letterSpacing: -0.64, fontWeight: FontWeight.bold),
          ),
          TextSpan(
            text: " " + LocaleKeys.demoMarathonNoteP1.tr(),
            style: const TextStyle(color: MyColors.grey77Color, fontSize: 17, letterSpacing: -0.64, fontWeight: FontWeight.w500),
          ),
          TextSpan(
            text: " " + LocaleKeys.demoMarathonNoteP2.tr(),
            style: const TextStyle(color: MyColors.darkTextColor, fontSize: 17, fontWeight: FontWeight.bold),
          ),
          TextSpan(
            text: " " + LocaleKeys.demoMarathonNoteP3.tr(),
            style: const TextStyle(color: MyColors.grey77Color, fontSize: 17, letterSpacing: -0.64, fontWeight: FontWeight.w500),
          )
        ],
      ),
    ).paddingOnly(right: 21, left: 21, top: 11, bottom: 0);
  }

  @override
  Widget build(BuildContext context) {
    if (provider.isUpComingMarathon && !provider.canPlayDemo) {
      return Column(
        crossAxisAlignment: CrossAxisAlignment.center,
        children: [
          if (provider.isButtonEnabled && (provider.totalSecondsToWaitForMarathon < 30 && provider.totalSecondsToWaitForMarathon > 0)) ...[
            LocaleKeys.pleaseClickButtonToJoinMarathon.tr().toText18(color: MyColors.greenColor, isCentered: true),
            20.height,
          ] else if (!provider.isButtonEnabled && (provider.totalSecondsToWaitForMarathon <= 0)) ...[
            LocaleKeys.youCannotJoinTheMarathon.tr().toText18(color: MyColors.redColor, isCentered: true),
            20.height,
          ],
          DefaultButton(
            LocaleKeys.joinMarathon.tr(),
            provider.isButtonEnabled ? () => provider.onJoinMarathonPressed(context) : null,
          )
        ],
      ).insideContainer;
    } else {
      return DefaultButton(
        LocaleKeys.joinDemoMarathon.tr(),
        () => provider.onJoinDemoMarathonPressed(context),
        color: MyColors.yellowColorII,
      ).insideContainer;
    }
  }
}
