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/resource/colors.gen.dart';
import 'package:location/utils/common_expand.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: buildCustomAvatarOrDefaultAvatarView(
                      size: 44.w,
                      avatar: userInfo.avatar,
                      isMine: userInfo.isMine == true))),
          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),
                );
              }),
            ),
          )
        ],
      ),
    ),
  );
}

