import 'package:didvan/config/design_config.dart';
import 'package:didvan/config/theme_data.dart';
import 'package:didvan/routes/routes.dart';
import 'package:didvan/views/home/new_statistic/new_statistics_state.dart';
import 'package:didvan/views/widgets/didvan/text.dart';

import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:provider/provider.dart';

class StatMenuItemType {
  final String label;
  final String asset;
  final int id;

  StatMenuItemType(
      {required this.label, required this.asset, required this.id});
}

class NewStatisticCategories extends StatefulWidget {
  const NewStatisticCategories({super.key});

  @override
  State<NewStatisticCategories> createState() => _NewStatisticCategoriesState();
}

class _NewStatisticCategoriesState extends State<NewStatisticCategories> {
  void _onTap(int id, String title, BuildContext context, BuildContext ctx) {
    if (id != 6) {
      Navigator.of(context)
          .pushNamed(Routes.statGeneral, arguments: {"id": id, "title": title});
    } else {
      Navigator.of(ctx).pushNamed(Routes.stock);
    }
  }

  @override
  Widget build(BuildContext context) {
    final state = context.watch<NewStatisticState>();
    return Wrap(
      alignment: WrapAlignment.center,
      children: state.statCat
          .map(
            (e) => GestureDetector(
              onTap: () => _onTap(e.id, e.label, context, context),
              child: SizedBox(
                width: (MediaQuery.of(context).size.width - 56) / 3,
                child: Column(
                  children: [
                    Container(
                      width: 56,
                      height: 56,
                      padding: const EdgeInsets.all(8),
                      decoration: BoxDecoration(
                        color: Theme.of(context).colorScheme.surface,
                        borderRadius: DesignConfig.lowBorderRadius,
                        boxShadow: DesignConfig.defaultShadow,
                      ),
                      child: SvgPicture.asset(e.asset),
                    ),
                    const SizedBox(height: 4),
                    DidvanText(
                      e.label,
                      color: Theme.of(context).colorScheme.title,
                      style: Theme.of(context).textTheme.labelSmall,
                      fontWeight: FontWeight.w600,
                    ),
                    const SizedBox(height: 12),
                  ],
                ),
              ),
            ),
          )
          .toList(),
    );
  }
}
