{%- set static = (static is defined ? static : false) %}
{%- set staticRows = static ? true : (staticRows is defined ? staticRows : false) %}
{%- set cols = (cols is defined ? cols : []) %}
{%- set rows = (rows is defined ? rows : []) -%}
{% for col in cols %}
{%- if col.heading is defined and col.heading %}{{ col.heading }}{% else %} {% endif %}
{%- if col.info is defined -%}
{{ col.info|md|raw }}
{%- endif -%}
{% endfor %}
{% if not staticRows %}
{% endif %}
{% for rowId, row in rows %}
{% for colId, col in cols %}
{% set value = row[colId] is defined ? (row[colId].value is defined ? row[colId].value : row[colId]) : null %}
{% if col.type == 'heading' %}
{{ value|raw }}
{% else %}
{% set hasErrors = row[colId].hasErrors ?? false %}
{% set cellName = name~'['~rowId~']['~colId~']' %}
{% set textual = (col.type in ['singleline','multiline','number']) %}
{%- switch col.type -%}
{% case 'select' -%}
{% include "_includes/forms/select" with {
class: 'small',
name: cellName,
options: col.options,
value: value,
disabled: static
} only %}
{%- case 'checkbox' -%}
{%- case 'lightswitch' -%}
{% include "_includes/forms/lightswitch" with {
name: cellName,
on: value,
value: col.value ?? 1,
small: true,
disabled: static
} only %}
{%- default -%}
{%- endswitch -%}
{% endif %}
{% endfor %}
{% if not staticRows %}
{% endif %}
{% endfor %}
{% if not staticRows %}
{{ addRowLabel is defined ? addRowLabel : "Add a row"|t('app') }}
{% endif %}
{% if not static and (initJs is not defined or initJs) %}
{% js %}
new Craft.EditableTable(
"{{ id | namespaceInputId | e('js') }}",
"{{ name | namespaceInputName | e('js') }}",
{{ cols|json_encode|raw }});
{% endjs %}
{% endif %}