/*
 * @Author       : WuWei
 * @LastEditors  : WuWei
 * @Date         : 2021-12-10 16:35:38
 * @LastEditTime : 2023-09-22 17:34:15
 * @Description  : Do not edit
 */
import 'package:app_package/src/view_models/message_store.dart';
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';

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

class _PageView extends StatelessWidget {
  const _PageView({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final store = Provider.of<PrivateMessageStore>(context, listen: true);
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        brightness: Brightness.light,
        title: WisText('${store.routingArgs?['appBarTitle'] ?? '表单列表'}',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
      ),
      body: WisScrollView(
        key: store.scrollViewKey,
        onInit: () => store.onInitList(),
        onRefresh: () => store.onInitList(),
        onLoad: () => store.onGetFormList(true),
        slivers: [
          SliverToBoxAdapter(
            child: Column(
              children: [
                for (int i = 0; i < store.formHisList.length; i++)
                  WisCard(
                    margin: EdgeInsets.fromLTRB(
                        15.pt, i == 0 ? 15.pt : 0, 15.pt, 10.pt),
                    child: Wisdom.column(
                      onTap: () => store.toDetail(
                          store.formHisList[i], store.formHisList[i].title),
                      color: Colors.white,
                      crossAxisAlignment: CrossAxisAlignment.stretch,
                      padding: EdgeInsets.symmetric(horizontal: 15.pt),
                      children: [
                        Wisdom.row(
                          padding: EdgeInsets.symmetric(vertical: 20.pt),
                          border: Border(
                            bottom: BorderSide(
                              width: 0.5.pt,
                              color: colorScheme.divider2,
                            ),
                          ),
                          children: [
                            WisText(
                              store.formHisList[i].title ?? '--',
                              size: 15.pt,
                              weight: FontWeight.w600,
                              color: colorScheme.mainTitle,
                              maxLines: 2,
                              overflow: TextOverflow.ellipsis,
                            ),
                          ],
                        ),
                        Wisdom.row(
                          padding: EdgeInsets.symmetric(vertical: 10.pt),
                          children: [
                            WisText(
                              store.formHisList[i].fillByName ?? '--',
                              overflow: TextOverflow.ellipsis,
                              size: 14.pt,
                              weight: FontWeight.w300,
                              color: colorScheme.minor,
                            ).asExpanded(),
                            WisText(
                              store.formHisList[i].fillAt ?? '--',
                              size: 14.pt,
                              weight: FontWeight.w300,
                              color: colorScheme.minor,
                            ),
                          ],
                        )
                      ],
                    ),
                  ),
              ],
            ),
          )
        ],
      ),
      bottomNavigationBar: store.hasFillAuth == true
          ? SafeArea(
              child: Wisdom.row(
                  height: 60.pt,
                  color: Colors.white,
                  padding:
                      EdgeInsets.symmetric(horizontal: 15.pt, vertical: 8.pt),
                  children: [
                    WisButton(
                      buttonShape: WisButtonShape.round,
                      constraints: BoxConstraints(minHeight: 44.pt),
                      onPressed: () => store
                          .toAddForm('${store.routingArgs!['appBarTitle']}'),
                      child: Text(
                        '新增填表',
                        style: TextStyle(fontSize: 18.pt),
                      ),
                    ).asExpanded(),
                  ]),
            )
          : Container(height: 0),
    );
  }
}
