import 'dart:io' show Platform;

import 'package:flutter/widgets.dart';

import '../constants/breakpoints.dart';
import 'media_poster_card.dart';

abstract final class MediaRowMetrics {
  static const landscapeCompactWidth = 185.0;
  static const landscapeExpandedWidth = 232.0;
  static const posterCompactWidth = 130.0;
  static const posterExpandedWidth = 158.0;

  static const landscapeCompactHeight = 171.0;
  static const landscapeExpandedHeight = 214.0;
  static const posterCompactHeight = 250.0;
  static const posterExpandedHeight = 304.0;

  static const _landscapeAndroidWidth = 148.0;
  static const _posterAndroidWidth = 110.0;
  static const _landscapeAndroidHeight = 137.0;
  static const _posterAndroidHeight = 211.0;

  static final bool _isAndroid = Platform.isAndroid;

  static bool isCompact(BuildContext context) =>
      Breakpoints.isCompact(MediaQuery.sizeOf(context).width);

  static double cardWidth(MediaCardVariant variant, {required bool compact}) {
    if (compact && _isAndroid) {
      return switch (variant) {
        MediaCardVariant.landscape => _landscapeAndroidWidth,
        MediaCardVariant.poster => _posterAndroidWidth,
      };
    }
    return switch (variant) {
      MediaCardVariant.landscape =>
        compact ? landscapeCompactWidth : landscapeExpandedWidth,
      MediaCardVariant.poster =>
        compact ? posterCompactWidth : posterExpandedWidth,
    };
  }

  static double rowHeight(MediaCardVariant variant, {required bool compact}) {
    if (compact && _isAndroid) {
      return switch (variant) {
        MediaCardVariant.landscape => _landscapeAndroidHeight,
        MediaCardVariant.poster => _posterAndroidHeight,
      };
    }
    return switch (variant) {
      MediaCardVariant.landscape =>
        compact ? landscapeCompactHeight : landscapeExpandedHeight,
      MediaCardVariant.poster =>
        compact ? posterCompactHeight : posterExpandedHeight,
    };
  }
}
