import 'package:cims_apps/application/component/subscribe/goal_investing_view.dart';
import 'package:cims_apps/application/component/subscribe/input_investment_view.dart';
import 'package:cims_apps/application/component/subscribe/total_payment_view.dart';
import 'package:cims_apps/application/theme/color_palette.dart';
import 'package:cims_apps/features/dashboard/dashboard_account/view/plan/view_model/plan_view_model.dart';
import 'package:cims_apps/features/dashboard/dashboard_account/view/product/view_model/product_view_model.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class SelectGoalInvesting extends StatelessWidget {
  const SelectGoalInvesting({super.key});

  @override
  Widget build(BuildContext context) {

    return ChangeNotifierProvider(
      create: (context) => ProductViewModel(),
      child: Consumer<ProductViewModel>(
        builder: (context, provider, child) {
          return Container(
            decoration: BoxDecoration(
                borderRadius: BorderRadius.circular(16)
            ),
            padding: EdgeInsets.all(24),
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    Text('Your Goal in Investing',
                      style: TextStyle(
                          fontWeight: FontWeight.w700,
                          color: ColorPalette.slate800,
                          fontSize: 18
                      ),
                    ),
                    GestureDetector(
                        onTap: () {
                          Navigator.pop(context);
                        },
                        child: Icon(Icons.close_rounded, color: ColorPalette.slate400)
                    )
                  ],
                ),
                SizedBox(height: 32),
                GoalInvestingView(
                  onListSelected: (p0) {
                    Navigator.pop(context);
                    showModalBottomSheet(
                      context: context,
                      isScrollControlled: true,
                      builder: (context) {
                        return ChangeNotifierProvider(
                          create: (context) => ProductViewModel(),
                          child: Consumer<ProductViewModel>(
                            builder: (context, provider, child) {
                              return Padding(
                                padding: EdgeInsets.symmetric(vertical: 16),
                                child: InputInvestmentView(
                                  currentPlan: p0,
                                  changePlan: () {
                                    Navigator.pop(context);
                                    showModalBottomSheet(
                                      context: context,
                                      isScrollControlled: true,
                                      builder: (context) => SelectGoalInvesting(),
                                    );
                                  },
                                  nextMove: (value) {
                                    Navigator.pop(context);
                                    int formatIntParse = int.parse(value.replaceAll('Rp ', '').replaceAll('.', ''));
                                    showModalBottomSheet(
                                      context: context,
                                      isScrollControlled: true,
                                      builder: (context) =>
                                        ChangeNotifierProvider(
                                          create: (context) => ProductViewModel(),
                                          child: Consumer<ProductViewModel>(
                                              builder: (context, provider, child) {
                                                return TotalPaymentView(
                                                  listProduct: [
                                                    provider.getSelectedProduct
                                                  ],
                                                  totalInvest: formatIntParse,
                                                  isAgree: provider.isAgree,
                                                  onTapAgree: provider.setAgree,
                                                );
                                              }
                                            ),
                                          )
                                    );
                                  },
                                ),
                              );
                            }
                          ),
                        );
                      },
                    );
                  },
                )
              ],
            ),
          );
        }
      ),
    );
  }
}
