/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2023-08-07 11:01:15
 * @LastEditTime : 2023-09-20 10:18:34
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

import '../../view_models/filter_store.dart';

class FilterPage extends StatelessWidget {
  const FilterPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return _PageView();
  }
}

class _PageView extends StatefulWidget {
  _PageView({Key? key}) : super(key: key);
  @override
  _PageViewState createState() => _PageViewState();
}

class _PageViewState extends State<_PageView> {
  @override
  void dispose() {
    Get.delete<FilterStore>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    final style = WTheme.of(context);
    final colorScheme = style.colorScheme;
    final FilterStore store =
        Get.isRegistered() ? Get.find() : Get.put(FilterStore());

    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: Icon(
            Icons.close,
            color: colorScheme.mainTitle,
            size: 25.pt,
          ),
        ),
      ),
      body: WisScrollView(
        onInit: () => store.onInitData(),
        slivers: [
          SliverToBoxAdapter(
            child: Wisdom.column(
              color: Colors.white,
              crossAxisAlignment: CrossAxisAlignment.stretch,
              padding: EdgeInsets.only(
                top: 5.pt,
                left: 15.pt,
                right: 15.pt,
                bottom: 15.pt,
              ),
              children: [
                // WFilterButtons(
                //   name: '状态',
                //   child: Wrap(
                //     spacing: 15.pt,
                //     runSpacing: 12.pt,
                //     alignment: WrapAlignment.start,
                //     children: [
                //       for (var i = 0; i < store.statusList.length; i++) ...[
                //         WButton(
                //           onPressed: () => store
                //               .changeStatusValue(store.statusList[i]['code']),
                //           color: Color.fromRGBO(246, 247, 252, 1),
                //           shape: RoundedRectangleBorder(
                //             borderRadius: BorderRadius.circular(4.pt),
                //             side: BorderSide(
                //               width: 1,
                //               color: store.status == store.statusList[i]['code']
                //                   ? colorScheme.primary.withOpacity(0.5)
                //                   : colorScheme.background,
                //               style: BorderStyle.solid,
                //             ),
                //           ),
                //           child: Text(
                //             store.statusList[i]['name'] ?? '',
                //             style: TextStyle(
                //               fontSize: 13.pt,
                //               color: store.status == store.statusList[i]['code']
                //                   ? colorScheme.primary
                //                   : colorScheme.minor,
                //             ),
                //           ),
                //         )
                //       ],
                //     ],
                //   ),
                // ),
                SizedBox(height: 10.pt),
                Obx(() {
                  return WFilterButtons(
                    name: '类型',
                    child: Wrap(
                      spacing: 15.pt,
                      runSpacing: 12.pt,
                      alignment: WrapAlignment.start,
                      children: [
                        for (var i = 0; i < store.classList.length; i++) ...[
                          Obx(() {
                            return WButton(
                              onPressed: () =>
                                  store.changeClass(store.classList[i].id),
                              color: Color.fromRGBO(246, 247, 252, 1),
                              shape: RoundedRectangleBorder(
                                borderRadius: BorderRadius.circular(4.pt),
                                side: BorderSide(
                                  width: 1,
                                  color: store.classId == store.classList[i].id
                                      ? colorScheme.primary.withOpacity(0.5)
                                      : colorScheme.background,
                                  style: BorderStyle.solid,
                                ),
                              ),
                              child: Text(
                                store.classList[i].name ?? '',
                                style: TextStyle(
                                  fontSize: 13.pt,
                                  color: store.classId == store.classList[i].id
                                      ? colorScheme.primary
                                      : colorScheme.minor,
                                ),
                              ),
                            );
                          }),
                        ],
                      ],
                    ),
                  );
                }),
                SizedBox(height: 10.pt),
                WFilterButtons(
                  name: '服务类型',
                  child: Wrap(
                    spacing: 15.pt,
                    runSpacing: 12.pt,
                    alignment: WrapAlignment.start,
                    children: [
                      for (var i = 0;
                          i < store.dynamicTypeList.length;
                          i++) ...[
                        Obx(() {
                          return WButton(
                            onPressed: () => store.changeDynamicType(
                                store.dynamicTypeList[i]['code']),
                            color: Color.fromRGBO(246, 247, 252, 1),
                            shape: RoundedRectangleBorder(
                              borderRadius: BorderRadius.circular(4.pt),
                              side: BorderSide(
                                width: 1,
                                color: store.type ==
                                        store.dynamicTypeList[i]['code']
                                    ? colorScheme.primary.withOpacity(0.5)
                                    : colorScheme.background,
                                style: BorderStyle.solid,
                              ),
                            ),
                            child: Text(
                              store.dynamicTypeList[i]['name'] ?? '',
                              style: TextStyle(
                                fontSize: 13.pt,
                                color: store.type ==
                                        store.dynamicTypeList[i]['code']
                                    ? 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(),
        ],
      ),
    );
  }
}
