<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <record id="view_employee_form_inherit_hr_attendance" model="ir.ui.view">
        <field name="name">hr.employee</field>
        <field name="model">hr.employee</field>
        <field name="inherit_id" ref="hr.view_employee_form"/>
        <field name="priority">10</field>
        <field name="groups_id" eval="[(4,ref('hr_attendance.group_hr_attendance_user'))]"/>
        <field name="arch" type="xml">
            <xpath expr="//button[@name='toggle_active']" position="before">
                <field name="attendance_state" invisible="1"/>
                <button name="%(hr_attendance_action_employee)d"
                    class="oe_stat_button"
                    type="action" attrs="{'invisible': [('attendance_state', '=', False)]}">
                    <div role="img" id="oe_hr_attendance_status" class="fa fa-fw fa-circle o_button_icon oe_hr_attendance_status_green" attrs="{'invisible': [('attendance_state', '=', 'checked_out')]}" aria-label="Available" title="Available"/>
                    <div role="img" id="oe_hr_attendance_status" class="fa fa-fw fa-circle o_button_icon oe_hr_attendance_status_red" attrs="{'invisible': [('attendance_state', '=', 'checked_in')]}" aria-label="Not available" title="Not available"/>
                    <div class="o_stat_info">
                        <span class="o_stat_text">Attendance</span>
                    </div>
                </button>
            </xpath>
            <xpath expr="//group[@name='active_group']" position="after">
                <group string='Attendance' groups="hr_attendance.group_hr_attendance_user">
                    <field name="barcode"/>
                    <field name="pin" groups="hr_attendance.group_hr_attendance_use_pin"/>
                    <field name="manual_attendance" attrs="{'invisible': [('user_id', '=', False)]}"/>
                </group>
            </xpath>
        </field>
    </record>

     <!--Inherit employee search view -->
    <record id="view_employee_filter_inherit_hr_attendance" model="ir.ui.view">
        <field name="name">hr.employee.filter.inherit.attendance</field>
        <field name="model">hr.employee</field>
        <field name="inherit_id" ref="hr.view_employee_filter"/>
        <field name="arch" type="xml">
            <xpath expr="//filter[@name='inactive']" position="before">
                <filter string="Signed In" name="signed_in" domain="[('last_attendance_id.check_out', '=', False)]"/>
                <filter string="Signed Out" name="signed_out" domain="['|', ('last_attendance_id', '=', False), ('last_attendance_id.check_out', '!=', False)]"/>
                <separator/>
            </xpath>
        </field>
    </record>

    <!-- employee kanban view specifically for hr_attendance (to check in/out) -->
    <record id="hr_employees_view_kanban" model="ir.ui.view">
        <field name="name">hr.employee.kanban</field>
        <field name="model">hr.employee</field>
        <field name="priority">99</field>
        <field name="arch" type="xml">
            <kanban class="o_hr_employee_attendance_kanban" create="false">
                <field name="attendance_state"/>
                <field name="id"/>
                <templates>
                    <t t-name="kanban-box">
                    <div class="oe_kanban_global_click">
                        <div class="o_kanban_image">
                            <img t-att-src="kanban_image('hr.employee', 'image_medium', record.id.raw_value)" alt="Employee"/>
                        </div>
                        <div class="oe_kanban_details">
                            <div id="textbox">
                                <div class="float-right" t-if="record.attendance_state.raw_value == 'checked_in'">
                                    <span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_green" role="img" aria-label="Available" title="Available"></span>
                                </div>
                                <div class="float-right" t-if="record.attendance_state.raw_value == 'checked_out'">
                                    <span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_red" role="img" aria-label="Not available" title="Not available"></span>
                                </div>
                                <strong>
                                    <field name="name"/>
                                </strong>
                            </div>
                            <ul>
                                <li t-if="record.job_id.raw_value"><field name="job_id"/></li>
                                <li t-if="record.work_location.raw_value"><field name="work_location"/></li>
                            </ul>
                        </div>
                    </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <record id="view_employee_kanban_inherit_hr_attendance" model="ir.ui.view">
        <field name="name">hr.employee</field>
        <field name="model">hr.employee</field>
        <field name="inherit_id" ref="hr.hr_kanban_view_employees"/>
        <field name="priority">1</field>
        <field name="arch" type="xml">
            <templates position="before">
                <field name="attendance_state"/>
            </templates>
            <field name="name" position="replace">
                <div>
                    <div class="float-right" t-if="record.attendance_state.raw_value == 'checked_in'">
                        <span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_green" role="img" aria-label="Available" title="Available"></span>
                    </div>
                    <div class="float-right" t-if="record.attendance_state.raw_value == 'checked_out'">
                        <span id="oe_hr_attendance_status" class="fa fa-circle oe_hr_attendance_status_red" role="img" aria-label="Not available" title="Not available"></span>
                    </div>
                    <strong>
                        <field name="name" placeholder="Employee's Name"/>
                    </strong>
                </div>
            </field>
        </field>
    </record>

    <record id="hr_employee_attendance_action_kanban" model="ir.actions.act_window">
        <field name="name">Employees</field>
        <field name="res_model">hr.employee</field>
        <field name="view_mode">kanban,tree,activity</field>
        <field name="view_id" ref="hr_employees_view_kanban"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create a new employee
            </p><p>
                Add a few employees to be able to select an employee here and perform his check in / check out.
                To create employees go to the Employees menu.
            </p>
        </field>
    </record>

</odoo>
