<odoo>
    <record id="res_config_settings_view_form" model="ir.ui.view">
        <field name="name">res.config.settings.view.form.inherit.otoolkit_api</field>
        <field name="model">res.config.settings</field>
        <field name="priority" eval="40"/>
        <field name="inherit_id" ref="base.res_config_settings_view_form"/>
        <field name="arch" type="xml">
            <xpath expr="//form" position="inside">
                <app data-string="O'Toolkit" id="otoolkit_auth" string="O'Toolkit" name="otoolkit_auth">
                    <block title="API Authentication" id="api_authentication">
                        <setting id="otoolkit_api_key_settings" string="API Key"
                                 help="Enter an O'Token key from your O'Solutions portal.">
                            <field name="otoolkit_api_key" class="o_light_label mt8"
                                   placeholder="oso_k_..."/>
                        </setting>
                        <setting id="otoolkit_account_settings" string="O'Solutions Portal"
                                 help="Manage your API keys, token balance and usage from the O'Solutions portal.">
                            <a href="https://portal.osolutions.app/dashboard/api-keys" target="_blank"
                               class="btn-link" role="button">
                                <i class="o_button_icon oi oi-fw oi-arrow-right me-1" aria-hidden="true"/>
                                <span>Open Portal</span>
                            </a>
                        </setting>
                        <setting id="otoolkit_tokens_settings" string="Token Balance"
                                 help="Available O'Token balance on your account.">
                            <field name="otoolkit_key_status" invisible="1"/>

                            <div invisible="otoolkit_key_status != 'invalid'"
                                 class="alert alert-danger mb-0" role="alert">
                                This API key is not valid. Please check your key in the
                                <a href="https://portal.osolutions.app/dashboard/api-keys"
                                   target="_blank">O'Solutions Portal</a>.
                            </div>
                            <div invisible="otoolkit_key_status != 'error'"
                                 class="alert alert-warning mb-0" role="alert">
                                Could not connect to the O'Toolkit API. Please try again later.
                            </div>
                            <div invisible="otoolkit_key_status != 'none'"
                                 class="alert alert-info mb-0" role="alert">
                                Enter an API key to start using O'Toolkit services.
                                <a href="https://portal.osolutions.app/dashboard/api-keys"
                                   target="_blank">Get your key</a>
                            </div>
                            <div invisible="otoolkit_key_status != 'valid'">
                                <span class="fw-bold fs-5"><field name="otoolkit_api_token_count" class="d-inline"/> tokens</span>
                                <button string="Refresh" type="object" name="refresh_token_count"
                                        class="btn-link ms-2"/>
                            </div>
                        </setting>
                    </block>
                </app>
            </xpath>
        </field>
    </record>
</odoo>
