import 'dart:ui';

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:location/data/bean/user_info.dart';
import 'package:location/data/consts/constants.dart';
import 'package:location/resource/assets.gen.dart';
import 'package:location/resource/colors.gen.dart';
import 'package:location/resource/string.gen.dart';
import 'package:location/utils/common_expand.dart';
import 'package:location/widget/relative_time_text.dart';
import '../../utils/common_style.dart';
import '../../utils/common_util.dart';
import '../../widget/marquee_text.dart';

Widget mainFriendItem(UserInfo userInfo, bool isSelected,
    {required VoidCallback onTap}) {
  return GestureDetector(
    onTap: onTap,
    child: Container(
      margin: EdgeInsets.only(right: 12.w),
      child: Stack(
        children: [
          Container(
              decoration: BoxDecoration(
                  color: ColorName.white,
                  shape: BoxShape.circle,
                  border: isSelected
                      ? Border.all(color: ColorName.colorPrimary, width: 2.w)
                      : null),
              width: 52.w,
              height: 52.w,
              child: Center(
                  child: Image.asset(
                      userInfo.isMine == true
                          ? Assets.images.iconDefaultMineAvatar.path
                          : Assets.images.iconDefaultFriendAvatar.path,
                      width: 44.w,
                      height: 44.w))),
          Positioned(
            left: 3.w,
            bottom: 0,
            right: 3.w,
            child: Container(
              height: 16.w,
              padding: EdgeInsets.symmetric(horizontal: 2.w),
              decoration: BoxDecoration(
                color: ColorName.white,
                borderRadius: BorderRadius.circular(10.w),
                border: Border.all(color: '#E8E8E8'.color, width: 1.w),
              ),
              child: Builder(builder: (context) {
                String nickName = userNickName(
                    userInfo.remark, userInfo.phoneNumber, !isSelected);
                TextStyle style =
                    TextStyle(fontSize: 10.sp, color: ColorName.black80);
                return Center(
                  child: isSelected
                      ? MarqueeText.marquee(
                          text: nickName,
                          containerWidth: 45.w,
                          textStyle: TextStyle(
                              fontSize: 10.sp, color: ColorName.black80))
                      : Text(nickName, style: style),
                );
              }),
            ),
          )
        ],
      ),
    ),
  );
}

Widget mainSelectedFriendItem(UserInfo userInfo, bool isMemberExpired,
    {VoidCallback? viewTraceClick}) {
  return Container(
      width: 336.w,
      height: 86.w,
      decoration: BoxDecoration(
          color: ColorName.white,
          borderRadius: BorderRadius.all(Radius.circular(20.w))),
      child: Row(
        children: [
          SizedBox(width: 7.w),
          Image(
              image: userInfo.isMine == true
                  ? Assets.images.iconDefaultMineAvatar.provider()
                  : Assets.images.iconDefaultFriendAvatar.provider(),
              width: 50.w,
              height: 50.w),
          SizedBox(width: 5.w),
          Expanded(
            child: Container(
              margin: EdgeInsets.symmetric(vertical: 15.w),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    children: [
                      Text(
                        userInfo.getUserNickName(),
                        style: TextStyle(
                            fontWeight: FontWeight.bold,
                            fontSize: 16.sp,
                            color: '#202020'.color),
                      ),
                      SizedBox(width: 7.w),
                      RelativeTimeText(
                          timestamp:
                              userInfo.lastLocation.value?.lastUpdateTime,
                          updateInterval: Duration(minutes: 1),
                          style: TextStyle(
                              fontSize: 12.sp, color: '#A7A7A7'.color)),
                      Spacer(),
                      GestureDetector(
                        onTap: () {
                          viewTraceClick?.call();
                        },
                        child: Container(
                            margin: EdgeInsets.only(right: 16.w),
                            decoration: getPrimaryBtnDecoration(32.w),
                            padding: EdgeInsets.symmetric(
                                horizontal: 21.w, vertical: 5.w),
                            child: Text(StringName.locationTrace,
                                style: TextStyle(
                                    fontSize: 15.sp, color: Colors.white))),
                      )
                    ],
                  ),
                  Expanded(
                    child: Container(
                      margin: EdgeInsets.only(right: 17.w),
                      child: ImageFiltered(
                        enabled: userInfo.blockedMe == true ||
                            (isMemberExpired && !(userInfo.isMine == true)),
                        imageFilter: ImageFilter.blur(
                          sigmaX: Constants.blurredX,
                          sigmaY: Constants.blurredY,
                        ),
                        child: userInfo.blockedMe == true ||
                                (isMemberExpired && !(userInfo.isMine == true))
                            ? Text(
                                addressCheck(
                                    userInfo.lastLocation.value?.address),
                                style: TextStyle(
                                    fontSize: 13.sp, color: ColorName.black50))
                            : MarqueeText.marquee(
                                text: addressCheck(
                                    userInfo.lastLocation.value?.address),
                                textStyle: TextStyle(
                                    fontSize: 13.sp, color: ColorName.black50),
                                containerWidth: 244.w),
                      ),
                    ),
                  )
                  // Text('广东省广州市天河区XX街街XX街区XX村XX')
                ],
              ),
            ),
          )
        ],
      ));
}
