<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <!-- HR override buttons on the leave form, visible only to Time Off Officers -->
        <record id="view_hr_leave_form_xeno_override" model="ir.ui.view">
            <field name="name">hr.leave.form.xeno.override</field>
            <field name="model">hr.leave</field>
            <field name="inherit_id" ref="hr_holidays.hr_leave_view_form"/>
            <field name="arch" type="xml">
                <xpath expr="//header" position="inside">
                    <button name="action_xeno_force_approve" type="object"
                            string="Force Approve" class="btn-secondary"
                            confirm="This bypasses the normal approval chain. Continue?"
                            invisible="state == 'validate'"
                            groups="hr_holidays.group_hr_holidays_user"/>
                    <button name="action_xeno_force_reject" type="object"
                            string="Force Reject" class="btn-secondary"
                            confirm="This bypasses the normal approval chain. Continue?"
                            invisible="state in ('refuse', 'cancel')"
                            groups="hr_holidays.group_hr_holidays_user"/>
                    <button name="%(xeno_leave.action_xeno_leave_hr_update)d" type="action"
                            string="HR Update" class="btn-secondary"
                            context="{'default_leave_id': id}"
                            groups="hr_holidays.group_hr_holidays_user"/>
                </xpath>
            </field>
        </record>

        <!-- Read-only approval chain progress, snapshotted at submission:
             the Odoo-native equivalent of XENHR's chain preview, visible to
             both the requester and whoever is approving. -->
        <record id="view_hr_leave_form_xeno_approval_chain" model="ir.ui.view">
            <field name="name">hr.leave.form.xeno.approval.chain</field>
            <field name="model">hr.leave</field>
            <field name="inherit_id" ref="hr_holidays.hr_leave_view_form"/>
            <field name="arch" type="xml">
                <xpath expr="//sheet" position="inside">
                    <group string="Approval Chain" invisible="not xeno_approval_step_ids">
                        <field name="xeno_approval_step_ids" nolabel="1" colspan="2"
                               widget="xeno_approval_chain">
                            <list create="false" delete="false" decoration-muted="state == 'pending'">
                                <field name="step_order"/>
                                <field name="label"/>
                                <field name="approver_user_id" widget="many2one_avatar_user"/>
                                <field name="state" widget="badge"
                                       decoration-success="state == 'approved'"
                                       decoration-danger="state == 'rejected'"
                                       decoration-info="state == 'pending'"/>
                                <field name="decided_by"/>
                                <field name="decided_at"/>
                            </list>
                        </field>
                    </group>
                </xpath>
            </field>
        </record>

        <!-- Apply-for-Leave layout, mirroring XENHR's dialog: balance summary
             strip (Total/Used/Pending/Remaining) under the leave type, then a
             "Leave Type Basis" pill picker (Full-day/Part-time/First-half/
             Second-half), only for Flexible Duration types -->
        <record id="view_hr_leave_form_xeno_flexible_duration" model="ir.ui.view">
            <field name="name">hr.leave.form.xeno.flexible.duration</field>
            <field name="model">hr.leave</field>
            <field name="inherit_id" ref="hr_holidays.hr_leave_view_form"/>
            <field name="arch" type="xml">
                <field name="holiday_status_id" position="after">
                    <field name="xeno_flexible_duration" invisible="1"/>
                    <field name="xeno_can_edit_content" invisible="1"/>
                    <div colspan="2" class="alert alert-info o_xeno_leave_type_detail" role="alert"
                         invisible="not xeno_leave_type_detail">
                        <field name="xeno_leave_type_detail" nolabel="1" readonly="1"/>
                    </div>
                    <div colspan="2" class="o_xeno_balance_strip"
                         invisible="not holiday_status_id">
                        <span class="o_xeno_bal">Total
                            <field name="xeno_balance_total"/></span>
                        <span class="o_xeno_bal">Used
                            <field name="xeno_balance_used"/></span>
                        <span class="o_xeno_bal">Pending
                            <field name="xeno_balance_pending"/></span>
                        <span class="o_xeno_bal o_xeno_bal_remaining">Remaining
                            <field name="xeno_balance_remaining"/></span>
                    </div>
                    <field name="xeno_request_unit" string="Leave Type Basis"
                           invisible="not xeno_flexible_duration"
                           required="xeno_flexible_duration"
                           readonly="not xeno_can_edit_content"
                           widget="radio" options="{'horizontal': true}"
                           class="o_xeno_basis_pills"/>
                </field>
                <!-- Period selectors become redundant for flexible types: the
                     First-half/Second-half basis sets them automatically -->
                <xpath expr="//label[@for='request_date_from_period']" position="attributes">
                    <attribute name="invisible">not request_unit_half or xeno_flexible_duration</attribute>
                </xpath>
                <xpath expr="//label[@for='request_date_from_period']/following-sibling::div[1]" position="attributes">
                    <attribute name="invisible">not request_unit_half or xeno_flexible_duration</attribute>
                </xpath>
            </field>
        </record>

        <!-- Once a leave request is saved, only HR may edit its content,
             the requester's only remaining self-service action is Cancel.
             Combines with (doesn't replace) each field's existing
             state-based readonly condition. -->
        <record id="view_hr_leave_form_xeno_lock_content" model="ir.ui.view">
            <field name="name">hr.leave.form.xeno.lock.content</field>
            <field name="model">hr.leave</field>
            <field name="inherit_id" ref="hr_holidays.hr_leave_view_form"/>
            <field name="arch" type="xml">
                <field name="holiday_status_id" position="attributes">
                    <attribute name="readonly">state in ['cancel', 'refuse', 'validate', 'validate1'] or not xeno_can_edit_content</attribute>
                </field>
                <field name="request_date_from" position="attributes">
                    <attribute name="readonly">state != 'confirm' or not xeno_can_edit_content</attribute>
                </field>
                <field name="request_date_from_period" position="attributes">
                    <attribute name="readonly">state != 'confirm' or not xeno_can_edit_content</attribute>
                </field>
                <field name="request_date_to_period" position="attributes">
                    <attribute name="readonly">state != 'confirm' or not xeno_can_edit_content</attribute>
                </field>
                <field name="request_hour_from" position="attributes">
                    <attribute name="readonly">state == 'validate' or not xeno_can_edit_content</attribute>
                </field>
                <field name="request_hour_to" position="attributes">
                    <attribute name="readonly">state == 'validate' or not xeno_can_edit_content</attribute>
                </field>
                <field name="name" position="attributes">
                    <attribute name="readonly">state != 'confirm' or not xeno_can_edit_content</attribute>
                </field>
            </field>
        </record>

        <!-- HR/Admin-only "Analysis" checklist (same 5 checks as the Leave
             Approval decision dialog), directly below core's own "Employee's
             summary" widget in the sidebar. -->
        <record id="view_hr_leave_form_xeno_analysis" model="ir.ui.view">
            <field name="name">hr.leave.form.xeno.analysis</field>
            <field name="model">hr.leave</field>
            <field name="inherit_id" ref="hr_holidays.hr_leave_view_form"/>
            <field name="arch" type="xml">
                <xpath expr="//widget[@name='hr_leave_stats']" position="after">
                    <widget name="xeno_leave_analysis" groups="hr_holidays.group_hr_holidays_user"/>
                </xpath>
            </field>
        </record>

        <!-- "My Team Leaves": pending leaves where I'm the configured approver -->
        <record id="action_xeno_my_team_leaves" model="ir.actions.act_window">
            <field name="name">My Team Leaves</field>
            <field name="res_model">hr.leave</field>
            <field name="view_mode">list,form</field>
            <field name="domain">[('xeno_is_approver_for_me', '=', True)]</field>
            <field name="help" type="html">
                <p class="o_view_nocontent_smiling_face">No leave requests waiting on you right now.</p>
                <p>Shows requests where you're the configured approver (see Configuration → Leave Approvers) -- employee-specific rule first, else your department's rule.</p>
            </field>
        </record>
    </data>
    <data noupdate="1">
        <menuitem id="menu_xeno_my_team_leaves"
                  name="My Team Leaves"
                  parent="hr_holidays.menu_hr_holidays_management"
                  action="action_xeno_my_team_leaves"
                  groups="hr_holidays.group_hr_holidays_user"
                  sequence="15"/>
    </data>
</odoo>
