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

    <!-- Add fax number field + fax history tab to contact form -->
    <record id="view_partner_form_inherit_fusion_faxes" model="ir.ui.view">
        <field name="name">res.partner.form.inherit.fusion_faxes</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">

            <!-- Add fax number on its own row below phone (fax users only) -->
            <xpath expr="//field[@name='phone']/.." position="after">
                <div class="d-flex align-items-baseline w-md-50"
                     groups="fusion_faxes.group_fax_user">
                    <i class="fa fa-fw me-1 fa-fax text-primary" title="Fax"/>
                    <field name="x_ff_fax_number" class="w-100" widget="phone"
                           placeholder="Fax number..."/>
                </div>
            </xpath>

            <!-- Add smart button for fax count (fax users only) -->
            <xpath expr="//div[@name='button_box']" position="inside">
                <button name="action_view_faxes" type="object"
                        class="oe_stat_button" icon="fa-fax"
                        invisible="x_ff_fax_count == 0"
                        groups="fusion_faxes.group_fax_user">
                    <field name="x_ff_fax_count" widget="statinfo" string="Faxes"/>
                </button>
            </xpath>

            <!-- Add Fax History tab (fax users only) -->
            <xpath expr="//page[@name='internal_notes']" position="after">
                <page string="Fax History" name="fax_history"
                      invisible="x_ff_fax_count == 0"
                      groups="fusion_faxes.group_fax_user">
                    <field name="x_ff_fax_ids" readonly="1">
                        <list>
                            <field name="name"/>
                            <field name="sent_date"/>
                            <field name="fax_number"/>
                            <field name="page_count"/>
                            <field name="state" widget="badge"
                                   decoration-success="state == 'sent'"
                                   decoration-danger="state == 'failed'"/>
                            <field name="sent_by_id"/>
                        </list>
                    </field>
                </page>
            </xpath>

        </field>
    </record>

</odoo>
