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/classes/decorations_helper.dart';
import 'package:mohem_flutter_app/extensions/int_extensions.dart';
import 'package:mohem_flutter_app/extensions/string_extensions.dart';
import 'package:mohem_flutter_app/generated/locale_keys.g.dart';
import 'package:mohem_flutter_app/ui/marathon/marathon_provider.dart';

class QualifiersContainer extends StatefulWidget {
  final MarathonProvider provider;

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

  @override
  State<QualifiersContainer> createState() => _QualifiersContainerState();
}

class _QualifiersContainerState extends State<QualifiersContainer> {
  @override
  void initState() {
    widget.provider.startTimerForWinnerSelection();
    widget.provider.callGetSelectedWinnersApi();
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      decoration: MyDecorations.shadowDecoration,
      padding: const EdgeInsets.only(top: 14, left: 18, right: 14, bottom: 18),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: <Widget>[
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: <Widget>[
              LocaleKeys.winnerSelection.tr().toText21(color: MyColors.grey3AColor),
              "00:${widget.provider.totalSecondsToWaitForWinner < 10 ? "0${widget.provider.totalSecondsToWaitForWinner}" : widget.provider.totalSecondsToWaitForWinner}"
                  .toText18(color: MyColors.redColor),
            ],
          ),
          10.height,
          Row(
             crossAxisAlignment: CrossAxisAlignment.end,
            children: <Widget>[
              widget.provider.totalQualifiers != null ? widget.provider.totalQualifiers.toString().toText30(color: MyColors.greenColor, isBold: true) : const SizedBox(),
              2.width,
              LocaleKeys.qualifiers.tr().toText16(color: MyColors.greenColor),
            ],
          ),
        ],
      ),
    );
  }
}
