{%- comment -%} Remove leading and trailing whitespace from `tag_name`. {%- endcomment -%}
{%- assign tag_name = tag_name | strip -%}
{%- comment -%} Handle the `tag_name: ''` case. {%- endcomment -%}
{%- if tag_name and tag_name.size < 1 -%}
    {%- assign tag_name = false -%}
{%- endif -%}
{%- if tag_name -%}
    <{{ tag_name }} 
    {{- attrs | to_attrs -}}
    {{- additional_attrs -}}
    {%- if self_closing == true -%}
        {{- ' /' -}}
    {%- endif -%}
    >
{%- endif -%}
{%- unless self_closing == true -%}
    {%- ifslot -%}
        {%- slot -%}
    {%- else -%}
        {{- inner_html -}}
    {%- endifslot -%}
    {%- if tag_name -%}
        </
        {{- tag_name -}}
        >
    {%- endif -%}
{%- endunless -%}{%- comment -%}
    This component can generate an `img` tag or a `div style="background-..."`.
{%- endcomment -%}
{%- assign is_global_asset = is_global_asset | default: false -%}
{%- if bg -%}
    {%- comment -%} Background image {%- endcomment -%}
    {%- assign tag_name = tag_name | default: 'div' -%}
    {%- assign self_closing = self_closing | default: false -%}
    {%- comment -%} We render attrs ourselves and filter out `style`. {%- endcomment -%}
    {%- assign attr_list = attrs | to_attrs: list: true -%}
    {%- capture additional_attrs -%}
        {%- comment -%} Include attributes from context. {%- endcomment -%}
        {%- for attr in attr_list -%}
            {%- unless attr[0] == 'style' -%}
                {{- ' ' -}}
                {{- attr[0] -}}
                {%- if attr[1].size > 0 -%}
                    ="{{- attr[1] -}}"
                {%- endif -%}
            {%- endunless -%}
        {%- endfor -%}
        {{- ' ' -}}
        style="
            {%- comment -%} Render bg styles. Use src if we didn't get an image. {%- endcomment -%}
            {%- assign has_bg_image = false -%}
            {%- assign has_bg_size = false -%}
            {%- assign has_bg_position_x = false -%}
            {%- assign has_bg_position_y = false -%}
            {%- assign has_bg_repeat = false -%}
            {%- for prop in bg -%}
                {%- case prop[0] -%}
                    {%- when 'image' -%}
                        {%- assign has_bg_image = true -%}
                    {%- when 'size' -%}
                        {%- assign has_bg_size = true -%}
                    {%- when 'position' -%}
                        {%- assign has_bg_position_x = true -%}
                        {%- assign has_bg_position_y = true -%}
                    {%- when 'position-x' -%}
                        {%- assign has_bg_position_x = true -%}
                    {%- when 'position-y' -%}
                        {%- assign has_bg_position_y = true -%}
                    {%- when 'repeat' -%}
                        {%- assign has_bg_repeat = true -%}
                {%- endcase -%}
                background-{{- prop[0] -}}: {{- prop[1] -}};
            {%- endfor -%}
            {%- unless has_bg_image -%}
                background-image: url('{{- src | asset_url: global: is_global_asset -}}');
            {%- endunless -%}
            {%- unless has_bg_size -%}
                background-size: cover;
            {%- endunless -%}
            {%- unless has_bg_position_x -%}
                background-position-x: center;
            {%- endunless -%}
            {%- unless has_bg_position_y -%}
                background-position-y: center;
            {%- endunless -%}
            {%- unless has_bg_repeat -%}
                background-repeat: no-repeat;
            {%- endunless -%}
            {%- comment -%} Add any styles from the style attribute. {%- endcomment -%}
            {{- attrs.style -}}
        "
    {%- endcapture -%}
    {%- comment -%} Remove attrs so we don't render them twice. {%- endcomment -%}
    {%- assign attrs = nil -%}
{%- else -%}
    {%- comment -%} Normal img tag {%- endcomment -%}
    {%- assign tag_name = 'img' -%}
    {%- assign self_closing = true -%}
    {%- capture additional_attrs -%}
        {%- if srcset.size > 0 -%}
            {{- ' ' -}}
            srcset="{{ srcset }}"
        {%- endif -%}
        {%- if sizes.size > 0 -%}
            {{- ' ' -}}
            sizes="{{ sizes }}"
        {%- endif -%}
        {{- ' ' -}}
        alt="{{ alt }}"
        {{- ' ' -}}
        src="{{ src | asset_url: global: is_global_asset }}"
    {%- endcapture -%}
{%- endif -%}
{%- include 'atom/element', tag_name: tag_name, self_closing: self_closing, additional_attrs: additional_attrs -%}{%- assign group_attrs = group.attrs | merge_props: class: 'listcard__group' -%}
{%- assign tag_name = 'div' -%}
{%- if collapsible -%}
    {%- assign tag_name = 'details' -%}
{%- endif -%}
<{{ tag_name }} {{ group_attrs | to_attrs }}>
    {% unless headline == false or group.headline == nil or group.headline.size == 0 %}
        {% if collapsible %}
            <summary>
        {% endif %}
        <h2 class="listcard__headline">{{ group.headline }}</h2>
        {% if collapsible %}
            </summary>
        {% endif %}
    {% endunless %}
    <div class="listcard__cards">
        {% for item in group.cards %}
            {%- include 'cardlist/listcard/item' -%}
        {% endfor %}
    </div>
    {% unless group.group_button_link == nil or group.cards.size < 4 %}
        <div class="listcard__group-button">
            <a href="{{group.group_button_link}}" class="btn">{{ group.group_button_label }}</a>
        </div>
    {% endunless %}
</{{ tag_name }}>{% assign card_count = forloop.index %}
{%- capture curr_class -%}
    listcard__card
    {%- unless item.id == nil -%}
        {{- ' ' -}} listcard__card--{{ item.id }}
    {%- endunless -%}
    {%- unless card_class == nil or card_class.size == 0 -%}
        {{- ' ' -}} listcard__card--{{ card_class }}
    {%- endunless -%}
{%- endcapture -%}
{%- assign card_attrs = item.attrs | merge_props: class: curr_class -%}
{% if singlelink %}
    {%- assign card_attrs = card_attrs | merge_props: href: item.ctas[0].link -%}
{% endif %}
{% if linkcard %}<a {{ card_attrs | to_attrs }}>{% elsif singlelink %}<a {{ card_attrs | to_attrs }}>{% else %}<div {{ card_attrs | to_attrs }}>{% endif %}
    {%- unless headline == false or item.headline == nil or item.headline.size == 0 -%}
    <h2 class="listcard__card-headline">{{ item.headline }}</h2>
    {%- endunless -%}
    {% unless subheadline == false or item.subheadline == nil or item.subheadline.size == 0 %}
    <h3 class="listcard__card-subheadline">{{ item.subheadline }}</h3>
    {% endunless %}
    {% unless images == false or item.images == nil or item.images.size == 0 %}
    {% if  compare == true %}
        <div class="listcard__card-images">
            <div class="listcard__comparison comparison comparison--popup">
                <figure style="background-image: url('{{ item.compare_img_1 | asset_url }}')">
                    <a class="listcard__card-image-link listcard__card-image-link--before" href="#view-{{ item.id }}">Before</a>
                    <div
                        class="divisor"
                        style="
                            background-image: url('{{ item.compare_img_2 | asset_url }}');
                            clip-path: inset(0 0 0 50%);
                        ">
                        <a class="listcard__card-image-link listcard__card-image-link--after" href="#view-{{ item.id }}">After</a>
                    </div>
                </figure>
                <input type="range" min="0" max="100" value="50" class="slider">
            </div>
            <div id="view-{{ item.id }}" class="modal-window comparison">
                <a href="#" class="modal-close">Close</a>
                <div class="modal-window__wrapper">
                    <figure style="background-image: url('{{ item.compare_img_1 | asset_url }}')">
                        <span class="listcard__card-image-link listcard__card-image-link--before">Before</span>
                        <div
                            class="divisor"
                            style="
                                background-image: url('{{ item.compare_img_2 | asset_url }}');
                                clip-path: inset(0 0 0 50%);
                            ">
                            <span class="listcard__card-image-link listcard__card-image-link--after">After</span>
                        </div>
                    </figure>
                    <input type="range" min="0" max="100" value="50" class="slider">                        
                </div>
            </div>
            
        </div>
    {% else %}
        {% if legacy %}
            <div class="listcard__card-images">
            {% for image in item.images %}
                {% using image %}
                    {%- comment -%}
                        We're adding a class list to the `image` data before `atom/img`.
                        If `attrs.class` already exists, our class list will be added after.
                        `capture` is needed because we're using data from `forloop.index`.
                        If we wanted to use a constant class list without dynamic data, we could do it inline like:
                            `{%- assign attrs = attrs | merge_props: class: "my-static class-list" -%}`
                    {%- endcomment -%}
                    {%- capture class -%}
                    {% if image_link -%}
                    listcard__card-image-linkable listcard__card-image-linkable--{{ forloop.index }}
                    {%- else -%}
                    listcard__card-image listcard__card-image--{{ forloop.index }}
                    {%- endif %}
                    {%- endcapture %}
                    
                    {% if image_link %}
                    {%- assign tag_name = 'a' -%}
                    {%- assign attrs = attrs | merge_props: href: image_link -%}
                    {% endif %}
                    {%- assign attrs = attrs | merge_props: class: class -%}
                    {% include "atom/img" %}
                {% endusing %}
                {% if image.modal_img %}
                    <div id="{{ image.id }}" class="modal-window">
                        <a href="#" class="modal-close">Close</a>
                        {% using image %}
                    {%- comment -%}
                        We're adding a class list to the `image` data before `atom/img`.
                        If `attrs.class` already exists, our class list will be added after.
                        `capture` is needed because we're using data from `forloop.index`.
                        If we wanted to use a constant class list without dynamic data, we could do it inline like:
                            `{%- assign attrs = attrs | merge_props: class: "my-static class-list" -%}`
                    {%- endcomment -%}
                    {%- capture class -%}
                        listcard__modal-image listcard__modal-image--{{ forloop.index }}
                    {%- endcapture -%}
                    {%- assign attrs = attrs | merge_props: class: class -%}
                    {% include "atom/img" %}
                {% endusing %}
                    </div>
                {% endif %}
            {% endfor %}
         </div>
         {% if image.image_text %}
            <p class="listcard__card-image-text listcard__card-image-text--{{forloop.index}}">{{image.image_text}}</p>
        {% endif %}
        {% else %}
            <div class="listcard__card-images">
            {% for image in item.images %}
                {% using image %}
                    {%- comment -%}
                        We're adding a class list to the `image` data before `atom/img`.
                        If `attrs.class` already exists, our class list will be added after.
                        `capture` is needed because we're using data from `forloop.index`.
                        If we wanted to use a constant class list without dynamic data, we could do it inline like:
                            `{%- assign attrs = attrs | merge_props: class: "my-static class-list" -%}`
                    {%- endcomment -%}
                    
                    {%- capture class -%}
                    {% if image_link -%}
                    listcard__card-image-linkable listcard__card-image-linkable--{{ forloop.index }}
                    {%- else -%}
                    listcard__card-image listcard__card-image--{{ forloop.index }}
                    {%- endif %}
                    {%- endcapture %}
                    
                    {% if image_link %}
                    {%- assign tag_name = 'a' -%}
                    {%- assign attrs = attrs | merge_props: href: image_link -%}
                    {% endif %}
                    {%- assign attrs = attrs | merge_props: class: class -%}
                
                    {% include "atom/img" %}
                {% endusing %}
                {% if image.image_text %}
                    <p class="listcard__card-image-text listcard__card-image-text--{{forloop.index}}">{{image.image_text}}</p>
                {% endif %}
                
            {% endfor %}
            {%- if item.images[0].modal_img -%}
                <div id="view-{{ item.id }}" class="modal-window">
                    <a class="image_next" href="#modal_next-{{ item.id }}"> > </a>
                    <a class="image_prev" href="#modal_prev-{{ item.id }}"> < </a>
                    <a href="#" class="modal-close">Close</a>
                    <div class="modal_next" id="modal_next-{{ item.id }}">
                        <div class="modal_prev" id="modal_prev-{{ item.id }}">
                            {% for image in item.images %}        
                                {% using image.modal_img %}
                                    {%- comment -%}
                                        We're adding a class list to the `image` data before `atom/img`.
                                        If `attrs.class` already exists, our class list will be added after.
                                        `capture` is needed because we're using data from `forloop.index`.
                                        If we wanted to use a constant class list without dynamic data, we could do it inline like:
                                            `{%- assign attrs = attrs | merge_props: class: "my-static class-list" -%}`
                                    {%- endcomment -%}
                                    {%- capture class -%}
                                        listcard__modal-image listcard__modal-image--{{ forloop.index }}
                                    {%- endcapture -%}
                                    {%- assign attrs = attrs | merge_props: class: class -%}
                                    {% include "atom/img" %}
                                {% endusing %}     
                            {% endfor %}
                        </div>
                    </div>
                </div>
            {%- endif -%}
            </div>
        {% endif %}
    {% endif %}
    {% endunless %}
    {% unless text == false or item.text == nil or item.text.size == 0 %}
    <div class="listcard__card-text">{{item.text}}</div>
    {% endunless %}
    {% unless details == false or item.details == nil or item.details.size == 0 %}
    <div class="listcard__card-details">
        {% for detail in item.details %}
            <div class="listcard__card-detail {{ detail.class }}">
                <h3>{{ detail.label }}</h3>
                {%- if detail.link -%}
                    <a href="{{ detail.link }}">{{ detail.text }}</a>
                {%- else -%}
                    <p>{{ detail.text }}</p>
                {%- endif -%}
            </div>
        {% endfor %}
    </div>
    {% endunless %}
    {% unless ctas == false or item.ctas == nil or item.ctas.size == 0 or linkcard or singlelink%}
    <div class="listcard__card-ctas">
        {% for cta in item.ctas %}
            <a href="{{cta.link}}" class="btn" target="{{cta.target}}">{{cta.label}}</a>
        {% endfor %}
    </div>
    {% endunless %}
    {% if singlelink %}
        <div class="listcard__card-ctas">
            {% for cta in item.ctas %}
                <div class="btn">{{cta.label}}</div>
            {% endfor %}
        </div>
    {% endif %}
{% if singlelink %}</a>{% elsif linkcard %}</a>{% else %}</div>{% endif %}
*Individual results are not guaranteed and may vary from person to person. Images may contain models.