/*
 * @Author: wjc
 * @Date: 2022-04-19 14:57:47
 * @LastEditors: wjc
 * @LastEditTime: 2023-03-30 15:22:45
 * @Description: 
 */
import 'package:flutter/material.dart';
import 'package:wisdom_cli/wisdom_cli.dart';
import 'package:smart_devices_package/src/components/showCofirmMeterDialog.dart';
import '../../view_models/private_sd_detail_model.dart';
import '../../view_models/private_sd_index_model.dart';
part 'components/detail.dart';
part 'components/timing.dart';

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

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<PrivateDetailStore>(context, listen: true);
    var item = store.routingArgs['item'];
    final colorScheme = WTheme.of(context).colorScheme;
    return new WillPopScope(
      onWillPop: () {
        Navigator.pop(context, item);
        return new Future(() => false);
      },
      child: 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: WisTabPage(
          onChange: (index) => {store.setTabIndex(index)},
          tabs: <Widget>[
            WisText('设备详情'),
            WisText('定时管理'),
          ],
          views: <Widget>[
            _TabDetailComponent(),
            _TabTimingComponent(),
          ],
          indicatorPadding: EdgeInsets.symmetric(horizontal: 23.pt),
          indicatorWeight: 4.0,
          indicator: RoundUnderlineTabIndicator(
            width: 25.pt,
          ),
        ),
        bottomNavigationBar: store.tabIndex == 0
            ? Container(
                height: 0,
              )
            : Wisdom.row(
                color: Colors.white,
                height: 80.pt,
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.stretch,
                padding:
                    EdgeInsets.symmetric(horizontal: 15.pt, vertical: 18.pt),
                onTap: () => store.route2TimingPage(null),
                children: [
                    Wisdom(
                      height: 44.pt,
                      color: colorScheme.primary,
                      borderRadius: BorderRadius.circular(25.pt),
                      child: Center(
                        child: WisText(
                          '新增定时',
                          size: 16.pt,
                          color: Colors.white,
                        ),
                      ),
                    ).asExpanded(),
                  ]),
        // WButton(
        //   height: 44.pt,
        //   shape: RoundedRectangleBorder(),
        //   onPressed: () => store.route2TimingPage(null),
        //   child: WisText("新增定时"),
        // ),
      ),
    );
  }
}
