import SwiftUI
import SFSafeSymbols

struct LocalizedPageDetailView: View {

    let isExternalPage: Bool

    @ObservedObject
    var page: LocalizedPage

    let transferImage: (language: ContentLanguage, image: FileResource)?

    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)
                }
            }

            LinkPreviewDetailView(
                linkPreview: page.linkPreview,
                fallbackTitle: page.title,
                transferImage: transferImage)
        }
    }
}

#Preview(traits: .fixedLayout(width: 400, height: 600)) {
    LocalizedPageDetailView(
        isExternalPage: false,
        page: Page.Mock.empty.english,
        transferImage: nil
    )
    .padding()
    .environmentObject(Content.mock)
}
