import WidgetKit
import SwiftUI
import ActivityKit

// 1. Define the data that DOES NOT change (static)
struct BeemActivityAttributes: ActivityAttributes {
    public struct ContentState: Codable, Hashable {
        // 2. Define the data that WILL be updated (dynamic)
        var eta: String
        var progress: Double
    }

    // Data you send once when the activity starts
    var driverName: String
    var carModel: String
    var licensePlate: String
}

// 3. Create the UI of the Live Activity
struct BeemActivitiesWidgetLiveActivity: Widget {
    var body: some WidgetConfiguration {
        ActivityConfiguration(for: BeemActivityAttributes.self) { context in
            // MARK: Live Activity UI on the Lock Screen
            VStack(alignment: .leading, spacing: 8) {
                HStack {
                    Text("Arrivée dans \(context.state.eta)")
                        .font(.title2)
                        .fontWeight(.bold)
                        .foregroundColor(.white)
                    Spacer()
                    Text("Wanis") // Your App Name
                        .font(.title3)
                        .fontWeight(.bold)
                        .foregroundColor(Color(red: 0.2, green: 0.8, blue: 0.2)) // Green color
                }
                Text("\(context.attributes.licensePlate) · \(context.attributes.carModel)")
                    .font(.body)
                    .foregroundColor(.gray)

                ProgressView(value: context.state.progress)
                    .progressViewStyle(LinearProgressViewStyle(tint: Color(red: 0.2, green: 0.8, blue: 0.2)))
            }
            .padding(20)
            .background(Color.black.opacity(0.8))

        } dynamicIsland: { context in
            // MARK: Define Dynamic Island UI here (optional for now)
            DynamicIsland {
                DynamicIslandExpandedRegion(.leading) {
                    Text("Driver")
                }
                // ... other regions
            } compactLeading: {
                Image(systemName: "car.fill")
            } compactTrailing: {
                Text(context.state.eta)
            } minimal: {
                Text(context.state.eta)
            }
        }
    }
}