import SwiftUI

struct PostFeedSettingsView: View {

    @Binding
    var language: ContentLanguage

    @ObservedObject
    var postSettings: PostSettings

    private var transferImage: (language: ContentLanguage, image: FileResource)? {
        postSettings.localized(in: language.next).linkPreview.image.map {
            (language.next, $0)
        }
    }

    var body: some View {
        ScrollView {
            VStack(alignment: .leading) {
                IntegerPropertyView(
                    title: "Content Width",
                    value: $postSettings.contentWidth,
                    footer: "The maximum width of the content the post feed (in pixels)")

                IntegerPropertyView(
                    title: "Posts Per Page",
                    value: $postSettings.postsPerPage,
                    footer: "The maximum number of posts displayed on a single page")

                FilePropertyView(
                    title: "Default CSS File",
                    footer: "The CSS file containing the styling of all post pages",
                    selectedFile: $postSettings.defaultCssFile)

                FilePropertyView(
                    title: "Swiper CSS File",
                    footer: "The CSS file containing the styling of image galleries in post feeds",
                    selectedFile: $postSettings.swiperCssFile)

                FilePropertyView(
                    title: "Swiper JavaScript File",
                    footer: "The JavaScript file to load the image gallery code in post feeds",
                    selectedFile: $postSettings.swiperJsFile)

                LocalizedPostFeedSettingsView(
                    settings: postSettings.localized(in: language),
                    transferImage: transferImage)
                .id(language)
            }
            .padding()
        }
    }
}


#Preview {
    PostFeedSettingsView(
        language: .constant(.english),
        postSettings: .default)
    .padding()
}
