import SwiftUI

struct OptionalImagePropertyView: View {

    let title: LocalizedStringKey

    @Binding
    var selectedImage: FileResource?

    let footer: LocalizedStringKey

    @State
    private var showSelectionSheet = false

    var body: some View {
        GenericPropertyView(title: title, footer: footer) {
            if let image = selectedImage {
                image.imageToDisplay
                    .resizable()
                    .aspectRatio(contentMode: .fit)
                    .frame(maxHeight: 300)
                    .cornerRadius(8)
            }
            HStack {
                Text(selectedImage?.id ?? "No file selected")
                Spacer()
                Button("Select") {
                    showSelectionSheet = true
                }
            }
        }
        .sheet(isPresented: $showSelectionSheet) {
            FileSelectionView(selectedFile: $selectedImage, allowedType: .image)
        }
    }
}
