<odoo>
    <!-- KDS Kanban View -->
    <record id="view_pos_order_line_kds_kanban" model="ir.ui.view">
        <field name="name">pos.order.line.kds.kanban</field>
        <field name="model">pos.order.line</field>
        <field name="arch" type="xml">
            <kanban js_class="kds_kanban" default_group_by="preparation_status" create="false" class="o_kanban_small_column o_kanban_project_tasks">
                <field name="preparation_status"/>
                <field name="color"/>
                <field name="product_id"/>
                <field name="qty"/>
                <field name="order_id"/>
                <field name="table_id"/>
                <field name="floor_id"/>
                <field name="order_source"/>
                <field name="fulfilment_type"/>
                <field name="customer_note"/>
                <field name="create_date"/>
                <templates>
                    <t t-name="kanban-box">
                        <div t-attf-class="oe_kanban_global_click role_kitchen_card #{'oe_kanban_color_' + kanban_getcolor(record.color.raw_value)} shadow-sm border-0 mb-3" style="border-radius: 12px; border-left: 5px solid #fecd4f !important;">
                            <div class="oe_kanban_content p-3">
                                <div class="o_kanban_record_top mb-2">
                                    <div class="o_kanban_record_headings">
                                        <strong class="o_kanban_record_title" style="font-size: 1.2rem; color: #171422;">
                                            <field name="qty"/> x <field name="product_id"/>
                                        </strong>
                                    </div>
                                    <div class="ms-auto h5 mb-0">
                                        <span t-if="record.table_id.raw_value" class="badge rounded-pill bg-light text-dark border">
                                            <i class="fa fa-map-marker me-1" title="Table"/> <field name="table_id"/>
                                        </span>
                                    </div>
                                </div>
                                
                                <t t-if="record.customer_note.raw_value">
                                    <div class="alert alert-warning py-2 px-3 mb-3 border-0" role="status" style="background: rgba(254, 205, 79, 0.1); border-radius: 8px;">
                                        <i class="fa fa-sticky-note-o me-2" title="Note"/> <strong>Note:</strong> <field name="customer_note"/>
                                    </div>
                                </t>

                                <div class="o_kanban_record_body small text-muted mb-3">
                                    <div class="d-flex justify-content-between align-items-center mb-1">
                                        <span><i class="fa fa-clock-o me-1" title="Time"/> <field name="create_date"/></span>
                                        <span class="text-uppercase fw-bold" style="font-size: 0.7rem;"><field name="floor_id"/></span>
                                    </div>
                                    <div class="d-flex justify-content-between align-items-center">
                                        <span t-if="record.order_source.raw_value" class="badge bg-info-light text-info border-info" style="font-size: 0.65rem; background: rgba(23, 162, 184, 0.1);">
                                            <i class="fa fa-plug me-1" title="Source"/> <field name="order_source"/>
                                        </span>
                                        <span t-if="record.fulfilment_type.raw_value" class="badge bg-warning-light text-warning border-warning" style="font-size: 0.65rem; background: rgba(254, 205, 79, 0.1);">
                                            <i class="fa fa-truck me-1" title="Fulfilment"/> <field name="fulfilment_type"/>
                                        </span>
                                    </div>
                                </div>

                                <div class="o_kanban_record_bottom border-top pt-3 mt-2">
                                    <div class="oe_kanban_bottom_left">
                                        <field name="preparation_status" widget="badge" decoration-warning="preparation_status == 'waiting'" decoration-info="preparation_status == 'preparing'" decoration-success="preparation_status == 'ready'" decoration-muted="preparation_status == 'served'"/>
                                    </div>
                                    <div class="oe_kanban_bottom_right">
                                        <button t-if="record.preparation_status.raw_value == 'waiting'" 
                                                name="action_start_preparing" type="object" 
                                                class="btn btn-sm btn-primary px-3 shadow-sm" style="background: #171422; border: none; border-radius: 8px;">
                                            Start Cooking
                                        </button>
                                        <button t-if="record.preparation_status.raw_value == 'preparing'" 
                                                name="action_mark_ready" type="object" 
                                                class="btn btn-sm btn-success px-3 shadow-sm" style="background: #28a745; border: none; border-radius: 8px;">
                                            Mark Ready
                                        </button>
                                        <button t-if="record.preparation_status.raw_value == 'ready' and record.customer_note.raw_value != 'Web Order'" 
                                                name="action_mark_served" type="object" 
                                                class="btn btn-sm btn-outline-dark px-3 shadow-sm" style="border-radius: 8px;">
                                            Served
                                        </button>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <!-- KDS Tree View -->
    <record id="view_pos_order_line_kds_tree" model="ir.ui.view">
        <field name="name">pos.order.line.kds.tree</field>
        <field name="model">pos.order.line</field>
        <field name="arch" type="xml">
            <tree string="Kitchen Orders" create="false" edit="false" decoration-info="preparation_status == 'preparing'" decoration-success="preparation_status == 'ready'" decoration-muted="preparation_status == 'served'">
                <field name="order_id"/>
                <field name="order_source" widget="badge"/>
                <field name="fulfilment_type" widget="badge"/>
                <field name="floor_id"/>
                <field name="table_id"/>
                <field name="product_id"/>
                <field name="qty"/>
                <field name="customer_note" string="Notes"/>
                <field name="preparation_status" widget="badge" decoration-info="preparation_status == 'preparing'" decoration-success="preparation_status == 'ready'" decoration-warning="preparation_status == 'waiting'"/>
                <field name="create_date" string="Ordered At" widget="remaining_days"/>
            </tree>
        </field>
    </record>

    <!-- KDS Search View -->
    <record id="view_pos_order_line_kds_search" model="ir.ui.view">
        <field name="name">pos.order.line.kds.search</field>
        <field name="model">pos.order.line</field>
        <field name="arch" type="xml">
            <search string="Kitchen Orders Search">
                <field name="order_id"/>
                <field name="product_id"/>
                <field name="table_id"/>
                <field name="floor_id"/>
                <separator/>
                <filter string="Waiting" name="waiting" domain="[('preparation_status', '=', 'waiting')]"/>
                <filter string="Preparing" name="preparing" domain="[('preparation_status', '=', 'preparing')]"/>
                <filter string="Ready" name="ready" domain="[('preparation_status', '=', 'ready')]"/>
                <filter string="In Progress" name="in_progress" domain="[('preparation_status', 'in', ['waiting', 'preparing'])]"/>
                <separator/>
                <filter string="Today" name="today" domain="[('create_date', '>=', context_today().strftime('%Y-%m-%d 00:00:00'))]"/>
                <group expand="0" string="Group By">
                    <filter string="Status" name="group_status" context="{'group_by': 'preparation_status'}"/>
                    <filter string="Table" name="group_table" context="{'group_by': 'table_id'}"/>
                    <filter string="Floor" name="group_floor" context="{'group_by': 'floor_id'}"/>
                </group>
            </search>
        </field>
    </record>

    <!-- Window Action -->
    <record id="action_kds_dashboard" model="ir.actions.act_window">
        <field name="name">Kitchen Display System</field>
        <field name="res_model">pos.order.line</field>
        <field name="view_mode">kanban,tree,form</field>
        <field name="domain">[('product_id.is_kitchen_item', '=', True), ('product_id.name', '!=', 'Water'), ('order_id.session_id.state', '!=', 'closed'), '|', ('product_id.pos_categ_ids', '=', False), ('product_id.pos_categ_ids.name', '!=', 'Drinks')]</field>
        <field name="search_view_id" ref="view_pos_order_line_kds_search"/>
        <field name="context">{'search_default_today': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Welcome to the Kitchen!
            </p>
            <p>
                Orders sent from the POS will appear here for preparation.
            </p>
        </field>
    </record>
</odoo>
