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

    <!-- ============================================================ -->
    <!-- TAX REMITTANCE FORM VIEW                                      -->
    <!-- ============================================================ -->
    <record id="hr_tax_remittance_view_form" model="ir.ui.view">
        <field name="name">hr.tax.remittance.form</field>
        <field name="model">hr.tax.remittance</field>
        <field name="arch" type="xml">
            <form string="Tax Remittance">
                <header>
                    <button name="action_calculate_amounts" 
                            string="Calculate Amounts" 
                            type="object" 
                            class="btn-primary"
                            invisible="state == 'paid'"/>
                    <button name="action_mark_paid" 
                            string="Mark as Paid" 
                            type="object" 
                            class="btn-success"
                            invisible="state == 'paid'"/>
                    <field name="state" widget="statusbar" 
                           statusbar_visible="draft,pending,due,paid"/>
                </header>
                <sheet>
                    <div class="oe_button_box" name="button_box">
                        <button type="object" class="oe_stat_button" 
                                name="action_view_payslips"
                                icon="fa-file-text-o"
                                invisible="payslip_count == 0">
                            <field name="payslip_count" widget="statinfo" string="Payslips"/>
                        </button>
                    </div>
                    
                    <!-- Status Ribbons -->
                    <widget name="web_ribbon" title="Paid" bg_color="text-bg-success" 
                            invisible="state != 'paid'"/>
                    <widget name="web_ribbon" title="Past Due" bg_color="text-bg-danger" 
                            invisible="state != 'past_due'"/>
                    <widget name="web_ribbon" title="Due Soon" bg_color="text-bg-warning" 
                            invisible="state != 'due'"/>

                    <div class="oe_title">
                        <h1>
                            <field name="name" readonly="1"/>
                        </h1>
                    </div>

                    <!-- Period Info -->
                    <group>
                        <group string="Period">
                            <field name="company_id" readonly="state == 'paid'"/>
                            <field name="period_type"/>
                            <field name="period_start"/>
                            <field name="period_end"/>
                            <field name="due_date"/>
                        </group>
                        <group string="Payment">
                            <field name="payment_date"/>
                            <field name="payment_method"/>
                            <field name="payment_reference"/>
                        </group>
                    </group>

                    <notebook>
                        <page string="Remittance Details" name="details">
                            
                            <!-- CPP Section -->
                            <group string="Canada Pension Plan (CPP)">
                                <group>
                                    <field name="cpp_employee" widget="monetary"/>
                                    <field name="cpp_employer" widget="monetary"/>
                                </group>
                                <group>
                                    <field name="cpp2_employee" widget="monetary"/>
                                    <field name="cpp2_employer" widget="monetary"/>
                                </group>
                            </group>

                            <!-- EI Section -->
                            <group string="Employment Insurance (EI)">
                                <group>
                                    <field name="ei_employee" widget="monetary"/>
                                </group>
                                <group>
                                    <field name="ei_employer" widget="monetary"/>
                                </group>
                            </group>

                            <!-- Tax Section -->
                            <group string="Income Tax">
                                <group>
                                    <field name="income_tax" widget="monetary"/>
                                </group>
                            </group>

                            <group>
                                <group string="Total">
                                    <field name="total" widget="monetary" class="fw-bold fs-4"/>
                                </group>
                            </group>

                        </page>

                        <page string="Payslips" name="payslips">
                            <field name="payslip_ids">
                                <list>
                                    <field name="employee_id"/>
                                    <field name="name"/>
                                    <field name="date_from"/>
                                    <field name="date_to"/>
                                    <field name="net_wage" widget="monetary"/>
                                    <field name="state"/>
                                </list>
                            </field>
                        </page>
                    </notebook>

                    <field name="currency_id" invisible="1"/>
                </sheet>
                <chatter/>
            </form>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- TAX REMITTANCE LIST VIEW                                      -->
    <!-- ============================================================ -->
    <record id="hr_tax_remittance_view_list" model="ir.ui.view">
        <field name="name">hr.tax.remittance.list</field>
        <field name="model">hr.tax.remittance</field>
        <field name="arch" type="xml">
            <list string="Tax Remittances"
                  decoration-danger="state == 'past_due'"
                  decoration-warning="state == 'due'"
                  decoration-success="state == 'paid'"
                  decoration-muted="state == 'draft'">
                <field name="name"/>
                <field name="period_start"/>
                <field name="period_end"/>
                <field name="due_date"/>
                <field name="total" widget="monetary" sum="Total"/>
                <field name="payment_date"/>
                <field name="state" widget="badge"
                       decoration-danger="state == 'past_due'"
                       decoration-warning="state == 'due'"
                       decoration-success="state == 'paid'"/>
                <field name="currency_id" column_invisible="1"/>
            </list>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- TAX REMITTANCE KANBAN VIEW                                    -->
    <!-- ============================================================ -->
    <record id="hr_tax_remittance_view_kanban" model="ir.ui.view">
        <field name="name">hr.tax.remittance.kanban</field>
        <field name="model">hr.tax.remittance</field>
        <field name="arch" type="xml">
            <kanban class="o_kanban_mobile" default_group_by="state">
                <field name="name"/>
                <field name="period_start"/>
                <field name="period_end"/>
                <field name="due_date"/>
                <field name="total"/>
                <field name="state"/>
                <field name="currency_id"/>
                <templates>
                    <t t-name="card">
                        <div class="oe_kanban_content">
                            <div class="o_kanban_record_top mb-2">
                                <div class="o_kanban_record_headings">
                                    <strong class="o_kanban_record_title">
                                        <field name="name"/>
                                    </strong>
                                </div>
                                <field name="state" widget="label_selection" 
                                       options="{'classes': {'draft': 'secondary', 'pending': 'info', 'due': 'warning', 'past_due': 'danger', 'paid': 'success'}}"/>
                            </div>
                            <div class="o_kanban_record_body">
                                <div>
                                    <span t-out="record.period_start.value"/> - <span t-out="record.period_end.value"/>
                                </div>
                                <div class="text-muted">
                                    Due: <field name="due_date"/>
                                </div>
                            </div>
                            <div class="o_kanban_record_bottom">
                                <div class="oe_kanban_bottom_left">
                                    <strong class="fs-5">
                                        <field name="total" widget="monetary"/>
                                    </strong>
                                </div>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- TAX REMITTANCE SEARCH VIEW                                    -->
    <!-- ============================================================ -->
    <record id="hr_tax_remittance_view_search" model="ir.ui.view">
        <field name="name">hr.tax.remittance.search</field>
        <field name="model">hr.tax.remittance</field>
        <field name="arch" type="xml">
            <search string="Search Tax Remittances">
                <field name="name"/>
                <field name="period_start"/>
                <field name="period_end"/>
                <filter name="filter_paid" string="Paid" domain="[('state', '=', 'paid')]"/>
                <filter name="filter_draft" string="Draft" domain="[('state', '=', 'draft')]"/>
                <filter name="group_state" string="Status" context="{'group_by': 'state'}"/>
            </search>
        </field>
    </record>

    <!-- ============================================================ -->
    <!-- TAX REMITTANCE ACTION                                         -->
    <!-- ============================================================ -->
    <record id="hr_tax_remittance_action" model="ir.actions.act_window">
        <field name="name">Tax Remittances</field>
        <field name="res_model">hr.tax.remittance</field>
        <field name="view_mode">kanban,list,form</field>
        <field name="context">{}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                Create your first tax remittance
            </p>
            <p>
                Track CPP, EI, and income tax remittances to CRA.
                The system can calculate amounts automatically from confirmed payslips.
            </p>
        </field>
    </record>

    <!-- Menus moved to fusion_payroll_menus.xml -->

    <!-- ============================================================ -->
    <!-- TAX REMITTANCE SEQUENCE                                       -->
    <!-- ============================================================ -->
    <record id="sequence_hr_tax_remittance" model="ir.sequence">
        <field name="name">Tax Remittance Sequence</field>
        <field name="code">hr.tax.remittance</field>
        <field name="prefix">REM-%(year)s-</field>
        <field name="padding">4</field>
        <field name="company_id" eval="False"/>
    </record>

</odoo>
