/*
 * @Author: ChenYaJin
 * @Date: 2022-12-12 11:27:08
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-02-13 14:34:55
 * @Description: 
 */
import 'package:get/get.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import '../../assets.gen.dart';
import 'package:service_center_package/src/view_models/service_center_report.dart';

class FilterReportPage extends StatelessWidget {
  const FilterReportPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final ServiceCenterReportStore store = Get.find<ServiceCenterReportStore>();

    return Scaffold(
      backgroundColor: Color(0xFFF8F8F8),
      appBar: WAppBar(
        title: WisText(
          '筛选',
          color: colorScheme.mainTitle,
          weight: FontWeight.w600,
          size: 18.pt,
        ),
        brightness: Brightness.light,
        backgroundColor: Colors.white,
        leading: IconButton(
          onPressed: () {
            store.back();
          },
          icon: Image(
            image: AssetList.$close_0_png_image,
            width: 25.pt,
          ),
        ),
      ),
      body: WisScrollView(
        slivers: [
          SliverToBoxAdapter(
            child: Wisdom.column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              color: Colors.white,
              minHeight: MediaQuery.of(context).size.height,
              padding: EdgeInsets.only(
                top: 5.pt,
                left: 15.pt,
                right: 15.pt,
                bottom: 15.pt,
              ),
              children: [
                Wisdom.column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: [
                    Text(
                      '提报类型',
                      style: TextStyle(
                        fontSize: 16.pt,
                        fontWeight: FontWeight.bold,
                      ),
                    ).asPaddingSymmetric(vertical: 5.pt),
                    ButtonTheme(
                      minWidth: 100.pt,
                      height: 39.pt,
                      textTheme: ButtonTextTheme.accent,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(4.pt),
                      ),
                      child: Obx(
                        () => Wrap(
                          spacing: 10.pt,
                          runSpacing: 15.pt,
                          alignment: WrapAlignment.start,
                          children: [
                            for (var i = 0; i < store.typeList.length; i++) ...[
                              WButton(
                                onPressed: () =>
                                    store.onChooseType(store.typeList[i]['id']),
                                color: Color.fromRGBO(246, 247, 252, 1),
                                shape: RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(4.pt),
                                  side: BorderSide(
                                    width: 1,
                                    color: store.businessTypeId.value ==
                                            store.typeList[i]['id']
                                        ? colorScheme.primary.withOpacity(0.5)
                                        : colorScheme.background,
                                    style: BorderStyle.solid,
                                  ),
                                ),
                                child: Text(
                                  store.typeList[i]['name'] ?? '',
                                  style: TextStyle(
                                    fontSize: 13.pt,
                                    color: store.businessTypeId.value ==
                                            store.typeList[i]['id']
                                        ? colorScheme.primary
                                        : colorScheme.minor,
                                  ),
                                ),
                              ),
                            ],
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
                Wisdom.column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: [
                    Text(
                      '分类',
                      style: TextStyle(
                        fontSize: 16.pt,
                        fontWeight: FontWeight.bold,
                      ),
                    ).asPaddingSymmetric(vertical: 5.pt),
                    ButtonTheme(
                      minWidth: 100.pt,
                      height: 39.pt,
                      textTheme: ButtonTextTheme.accent,
                      shape: RoundedRectangleBorder(
                        borderRadius: BorderRadius.circular(4.pt),
                      ),
                      child: Obx(
                        () => Wrap(
                          spacing: 15.pt,
                          runSpacing: 15.pt,
                          alignment: WrapAlignment.start,
                          children: [
                            WButton(
                              onPressed: () => store.onResetSort(),
                              color: Color.fromRGBO(246, 247, 252, 1),
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(4.pt),
                                side: BorderSide(
                                  width: 1,
                                  color: store.checkSortIds.length == 0 &&
                                          store.businessTypeId.value.isNotEmpty
                                      ? colorScheme.primary.withOpacity(0.5)
                                      : colorScheme.background,
                                  style: BorderStyle.solid,
                                ),
                              ),
                              child: Text(
                                '全部',
                                style: TextStyle(
                                  fontSize: 13.pt,
                                  color: store.checkSortIds.length == 0 &&
                                          store.businessTypeId.value.isNotEmpty
                                      ? colorScheme.primary
                                      : colorScheme.minor,
                                ),
                              ),
                            ),
                            for (var item in store.sortList) ...[
                              WButton(
                                onPressed: () => store.onChooseSort(item['id']),
                                color: Color.fromRGBO(246, 247, 252, 1),
                                shape: RoundedRectangleBorder(
                                  borderRadius: BorderRadius.circular(4.pt),
                                  side: BorderSide(
                                    width: 1,
                                    color: store.checkSortIds
                                            .contains(item['id'])
                                        ? colorScheme.primary.withOpacity(0.5)
                                        : colorScheme.background,
                                    style: BorderStyle.solid,
                                  ),
                                ),
                                child: Text(
                                  item['sortName'] ?? '',
                                  style: TextStyle(
                                    fontSize: 13.pt,
                                    color:
                                        store.checkSortIds.contains(item['id'])
                                            ? colorScheme.primary
                                            : colorScheme.minor,
                                  ),
                                ),
                              )
                            ],
                          ],
                        ),
                      ),
                    ),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
      bottomNavigationBar: Wisdom.row(
        padding: EdgeInsets.symmetric(horizontal: 15.pt),
        color: Colors.white,
        children: [
          SafeArea(
            child: WLoadingButton(
              color: Colors.white,
              height: 44.pt,
              minWidth: 120.pt,
              margin: EdgeInsets.symmetric(vertical: 8.pt),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(25.pt),
                side: BorderSide(
                  width: 1,
                  color: colorScheme.primary.withOpacity(0.5),
                  style: BorderStyle.solid,
                ),
              ),
              onPressed: () => store.onResetInner(),
              child: WisText('重置', color: colorScheme.primary),
            ),
          ),
          SafeArea(
            child: WLoadingButton(
              height: 44.pt,
              margin: EdgeInsets.only(top: 8.pt, bottom: 8.pt, left: 10.pt),
              shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(25.pt),
              ),
              onPressed: () => store.submit(),
              child: Text("确认"),
            ),
          ).asExpanded(),
        ],
      ),
    );
  }
}
