import 'package:flutter/material.dart';
import 'package:shimmer/shimmer.dart';
import 'package:zhiying_comm/util/empty_util.dart';

class HomeBannerSkeleton extends StatelessWidget {
  final Map<String, dynamic> model;

  const HomeBannerSkeleton(this.model);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 60,
      margin: const EdgeInsets.symmetric(vertical: 12.5),
      width: double.infinity,
      color: Colors.white,
      child: _styleWidget(EmptyUtil.isEmpty(model) ? 1 : model.containsKey('mod_name') ? _getCount(model['mod_name']) : 1),
    );
  }

  int _getCount(String modName) {
    if (!EmptyUtil.isEmpty(modName)) {
      if (modName.endsWith('one')) {
        return 1;
      }
      if (modName.endsWith('two')) {
        return 2;
      }
      if (modName.endsWith('three')) {
        return 3;
      }
      if (modName.endsWith('four')) {
        return 4;
      }
      if (modName.endsWith('five')) {
        return 5;
      }
    }

    return 1;
  }
   
  
  Widget _styleWidget(int size) {
    List data = [];
    for(int i = 0 ; i < size; i++){
      data.add(i);
    }
    return Row(
      children: data.map((index){
        var margin;
        margin = const EdgeInsets.only(left: 10, right: 10);
        return Flexible(
          flex: 1,
          child: Shimmer.fromColors(
            baseColor: Colors.grey[300],
            highlightColor: Colors.grey[100],
            child: Container(
              height: double.infinity,
              width: double.infinity,
              margin: margin,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(7.5),
              ),
            ),
          ),
        );
      }).toList(),
    );
  }

}
