import 'package:didvan/config/theme_data.dart';
import 'package:didvan/constants/app_icons.dart';
import 'package:didvan/models/overview_data.dart';
import 'package:didvan/models/requests/radar.dart';
import 'package:didvan/routes/routes.dart';
import 'package:didvan/utils/date_time.dart';
import 'package:didvan/views/home/widgets/bookmark_button.dart';
import 'package:didvan/views/widgets/didvan/card.dart';
import 'package:didvan/views/widgets/didvan/divider.dart';
import 'package:didvan/views/widgets/didvan/icon_button.dart';
import 'package:didvan/views/widgets/didvan/text.dart';
import 'package:didvan/views/widgets/shimmer_placeholder.dart';
import 'package:didvan/views/widgets/skeleton_image.dart';
import 'package:flutter/material.dart';

class RadarOverview extends StatelessWidget {
  final OverviewData radar;
  final void Function(int id, int count) onCommentsChanged;
  final void Function(int id, bool value) onMarkChanged;
  final bool hasUnmarkConfirmation;
  final RadarRequestArgs? radarRequestArgs;
  const RadarOverview({
    Key? key,
    required this.radar,
    required this.onCommentsChanged,
    required this.onMarkChanged,
    this.radarRequestArgs,
    this.hasUnmarkConfirmation = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DidvanCard(
      onTap: () => Navigator.of(context).pushNamed(
        Routes.radarDetails,
        arguments: {
          'onMarkChanged': onMarkChanged,
          'onCommentsChanged': onCommentsChanged,
          'id': radar.id,
          'args': radarRequestArgs,
          'hasUnmarkConfirmation': hasUnmarkConfirmation,
        },
      ),
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          DidvanText(
            radar.title,
            fontWeight: FontWeight.w600,
          ),
          const SizedBox(height: 8),
          Stack(
            children: [
              SkeletonImage(
                imageUrl: radar.image,
                aspectRatio: 16 / 9,
              ),
              if (radar.forManagers)
                Positioned(
                  top: 0,
                  right: 0,
                  child: Container(
                    padding: const EdgeInsets.all(4),
                    decoration: BoxDecoration(
                      color: Theme.of(context).colorScheme.secondary,
                      borderRadius: const BorderRadius.only(
                        bottomLeft: Radius.circular(8),
                        topRight: Radius.circular(8),
                      ),
                    ),
                    child: DidvanText(
                      'برای مدیران',
                      style: Theme.of(context).textTheme.overline,
                      color: Theme.of(context).colorScheme.white,
                    ),
                  ),
                ),
            ],
          ),
          const SizedBox(height: 8),
          Row(
            children: [
              DidvanText(
                radar.categories!.first.label,
                style: Theme.of(context).textTheme.overline,
                color: Theme.of(context).colorScheme.caption,
              ),
              const Spacer(),
              DidvanText(
                '${DateTimeUtils.momentGenerator(radar.createdAt)} | خواندن در ${radar.timeToRead} دقیقه',
                style: Theme.of(context).textTheme.overline,
                color: Theme.of(context).colorScheme.caption,
              ),
            ],
          ),
          const SizedBox(height: 8),
          DidvanText(
            radar.description,
            maxLines: 3,
            overflow: TextOverflow.ellipsis,
          ),
          const DidvanDivider(),
          Row(
            children: [
              BookmarkButton(
                value: radar.marked,
                onMarkChanged: (value) => onMarkChanged(radar.id, value),
                askForConfirmation: hasUnmarkConfirmation,
              ),
              const Spacer(),
              if (radar.comments != 0) DidvanText(radar.comments.toString()),
              const SizedBox(width: 4),
              DidvanIconButton(
                icon: DidvanIcons.chats_regular,
                gestureSize: 24,
                onPressed: () => Navigator.of(context).pushNamed(
                  Routes.comments,
                  arguments: {
                    'isRadar': true,
                    'title': radar.title,
                    'id': radar.id,
                    'onCommentsChanged': (count) =>
                        onCommentsChanged(radar.id, count)
                  },
                ),
              ),
              const SizedBox(width: 16),
              // const DidvanText('10'),
              // const SizedBox(width: 4),
              // const Icon(DidvanIcons.evaluation_regular),
            ],
          ),
        ],
      ),
    );
  }

  static Widget get placeholder => DidvanCard(
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            const ShimmerPlaceholder(height: 16),
            const SizedBox(height: 8),
            const ShimmerPlaceholder(
              width: 200,
              height: 16,
            ),
            const SizedBox(height: 16),
            const AspectRatio(aspectRatio: 16 / 9, child: ShimmerPlaceholder()),
            const SizedBox(height: 8),
            Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: const [
                ShimmerPlaceholder(
                  height: 12,
                  width: 70,
                ),
                ShimmerPlaceholder(
                  height: 12,
                  width: 70,
                ),
              ],
            ),
            const SizedBox(height: 8),
            const ShimmerPlaceholder(
              height: 16,
            ),
            const SizedBox(height: 8),
            const ShimmerPlaceholder(
              height: 16,
            ),
            const SizedBox(height: 8),
            const ShimmerPlaceholder(
              height: 16,
            ),
            const DidvanDivider(),
            Row(
              children: const [
                ShimmerPlaceholder(
                  height: 32,
                  width: 32,
                ),
                Spacer(),
                ShimmerPlaceholder(
                  height: 32,
                  width: 32,
                ),
                SizedBox(width: 16),
                ShimmerPlaceholder(
                  height: 32,
                  width: 32,
                ),
              ],
            ),
          ],
        ),
      );
}
