import SwiftUI
import SFSafeSymbols

struct GenerationResultsIssueView: View {

    @State
    private var showList = false

    let text: String

    let status: IssueStatus

    let items: () -> [String]

    var body: some View {
        HStack {
            Button(action: showListIfNonEmpty) {
                Image(systemSymbol: status.symbol)
                    .foregroundStyle(status.color)
            }.buttonStyle(.plain)
            Text(text)
        }
        .sheet(isPresented: $showList) {
            VStack {
                List(items(), id: \.self) { item in
                    Text(item)
                }
                .frame(minHeight: 400)
                Button("Close") { showList = false }
            }
        }
    }

    private func showListIfNonEmpty() {
        guard !items().isEmpty else {
            return
        }
        showList = true
    }
}
