<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <record id="mail_group_message_view_list" model="ir.ui.view">
        <field name="name">mail.group.message.view.list</field>
        <field name="model">mail.group.message</field>
        <field name="arch" type="xml">
            <tree sample="1">
                <field name="create_date" string="Date"/>
                <field name="author_id"/>
                <field name="email_from"/>
                <field name="subject"/>
                <field name="mail_group_id"/>
                <field name="moderation_status"/>
                <field name="is_group_moderated" invisible="1"/>
                <button name="action_moderate_accept" string="Accept" title="Accept"
                    type="object" class="btn btn-primary"
                    attrs="{'invisible': ['|', ('moderation_status', '!=', 'pending_moderation'), ('is_group_moderated', '=', False)]}"/>
                <button name="%(mail_group_message_reject_action)d"
                    string="Reject" title="Remove message with explanation"
                    type="action" class="btn btn-secondary"
                    attrs="{'invisible': ['|', ('moderation_status', '!=', 'pending_moderation'), ('is_group_moderated', '=', False)]}"
                    context="{'default_mail_group_message_id': id, 'default_action': 'reject'}" />
                <button name="action_moderate_allow" string="Whitelist"
                    title="Add this email address to white list of people and accept all pending messages from the same author."
                    type="object" class="btn btn-secondary"
                    attrs="{'invisible': ['|', ('moderation_status', '!=', 'pending_moderation'), ('is_group_moderated', '=', False)]}"/>
                <button name="%(mail_group_message_reject_action)d"
                    string="Ban" title="Ban this email address and reject all pending messages from the same author and send an email to the author"
                    type="action" class="btn btn-secondary"
                    attrs="{'invisible': ['|', ('moderation_status', '!=', 'pending_moderation'), ('is_group_moderated', '=', False)]}"
                    context="{'default_mail_group_message_id': id, 'default_action': 'ban'}" />
                <button name="action_moderate_accept" string="Send" title="Send"
                    type="object" class="btn btn-primary"
                    attrs="{'invisible': ['|', ('moderation_status', '!=', 'pending_moderation'), ('is_group_moderated', '=', True)]}"/>
            </tree>
        </field>
    </record>
    <record id="mail_group_message_view_form" model="ir.ui.view">
        <field name="name">mail.group.message.view.form</field>
        <field name="model">mail.group.message</field>
        <field name="arch" type="xml">
            <form string="Group Message" class="o_mail_group_message_form">
                <header>
                    <button name="action_moderate_accept" string="Accept" title="Accept"
                        type="object" class="btn btn-primary"
                        attrs="{'invisible': ['|', ('moderation_status', '!=', 'pending_moderation'), ('is_group_moderated', '=', False)]}"/>
                    <button name="%(mail_group_message_reject_action)d"
                        string="Reject" title="Remove message with explanation"
                        type="action" class="btn btn-secondary"
                        attrs="{'invisible': ['|', ('moderation_status', '!=', 'pending_moderation'), ('is_group_moderated', '=', False)]}"
                        context="{'default_mail_group_message_id': id, 'default_action': 'reject'}" />
                    <button name="action_moderate_allow" string="Whitelist"
                        title="Add this email address to white list of people and accept all pending messages from the same author."
                        type="object" class="btn btn-secondary"
                        attrs="{'invisible': [('is_group_moderated', '=', False)]}"/>
                    <button name="%(mail_group_message_reject_action)d"
                        string="Ban" title="Ban this email address and reject all pending messages from the same author and send an email to the author"
                        type="action" class="btn btn-secondary"
                        attrs="{'invisible': ['|', ('moderation_status', '!=', 'pending_moderation'), ('is_group_moderated', '=', False)]}"
                        context="{'default_mail_group_message_id': id, 'default_action': 'ban'}" />
                    <button name="action_moderate_accept" string="Send" title="Send"
                        type="object" class="btn btn-primary"
                        attrs="{'invisible': ['|', ('moderation_status', '!=', 'pending_moderation'), ('is_group_moderated', '=', True)]}"/>
                </header>
                <sheet>
                    <widget name="web_ribbon" title="Rejected" bg_color="bg-danger"
                        attrs="{'invisible': [('moderation_status', '!=', 'rejected')]}"/>
                    <widget name="web_ribbon" title="Accepted" bg_color="bg-success"
                        attrs="{'invisible': [('moderation_status', '!=', 'accepted')]}"/>
                    <group>
                        <field name="mail_message_id" invisible="1"/>
                        <field name="moderation_status" invisible="1"/>
                        <field name="is_group_moderated" invisible="1"/>
                        <field name="subject"/>
                        <field name="author_id"/>
                        <label for="email_from" string="From"/>
                        <div>
                            <field name="email_from" nolabel="1"/>
                            <span class="oe_read_only ml-2 badge badge-success" attrs="{'invisible': [('author_moderation', '!=', 'allow')]}">Whitelisted</span>
                            <span class="oe_read_only ml-2 badge badge-danger" attrs="{'invisible': [('author_moderation', '!=', 'ban')]}">Banned</span>
                            <field name="author_moderation" invisible="1"/>
                        </div>
                        <field name="mail_group_id"/>
                        <field name="attachment_ids" widget="many2many_binary"/>
                        <field name="body" options="{'style-inline': true}"/>
                    </group>
                </sheet>
            </form>
        </field>
    </record>
    <record id="mail_group_message_view_search" model="ir.ui.view">
        <field name="name">mail.group.message.view.search</field>
        <field name="model">mail.group.message</field>
        <field name="arch" type="xml">
            <search string="Search Group Message">
                <field name="mail_group_id"/>
                <field name="email_from"/>
                <field name="author_id"/>
                <field name="moderation_status"/>
                <separator/>
                <group expand="0" string="Group By">
                    <filter string="group" name="group_by_group" context="{'group_by': 'mail_group_id'}"/>
                </group>
            </search>
        </field>
    </record>
    <record id="mail_group_message_action" model="ir.actions.act_window">
        <field name="name">Messages</field>
        <field name="res_model">mail.group.message</field>
        <field name="view_mode">tree,form</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">No Messages in this list yet!</p>
            <p>When people send an email to the alias of the list, they will appear here.</p>
        </field>
    </record>
</odoo>
