{% extends 'components/base_nhncloud.html' %}
{% load static %}
{% block main_area %}
<section>
    <div class="container mt-5">
        <div class="row justify-content-between">
            {% if target == "tokenErr" %}
            <div class="col-lg-12">
                <h1>Toekn Identification Get ERR</h1>
                <hr>
            </div>
            <div class="col-lg-12">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th scope="col">status</th>
                            <th scope="col">title</th>
                            <th scope="col">detail</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{{ code }} </td>
                            <td>{{ errTitle }}</td>
                            <td>{{ errMsg }}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            {% elif target == "infoClusterErr" %}
            <div class="col-lg-12">
                <h1>Cluster Information Get ERR Message</h1>
                <hr>
            </div>
            <div class="col-lg-12">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th scope="col">status</th>
                            <th scope="col">title</th>
                            <th scope="col">detail</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{{ clusterInfoStatus }} </td>
                            <td>{{ clusterInfoTitle }}</td>
                            <td>{{ clusterInfoDetail }}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            {% elif target == "infoClusterDetail" %}
            <div class="col-lg-12">
                <h1>Result Message</h1>
                <hr>
            </div>
            <div class="col-lg-12">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th scope="col">name</th>
                            <th scope="col">status</th>
                            <th scope="col">config</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{{ clusterName }} </td>
                            <td>{{ clusterInfoStatus }} </td>
                            <td>{{ kubeConfig }}</td>
                        </tr>
                    </tbody>
                </table>
            </div>
            
            
            <!-- start ObjectStorageList -->
            {% elif target == "objectStorageList" %}
            {% if objectList %}
            <div class="col-lg-12">
                <h1>Result Message</h1>
                <h6>Object 삭제시 Object에 속한 저장 중인 데이터가 모두 삭제 됩니다.</h6>
                <hr>
            </div>
            {% for var in objectList %}
            <div class="col-lg-12">
                <table class="table table-striped">
                    <thead>
                        <tr>
                            <th scope="col">No</th>
                            <th scope="col">Region</th>
                            <th scope="col">Name</th>
                            <th scope="col">
                                delete
                            </th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td>{{ forloop.counter }}</td>
                            <td id="region-{{ forloop.counter }}">{{ region }}</td>
                            <td id="objStorageNameId-{{ forloop.counter }}">{{ var }}</td>
                            <td>
                                <a type="submit" id="delete-{{ forloop.counter }}" class="btn btn-info float-right" href="#" data-bs-toggle="modal" data-bs-target="#deleteModal" onclick="tenantIdToModal();">Delete</a>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            {% endfor %}
            {% else %}
            <div class="col-lg-12">
                <h1>Result Message</h1>
                <hr>
            </div>
            <div class="row">
                <div class="col-lg-8">
                    <h3>리전에 생성된 Object Storage가 없습니다...</h3>
                </div>
                <div class="col-lg-2">
                    <a class="btn btn-primary float-left" href="/nhncloud/">API List</a>
                </div>
                <div class="col-lg-2">
                    <a class="btn btn-primary float-left" href="/nhncloud/infoObjectStorageRequest">Create Object</a>
                </div>
            </div>
            {% endif %}
            <!-- end ObjectStorageList -->
            {% else %}
            <div class="col-lg-12">
                <h1>Result Message</h1>
                <hr>
            </div>
            <div class="row">
                <div class="col-lg-8">
                    <h3>{{ resultMsg }}</h3>
                </div>
                <div class="col-lg-2">
                    <a class="btn btn-primary float-left" href="/nhncloud/">API List</a>
                </div>
            </div>
            {% endif %}
        </div>
    </div>
    
    
    <!-- Delete ObjectStorage -->
    {% elif target == "objectStorageList" %}
    <form method="post" action="{% url 'nhncloud:removeObjectStorage' %}">{% csrf_token %}
        <input type="hidden" class="form-control" name="objStrgAccount" id="objStrgAccount" value="{{ user.nhn_obstg_sc }}">
        <input type="hidden" class="form-control" name="tenantId" id="tenantId" value="{{ user.nhn_obstg_tntid }}">
        <input type="hidden" class="form-control" name="usrEmail" id="usrEmail" value="{{ user.nhnc_id }}">
        <div class="modal fade" id="deleteModal" tabindex="-1" aria-labelledby="deleteModal" aria-hidden="true">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="deleteModalTitle">API 비밀번호를 입력해주세요.</h5>
                        <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <div class="modal-body">
                        <div class="mb-3">
                            <div class="row">
                                <div class="col-md-4 form-group">
                                    <label for="region">Region</label>
                                </div>
                                <div class="col-md-8">
                                    <select class="form-control" name="region" id="region" readonly>
                                        <option value="select...">select...</option>
                                        <option value="kr1">판교</option>
                                        <option value="kr2">평촌</option>
                                    </select>                                
                                </div>
                            </div>        
                        </div>
                        <div class="mb-3">
                            <div class="row">
                                <div class="col-md-4">
                                    <label for="objStorageNameId">Object Name</label>
                                </div>
                                <div class="col-md-8">
                                    <input type="text" class="form-control" name="objStorageNameId" id="objStorageNameId" readonly>
                                </div>
                            </div>
                        </div>
                        <div class="mb-3">
                            <div class="row">
                                <div class="col-md-4">
                                    <label for="apiPw">API Password</label>
                                </div>
                                <div class="col-md-8">
                                    <input type="password" class="form-control" name="apiPw" id="apiPw">
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-info float-right" onclick="alert('삭제 명령 전송 후 Cluster 리스트가 조회됩니다...')">Request</button>
                        <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    <script>
        function tenantIdToModal(){
            id = event.srcElement.id
            var idx = id.indexOf('-') + 1
            tenantId = "tenant_id-" + id.substring(idx)
            objStorageNameId = "objStorageNameId-" + id.substring(idx)
            regionId = "region-" + id.substring(idx)
            document.getElementById('region').value = document.getElementById(regionId).innerText
            // 오브젝트 스토리지이름
            document.getElementById('objStorageNameId').value = document.getElementById(objStorageNameId).innerText
        }
    </script>
    {% else %}    
    {% endif %}
</section>

{% endblock %}