/**
 * SummaryFiles component
 * Renders a list of files using FileBar for consistent styling across the app.
 * Supports both FormFileAttachment (new) and FileData (legacy) shapes.
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback } from 'react';
import { IoLockClosed } from 'react-icons/io5';
import { cn } from '../../../utils/cn.js';
import { FileBar } from '../file_bar/index.js';
/** Derive validation prop for FileBar from error/passed sets */
function get_validation(file_id, error_file_ids, passed_file_ids) {
    if (error_file_ids?.has(file_id)) {
        return { state: 'issues', issue_count: 1 };
    }
    if (passed_file_ids?.has(file_id)) {
        return { state: 'passed' };
    }
    return null;
}
/** Build download URL from callback or legacy file_path */
function build_download_url(attachment, is_private, get_download_url) {
    if (get_download_url) {
        return get_download_url(attachment.file_id, is_private ? 'private' : 'public');
    }
    if (attachment.file_path) {
        return is_private
            ? `/api/collab-forms/private-files/${encodeURIComponent(attachment.file_path)}`
            : `/api/collab-forms/files/${encodeURIComponent(attachment.file_path)}`;
    }
    return '#';
}
/**
 * SummaryFiles component
 * Renders public and private files in separate sections using FileBar
 */
export function SummaryFiles({ files, private_files, field_id, class_name, get_download_url, show_file_status, error_file_ids, passed_file_ids, on_file_issue_click, on_file_click, }) {
    const has_public_files = files && files.length > 0;
    const has_private_files = private_files && private_files.length > 0;
    const handle_download = useCallback((attachment, is_private) => {
        const url = build_download_url(attachment, is_private, get_download_url);
        if (url && url !== '#') {
            window.open(url, '_blank', 'noopener,noreferrer');
        }
    }, [get_download_url]);
    if (!has_public_files && !has_private_files) {
        return null;
    }
    return (_jsxs("div", { className: cn('cls_summary_files space-y-1.5', class_name), "data-field-id": field_id, children: [has_public_files && (_jsxs("div", { className: "cls_summary_files_public", children: [has_private_files && (_jsx("div", { className: "cls_summary_files_section_header text-xs font-medium text-muted-foreground uppercase tracking-wider mb-1", children: "Public Files" })), _jsx("div", { className: "cls_summary_files_list space-y-1.5", children: files.map((attachment, index) => (_jsx(FileBar, { attachment: attachment, validation: get_validation(attachment.file_id, error_file_ids, passed_file_ids), on_validation_click: on_file_issue_click, on_download: on_file_click ? undefined : () => handle_download(attachment, false), on_view: on_file_click ? () => on_file_click(attachment) : undefined, max_width: "max-w-full" }, attachment.file_id || index))) })] })), has_private_files && (_jsxs("div", { className: cn('cls_summary_files_private rounded-md bg-muted/50 p-2', has_public_files && 'mt-2'), children: [_jsxs("div", { className: "cls_summary_files_section_header text-xs font-medium text-muted-foreground uppercase tracking-wider mb-1 flex items-center gap-1", children: [_jsx(IoLockClosed, { className: "h-3 w-3" }), "Private Files"] }), _jsx("div", { className: "cls_summary_files_list space-y-1.5", children: private_files.map((attachment, index) => (_jsx(FileBar, { attachment: attachment, validation: get_validation(attachment.file_id, error_file_ids, passed_file_ids), on_validation_click: on_file_issue_click, on_download: on_file_click ? undefined : () => handle_download(attachment, true), on_view: on_file_click ? () => on_file_click(attachment) : undefined, max_width: "max-w-full" }, attachment.file_id || index))) })] }))] }));
}
export default SummaryFiles;
//# sourceMappingURL=summary_files.js.map