{#
  Copyright DB InfraGO AG and contributors
  SPDX-License-Identifier: Apache-2.0
#}
{% from 'common_macros.html.j2' import show_other_attributes, description %}

{% macro render_name_with_icon(obj) %}
  <a href="hlink://{{ obj.uuid }}">
    <img
      src="{{ obj._get_icon('datauri_svg', size=15) }}"
      height="15"
      width="15"
      style="display:inline-block"
    />
    {{ obj.name }}
  </a>
{% endmacro %}

{% macro describe_transition(tx) %}
  {% if tx.guard %}
    While in <i>{{ render_name_with_icon(tx.source) | safe }}</i>, if
    {{ tx.guard.specification['capella:linkedText'] }}, the System shall
    transition to <i>{{ render_name_with_icon(tx.destination) | safe }}</i>
  {% else %}
    Upon completion of all entry activities of
    <i>{{ render_name_with_icon(tx.source) | safe }}</i> the System shall
    transition to <i>{{ render_name_with_icon(tx.destination) | safe }}</i>
  {% endif %}
{% endmacro %}

<h2>
  <span style="font-weight:normal">{{ object.__class__.__name__ }}</span>
  {{ object.name }}
</h2>

{% if object.incoming_transitions %}
  <p>
    The system may transition to {{ object.__class__.__name__ }}
    <i>{{ object.name }}</i> in the following cases:
  </p>
  <p></p>
  <ul>
    {% for tx in object.incoming_transitions %}
      <li>{{ describe_transition(tx) | safe }}</li>
    {% endfor %}
  </ul>
{% endif %}

{% if object.entries %}
  <p>
    On entry into the <b>{{ object.name }}</b> {{ object.__class__.__name__ }}
    the system shall perform the following activities:
    {% for fnc in object.entries %}
      {{ render_name_with_icon(fnc) | safe }};
    {% endfor %}
  </p>
{% endif %}

{% if object.do_activity %}
  <p>
    While in <b>{{ object.name }}</b> {{ object.__class__.__name__ }} the
    system may perform the following activities:
  </p>
  <ul>
    {% for fnc in object.do_activity %}
      <li>{{ render_name_with_icon(fnc) | safe }}</li>
    {% endfor %}
  </ul>
{% endif %}
{% set substates = [] %}
{% for region in object.regions %}
  {% for rstate in object.states %}
    {{ substates.append(rstate) }}
  {% endfor %}
{% endfor %}

{% if substates %}
  <p>
    While in <b>{{ object.name }}</b> {{ object.__class__.__name__ }} the
    system may be in one of the following
    sub-{{ object.__class__.__name__ | lower }}s
  </p>
  <ul>
    {% for substate in substates %}
      <li>{{ render_name_with_icon(substate) | safe }}</li>
    {% endfor %}
  </ul>
{% endif %}

{% if object.exit %}
  <p>
    On exit from the <b>{{ object.name }}</b> {{ object.__class__.__name__ }}
    the system shall perform the following activities:
    {% for fnc in object.exit %}
      {{ render_name_with_icon(fnc) | safe }};
    {% endfor %}
  </p>
{% endif %}

{% if object.outgoing_transitions %}
  <p>
    The system may transition from {{ object.__class__.__name__ }}
    <i>{{ object.name }}</i> in the following cases:
  </p>
  <p></p>
  <ul>
    {% for tx in object.outgoing_transitions %}
      <li>{{ describe_transition(tx) | safe }}</li>
    {% endfor %}
  </ul>
{% endif %}

<h2>Other properties of "{{ object.name }}"</h2>
{%-
  set excluded = [
    "do_activity",
    "entry",
    "exit",
    "incoming_transitions",
    "name",
    "outgoing_transitions",
    "related_transitions",
    "xtype",
  ]
-%}
{{ show_other_attributes(object, excluded=excluded) | safe }}
