import 'dart:math';

import 'package:chat/chat/gift_widget.dart';
import 'package:chat/models/gift_item_model.dart';
import 'package:chat/models/gift_select_provider.dart';
import 'package:chat/utils/screen.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';

class GiftPage extends StatelessWidget {
  final List<GiftItemModel> giftList;
  final int pageIndex;

  GiftPage(this.giftList, this.pageIndex);

  @override
  Widget build(BuildContext context) {
    int length = giftList.length - pageIndex * 8;
    length = min(length, 8);

    int curSelectIndex =
        Provider.of<GiftSelectProvider>(context).curSelectIndex;

        print('page $pageIndex curSelectIndex $curSelectIndex');
    return Container(
        width: Screen.width,
        height: 150,
        child: Wrap(
            direction: Axis.horizontal,
            runSpacing: 5,
            spacing: 10,
            children: List<Widget>.generate(length, (int i) {
              int index = pageIndex * 8 + i;
              return GestureDetector(
                  child: GiftItem(
                      itemModel: giftList[index],
                      isSelected: index == curSelectIndex),
                  onTap: () {
                    if (index != curSelectIndex) {
                      Provider.of<GiftSelectProvider>(context)
                          .changeSelectIndex(index);
                    }
                  });
            })));
  }
}
