import 'package:flutter/material.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:qyuota/config/colors.dart';
import 'package:qyuota/config/images.dart';
import 'package:qyuota/config/text_style.dart';
import 'package:qyuota/view/auth/welcome_screen.dart';
import 'package:qyuota/view/profile/edit_profile_screen.dart';
import 'package:qyuota/view/profile/privacy_policy_screen.dart';
import 'package:qyuota/widget/custom_button.dart';


class ProfileView extends StatefulWidget {
  const ProfileView({Key? key}) : super(key: key);

  @override
  State<ProfileView> createState() => _ProfileViewState();
}

class _ProfileViewState extends State<ProfileView> {
  @override
  Widget build(BuildContext context) {
    return Stack(
      alignment: Alignment.topCenter,
      children: [
        Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Expanded(
              child: Container(
                color: ConstColors.primaryColor,
                child: Column(
                  children: [
                    SizedBox(height: MediaQuery.of(context).padding.top + 15),
                    Padding(
                      padding: const EdgeInsets.only(left: 20, right: 20),
                      child: Row(
                        mainAxisAlignment: MainAxisAlignment.spaceBetween,
                        children: [
                          const Icon(
                            Icons.arrow_back,
                            color: Colors.transparent,
                          ),
                          Text(
                            "Profil",
                            style: pSemiBold18.copyWith(
                              fontSize: 20,
                              color: ConstColors.whiteColor,
                            ),
                          ),
                          SizedBox(
                            height: 24,
                            width: 24,
                            child: SvgPicture.asset(
                              DefaultImages.h1,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                ),
              ),
            ),
            Expanded(
              flex: 2,
              child: ListView(
                padding: EdgeInsets.zero,
                physics: const ClampingScrollPhysics(),
                children: [
                  Padding(
                    padding:
                        const EdgeInsets.only(left: 20, right: 20, top: 100),
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Container(
                          width: Get.width,
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(12),
                            color: ConstColors.whiteColor,
                            boxShadow: [
                              BoxShadow(
                                color:
                                    const Color(0xff4E568C).withOpacity(0.06),
                              ),
                            ],
                          ),
                          child: Padding(
                            padding: const EdgeInsets.only(
                                left: 20, right: 20, top: 20, bottom: 20),
                            child: Column(
                              children: [
                                row(
                                  DefaultImages.p5,
                                  "Bantuan",
                                  "",
                                ),
                                const SizedBox(height: 5),
                                Divider(
                                  color: ConstColors.lightTextColor
                                      .withOpacity(0.5),
                                ),
                                const SizedBox(height: 5),
                                row(
                                  DefaultImages.p7,
                                  "Tentang",
                                  "",
                                ),
                                const SizedBox(height: 5),
                                Divider(
                                  color: ConstColors.lightTextColor
                                      .withOpacity(0.5),
                                ),
                                const SizedBox(height: 5),
                                InkWell(
                                  onTap: () {
                                    Get.to(
                                      const PrivacyPolicyScreen(),
                                      transition: Transition.rightToLeft,
                                    );
                                  },
                                  child: row(
                                    DefaultImages.p8,
                                    "Privacy Policy",
                                    "",
                                  ),
                                ),
                                const SizedBox(height: 5),
                                Divider(
                                  color: ConstColors.lightTextColor
                                      .withOpacity(0.5),
                                ),
                                const SizedBox(height: 5),
                                row(
                                  DefaultImages.p9,
                                  "Syarat dan ketentuan",
                                  "",
                                ),
                              ],
                            ),
                          ),
                        ),
                        const SizedBox(height: 20),
                        CustomButton(
                          text: "Log Out",
                          color: Colors.transparent,
                          onTap: () {
                            Get.offAll(
                              const WelcomeScreen(),
                              transition: Transition.rightToLeft,
                            );

                          },
                          textColor: ConstColors.skyColor,
                        ),
                        const SizedBox(height: 20),
                      ],
                    ),
                  ),
                ],
              ),
            ),
          ],
        ),
        Padding(
          padding: const EdgeInsets.only(top: 120, left: 20, right: 20),
          child: Container(
            height: 166,
            width: Get.width,
            decoration: BoxDecoration(
              borderRadius: BorderRadius.circular(12),
              color: ConstColors.whiteColor,
              boxShadow: [
                BoxShadow(
                  color: const Color(0xff4E568C).withOpacity(0.06),
                ),
              ],
            ),
            child: Padding(
              padding: const EdgeInsets.only(left: 20, right: 20),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                children: [
                  const Expanded(child: SizedBox()),
                  Text(
                    "Hello, Hayung",
                    style: pSemiBold18.copyWith(
                      fontSize: 20,
                    ),
                  ),
                  const SizedBox(height: 10),
                  Row(
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: [
                      Text(
                        "+0123456789 ",
                        style: pRegular14.copyWith(
                          fontSize: 16,
                          color: ConstColors.lightColor,
                        ),
                      ),
                      Text(
                        "Prepaid ",
                        style: pRegular14.copyWith(
                          fontSize: 16,
                          color: ConstColors.primaryColor,
                        ),
                      ),
                      SizedBox(
                        height: 18,
                        width: 18,
                        child: SvgPicture.asset(
                          DefaultImages.p24,
                        ),
                      ),
                    ],
                  ),
                  const SizedBox(height: 20),
                  InkWell(
                    onTap: () {
                      Get.to(
                        const EditProfileScreen(),
                        transition: Transition.rightToLeft,
                      );
                    },
                    child: Text(
                      "Edit Profil",
                      style: pSemiBold20.copyWith(
                        fontSize: 14,
                        color: ConstColors.skyColor,
                      ),
                    ),
                  ),
                  const SizedBox(height: 20),
                ],
              ),
            ),
          ),
        ),
        Padding(
          padding: const EdgeInsets.only(top: 90),
          child: Container(
            height: 64,
            width: 64,
            decoration: const BoxDecoration(
              image: DecorationImage(
                image: AssetImage(
                  DefaultImages.p26,
                ),
              ),
            ),
          ),
        ),
      ],
    );
  }
}

Widget row(String image, String text1, String text2) {
  return Row(
    children: [
      SizedBox(
        height: 24,
        width: 24,
        child: SvgPicture.asset(
          image,
          fit: BoxFit.fill,
        ),
      ),
      const SizedBox(width: 14),
      Expanded(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Text(
              text1,
              style: pRegular14.copyWith(
                fontSize: 16,
              ),
            ),
            text2 == ""
                ? const SizedBox()
                : Padding(
                    padding: const EdgeInsets.only(top: 5),
                    child: Text(
                      text2,
                      style: pRegular14.copyWith(
                        fontSize: 12,
                        color: const Color(0xff00D455),
                      ),
                    ),
                  ),
          ],
        ),
      ),
      const Icon(
        Icons.arrow_forward_ios,
        color: ConstColors.lightTextColor,
        size: 15,
      )
    ],
  );
}
