import ForgejoKit
import SwiftUI

struct MilestoneDisplaySection: View {
    let milestone: IssueMilestone

    var body: some View {
        Section("Milestone") {
            HStack(spacing: 8) {
                Image(systemName: "flag")
                    .foregroundStyle(.secondary)
                VStack(alignment: .leading, spacing: 2) {
                    Text(milestone.title)
                        .font(.subheadline)
                    if let due = milestone.dueOn {
                        Text("Due \(due, style: .date)")
                            .font(.caption)
                            .foregroundStyle(.secondary)
                    }
                }
            }
        }
    }
}

struct AssigneesDisplaySection: View {
    let assignees: [User]

    var body: some View {
        Section("Assignees") {
            ForEach(assignees) { user in
                HStack(spacing: 8) {
                    Image(systemName: "person")
                        .foregroundStyle(.secondary)
                    Text(user.fullName ?? user.login)
                        .font(.subheadline)
                    if user.fullName != nil {
                        Text("@\(user.login)")
                            .font(.caption)
                            .foregroundStyle(.secondary)
                    }
                }
            }
        }
    }
}

#if DEBUG
    #Preview("Milestone") {
        List {
            MilestoneDisplaySection(milestone: .preview)
        }
    }

    #Preview("Assignees") {
        List {
            AssigneesDisplaySection(assignees: [.preview, .previewBot])
        }
    }
#endif
