import(common.tpl)

//subscription fields
[data-v-subscription-subscription_id]|innerText = $this->subscription['subscription_id'] ?? ''
[data-v-subscription-plan_name]|innerText      = $this->subscription['plan_name'] ?? ''
[data-v-subscription-product_name]|innerText    = $this->subscription['product_name'] ?? ''
[data-v-subscription-product_name]|href         = <?php echo Vvveb\url('product/product/index', ['slug' => $this->subscription['product_slug'] ?? '']);?>
[data-v-subscription-order_id]|innerText        = $this->subscription['order_id'] ?? ''
[data-v-subscription-price]|innerText           = $this->subscription['price'] ?? ''
[data-v-subscription-quantity]|innerText        = $this->subscription['quantity'] ?? ''
[data-v-subscription-period]|innerText           = $this->subscription['period'] ?? ''
[data-v-subscription-cycle]|innerText            = $this->subscription['cycle'] ?? ''
[data-v-subscription-length]|innerText           = $this->subscription['length'] ?? ''
[data-v-subscription-left]|innerText              = $this->subscription['left'] ?? ''
[data-v-subscription-date_next]|innerText        = $this->subscription['date_next'] ?? ''
[data-v-subscription-status_name]|innerText      = $this->subscription['status_name'] ?? ''
[data-v-subscription-created_at]|innerText       = $this->subscription['created_at'] ?? ''
[data-v-subscription-updated_at]|innerText       = $this->subscription['updated_at'] ?? ''

//trial fields
[data-v-subscription-trial_price]|innerText     = $this->subscription['trial_price'] ?? ''
[data-v-subscription-trial_period]|innerText     = $this->subscription['trial_period'] ?? ''
[data-v-subscription-trial_cycle]|innerText       = $this->subscription['trial_cycle'] ?? ''
[data-v-subscription-trial_length]|innerText     = $this->subscription['trial_length'] ?? ''
[data-v-subscription-trial_left]|innerText        = $this->subscription['trial_left'] ?? ''

//action buttons — only show relevant actions based on current status
form[data-v-action-cancel]|action = <?php echo Vvveb\url('user/subscription/cancel', ['subscription_id' => $this->subscription['subscription_id'] ?? 0]);?>
form[data-v-action-pause]|action  = <?php echo Vvveb\url('user/subscription/pause', ['subscription_id' => $this->subscription['subscription_id'] ?? 0]);?>
form[data-v-action-resume]|action = <?php echo Vvveb\url('user/subscription/resume', ['subscription_id' => $this->subscription['subscription_id'] ?? 0]);?>

//show/hide action buttons based on status
form[data-v-action-cancel]|delete = <?php if (!in_array((int)($this->subscription['subscription_status_id'] ?? 0), [2, 1])) { ?>@_SELF_@<?php } ?>
form[data-v-action-pause]|delete  = <?php if ((int)($this->subscription['subscription_status_id'] ?? 0) !== 2) { ?>@_SELF_@<?php } ?>
form[data-v-action-resume]|delete = <?php if ((int)($this->subscription['subscription_status_id'] ?? 0) !== 1) { ?>@_SELF_@<?php } ?>

//status badge class
[data-v-subscription-status_name]|addClass = <?php
$statusId = $this->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',
};
?>

//subscription logs/history
@subscription_logs = [data-v-subscription-logs] [data-v-subscription-log]
@subscription_logs|deleteAllButFirstChild

@subscription_logs|before = <?php
if (isset($this->subscription_logs) && is_array($this->subscription_logs)) {
	foreach ($this->subscription_logs as $log) { ?>

	@subscription_logs [data-v-subscription-log-status_name]|innerText = $log['status_name'] ?? ''
	@subscription_logs [data-v-subscription-log-note]|innerText         = $log['note'] ?? ''
	@subscription_logs [data-v-subscription-log-created_at]|innerText    = $log['created_at'] ?? ''

	@subscription_logs|after = <?php
	}
} ?>

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