import ForgejoKit
import SwiftUI

struct IssuesOverviewView: View {
    let authService: AuthenticationService

    init(authService: AuthenticationService) {
        self.authService = authService
    }

    var body: some View {
        SearchableOverviewView(
            authService: authService,
            issueType: "issues",
            navigationTitle: "Issues",
            searchPrompt: "Search issues",
            emptyTitle: "No Issues",
            emptyOpenIcon: "checkmark.circle",
            emptyClosedIcon: "exclamationmark.circle",
            itemNoun: "issues",
            createButtonId: "issue-create-button",
            showReviewRequested: false,
            row: { issue in
                IssueRow(issue: issue)
            },
            detail: { repository, number, auth in
                IssueDetailView(
                    repository: repository,
                    issueNumber: number,
                    authService: auth,
                )
            },
            createView: { repo, auth, embedded, onCreated in
                IssueCreateView(
                    repository: repo,
                    authService: auth,
                    embeddedInNavigation: embedded,
                    onCreated: onCreated,
                )
            },
        )
    }

    #if DEBUG
        init(preview _: Void, authService: AuthenticationService, issues _: [Issue]) {
            self.authService = authService
        }
    #endif
}

#if DEBUG
    #Preview {
        NavigationStack {
            IssuesOverviewView(
                preview: (),
                authService: .previewDefault,
                issues: [.previewWithRepo],
            )
        }
    }
#endif
