import 'package:flutter/material.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/core/styles/app_images.dart';
import 'package:tanami_app/features/MainScreens/Portfolio/domain/model/portfolio_model.dart';
import 'package:tanami_app/features/MainScreens/Portfolio/presentation/widgets/exited_card.dart';
import 'package:tanami_app/features/MainScreens/Portfolio/presentation/widgets/pending_card.dart';
import 'package:tanami_app/shared/components/text_widget.dart';

import '../../../../../core/styles/app_text.dart';

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: AppColor.plainWhite,
      body: CustomScrollView(
        slivers: [
          SliverAppBar(
            elevation: 0,
            scrolledUnderElevation: 0,
            expandedHeight: 230.h,
            automaticallyImplyLeading: false,
            snap: false,
            pinned: true,
            floating: false,
            flexibleSpace: LayoutBuilder(
                builder: (BuildContext context, BoxConstraints constraints) {
              var top = constraints.biggest.height;
              var percentage =
                  ((top - kToolbarHeight) / (200.0 - kToolbarHeight))
                      .clamp(0.0, 1.0);
              var opacity = (1 - percentage).clamp(0.0, 1.0);
              return FlexibleSpaceBar(
                // centerTitle: true,
                titlePadding:
                    const EdgeInsets.only(left: 30, top: 0, bottom: 15),
                title: Opacity(
                  opacity: opacity,
                  child: Row(
                    children: [
                      TextWidget().text12W700(
                        AppText.portfolio,
                        clr: const Color(0xFF888888),
                      ),
                      TextWidget().text14W700(
                        'SAR 178,000',
                        clr: AppColor.plainBlack,
                      ),
                    ],
                  ),
                ),
                background: Stack(
                  // fit: StackFit.expand,
                  children: [
                    Image.asset(
                      AppImages.portfolioBg,
                      fit: BoxFit.cover,
                      alignment: Alignment.topCenter,
                    ),
                    Padding(
                      padding: const EdgeInsets.only(left: 40.0),
                      child: Opacity(
                        opacity: percentage,
                        child: Column(
                          mainAxisAlignment: MainAxisAlignment.center,
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            TextWidget().text14W700(
                              AppText.portfolioText,
                              clr: const Color(0xFFC9D9CB),
                            ),
                            Gap(
                              8.h,
                            ),
                            TextWidget().text28W700(
                              'SAR 178,000',
                            ),
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              );
            }),
            backgroundColor: Colors.white,
          ),
          SliverList(
            delegate: SliverChildBuilderDelegate(
              (context, index) => portfolioModelList[index].status == "Exited"
                  ? ExitedCard(
                      portfolioModel: portfolioModelList[index],
                    )
                  : PendingCard(
                      portfolioModel: portfolioModelList[index],
                    ),
              childCount: 3,
            ),
          ),
        ],
      ),
    );
  }
}
