<?xml version="1.0" encoding="UTF-8"?>
<odoo>
    <!-- ================================================================= -->
    <!-- DASHBOARD ACTION -->
    <!-- ================================================================= -->
    <record id="action_fusion_accounts_dashboard" model="ir.actions.act_window">
        <field name="name">Dashboard</field>
        <field name="res_model">fusion.accounts.log</field>
        <field name="view_mode">kanban,list,form</field>
        <field name="context">{'search_default_filter_date': 1, 'search_default_group_action': 1}</field>
        <field name="search_view_id" ref="view_fusion_accounts_log_search"/>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Fusion Accounts Dashboard
            </p>
            <p>
                Email processing activity will appear here.
                Configure your email aliases and AI settings under Configuration.
            </p>
        </field>
    </record>

    <!-- ================================================================= -->
    <!-- DASHBOARD KANBAN VIEW -->
    <!-- ================================================================= -->
    <record id="view_fusion_accounts_log_kanban" model="ir.ui.view">
        <field name="name">fusion.accounts.log.kanban</field>
        <field name="model">fusion.accounts.log</field>
        <field name="arch" type="xml">
            <kanban class="o_kanban_dashboard" create="0" edit="0"
                    group_create="0" group_delete="0" group_edit="0"
                    default_group_by="action_taken">
                <field name="email_from"/>
                <field name="email_subject"/>
                <field name="vendor_id"/>
                <field name="match_level"/>
                <field name="action_taken"/>
                <field name="bill_id"/>
                <field name="ai_extracted"/>
                <field name="create_date"/>
                <field name="vendor_blocked"/>
                <templates>
                    <t t-name="card">
                        <div class="d-flex flex-column">
                            <strong class="fs-5 mb-1">
                                <field name="email_subject"/>
                            </strong>
                            <div class="text-muted small mb-1">
                                <i class="fa fa-envelope-o me-1"/>
                                <field name="email_from"/>
                            </div>
                            <div class="d-flex align-items-center gap-2 mb-1">
                                <field name="match_level" widget="badge"
                                       decoration-info="match_level == 'exact_email'"
                                       decoration-success="match_level == 'domain'"
                                       decoration-warning="match_level == 'name'"
                                       decoration-danger="match_level == 'no_match'"/>
                                <span t-if="record.ai_extracted.raw_value" class="badge text-bg-primary">
                                    <i class="fa fa-magic me-1"/>AI
                                </span>
                            </div>
                            <div t-if="record.vendor_id.value" class="text-muted small">
                                <i class="fa fa-building-o me-1"/>
                                <field name="vendor_id"/>
                            </div>
                            <div t-if="record.bill_id.value" class="small mt-1">
                                <i class="fa fa-file-text-o me-1"/>
                                <field name="bill_id"/>
                            </div>
                            <div class="text-muted small mt-1">
                                <field name="create_date" widget="datetime"/>
                            </div>
                            <!-- Block/Enable buttons -->
                            <div t-if="record.vendor_id.value" class="mt-2 d-flex gap-1">
                                <button t-if="!record.vendor_blocked.raw_value"
                                        name="action_block_vendor" type="object"
                                        class="btn btn-sm btn-outline-danger">
                                    <i class="fa fa-ban me-1"/>Block Vendor
                                </button>
                                <button t-if="record.vendor_blocked.raw_value"
                                        name="action_enable_vendor" type="object"
                                        class="btn btn-sm btn-outline-success">
                                    <i class="fa fa-check me-1"/>Enable Vendor
                                </button>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>
</odoo>
