<?xml version="1.0" encoding="utf-8"?>
<odoo>

    <record id="view_move_form_clover_button" model="ir.ui.view">
        <field name="name">account.move.form.clover.button</field>
        <field name="model">account.move</field>
        <field name="inherit_id" ref="account.view_move_form"/>
        <field name="priority">60</field>
        <field name="arch" type="xml">

            <!-- Clover Refund smart button on invoices -->
            <xpath expr="//div[@name='button_box']" position="inside">
                <button name="action_view_clover_refunds"
                        type="object"
                        class="oe_stat_button"
                        icon="fa-undo"
                        invisible="clover_refund_count == 0">
                    <field name="clover_refund_count" widget="statinfo" string="Clover Refunds"/>
                </button>
            </xpath>

            <!-- Collect payment button on invoices -->
            <xpath expr="//button[@id='account_invoice_payment_btn']" position="after">
                <button name="action_open_clover_payment_wizard"
                        string="Collect Clover Payment"
                        type="object"
                        class="btn-secondary"
                        icon="fa-credit-card"
                        invisible="state != 'posted' or payment_state not in ('not_paid', 'partial') or move_type != 'out_invoice' or not clover_provider_enabled"
                        groups="fusion_clover.group_fusion_clover_user"
                        data-hotkey="p"/>
            </xpath>

            <!-- Refund via Clover button on credit notes -->
            <xpath expr="//button[@id='account_invoice_payment_btn']" position="after">
                <button name="action_open_clover_refund_wizard"
                        string="Refund via Clover"
                        type="object"
                        class="btn-secondary"
                        icon="fa-undo"
                        invisible="state != 'posted' or payment_state not in ('not_paid', 'partial') or move_type != 'out_refund' or clover_refunded or not clover_provider_enabled"
                        groups="fusion_clover.group_fusion_clover_user"
                        data-hotkey="r"/>
            </xpath>

            <!-- Resend Receipt button on invoices -->
            <xpath expr="//button[@id='account_invoice_payment_btn']" position="after">
                <button name="action_resend_clover_receipt"
                        string="Resend Receipt"
                        type="object"
                        class="btn-secondary"
                        icon="fa-envelope"
                        invisible="state != 'posted' or move_type != 'out_invoice' or not has_clover_receipt"
                        groups="fusion_clover.group_fusion_clover_user"/>
            </xpath>

            <!-- Resend Receipt button on credit notes -->
            <xpath expr="//button[@id='account_invoice_payment_btn']" position="after">
                <button name="action_resend_clover_receipt"
                        string="Resend Refund Receipt"
                        type="object"
                        class="btn-secondary"
                        icon="fa-envelope"
                        invisible="state != 'posted' or move_type != 'out_refund' or not clover_refunded"
                        groups="fusion_clover.group_fusion_clover_user"/>
            </xpath>

            <!-- Refunded banner on credit notes -->
            <xpath expr="//header" position="before">
                <div class="alert alert-info text-center mb-0"
                     role="status"
                     invisible="not clover_refunded">
                    <strong>Refunded via Clover</strong> — This credit note has been
                    refunded to the customer's card through Clover.
                </div>
                <field name="clover_refunded" invisible="1"/>
                <field name="has_clover_receipt" invisible="1"/>
                <field name="clover_provider_enabled" invisible="1"/>
            </xpath>

        </field>
    </record>

</odoo>
