<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Tree View -->
    <record id="view_restaurant_reservation_tree" model="ir.ui.view">
        <field name="name">restaurant.reservation.tree</field>
        <field name="model">restaurant.reservation</field>
        <field name="arch" type="xml">
            <tree string="Reservations" decoration-info="state == 'draft'" decoration-success="state == 'confirmed'" decoration-muted="state == 'completed'">
                <field name="name"/>
                <field name="customer_name"/>
                <field name="phone"/>
                <field name="floor_id"/>
                <field name="table_ids" widget="many2many_tags"/>
                <field name="start_time"/>
                <field name="end_time"/>
                <field name="num_people"/>
                <field name="state" widget="badge" decoration-info="state == 'draft'" decoration-success="state == 'confirmed'"/>
            </tree>
        </field>
    </record>

    <!-- Form View -->
    <record id="view_restaurant_reservation_form" model="ir.ui.view">
        <field name="name">restaurant.reservation.form</field>
        <field name="model">restaurant.reservation</field>
        <field name="arch" type="xml">
            <form string="Reservation">
                <header>
                    <button name="action_confirm" string="Confirm" type="object" class="oe_highlight" invisible="state != 'draft'"/>
                    <button name="action_complete" string="Mark Completed" type="object" invisible="state != 'confirmed'"/>
                    <button name="action_cancel" string="Cancel" type="object" invisible="state not in ['draft', 'confirmed']"/>
                    <field name="state" widget="statusbar" statusbar_visible="draft,confirmed,completed"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <field name="whatsapp_url" invisible="1"/>
                        <button name="action_whatsapp" type="object" class="oe_stat_button" icon="fa-whatsapp" string="WhatsApp" invisible="not whatsapp_url"/>
                    </div>
                    <div class="oe_title">
                        <h1>
                            <field name="name"/>
                        </h1>
                    </div>
                    <group>
                        <group string="Customer Information">
                            <field name="customer_name"/>
                            <field name="phone"/>
                            <field name="email"/>
                            <field name="num_people"/>
                            <field name="is_admin_override"/>
                            <field name="override_reason" invisible="not is_admin_override" required="is_admin_override"/>
                            <field name="overridden_by_id" invisible="not is_admin_override"/>
                        </group>
                        <group string="Reservation Details">
                            <field name="floor_id"/>
                            <field name="table_ids" widget="many2many_tags" domain="[('floor_id', '=', floor_id)]"/>
                            <field name="start_time"/>
                            <field name="end_time"/>
                        </group>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- Search View -->
    <record id="view_restaurant_reservation_search" model="ir.ui.view">
        <field name="name">restaurant.reservation.search</field>
        <field name="model">restaurant.reservation</field>
        <field name="arch" type="xml">
            <search>
                <field name="name"/>
                <field name="customer_name"/>
                <field name="phone"/>
                <field name="table_ids"/>
                <filter string="Draft" name="draft" domain="[('state', '=', 'draft')]"/>
                <filter string="Confirmed" name="confirmed" domain="[('state', '=', 'confirmed')]"/>
                <filter string="Completed" name="completed" domain="[('state', '=', 'completed')]"/>
                <group expand="0" string="Group By">
                    <filter string="Status" name="group_by_status" context="{'group_by': 'state'}"/>
                    <filter string="Date" name="group_by_date" context="{'group_by': 'start_time'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Action -->
    <record id="action_restaurant_reservation" model="ir.actions.act_window">
        <field name="name">Table Reservations</field>
        <field name="type">ir.actions.act_window</field>
        <field name="res_model">restaurant.reservation</field>
        <field name="view_mode">tree,form</field>
        <field name="search_view_id" ref="view_restaurant_reservation_search"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create your first table reservation!
            </p>
        </field>
    </record>
</odoo>
