import 'package:flutter/material.dart';
import 'package:initial_folder/providers/order_provider.dart';
import 'package:initial_folder/providers/page_provider.dart';
import 'package:initial_folder/screens/home/home_screen.dart';
import 'package:initial_folder/size_config.dart';
import 'package:initial_folder/theme.dart';
import 'package:initial_folder/widgets/login_regist/default_button_payment.dart';
import 'package:provider/provider.dart';

import '../../providers/my_course_provider.dart';

class SuccessPaidCourse extends StatefulWidget {
  static const String routeName = "/success-paid-course";

  @override
  State<SuccessPaidCourse> createState() => _SuccessPaidCourseState();
}

class _SuccessPaidCourseState extends State<SuccessPaidCourse> {
  @override
  Widget build(BuildContext context) {
    var orders = Provider.of<OrderProvider>(context).orders;
    var pageProvider = Provider.of<PageProvider>(context);

    return Scaffold(
      appBar: AppBar(
        scrolledUnderElevation: 0.0,
        backgroundColor: Theme.of(context).colorScheme.background,
        leadingWidth: 14,
      ),
      body: ListView(
        children: [
          Image.asset(
            "assets/images/success_pay.png",
            width: getProportionateScreenWidth(100),
            height: getProportionateScreenHeight(100),
          ),
          SizedBox(height: getProportionateScreenHeight(15)),
          Text(
            'Pembayaran Berhasil',
            style: thirdTextStyle.copyWith(
              fontWeight: semiBold,
              fontSize: getProportionateScreenWidth(14),
            ),
            textAlign: TextAlign.center,
          ),
          SizedBox(height: getProportionateScreenHeight(15)),
          Container(
            margin: EdgeInsets.symmetric(horizontal: 16),
            width: SizeConfig.screenWidth,
            height: getProportionateScreenHeight(169),
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(5),
            ),
            child: Column(
              children: [
                Container(
                  width: getProportionateScreenWidth(278),
                  height: getProportionateScreenHeight(145),
                  decoration: BoxDecoration(
                    borderRadius: BorderRadius.circular(5),
                    image: DecorationImage(
                      image: NetworkImage(
                        orders[0].imageUrl, // Ambil dari OrderProvider
                      ),
                      fit: BoxFit.cover,
                    ),
                  ),
                ),
              ],
            ),
          ),
          Padding(
            padding: EdgeInsets.symmetric(
                horizontal: getProportionateScreenWidth(15)),
            child: Container(
              margin: EdgeInsets.only(
                bottom: getProportionateScreenHeight(8),
              ),
              child: Center(
                child: Text(
                  orders[0].title ?? '', // Ambil dari OrderProvider
                  style: thirdTextStyle.copyWith(
                    fontSize: getProportionateScreenWidth(14),
                    letterSpacing: 0.2,
                  ),
                  textAlign: TextAlign.center,
                ),
              ),
            ),
          ),
          Container(
            child: Center(
              child: Text(
                'Oleh ${orders[0].instructor}', // Ambil dari OrderProvider
                style: thirdTextStyle.copyWith(
                  fontSize: getProportionateScreenWidth(11),
                  letterSpacing: 0.5,
                  fontFamily: "Poppins",
                ),
                textAlign: TextAlign.center,
              ),
            ),
          ),
          SizedBox(height: getProportionateScreenHeight(10)),
          Container(
            margin: EdgeInsets.symmetric(horizontal: 16),
            child: DefaultButtonPayment(
              width: double.infinity,
              height: getProportionateScreenHeight(34),
              text: 'Lihat Kursus',
              press: () async {
                await Provider.of<MyCourseProvider>(context, listen: false)
                    .getMyCourse();
                pageProvider.currentIndex = 2;
                Navigator.pushAndRemoveUntil(
                  context,
                  MaterialPageRoute(
                    builder: (context) => HomeScreen(),
                  ),
                  (route) => false,
                );
              },
            ),
          ),
        ],
      ),
    );
  }
}
