import 'package:cims_apps/application/assets/path_assets.dart';
import 'package:cims_apps/application/theme/color_palette.dart';
import 'package:cims_apps/core/utils/size_config.dart';
import 'package:cims_apps/features/auth/registration/view/submission_data/risk_profile/risk_profile_view_model/risk_profile_view_model.dart';
import 'package:flutter/material.dart';

class RiskProfile extends StatelessWidget {
  final int totalScore;
  final bool rowSuitableProduct;
  const RiskProfile({super.key, required this.totalScore, required this.rowSuitableProduct});

  @override
  Widget build(BuildContext context) {
    List<RiskProfileResult> listRiskProfileResult = [
      RiskProfileResult(
          'Conservative',
          PathAssets.imgCat,
          ColorPalette.green500,
          'Investors with a conservative risk profile are risk-averse or do not want to experience large losses. Therefore, mutual fund products that are suitable for conservative investors are products that have low risk and stable returns.',
          [
            {'desc': 'Money Market Mutual Fund', 'icon': PathAssets.iconStrongBox},
            {'desc': 'Fixed Income Mutual Fund', 'icon': PathAssets.iconMoneyReceive},
            {'desc': 'Balanced Mutual Fund', 'icon': PathAssets.iconBalance},
          ]
      ),
      RiskProfileResult(
          'Moderate',
          PathAssets.imgDeer,
          ColorPalette.orange500,
          'Investors with a moderate risk profile are investors who are ready to accept moderate risk to get higher returns than conservative mutual fund products. Therefore, mutual fund products that are suitable for moderate investors are products that have moderate risk and higher returns than conservative mutual fund products.',
          [
            {'desc': 'Fixed Income Mutual Fund', 'icon': PathAssets.iconMoneyReceive},
            {'desc': 'Balanced Mutual Fund', 'icon': PathAssets.iconBalance},
          ]
      ),
      RiskProfileResult(
          'Aggressive',
          PathAssets.imgLion,
          ColorPalette.purple500,
          'Investors with an aggressive risk profile are investors who are ready to accept high risks to get high returns. Therefore, mutual fund products that are suitable for aggressive investors are products that have high risk and high returns.',
          [
            {'desc': 'Equity Mutual Fund', 'icon': PathAssets.iconCoins},
            {'desc': 'Aggressive Balanced Fund', 'icon': PathAssets.iconBalance},
          ]
      )
    ];
    RiskProfileResult riskProfile;
    if(totalScore <= 25){
      riskProfile = listRiskProfileResult[0];
    }else if(totalScore <= 50){
      riskProfile = listRiskProfileResult[1];
    }else{
      riskProfile = listRiskProfileResult[2];
    }

    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      children: [
        ClipRRect(
          borderRadius: BorderRadius.circular(8),
          child: Container(
            decoration: BoxDecoration(
              color: riskProfile.color,
              image: DecorationImage(image: AssetImage(riskProfile.img), alignment: Alignment.centerRight),
              boxShadow: [
                BoxShadow(
                  color: riskProfile.color.withOpacity(0.2),
                  blurRadius: 30
                )
              ]
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Container(
                  padding: EdgeInsets.all(24),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        riskProfile.type,
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 24,
                            color: ColorPalette.white
                        ),
                      ),
                      SizedBox(height: 16,),
                      Text('Total Score :',
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 16,
                            color: ColorPalette.white
                        ),
                      ),
                      Text('$totalScore',
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 28,
                            color: ColorPalette.white
                        ),
                      )
                    ],
                  ),
                ),
              ],
            ),
          ),
        ),
        SizedBox(
          height: 24,
        ),
        Text(
            riskProfile.desc,
            style: TextStyle(
                color: ColorPalette.slate500,
                fontSize: 16
            )
        ),
        SizedBox(
          height: 24,
        ),
        Text(
          'Suitable Product',
          style: TextStyle(
              color: ColorPalette.slate800,
              fontWeight: FontWeight.bold,
              fontSize: 18
          ),
        ),
        SizedBox(
          height: 16,
        ),
        rowSuitableProduct ?
          Row(
            children: riskProfile.suitableProduct.asMap().entries.map((e) {
              return Expanded(
                child: Container(
                  margin: EdgeInsets.only(left: e.key != 0 ? 12 : 0),
                  padding: EdgeInsets.all(16),
                  decoration: BoxDecoration(
                    border: Border.all(color: ColorPalette.slate200),
                    borderRadius: BorderRadius.circular(6)
                  ),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Container(
                          padding: EdgeInsets.all(8),
                          decoration: BoxDecoration(
                              shape: BoxShape.circle,
                              color: riskProfile.color.withOpacity(0.1)
                          ),
                          child: Image.asset(e.value['icon'], width: SizeConfig.width * 0.07, color: riskProfile.color)
                      ),
                      SizedBox(
                        height: 12,
                      ),
                      Text(e.value['desc'],
                        style: TextStyle(
                            fontSize: 16,
                            fontWeight: FontWeight.bold,
                            color: ColorPalette.slate800
                        ),
                      )
                    ],
                  ),
                )
              );
            }).toList(),
          )
        : Wrap(
          runSpacing: 16,
          children: riskProfile.suitableProduct.map((e) {
            return Container(
              padding: EdgeInsets.all(16),
              decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(6),
                border: Border.all(color: ColorPalette.slate200),
              ),
              child: Row(
                children: [
                  Container(
                      padding: EdgeInsets.all(8),
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                          shape: BoxShape.circle,
                          color: riskProfile.color.withOpacity(0.1)
                      ),
                      child: Image.asset(e['icon'], width: SizeConfig.width * 0.07, color: riskProfile.color)
                  ),
                  SizedBox(
                    width: 12,
                  ),
                  Expanded(
                    child: Text(e['desc'],
                      style: TextStyle(
                          fontSize: 18,
                          fontWeight: FontWeight.bold,
                          color: ColorPalette.slate800
                      ),
                    ),
                  )
                ],
              ),
            );
          }).toList(),
        )
      ],
    );
  }
}
