import SwiftUI

struct LocalizedTagDetailView: View {
    
    @ObservedObject
    var tag: LocalizedTag
    
    @EnvironmentObject
    private var content: Content
    
    @State
    private var showImagePicker = false
    
    var body: some View {
        VStack(alignment: .leading) {
            StringPropertyView(
                title: "Name",
                text: $tag.name,
                footer: "The displayed name of the tag")
            
            IdPropertyView(
                id: $tag.urlComponent,
                title: "Page URL String",
                footer: "The url component to use in the url for this tag",
                validation: tag.isValid,
                update: { tag.urlComponent = $0 })

            if let url = tag.originalUrl {
                GenericPropertyView(title: "Original URL") {
                    Text(url)
                }
            }

            OptionalStringPropertyView(
                title: "Preview Title",
                text: $tag.linkPreviewTitle,
                prompt: tag.name,
                footer: "The title to use for the tag in previews and on tag pages")

            OptionalImagePropertyView(
                title: "Preview Image",
                selectedImage: $tag.linkPreviewImage,
                footer: "The image to show for previews of this page")
            
            OptionalTextFieldPropertyView(
                title: "Preview Description",
                text: $tag.linkPreviewDescription,
                footer: "The description to show in previews of the page")
        }
    }
}

#Preview {
    LocalizedTagDetailView(tag: Tag.mock.english)
}
