import 'package:flutter/foundation.dart' show kIsWeb;
import 'package:flutter/material.dart';
import 'package:kasy_kit/core/theme/extensions/theme_extension.dart';

/// Kasy Design System — shared component shadows.
class KasyShadows {
  KasyShadows._();

  /// Compact omnidirectional shadow used by surface components.
  ///
  /// On web the shadow is significantly reduced so components rely on borders
  /// for visual separation instead of heavy CSS box-shadows.
  static BoxShadow component(
    BuildContext context, {
    double blurRadius = 4.0,
    double spreadRadius = -1.9,
    Offset offset = const Offset(0, 0.95),
  }) {
    final double baseAlpha = context.isDark ? 0.31 : 0.145;
    final double alpha = kIsWeb ? baseAlpha * 0.42 : baseAlpha;
    return BoxShadow(
      color: const Color(0xFF000000).withValues(alpha: alpha),
      blurRadius: blurRadius,
      spreadRadius: spreadRadius,
      offset: offset,
    );
  }

  /// Resting border for [KasyTextField] and [KasyTextArea].
  ///
  /// Web: shadcn-style stroke (no shadow). Native: hairline + shadow together.
  static Color inputFieldRestingBorder(BuildContext context) {
    if (kIsWeb) {
      return context.colors.outline.withValues(alpha: 0.26);
    }
    return context.colors.outline.withValues(
      alpha: context.isDark ? 0.20 : 0.12,
    );
  }

  /// Standard shadow for input surfaces ([KasyTextField] and [KasyTextArea]).
  ///
  /// Slightly tighter and softer than [component] — native only (callers skip on web).
  static BoxShadow inputField(BuildContext context, {required bool enabled}) {
    final BoxShadow base =
        component(
          context,
          blurRadius: 2.4,
          spreadRadius: -1.1,
          offset: const Offset(0, 0.85),
        ).copyWith(
          color: const Color(
            0xFF000000,
          ).withValues(alpha: context.isDark ? 0.28 : 0.11),
        );

    if (enabled) return base;

    return base.copyWith(
      color: base.color.withValues(alpha: base.color.a * 0.72),
      blurRadius: base.blurRadius - 0.3,
    );
  }
}
