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

    <!-- Location Form View -->
    <record id="view_fusion_clock_location_form" model="ir.ui.view">
        <field name="name">fusion.clock.location.form</field>
        <field name="model">fusion.clock.location</field>
        <field name="arch" type="xml">
            <form string="Clock Location">
                <header>
                    <button name="action_geocode_address" type="object"
                            string="Geocode Address" class="btn-primary"
                            icon="fa-map-marker"
                            confirm="This will update latitude/longitude from the address using Google Maps API."/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="action_view_attendances" type="object"
                                class="oe_stat_button" icon="fa-clock-o">
                            <field name="attendance_count" widget="statinfo" string="Attendances"/>
                        </button>
                    </div>
                    <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger" invisible="active"/>
                    <div class="oe_title">
                        <label for="name"/>
                        <h1>
                            <field name="name" placeholder="e.g. Main Office"/>
                        </h1>
                    </div>
                    <group>
                        <group string="Address">
                            <field name="address" widget="fclk_places_autocomplete"
                                   placeholder="Start typing an address..."/>
                            <field name="timezone"/>
                        </group>
                        <group string="Geofence">
                            <field name="latitude"/>
                            <field name="longitude"/>
                            <field name="radius"/>
                            <field name="color" widget="color"/>
                        </group>
                    </group>
                    <group>
                        <group string="Access">
                            <field name="all_employees"/>
                            <field name="employee_ids" widget="many2many_tags"
                                   invisible="all_employees"/>
                        </group>
                        <group string="Verification">
                            <field name="require_photo"/>
                        </group>
                    </group>
                    <group>
                        <group string="IP Whitelist">
                            <div colspan="2">
                                <button name="action_detect_ip" type="object"
                                        string="Detect My IP" class="btn-secondary mb-2"
                                        icon="fa-crosshairs"
                                        title="Detect your current public IP and add it to the whitelist"/>
                            </div>
                            <field name="ip_whitelist" nolabel="1" colspan="2"
                                   placeholder="One IP or CIDR per line, e.g.&#10;192.168.1.0/24&#10;10.0.0.100"/>
                        </group>
                        <group string="Other">
                            <field name="company_id" groups="base.group_multi_company"/>
                            <field name="active" invisible="1"/>
                            <field name="sequence"/>
                        </group>
                    </group>

                    <!-- Interactive Map Preview -->
                    <group string="Map Preview">
                        <field name="map_url" widget="fclk_location_map" nolabel="1" colspan="2"/>
                    </group>

                    <group string="Notes">
                        <field name="note" nolabel="1" colspan="2" placeholder="Additional notes about this location..."/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Location List View -->
    <record id="view_fusion_clock_location_list" model="ir.ui.view">
        <field name="name">fusion.clock.location.list</field>
        <field name="model">fusion.clock.location</field>
        <field name="arch" type="xml">
            <list string="Clock Locations" default_order="sequence, name">
                <field name="sequence" widget="handle"/>
                <field name="name"/>
                <field name="address"/>
                <field name="radius" string="Radius (m)"/>
                <field name="all_employees"/>
                <field name="attendance_count" string="Attendances"/>
                <field name="company_id" groups="base.group_multi_company"/>
                <field name="active" column_invisible="True"/>
            </list>
        </field>
    </record>

    <!-- Location Search View -->
    <record id="view_fusion_clock_location_search" model="ir.ui.view">
        <field name="name">fusion.clock.location.search</field>
        <field name="model">fusion.clock.location</field>
        <field name="arch" type="xml">
            <search string="Search Locations">
                <field name="name"/>
                <field name="address"/>
                <filter name="active" string="Active" domain="[('active', '=', True)]"/>
                <filter name="archived" string="Archived" domain="[('active', '=', False)]"/>
                <separator/>
                <filter name="all_employees" string="All Employees" domain="[('all_employees', '=', True)]"/>
                <separator/>
                <filter name="group_company" string="Company" context="{'group_by': 'company_id'}"/>
            </search>
        </field>
    </record>

    <!-- Location Action -->
    <record id="action_fusion_clock_location" model="ir.actions.act_window">
        <field name="name">Clock Locations</field>
        <field name="res_model">fusion.clock.location</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="view_fusion_clock_location_search"/>
        <field name="context">{'search_default_active': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create your first clock location
            </p>
            <p>
                Define geofenced locations where employees can clock in and out.
                Set the address, radius, and which employees are allowed.
            </p>
        </field>
    </record>

</odoo>
