/**
 * PrintView - Print/PDF optimized view
 *
 * Features:
 * - Clean, non-interactive layout
 * - No field controls or icons
 * - All sections expanded
 * - Print-optimized CSS (no shadows, good page breaks)
 * - Header/footer slots for branding
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useFormViewContext } from '../context.js';
import { useShouldRenderField, useShouldRenderGroup, useShouldRenderSection } from '../use_form_view.js';
import { cn } from '../../../utils/cn.js';
import { get_field_value, is_field_empty } from '../../shared/field_utils/index.js';
import { format_date_value, get_display_label } from '../../shared/summary_utils/index.js';
import { SummaryDataTable } from './summary_data_table.js';
import { use_field_action_slot } from '../../shared/use_field_action_slot.js';
/**
 * PrintSection - Renders a section for print
 */
function PrintSection({ section, section_index, page_break, }) {
    const should_render_sec = useShouldRenderSection();
    if (!should_render_sec(section))
        return null;
    return (_jsxs("div", { className: cn('cls_print_section mb-8', page_break && 'break-before-page'), children: [_jsx("div", { className: "border-b-2 border-black pb-2 mb-4", children: _jsx("h2", { className: "text-xl font-bold text-foreground", children: section.section_name || `Section ${section_index + 1}` }) }), _jsx("div", { className: "space-y-4", children: section.groups && section.groups.length > 0 ? (section.groups.map((group) => (_jsx(PrintGroup, { field: group }, group.id)))) : (_jsx("p", { className: "text-gray-500 italic", children: "No information entered" })) })] }));
}
/**
 * PrintGroup - Renders a group for print
 */
function PrintGroup({ field }) {
    const should_render = useShouldRenderField();
    const should_render_grp = useShouldRenderGroup();
    if (!should_render(field)) {
        return null;
    }
    // Skip empty groups for responders/non-visibility roles
    if (field.field_type === 'group' && !should_render_grp(field)) {
        return null;
    }
    const is_group = field.field_type === 'group';
    if (is_group && field.fields) {
        return (_jsxs("div", { className: "cls_print_group mb-4", children: [field.label && (_jsx("h3", { className: "font-semibold text-sm uppercase tracking-wide mb-2 border-b pb-1 text-foreground", children: field.label })), _jsx("div", { className: "space-y-2 pl-4", children: field.fields.map((child) => (_jsx(PrintField, { field: child }, child.id))) })] }));
    }
    return _jsx(PrintField, { field: field });
}
/**
 * PrintField - Renders a single field for print
 */
function PrintField({ field }) {
    const { form_data, settings } = useFormViewContext();
    const should_render = useShouldRenderField();
    const field_action_slot = use_field_action_slot(field.id);
    if (!should_render(field)) {
        return null;
    }
    const value = get_field_value(field.id, form_data);
    const is_empty = is_field_empty(value);
    // Skip empty fields if configured
    if (is_empty && !settings.show_empty_fields) {
        return null;
    }
    // Data table fields get special rendering
    if (field.component_type === 'HazoCollabFormDataTable' && field.table_config) {
        const rows = (Array.isArray(value) ? value : []);
        return (_jsxs("div", { className: "cls_print_field py-2", children: [_jsx("span", { className: "font-medium text-sm", children: field.label || field.id }), _jsx(SummaryDataTable, { table_config: field.table_config, rows: rows, date_format: settings.date_format, class_name: "mt-1" })] }));
    }
    // Format value based on field type
    let display_value;
    if (is_empty) {
        display_value = '—'; // Em dash for empty values in print
    }
    else if (field.component_type === 'HazoCollabFormCheckbox') {
        display_value = value === true || value === 'true' ? 'Yes' : 'No';
    }
    else if (field.component_type === 'HazoCollabFormDate') {
        display_value = format_date_value(value, settings.date_format);
    }
    else if (field.component_type === 'HazoCollabFormCombo' || field.component_type === 'HazoCollabFormRadio') {
        display_value = get_display_label(field.input_options, String(value));
    }
    else if (field.component_type === 'HazoCollabFormDoc') {
        // Handle document fields
        if (Array.isArray(value) && value.length > 0) {
            display_value = `${value.length} document(s) attached`;
        }
        else {
            display_value = '—';
        }
    }
    else {
        display_value = String(value);
    }
    return (_jsxs("div", { className: "cls_print_field py-1 border-b border-dotted border-gray-300", children: [_jsxs("div", { className: "grid grid-cols-[200px_1fr_auto] gap-4", children: [_jsx("span", { className: "font-medium text-sm", children: field.label || field.id }), _jsx("span", { className: "text-sm", children: display_value }), field_action_slot.row_end] }), field_action_slot.row_below && (_jsx("div", { className: "cls_field_action_below mt-1", children: field_action_slot.row_below }))] }));
}
/**
 * PrintHeader - Default print header
 */
function PrintHeader({ title }) {
    return (_jsxs("div", { className: "cls_print_header mb-8 pb-4 border-b-2 border-black", children: [_jsx("h1", { className: "text-2xl font-bold text-foreground", children: title || 'Form Summary' }), _jsxs("p", { className: "text-sm text-gray-600 mt-1", children: ["Generated on ", new Date().toLocaleDateString()] })] }));
}
/**
 * PrintFooter - Default print footer
 */
function PrintFooter() {
    return (_jsx("div", { className: "cls_print_footer mt-8 pt-4 border-t text-sm text-gray-500 text-center", children: _jsx("p", { children: "This document was generated automatically." }) }));
}
/**
 * PrintView component
 *
 * Optimized for printing/PDF export:
 * - No interactive controls
 * - High contrast text
 * - No shadows or decorative elements
 * - Page break support
 * - Header/footer slots
 */
export function PrintView({ header, footer, page_break_between_sections = false, title, } = {}) {
    const { sections } = useFormViewContext();
    return (_jsxs("div", { className: cn('cls_form_view_print', 'bg-white text-black', 
        // Print-specific styles
        'print:p-0', '[print-color-adjust:exact] [-webkit-print-color-adjust:exact]'), children: [header !== undefined ? header : _jsx(PrintHeader, { title: title }), _jsx("div", { className: "space-y-8", children: sections.map((section, index) => (_jsx(PrintSection, { section: section, section_index: index, page_break: page_break_between_sections && index > 0 }, `${section.section_name || 'section'}_${index}`))) }), footer !== undefined ? footer : _jsx(PrintFooter, {})] }));
}
//# sourceMappingURL=print_view.js.map