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

    <record id="poynt_refund_wizard_form" model="ir.ui.view">
        <field name="name">poynt.refund.wizard.form</field>
        <field name="model">poynt.refund.wizard</field>
        <field name="arch" type="xml">
            <form string="Refund via Poynt">

                <!-- Success banner -->
                <div class="alert alert-success text-center"
                     role="status"
                     invisible="state != 'done'">
                    <strong>Refund Processed Successfully</strong>
                    <p><field name="status_message" nolabel="1" readonly="1"/></p>
                </div>

                <!-- Error banner -->
                <div class="alert alert-danger text-center"
                     role="alert"
                     invisible="state != 'error'">
                    <strong>Refund Failed</strong>
                    <p><field name="status_message" nolabel="1" readonly="1"/></p>
                </div>

                <!-- Non-referenced credit warning -->
                <div class="alert alert-warning text-center"
                     role="alert"
                     invisible="state != 'confirm' or refund_type != 'non_referenced'">
                    <strong>Non-Referenced Credit Required</strong>
                    <p>
                        The original transaction is over 180 days old.
                        The customer's card must be physically present on the
                        terminal to process this refund.
                    </p>
                </div>

                <group invisible="state == 'done'">
                    <group string="Refund Details">
                        <field name="credit_note_id" readonly="1"/>
                        <field name="original_invoice_id" readonly="1"/>
                        <field name="partner_id" readonly="1"/>
                        <field name="amount" readonly="state != 'confirm'"/>
                        <field name="currency_id" invisible="1"/>
                    </group>
                    <group string="Original Payment">
                        <field name="provider_id" invisible="1"/>
                        <field name="provider_name"/>
                        <field name="original_transaction_id" readonly="1"/>
                        <field name="original_poynt_txn_id" readonly="1"/>
                        <field name="card_info" readonly="1"
                               invisible="not card_info"/>
                        <field name="transaction_age_days" readonly="1"/>
                        <field name="refund_type" readonly="1"/>
                    </group>
                </group>

                <!-- Terminal selector for non-referenced credits -->
                <group invisible="state != 'confirm' or refund_type != 'non_referenced'">
                    <group string="Terminal">
                        <field name="terminal_id"
                               required="refund_type == 'non_referenced'"
                               options="{'no_create': True}"/>
                    </group>
                </group>

                <!-- Refund method note -->
                <group invisible="state != 'confirm'">
                    <field name="refund_type_note" readonly="1" nolabel="1"
                           widget="text" colspan="2"/>
                </group>

                <footer>
                    <!-- Confirm state -->
                    <button string="Process Refund"
                            name="action_process_refund"
                            type="object"
                            class="btn-primary"
                            icon="fa-undo"
                            invisible="state != 'confirm'"
                            confirm="Are you sure you want to refund this amount? This cannot be undone."
                            data-hotkey="q"/>
                    <button string="Cancel"
                            class="btn-secondary"
                            special="cancel"
                            invisible="state != 'confirm'"
                            data-hotkey="x"/>
                    <!-- Done state -->
                    <button string="Send Receipt"
                            name="action_send_receipt"
                            type="object"
                            class="btn-primary"
                            icon="fa-envelope"
                            invisible="state != 'done'"
                            data-hotkey="s"/>
                    <button string="Close"
                            class="btn-secondary"
                            special="cancel"
                            invisible="state != 'done'"
                            data-hotkey="x"/>
                    <!-- Error state -->
                    <button string="Close"
                            class="btn-primary"
                            special="cancel"
                            invisible="state != 'error'"
                            data-hotkey="x"/>
                </footer>

            </form>
        </field>
    </record>

</odoo>
