{%- import "apostrophe-ui:components/fields.html" as commonFields with context -%}
{%- import "fieldset.html" as fieldset with context -%}
{%- macro fields(fields, options = {}) -%}
{%- set groups = apos.schemas.toGroups(fields) -%}
{%- if options.tabs != false -%}
{%- if groups.length > 1 -%}
{%- for group in groups -%}
{%- if group.fields.length -%}
{{ __(group.label | d('')) }}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endif -%}
{%- for group in groups -%}
{%- if group.fields.length -%}
{%- for field in group.fields -%}
{%- if not field.contextual -%}
{{ apos.schemas.field(field, options.readOnly) }}
{%- endif -%}
{%- endfor -%}
{%- endif -%}
{%- endfor -%}
{%- endmacro -%}
{# Output a fieldset for the given field, and call the given #}
{# macro to populate it. Usually not called directly #}
{%- macro fieldset(field, bodyMacro) %}
{{ fieldset.render(field, bodyMacro) }}
{%- endmacro -%}
{# This is used directly to output a text field #}
{%- macro string(field) -%}
{{ fieldset(field, stringBody) }}
{%- endmacro -%}
{# Usually passed to fieldset() by text(), this can also be called #}
{# directly if you don't want the fieldset #}
{%- macro stringBody(field, options) -%}
{%- if field.textarea -%}
{{ commonFields.textarea(field.name, field.placeholder, field.readOnly, options) }}
{%- else -%}
{{ commonFields.string(field.name, field.placeholder, '', field.readOnly, options) }}
{%- endif -%}
{%- endmacro -%}
{%- macro colorBody(field, options) -%}
{{ commonFields.color(field.name, field.placeholder, '', field.readOnly, options) }}
{%- endmacro -%}
{%- macro rangeBody(field, options) -%}
{{ commonFields.range(field.name, field.min, field.max, field.step, field.placeholder, '', field.readOnly, options) }}
{%- endmacro -%}
{%- macro integer(field) -%}
{{ fieldset(field, stringBody) }}
{%- endmacro -%}
{%- macro float(field) -%}
{{ fieldset(field, stringBody) }}
{%- endmacro -%}
{%- macro slug(field) -%}
{{ fieldset(field, stringBody) }}
{%- endmacro -%}
{%- macro password(field) -%}
{{ fieldset(field, passwordBody) }}
{%- endmacro -%}
{%- macro passwordBody(field, options) -%}
{%- endmacro -%}
{%- macro tags(field) -%}
{{ fieldset(field, tagsBody) }}
{%- endmacro -%}
{%- macro tagsBody(field, options) -%}
{# Always using this wrapper div makes it easy to use this with #}
{# selective, and in both standalone and fieldset situations. -Tom #}
{# Text entry for autocompleting the next item #}
{% if not field.readOnly %}{% endif %}
{{ __('Example label') }}
{# Link to remove this choice #}
{% if not field.readOnly %}
{{ __('Limit Reached!') }} {{ __("Add") }}
{% endif %}