import 'package:cims_apps/application/component/button/button_view.dart';
import 'package:cims_apps/application/component/custom_app_bar/custom_app_bar.dart';
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/numeric_pad/numeric_pad.dart';
import 'package:cims_apps/application/component/risk_profile.dart';
import 'package:cims_apps/application/component/text_form/text_form_view.dart';
import 'package:cims_apps/application/theme/color_palette.dart';
import 'package:cims_apps/core/utils/number_formatter.dart';
import 'package:cims_apps/core/utils/size_config.dart';
import 'package:cims_apps/features/dashboard/dashboard_account/view/plan/view/step_invest_plan/options_starting_invest.dart';
import 'package:cims_apps/features/dashboard/dashboard_account/view/plan/view_model/plan_view_model.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class PlanView extends StatefulWidget {
  const PlanView({super.key});

  @override
  State<PlanView> createState() => _PlanViewState();
}

class _PlanViewState extends State<PlanView> {
  TextEditingController inputController = TextEditingController();

  @override
  void initState() {
    // TODO: implement initState
    inputController.text = 'Rp 0';
    super.initState();
  }

  @override
  void dispose() {
    // TODO: implement dispose
    super.dispose();
    inputController.dispose();
  }

  @override
  Widget build(BuildContext context) {

    return Scaffold(
      appBar: CustomAppBar(height: 70, title: 'Investment Plan'),
      body: SingleChildScrollView(
        padding: EdgeInsets.all(24),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            RiskProfile(
              totalScore: 26,
              rowSuitableProduct: true
            ),
            SizedBox(
              height: 32,
            ),
            Text('Your Goal in Investing',
              style: TextStyle(
                fontWeight: FontWeight.w700,
                color: ColorPalette.slate800,
                fontSize: 18
              ),
            ),
            SizedBox(
              height: 24,
            ),
            GoalInvestingView(
              onListSelected: (p0) {
                showModalBottomSheet(
                  context: context,
                  isScrollControlled: true,
                  builder: (context) {
                    return modalInvest(context, p0);
                  },
                );
              },
            )
          ],
        ),
      ),
    );
  }

  Widget modalInvest(context, String text) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(16)
      ),
      child: Column(
        mainAxisSize: MainAxisSize.min,
        children: [
          Padding(
            padding: const EdgeInsets.symmetric(horizontal: 24, vertical: 18),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
                Text("It's time to invest",
                  style: TextStyle(
                    fontSize: 16,
                    fontWeight: FontWeight.w600
                  ),
                ),
                GestureDetector(
                  onTap: () {
                    Navigator.pop(context);
                  },
                  child: Icon(Icons.close_rounded)
                )
              ],
            ),
          ),
          Divider(color: ColorPalette.slate200, height: 1),
          InputInvestmentView(
            selectedPlan: text,
            nextMove: (value) {
              Navigator.pop(context);
              int formatIntParse = int.parse(value.replaceAll('Rp ', '').replaceAll(',', ''));
              showModalBottomSheet(context: context, builder: (context) => OptionsStartingInvest(totalInvest: formatIntParse));
            },
          ),
        ],
      ),
    );
  }
}
