// ignore_for_file: deprecated_member_use_from_same_package

import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hoshan/ui/screens/tools/bloc/tools_bloc.dart';
import 'package:hoshan/ui/theme/responsive.dart';
import 'package:hoshan/ui/widgets/components/bot/tool_card.dart';
import 'package:hoshan/ui/widgets/components/bot/tool_card_placeholder.dart';
import 'package:hoshan/ui/widgets/sections/header/reversible_appbar.dart';

class ToolsPage extends StatelessWidget {
  const ToolsPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: ReversibleAppbar(
        context,
        titleText: 'ابزار ها',
      ),
      body: Responsive(context).maxWidthInDesktop(
        child: (contxet, mw) => Directionality(
          textDirection: TextDirection.rtl,
          child: BlocBuilder<ToolsBloc, ToolsState>(
            builder: (context, state) {
              if (state is ToolsFail || state is ToolsEmpty) {
                return const SizedBox.shrink();
              }
              if (state is ToolsSuccess) {
                final privateBots = state.categories;
                return ListView.builder(
                  itemCount: privateBots.length,
                  shrinkWrap: true,
                  padding: const EdgeInsets.symmetric(horizontal: 8),
                  physics: const BouncingScrollPhysics(),
                  itemBuilder: (context, index) {
                    final cat = privateBots[index];
                    return ToolCard(cat: cat);
                  },
                );
              }

              return ListView.builder(
                itemCount: 10,
                shrinkWrap: true,
                padding: const EdgeInsets.symmetric(horizontal: 8),
                physics: const NeverScrollableScrollPhysics(),
                itemBuilder: (context, index) {
                  return const ToolCardPlaceholder();
                },
              );
            },
          ),
        ),
      ),
    );
  }
}
