import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:stacked/stacked.dart';
import 'package:yimaru_app/ui/common/app_colors.dart';
import 'package:yimaru_app/ui/common/ui_helpers.dart';
import 'package:yimaru_app/ui/widgets/custom_elevated_button.dart';
import 'package:yimaru_app/ui/views/onboarding/onboarding_viewmodel.dart';
import 'package:yimaru_app/ui/widgets/onboarding_app_bar.dart';

class AssessmentResult extends ViewModelWidget<OnboardingViewModel> {
  const AssessmentResult({super.key});

  @override
  Widget build(BuildContext context, OnboardingViewModel viewModel) =>
      _buildScaffoldWrapper(viewModel);

  Widget _buildScaffoldWrapper(OnboardingViewModel viewModel) => Scaffold(
        backgroundColor: kcBackgroundColor,
        body: _buildScaffold(viewModel),
      );

  Widget _buildScaffold(OnboardingViewModel viewModel) => Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: _buildScaffoldChildren(viewModel),
      );

  List<Widget> _buildScaffoldChildren(OnboardingViewModel viewModel) =>
      [_buildAppBar(), _buildExpandedBody(viewModel)];

  Widget _buildAppBar() => const OnboardingAppBar(showBackButton: false);

  Widget _buildExpandedBody(OnboardingViewModel viewModel) =>
      Expanded(child: _buildBodyWrapper(viewModel));

  Widget _buildBodyWrapper(OnboardingViewModel viewModel) => Padding(
        padding: const EdgeInsets.symmetric(horizontal: 15),
        child: _buildBody(viewModel),
      );

  Widget _buildBody(OnboardingViewModel viewModel) => Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: _buildBodyChildren(viewModel),
      );

  List<Widget> _buildBodyChildren(OnboardingViewModel viewModel) =>
      [_buildUpperColumn(viewModel), _buildLowerColumn(viewModel)];

  Widget _buildUpperColumn(OnboardingViewModel viewModel) => Column(
        mainAxisSize: MainAxisSize.min,
        mainAxisAlignment: MainAxisAlignment.center,
        crossAxisAlignment: CrossAxisAlignment.stretch,
        children: _buildUpperColumnChildren(viewModel),
      );

  List<Widget> _buildUpperColumnChildren(OnboardingViewModel viewModel) => [
        verticalSpaceLarge,
        _buildTitle(),
        verticalSpaceSmall,
        _buildPrimarySubTitle(),
        verticalSpaceMedium,
        _buildIcon(),
        verticalSpaceMedium,
        _buildSecondarySubTitle()
      ];

  Widget _buildTitle() => const Text(
        'You’re likely a B1 speaker!',
        textAlign: TextAlign.center,
        style: TextStyle(
          fontSize: 25,
          color: kcPrimaryColor,
          fontWeight: FontWeight.w600,
        ),
      );

  Widget _buildPrimarySubTitle() => const Text(
        'Great Job! Here’s your next step to keep improving.',
        textAlign: TextAlign.center,
        style: TextStyle(color: kcMediumGrey),
      );

  Widget _buildIcon() => SvgPicture.asset('assets/icons/b1.svg');

  Widget _buildSecondarySubTitle() => const Text(
        'Let\'s start your practice',
        textAlign: TextAlign.center,
        style: TextStyle(color: kcMediumGrey),
      );

  Widget _buildLowerColumn(OnboardingViewModel viewModel) => Column(
        mainAxisSize: MainAxisSize.min,
        children: _buildLowerColumnChildren(viewModel),
      );

  List<Widget> _buildLowerColumnChildren(OnboardingViewModel viewModel) => [
        _buildContinueButton(viewModel),
        verticalSpaceMedium,
        _buildSkipButtonWrapper(viewModel)
      ];

  Widget _buildContinueButton(OnboardingViewModel viewModel) =>
      CustomElevatedButton(
        height: 55,
        text: 'Continue',
        borderRadius: 12,
        onTap: () => viewModel.next(),
        foregroundColor: kcWhiteColor,
        backgroundColor: kcPrimaryColor,
      );

  Widget _buildSkipButtonWrapper(OnboardingViewModel viewModel) => Padding(
        padding: const EdgeInsets.only(bottom: 50),
        child: _buildSkipButton(viewModel),
      );

  Widget _buildSkipButton(OnboardingViewModel viewModel) =>
      CustomElevatedButton(
        height: 55,
        borderRadius: 12,
        text: 'Practice Speaking',
        borderColor: kcPrimaryColor,
        onTap: () => viewModel.next(),
        backgroundColor: kcWhiteColor,
        foregroundColor: kcPrimaryColor,
      );
}
