import SwiftUI
import HighlightedTextEditor
import SFSafeSymbols

struct PostContentView: View {

    @ObservedObject
    var post: Post

    @Environment(\.language)
    private var language

    init(post: Post) {
        self.post = post
    }

    var body: some View {
        let localized = post.localized(in: language)
        let other = post.localized(in: language.next)
        VStack(alignment: .leading) {
            PostImagesView(
                post: localized,
                other: other)
            PostTitleView(post: localized)
            if let page = post.linkedPage {
                LinkedPageTagView(page: page)
            } else {
                TagDisplayView(tags: $post.tags)
            }
            PostLabelsView(
                post: post,
                localized: localized,
                other: other)
            PostTextView(post: localized)
        }
        .padding()
    }
}

extension PostContentView: MainContentView {

    init(item: Post) {
        self.post = item
    }

    static let itemDescription = "a post"
}

#Preview(traits: .fixedLayout(width: 450, height: 600)) {
    List {
        PostContentView(post: .Mock.hike2)
            .listRowSeparator(.hidden)
            .environment(\.language, ContentLanguage.german)
        PostContentView(post: .Mock.hike)
            .listRowSeparator(.hidden)
    }
    .environmentObject(Content.mock)
}
