import SwiftUI

/// Aspect ratio options for the photo cropper
enum CropAspectRatio: Identifiable, CaseIterable, Equatable {
    case original         // Use image's original aspect ratio
    case square           // 1:1 for profile photos
    case threeToTwo       // 3:2
    case fiveToThree      // 5:3
    case fourToThree      // 4:3
    case fiveToFour       // 5:4
    case sevenToFive      // 7:5
    case sixteenToNine    // 16:9
    case banner           // Wide ratio for cover/banner photos (roughly 2.3:1)

    var id: String { displayName }

    static var allCases: [CropAspectRatio] {
        [.original, .square, .threeToTwo, .fiveToThree, .fourToThree, .fiveToFour, .sevenToFive, .sixteenToNine]
    }

    var displayName: String {
        switch self {
        case .original: return String.localized("Original")
        case .square: return String.localized("Square")
        case .threeToTwo: return "3:2"
        case .fiveToThree: return "5:3"
        case .fourToThree: return "4:3"
        case .fiveToFour: return "5:4"
        case .sevenToFive: return "7:5"
        case .sixteenToNine: return "16:9"
        case .banner: return String.localized("Banner")
        }
    }

    /// Returns the ratio (width / height). For .original, pass the image size.
    func ratio(for imageSize: CGSize? = nil) -> CGFloat {
        switch self {
        case .original:
            guard let size = imageSize, size.height > 0 else { return 1.0 }
            return size.width / size.height
        case .square:
            return 1.0
        case .threeToTwo:
            return 3.0 / 2.0
        case .fiveToThree:
            return 5.0 / 3.0
        case .fourToThree:
            return 4.0 / 3.0
        case .fiveToFour:
            return 5.0 / 4.0
        case .sevenToFive:
            return 7.0 / 5.0
        case .sixteenToNine:
            return 16.0 / 9.0
        case .banner:
            return 2.3
        }
    }

    /// Simple ratio for backwards compatibility (doesn't handle .original properly)
    var ratio: CGFloat {
        ratio(for: nil)
    }
}
