<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <!-- Kanban View for Parameters Dashboard -->
    <record id="view_lims_analysis_parameter_kanban" model="ir.ui.view">
        <field name="name">lims.analysis.parameter.kanban</field>
        <field name="model">lims.analysis.parameter</field>
        <field name="arch" type="xml">
            <kanban class="o_kanban_mobile">
                <field name="code"/>
                <field name="name"/>
                <field name="value_type"/>
                <field name="unit"/>
                <field name="analysis_count"/>
                <field name="active"/>
                <templates>
                    <t t-name="kanban-box">
                        <div t-attf-class="oe_kanban_global_click">
                            <div class="o_kanban_record_top">
                                <div class="o_kanban_record_headings">
                                    <strong class="o_kanban_record_title">
                                        <field name="code"/> - <field name="name"/>
                                    </strong>
                                </div>
                            </div>
                            <div class="o_kanban_record_body">
                                <div class="text-muted">
                                    <span>Tipo: </span>
                                    <field name="value_type" widget="badge"/>
                                </div>
                                <div t-if="record.unit.raw_value" class="text-muted">
                                    <span>Unidad: </span>
                                    <field name="unit"/>
                                </div>
                            </div>
                            <div class="o_kanban_record_bottom">
                                <div class="oe_kanban_bottom_left">
                                    <span t-if="!record.active.raw_value" 
                                          class="badge badge-danger">Archivado</span>
                                </div>
                                <div class="oe_kanban_bottom_right">
                                    <field name="analysis_count" widget="badge"/>
                                    <span> análisis</span>
                                </div>
                            </div>
                        </div>
                    </t>
                </templates>
            </kanban>
        </field>
    </record>

    <!-- Graph View for Parameter Usage Statistics -->
    <record id="view_product_template_parameter_graph" model="ir.ui.view">
        <field name="name">product.template.parameter.graph</field>
        <field name="model">product.template.parameter</field>
        <field name="arch" type="xml">
            <graph string="Uso de Parámetros en Análisis" type="bar">
                <field name="parameter_id"/>
                <field name="product_tmpl_id" type="measure"/>
            </graph>
        </field>
    </record>

    <!-- Dashboard Action for Parameters -->
    <record id="action_lims_parameter_dashboard" model="ir.actions.act_window">
        <field name="name">Panel de Parámetros</field>
        <field name="res_model">lims.analysis.parameter</field>
        <field name="view_mode">kanban,list,form</field>
        <field name="search_view_id" ref="view_lims_analysis_parameter_search"/>
        <field name="context">{'search_default_active': 1}</field>
        <field name="help" type="html">
            <p class="o_view_nocontent_smiling_face">
                No hay parámetros configurados
            </p>
            <p>
                Configure los parámetros que se utilizarán en los análisis clínicos.
                Cada parámetro puede tener múltiples rangos de referencia según
                las características del paciente.
            </p>
        </field>
    </record>

    <!-- Parameter Statistics Action -->
    <record id="action_lims_parameter_statistics" model="ir.actions.act_window">
        <field name="name">Estadísticas de Parámetros</field>
        <field name="res_model">product.template.parameter</field>
        <field name="view_mode">graph,pivot,list</field>
        <field name="help" type="html">
            <p>
                Visualización estadística del uso de parámetros en los diferentes análisis.
            </p>
        </field>
    </record>

    <!-- Configuration Summary Dashboard -->
    <record id="view_lims_config_summary_form" model="ir.ui.view">
        <field name="name">lims.config.summary.form</field>
        <field name="model">res.config.settings</field>
        <field name="mode">primary</field>
        <field name="inherit_id" ref="lims_management.res_config_settings_view_form_lims"/>
        <field name="arch" type="xml">
            <xpath expr="//app[@name='lims_management']//block[@name='lims_settings']" position="after">
                <div class="row mt16" id="lims_configuration_stats">
                    <div class="col-12">
                        <h2>Estadísticas de Configuración</h2>
                    </div>
                    <div class="col-lg-3 col-md-6">
                        <div class="card">
                            <div class="card-body text-center">
                                <h4>Parámetros</h4>
                                <p class="text-muted">Total configurados</p>
                                <button name="%(action_lims_analysis_parameter)d" 
                                        string="Ver Parámetros" 
                                        type="action" 
                                        class="btn-link"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6">
                        <div class="card">
                            <div class="card-body text-center">
                                <h4>Rangos</h4>
                                <p class="text-muted">Rangos de referencia</p>
                                <button name="%(action_lims_parameter_range)d" 
                                        string="Ver Rangos" 
                                        type="action" 
                                        class="btn-link"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6">
                        <div class="card">
                            <div class="card-body text-center">
                                <h4>Análisis</h4>
                                <p class="text-muted">Con parámetros</p>
                                <button name="%(action_product_template_parameter_config)d" 
                                        string="Ver Configuración" 
                                        type="action" 
                                        class="btn-link"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-lg-3 col-md-6">
                        <div class="card">
                            <div class="card-body text-center">
                                <h4>Estadísticas</h4>
                                <p class="text-muted">Uso de parámetros</p>
                                <button name="%(action_lims_parameter_statistics)d" 
                                        string="Ver Estadísticas" 
                                        type="action" 
                                        class="btn-link"/>
                            </div>
                        </div>
                    </div>
                </div>
            </xpath>
        </field>
    </record>

    <!-- Add menus -->
    <menuitem id="menu_lims_parameter_dashboard"
              name="Panel de Parámetros"
              parent="lims_management.lims_menu_config"
              action="action_lims_parameter_dashboard"
              sequence="10"/>
              
    <menuitem id="menu_lims_parameter_statistics"
              name="Estadísticas"
              parent="lims_management.lims_menu_config"
              action="action_lims_parameter_statistics"
              sequence="40"/>
</odoo>