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

    <!-- ============================================================ -->
    <!-- SECTION TREE VIEW                                             -->
    <!-- ============================================================ -->
    <record id="view_wc_section_tree" model="ir.ui.view">
        <field name="name">fusion.wc.section.tree</field>
        <field name="model">fusion.wc.section</field>
        <field name="arch" type="xml">
            <list>
                <field name="sequence" widget="handle"/>
                <field name="name"/>
                <field name="code"/>
                <field name="parent_id"/>
                <field name="equipment_type"/>
                <field name="has_build_type"/>
                <field name="is_adp_options_section"/>
                <field name="option_count" string="Options"/>
                <field name="active" column_invisible="1"/>
            </list>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- SECTION OPTION ACTION (for stat button — must be before form) -->
    <!-- ============================================================ -->
    <record id="action_wc_section_option" model="ir.actions.act_window">
        <field name="name">Section Options</field>
        <field name="res_model">fusion.wc.section.option</field>
        <field name="view_mode">list,form</field>
        <field name="context">{'default_section_id': active_id}</field>
        <field name="domain">[('section_id', '=', active_id)]</field>
    </record>

    <!-- ============================================================ -->
    <!-- SECTION FORM VIEW                                             -->
    <!-- ============================================================ -->
    <record id="view_wc_section_form" model="ir.ui.view">
        <field name="name">fusion.wc.section.form</field>
        <field name="model">fusion.wc.section</field>
        <field name="arch" type="xml">
            <form string="Wheelchair Section">
                <header>
                    <button name="action_auto_populate_options"
                        string="Auto-Populate Products from Inventory"
                        type="object" class="btn-secondary"
                        icon="fa-magic"
                        confirm="This will scan your product inventory for ADP device codes matching this section and add them as options. Continue?"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button name="%(fusion_quotations.action_wc_section_option)d"
                            type="action" class="oe_stat_button" icon="fa-list"
                            context="{'default_section_id': id, 'search_default_section_id': id}">
                            <field name="option_count" widget="statinfo" string="Options"/>
                        </button>
                    </div>
                    <widget name="web_ribbon" title="Archived" bg_color="text-bg-danger"
                        invisible="active"/>
                    <div class="oe_title">
                        <h1>
                            <field name="name" placeholder="Section Name"/>
                        </h1>
                    </div>
                    <group>
                        <group>
                            <field name="code"/>
                            <field name="sequence"/>
                            <field name="parent_id"/>
                            <field name="equipment_type"/>
                            <field name="icon" placeholder="fa-wheelchair"/>
                            <field name="product_category_id"/>
                        </group>
                        <group>
                            <field name="required"/>
                            <field name="allow_multiple"/>
                            <field name="is_adp_options_section"/>
                            <field name="has_build_type"/>
                            <field name="active"/>
                        </group>
                    </group>
                    <group string="Measurement Fields" col="4">
                        <field name="has_width"/>
                        <field name="width_label" invisible="not has_width"/>
                        <field name="has_depth"/>
                        <field name="depth_label" invisible="not has_depth"/>
                        <field name="has_height"/>
                        <field name="height_label" invisible="not has_height"/>
                        <field name="has_length"/>
                        <field name="length_label" invisible="not has_length"/>
                    </group>
                    <field name="description" placeholder="Help text for sales reps..."/>
                    <notebook>
                        <page string="Product Options" name="options">
                            <field name="option_ids">
                                <list editable="bottom">
                                    <field name="sequence" widget="handle"/>
                                    <field name="product_tmpl_id"/>
                                    <field name="variant_count" string="Variants"/>
                                    <field name="is_standard"/>
                                    <field name="adp_device_code"/>
                                    <field name="adp_price"/>
                                    <field name="list_price"/>
                                    <field name="available_build_types"/>
                                    <field name="requires_clinical_rationale"/>
                                </list>
                            </field>
                        </page>
                        <page string="Sub-Sections" name="children">
                            <field name="child_ids">
                                <list>
                                    <field name="sequence" widget="handle"/>
                                    <field name="name"/>
                                    <field name="code"/>
                                    <field name="has_build_type"/>
                                    <field name="option_count" string="Options"/>
                                </list>
                            </field>
                        </page>
                    </notebook>
                </sheet>
            </form>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- SECTION ACTION                                                -->
    <!-- ============================================================ -->
    <record id="action_wc_section" model="ir.actions.act_window">
        <field name="name">Wheelchair Sections</field>
        <field name="res_model">fusion.wc.section</field>
        <field name="view_mode">list,form</field>
        <field name="context">{'search_default_active': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Configure wheelchair sections
            </p>
            <p>
                Define sections like Frame, Cushion, Backrest, etc.
                and add product options to each section.
            </p>
        </field>
    </record>

</odoo>
