{% from "govuk_frontend_jinja/components/table/macro.html" import govukTable %}
{% from "govuk_frontend_jinja/components/tag/macro.html" import govukTag %}

{% macro render_data_set_data_with_missing_data_grant_recipients(column_names,missing_data_rows,all_row_data) %}

  {% set table_head = [{"text": constants.data_set_external_id_column_header}, {"text": constants.data_set_grant_recipient_column_header}] %}
  {% for column in column_names %}
    {% do table_head.append({"text": column}) %}
  {% endfor %}

  {% set rows = [] %}
  {% for missing_data_row in missing_data_rows %}
    {% set data_row = all_row_data[missing_data_row.row_number] %}

    {% set row_cells = [{"text": missing_data_row.external_id}] %}

    {% if missing_data_row.grant_recipient_entirely_missing %}
      {% do row_cells.append({"html": govukTag({"text": "Grant recipient missing", "classes": "govuk-tag--red app-status-tag"}) ~ " " ~ missing_data_row.grant_recipient_name}) %}
    {% else %}
      {% do row_cells.append({"text": missing_data_row.grant_recipient_name}) %}
    {% endif %}

    {% for column in column_names %}
      {% if missing_data_row.grant_recipient_entirely_missing or column in missing_data_row.missing_columns %}
        {% do row_cells.append({"html": govukTag({"text": "Data missing", "classes": "govuk-tag--orange"})}) %}
      {% else %}
        {% do row_cells.append({"text": data_row.get(column, "")}) %}
      {% endif %}
    {% endfor %}
    {% do rows.append(row_cells) %}
  {% endfor %}

  {{ govukTable({"head": table_head, "rows": rows}) }}
{% endmacro %}
