import SwiftUI
import SFSafeSymbols

struct InsertableLabels: View, InsertableCommandView {

    static let title = "Labels"

    static let sheetTitle = "Insert labels"

    static let icon: SFSymbol = .squaresBelowRectangle

    final class Model: InsertableCommandModel {

        @Published
        var labels: [ContentLabel] = []

        var isReady: Bool {
            !labels.isEmpty
        }

        init() {

        }

        var command: String? {
            guard !labels.isEmpty else {
                return nil
            }
            var result = "```labels"
            for label in labels {
                result += "\n\(label.icon.rawValue): \(label.value)"
            }
            result += "\n```"
            return result
        }
    }

    @ObservedObject
    private var model: Model

    init(model: Model) {
        self.model = model
    }

    var body: some View {
        LabelCreationView(labels: $model.labels)
    }

}
