/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2023-02-20 09:09:31
 * @LastEditTime : 2023-07-18 16:14:37
 * @Description  : Do not edit
 */
import 'package:flutter/material.dart';
import 'package:qrcode_package/src/view_models/private_norm_picker_store.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

class NormDetailPage extends StatelessWidget {
  const NormDetailPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (providerContext) =>
          PrivateNormPickerStore(context, providerContext),
      child: _PageView(),
      lazy: false,
    );
  }
}

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

class _PageViewState extends State<_PageView> {
  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateNormPickerStore>(context, listen: true);
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        title: WisText('设备登记详情',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: WisScrollView(
        onInit: () => store.getNormDetail(),
        slivers: <Widget>[
          Wisdom(
            border: Border(
              bottom: BorderSide(
                color: colorScheme.divider,
              ),
            ),
            alignment: Alignment.center,
            padding: EdgeInsets.all(20.pt),
            child: WisText(
              '${store.normDetail?.name ?? '--'}',
              size: 18.pt,
              color: colorScheme.mainTitle,
            ),
          ).asSliver(),
          Wisdom.column(
            padding: EdgeInsets.all(15.pt),
            crossAxisAlignment: CrossAxisAlignment.start,
            border: Border(
              bottom: BorderSide(
                color: colorScheme.divider,
              ),
            ),
            children: [
              WisText(
                '周期',
                size: 16.pt,
                color: colorScheme.mainTitle,
                weight: FontWeight.w500,
              ),
              SizedBox(height: 15.pt),
              WisText(
                '${store.normDetail?.cycleName ?? '--'}',
                size: 15.pt,
                color: Color(0xff666666),
              ),
            ],
          ).asSliver(),
          Wisdom.column(
            padding: EdgeInsets.all(15.pt),
            crossAxisAlignment: CrossAxisAlignment.start,
            border: Border(
              bottom: BorderSide(
                color: colorScheme.divider,
              ),
            ),
            children: [
              WisText(
                '规程',
                size: 16.pt,
                color: colorScheme.mainTitle,
                weight: FontWeight.w500,
              ),
              SizedBox(height: 15.pt),
              Wisdom.row(
                color: colorScheme.background2,
                borderRadius: BorderRadius.circular(4.pt),
                padding: EdgeInsets.all(15.pt),
                border: Border.all(
                  color: colorScheme.divider,
                ),
                children: [
                  HtmlWidget(
                    store.normDetail?.rule ?? '--',
                  ).asExpanded(),
                ],
              ),
            ],
          ).asSliver(),
          Wisdom.column(
            padding: EdgeInsets.all(15.pt),
            crossAxisAlignment: CrossAxisAlignment.start,
            border: Border(
              bottom: BorderSide(
                color: colorScheme.divider,
              ),
            ),
            children: [
              WisText(
                '操作',
                size: 16.pt,
                color: colorScheme.mainTitle,
                weight: FontWeight.w500,
              ),
              SizedBox(height: 15.pt),
              Wisdom.column(
                crossAxisAlignment: CrossAxisAlignment.stretch,
                color: colorScheme.background2,
                borderRadius: BorderRadius.circular(4.pt),
                padding: EdgeInsets.all(15.pt),
                border: Border.all(
                  color: colorScheme.divider,
                ),
                children: [
                  if (store.normDetail?.operators != null) ...[
                    for (int i = 0;
                        i < store.normDetail!.operators!.length;
                        i++)
                      RichText(
                        text: TextSpan(
                          children: [
                            TextSpan(text: '${i + 1}、'),
                            TextSpan(
                                text:
                                    '${store.normDetail!.operators![i].name}'),
                            TextSpan(
                                text:
                                    '${store.normDetail!.operators![i].type == 'radio' ? '单选：' : store.normDetail!.operators![i].type == 'checkbox' ? '多选：' : store.normDetail!.operators![i].type == 'text' ? '输入框' : '图片'}'),
                            TextSpan(
                              text:
                                  '${store.normDetail!.operators![i].connent!.join('/')}',
                            ),
                          ],
                          style: TextStyle(
                            fontSize: 14.pt,
                            fontWeight: FontWeight.w400,
                            color: Color(0xFF616178),
                          ),
                        ),
                      ),
                  ],
                ],
              ),
            ],
          ).asSliver(),
        ],
      ),
    );
  }
}
