import SwiftUI
import Lottie

// MARK: - ChatEmptyStateView

struct ChatEmptyStateView: View {
    let searchText: String

    var body: some View {
        VStack(spacing: 0) {
            if searchText.isEmpty {
                noConversationsContent
            } else {
                noSearchResultsContent
            }
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity)
        .offset(y: -40)
    }
}

// MARK: - Content Variants

private extension ChatEmptyStateView {
    var noConversationsContent: some View {
        Group {
            LottieView(animationName: "letter", loopMode: .playOnce, animationSpeed: 1.0)
                .frame(width: 150, height: 150)

            Spacer().frame(height: 24)

            Text("No conversations yet")
                .font(.system(size: 18, weight: .semibold))
                .foregroundStyle(RosettaColors.Adaptive.textSecondary)
                .multilineTextAlignment(.center)

            Spacer().frame(height: 8)

            Text("Start a new conversation to get started")
                .font(.system(size: 15))
                .foregroundStyle(RosettaColors.Adaptive.textSecondary)
                .multilineTextAlignment(.center)
                .padding(.horizontal, 40)
        }
    }

    var noSearchResultsContent: some View {
        Group {
            Image(systemName: "magnifyingglass")
                .font(.system(size: 52))
                .foregroundStyle(RosettaColors.Adaptive.textSecondary.opacity(0.5))

            Spacer().frame(height: 16)

            Text("No results for \"\(searchText)\"")
                .font(.system(size: 18, weight: .semibold))
                .foregroundStyle(RosettaColors.Adaptive.textSecondary)
                .multilineTextAlignment(.center)
        }
    }
}

// MARK: - Preview

#Preview {
    ChatEmptyStateView(searchText: "")
}
