/*
 * @Author: WuWei
 * @Date: 2020-07-21 11:06:13
 * @LastEditors: ChenYaJin
 * @LastEditTime: 2023-03-27 14:36:49
 * @Description: 详情首页
 */
import 'package:app_package/app_package.dart';
import 'package:flutter/material.dart';
import 'package:report_package/src/models/report_detail.dart';
import 'package:report_package/src/models/report_dialog.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import '../../view_models/private_detail_model.dart';
import '../../components/list_item.dart';
part './components/consult.dart';
part './components/detail.dart';
part './components/score.dart';
part './components/bottom_detail.dart';
part './components/bottom_consult.dart';

// part 'components/list.dart';
class DetailPage extends StatelessWidget {
  const DetailPage({Key? key}) : super(key: key);
  @override
  Widget build(BuildContext context) {
    return ChangeNotifierProvider(
      create: (_) => PrivateReportDetailStore(context),
      child: _PageView(),
      lazy: false,
    );
  }
}

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

class _PageViewState extends State<_PageView> {
  PrivateReportDetailStore get store => Provider.of(context, listen: false);
  @override
  Widget build(BuildContext context) {
    PrivateReportDetailStore _store;
    _store = Provider.of<PrivateReportDetailStore>(context, listen: true);
    final colorScheme = WTheme.of(context).colorScheme;
    return Scaffold(
      appBar: WAppBar(
        iconTheme: IconThemeData(
          color: colorScheme.mainTitle,
          size: 19.pt,
        ),
        backgroundColor: Colors.white,
        brightness: Brightness.light,
        title: WisText('报事详情',
            size: 19.pt, weight: FontWeight.w600, color: colorScheme.mainTitle),
      ),
      body: Column(children: [
        if (_store.reportDetail?.statusName != '待受理') ...[
          if (_store.reportDetail?.linkId != null &&
              _store.reportDetail?.linkId != '') ...[
            _InCludeScore().asFlexible(flex: 1),
          ] else ...[
            _NotInCludeScore().asFlexible(flex: 1),
          ],
        ] else ...[
          _TabDetailComponent().asFlexible(flex: 1),
        ]
      ]),
      bottomNavigationBar: _store.tabIndex == 0
          ? _BottomDetailComponent()
          : _store.reportDetail?.linkId != null &&
                  _store.reportDetail?.linkId != '' &&
                  _store.tabIndex == 2
              ? _BottomConsultComponent()
              : (_store.reportDetail?.linkId == null ||
                          _store.reportDetail?.linkId == '') &&
                      _store.tabIndex == 1
                  ? _BottomConsultComponent()
                  : null,
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final _store = Provider.of<PrivateReportDetailStore>(
      context,
      listen: true,
    );

    return WisTabPage(
      initialIndex: _store.args['index'] ?? 0,
      onChange: (index) => {_store.setTabIndex(index)},
      tabs: <Widget>[
        WisText('报事详情'),
        WisText('查看评分'),
        WisText('在线沟通'),
      ],
      views: <Widget>[
        _TabDetailComponent(),
        _TabScoreComponent(),
        _TabConsultComponent(),
      ],
      indicatorPadding: EdgeInsets.symmetric(horizontal: 23.pt),
      indicatorWeight: 4.0,
      indicator: RoundUnderlineTabIndicator(
        width: 25.pt,
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final _store = Provider.of<PrivateReportDetailStore>(
      context,
      listen: true,
    );

    return WisTabPage(
      initialIndex: _store.args['index'] ?? 0,
      onChange: (index) => {_store.setTabIndex(index)},
      tabs: <Widget>[
        WisText('报事详情'),
        WisText('在线沟通'),
      ],
      views: <Widget>[
        _TabDetailComponent(),
        _TabConsultComponent(),
      ],
      indicatorPadding: EdgeInsets.symmetric(horizontal: 23.pt),
      indicatorWeight: 4.0,
      indicator: RoundUnderlineTabIndicator(
        width: 25.pt,
      ),
    );
  }
}
