import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:liquid_progress_indicator_v2/liquid_progress_indicator.dart';

import '../../../common/models/meeting_room_user.dart';
import '../../../utils/color_util.dart';
import '../../../utils/cus_behavior.dart';
import '../../../view/view_svg_path.dart';
import 'meeting_main_voice_logic.dart';
import 'meeting_main_voice_state.dart';

class MeetingMainVoiceComponent extends StatelessWidget {
  MeetingMainVoiceComponent({super.key, required this.users});

  final List<MeetingRoomUser> users;

  final MeetingMainVoiceLogic logic = Get.put(MeetingMainVoiceLogic());
  final MeetingMainVoiceState state = Get.find<MeetingMainVoiceLogic>().state;

  @override
  Widget build(BuildContext context) {
    return Container(
      alignment: Alignment.center,
      padding: const EdgeInsets.only(left: 22, right: 22),
      color: ColorUtil.Color_57_57_57,
      child: ScrollConfiguration(
          behavior: CusBehavior(),
          child: GridView.builder(
              gridDelegate:
              const SliverGridDelegateWithFixedCrossAxisCount(
                  crossAxisCount: 3,
                  childAspectRatio: 0.7,
                  crossAxisSpacing: 20),
              itemCount: users.length,
              itemBuilder: (BuildContext ctx, index) {
                return Column(
                  children: [
                    SizedBox(height: 20.h),
                    Container(
                      decoration: BoxDecoration(
                        borderRadius: BorderRadius.circular(99),
                        color: ColorUtil.Color_85_117_242
                      ),
                      width: 76.w,
                      height: 76.h,
                      alignment: Alignment.center,
                      child: Text(
                        users[index].userName.length > 3
                            ? users[index].userName.substring(users[index].userName.length - 2,users[index].userName.length)
                            : users[index].userName,
                        style: TextStyle(
                            fontSize: 22.sp,
                            color: ColorUtil.Color_244_244_244
                        ),
                      ),
                    ),
                    SizedBox(height: 6.h),
                    users[index].enableMicr == true
                    ? Text.rich(
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      TextSpan(
                        children: [
                          WidgetSpan(
                              child: Container(
                                width: 20.w,
                                height: 20.h,
                                child: LiquidCustomProgressIndicator(
                                    value: users[index].volume ?? 0.0,
                                    valueColor: const AlwaysStoppedAnimation(ColorUtil.Color_2_177_136),
                                    backgroundColor: ColorUtil.Color_255_255_255,
                                    direction: Axis.vertical,
                                    shapePath: ViewSvgPath.getMicrpphonePath()
                                ),
                              )
                          ),
                          TextSpan(
                            text: users[index].userName,
                            style: TextStyle(
                                fontSize: 12.sp,
                                color: ColorUtil.Color_255_255_255),

                          ),
                        ],
                      ),
                      textAlign: TextAlign.left,
                    )
                        : Text.rich(
                      maxLines: 1,
                      overflow: TextOverflow.ellipsis,
                      TextSpan(
                        children: [
                          WidgetSpan(
                            child: Image.asset(
                              'assets/images/meeting_main_microphone_open.png',
                              width: 20.w,
                              height: 20.h,
                            )
                          ),
                          TextSpan(
                            text: users[index].userName,
                            style: TextStyle(
                                fontSize: 12.sp,
                                color: ColorUtil.Color_255_255_255),

                          ),
                        ],
                      ),
                      textAlign: TextAlign.left,
                    )
                  ],
                );
              })),
    );
  }
}
