{% extends "base/skeleton.html" %}

{% load static %}

{% block title %}
API Browser - {{ tenant.branding_title }}
{% endblock %}

{% block head %}
<script type="module" src="{% static 'dist/rapidoc-min.js' %}"></script>
{% endblock %}

{% block body %}
<script>
function getCookie(name) {
    let cookieValue = "";
    if (document.cookie && document.cookie !== "") {
        const cookies = document.cookie.split(";");
        for (let i = 0; i < cookies.length; i++) {
            const cookie = cookies[i].trim();
            // Does this cookie string begin with the name we want?
            if (cookie.substring(0, name.length + 1) === name + "=") {
                cookieValue = decodeURIComponent(cookie.substring(name.length + 1));
                break;
            }
        }
    }
    return cookieValue;
}
window.addEventListener('DOMContentLoaded', (event) => {
    const rapidocEl = document.querySelector('rapi-doc');
    rapidocEl.addEventListener('before-try', (e) => {
        e.detail.request.headers.append('X-CSRFToken', getCookie("authentik_csrf"));
    });
});
</script>
<rapi-doc
    spec-url="{{ path }}"
    heading-text="authentik"
    theme="dark"
    render-style="view"
    primary-color="#fd4b2d"
    allow-spec-url-load="false"
    allow-spec-file-load="false">
    <div slot="logo">
        <img src="{% static 'dist/assets/icons/icon.png' %}" style="width:50px; height:50px" />
    </div>
</rapi-doc>
{% endblock %}
