/*
 * @Author: WuWei
 * @Date: 2020-07-15 14:49:51
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-30 15:38:46
 * @Description:
 */

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 HandupPage extends StatelessWidget {
  const HandupPage({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.hangUpRemark,
                              onChanged: (v) => store.handupRemarkChange(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>[
                              WisText('*', color: Color(0XFFFF495E)),
                              if (store.hangUpPhotos!.length < 3)
                                WImageSelecter(
                                  maxCount: 3,
                                  currentCount: store.hangUpPhotos?.length ?? 0,
                                  onSelected: (files) =>
                                      store.pickImageHandup(files),
                                  size: 58.pt,
                                ),
                              ...WImagePreview.buildList(
                                size: 58.pt,
                                images: store.hangUpPhotos!
                                    .map((e) => CachedNetworkImageProvider(
                                        AppParseUtil.image(e)))
                                    .toList(),
                                onDelete: (index) =>
                                    store.removeImageHandup(index),
                              ),
                            ],
                          ),
                          Container(
                            margin: EdgeInsets.only(top: 15.pt),
                            child: Text(
                              '最多上传3张图片，推荐上传问题解决前后的对比图片。图片会发送给业主，请勿发送无关图片。',
                              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.putHandup(),
                color: store.hangUpRemark == null ||
                        store.hangUpRemark == '' ||
                        store.hangUpPhotos == null ||
                        store.hangUpPhotos!.length == 0
                    ? Color.fromRGBO(192, 220, 250, 1)
                    : colorScheme.primary,
                borderRadius: BorderRadius.circular(25.pt),
                child: Wisdom(
                  alignment: Alignment.center,
                  child: WisText.white('确定挂起', size: 16.pt),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }
}
