<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- =============================================================
         Fusion Extraction Review Wizard – Form View
         ============================================================= -->
    <record id="fusion_extraction_review_wizard_form" model="ir.ui.view">
        <field name="name">fusion.extraction.review.wizard.form</field>
        <field name="model">fusion.extraction.review.wizard</field>
        <field name="arch" type="xml">
            <form string="Review Extracted Invoice Data">
                <header>
                    <button name="action_apply"
                            string="Apply to Invoice"
                            type="object"
                            class="btn-primary"
                            icon="fa-check"/>
                    <button name="action_re_extract"
                            string="Re-Extract"
                            type="object"
                            class="btn-warning"
                            icon="fa-refresh"
                            confirm="This will overwrite the current extraction. Continue?"/>
                    <button name="action_discard"
                            string="Discard"
                            type="object"
                            class="btn-secondary"
                            special="cancel"/>
                </header>
                <sheet>
                    <!-- Confidence banner -->
                    <div class="alert alert-success text-center"
                         role="alert"
                         invisible="confidence &lt; 70">
                        <strong>High confidence extraction</strong>
                        – <field name="confidence" widget="float" readonly="1" class="d-inline"/> %
                        of key fields were detected.
                    </div>
                    <div class="alert alert-warning text-center"
                         role="alert"
                         invisible="confidence &gt;= 70 or confidence &lt; 40">
                        <strong>Medium confidence extraction</strong>
                        – <field name="confidence" widget="float" readonly="1" class="d-inline"/> %
                        of key fields were detected. Please review carefully.
                    </div>
                    <div class="alert alert-danger text-center"
                         role="alert"
                         invisible="confidence &gt;= 40">
                        <strong>Low confidence extraction</strong>
                        – <field name="confidence" widget="float" readonly="1" class="d-inline"/> %
                        of key fields were detected. Manual entry may be required.
                    </div>

                    <group>
                        <group string="Invoice Header">
                            <field name="vendor_name"
                                   placeholder="e.g. Acme Corp"/>
                            <field name="invoice_number"
                                   placeholder="e.g. INV-2026-001"/>
                            <field name="invoice_date"/>
                            <field name="due_date"/>
                            <field name="currency_code"
                                   placeholder="e.g. USD"/>
                        </group>
                        <group string="Amounts">
                            <field name="subtotal"/>
                            <field name="tax_amount"/>
                            <field name="total_amount"/>
                        </group>
                    </group>

                    <notebook>
                        <page string="Line Items" name="line_items">
                            <field name="line_items_json"
                                   widget="ace"
                                   options="{'mode': 'json'}"
                                   placeholder='[{"description": "...", "quantity": 1, "unit_price": 0.0, "amount": 0.0}]'/>
                            <div class="text-muted small mt-2">
                                Edit the JSON array above to correct line items.
                                Each object should contain: description, quantity,
                                unit_price, amount.
                            </div>
                        </page>
                        <page string="Raw OCR Text" name="raw_text">
                            <field name="raw_text"
                                   readonly="1"
                                   nolabel="1"/>
                        </page>
                        <page string="Original Scan" name="scan_preview">
                            <group>
                                <field name="attachment_filename" invisible="1"/>
                                <field name="attachment_preview"
                                       widget="image"
                                       readonly="1"
                                       options="{'size': [800, 1100]}"
                                       invisible="not attachment_preview"/>
                                <div invisible="attachment_preview"
                                     class="text-muted">
                                    No image preview available. The attachment may
                                    be a PDF (open it separately to view).
                                </div>
                            </group>
                        </page>
                    </notebook>

                    <field name="move_id" invisible="1"/>
                    <field name="corrections_json" invisible="1"/>
                </sheet>
            </form>
        </field>
    </record>

    <!-- =============================================================
         Wizard Action (used internally from Python)
         ============================================================= -->
    <record id="fusion_extraction_review_wizard_action" model="ir.actions.act_window">
        <field name="name">Review Extracted Data</field>
        <field name="res_model">fusion.extraction.review.wizard</field>
        <field name="view_mode">form</field>
        <field name="target">new</field>
    </record>
</odoo>
