<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

 http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<div class="catalog-details">

    <div class="float-right">
        <button data-name="<%- model.id %>" class="btn composer"
            title="Open this blueprint in the Composer where the YAML can be edited and deployed.">YAML Composer</button>
        <button data-name="<%- model.id %>" class="btn btn-danger delete">Delete</button>
    </div>

    <% if (model.get("name") != model.get("symbolicName")) { %>
        <h2><%- model.get("name") %></h2>
        <p><%- model.getVersionedAttr("symbolicName") %></p>
    <% } else { %>
        <h2><%- model.getVersionedAttr("symbolicName") %></h2>
    <% } %>
    <% if (model.get("containingBundle")) { %>
        <p> Bundle: <%- model.get("containingBundle") %> </p>
    <% } %>
     
    <% if (model.get("description")) { %>
        <p><%- model.get("description") %></p>
    <% } %>

    <div id="catalog-details-accordion" class="accordion">
      <% if (model.get("planYaml")) { %>
        <div class="accordion-group">
            <div class="accordion-heading">
                <a class="accordion-toggle" data-toggle="collapse" data-parent="#catalog-details-accordion" href="#collapseYaml">
                    Plan
                </a>
            </div>
            <div id="collapseYaml" class="accordion-body collapse">
                <div class="accordion-inner">
                    <textarea rows="15" readonly><%- model.get("planYaml") %></textarea>
                </div>
            </div>
        </div>
      <% } %>
        <% if (viewName != "policies") { %>
        <div class="accordion-group">
            <div class="accordion-heading">
                <a class="accordion-toggle" data-toggle="collapse" data-parent="#catalog-details-accordion" href="#collapseConfiguration">
                    Configuration
                </a>
            </div>
            <div id="collapseConfiguration" class="accordion-body collapse">
                <div class="accordion-inner">
                    <% if (model.error) { %>
                    <p><i class="icon-exclamation-sign"></i> Could not load configuration</p>
                    <% } else if (!model.get("config")) { %>
                        <p>Loading...</p>
                    <% } else if (_.isEmpty(model.get("config"))) { %>
                        <p>No configuration</p>
                    <% } else { %>
                        <% var skip = [
                            'name',
                            'description',
                            'label',
                            'priority',
                            'reconfigurable'
                        ]; %>
                        <% _.each(model.get("config"), function(object, index) { %>
                        <div style="padding-bottom: 12px;">
                        <p><strong><%- object.name %></strong>: <%- object.description %></p>
                        <div style="margin-left: 24px;">
                        <table class="table table-striped table-condensed nonDatatables">
                            <tbody>
                            <% _.each(object, function(value, key) { %>
                            <% if (!_.contains(skip, key)) { %>
                            <tr>
                                <td><%- key %></td>
                                <td><%- typeof value === "string" ? value : JSON.stringify(value) %></td>
                            </tr>
                            <% } %>
                            <% }); %>
                            </tbody>
                        </table></div>
                        </div>
                        <% }); %>
                    <% } %>
                </div>
            </div>
        </div>
        <div class="accordion-group">
            <div class="accordion-heading">
                <a class="accordion-toggle" data-toggle="collapse" data-parent="#catalog-details-accordion" href="#collapseSensors">
                    Sensors
                </a>
            </div>
            <div id="collapseSensors" class="accordion-body collapse">
                <div class="accordion-inner">
                    <% if (model.error) { %>
                    <p><i class="icon-exclamation-sign"></i> Could not load sensors</p>
                    <% } else if (!model.get("sensors") && !model.get("config")) { %>
                        <p>Loading...</p>
                    <% } else if (_.isEmpty(model.get("sensors"))) { %>
                        <p>No sensors</p>
                    <% } else { %>
                        <table class="table table-striped table-condensed nonDatatables">
                            <thead>
                                <tr>
                                    <th>Name</th>
                                    <th>Type</th>
                                    <th>Description</th>
                                </tr>
                            </thead>
                            <tbody>
                            <% _.each(model.get("sensors"), function(object, index) { %>
                                <tr>
                                    <td><%- object.name %></td>
                                    <td><%- object.type %></td>
                                    <td><%- object.description %></td>
                                </tr>
                            <% }); %>
                            </tbody>
                        </table>
                    <% } %>
                </div>
            </div>
        </div>
        <div class="accordion-group">
            <div class="accordion-heading">
                <a class="accordion-toggle" data-toggle="collapse" data-parent="#catalog-details-accordion" href="#collapseEffectors">
                    Effectors
                </a>
            </div>
            <div id="collapseEffectors" class="accordion-body collapse">
                <div class="accordion-inner">
                <% if (model.error) { %>
                    <p><i class="icon-exclamation-sign"></i> Could not load effectors</p>
                <% } else if (!model.get("effectors") && !model.get("config")) { %>
                    <p>Loading...</p>
                <% } else if (_.isEmpty(model.get("effectors"))) { %>
                    <p>No effectors</p>
                <% } else { %>
                    <% _.each(model.get("effectors"), function(object, index) { %>
                        <div style="padding-bottom: 12px;">
                        <p><strong><%- object.name %></strong>: <%- object.description %></p>
                        <% if (!object.parameters || _.isEmpty(object.parameters)) { %>
                            <p>No parameters</p>
                        <% } else { %>
                            <div style="margin-left: 24px;">
                            <table class="table table-striped table-condensed nonDatatables">
                                <tbody>
                                    <% _.each(object.parameters, function(parameter, index) { %>
                                        <% _.each(parameter, function(value, key) { %>
                                        <tr>
                                            <td><%- key %></td>
                                            <td><%- value %></td>
                                        </tr>
                                        <% }); %>
                                    <% }); %>
                                </tbody>
                            </table>
                            </div>
                        <% } %>
                        </div>
                    <% }); %>
                <% } %>
                </div>
            </div>
        </div>
        <% } %>
    </div>

</div>
