import 'package:cs_resources/constants/color_constants.dart';
import 'package:cs_resources/generated/assets.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:widgets/ext/ex_widget.dart';
import 'package:widgets/load_state_layout.dart';
import 'package:widgets/my_text_view.dart';
import 'package:widgets/shatter/rating_widget.dart';
import 'package:widgets/widget_export.dart';

import 'applied_er_staff_reviews_controller.dart';

import 'package:plugin_basic/base/base_state.dart';
import 'package:plugin_basic/base/base_stateful_page.dart';
import 'package:plugin_basic/utils/ext_get_nav.dart';
import 'package:router/path/router_path.dart';
import 'package:shared/utils/screen_util.dart';
import 'package:widgets/my_appbar.dart';

import 'applied_staff_reviews_item.dart';
import 'applied_er_staff_reviews_state.dart';

/*
 * 员工的评论页面
 */
class AppliedErStaffReviewsPage extends BaseStatefulPage<AppliedErStaffReviewsController> {
  AppliedErStaffReviewsPage({Key? key}) : super(key: key);

  //启动当前页面
  static void startInstance(String? memberId, String? staffName, double? reviews, String? reviewCount) {
    return Get.start(
      RouterPath.THJobAppliedEmployeeRemarkER,
      arguments: {'memberId': memberId, 'staffName': staffName, 'reviews': reviews, 'reviewCount': reviewCount},
    );
  }

  @override
  AppliedErStaffReviewsController createRawController() {
    return AppliedErStaffReviewsController();
  }

  @override
  State<AppliedErStaffReviewsPage> createState() => _AppliedStaffReviewsState();
}

class _AppliedStaffReviewsState extends BaseState<AppliedErStaffReviewsPage, AppliedErStaffReviewsController> {
  late AppliedErStaffReviewsState state;

  @override
  void initState() {
    super.initState();
    state = controller.state;
    state.memberId = Get.arguments['memberId'];
    state.staffName = Get.arguments['staffName'];
    state.reviews = Get.arguments['reviews'];
    state.reviewCount = Get.arguments['reviewCount'];
  }

  @override
  Widget build(BuildContext context) {
    return autoCtlGetBuilder(builder: (controller) {
      return SafeArea(
        bottom: MediaQuery.of(context).padding.bottom > 38,
        top: false,
        child: Container(
          width: double.infinity,
          height: double.infinity,
          padding: EdgeInsets.only(top: ScreenUtil.getStatusBarH(context)),
          decoration: const BoxDecoration(
            gradient: LinearGradient(
              colors: [
                Color(0xFF091D44),
                Color(0xFF245A8A),
                Color(0xFF7F7CEC),
              ],
              begin: Alignment.topCenter,
              end: Alignment.bottomCenter,
            ),
          ),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            mainAxisSize: MainAxisSize.max,
            children: [
              MyAppBar.titleBar(context, "Staff Detail".tr),
              EasyRefresh(
                controller: controller.refreshController,
                onRefresh: controller.onRefresh,
                onLoad: controller.loadMore,
                child: LoadStateLayout(
                  state: controller.loadingState,
                  errorMessage: controller.errorMessage,
                  errorRetry: () {
                    controller.retryRequest();
                  },
                  successSliverWidget: [
                    //顶部用户信息
                    SliverToBoxAdapter(
                      child: _buildRemarkWidget(),
                    ),

                    //底部工作历史列表
                    SliverList(
                        delegate: SliverChildBuilderDelegate(
                      (context, index) {
                        return StaffReviewsItem(index: index, item: state.datas[index]);
                      },
                      childCount: state.datas.length,
                    ))
                  ],
                ),
              ).expanded(),
            ],
          ),
        ),
      );
    });
  }

  Widget _buildRemarkWidget() {
    return Container(
      padding: EdgeInsets.only(bottom: 22, left: 21, right: 21, top: 18.5),
      margin: EdgeInsets.only(left: 15, right: 15, top: 14.5, bottom: 5),
      decoration: BoxDecoration(
        color: Color(0xFF4DCFF6).withOpacity(0.2), // 设置背景颜色和不透明度
        borderRadius: BorderRadius.circular(5), // 设置圆角
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          MyTextView(
            state.staffName ?? "-",
            fontSize: 17,
            textColor: ColorConstants.white,
            isFontMedium: true,
            marginBottom: 8,
          ),
          Row(
            children: [
              RatingWidget(
                nomalImage: Assets.baseServiceRatingUnselected,
                selectImage: Assets.baseServiceRatingSelected,
                size: 21,
                padding: 5,
                selectAble: false,
                integerOnly: false,
                value: state.reviews ?? 0,
                onRatingUpdate: (value) {},
              ),
              MyTextView(
                "${state.reviews.toString()} (${state.reviewCount} Reviews)",
                fontSize: 14,
                marginLeft: 12,
                textColor: ColorConstants.textYellowF8AE00,
                isFontMedium: true,
              ).expanded(),
            ],
          ),
        ],
      ),
    );
  }
}
