/**
 * AgentComposeDialog — Pre-filled compose when agent forwards AI issues to client.
 * Quotes the specific field/file reference so client sees context.
 */
'use client';
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
import { useState, useCallback } from 'react';
import { cn } from './shared.js';
/** Build a compose context from an AI check on a file */
export function build_compose_from_check(file_name, check, content_ref, client_name) {
    return {
        source_label: file_name,
        suggested_message: `Hi ${client_name}, regarding ${file_name} — ${check.description.toLowerCase()}. Could you please provide an updated version?`,
        content_ref,
    };
}
/** Build a compose context from a text extraction field issue */
export function build_compose_from_field(field, category, content_ref, client_name) {
    return {
        source_label: `${field.label}: ${field.value}`,
        category,
        client_text: `${field.label}: ${field.value}`,
        suggested_message: `Hi ${client_name}, regarding your ${category.toLowerCase()} — ${field.label} (${field.value}): ${field.issue || 'could you please clarify this item?'}`,
        content_ref,
    };
}
export function AgentComposeDialog({ open, context, on_close, on_send, agent_name }) {
    const [message, set_message] = useState(context?.suggested_message || '');
    // Reset message when context changes
    const prev_ref = useState(context?.content_ref)[0];
    if (context?.content_ref !== prev_ref && context?.suggested_message) {
        set_message(context.suggested_message);
    }
    const handle_send = useCallback(() => {
        if (!message.trim() || !context)
            return;
        on_send(message.trim(), context.content_ref);
        set_message('');
        on_close();
    }, [message, context, on_send, on_close]);
    if (!open || !context)
        return null;
    return (_jsxs("div", { className: "fixed inset-0 z-50 flex items-center justify-center", children: [_jsx("div", { className: "absolute inset-0 bg-black/30", onClick: on_close }), _jsxs("div", { className: "relative bg-white rounded-lg shadow-xl w-full max-w-lg mx-4", children: [_jsxs("div", { className: "px-5 py-4 border-b border-[#E2E8F0]", children: [_jsx("h3", { className: "text-[15px] font-semibold text-[#0F172A]", children: "Send to Client" }), _jsx("p", { className: "text-[12px] text-[#94A3B8] mt-0.5", children: "Compose a message about this issue" })] }), _jsxs("div", { className: "px-5 py-4 space-y-3", children: [_jsxs("div", { className: "bg-[#F8FAFC] border border-[#E2E8F0] rounded-md px-3 py-2", children: [_jsx("span", { className: "text-[11px] text-[#94A3B8] uppercase tracking-wider font-medium", children: "Re: " }), context.category && (_jsxs("span", { className: "text-[12px] text-[#64748B]", children: [context.category, " > "] })), _jsx("span", { className: "text-[12px] font-medium text-[#334155]", children: context.source_label }), context.client_text && (_jsxs("p", { className: "text-[12px] text-[#94A3B8] italic mt-1", children: ["\u201C", context.client_text, "\u201D"] }))] }), _jsxs("div", { children: [_jsx("label", { className: "block text-[12px] font-medium text-[#334155] mb-1", children: "Your message" }), _jsx("textarea", { value: message, onChange: (e) => set_message(e.target.value), className: "w-full border border-[#E2E8F0] rounded-md px-3 py-2 text-[13px] resize-none focus:outline-none focus:ring-1 focus:ring-[#2563EB] focus:border-[#2563EB]", rows: 4, autoFocus: true })] }), _jsxs("div", { className: "text-[11px] text-[#94A3B8]", children: ["Client will see this as a message from ", _jsx("span", { className: "font-medium text-[#64748B]", children: agent_name })] })] }), _jsxs("div", { className: "px-5 py-3 border-t border-[#E2E8F0] flex justify-end gap-2", children: [_jsx("button", { onClick: on_close, className: "text-[13px] text-[#64748B] px-4 py-1.5 rounded hover:bg-[#F1F5F9] cursor-pointer", children: "Cancel" }), _jsx("button", { onClick: handle_send, disabled: !message.trim(), className: cn('text-[13px] font-medium px-4 py-1.5 rounded cursor-pointer', message.trim() ? 'bg-[#2563EB] text-white hover:bg-[#1D4ED8]' : 'bg-[#E2E8F0] text-[#94A3B8] cursor-not-allowed'), children: "Send" })] })] })] }));
}
//# sourceMappingURL=agent_compose_dialog.js.map