{#- -*- mode: sgml; tab-width: 1; indent-tabs-mode: nil -*-
 #
 # SPDX-License-Identifier: MIT
-#}

{%- import('macros/printElementId.xml.jinja2') as peid %}
{%- import('macros/printSpecialData.xml.jinja2') as psd %}
{%- import('macros/printDescription.xml.jinja2') as pd %}
{%- import('macros/printAdminData.xml.jinja2') as pad %}
{%- import('macros/printAudience.xml.jinja2') as paud %}
{%- import('macros/printPreConditionStateRef.xml.jinja2') as ppcsr %}
{%- import('macros/printStateTransitionRef.xml.jinja2') as pstr %}

{%- macro printTable(table) %}
<TABLE {{-peid.printElementIdAttribs(table)}}
       {{-make_xml_attrib("SEMANTIC", table.semantic)}}>
 {{ peid.printElementIdSubtags(table)|indent(1) }}
{%- if table.key_dop_ref %}
 <KEY-DOP-REF ID-REF="{{ table.key_dop_ref.ref_id }}" />
{%- endif %}
 {%- for table_row in table.table_rows_raw %}
 {%- if hasattr(table_row, "key") %}
 <TABLE-ROW {{-peid.printElementIdAttribs(table_row)}}
            {{-make_xml_attrib("SEMANTIC", table_row.semantic)}}>
  {{-peid.printElementIdSubtags(table_row)}}
  <KEY>{{table_row.key|e}}</KEY>
  {%- if table_row.dop_ref is not none %}
  <DATA-OBJECT-PROP-REF ID-REF="{{ table_row.dop_ref.ref_id }}" />
  {%- endif %}
  {%- if table_row.dop_snref is not none %}
  <DATA-OBJECT-PROP-SNREF SHORT-NAME="{{ table_row.dop_snref }}" />
  {%- endif %}
  {%- if table_row.structure_ref is not none %}
  <STRUCTURE-REF ID-REF="{{ table_row.structure_ref.ref_id }}" />
  {%- endif %}
  {%- if table_row.structure_snref is not none %}
  <STRUCTURE-SNREF SHORT-NAME="{{ table_row.structure_snref }}" />
  {%- endif %}
  {{- psd.printSpecialDataGroups(table_row.sdgs)|indent(2, first=True) }}
  {%- if table_row.audience is not none %}
  {{ paud.printAudience(table_row.audience) | indent(2) }}
  {%- endif %}
  {%- if table_row.functional_class_refs %}
  <FUNCT-CLASS-REFS>
    {%- for fc_ref in table_row.functional_class_refs %}
    <FUNCT-CLASS-REF ID-REF="{{ fc_ref.ref_id }}" />
    {%- endfor %}
  </FUNCT-CLASS-REFS>
  {%- endif %}
  {%- if table_row.state_transition_refs %}
  <STATE-TRANSITION-REFS>
    {%- for st_ref in table_row.state_transition_refs %}
    {{ pstr.printStateTransitionRef(st_ref)|indent(4) }}
    {%- endfor %}
  </STATE-TRANSITION-REFS>
  {%- endif %}
  {%- if table_row.pre_condition_state_refs %}
  <PRE-CONDITION-STATE-REFS>
    {%- for pcs_ref in table_row.pre_condition_state_refs %}
    {{ ppcsr.printPreConditionStateRef(ps_ref)|indent(4) }}
    {%- endfor %}
  </PRE-CONDITION-STATE-REFS>
  {%- endif %}
  {%- if table_row.admin_data is not none %}
  {{ pad.printAdminData(table_row.admin_data)|indent(2) }}
  {%- endif %}
 </TABLE-ROW>
 {%- else %}
 <TABLE-ROW-REF ID-REF="{{ table_row.ref_id }}" />
 {%- endif %}
{%- endfor %}
 {%- if table_diag_comm_connectors %}
 <TABLE-DIAG-COMM-CONNECTORS>
 {%- for tdcc in table_diag_comm_connectors %}
  <TABLE-DIAG-COMM-CONNECTOR>
   <SEMANTIC>{{tdcc.semantic}}</SEMANTIC>
   {%- if tdcc.diag_comm_ref %}
   <DIAG-COMM-REF ID-REF="{{ tdcc.diag_comm_ref.ref_id }}" />
   {%- elif tdcc.diag_comm_snref %}
   <DIAG-COMM-SNREF SHORT-NAME="{{ tdcc.diag_comm_snref }}" />
   {%- endif %}
  </TABLE-DIAG-COMM-CONNECTOR>
 {%- endfor %}
 </TABLE-DIAG-COMM-CONNECTORS>
 {%- endif %}
 {{- psd.printSpecialDataGroups(table.sdgs)|indent(1, first=True) }}
</TABLE>
{%- endmacro -%}
