import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:gap/gap.dart';
import 'package:tanami_app/core/styles/app_color.dart';
import 'package:tanami_app/features/MainScreens/Invest/presentation/bloc/io_invest/io_details_state.dart';
import 'package:tanami_app/features/MainScreens/Invest/presentation/widgets/invest_video_section.dart';

import '../bloc/io_invest/io_details_bloc.dart';
import '../widgets/invest_detail_details_section.dart';
import '../widgets/invest_detail_image_carousel.dart';
import '../widgets/invest_included_documents_section.dart';
import '../widgets/key_investment_section.dart';

class InvestDetailsLayout extends StatelessWidget {
  final String type;
  const InvestDetailsLayout({super.key, required this.type});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColor.plainWhite,
      body:
          BlocBuilder<IODetailsBloc, IODetailsState>(builder: (context, state) {
        if (state is IODetailsStateLoading) {
          return const Center(child: CircularProgressIndicator());
        } else if (state is IODetailsStateLoaded) {
          return SingleChildScrollView(
            child: Padding(
              padding:
                  const EdgeInsets.symmetric(horizontal: 16.0, vertical: 20.0),
              child: Column(
                children: [
                  Container(
                    decoration: BoxDecoration(
                      color: AppColor.plainWhite,
                      borderRadius:
                          const BorderRadius.all(Radius.circular(20.0)),
                      boxShadow: [
                        BoxShadow(
                          color: AppColor.plainBlack.withOpacity(0.15),
                          spreadRadius: 2,
                          blurRadius: 10,
                          offset: const Offset(0, 3),
                        ),
                      ],
                    ),
                    child: Column(
                      children: [
                        InvestDetailCarouselView(
                          type: type,
                          detailIOModel: state.detailIOModel,
                        ),
                        InvestDetailDetailsSection(
                          type: type,
                          detailIOModel: state.detailIOModel,
                        ),
                      ],
                    ),
                  ),
                  Gap(
                    20.h,
                  ),
                  const KeyInvestmentSection(),
                  type == "closed" ? const SizedBox() : Gap(20.h),
                  type == "closed"
                      ? const SizedBox()
                      : const InvestIncludedDocumentsSection(),
                  type == "closed" ? const SizedBox() : Gap(20.h),
                  type == "closed"
                      ? const SizedBox()
                      : const InvestVideoSection(),
                ],
              ),
            ),
          );
        } else {
          return const Center(child: Text('Something went wrong!'));
        }
      }),
    );
  }
}
