import SwiftUI

struct TagDisplayView: View {

    @Environment(\.language)
    private var language

    @EnvironmentObject
    private var content: Content

    @Binding
    var tags: [Tag]

    @State
    private var showTagPicker = false

    var body: some View {
        FlowHStack {
            ForEach(tags, id: \.identifier) { tag in
                TagView(text: tag.localized(in: language).name)
                    .foregroundStyle(.white)
            }
            Button(action: { showTagPicker = true }) {
                Image(systemSymbol: .squareAndPencilCircleFill)
                    .resizable()
                    .aspectRatio(1, contentMode: .fit)
                    .frame(height: 22)
                    .foregroundColor(Color.gray)
                    .background(Circle()
                        .fill(Color.white)
                        .padding(1))
            }
            .buttonStyle(.plain)
        }
        .sheet(isPresented: $showTagPicker) {
            TagSelectionView(
                presented: $showTagPicker,
                selected: $tags,
                tags: $content.tags)
        }
    }
}
