import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:loader_overlay/loader_overlay.dart';

import '../../app.dart';
import 'widgets/product_list_widget.dart';

class CartPage extends StatelessWidget {
  const CartPage({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GetX<CartController>(
      init: CartController(),
      builder: (cc) {
        final CartModel? model = cc.state.cartModel.value;
        return cc.loginStatusController.loginStatus
            ? cc.state.isLoading.value
                ? Scaffold(
                    appBar: CustomAppbarWidget(leading: AppBarBackBtn()),
                    body: Center(
                      child: CustomLoader(),
                    ),
                  )
                : model != null
                    ? LoaderOverlay(
                        useDefaultLoading: false,
                        overlayColor: Colors.transparent,
                        overlayWidget: CustomLoader(),
                        child: Container(
                          color: Colors.white,
                          child: SafeArea(
                            top: false,
                            child: Scaffold(
                              appBar: CustomAppbarWidget(leading: AppBarBackBtn()),
                              body: ProductListWidget(),
                            ),
                          ),
                        ),
                      )
                    : Scaffold(
                        appBar: CustomAppbarWidget(leading: AppBarBackBtn()),
                        body: Center(
                          child: SvgPicture.asset('assets/cart/cart_empty.svg'),
                        ),
                      )
            : Scaffold(
                appBar: CustomAppbarWidget(leading: AppBarBackBtn()),
                body: Center(
                  child: OutlinedButton(
                    onPressed: cc.navigateToLogin,
                    child: Text(
                      'please_login'.tr,
                      style: new TextStyle(
                        color: ThemeColor.mainColor,
                        fontWeight: FontWeight.w500,
                      ),
                    ),
                    style: OutlinedButton.styleFrom(
                      side: BorderSide(color: ThemeColor.mainColor),
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(10),
                      ),
                    ),
                  ),
                ),
              );
      },
    );
  }
}
