{% extends 'base.html' %}

{% block title %}Home{% endblock %}

{% block content %}
<h2>Environments</h2>
{% for environment in environments %}
<div class="card my-2">
    <div class="card-body">
        <h5 class="card-title">
            <a href="{{ url_for('ui.ui_get_environment', namespace=environment.namespace.name, name=environment.name) }}">{{ environment.namespace.name }}/{{ environment.name }}</a>
            <span class="badge badge-light">{{ (environment.current_build.size or 0) | filesizeformat(true) }}</span>
        </h5>
        {% if environment.current_build.has_yaml %}
        <a class="card-link" href="{{ url_for('api.api_get_build_yaml', build_id=environment.current_build_id) }}"><ion-icon name="code-download"></ion-icon> YAML</a>
        {% endif %}
        {% if environment.current_build.has_lockfile %}
        <a class="card-link" href="{{ url_for('ui.api_get_build_lockfile', build_id=environment.current_build_id) }}"><ion-icon name="lock-closed-outline"></ion-icon> Lockfile</a>
        {% endif %}
        {% if environment.current_build.has_conda_pack %}
        <a class="card-link" href="{{ url_for('ui.api_get_build_archive', build_id=environment.current_build_id) }}"><ion-icon name="archive-outline"></ion-icon> Archive</a>
        {% endif %}
        {% if environment.current_build.has_docker_manifest %}
        <a class="card-link" onclick="setClipboard('{{ registry_external_url }}/{{ environment.namespace.name }}/{{ environment.name }}:{{ environment.current_build.build_key }}')" role="button" data-toggle="popover" data-trigger="hover focus" data-content="Click to copy!"><ion-icon name="logo-docker"></ion-icon> Docker</a>
        {% endif %}
    </div>
</div>
{% endfor %}

<script>
 function setClipboard(value) {
     var tempInput = document.createElement("input");
     tempInput.style = "position: absolute; left: -1000px; top: -1000px";
     tempInput.value = value;
     document.body.appendChild(tempInput);
     tempInput.select();
     document.execCommand("copy");
     document.body.removeChild(tempInput);
 }
</script>
{% endblock %}
