/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2022-04-14 15:34:54
 * @LastEditTime : 2023-05-11 15:49:15
 * @Description  : Do not edit
 */

import 'package:app_package/app_package.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import '../../view_models/private_detail_model.dart';

class RepairPage extends StatelessWidget {
  const RepairPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => RepairDetailStore(context),
      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) {
    RepairDetailStore store;
    store = Provider.of<RepairDetailStore>(context);
    final style = WTheme.of(context);
    final colorScheme = style.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(
        slivers: <Widget>[
          SliverToBoxAdapter(
            child: Wisdom.column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                Wisdom.column(
                  crossAxisAlignment: CrossAxisAlignment.stretch,
                  children: <Widget>[
                    Wisdom(
                      margin: EdgeInsets.all(15.pt),
                      child: Text(
                        '绘制美好服务，从您的用心开始',
                        style: TextStyle(
                          fontSize: 13.pt,
                          color: Color(0xFF00BC84),
                        ),
                      ),
                    ),
                    WisCard(
                      color: Colors.white,
                      padding: EdgeInsets.fromLTRB(15.pt, 0, 15.pt, 15.pt),
                      margin: EdgeInsets.symmetric(horizontal: 15.pt),
                      elevation: 0,
                      child: Wisdom.column(
                        children: <Widget>[
                          WFormTile(
                            required: true,
                            leading: WisText(
                              '开启说明',
                              size: 15.pt,
                            ),
                          ),
                          Wisdom(
                            padding: EdgeInsets.only(bottom: 12.pt),
                            child: TextFormField(
                              initialValue: store.reopenRemark,
                              onChanged: (v) => store.onReopenRemarkChange(v),
                              validator: (v) => (v != '') ? null : '重新开启说明不可为空',
                              scrollPadding: EdgeInsets.zero,
                              decoration: InputDecoration(
                                fillColor: Colors.white,
                                contentPadding:
                                    EdgeInsets.symmetric(horizontal: 9.pt),
                                hintText:
                                    '简要说明本次服务重新开启的原因，该内容将会展示给业主，请仔细填写，内容不低于5个字。',
                              ),
                              minLines: 3,
                              maxLines: 5,
                              maxLength: 200,
                            ),
                          ),
                          Divider(
                            height: 30.pt,
                          ),
                          Wisdom.wrap(
                            alignment: Alignment.centerLeft,
                            wrapAlignment: WrapAlignment.start,
                            spacing: 10.pt,
                            runSpacing: 10.pt,
                            children: <Widget>[
                              if (store.reopenPhotos!.length < 6)
                                WImageSelecter(
                                  maxCount: 6,
                                  currentCount: store.reopenPhotos?.length ?? 0,
                                  onSelected: (files) =>
                                      store.pickImageReopen(files),
                                  size: 58.pt,
                                ),
                              ...WImagePreview.buildList(
                                size: 58.pt,
                                images: store.reopenPhotos!
                                    .map((e) => CachedNetworkImageProvider(
                                        AppParseUtil.image(e)))
                                    .toList(),
                                onDelete: (index) =>
                                    store.removeImageReopen(index),
                              ),
                            ],
                          ),
                          Container(
                            margin: EdgeInsets.only(top: 15.pt),
                            child: Text(
                              '最多上传6张图片，该图片将发送给业主，请核实后再上传。',
                              style: TextStyle(
                                fontSize: 14.pt,
                                color: Color(0xffcccccc),
                              ),
                            ),
                          ),
                        ],
                      ),
                    ),
                  ],
                )
              ],
            ),
          ),
        ],
      ),
      bottomNavigationBar: BottomAppBar(
        child: Wisdom.row(
          height: 60.pt,
          padding: EdgeInsets.symmetric(horizontal: 15.pt),
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Expanded(
              child: Wisdom(
                height: 44.pt,
                onTap: () => store.putReopen(),
                color: store.reopenRemark == null || store.reopenRemark == ''
                    ? Color.fromRGBO(192, 220, 250, 1)
                    : colorScheme.primary,
                borderRadius: BorderRadius.circular(25.pt),
                child: Wisdom(
                  alignment: Alignment.center,
                  child: WisText.white('确定重启', size: 16.pt),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
