import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:get/get.dart';
import 'package:intl/intl.dart';
import 'package:web_panel/utils/App_color.dart';
import 'package:web_panel/utils/spacing.dart';

import '../../../constants.dart';
import '../../../controllers/dashboard_controller.dart';

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

  @override
  Widget build(BuildContext context) {

    return GetX<DashBoardController>(
      init: DashBoardController(),
      builder: (controller) {
        debugPrint("dateTime now::${DateTime.now()}");
        DateTime sDate =controller.userDetails['subcription_start_date'] != null ? DateTime.parse(controller.userDetails['subcription_start_date']) : DateTime.now();
        DateTime eDate =controller.userDetails['subscriptin_end_date'] != null ?  DateTime.parse(controller.userDetails['subscriptin_end_date']) : DateTime.now();
       DateTime currentDate = DateTime.now();
        final differentDate = eDate.difference(currentDate).inDays;
        return Container(
          margin: EdgeInsets.only(top: defaultPadding),
          padding: EdgeInsets.all(defaultPadding),
          // decoration: BoxDecoration(
          //   border: Border.all(
          //     width: 2,
          //     color: AppColor.primaryColor.withOpacity(0.15),
          //   ),
          //   borderRadius: const BorderRadius.all(Radius.circular(defaultPadding)),
          // ),
          child: Column(
            // spacing: 4.sp,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              details(
                context: context,
                title: 'User Name',
                subtitle: controller.userDetails['userName']??'N/A',
                svgSrc: 'assets/icons/ic_Person.png',
                color: Colors.white,
              ),
              Spacing.height(4),
              details(
                context: context,
                title: 'Telegram ID',
                subtitle:  controller.userDetails['telegram_id'].toString(),
                svgSrc: 'assets/icons/ic_Telegram.png',
                color: Colors.white,
              ),
              Spacing.height(4),
              details(
                context: context,
                title: 'Subscription Start',
                subtitle:  DateFormat('dd MMM yyyy').format(sDate),
                svgSrc: 'assets/icons/ic_start_date.png',
                color: AppColor.green,
              ),
              Spacing.height(4),
              details(
                context: context,
                title:'Subscription End',
                subtitle:DateFormat('dd MMM yyyy').format(eDate),
                svgSrc: 'assets/icons/ic_dueDate.png',
                color: AppColor.red,
              ),
              Spacing.height(1),
              Text(
               '($differentDate Days left)',
                style: Theme.of(
                  context,
                ).textTheme.bodyLarge!.copyWith(color: Color(0xffaab0ba)),
              ),
              Spacing.height(4),
              details(
                context: context,
                title: 'Monthly Charge',
                subtitle: '\$${controller.userDetails['monthly_charges']??'N/A'}',
                svgSrc: 'assets/icons/ic_cardPayment.png',
                color: AppColor.primaryColor,
              ),
            ],
          ),
        );
      }
    );
  }

  Widget details({
    required BuildContext context,
    required String svgSrc,
    required String title,
    required String subtitle,
    required Color color,
  }) {
    return Column(
      crossAxisAlignment: CrossAxisAlignment.start,
      mainAxisAlignment: MainAxisAlignment.start,
      spacing: 1.sp,
      children: [
        Row(
          spacing: 2.sp,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            SizedBox(height: 24, width: 24, child: Image.asset(svgSrc)),
            Text(
              title,
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              style: Theme.of(
                context,
              ).textTheme?.bodyLarge?.copyWith(color: AppColor.lightText),
            ),
          ],
        ),

        Text(
          subtitle,
          style: Theme.of(context).textTheme.titleSmall!.copyWith(color: color),
        ),
      ],
    );
  }
}
