import Foundation
import CoreGraphics

struct WidgetQuickAction: Identifiable, Hashable {
    enum Destination: String, Hashable {
        case joinMeetings
        case schedule
        case calendar
        case settings
        case signIn
        case openMeetWeb
        case refreshMeetings
    }

    let id: String
    let title: String
    let systemImage: String
    let destination: Destination
}

struct WidgetVariant: Identifiable, Hashable {
    let id: String
    let title: String
    let subtitle: String
    let size: WidgetSize
    let quickActions: [WidgetQuickAction]
}

enum WidgetTemplates {
    static let meetVariants: [WidgetVariant] = [
        WidgetVariant(
            id: "meet_small",
            title: "Google Meet",
            subtitle: "Open and join quickly",
            size: .small,
            quickActions: [
                WidgetQuickAction(id: "open", title: "Open Meet", systemImage: "video.fill", destination: .openMeetWeb),
                WidgetQuickAction(id: "join", title: "Join Meetings", systemImage: "arrow.up.forward.app.fill", destination: .joinMeetings)
            ]
        ),
        WidgetVariant(
            id: "meet_medium",
            title: "Google Meet",
            subtitle: "Upcoming meetings",
            size: .medium,
            quickActions: [
                WidgetQuickAction(id: "schedule", title: "Schedule", systemImage: "clock.badge.checkmark", destination: .schedule),
                WidgetQuickAction(id: "calendar", title: "Calendar", systemImage: "calendar", destination: .calendar),
                WidgetQuickAction(id: "settings", title: "Settings", systemImage: "gearshape.fill", destination: .settings),
                WidgetQuickAction(id: "refresh", title: "Refresh", systemImage: "arrow.clockwise", destination: .refreshMeetings)
            ]
        )
    ]

    static func variant(for variantID: String) -> WidgetVariant {
        meetVariants.first(where: { $0.id == variantID }) ?? meetVariants[0]
    }
}

extension WidgetVariant {
    var previewCardSize: CGSize {
        switch size {
        case .small:
            return CGSize(width: 196, height: 196)
        case .medium:
            // Match the medium desktop widget’s tallest expected layout (e.g. 2 meetings + actions)
            // so the preview doesn’t clip inside the “Add Widget to Desktop” screen.
            return CGSize(width: 340, height: 288)
        }
    }
}
