{% comment %}
  Renders icon with text block

  Accepts:
  - block: {Object} passes in the block information.

  Usage:
  {% render 'ascendify-icon-with-text',
    block: block
  %}
{% endcomment %}
{%- liquid
  assign heading_1_empty = false
  assign heading_2_empty = false
  assign heading_3_empty = false
  assign text_only_all_items = true

  if block.settings.heading_1 == empty
    assign heading_1_empty = true
  endif

  if block.settings.heading_2 == empty
    assign heading_2_empty = true
  endif

  if block.settings.heading_3 == empty
    assign heading_3_empty = true
  endif

  if heading_1_empty == false and block.settings.icon_1 != 'none' or block.settings.image_1 != null
    assign text_only_all_items = false
  elsif heading_2_empty == false and block.settings.icon_2 != 'none' or block.settings.image_2 != null
    assign text_only_all_items = false
  elsif heading_3_empty == false and block.settings.icon_3 != 'none' or block.settings.image_3 != null
    assign text_only_all_items = false
  endif
-%}

{%- style -%}
{% if block.settings.icon_with_text_background %}
.icon-with-text--horizontal .icon-with-text__item {
    background: {{ block.settings.icon_with_text_backgroundcolor }};
    padding: 10px;
    border-radius: {{ block.settings.icon_with_text_backgroundradius }}px;
}
{% endif %}
{%- endstyle -%}

<ul
  class="icon-with-text icon-with-text--icon-{{ block.settings.icon_size }} icon-with-text--{{ block.settings.layout }} list-unstyled{% if text_only_all_items %} icon-with-text--text-only{% endif %} {{ block.settings.visibility }}"
  style="--desktop-icon-size: {{ block.settings.desktop_icon_size | divided_by: 10.0 }}rem; --desktop-spacing: {{ block.settings.desktop_spacing | divided_by: 10.0 }}rem; --desktop-text-size: {{ block.settings.desktop_text_size | divided_by: 10.0 }}rem; --mobile-icon-size: {{ block.settings.mobile_icon_size | divided_by: 10.0 }}rem; --mobile-spacing: {{ block.settings.mobile_spacing | divided_by: 10.0 }}rem; --mobile-text-size: {{ block.settings.mobile_text_size | divided_by: 10.0 }}rem;--margin-top: {{ block.settings.margin_top | divided_by: 10.0 }}rem;--margin-bottom: {{ block.settings.margin_bottom | divided_by: 10.0 }}rem;"
  {{ block.shopify_attributes }}
>
  {%- unless heading_1_empty -%}
    <li class="icon-with-text__item">
      {%- if block.settings.image_1 == null -%}
        {% render 'material-icon', icon: block.settings.icon_1, filled: block.settings.icon_1_fill, custom_color: block.settings.icon_color %}
      {%- else -%}
        <img
          src="{{ block.settings.image_1 | image_url }}"
          {% if block.settings.image_1.alt != blank %}
            alt="{{ block.settings.image_1.alt | escape }}"
          {% else %}
            role="presentation"
          {% endif %}
          height="auto"
          width="auto"
          loading="lazy"
        >
      {%- endif -%}
      <span class="h4">
        {{- block.settings.heading_1 -}}
      </span>
    </li>
  {%- endunless -%}
  {%- unless heading_2_empty -%}
    <li class="icon-with-text__item">
      {%- if block.settings.image_2 == null -%}
        {% render 'material-icon', icon: block.settings.icon_2, filled: block.settings.icon_2_fill, custom_color: block.settings.icon_color %}
      {%- else -%}
        <img
          src="{{ block.settings.image_2 | image_url }}"
          {% if block.settings.image_2.alt != blank %}
            alt="{{ block.settings.image_2.alt | escape }}"
          {% else %}
            role="presentation"
          {% endif %}
          height="auto"
          width="auto"
          loading="lazy"
        >
      {%- endif -%}
      <span class="h4">
        {{- block.settings.heading_2 -}}
      </span>
    </li>
  {%- endunless -%}
  {%- unless heading_3_empty -%}
    <li class="icon-with-text__item">
      {%- if block.settings.image_3 == null -%}
        {% render 'material-icon', icon: block.settings.icon_3, filled: block.settings.icon_3_fill, custom_color: block.settings.icon_color %}
      {%- else -%}
        <img
          src="{{ block.settings.image_3 | image_url }}"
          {% if block.settings.image_3.alt != blank %}
            alt="{{ block.settings.image_3.alt | escape }}"
          {% else %}
            role="presentation"
          {% endif %}
          height="auto"
          width="auto"
          loading="lazy"
        >
      {%- endif -%}
      <span class="h4">
        {{- block.settings.heading_3 -}}
      </span>
    </li>
  {%- endunless -%}
</ul>
