import(common.tpl)
import(pagination.tpl)

@subscriptions = [data-v-subscriptions] [data-v-subscription]
@subscriptions|deleteAllButFirstChild

@subscriptions|before = <?php
$count = 0;
if (isset($this->subscriptions) && is_array($this->subscriptions)) {
	foreach ($this->subscriptions as $index => $subscription) { ?>

	@subscriptions [data-v-subscription-subscription_id]|innerText = $subscription['subscription_id']
	@subscriptions [data-v-subscription-subscription_id]|href     = <?php echo Vvveb\url('user/subscription/index', ['subscription_id' => $subscription['subscription_id']]);?>

	@subscriptions [data-v-subscription-plan_name]|innerText      = $subscription['plan_name'] ?? ''
	@subscriptions [data-v-subscription-product_name]|innerText    = $subscription['product_name'] ?? ''
	@subscriptions [data-v-subscription-product_name]|href         = <?php echo Vvveb\url('product/product/index', ['slug' => $subscription['product_slug'] ?? '']);?>

	@subscriptions [data-v-subscription-price]|innerText           = $subscription['price']
	@subscriptions [data-v-subscription-quantity]|innerText        = $subscription['quantity']
	@subscriptions [data-v-subscription-period]|innerText          = $subscription['cycle'] . ' ' . $subscription['period']
	@subscriptions [data-v-subscription-date_next]|innerText       = $subscription['date_next']
	@subscriptions [data-v-subscription-status_name]|innerText     = $subscription['status_name'] ?? ''

	@subscriptions [data-v-subscription-created_at]|innerText      = $subscription['created_at']
	@subscriptions [data-v-subscription-updated_at]|innerText      = $subscription['updated_at']

	@subscriptions|after = <?php
		$count++;
	}
} ?>

//status badge classes
@subscriptions [data-v-subscription-status_name]|addClass = <?php
$statusId = $subscription['subscription_status_id'] ?? 0;
echo match((int)$statusId) {
	1 => 'badge bg-warning text-dark',
	2 => 'badge bg-success',
	3 => 'badge bg-danger',
	4 => 'badge bg-secondary',
	5 => 'badge bg-danger',
	6 => 'badge bg-dark',
	default => 'badge bg-info',
};
?>

//show empty message when no subscriptions
[data-v-if-not-subscriptions]|delete = <?php if (!empty($this->subscriptions)) { ?>@_SELF_@<?php } ?>
[data-v-if-subscriptions]|delete     = <?php if (empty($this->subscriptions)) { ?>@_SELF_@<?php } ?>
