import 'package:onlineschool/staff/labulabu/common_widget/TopPromoSlider.dart';
import 'package:onlineschool/cusomer/labulabu/screens/Details.dart';
import 'package:onlineschool/staff/labulabu/utils/Utils.dart';
import 'package:onlineschool/cusomer/signin/googleSigin.dart';
import 'package:flutter/material.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:intl/intl.dart';
import 'package:smooth_star_rating/smooth_star_rating.dart';

class GridTilesCategory extends StatelessWidget {
  String username;
  String mediaUrl;
  String mediaUrlTitle;
  String description;
  String category;
  String ownerId;
  String postId;
  String poster;
  String title;
  String language;
  String price;
  String pdfurl;
  double rating;

  //  writecontent
  String defaultFontFamily = 'Roboto-Light.ttf';
  double defaultFontSize = 14;
  double defaultIconSize = 17;

  GridTilesCategory({
    Key key,
    @required this.username,
    @required this.mediaUrl,
    @required this.mediaUrlTitle,
    @required this.description,
    @required this.category,
    @required this.ownerId,
    @required this.postId,
    @required this.title,
    @required this.poster,
    @required this.price,
    @required this.language,
    @required this.pdfurl,
    @required this.rating,
  }) : super(key: key);
  TextStyle boldStyle = TextStyle(
    color: Colors.black,
    fontWeight: FontWeight.bold,
  );


  @override
  Widget build(BuildContext context) {
    String formatPrice =
    new NumberFormat("#,##0", "en_US").format(int.parse(price));
    double width = (MediaQuery.of(context).size.width);
    return InkWell(
      onTap: () {

          Navigator.push(
            context,
            MaterialPageRoute(
                builder: (context) => Details(
                    username:username,
                    mediaUrl:mediaUrl,
                    mediaUrlTitle:mediaUrlTitle,
                    description:description,
                    category:category,
                    ownerId:ownerId,
                    postId:postId,
                    poster:poster,
                    title:title,
                    rating: rating,
                    language:language,
                    price:price,
                    pdfurl: pdfurl
                )),
          );
      },
      child: Card(
        color: Colors.white,
        elevation: 0,
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
//               buildPostHeader(title: username) ,
            buildLikeableImage(image: mediaUrlTitle,postId: postId+"staffcategory"),
            // writeContent(Icons.monetization_on, " "+formatPrice+" "+Utils.crrmark, 0xFFFF0000,Utils.price),
            writeContent(Icons.title, title, 0xFF666666,Utils.title),
            // writeContent(Icons.language, language, 0xFF666666, Utils.language),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: <Widget>[
//            Padding(padding: const EdgeInsets.only(left: 20.0, top: 40.0)),
                Expanded(child:  SmoothStarRating(
                  rating: rating,
                  isReadOnly: true,
                  size: width/50,
                  color: Colors.blue,
                  filledIconData: Icons.star,
//              halfFilledIconData: Icons.star_half,
                  defaultIconData: Icons.star_border,

                  starCount: 5,
                  allowHalfRating: false,
                  spacing: 2.0,
                  onRated: (value) {

                    rating = value;

                  },
                )),
              ],
            ),
          ],
        ),
      ),
    );
  }

  Widget writeContent(
      IconData icon,
      String text,
      int color,
      String label
      ) {
    return Container(
        child: Row(children: <Widget>[
          Column(
              mainAxisAlignment: MainAxisAlignment.center,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Icon(icon),
                Text(
                  label,
                  style: TextStyle(
                    color: Color(0xFF000000),
                    fontFamily: defaultFontFamily,
                    fontSize: defaultFontSize,
                  ),
                )
              ]),

          Expanded(
              child: Text(text,
                  maxLines: 2,
                  overflow: TextOverflow.ellipsis,
                  style: TextStyle(
                    color: Color(color),
                    fontFamily: defaultFontFamily,
                    fontSize: defaultFontSize,
                  ))),
        ]));
  }

//  buildPostHeader({String title}) {
//    if (ownerId == null) {
//      return Text(Utils.noAcount);
//    }
//
//    return ListTile(
//      title: GestureDetector(
//        child: AutoSizeText(title, style: boldStyle),
//      ),
//
////              trailing:  new DropdownButton<String>(
////                icon: const Icon(Icons.more_vert),
////                underline: SizedBox(),
////                items: <String>[openprofile,block,report].map((String value) {
////                  return new DropdownMenuItem<String>(
////                    value: value,
////                    child: new Text(value),
////                  );
////                }).toList(),
////                onChanged: (value) {
////
////                },
////              ),
//    );
//  }

  GestureDetector buildLikeableImage({String image,String postId}) {
    return GestureDetector(
      onTap:null,
      child: Stack(
        alignment: Alignment.center,
        children: <Widget>[TopPromoSlider(image: image,postId:postId,poster: poster,)],
      ),
    );
  }
}　fill  full buildLikeableImage with title and SmoothStarRating on card