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

    <!-- ================================================================== -->
    <!-- CLEANUP - FORM VIEW                                                 -->
    <!-- ================================================================== -->
    <record id="view_ltc_cleanup_form" model="ir.ui.view">
        <field name="name">fusion.ltc.cleanup.form</field>
        <field name="model">fusion.ltc.cleanup</field>
        <field name="arch" type="xml">
            <form string="Cleanup Schedule">
                <header>
                    <button name="action_start" type="object" string="Start"
                            class="btn-primary"
                            invisible="state != 'scheduled'"/>
                    <button name="action_complete" type="object" string="Complete"
                            class="btn-primary"
                            invisible="state != 'in_progress'"/>
                    <button name="action_cancel" type="object" string="Cancel"
                            invisible="state in ('completed', 'cancelled')"/>
                    <button name="action_reset" type="object" string="Reset to Scheduled"
                            invisible="state not in ('cancelled', 'rescheduled')"/>
                    <field name="state" widget="statusbar"
                           statusbar_visible="scheduled,in_progress,completed"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="action_create_task" type="object"
                                class="oe_stat_button" icon="fa-tasks">
                            <div class="o_field_widget o_stat_info">
                                <span class="o_stat_text">Task</span>
                            </div>
                        </button>
                    </div>
                    <div class="oe_title">
                        <label for="name"/>
                        <h1>
                            <field name="name" readonly="1"/>
                        </h1>
                    </div>

                    <group>
                        <group string="Schedule">
                            <field name="facility_id"/>
                            <field name="scheduled_date"/>
                            <field name="completed_date"/>
                            <field name="technician_id"/>
                        </group>
                        <group string="Details">
                            <field name="items_cleaned"/>
                            <field name="task_id" readonly="1"/>
                        </group>
                    </group>

                    <notebook>
                        <page string="Notes" name="notes">
                            <field name="notes" placeholder="Cleanup notes..."/>
                        </page>
                        <page string="Photos" name="photos">
                            <field name="photo_ids" widget="many2many_binary"/>
                        </page>
                    </notebook>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <!-- ================================================================== -->
    <!-- CLEANUP - LIST VIEW                                                 -->
    <!-- ================================================================== -->
    <record id="view_ltc_cleanup_list" model="ir.ui.view">
        <field name="name">fusion.ltc.cleanup.list</field>
        <field name="model">fusion.ltc.cleanup</field>
        <field name="arch" type="xml">
            <list string="Cleanup Schedule" default_order="scheduled_date desc"
                  decoration-success="state == 'completed'"
                  decoration-muted="state in ('cancelled', 'rescheduled')">
                <field name="name"/>
                <field name="facility_id"/>
                <field name="scheduled_date"/>
                <field name="completed_date" optional="show"/>
                <field name="technician_id" widget="many2one_avatar_user" optional="show"/>
                <field name="items_cleaned" optional="show"/>
                <field name="state" widget="badge"
                       decoration-info="state == 'scheduled'"
                       decoration-warning="state == 'in_progress'"
                       decoration-success="state == 'completed'"
                       decoration-danger="state == 'cancelled'"
                       decoration-muted="state == 'rescheduled'"/>
            </list>
        </field>
    </record>

    <!-- ================================================================== -->
    <!-- CLEANUP - KANBAN VIEW                                               -->
    <!-- ================================================================== -->
    <record id="view_ltc_cleanup_kanban" model="ir.ui.view">
        <field name="name">fusion.ltc.cleanup.kanban</field>
        <field name="model">fusion.ltc.cleanup</field>
        <field name="arch" type="xml">
            <kanban default_group_by="state" class="o_kanban_small_column">
                <templates>
                    <t t-name="card">
                        <div class="d-flex justify-content-between">
                            <field name="name" class="fw-bold"/>
                        </div>
                        <div>
                            <field name="facility_id" class="fw-bold"/>
                        </div>
                        <div class="text-muted">
                            Scheduled: <field name="scheduled_date"/>
                        </div>
                        <div t-if="record.completed_date.raw_value" class="text-muted">
                            Completed: <field name="completed_date"/>
                        </div>
                        <footer class="mt-2">
                            <field name="technician_id" widget="many2one_avatar_user"/>
                        </footer>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <!-- ================================================================== -->
    <!-- CLEANUP - SEARCH VIEW                                               -->
    <!-- ================================================================== -->
    <record id="view_ltc_cleanup_search" model="ir.ui.view">
        <field name="name">fusion.ltc.cleanup.search</field>
        <field name="model">fusion.ltc.cleanup</field>
        <field name="arch" type="xml">
            <search string="Search Cleanups">
                <field name="facility_id"/>
                <field name="technician_id"/>
                <separator/>
                <filter string="Scheduled" name="filter_scheduled"
                        domain="[('state', '=', 'scheduled')]"/>
                <filter string="In Progress" name="filter_in_progress"
                        domain="[('state', '=', 'in_progress')]"/>
                <filter string="Completed" name="filter_completed"
                        domain="[('state', '=', 'completed')]"/>
                <separator/>
                <filter string="Upcoming (7 Days)" name="filter_upcoming"
                        domain="[('scheduled_date', '&lt;=', (context_today() + datetime.timedelta(days=7)).strftime('%Y-%m-%d')),
                                 ('scheduled_date', '>=', context_today().strftime('%Y-%m-%d')),
                                 ('state', '=', 'scheduled')]"/>
                <filter string="Overdue" name="filter_overdue"
                        domain="[('scheduled_date', '&lt;', context_today().strftime('%Y-%m-%d')),
                                 ('state', '=', 'scheduled')]"/>
                <separator/>
                <filter string="Facility" name="group_facility"
                        context="{'group_by': 'facility_id'}"/>
                <filter string="Status" name="group_state"
                        context="{'group_by': 'state'}"/>
                <filter string="Technician" name="group_technician"
                        context="{'group_by': 'technician_id'}"/>
                <filter string="Scheduled Month" name="group_month"
                        context="{'group_by': 'scheduled_date:month'}"/>
            </search>
        </field>
    </record>

    <!-- ================================================================== -->
    <!-- ACTIONS                                                             -->
    <!-- ================================================================== -->
    <record id="action_ltc_cleanups" model="ir.actions.act_window">
        <field name="name">Cleanup Schedule</field>
        <field name="res_model">fusion.ltc.cleanup</field>
        <field name="view_mode">list,kanban,form</field>
        <field name="search_view_id" ref="view_ltc_cleanup_search"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No cleanups scheduled yet
            </p>
            <p>Cleanups are auto-scheduled based on facility settings, or can be created manually.</p>
        </field>
    </record>

</odoo>
