/**
 * HazoCollabFormRFIbox — Standalone Request for Information lifecycle component.
 *
 * Handles the full RFI lifecycle:
 * - Client respond (dialog, embedded, or collapsed)
 * - Agent review (accept / send back)
 * - Agent send back (feedback + option tag selector)
 * - Client re-respond with thread history
 *
 * Composes ClarificationItemBody as the core renderer.
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useCallback } from 'react';
import { cn } from '../../utils/cn.js';
import { ClarificationItemBody } from '../clarification/clarification_item_body.js';
import { CollapsibleCard } from '../shared/collapsible_card/index.js';
import { STATUS_CONFIG } from '../clarification/clarification_status_config.js';
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogDescription, } from '../shared/dialog/index.js';
import { RfiReviewActions } from './rfi_review_actions.js';
import { RfiSendBackForm } from './rfi_send_back_form.js';
export function HazoCollabFormRFIbox({ item, mode, display = 'embedded', open, on_open_change, dialog_title = 'Validation Issues', on_respond, on_accept, on_send_back, on_dismiss, on_resolve, file_manager, on_doc_view, available_response_options, initial_selected_options, initial_feedback, className, }) {
    // Derive rendering flags from mode
    const is_read_only = mode !== 'respond';
    const hide_submit = mode !== 'respond';
    const hide_response_form = mode === 'send_back';
    const config = STATUS_CONFIG[item.status] ?? STATUS_CONFIG.pending;
    // Response counter for footer
    const responded = item.status === 'responded' || item.status === 'resolved';
    const counter_text = responded ? '1 of 1 responded' : '0 of 1 responded';
    // Handle send-back
    const handle_send_back = useCallback((payload) => {
        on_send_back?.(item.id, payload);
    }, [on_send_back, item.id]);
    // ── Core content: ClarificationItemBody + mode-specific additions ──
    const core_content = (_jsxs("div", { className: cn('cls_rfi_box', className), children: [_jsx("div", { className: cn('rounded-lg overflow-hidden border border-l-[3px]', config.card_border, config.card_left_border), children: _jsx(ClarificationItemBody, { item: item, show_doc_references: true, read_only: is_read_only, hide_submit: hide_submit, hide_response_form: hide_response_form, file_manager: file_manager, on_respond: on_respond, on_resolve: on_resolve, on_dismiss: on_dismiss, on_doc_view: on_doc_view }) }), mode === 'review' && (_jsx(RfiReviewActions, { on_accept: on_accept ? () => on_accept(item.id) : undefined, on_send_back: on_send_back ? () => on_send_back(item.id, { feedback: '', response_options: [] }) : undefined })), mode === 'send_back' && (_jsx(RfiSendBackForm, { available_response_options: available_response_options ?? item.response_options, initial_selected_options: initial_selected_options, initial_feedback: initial_feedback, on_send_back: handle_send_back })), mode === 'respond' && (_jsx("div", { className: "flex items-center justify-between pt-3", children: _jsx("span", { className: "text-sm text-muted-foreground", children: counter_text }) }))] }));
    // ── Display wrapper ──
    if (display === 'dialog' && (mode === 'respond' || mode === 'read_only')) {
        return (_jsx(Dialog, { open: open, onOpenChange: on_open_change, children: _jsxs(DialogContent, { className: "max-w-2xl max-h-[80vh] overflow-y-auto", children: [_jsxs(DialogHeader, { children: [_jsx(DialogTitle, { children: dialog_title }), _jsx(DialogDescription, { children: item.status === 'pending'
                                    ? '1 pending issue requiring attention'
                                    : '1 issue' })] }), _jsx("div", { className: "mt-4", children: core_content })] }) }));
    }
    if (display === 'collapsed' && (mode === 'respond' || mode === 'read_only')) {
        const is_responded = item.status === 'responded' || item.status === 'resolved';
        const StatusIcon = config.Icon;
        const status_badge = is_responded ? (_jsx("span", { className: cn('inline-flex items-center px-1.5 py-0.5 rounded text-[10px] font-semibold shrink-0', item.status === 'responded' ? 'bg-blue-100 text-blue-700' :
                item.status === 'resolved' ? 'bg-green-100 text-green-700' :
                    'bg-gray-100 text-gray-600'), children: item.status === 'responded' ? 'Responded' : item.status === 'resolved' ? 'Resolved' : 'Dismissed' })) : undefined;
        return (_jsx("div", { className: cn('cls_rfi_box', className), children: _jsx(CollapsibleCard, { expanded: item.status === 'pending', icon: _jsx(StatusIcon, { className: cn('w-4 h-4 shrink-0', is_responded ? 'text-blue-500' : 'text-red-500') }), title: item.issue_description || 'Issue', title_class_name: is_responded ? 'text-muted-foreground' : 'text-foreground', tag: item.rule_name, trailing: status_badge, muted: is_responded, children: _jsx(ClarificationItemBody, { item: item, show_doc_references: true, read_only: mode === 'read_only', hide_submit: mode === 'read_only', file_manager: file_manager, on_respond: on_respond, on_doc_view: on_doc_view }) }) }));
    }
    // Default: embedded
    return core_content;
}
//# sourceMappingURL=hazo_rfi_box.js.map