{% extends "base.html" %}
{% block title %}{{ resource.name }} ({{resource.kind}}{% if namespace and resource.kind != 'Namespace': %} in {{namespace}}{% endif %}){% endblock %}
{% block content %}
<nav class="breadcrumb" aria-label="breadcrumbs">
    <ul>
        <li><a href="/clusters/{{ cluster }}">{{ cluster }}</a></li>
        {% if namespace and resource.kind != 'Namespace': %}
        <li><a href="/clusters/{{ cluster }}/namespaces/{{ namespace }}">{{ namespace }}</a></li>
        <li><a href="/clusters/{{ cluster }}/namespaces/{{ namespace }}/{{ resource.endpoint }}">{{ resource.endpoint }}</a></li>
        {% else: %}
        <li><a href="/clusters/{{ cluster }}/{{ resource.endpoint }}">{{ resource.endpoint }}</a></li>
        {% endif %}
        <li class="is-active"><a href="#">{{ resource.name }}</a></li>
    </ul>
</nav>

<h1 class="title">{{ resource.name }}
    <span class="links">
        <a
          {% if namespace: %}
          href="/clusters/{{ cluster }}/namespaces/{{ namespace }}/{{ resource.endpoint }}/{{ resource.name }}?download=yaml"
          {% else: %}
          href="/clusters/{{ cluster }}/{{ resource.endpoint }}/{{ resource.name }}?download=yaml"
          {% endif %}
          title="Download resource object as YAML"
          class="button is-light">
            <span class="icon"><i class="fas fa-file-download"></i></span>
        </a>
        {% for link in object_links[resource.endpoint]: %}
        <a href="{{ link.href.format(cluster=cluster, namespace=namespace, name=resource.name) }}"
           class="button is-primary"
           title="{{ link.title.format(cluster=cluster, namespace=namespace, name=resource.name) }}">
            <span class="icon"><i class="fas fa-{{ link.icon }}"></i></span>
        </a>
        {% endfor %}
        {% for label, label_value in resource.labels.items()|sort: %}
        {% for link in label_links[label]: %}
        <a href="{{ link.href.format(cluster=cluster, namespace=namespace, name=resource.name, label=label, label_value=label_value) }}"
           class="button is-info"
           title="{{ link.title.format(cluster=cluster, namespace=namespace, name=resource.name, label=label, label_value=label_value) }}">
            <span class="icon"><i class="fas fa-{{ link.icon }}"></i></span>
        </a>
        {% endfor %}
        {% endfor %}
    </span>
    <span class="meta">
        created {{ resource.metadata.creationTimestamp.replace('T', ' ').replace('Z', '') }},
        version {{ resource.metadata.resourceVersion }}
    </span>
</h1>
<div class="tabs is-small">
    <ul>
        <li {% if view != 'yaml': %} class="is-active" {% endif %}><a href="?">Default</a></li>
        <li {% if view == 'yaml': %} class="is-active" {% endif %}><a href="?view=yaml">YAML</a></li>
        {% if resource.kind in ('Pod', 'Deployment', 'ReplicaSet', 'DaemonSet', 'StatefulSet'): %}
        <li><a href="/clusters/{{ cluster }}/namespaces/{{ resource.metadata.namespace }}/{{ resource.endpoint }}/{{ resource.name }}/logs">Logs</a></li>
        {% endif %}
    </ul>
</div>

{% if view == 'yaml': %}
{% include "partials/yaml.html" %}
{% else: %}
<div class="section">
    {% for key, val in resource.labels.items()|sort: %}
    {% if namespace: %}
    <a href="/clusters/{{ cluster }}/namespaces/{{ namespace }}/{{ resource.endpoint }}?selector={{key}}={{val}}"><span class="tag is-link">{{ key }}: {{ val }}</span></a>
    {% else: %}
    <a href="/clusters/{{ cluster }}/{{ resource.endpoint }}?selector={{key}}={{val}}"><span class="tag is-link">{{ key }}: {{ val }}</span></a>
    {% endif %}
    {% endfor %}
</div>

<div class="section">
    {% for key, val in resource.annotations.items()|sort: %}
    <span class="tag">{{ key }}: {{ val|truncate(40) }}</span>
    {% endfor %}
</div>

{% if owners: %}
<div class="section">
    Owner{{ 's' if owners|length > 1 }}:
    {% for owner in owners: %}
    <a href="/clusters/{{ cluster }}/namespaces/{{ namespace }}/{{ owner.class.endpoint }}/{{ owner.name }}">{{ owner.name }} ({{ owner.class.kind }})</a>

    {% endfor %}
</div>
{% endif %}

{% for key, val in resource.obj.items()|sort: %}
{% if key not in ('metadata', 'apiVersion', 'kind'): %}

<div class="section">
    <h4 class="title is-5">{{ key|capitalize }}</h4>
    <div class="content">
        {{ val|yaml|highlight|safe }}
    </div>
</div>
{% endif %}
{% endfor %}

{% if resource.kind == "Namespace": %}
<div class="section">
    <a href="/clusters/{{ cluster }}/namespaces/{{ namespace }}/all">Show all objects in this namespace</a>
</div>
<div class="section">
    <a href="/clusters/{{ cluster }}/namespaces/{{ namespace }}/_resource-types">Show Resource Types in this namespace</a>
</div>
{% endif %}


{% if table: %}
<div class="section">
    <h4 class="title is-5">Pods</h4>
    <table class="table is-striped">
        <tr>
            {% if not namespace: %}
            <th>Namespace</th>
            {% endif %}
            {% for column in table.columns: %}
            <th title="{{ column.description }}"><a href="{{ rel_url.update_query(sort=column.name) }}">{{ column.name }}</a></th>
            {% endfor %}
            <th><a href="{{ rel_url.update_query(sort='Created') }}">Created</th>
        </tr>
        {% for row in table.rows: %}
        <tr>
            {% if not namespace: %}
            <td><a href="/clusters/{{ table.obj.cluster.name }}/namespaces/{{ row.object.metadata.namespace }}">{{ row.object.metadata.namespace }}</a></td>
            {% endif %}
            {% for cell in row.cells: %}
            {% if loop.first: %}
            {% if row.object.metadata.namespace: %}
            <td><a href="/clusters/{{ table.obj.cluster.name }}/namespaces/{{ row.object.metadata.namespace }}/{{ table.api_obj_class.endpoint }}/{{ row.object.metadata.name }}">{{ cell }}</a></td>
            {% else: %}
            <td><a href="/clusters/{{ table.obj.cluster.name }}/{{ table.api_obj_class.endpoint }}/{{ row.object.metadata.name }}">{{ cell }}</a></td>
            {% endif %}
            {% else: %}
            <td class="{{ get_cell_class(table, loop.index0, cell) }}"
                {% if table.columns[loop.index0].name in ('Age', 'First Seen'): %}
                style="color:{{ row.object.metadata.creationTimestamp|age_color(days=1) }}"
                {% endif %}
                >
                {% if table.columns[loop.index0].name == 'Node': %}
                <a href="/clusters/{{ table.obj.cluster.name }}/nodes/{{ cell }}">{{ cell if cell is not none}}</a>
                {% else: %}
                {{ cell if cell is not none}}
                {% endif %}
            </td>
            {% endif %}
            {% endfor %}
            <td style="color:{{ row.object.metadata.creationTimestamp|age_color(days=1) }}">{{ row.object.metadata.creationTimestamp.replace('T', ' ').replace('Z', '') }}</td>
        </tr>
        {% else: %}
        <tr>
            <td colspan="{{ table.columns|length + 1 }}">No {{ table.api_obj_class.kind }} objects {% if namespace and not is_all_namespaces:%} in namespace "{{ namespace }}"{% endif %} found.</td>
        </tr>
        {% endfor %}
    </table>
</div>
{% endif %}

<div class="section">
    {% include "partials/events.html" %}
</div>

{% endif %}

{% endblock %}
