import 'package:feelverapp/ui/shop/shop_service_presenter.dart';
import 'package:feelverapp/util/SizeConfig.dart';
import 'package:feelverapp/util/rating_star.dart';
import 'package:flutter/material.dart';

import '../../service/api.dart';

class ShopServicePage extends StatefulWidget {
  @override
  _ShopServicePageState createState() => _ShopServicePageState();
}

class _ShopServicePageState extends State<ShopServicePage>
    with TickerProviderStateMixin {
  double rate1 = 0;

  ShopServicePresenter presenter;

  @override
  void initState() {
    super.initState();

    presenter = ShopServicePresenter(this);
    presenter.Servicelistitem();
  }

  @override
  void dispose() {
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    SizeConfig(context);
    return Container(
        child: presenter.serviceModel == null
            ? Container()
            : ListView.builder(
                itemCount: presenter.serviceModel.data.length,
                itemBuilder: (context, i) {
                  return myCard(
                    presenter.serviceModel.data[i].name,
                    presenter.serviceModel.data[i].cover,
                    presenter.serviceModel.data[i].price,
                    presenter.serviceModel.data[i].duration,
                    presenter.serviceModel.data[i].specialPrice == null ? "" : presenter.serviceModel.data[i].specialPrice,
                  );
                })

        );
  }

  Widget myCard(String title, String image, String price, String time, String special_price) {
    return Card(
      margin: EdgeInsets.only(
          right: SizeConfig.getPadding(16),
          left: SizeConfig.getPadding(16),
          top: SizeConfig.getPadding(10),
          bottom: SizeConfig.getPadding(10)),
      child: Container(
//        color: Colors.red,
        margin: EdgeInsets.only(right: 15, left: 15, bottom: 20, top: 20),
//                          color: Colors.blueGrey,
        child: Column(
          children: <Widget>[
            Row(
              children: <Widget>[
                Expanded(
                  flex: 3,
                  child: Container(
//                          color: Colors.blue,
                      height: SizeConfig.getHeight(250),
                      child: presenter.serviceModel == null
                          ? Image.asset(
                              "assets/images/demo_img.png",
                              fit: BoxFit.cover,
                            )
                          : Image.network(
                        Api.baseApiforimage + image,
                              fit: BoxFit.cover,
                            ),),
                ),
                Expanded(
                  flex: 5,
                  child: Container(
                    margin: EdgeInsets.only(left: 15),
//                          color: Colors.yellow,
                    height: SizeConfig.getHeight(260),
                    child: Column(
                      children: <Widget>[
                        Container(
                          padding: EdgeInsets.all(10),
                          alignment: Alignment.topLeft,
//                                  color: Colors.red,
                          child: Column(
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: <Widget>[
                              Text(
                                title,
                                style: TextStyle(
                                    color: Colors.black,
                                    fontSize: SizeConfig.getFontSize(18),
                                    fontFamily: "SF_Pro_Text",
                                    fontWeight: FontWeight.w500),
                              ),
                              SizedBox(
                                height: 5,
                              ),
                              Text(
                                "SPA Cenvaree @ Centara Grand CentralWorld Bangkok",
                                style: TextStyle(
                                    color: Color(0xff969696),
                                    fontSize: SizeConfig.getFontSize(11),
                                    fontFamily: "SF_Pro_Text",
                                    fontWeight: FontWeight.w500),
                              ),
                            ],
                          ),
                        ),
                        Container(
                          padding: EdgeInsets.only(left: 10, right: 10),
                          alignment: Alignment.topLeft,
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.start,
                            children: <Widget>[
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Image.asset(
                                    'assets/images/pin_drop.png',
                                    height: 20,
                                    width: 20,
                                  ),
                                  SizedBox(
                                    width: 5,
                                  ),
                                  Text(
                                    "พญาไท กรุงเทพฯ",
                                    style: TextStyle(
                                      color: Colors.black,
                                      fontSize: SizeConfig.getFontSize(13),
                                      fontFamily: "SF_Pro_Text",
                                    ),
                                  ),
                                ],
                              ),
                              SizedBox(
                                height: 10,
                              ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.center,
                                children: <Widget>[
                                  Icon(
                                    Icons.access_time,
                                    color: Color(0xffEEAFB7),
                                  ),
                                  SizedBox(
                                    width: 5,
                                  ),
                                  Text(
                                    time,
                                    style: TextStyle(
                                      color: Colors.black,
                                      fontSize: SizeConfig.getFontSize(13),
                                      fontFamily: "SF_Pro_Text",
                                    ),
                                  ),
                                ],
                              ),
                              SizedBox(
                                height: 10,
                              ),
                              Row(
                                crossAxisAlignment: CrossAxisAlignment.end,
                                children: <Widget>[
                                  Text(
                                    special_price,
                                    style: TextStyle(
                                      fontSize: SizeConfig.getFontSize(12),
                                      decoration: TextDecoration.lineThrough,
                                    ),
                                  ),
                                  SizedBox(
                                    width: 15,
                                  ),
                                  Text(
                                    "฿" + price,
                                    style: TextStyle(
                                        color: Colors.red,
                                        fontSize: SizeConfig.getFontSize(18),
                                        fontFamily: "SF_Pro_Text",
                                        fontWeight: FontWeight.w500),
                                  ),
                                ],
                              ),
                              SizedBox(
                                height: SizeConfig.getHeight(5),
                              ),
                              Container(
                                child: Row(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: <Widget>[
                                    RatingStar(
                                      isRating: true,
                                      rate: rate1,
                                      starSize: 20,
                                      onChangeRate: (i) {
                                        setState(() {
                                          rate1 = i;
                                          print(i);
                                        });
                                      },
                                    ),
                                  ],
                                ),
                              ),
                            ],
                          ),
                        ),
                      ],
                    ),
                  ),
                ),
              ],
            ),
          ],
        ),
      ),
    );
  }
}
