{# -*- coding: utf-8 -*-

  This file is part of Invenio.
  Copyright (C) 2023 CERN.

  Invenio is free software; you can redistribute it and/or modify it
  under the terms of the MIT License; see LICENSE file for more details.
#}

{% macro list_vocabulary_values(values) %}
  {% if values.title_l10n is defined %}
    {{ values.title_l10n }}
  {% else %}
    {% for value in values %}
      {{ value.title_l10n }}{{ ", " if not loop.last }}
    {% endfor %}
  {% endif %}
{% endmacro %}

{% macro list_string_values(values) %}
  {% for value in values %}
    {{ value }}{{ ", " if not loop.last }}
  {% endfor %}
{% endmacro %}

{% macro show_custom_field(value, config) %}
  {% if value is string %}
    <dd>{{ value | safe }}</dd>
  {% elif value is boolean %}
    <dd>
      {% if value %}
        {{ config.props.trueLabel}}
      {% else %}
        {{ config.props.falseLabel }}
      {% endif %}
    </dd>
  {% elif config.is_vocabulary %}
    <dd>{{ list_vocabulary_values(value) }}</dd>
  {% elif value is mapping and value|length > 0 and value[0] is string %}
    <dd>{{ list_string_values(value) }}</dd>
  {% else %}
    <dd>{{ value }}</dd>
  {% endif %}
{% endmacro %}
