<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <record id="view_mod_pca_received_wizard_form" model="ir.ui.view">
        <field name="name">fusion_claims.mod.pca.received.wizard.form</field>
        <field name="model">fusion_claims.mod.pca.received.wizard</field>
        <field name="arch" type="xml">
            <form string="PCA Received">
                <field name="sale_order_id" invisible="1"/>
                <field name="currency_id" invisible="1"/>

                <div class="alert alert-success mb-3">
                    <i class="fa fa-file-text"/>
                    Upload the PCA document, confirm approval amounts, and create invoice(s).
                </div>

                <!-- PCA Document + Case Details -->
                <group>
                    <group string="PCA Document">
                        <field name="pca_document" filename="pca_filename" required="1"/>
                        <field name="pca_filename" invisible="1"/>
                    </group>
                    <group string="Case Details">
                        <field name="case_worker_id"
                               options="{'no_create': False, 'no_quick_create': False}"
                               placeholder="Select or create case worker..."/>
                        <field name="hvmp_reference"
                               placeholder="e.g. HVW38845"/>
                    </group>
                </group>

                <!-- Approval Details -->
                <group>
                    <group string="Approval">
                        <field name="approval_type" widget="radio"/>
                        <field name="approved_amount" string="Approved Amount"
                               invisible="approval_type != 'partial'"
                               required="approval_type == 'partial'"/>
                        <field name="order_total" string="Order Subtotal" readonly="1"/>
                    </group>
                </group>

                <!-- Split Preview Table (partial only) -->
                <group invisible="approval_type != 'partial' or not approved_amount">
                    <separator string="Split Preview"/>
                </group>
                <field name="preview_line_ids"
                       invisible="approval_type != 'partial' or not approved_amount"
                       readonly="1" nolabel="1">
                    <list editable="bottom" create="0" delete="0">
                        <field name="product_name" string="Product"/>
                        <field name="quantity" string="Qty"/>
                        <field name="line_total" string="Line Total" widget="monetary"/>
                        <field name="mod_amount" string="MOD Pays" widget="monetary"
                               decoration-success="mod_amount > 0"/>
                        <field name="client_amount" string="Client Pays" widget="monetary"
                               decoration-danger="client_amount > 0"/>
                    </list>
                </field>

                <footer>
                    <button name="action_confirm" type="object"
                            string="Confirm PCA and Create Invoice(s)"
                            class="btn-success" icon="fa-check"/>
                    <button string="Cancel" class="btn-secondary" special="cancel"/>
                </footer>
            </form>
        </field>
    </record>
</odoo>
