import SwiftUI
import SFSafeSymbols

struct TextWithPopup: View {

    let symbol: SFSymbol

    let text: LocalizedStringKey

    let items: [String]

    @State
    private var isHovering = false

    var body: some View {
        HStack {
            Image(systemSymbol: symbol)
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: 16, height: 16)
            Text(text)
        }
        .contentShape(Rectangle())
        .onTapGesture {
            if items.count > 0 {
                isHovering.toggle()
            }
        }
        .sheet(isPresented: $isHovering) {
            ListPopup(items: items)
                .onTapGesture {
                    isHovering.toggle()
                }
        }
    }
}
