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

    <!-- Add RingCentral calls tab and smart button to contact form -->
    <record id="view_partner_form_inherit_rc" model="ir.ui.view">
        <field name="name">res.partner.form.inherit.fusion_ringcentral</field>
        <field name="model">res.partner</field>
        <field name="inherit_id" ref="base.view_partner_form"/>
        <field name="arch" type="xml">

            <!-- Smart button for call count (RC users only) -->
            <xpath expr="//div[@name='button_box']" position="inside">
                <button name="action_view_rc_calls" type="object"
                        class="oe_stat_button" icon="fa-phone"
                        invisible="rc_call_count == 0"
                        groups="fusion_ringcentral.group_rc_user">
                    <field name="rc_call_count" widget="statinfo" string="Calls"/>
                </button>
            </xpath>

            <!-- RingCentral Calls tab (RC users only) -->
            <xpath expr="//page[@name='internal_notes']" position="after">
                <page string="RingCentral Calls" name="rc_calls"
                      invisible="rc_call_count == 0"
                      groups="fusion_ringcentral.group_rc_user">
                    <field name="rc_call_ids" readonly="1">
                        <list decoration-danger="status in ('missed', 'no_answer')"
                              decoration-success="status == 'answered'">
                            <field name="name"/>
                            <field name="direction" widget="badge"
                                   decoration-info="direction == 'outbound'"
                                   decoration-success="direction == 'inbound'"/>
                            <field name="start_time"/>
                            <field name="from_number"/>
                            <field name="to_number"/>
                            <field name="duration_display" string="Duration"/>
                            <field name="status" widget="badge"
                                   decoration-success="status == 'answered'"
                                   decoration-danger="status in ('missed', 'no_answer')"/>
                            <field name="has_recording" string="Rec" widget="boolean"/>
                        </list>
                    </field>
                </page>
            </xpath>

        </field>
    </record>

</odoo>
