import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:fooddeliveryapp/constants.dart';
import 'package:fooddeliveryapp/model/product.dart';
import 'package:fooddeliveryapp/pages/cart.dart';
import 'package:fooddeliveryapp/pages/order/components/body.dart';

class HomeSrcreen extends StatelessWidget {
  static const routeName = '/order';
  final int index;

  //构造函数 同时传入桌号
  HomeSrcreen({Key key, @required this.index}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: getMyTabs().length,
      child: Scaffold(
        appBar: buildAppBar(context),
        body: Body(),
      ),
    );
  }

  AppBar buildAppBar(BuildContext context) {
    return AppBar(
      backgroundColor: Colors.white,
      elevation: 0,
      title: Padding(
        padding: const EdgeInsets.symmetric(horizontal: kDefaultPaddin),
        child: Text(
          "海底捞火锅",
          style: Theme.of(context)
              .textTheme
              .headline5
              .copyWith(fontWeight: FontWeight.bold),
        ),
      ),
      leading: IconButton(
        icon: SvgPicture.asset("assets/icons/back.svg"),
        onPressed: () {},
      ),
      actions: <Widget>[
        // IconButton(
        //   icon: SvgPicture.asset(
        //     "assets/icons/search.svg",
        //     // By default our  icon color is white
        //     color: kTextColor,
        //   ),
        //   onPressed: () {},
        // ),
        IconButton(
          icon: SvgPicture.asset(
            "assets/icons/cart.svg",
            // By default our  icon color is white
            color: kTextColor,
          ),
          onPressed: () {
            Navigator.pushNamed(context, OrderCart.routeName, arguments: index);
          },
        ),
        SizedBox(width: kDefaultPaddin / 2)
      ],
      bottom: TabBar(tabs: getMyTabs().map((e) => e.tab).toList()),
    );
  }
}

List<MyTab> getMyTabs() {
  return [
    MyTab(
      Tab(
        child: Text(
          "锅底",
          style: TextStyle(color: Colors.black),
        ),
      ),
      Menu(
        productsList: productsguodi,
      ),
    ),
    MyTab(
      Tab(
        child: Text(
          "荤菜",
          style: TextStyle(color: Colors.black),
        ),
      ),
      // Icon(Icons.directions_transit, color: Colors.pink, size: 60),
      Menu(productsList: productshuncai),
    ),
    MyTab(
      Tab(
        child: Text(
          "素菜",
          style: TextStyle(color: Colors.black),
        ),
      ),
      // Icon(Icons.directions_bike, color: Colors.pink, size: 60),
      Menu(productsList: productssucai),
    ),
    MyTab(
      Tab(
        child: Text(
          "主食",
          style: TextStyle(color: Colors.black),
        ),
      ),
      // Icon(Icons.directions_bike, color: Colors.pink, size: 60),
      Menu(productsList: productsZhushi),
    ),
    MyTab(
      Tab(
        child: Text(
          "酒水",
          style: TextStyle(color: Colors.black),
        ),
      ),
      // Icon(Icons.directions_bike, color: Colors.pink, size: 60),
      Menu(productsList: productsJiushui),
    ),
    MyTab(
      Tab(
        child: Text(
          "调料",
          style: TextStyle(color: Colors.black),
        ),
      ),
      // Icon(Icons.directions_bike, color: Colors.pink, size: 60),
      Menu(productsList: productsTiaoliao),
    )
  ];
}

/// 因此抽象成独立的类
class MyTab {
  Tab tab;
  Widget body;

  MyTab(this.tab, this.body);
}
