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

    <record id="event_event_view_form" model="ir.ui.view">
        <field name="name">event.event.view.form.inherit.website</field>
        <field name="model">event.event</field>
        <field name="priority" eval="5"/>
        <field name="inherit_id" ref="event.view_event_form"/>
        <field name="arch" type="xml">
            <xpath expr="//group[@name='right_event_details']/field[@name='company_id']" position="after">
                <field name="website_id" invisible="1"/>
                <field name="website_id" options="{'no_create': True}" domain="['|', ('company_id', '=', False), ('company_id', '=', company_id)]" groups="website.group_multi_website"/>
            </xpath>
            <xpath expr="//field[@name='tag_ids']" position="attributes">
                <attribute name="context">{'default_website_id': website_id}</attribute>
                <attribute name="groups">website.group_multi_website</attribute>
            </xpath>
            <div name="button_box" position="inside">
                <field name="website_url" invisible="1"/>
                <field name="is_published" widget="website_redirect_button"/>
            </div>
            <xpath expr="//div[hasclass('oe_title')]" position="after">
                <div name="event_menu_configuration" groups="base.group_no_one">
                    <label for="website_menu" string="Website Submenu"/>
                    <field name="website_menu"/>
                    <!-- hidden sub-menus, they are triggered all at once based on "website_menu" -->
                    <field name="introduction_menu" invisible="1"/>
                    <field name="location_menu" invisible="1"/>
                    <field name="register_menu" invisible="1"/>
                    <label for="menu_register_cta" string="Extra Register Button"/>
                    <field name="menu_register_cta"/>
                    <label for="community_menu" string="Community" invisible="1"/>
                    <field name="community_menu" invisible="1"/>
                </div>
            </xpath>
            <page name="event_notes" position="before">
                <page string="Questions" name="questions">
                    <field name="question_ids" string="Question" nolabel="1">
                        <tree>
                            <field name="sequence" widget="handle" />
                            <field name="title"/>
                            <field name="is_mandatory_answer" string="Mandatory"/>
                            <field name="once_per_order" string="Once per Order"/>
                            <field name="question_type" string="Type" />
                            <field name="answer_ids" widget="many2many_tags"
                                invisible="question_type != 'simple_choice'" />
                            <button name="action_view_question_answers" type="object" class="p-0" icon="fa-bar-chart pe-1" string="Stats"
                                    title="Answer Breakdown" invisible="question_type not in ['simple_choice', 'text_box']"/>
                        </tree>
                        <!-- Need to repeat the whole tree form here to be able to create answers properly
                            Without this, the sub-fields of answer_ids are unknown to the web framework.
                            We need this because we create questions and answers when the event type changes. -->
                        <form string="Question">
                            <sheet>
                                <h1 class="d-flex"><field name="title" placeholder='e.g. "Do you have any diet restrictions?"' class="flex-grow-1"/></h1>
                                <group>
                                    <group>
                                        <field name="is_mandatory_answer"/>
                                        <field name="question_type" widget="radio"/>
                                    </group>
                                    <group>
                                        <field name="once_per_order"/>
                                    </group>
                                </group>
                                <notebook invisible="question_type != 'simple_choice'">
                                    <page string="Answers" name="answers">
                                        <field name="answer_ids">
                                            <tree editable="bottom">
                                                <!-- 'display_name' is necessary for the many2many_tags to work on the event view -->
                                                <field name="display_name" column_invisible="True" />
                                                <field name="sequence" widget="handle" />
                                                <field name="name"/>
                                            </tree>
                                        </field>
                                    </page>
                                </notebook>
                            </sheet>
                        </form>
                    </field>
                </page>
            </page>
              
            <field name="tag_ids" position="attributes">
                <attribute name="domain">['|', ('category_id.website_id', '=', website_id), ('category_id.website_id', '=', False)]</attribute>
                <attribute name="invisible">not website_id</attribute>
            </field>

            <field name="tag_ids" position="after">
                <field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color', 'no_quick_create': True}" invisible="website_id"></field>
            </field>
            
        </field>
    </record>

    <record id="event_event_view_list" model="ir.ui.view">
        <field name="name">event.event.view.list.inherit.website</field>
        <field name="model">event.event</field>
        <field name="inherit_id" ref="event.view_event_tree"/>
        <field name="arch" type="xml">
            <field name="company_id" position="after">
                <field name="company_id" column_invisible="True"/>
                <field name="website_id" groups="website.group_multi_website" domain="['|', ('company_id', '=', company_id), ('company_id', '=', False)]" optional="show"/>
            </field>
        </field>
    </record>

    <record id="event_event_view_search" model="ir.ui.view">
        <field name="name">event.event.search.inherit.website</field>
        <field name="model">event.event</field>
        <field name="inherit_id" ref="event.view_event_search"/>
        <field name="arch" type="xml">
            <xpath expr="//filter[@name='upcoming']" position="after">
                <separator/>
                <filter string="Published" name="filter_published" domain="[('website_published', '=', True)]"/>
            </xpath>
        </field>
    </record>
</odoo>
