import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:hoshan/data/model/ai/bots_model.dart';
import 'package:hoshan/ui/theme/colors.dart';
import 'package:hoshan/ui/theme/cubit/theme_mode_cubit.dart';
import 'package:hoshan/ui/theme/responsive.dart';
import 'package:hoshan/ui/theme/text.dart';
import 'package:hoshan/ui/widgets/components/image/network_image.dart';

class BotRowCard extends StatelessWidget {
  final Bots bot;
  final int index;
  const BotRowCard({super.key, required this.bot, this.index = 0});

  @override
  Widget build(BuildContext context) {
    final isDark = context.read<ThemeModeCubit>().state == ThemeMode.dark;
    return Container(
      width: Responsive(context).isMobile()
          ? MediaQuery.sizeOf(context).width * 0.7
          : 300,
      margin: const EdgeInsets.symmetric(horizontal: 8, vertical: 8),
      decoration: BoxDecoration(
          boxShadow: const [
            BoxShadow(
              color: Color(0x664D4D4D),
              blurRadius: 6,
              offset: Offset(0, 1),
              spreadRadius: 0,
            )
          ],
          color: Theme.of(context).colorScheme.surface,
          borderRadius: BorderRadius.circular(8)),
      child: Stack(
        children: [
          Positioned(
              top: 0,
              right: 0,
              bottom: 0,
              child: Container(
                width: 40,
                decoration: BoxDecoration(
                    borderRadius: const BorderRadius.only(
                        topRight: Radius.circular(8),
                        bottomRight: Radius.circular(8)),
                    color: isDark
                        ? index % 2 == 0
                            ? Theme.of(context).colorScheme.primary
                            : Theme.of(context).colorScheme.secondary
                        : index % 2 == 0
                            ? AppColors.primaryColor[200]
                            : AppColors.secondryColor[200]),
              )),
          Padding(
            padding: const EdgeInsets.all(8.0),
            child: Row(
              children: [
                const SizedBox(
                  width: 8,
                ),
                Center(
                  child: Container(
                    padding: const EdgeInsets.all(2),
                    decoration: BoxDecoration(
                        shape: BoxShape.circle,
                        color: index % 2 == 0
                            ? AppColors.primaryColor.defaultShade
                            : AppColors.secondryColor.defaultShade),
                    child: ImageNetwork(
                      width: 48,
                      height: 48,
                      radius: 360,
                      url: bot.image,
                      color: bot.image != null && bot.image!.contains('/llm')
                          ? Theme.of(context).colorScheme.onSurface
                          : null,
                    ),
                  ),
                ),
                Expanded(
                    child: Padding(
                  padding:
                      const EdgeInsets.symmetric(horizontal: 8.0, vertical: 4),
                  child: Column(
                    mainAxisAlignment: MainAxisAlignment.center,
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        bot.name ?? '',
                        maxLines: 1,
                        overflow: TextOverflow.ellipsis,
                        style: AppTextStyles.body5.copyWith(
                            fontWeight: FontWeight.bold,
                            color: Theme.of(context).colorScheme.onSurface),
                      ),
                      const SizedBox(
                        height: 4,
                      ),
                      Row(
                        children: [
                          Container(
                            decoration: BoxDecoration(
                              borderRadius: BorderRadius.circular(8),
                              color: index % 2 == 0
                                  ? AppColors.primaryColor.defaultShade
                                  : AppColors.secondryColor.defaultShade,
                            ),
                            padding: const EdgeInsets.symmetric(
                                horizontal: 4, vertical: 4),
                            child: Text(
                              'رایگان',
                              style: AppTextStyles.body6.copyWith(
                                  color: Colors.white,
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                          Container(
                            height: 12,
                            width: 1,
                            color: AppColors.gray.defaultShade,
                            margin: const EdgeInsets.symmetric(horizontal: 4),
                          ),
                          Text(
                            bot.limit != null
                                ? bot.limit == -1
                                    ? 'بدون محدودیت'
                                    : '${bot.limit} پیام در هر ساعت'
                                : '',
                            style: AppTextStyles.body5.copyWith(
                                color: bot.limit == -1
                                    ? Theme.of(context).colorScheme.secondary
                                    : Theme.of(context).colorScheme.onSurface),
                          ),
                        ],
                      )
                    ],
                  ),
                )),
              ],
            ),
          ),
        ],
      ),
    );
  }
}
