{#
  Copyright DB InfraGO AG and contributors
  SPDX-License-Identifier: Apache-2.0
#}
{%
  from 'common_macros.html.j2' import
  show_other_attributes,
  description,
  render_reqs_by_type,
  linked_name,
  linked_name_with_icon,
  render_data_flow_and_involved_activities,
  render_related_diagrams,
  render_constraints,
  display_traceability
%}

<h1>{{ object.name }}</h1>
{{ description(object) | safe }}

<b>Pre-condition</b>:
{% if object.precondition %}
  <p>{{ object.precondition.specification['capella:linkedText']|safe }}</p>
{% else %}
  <p style="color:red">No pre-condition defined</p>
{% endif %}

<b>Post-condition</b>:
{% if object.postcondition %}
  <p>{{ object.postcondition.specification['capella:linkedText']|safe }}</p>
{% else %}
  <p style="color:red">No post-condition defined</p>
{% endif %}

<h2>Context Diagram</h2>
<p>
  The diagram below provides an overview of the components immediately involved
  in the Capability and related Capabilities.
</p>
{{ render_diagram(object, "context_diagram") }}

<h2>Functional Requirements</h2>
{{
  render_data_flow_and_involved_activities(
    object,
    object.involved_functions,
    object.involved_components,
    "The diagram below provides an overview of the Physical System (green) and actor (blue) functions that are required to realise the Capability.",
    "This section provides a summary of what functions are required from the Physical System and the actors to enable the CapabilityRealization.",
    "CapabilityRealization",
    "functions",
    "components",
    "PhysicalComponent"
  )
}}
{%- set related_chains = (object.involved_chains + object.owned_chains) | unique(attribute="uuid") | list -%}
{%- if related_chains -%}
  <h2>Related Functional Chains</h2>
  <p>
    The following functional chains are related to the Capability
    {{ object.name }}:
  </p>
  <ul>
    {%- for chain in related_chains -%}
      <li>{{ linked_name_with_icon(chain) | safe }}</li>
    {%- endfor -%}
  </ul>
{%- endif -%}

{{ render_related_diagrams(object) | safe }}

{{ render_constraints(object) | safe }}

{% if object.requirements %}
  <h2>Linked Requirement objects</h2>
  {% set types = model.search("RequirementType") | map(attribute="long_name") | unique | list %}
  {{ render_reqs_by_type(object.requirements, types) | safe }}
{% endif %}

{{ display_traceability(object)| safe }}

<h2>Other properties of "{{ object.name }}"</h2>

{%-
  set excluded = [
    "constraints",
    "context_diagram",
    "data_flow_view",
    "description",
    "diagrams",
    "involved_chains",
    "involved_components",
    "involved_functions",
    "name",
    "owned_chains",
    "parent",
    "postcondition",
    "precondition",
    "realizing_capabilities",
    "requirements",
    "visible_on_diagrams",
    "xtype",
  ]
-%}
{{ show_other_attributes(object, excluded=excluded) | safe }}
