{* Section: Adressen *}

<div class="admin2000-form-section">
<div class="admin2000-form-section-title">Adressen</div>

{if $customer_addresses}
<div class="admin2000-address-grid">
	{foreach from=$customer_addresses item=address}
	<div class="admin2000-address-card">
		<div class="admin2000-address-card-header">
			Adresse
			{if $address.id == $customer_data.default_address}
				<span class="admin2000-badge-primary">Standard</span>
			{/if}
		</div>

		<div class="admin2000-address-card-body">
			{* Honorific (0=Herr, 1=Frau, 2=Firma) *}
			{if $address.honorific == 0}
				<div class="admin2000-address-honorific">Herr</div>
			{elseif $address.honorific == 1}
				<div class="admin2000-address-honorific">Frau</div>
			{elseif $address.honorific == 2}
				<div class="admin2000-address-honorific">Firma</div>
			{/if}

			{if $address.company != ''}
				<div class="admin2000-address-company">{$address.company|escape:'html'}</div>
			{/if}

			<div class="admin2000-address-name">
				{$address.firstname|escape:'html'} {$address.surname|escape:'html'}
			</div>

			<div class="admin2000-address-street">
				{$address.street|escape:'html'} {$address.house_number|escape:'html'}
			</div>

			<div class="admin2000-address-city">
				{$address.zip_code|escape:'html'} {$address.city|escape:'html'}
			</div>

			{if $address.country_name}
				<div class="admin2000-address-country">{$address.country_name|escape:'html'}</div>
			{/if}
		</div>

		<div class="admin2000-address-card-actions">
			{if $address.id != $customer_data.default_address}
				<button type="button" class="admin2000-btn-small admin2000-btn-secondary set-standard-address" data-address-id="{$address.id}">
					Standard setzen
				</button>
			{/if}
			<a href="./index.php?admin_modul=admin_customer_actions&action=edit_customer_address&address_id={$address.id}" class="admin2000-btn-small admin2000-btn-primary">
				Bearbeiten
			</a>
			<button type="button" class="admin2000-btn-small admin2000-btn-danger delete-address" data-address-id="{$address.id}">
				Löschen
			</button>
		</div>
	</div>
	{/foreach}

	{* Add New Address Card *}
	<div class="admin2000-address-card admin2000-address-card-add">
		<a href="./index.php?admin_modul=admin_customer_actions&action=new_customer_address&customer_id={$customer_id}" class="admin2000-address-add-link">
			<div class="admin2000-address-add-icon">+</div>
			<div class="admin2000-address-add-text">Neue Adresse hinzufügen</div>
		</a>
	</div>
</div>
{else}
<div class="admin2000-empty-state">
	<p>Keine Adressen vorhanden</p>
	<a href="./index.php?admin_modul=admin_customer_actions&action=new_customer_address&customer_id={$customer_id}" class="admin2000-btn admin2000-btn-primary">
		Erste Adresse hinzufügen
	</a>
</div>
{/if}

</div>

<script>
$(document).ready(function() {
	// Delete address confirmation
	$('.delete-address').click(function() {
		var addressId = $(this).data('address-id');
		if (confirm('Adresse wirklich löschen?')) {
			// TODO: AJAX delete call
			window.location.href = './index.php?admin_modul=admin_customer_actions&action=delete_customer_address&address_id=' + addressId + '&customer_id={$customer_id}';
		}
	});

	// Set standard address
	$('.set-standard-address').click(function() {
		var addressId = $(this).data('address-id');
		// TODO: AJAX call to set standard
		window.location.href = './index.php?admin_modul=admin_customer_actions&action=set_standard_address&address_id=' + addressId + '&customer_id={$customer_id}';
	});
});
</script>
