| 1 |
<?php |
| 2 |
/** |
| 3 |
* Preview-only Booking Mode selector for Setup Wizard Step 4. |
| 4 |
* |
| 5 |
* @package Booking Calendar |
| 6 |
* @var array<string,mixed> $template_context Authorized toolbar context. |
| 7 |
*/ |
| 8 |
|
| 9 |
if ( ! defined( 'ABSPATH' ) ) { |
| 10 |
exit; |
| 11 |
} |
| 12 |
|
| 13 |
$step_data = isset( $template_context['step_data'] ) && is_array( $template_context['step_data'] ) ? $template_context['step_data'] : array(); |
| 14 |
$experiences = isset( $step_data['experiences'] ) && is_array( $step_data['experiences'] ) ? $step_data['experiences'] : array(); |
| 15 |
$selected_mode_id = isset( $step_data['values']['booking_experience'] ) ? sanitize_key( (string) $step_data['values']['booking_experience'] ) : ''; |
| 16 |
$selected_mode_title = ''; |
| 17 |
$selector_items = array(); |
| 18 |
|
| 19 |
foreach ( $experiences as $experience ) { |
| 20 |
if ( ! is_array( $experience ) || empty( $experience['id'] ) || empty( $experience['toolbar_label'] ) || empty( $experience['toolbar_title'] ) ) { |
| 21 |
continue; |
| 22 |
} |
| 23 |
|
| 24 |
$mode_id = sanitize_key( (string) $experience['id'] ); |
| 25 |
$toolbar_label = sanitize_text_field( (string) $experience['toolbar_label'] ); |
| 26 |
$toolbar_title = sanitize_text_field( (string) $experience['toolbar_title'] ); |
| 27 |
$is_selected = $selected_mode_id === $mode_id; |
| 28 |
$attributes = array( |
| 29 |
'class' => 'wpbc_setup_wizard__mode-toolbar-option' . ( $is_selected ? ' is-current' : '' ), |
| 30 |
'data-wpbc-setup-wizard-mode-toolbar-option' => $mode_id, |
| 31 |
'data-wpbc-setup-wizard-mode-toolbar-title' => $toolbar_title, |
| 32 |
'role' => 'menuitemradio', |
| 33 |
'aria-checked' => $is_selected ? 'true' : 'false', |
| 34 |
); |
| 35 |
|
| 36 |
if ( $is_selected ) { |
| 37 |
$selected_mode_title = $toolbar_title; |
| 38 |
} |
| 39 |
|
| 40 |
$selector_items[] = array( |
| 41 |
'type' => 'link', |
| 42 |
'title' => $toolbar_label, |
| 43 |
'url' => '#', |
| 44 |
'attr' => $attributes, |
| 45 |
); |
| 46 |
} |
| 47 |
|
| 48 |
if ( empty( $selector_items ) ) { |
| 49 |
return; |
| 50 |
} |
| 51 |
|
| 52 |
if ( '' === $selected_mode_title ) { |
| 53 |
$selected_mode_title = (string) $selector_items[0]['attr']['data-wpbc-setup-wizard-mode-toolbar-title']; |
| 54 |
} |
| 55 |
?> |
| 56 |
<div class="wpbc_setup_wizard__mode-toolbar-preview" data-wpbc-setup-wizard-mode-toolbar> |
| 57 |
<?php |
| 58 |
wpbc_ui_el__divider_vertical( |
| 59 |
array( |
| 60 |
'class' => 'wpbc_booking_modes_toolbar_divider wpbc_ui_el__vertical_line', |
| 61 |
) |
| 62 |
); |
| 63 |
wpbc_ui_el__dropdown_menu( |
| 64 |
array( |
| 65 |
'title_html' => '<span class="nav-tab-text" data-wpbc-setup-wizard-mode-toolbar-label>' . esc_html( $selected_mode_title ) . '</span>', |
| 66 |
'has_border' => false, |
| 67 |
'class' => 'wpbc_booking_modes_toggle wpbc_setup_wizard__mode-toolbar-toggle', |
| 68 |
'container_class' => 'wpbc_booking_modes_selector wpbc_setup_wizard__mode-toolbar-selector', |
| 69 |
'attr' => array( |
| 70 |
'aria-label' => __( 'Booking Calendar administration mode preview', 'booking' ), |
| 71 |
), |
| 72 |
'items' => $selector_items, |
| 73 |
) |
| 74 |
); |
| 75 |
?> |
| 76 |
<div |
| 77 |
class="wpbc_setup_wizard__mode-toolbar-tooltip" |
| 78 |
data-wpbc-setup-wizard-mode-toolbar-tooltip |
| 79 |
role="status" |
| 80 |
aria-live="polite" |
| 81 |
aria-hidden="true" |
| 82 |
> |
| 83 |
<?php esc_html_e( 'You can change the Booking Mode here at any time after setup.', 'booking' ); ?> |
| 84 |
</div> |
| 85 |
</div> |
| 86 |
|