import 'package:connectycube_sdk/connectycube_sdk.dart';
import 'package:flutter/material.dart';
import 'package:vmeeting/service/routes/routes_name.dart';
import 'package:vmeeting/src/extension/context_extensions.dart';
import 'package:vmeeting/src/widgets/small_text.dart';
import '../../src/constants/colors_const.dart';
import '../../src/controllers/enter_number_cont.dart';
import '../../src/utils/app_utils.dart';
import '../../src/widgets/big_text_widget.dart';
import '../../src/widgets/image_avatar.dart';

class ProfilePage extends StatelessWidget {
  final NumberController controller;
  const ProfilePage({super.key, required this.controller});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: buildUI(context),
    );
  }

  Widget buildUI(BuildContext context) {
    return Container(
      margin: EdgeInsets.symmetric(horizontal: context.w * 0.06),
      child: SingleChildScrollView(
        child: Column(
          children: [
            buildImage(context),
            SizedBox(height: context.h * 0.06),
            buildDetails(context),
          ],
        ),
      )
    );
  }

  Widget buildDetails(BuildContext context) {
    DateTime? createdAt = DateTime.parse(AppUtils.userModel.createdAt.toString());
    final result = '${createdAt.year}-${createdAt.month}-${createdAt.day} / ${createdAt.hour}:${createdAt.minute}:${createdAt.second}';
    return Column(
      children: [
        Container(
          height: context.h * 0.06,
          decoration: BoxDecoration(
              color: ColorConst.appBackgroundColor,
              borderRadius: BorderRadius.circular(12)),
          child: Center(
            child: SmallText(
              text: "ID: ${AppUtils.userModel.id ?? ""}",
            ),
          ),
        ),
        SizedBox(height: context.h * 0.02),
        Container(
          height: context.h * 0.06,
          decoration: BoxDecoration(
              color: ColorConst.appBackgroundColor,
              borderRadius: BorderRadius.circular(12)),
          child: Center(
            child: SmallText(
              text: "Full Name: ${AppUtils.userModel.fullName ?? ""}",
            ),
          ),
        ),
        SizedBox(height: context.h * 0.02),
        Container(
          height: context.h * 0.06,
          decoration: BoxDecoration(
              color: ColorConst.appBackgroundColor,
              borderRadius: BorderRadius.circular(12)),
          child: Center(
            child: SmallText(
              text: "Emile: ${AppUtils.userModel.email ?? " "}",
            ),
          ),
        ),
        SizedBox(height: context.h * 0.02),
        Container(
          height: context.h * 0.06,
          decoration: BoxDecoration(
              color: ColorConst.appBackgroundColor,
              borderRadius: BorderRadius.circular(12)),
          child: Center(
            child: SmallText(
              text: "Phone: ${AppUtils.userModel.phone ?? "No phone"}",
            ),
          ),
        ),
        SizedBox(height: context.h * 0.02),
        Container(
          height: context.h * 0.06,
          decoration: BoxDecoration(
              color: ColorConst.appBackgroundColor,
              borderRadius: BorderRadius.circular(12)),
          child: Center(
            child: SmallText(
              text: "Create Date: $result",
            ),
          ),
        ),
        SizedBox(height: context.h * 0.05),
        buildButtons(context),
      ],
    );
  }

  Widget buildButtons(BuildContext context) {
    return ElevatedButton(
      style: ElevatedButton.styleFrom(
        foregroundColor: Colors.white,
        backgroundColor: ColorConst.appGreenColor,
        disabledForegroundColor: Colors.grey.withOpacity(0.38),
        disabledBackgroundColor: Colors.grey.withOpacity(0.12),
      ),
      onPressed: () async {
       final response =  Navigator.pushNamed(context, MainRoutes.edit_profile_page);

      },
      child: SizedBox(
        height: context.h * 0.06,
        child:  Center(
          child: BigText(
            text: "Edit Profile".toUpperCase(),
            fontWidget: FontWeight.bold,
            size: 16,
          ),
        ),
      ),
    );
  }

  Widget buildImage(BuildContext context,) {
    return Center(
        child: AvatarImage(
          radius: context.h * 0.09,
          imagePath: getPrivateUrlForUid(AppUtils.userModel.avatar),
        ));
  }
}
