import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.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/consts.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 MarathonDetailsCard extends StatelessWidget {
  final MarathonProvider provider;

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

  @override
  Widget build(BuildContext context) {
    return Container(
      width: double.infinity,
      decoration: MyDecorations.shadowDecoration,
      padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 14),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              LocaleKeys.contestTopicAbout.tr().toText16(color: MyColors.grey77Color),
              "${AppState().isArabic(context) ? provider.marathonDetailModel.titleAr : provider.marathonDetailModel.titleEn}".toText20(color: MyColors.textMixColor, isBold: true),
              Row(
                children: <Widget>[
                  Flexible(
                    child: "${AppState().isArabic(context) ? provider.marathonDetailModel.descAr : provider.marathonDetailModel.descEn}".toText14(color: MyColors.grey77Color),
                  )
                ],
              ),
              if (provider.marathonDetailModel.sponsors != null) ...<Widget>[
                5.height,
                provider.marathonDetailModel.sponsors?.first.sponsorPrizes != null
                    ? Row(
                        children: <Widget>[
                          "${LocaleKeys.prize.tr()} ".toText16(color: MyColors.grey77Color, isBold: true),
                          "${AppState().isArabic(context) ? provider.marathonDetailModel.sponsors?.first.sponsorPrizes?.first.marathonPrizeAr : provider.marathonDetailModel.sponsors?.first.sponsorPrizes?.first.marathonPrizeAr}"
                              .toText16(color: MyColors.greenColor, isBold: true),
                        ],
                      )
                    : const SizedBox(),
                Row(
                  children: <Widget>[
                    "${LocaleKeys.sponsoredBy.tr()} ".toText16(color: MyColors.grey77Color),
                    "${AppState().isArabic(context) ? provider.marathonDetailModel.sponsors?.first.nameAr : provider.marathonDetailModel.sponsors?.first.nameEn}"
                        .toText16(color: MyColors.darkTextColor, isBold: true),
                  ],
                ),
                10.height,
                Row(
                  mainAxisAlignment: MainAxisAlignment.center,
                  children: <Widget>[
                    Image.network(
                      ApiConsts.marathonBaseUrlServices + provider.marathonDetailModel.sponsors!.first.image!,
                      height: 50,
                      width: 150,
                      fit: BoxFit.contain,
                      errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) {
                        return const Center();
                      },
                    )
                  ],
                ),
              ]
            ],
          ),
        ],
      ),
    );
  }
}
