import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:taafee_mobile/common/const/const.dart';
import 'package:taafee_mobile/features/home/business_logic_layer/home_controller.dart';

// ignore: must_be_immutable
class CircleAvatarWidget extends StatelessWidget {
  final double? radius;
  CircleAvatarWidget({
    super.key,
    this.radius,
    this.avatarImageLink,
    required this.isUserAvatar,
  });
  final HomeController homeController = Get.find<HomeController>();
  String? avatarImageLink;
  bool isUserAvatar;
  @override
  Widget build(BuildContext context) {
    //avatarImageLink = homeController.user.value!.avatarImage?.substring(7);

    return isUserAvatar == false
        ? ((avatarImageLink == null)
            ? CircleAvatar(
                radius: radius ?? 30,
                backgroundImage:
                    const AssetImage("assets/images/default_user_avatar.png"),
              )
            : CircleAvatar(
                radius: radius ?? 30,
                backgroundImage: CachedNetworkImageProvider(Domain.domain +
                    homeController.user.value!.avatarImage!.substring(7))))
        : Obx(() => (homeController.isAvatarImagePicked.value == true)
            ? CircleAvatar(
                radius: radius ?? 30,
                backgroundImage:
                    FileImage(homeController.pickedUserImage.value!),
              )
            : (homeController.isUserHasAvatar.value == false)
                ? CircleAvatar(
                    radius: radius ?? 30,
                    backgroundImage: const AssetImage(
                        "assets/images/default_user_avatar.png"),
                  )
                : CircleAvatar(
                    radius: radius ?? 30,
                    backgroundImage: CachedNetworkImageProvider(Domain.domain +
                        homeController.user.value!.avatarImage!.substring(7)),
                  ));
  }
}
