| 1 |
<?php |
| 2 |
/** |
| 3 |
* Plan detail view. Uses the shared WPSubsTabs component (client-side tabs - |
| 4 |
* no page reload): Durations | Products (read-only). |
| 5 |
* |
| 6 |
* @var array $plan Plan (PlanPresenter shape). |
| 7 |
* @var string $list_url Base list URL. |
| 8 |
* |
| 9 |
* @package SpringDevs\Subscription\Admin |
| 10 |
*/ |
| 11 |
|
| 12 |
if ( ! defined( 'ABSPATH' ) ) { |
| 13 |
exit; |
| 14 |
} |
| 15 |
|
| 16 |
use SpringDevs\Subscription\Admin\Plans; |
| 17 |
?> |
| 18 |
<div class="wp-subscription-admin-content list-page"> |
| 19 |
<div data-plan-type="<?php echo esc_attr( $plan['type'] ); ?>" data-plan-id="<?php echo esc_attr( $plan['id'] ); ?>"> |
| 20 |
|
| 21 |
<!-- Page header (mirrors the subscription details head) --> |
| 22 |
<?php |
| 23 |
$term_count = count( $plan['terms'] ); |
| 24 |
$product_count = count( $plan['products'] ); |
| 25 |
$sep = '<span style="color:var(--wpsubs-text-subtle);">·</span>'; |
| 26 |
|
| 27 |
$meta = array(); |
| 28 |
$meta[] = '<span class="wpsubs-badge wpsubs-badge--neutral">' . esc_html( Plans::type_label( $plan['type'] ) ) . '</span>'; |
| 29 |
if ( 'draft' === $plan['status'] ) { |
| 30 |
$meta[] = '<span class="wpsubs-badge wpsubs-badge--draft">' . esc_html__( 'Draft', 'subscription' ) . '</span>'; |
| 31 |
} |
| 32 |
/* translators: %d: number of durations. */ |
| 33 |
$meta[] = esc_html( sprintf( _n( '%d duration', '%d durations', $term_count, 'subscription' ), $term_count ) ); |
| 34 |
/* translators: %d: number of connected products. */ |
| 35 |
$meta[] = esc_html( sprintf( _n( '%d product', '%d products', $product_count, 'subscription' ), $product_count ) ); |
| 36 |
?> |
| 37 |
<?php |
| 38 |
/* |
| 39 |
* Two columns: the title block on the left, the tab-scoped actions on |
| 40 |
* the right. The actions belong on the title's line rather than on the |
| 41 |
* tab rule, so the page has a single header row to read across. |
| 42 |
*/ |
| 43 |
?> |
| 44 |
<div style="display:flex;align-items:flex-start;gap:16px;margin-bottom:4px;"> |
| 45 |
<div style="flex:1 1 auto;min-width:0;"> |
| 46 |
<div style="display:flex;align-items:center;flex-wrap:wrap;gap:10px;margin:0 0 8px;" data-subscrpt-rename> |
| 47 |
<h1 data-subscrpt-rename-display style="font-size:1.375rem;font-weight:700;color:var(--wpsubs-text);margin:0;line-height:1.2;"><?php echo esc_html( $plan['name'] ); ?></h1> |
| 48 |
<button type="button" class="wpsubs-icon-action" data-subscrpt-rename-open title="<?php esc_attr_e( 'Rename plan', 'subscription' ); ?>" aria-label="<?php esc_attr_e( 'Rename plan', 'subscription' ); ?>"> |
| 49 |
<span class="dashicons dashicons-edit"></span> |
| 50 |
</button> |
| 51 |
<?php // Buttons match the input's 36px height — no --sm here. ?> |
| 52 |
<span data-subscrpt-rename-form style="display:none;align-items:center;gap:8px;"> |
| 53 |
<input type="text" class="wpsubs-input" data-subscrpt-rename-input value="<?php echo esc_attr( $plan['name'] ); ?>" aria-label="<?php esc_attr_e( 'Plan name', 'subscription' ); ?>" style="min-width:260px;" /> |
| 54 |
<button type="button" class="wpsubs-btn wpsubs-btn--primary" data-subscrpt-rename-save><?php esc_html_e( 'Save', 'subscription' ); ?></button> |
| 55 |
<button type="button" class="wpsubs-btn wpsubs-btn--outline" data-subscrpt-rename-cancel><?php esc_html_e( 'Cancel', 'subscription' ); ?></button> |
| 56 |
</span> |
| 57 |
</div> |
| 58 |
<div style="display:flex;align-items:center;flex-wrap:wrap;gap:8px;font-size:13px;color:var(--wpsubs-text-muted);margin:0;line-height:1.5;"> |
| 59 |
<?php echo wp_kses_post( implode( $sep, $meta ) ); ?> |
| 60 |
</div> |
| 61 |
</div> |
| 62 |
|
| 63 |
<?php // One slot, one button: each tab's primary action, swapped by plans.js. ?> |
| 64 |
<div style="flex:0 0 auto;display:flex;align-items:center;gap:8px;"> |
| 65 |
<button type="button" class="wpsubs-btn wpsubs-btn--primary" data-wpsubs-modal-open="subscrpt-term-modal" data-subscrpt-add-term data-subscrpt-tab-action="subscrpt-tab-selling"> |
| 66 |
<span class="dashicons dashicons-plus-alt2" style="font-size:16px;width:16px;height:16px;line-height:1;"></span> |
| 67 |
<?php esc_html_e( 'Add Duration', 'subscription' ); ?> |
| 68 |
</button> |
| 69 |
<?php // Nothing to manage until a product is attached — the empty state invites the first one. ?> |
| 70 |
<?php if ( ! empty( $plan['terms'] ) && ! empty( $plan['products'] ) ) : ?> |
| 71 |
<button type="button" class="wpsubs-btn wpsubs-btn--primary" data-wpsubs-modal-open="subscrpt-add-product" data-subscrpt-tab-action="subscrpt-tab-products"> |
| 72 |
<span class="dashicons dashicons-edit" style="font-size:16px;width:16px;height:16px;line-height:1;"></span> |
| 73 |
<?php esc_html_e( 'Manage Products', 'subscription' ); ?> |
| 74 |
</button> |
| 75 |
<?php endif; ?> |
| 76 |
</div> |
| 77 |
</div> |
| 78 |
|
| 79 |
<div class="wpsubs-tabs" data-tabs-query="tab"> |
| 80 |
<div class="wpsubs-tabs__list" role="tablist"> |
| 81 |
<button class="wpsubs-tabs__tab" role="tab" id="subscrpt-tab-selling" data-tab-key="plans" aria-controls="subscrpt-panel-selling" aria-selected="true"> |
| 82 |
<?php esc_html_e( 'Durations', 'subscription' ); ?> |
| 83 |
</button> |
| 84 |
<button class="wpsubs-tabs__tab" role="tab" id="subscrpt-tab-products" data-tab-key="products" aria-controls="subscrpt-panel-products" aria-selected="false"> |
| 85 |
<?php esc_html_e( 'Products', 'subscription' ); ?> |
| 86 |
</button> |
| 87 |
</div> |
| 88 |
|
| 89 |
<div class="wpsubs-tab-panel" role="tabpanel" id="subscrpt-panel-selling" aria-labelledby="subscrpt-tab-selling"> |
| 90 |
<?php require __DIR__ . '/tab-selling-plans.php'; ?> |
| 91 |
</div> |
| 92 |
|
| 93 |
<div class="wpsubs-tab-panel" role="tabpanel" id="subscrpt-panel-products" aria-labelledby="subscrpt-tab-products" hidden> |
| 94 |
<?php require __DIR__ . '/tab-products.php'; ?> |
| 95 |
</div> |
| 96 |
</div> |
| 97 |
|
| 98 |
</div> |
| 99 |
</div> |
| 100 |
|
| 101 |
<?php require __DIR__ . '/modal-term.php'; ?> |
| 102 |
|