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/studio.dart';
import 'package:didvan/routes/routes.dart';
import 'package:didvan/views/widgets/bookmark_button.dart';
import 'package:didvan/views/widgets/didvan/icon_button.dart';
import 'package:didvan/views/widgets/duration_widget.dart';
import 'package:didvan/views/widgets/didvan/card.dart';
import 'package:didvan/views/widgets/didvan/divider.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';
import 'package:persian_number_utility/persian_number_utility.dart';

class VideoOverview extends StatelessWidget {
  final OverviewData video;
  final void Function(int id, bool value, bool shouldUpdate) onMarkChanged;
  final bool hasUnmarkConfirmation;
  final StudioRequestArgs studioRequestArgs;
  const VideoOverview({
    Key? key,
    required this.video,
    required this.onMarkChanged,
    required this.studioRequestArgs,
    this.hasUnmarkConfirmation = false,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return DidvanCard(
      onTap: () => Navigator.of(context).pushNamed(
        Routes.studioDetails,
        arguments: {
          'onMarkChanged': (id, value) => onMarkChanged(id, value, true),
          'id': video.id,
          'args': studioRequestArgs,
          'hasUnmarkConfirmation': hasUnmarkConfirmation,
          'isVideo': true,
        },
      ),
      child: Row(
        children: [
          Stack(
            alignment: Alignment.center,
            children: [
              SkeletonImage(
                imageUrl: video.image,
                height: 108,
                width: 108,
              ),
              Container(
                height: 28,
                width: 28,
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: Theme.of(context)
                      .colorScheme
                      .secondary
                      .withValues(alpha: 0.7),
                ),
                child: Icon(
                  DidvanIcons.play_solid,
                  color: Theme.of(context).colorScheme.white,
                ),
              ),
            ],
          ),
          const SizedBox(width: 8),
          Expanded(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                DidvanText(
                  video.title,
                  style: Theme.of(context).textTheme.bodyLarge,
                  maxLines: 1,
                  overflow: TextOverflow.ellipsis,
                ),
                const SizedBox(height: 4),
                Row(
                  crossAxisAlignment: CrossAxisAlignment.start,
                  children: [
                    const Icon(
                      DidvanIcons.calendar_day_regular,
                      size: 16,
                    ),
                    const SizedBox(width: 4),
                    DidvanText(
                      DateTime.parse(video.createdAt).toPersianDateStr(),
                      style: Theme.of(context).textTheme.labelSmall,
                      color: Theme.of(context).colorScheme.caption,
                    ),
                  ],
                ),
                const DidvanDivider(verticalPadding: 8),
                Row(
                  children: [
                    DurationWidget(duration: video.duration!),
                    const Spacer(),
                    DidvanIconButton(
                      gestureSize: 32,
                      onPressed: () => Navigator.of(context).pushNamed(
                        Routes.mentions,
                        arguments: {
                          'id': video.id,
                          'type': 'studio',
                          'title': video.title,
                        },
                      ),
                      icon: DidvanIcons.mention_icon,
                    ),
                    const SizedBox(width: 8.0),
                    BookmarkButton(
                      itemId: video.id,
                      type: 'video',
                      gestureSize: 32,
                      value: video.marked,
                      onMarkChanged: (value) =>
                          onMarkChanged(video.id, value, false),
                      askForConfirmation: hasUnmarkConfirmation,
                    ),
                  ],
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  static Widget get placeHolder => DidvanCard(
        child: Row(
          children: [
            const ShimmerPlaceholder(height: 108, width: 108),
            const SizedBox(width: 8),
            Expanded(
              child: Column(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  const ShimmerPlaceholder(height: 20),
                  const SizedBox(height: 8),
                  const ShimmerPlaceholder(width: 100, height: 16),
                  const DidvanDivider(verticalPadding: 10),
                  Row(
                    children: [
                      ShimmerPlaceholder(
                        height: 36,
                        width: 92,
                        borderRadius: BorderRadius.circular(5),
                      ),
                      const Spacer(),
                      const ShimmerPlaceholder(width: 24, height: 24),
                      const SizedBox(width: 16),
                      const ShimmerPlaceholder(width: 24, height: 24),
                    ],
                  ),
                ],
              ),
            ),
          ],
        ),
      );
}
