{% extends 'base.html' %}
{% load buttons %}
{% load custom_links %}
{% load helpers %}
{% load secret_helpers %}
{% load static %}
{% load plugins %}

{% block header %}
    <div class="row noprint">
        <div class="col-md-12">
            <ol class="breadcrumb">
                <li><a href="{% url 'secrets:secret_list' %}">Secrets</a></li>
                <li><a href="{% url 'secrets:secret_list' %}?role={{ secret.role.slug }}">{{ secret.role }}</a></li>
                <li>{{ secret.device }}{% if secret.name %} ({{ secret.name }}){% endif %}</li>
            </ol>
        </div>
    </div>
    <div class="pull-right noprint">
        {% plugin_buttons secret %}
        {% if perms.secrets.change_secret %}
            {% edit_button secret %}
        {% endif %}
        {% if perms.secrets.delete_secret %}
            {% delete_button secret %}
        {% endif %}
    </div>
    <h1>{% block title %}{{ secret }}{% endblock %}</h1>
    {% include 'inc/created_updated.html' with obj=secret %}
    <div class="pull-right noprint">
        {% custom_links secret %}
    </div>
    <ul class="nav nav-tabs">
        <li role="presentation"{% if not active_tab %} class="active"{% endif %}>
            <a href="{{ secret.get_absolute_url }}">Secret</a>
        </li>
        {% if perms.extras.view_objectchange %}
            <li role="presentation"{% if active_tab == 'changelog' %} class="active"{% endif %}>
                <a href="{% url 'secrets:secret_changelog' pk=secret.pk %}">Change Log</a>
            </li>
        {% endif %}
    </ul>
{% endblock %}

{% block content %}
<div class="row">
	<div class="col-md-6">
        <div class="panel panel-default">
            <div class="panel-heading">
                <strong>Secret Attributes</strong>
            </div>
            <table class="table table-hover panel-body">
                <tr>
                    <td>Device</td>
                    <td>
                        <a href="{% url 'dcim:device' pk=secret.device.pk %}">{{ secret.device }}</a>
                    </td>
                </tr>
                <tr>
                    <td>Role</td>
                    <td>{{ secret.role }}</td>
                </tr>
                <tr>
                    <td>Name</td>
                    <td>{{ secret.name|placeholder }}</td>
                </tr>
            </table>
        </div>
        {% include 'inc/custom_fields_panel.html' with obj=secret %}
        {% plugin_left_page secret %}
	</div>
	<div class="col-md-6">
        {% if secret|decryptable_by:request.user %}
            <div class="panel panel-default">
                <div class="panel-heading">
                    <strong>Secret Data</strong>
                </div>
                <div class="panel-body">
                    <form id="secret_form">
                        {% csrf_token %}
                    </form>
                    <div class="row">
                        <div class="col-md-2">Secret</div>
                        <div class="col-md-6" id="secret_{{ secret.pk }}">********</div>
                        <div class="col-md-4 text-right noprint">
                            <button class="btn btn-xs btn-success unlock-secret" secret-id="{{ secret.pk }}">
                                <i class="fa fa-lock"></i> Unlock
                            </button>
                            <button class="btn btn-xs btn-default copy-secret collapse" secret-id="{{ secret.pk }}" data-clipboard-target="#secret_{{ secret.pk }}">
                                <i class="fa fa-copy"></i> Copy
                            </button>
                            <button class="btn btn-xs btn-danger lock-secret collapse" secret-id="{{ secret.pk }}">
                                <i class="fa fa-unlock-alt"></i> Lock
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        {% else %}
            <div class="alert alert-warning">
                <i class="fa fa-warning" aria-hidden="true"></i>
                You do not have permission to decrypt this secret.
            </div>
        {% endif %}
        {% include 'extras/inc/tags_panel.html' with tags=secret.tags.all url='secrets:secret_list' %}
        {% plugin_right_page secret %}
    </div>
</div>
<div class="row">
    <div class="col-md-12">
        {% plugin_full_width_page secret %}
    </div>
</div>

{% include 'secrets/inc/private_key_modal.html' %}
{% endblock %}

{% block javascript %}
<script src="{% static 'js/secrets.js' %}?v{{ settings.VERSION }}"></script>
{% endblock %}
