import SwiftUI

struct SearchOverlayView: View {
    @Binding var query: String
    let matchCount: Int
    let currentIndex: Int
    let onSearch: (String) -> Void
    let onNext: () -> Void
    let onPrev: () -> Void
    let onClose: () -> Void

    var body: some View {
        HStack(spacing: 8) {
            Image(systemName: "magnifyingglass")
                .foregroundStyle(.secondary)

            TextField("Search messages", text: $query)
                .textFieldStyle(.roundedBorder)
                .onChange(of: query) { _, newValue in
                    onSearch(newValue)
                }

            if matchCount > 0 {
                Text("\(currentIndex + 1)/\(matchCount)")
                    .font(.caption)
                    .foregroundStyle(.secondary)
                    .fixedSize()

                Button(action: onPrev) {
                    Image(systemName: "chevron.up")
                }
                Button(action: onNext) {
                    Image(systemName: "chevron.down")
                }
            }

            Button(action: onClose) {
                Image(systemName: "xmark.circle.fill")
                    .foregroundStyle(.secondary)
            }
        }
        .padding(.horizontal)
        .padding(.vertical, 6)
        .background(.ultraThinMaterial)
    }
}
