<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title><%= element.name %></title>
        <% include head %>
    </head>
    <body>
        <div>

            <!-- Name Title -->

            <h1><%=: element | toName %></h1>

            <!-- Type and Stereotype -->

            <section style="margin-top: .5em;">
                <span class="alert alert-info">
                    <span class="node-icon <%=: element | toIcon %>"></span>
                    <%= element.getClassName() %>
                </span>
                <% if (element.stereotype instanceof type.UMLStereotype) { %>
                    <span style="margin-left: 10px" class="alert alert-info"><%-: element.stereotype | toValue %></span>
                <% } else if (typeof element.stereotype === "string") { %>
                    <span style="margin-left: 10px" class="alert alert-info">«<%-: element.stereotype | toValue %>»</span>
                <% } %>
            </section>

            <!-- Path -->

            <section style="margin-top: 10px">
                <% var terms = []; %>
                <% element.traverseUp(function (e) { terms.unshift(e); }); %>
                <% for (var i = 0, len = terms.length; i < len; i++) { %>
                    <% if (i > 0) { %><span>::</span><% } %>
                    <span class="label label-info"><%-: terms[i] | toValue %></span>
                <% } %>
            </section>

            <!-- Diagram -->

            <% if (element instanceof type.Diagram) { %>
            <section>
                <h3>Diagram</h3>
                <img src="<%=: element | toDiagram %>">
            </section>
            <% } %>

            <!-- Description -->

            <% if (element instanceof type.ExtensibleModel) { %>
            <section>
                <h3>Description</h3>
                <div>
                    <% if (element.documentation.trim().length === 0) { %>
                        <span class="label label-info">none</span>
                    <% } else { %>
                        <%-: element.documentation | markdown %>
                    <% } %>
                </div>
            </section>
            <% } %>

            <!-- Specification -->

            <% if ((element instanceof type.UMLConstraint || element instanceof type.UMLOperation) && (element.specification.length > 0)) { %>
            <section>
                <h3>Specification</h3>
                <pre><%= element.specification %></pre>
            </section>
            <% } %>

            <!-- Directed Relationship -->

            <% if (element instanceof type.DirectedRelationship && element.source && element.target) { %>
            <section class="element-list">
                <table width="100%">
                    <tr>
                        <td width="50%">
                            <h3>Source</h3>
                            <ul class="nav nav-list">
                                <li><%-: element.source | toValue %></a></li>
                            </ul>
                        </td>
                        <td width="50%">
                            <h3>Target</h3>
                            <ul class="nav nav-list">
                                <li><%-: element.target | toValue %></a></li>
                            </ul>
                        </td>
                    </tr>
                </table>
            </section>
            <% } %>

            <!-- Undirected Relationship -->

            <% if (element instanceof type.UndirectedRelationship && element.end1 && element.end2) { %>
            <section class="element-list">
                <table width="100%">
                    <tr>
                        <td width="50%" style="padding-right: 1em">
                            <h3>End1</h3>
                            <% var elem = element.end1, properties = elem.getMetaAttributes(); %>
                            <% include properties %>
                        </td>
                        <td width="50%" style="padding-right: 1em">
                            <h3>End2</h3>
                            <% var elem = element.end2, properties = elem.getMetaAttributes(); %>
                            <% include properties %>
                        </td>
                    </tr>
                </table>
            </section>
            <% } %>

            <!-- Classifier -->

            <% if (element instanceof type.UMLClassifier) { %>
                <% var title = "Generalized Elements", list = element.getGeneralElements() || []; %>
                <% include list %>

                <% var title = "Specialized Elements", list = element.getSpecialElements() || []; %>
                <% include list %>

                <% var title = "Interfaces", list = element.getInterfaces() || []; %>
                <% include list %>

                <% var title = "Components", list = element.getComponents() || []; %>
                <% include list %>

                <% var title = "Deployment Targets", list = element.getDeploymentTargets() || []; %>
                <% include list %>
            <% } %>

            <!-- Interface -->

            <% if (element instanceof type.UMLInterface) { %>
                <% var title = "Implementing Classifiers", list = element.getImplementingClassifiers() || []; %>
                <% include list %>
            <% } %>

            <!-- Component -->

            <% if (element instanceof type.UMLComponent) { %>
                <% var title = "Realizing Classifiers", list = element.getRealizingClassifiers() || []; %>
                <% include list %>
            <% } %>

            <!-- Node -->

            <% if (element instanceof type.UMLNode) { %>
                <% var title = "Deployed Elements", list = element.getDeployedElements() || []; %>
                <% include list %>
            <% } %>

            <!-- Actor -->

            <% if (element instanceof type.UMLActor) { %>
                <% var title = "Use Cases", list = element.getUseCases() || []; %>
                <% include list %>
            <% } %>

            <!-- Use Case -->

            <% if (element instanceof type.UMLUseCase) { %>
                <% var title = "Actors", list = element.getActors() || []; %>
                <% include list %>

                <% var title = "Included Use Cases", list = element.getIncludedUseCases() || []; %>
                <% include list %>

                <% var title = "Extending Use Cases", list = element.getExtendingUseCases() || []; %>
                <% include list %>
            <% } %>

            <!-- Template Parameters -->

            <% if (element instanceof type.UMLModelElement && element.templateParameters && element.templateParameters.length > 0) { %>
            <section>
                <h3>Template Parameters</h3>
                <table class="table table-striped table-bordered">
                    <tr>
                        <th>Visibility</th>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Description</th>
                    </tr>
                    <% element.templateParameters.forEach(function (param) { %>
                    <tr>
                        <td><%= param.visibility %></td>
                        <td><a href="<%=: param | toUrl %>"><%=: param | toName %></a></td>
                        <td><%-: param.parameterType | toValue %></td>
                        <td><%-: param.documentation | markdown %></td>
                    </tr>
                    <% }); %>
                </table>
            </section>
            <% } %>

            <!-- Literals -->

            <% if (element instanceof type.UMLEnumeration && element.literals && element.literals.length > 0) { %>
            <section>
                <h3>Literals</h3>
                <table class="table table-striped table-bordered">
                    <tr>
                        <th>Visibility</th>
                        <th>Name</th>
                        <th>Description</th>
                    </tr>
                    <% element.literals.forEach(function (literal) { %>
                    <tr>
                        <td><%= literal.visibility %></td>
                        <td><a href="<%=: literal | toUrl %>"><%=: literal | toName %></a></td>
                        <td><%-: literal.documentation | markdown %></td>
                    </tr>
                    <% }); %>
                </table>
            </section>
            <% } %>

            <!-- Attributes -->

            <% if (element instanceof type.UMLClassifier && element.attributes && element.attributes.length > 0) { %>
            <section>
                <h3>Attributes</h3>
                <table class="table table-striped table-bordered">
                    <tr>
                        <th>Visibility</th>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Description</th>
                    </tr>
                    <% element.attributes.forEach(function (attr) { %>
                    <tr>
                        <td><%= attr.visibility %></td>
                        <td><a href="<%=: attr | toUrl %>"><%=: attr | toName %></a></td>
                        <td><%-: attr.type | toType %></td>
                        <td><%-: attr.documentation | markdown %></td>
                    </tr>
                    <% }); %>
                </table>
            </section>
            <% } %>

            <!-- Operations -->

            <% if (element instanceof type.UMLClassifier && element.operations && element.operations.length > 0) { %>
            <section>
                <h3>Operations</h3>
                <table class="table table-striped table-bordered">
                    <tr>
                        <th>Visibility</th>
                        <th>Name</th>
                        <th>Description</th>
                    </tr>
                    <% element.operations.forEach(function (op) { %>
                    <tr>
                        <td><%= op.visibility %></td>
                        <td><a href="<%=: op | toUrl %>"><%=: op.getString({showOperationSignature: true, showType: true}) %></a></td>
                        <td><%-: op.documentation | markdown %></td>
                    </tr>
                    <% }); %>
                </table>
            </section>
            <% } %>

            <!-- Receptions -->

            <% if (element instanceof type.UMLClassifier && element.receptions && element.receptions.length > 0) { %>
            <section>
                <h3>Receptions</h3>
                <table class="table table-striped table-bordered">
                    <tr>
                        <th>Visibility</th>
                        <th>Name</th>
                        <th>Signal</th>
                        <th>Description</th>
                    </tr>
                    <% element.receptions.forEach(function (recep) { %>
                    <tr>
                        <td><%= recep.visibility %></td>
                        <td><a href="<%=: recep | toUrl %>"><%=: recep.getString({showOperationSignature: true, showType: true}) %></a></td>
                        <td><%-: recep.signal | toType %></td>
                        <td><%-: recep.documentation | markdown %></td>
                    </tr>
                    <% }); %>
                </table>
            </section>
            <% } %>

            <!-- Extension Points -->

            <% if (element instanceof type.UMLUseCase && element.extensionPoints && element.extensionPoints.length > 0) { %>
            <section>
                <h3>Extension Points</h3>
                <table class="table table-striped table-bordered">
                    <tr>
                        <th>Name</th>
                        <th>Location</th>
                        <th>Description</th>
                    </tr>
                    <% element.extensionPoints.forEach(function (ep) { %>
                    <tr>
                        <td><a href="<%=: ep | toUrl %>"><%=: ep | toName %></a></td>
                        <td><%-: ep.location | toValue %></td>
                        <td><%-: ep.documentation | markdown %></td>
                    </tr>
                    <% }); %>
                </table>
            </section>
            <% } %>

            <!-- Parameters -->

            <% if (element instanceof type.UMLBehavioralFeature && element.parameters && element.parameters.length > 0) { %>
            <section>
                <h3>Parameters</h3>
                <table class="table table-striped table-bordered">
                    <tr>
                        <th>Direction</th>
                        <th>Name</th>
                        <th>Type</th>
                        <th>Description</th>
                    </tr>
                    <% element.parameters.forEach(function (param) { %>
                    <tr>
                        <td><%= param.direction %></td>
                        <td><a href="<%=: param | toUrl %>"><%=: param | toName %></a></td>
                        <td><%-: param.type | toValue %></td>
                        <td><%-: param.documentation | markdown %></td>
                    </tr>
                    <% }); %>
                </table>
            </section>
            <% } %>

            <!-- Diagrams -->

            <%
            var _diagrams = [];
            if (element.ownedElements && element.ownedElements.length > 0) {
                element.ownedElements.forEach(function (e) {
                    if (e instanceof type.Diagram) { _diagrams.push(e); }
                });
            }
            %>
            <% if (_diagrams.length > 0) { %>
            <section class="element-list">
                <h3>Diagrams</h3>
                <div>
                    <% _diagrams.forEach(function (d) { %>
                    <div style="display: inline-block; width: 250px; vertical-align: top;">
                        <div class="member">
                            <a href="<%=: d | toUrl %>">
                            <img src="<%=: d | toDiagram %>">
                            <div style="text-align: center; margin-top: 1em;"><%-: d | toName %></div>
                            </a>
                        </div>
                    </div>
                    <% }); %>
                </div>
            </section>
            <% } %>

            <!-- Behavior -->

            <% if (element instanceof type.UMLBehavior) { %>
                <% var title = "Preconditions", list = element.preconditions || []; %>
                <% include list %>

                <% var title = "Postconditions", list = element.postconditions || []; %>
                <% include list %>
            <% } %>

            <!-- Action -->

            <% if (element instanceof type.UMLAction) { %>
                <% var title = "Inputs", list = element.inputs || []; %>
                <% include list %>

                <% var title = "Outputs", list = element.outputs || []; %>
                <% include list %>

                <% var title = "Triggers", list = element.triggers || []; %>
                <% include list %>

                <% var title = "Local Preconditions", list = element.localPreconditions || []; %>
                <% include list %>

                <% var title = "Local Postconditions", list = element.localPostconditions || []; %>
                <% include list %>
            <% } %>

            <!-- Interaction -->

            <% if (element instanceof type.UMLInteraction) { %>
                <% var title = "Fragments", list = element.fragments || []; %>
                <% include list %>

                <% var title = "Participants", list = element.participants || []; %>
                <% include list %>

                <% var title = "Messages", list = element.messages || []; %>
                <% include list %>
            <% } %>

            <!-- CombinedFragment -->

            <% if (element instanceof type.UMLCombinedFragment) { %>
                <% var title = "Interaction Operands", list = element.operands || []; %>
                <% include list %>
            <% } %>

            <!-- Activity -->

            <% if (element instanceof type.UMLActivity) { %>
                <% var title = "Groups", list = element.groups || []; %>
                <% include list %>

                <% var title = "Nodes", list = element.nodes || []; %>
                <% include list %>

                <% var title = "Edges", list = element.edges || []; %>
                <% include list %>
            <% } %>

            <!-- State Machine -->

            <% if (element instanceof type.UMLStateMachine) { %>
                <% var title = "Regions", list = element.regions || []; %>
                <% include list %>
            <% } %>

            <!-- State Machine -->

            <% if (element instanceof type.UMLRegion) { %>
                <% var title = "Vertices", list = element.vertices || []; %>
                <% include list %>

                <% var title = "Transitions", list = element.transitions || []; %>
                <% include list %>
            <% } %>

            <!-- State -->

            <% if (element instanceof type.UMLState) { %>
                <% var title = "Entry Activities", list = element.entryActivities || []; %>
                <% include list %>

                <% var title = "Do Activities", list = element.doActivities || []; %>
                <% include list %>

                <% var title = "Exit Activities", list = element.exitActivities || []; %>
                <% include list %>

                <% var title = "Connections", list = element.connections || []; %>
                <% include list %>

                <% var title = "Regions", list = element.regions || []; %>
                <% include list %>
            <% } %>

            <!-- Vertex -->

            <% if (element instanceof type.UMLVertex) { %>
                <% var title = "Incoming Transitions", list = element.getIncomingTransitions() || []; %>
                <% include list %>

                <% var title = "Outgoing Transitions", list = element.getOutgoingTransitions() || []; %>
                <% include list %>
            <% } %>

            <!-- Transition -->

            <% if (element instanceof type.UMLTransition) { %>
                <% var title = "Triggers", list = element.triggers || []; %>
                <% include list %>

                <% var title = "Effects", list = element.effects || []; %>
                <% include list %>
            <% } %>

            <!-- Properties -->

            <section>
                <h3>Properties</h3>
                <% var elem = element, properties = elem.getMetaAttributes(); %>
                <% include properties %>
            </section>

            <!-- Tags -->

            <% if (element instanceof type.Model && element.tags && element.tags.length > 0) { %>
            <section>
                <h3>Tags</h3>
                <table class="table table-striped table-bordered">
                    <tr>
                        <th>Name</th>
                        <th>Kind</th>
                        <th>Value</th>
                    </tr>
                    <% element.tags.forEach(function (tag) { %>
                    <tr>
                        <td><%= tag.name %></td>
                        <td><span class="label label-info"><%= tag.kind %></span></td>
                        <td>
                            <% if (tag.kind === mdjson.Core.TK_BOOLEAN) { %>
                            <%-: tag.checked | toValue %>
                            <% } else if (tag.kind === mdjson.Core.TK_REFERENCE) { %>
                            <%-: tag.reference | toValue %>
                            <% } else if (tag.kind === mdjson.Core.TK_NUMBER) { %>
                            <%-: tag.number | toValue %>
                            <% } else { %>
                            <%-: tag.value | toValue %>
                            <% } %>
                        </td>
                    </tr>
                    <% }); %>
                </table>
            </section>
            <% } %>

            <!-- Constraints, Dependencies, Dependants -->

            <% if (element instanceof type.UMLModelElement) { %>
                <% var title = "Constraints", list = element.getConstraints() || []; %>
                <% include list %>

                <% var title = "Dependencies", list = element.getDependencies() || []; %>
                <% include list %>

                <% var title = "Dependants", list = element.getDependants() || []; %>
                <% include list %>
            <% } %>

            <!-- Relationships -->

            <% var title = "Relationships", list = mdjson.Repository.getRelationshipsOf(element) || []; %>
            <% include list %>

            <!-- Owned Elements -->

            <% var title = "Owned Elements", list = element.ownedElements || []; %>
            <% include list %>

        </div>
    </body>
</html>
