import SwiftUI
import SFSafeSymbols

struct LocalizedPageDetailView: View {

    let isExternalPage: Bool

    @ObservedObject
    var page: LocalizedPage

    var body: some View {
        VStack(alignment: .leading) {
            IdPropertyView(
                id: $page.urlString,
                title: "Page URL String",
                footer: "The url component to use for the link to the page",
                validation: page.isValid,
                update: { page.urlString = $0 })
            .disabled(isExternalPage)

            BoolPropertyView(
                title: "Hide automatic title",
                value: $page.hideTitle,
                footer: "Prevent the date and title from being printed on the page")
            .disabled(isExternalPage)

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

            OptionalStringPropertyView(
                title: "Preview Title",
                text: $page.linkPreviewTitle,
                prompt: page.title,
                footer: "The title to use for the page when linking to it")

            OptionalImagePropertyView(
                title: "Preview Image",
                selectedImage: $page.linkPreviewImage,
                footer: "The image to show for previews of this page")

            OptionalTextFieldPropertyView(
                title: "Preview Description",
                text: $page.linkPreviewDescription,
                footer: "The description to show in previews of the page")
        }
    }
}

#Preview {
    LocalizedPageDetailView(isExternalPage: false, page: .english)
        .environmentObject(Content.mock)
}
