{% set onListingPage = entry and entry.type.handle == "locationsListing" %}

{% embed "_organisms/card" with {
	self: {
		image: item.featureImage[0]|default,
		heading: item.title,
		text: item.summary,
		url: onListingPage ? entry.url ~ "/" ~ item.slug : item.url,
		classes: "card--strip",
	}
} %}
	{% block cardHeading %}

		{{ parent() }}

		{% import "macros" as macros %}

		{# Let's only show relevant types on the listing page #}
		{% if onListingPage %}
			{% set listingTypeIds = entry.locationsTypes|map(c => c.id) %}

			{% set types = [item.locationsTypePrimary[0]|default] %}
			{% set types = types|merge(
				item.locationsTypeSecondary|filter(c => c.id in listingTypeIds)
			) %}
		{% else %}
			{% set types = [item.locationsTypePrimary[0]|default] %}
		{% endif %}

		{% include "_molecules/datalist" with {
			self: {
				classes: ["mt-3", "mb-5", "w-full"],
				items: [
					{
						key: macros.icon("outline/tag"),
						aria: "Location Type",
						value: types|join(", "),
					},
					{
						key: macros.icon("outline/location-marker"),
						aria: "Address",
						value: macros.formatAddress(item.addressesLineOne, item.addressesLineTwo, item.addressesSuburb, item.addressesState, item.addressesPostCode),
					},
				]
			}
		} %}

	{% endblock %}

	{% block cardContent %}

		{{ parent() }}

		{% if item.locationsFeatures|default %}
			<div class="mt-8">
				{% include "_molecules/tag-cloud" with {
					self: {
						tags: item.locationsFeatures,
					}
				} %}
			</div>
		{% endif %}

	{% endblock %}

{% endembed %}
