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

    <!-- ===== Tree View ===== -->
    <record id="woo_conflict_view_tree" model="ir.ui.view">
        <field name="name">woo.conflict.tree</field>
        <field name="model">woo.conflict</field>
        <field name="arch" type="xml">
            <list>
                <field name="instance_id"/>
                <field name="conflict_type"/>
                <field name="field_name"/>
                <field name="odoo_value"/>
                <field name="woo_value"/>
                <field name="resolution" widget="badge"
                       decoration-warning="resolution == 'pending'"
                       decoration-success="resolution != 'pending'"/>
            </list>
        </field>
    </record>

    <!-- ===== Form View ===== -->
    <record id="woo_conflict_view_form" model="ir.ui.view">
        <field name="name">woo.conflict.form</field>
        <field name="model">woo.conflict</field>
        <field name="arch" type="xml">
            <form>
                <header>
                    <button name="action_use_odoo" type="object"
                            string="Use Odoo Value" class="oe_highlight"
                            invisible="resolution != 'pending'"/>
                    <button name="action_use_woo" type="object"
                            string="Use WooCommerce Value"
                            invisible="resolution != 'pending'"/>
                    <field name="resolution" widget="statusbar"/>
                </header>
                <sheet>
                    <group>
                        <group string="Context">
                            <field name="instance_id"/>
                            <field name="conflict_type"/>
                            <field name="field_name"/>
                            <field name="company_id" groups="base.group_multi_company"/>
                        </group>
                        <group string="Values">
                            <field name="odoo_value"/>
                            <field name="woo_value"/>
                        </group>
                    </group>
                    <group string="Related Records">
                        <field name="map_id" invisible="conflict_type != 'product'"/>
                        <field name="customer_id" invisible="conflict_type != 'customer'"/>
                        <field name="order_id" invisible="conflict_type != 'order'"/>
                        <field name="resolved_by"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>

    <!-- ===== Search View ===== -->
    <record id="woo_conflict_view_search" model="ir.ui.view">
        <field name="name">woo.conflict.search</field>
        <field name="model">woo.conflict</field>
        <field name="arch" type="xml">
            <search>
                <field name="field_name"/>
                <filter name="pending" string="Pending"
                        domain="[('resolution', '=', 'pending')]"/>
                <filter name="resolved" string="Resolved"
                        domain="[('resolution', '!=', 'pending')]"/>
                <separator/>
                <filter name="group_type" string="Type"
                        context="{'group_by': 'conflict_type'}"/>
                <filter name="group_instance" string="Instance"
                        context="{'group_by': 'instance_id'}"/>
                <filter name="group_resolution" string="Resolution"
                        context="{'group_by': 'resolution'}"/>
            </search>
        </field>
    </record>

    <!-- ===== Action ===== -->
    <record id="action_woo_conflict" model="ir.actions.act_window">
        <field name="name">Sync Conflicts</field>
        <field name="res_model">woo.conflict</field>
        <field name="view_mode">list,form</field>
        <field name="search_view_id" ref="woo_conflict_view_search"/>
    </record>

</odoo>
