'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
 * CuratedIssuesList — spec 097, FR-37 / task-45.
 *
 * Renders the result of GetCuratedIssuesByLaneUseCase as a list of issue
 * cards: title, difficulty badge, acceptance-criteria preview, and a link
 * to the GitHub issue. Pure presentation — data comes via props.
 */
import { ExternalLink } from 'lucide-react';
import { Badge } from '../ui/badge.js';
import { Skeleton } from '../ui/skeleton.js';
import { ContributionDifficulty } from '../../../../../packages/core/src/domain/generated/output.js';
const DIFFICULTY_VARIANT = {
    [ContributionDifficulty.GoodFirst]: 'default',
    [ContributionDifficulty.Easy]: 'secondary',
    [ContributionDifficulty.Medium]: 'outline',
    [ContributionDifficulty.Hard]: 'destructive',
};
const DIFFICULTY_LABEL = {
    [ContributionDifficulty.GoodFirst]: 'good first',
    [ContributionDifficulty.Easy]: 'easy',
    [ContributionDifficulty.Medium]: 'medium',
    [ContributionDifficulty.Hard]: 'hard',
};
const PREVIEW_MAX_LEN = 160;
export function CuratedIssuesList({ issues, loading, error }) {
    return (_jsx("section", { className: "flex flex-col gap-3", "data-testid": "curated-issues-list", "aria-label": "Curated good-first-issues", children: loading ? (_jsx(LoadingState, {})) : error ? (_jsx(ErrorState, { message: error })) : issues.length === 0 ? (_jsx(EmptyState, {})) : (_jsx("ul", { className: "flex flex-col gap-3", "data-testid": "curated-issues-list-items", children: issues.map((issue) => (_jsx(IssueCard, { issue: issue }, `${issue.owner}/${issue.repo}#${issue.issueNumber}`))) })) }));
}
function IssueCard({ issue }) {
    const slug = `${issue.owner}/${issue.repo}#${issue.issueNumber}`;
    const preview = previewCriteria(issue.acceptanceCriteria);
    return (_jsxs("li", { className: "bg-card flex flex-col gap-2 rounded-lg border p-3", "data-testid": `curated-issue-${issue.issueNumber}`, children: [_jsxs("div", { className: "flex items-start justify-between gap-2", children: [_jsxs("div", { className: "flex min-w-0 flex-col gap-1", children: [_jsxs("a", { href: issue.url, target: "_blank", rel: "noopener noreferrer", className: "text-primary inline-flex items-center gap-1 truncate text-sm font-medium hover:underline", "data-testid": `curated-issue-link-${issue.issueNumber}`, children: [issue.title, _jsx(ExternalLink, { className: "size-3 shrink-0", "aria-hidden": true })] }), _jsx("p", { className: "text-muted-foreground text-xs", children: slug })] }), _jsx(Badge, { variant: DIFFICULTY_VARIANT[issue.difficulty] ?? 'outline', className: "shrink-0", "data-testid": `curated-issue-difficulty-${issue.issueNumber}`, children: DIFFICULTY_LABEL[issue.difficulty] ?? issue.difficulty })] }), preview ? (_jsx("p", { className: "text-muted-foreground line-clamp-2 text-xs", "data-testid": `curated-issue-preview-${issue.issueNumber}`, children: preview })) : null] }));
}
function previewCriteria(text) {
    if (!text)
        return undefined;
    const trimmed = text.replace(/\s+/g, ' ').trim();
    if (trimmed.length <= PREVIEW_MAX_LEN)
        return trimmed;
    return `${trimmed.slice(0, PREVIEW_MAX_LEN - 1)}…`;
}
function LoadingState() {
    return (_jsx("ul", { className: "flex flex-col gap-3", "data-testid": "curated-issues-loading", children: ['l1', 'l2', 'l3'].map((k) => (_jsxs("li", { className: "bg-card flex flex-col gap-2 rounded-lg border p-3", children: [_jsx(Skeleton, { className: "h-4 w-3/4" }), _jsx(Skeleton, { className: "h-3 w-1/3" })] }, k))) }));
}
function EmptyState() {
    return (_jsx("p", { className: "text-muted-foreground rounded-lg border border-dashed p-4 text-sm", "data-testid": "curated-issues-empty", children: "No good-first-issues open in this lane right now \u2014 check back soon, or pick a different lane." }));
}
function ErrorState({ message }) {
    return (_jsxs("p", { className: "text-destructive bg-destructive/5 border-destructive/40 rounded-lg border p-4 text-sm", "data-testid": "curated-issues-error", role: "alert", children: ["Couldn't load curated issues: ", message] }));
}
