"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { cn } from "@stigmer/theme";
import { SelectionCheckbox } from "./SelectionCheckbox";
/**
 * Compact list view for the resource workbench.
 *
 * Renders items as a single-column vertical list of rows. Each row
 * supports selection, an action slot, and click handling. Row content
 * is customizable via the `renderRow` prop.
 *
 * This component renders **only the list**. Search, filters, and
 * pagination are handled by the parent `ResourceWorkbench`.
 */
export function ResourceList({ items, renderRow, enableSelection = false, selectedIds, onToggleSelection, getItemId = defaultGetId, renderRowAction, onRowClick, "aria-label": ariaLabel = "Resource list", className, }) {
    return (_jsx("div", { role: "list", "aria-label": ariaLabel, className: cn("flex flex-col", className), children: items.map((item, index) => {
            const id = getItemId(item);
            const isSelected = selectedIds?.has(id) ?? false;
            const isClickable = !!onRowClick;
            return (_jsxs("div", { role: "listitem", "aria-selected": enableSelection ? isSelected : undefined, onClick: isClickable
                    ? (e) => {
                        const target = e.target;
                        if (target.closest("button") ||
                            target.closest("input") ||
                            target.closest("[role='menu']")) {
                            return;
                        }
                        onRowClick(item);
                    }
                    : undefined, className: cn("flex items-center gap-3 rounded-lg px-3 py-2.5 transition-colors", isSelected && "bg-primary-subtle", isClickable && "cursor-pointer hover:bg-accent-hover", isClickable && "focus-within:ring-2 focus-within:ring-inset focus-within:ring-ring"), children: [enableSelection && onToggleSelection && (_jsx(SelectionCheckbox, { checked: isSelected, onChange: () => onToggleSelection(id), "aria-label": `Select item ${id}` })), _jsx("div", { className: "min-w-0 flex-1", children: renderRow(item, index) }), renderRowAction && (_jsx("div", { className: "ml-auto shrink-0", onClick: (e) => e.stopPropagation(), children: renderRowAction(item) }))] }, id || `row-${index}`));
        }) }));
}
function defaultGetId(item) {
    const r = item;
    if (typeof r.id === "string")
        return r.id;
    if (typeof r.slug === "string")
        return r.slug;
    return "";
}
//# sourceMappingURL=ResourceList.js.map