import SwiftUI

struct FilePropertyView: View {

    let title: LocalizedStringKey

    let footer: LocalizedStringKey

    @Binding
    var selectedFile: FileResource?

    let allowedType: FileTypeCategory?

    init(title: LocalizedStringKey, footer: LocalizedStringKey, selectedFile: Binding<FileResource?>, allowedType: FileTypeCategory? = nil) {
        self.title = title
        self.footer = footer
        self._selectedFile = selectedFile
        self.allowedType = allowedType
    }

    @State
    private var showFileSelectionSheet = false

    var body: some View {
        GenericPropertyView(title: title, footer: footer) {
            HStack {
                Text(selectedFile?.identifier ?? "No file selected")
                Spacer()
                Button("Select") {
                    showFileSelectionSheet = true
                }
            }
        }
        .sheet(isPresented: $showFileSelectionSheet) {
            FileSelectionView(selectedFile: $selectedFile, allowedType: allowedType)
        }
    }
}
