{% extends '_base.html' %}
{% load static from staticfiles %}
{% load secret_helpers %}

{% block content %}
<div class="row">
    <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">
    {% if perms.secrets.change_secret %}
		<a href="{% url 'secrets:secret_edit' pk=secret.pk %}" class="btn btn-warning">
			<span class="fa fa-pencil" aria-hidden="true"></span>
			Edit this secret
		</a>
    {% endif %}
    {% if perms.secrets.delete_secret %}
		<a href="{% url 'secrets:secret_delete' pk=secret.pk %}" class="btn btn-danger">
			<span class="fa fa-trash" aria-hidden="true"></span>
			Delete this secret
		</a>
    {% endif %}
</div>
<h1>{% block title %}{{ secret }}{% endblock %}</h1>
{% include 'inc/created_updated.html' with obj=secret %}
<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>
                        {% if secret.name %}
                            <span>{{ secret.name }}</span>
                        {% else %}
                            <span class="text-muted">N/A</span>
                        {% endif %}
                    </td>
                </tr>
            </table>
        </div>
	</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-8" id="secret_{{ secret.pk }}">********</div>
                        <div class="col-md-2 text-right">
                            <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-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 %}
    </div>
</div>

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

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