
        <div class="panel-pad">
            <div class="row">
                <div class="col-md-6 col-border service-info">
                    <label><?php $this->_('ClientServices.manage.heading_package');?></label>
                    <h4><?php (print (isset($service->package->name) ? $this->Html->safe($service->package->name) : null));?></h4>
                    <label><?php $this->_('ClientServices.manage.heading_service_name');?></label>
                    <h4><?php (print (isset($service->name) ? $this->Html->safe($service->name) : null));?></h4>
                    <label><?php $this->_('ClientServices.manage.heading_date_added');?></label>
                    <h4><?php echo $this->Date->cast($service->date_added);?></h4>
                    <label><?php $this->_('ClientServices.manage.heading_package_term');?></label>
                    <?php
                    $package_term = '';
                    if (($service->package_pricing->period ?? null) == 'onetime') {
                        $package_term = ($periods[$service->package_pricing->period] ?? null);
                    } else {
                        $term = (isset($service->package_pricing->term) ? $this->Html->safe($service->package_pricing->term) : null);
                        $package_term = $this->Html->concat(' ', $term, ($term == 1 ? ($periods[$service->package_pricing->period] ?? null) : ($periods[$service->package_pricing->period . '_plural'] ?? null)));
                    }
                    ?>
                    <h4><?php (print (isset($package_term) ? $this->Html->safe($package_term) : null));?></h4>
                </div>
                <div class="col-md-6 service-info">
                    <label><?php $this->_('ClientServices.index.heading_status');?></label>
                    <?php
                    $button = [
                        'status' => $service->status,
                        'class' => in_array(($service->status ?? null), ['suspended', 'canceled']) ? 'danger' : (($service->status ?? null) == 'active' ? 'success' : 'warning')
                    ];
                    ?>
                    <h4>
                        <div class="badge badge-<?php (print (isset($button['class']) ? $this->Html->safe($button['class']) : null));?>">
                            <?php $this->_('ClientServices.manage.button_' . (isset($button['status']) ? $this->Html->safe($button['status']) : null));?>
                        </div>
                    </h4>

                    <label><?php $this->_('ClientServices.manage.heading_date_renews');?></label>
                    <h4>
                        <?php
                        echo empty($service->date_paid_through)
                            ? (empty($service->date_renews)
                                ? $this->_('ClientServices.manage.text_adte_never', true)
                                : $this->Date->cast($service->date_renews))
                            : $this->Date->cast($service->date_paid_through);
                        ?>
                    </h4>
                    <label><?php $this->_('ClientServices.manage.heading_date_next_invoice');?></label>
                    <h4>
                        <?php
                        if (($next_invoice_date ?? false)) {
                            echo $this->Date->cast($next_invoice_date);
                        } else {
                            $this->_('ClientServices.manage.text_date_never');
                        }
                        ?>
                    </h4>
                    <label><?php $this->_('ClientServices.manage.heading_price' . (($service->package_pricing->period ?? null) == 'onetime' ? '_onetime' : ''));?></label>
                    <h4>
                        <?php
                        $currency = ($service->override_currency ?? ($service->package_pricing->currency ?? null));
                        if (($service->package_pricing->period ?? null) == 'onetime') {
                            $price = ($service->override_price ?? ($service->package_pricing->price ?? null));
                            echo $this->CurrencyFormat->format($price, ($currency ?? null));
                        } else {
                            echo $this->CurrencyFormat->format(($service->renewal_price ?? null), ($currency ?? null));
                        }
                        ?>
                    </h4>
                    <?php
                    // Display the coupon that should apply when the service renews
                    if (($recurring_coupon ?? null)) {
                    ?>
                    <label><?php $this->_('ClientServices.manage.heading_recurring_coupon');?></label>
                    <h4>
                        <?php
                        if (($recurring_coupon->recurring_amount->type ?? null) == 'percent') {
                            $this->_('ClientServices.manage.text_coupon_percent', false, $this->Html->safe((isset($recurring_coupon->code) ? $recurring_coupon->code : null)), $this->CurrencyFormat->cast((isset($recurring_coupon->recurring_amount->amount) ? $recurring_coupon->recurring_amount->amount : null), (isset($recurring_coupon->recurring_amount->currency) ? $recurring_coupon->recurring_amount->currency : null)));
                        } else {
                            $this->_('ClientServices.manage.text_coupon_amount', false, $this->Html->safe((isset($recurring_coupon->code) ? $recurring_coupon->code : null)), $this->CurrencyFormat->format((isset($recurring_coupon->recurring_amount->amount) ? $recurring_coupon->recurring_amount->amount : null), (isset($recurring_coupon->recurring_amount->currency) ? $recurring_coupon->recurring_amount->currency : null)));
                        }
                        ?>
                    </h4>
                    <?php
                    }
                    ?>
                </div>
            </div>
        </div>
        <?php
        // Display the Configurable Options section
        if (!empty($service->options)) {
        ?>
        <hr />
        <h4><?php $this->_('ClientServices.manage.heading_config_options');?></h4>
        <div class="table-responsive">
            <table class="table table-striped">
                <tbody>
                    <?php
                    $currency_options = [
                        'decimals' => 4,
                        'significant_decimals' => true
                    ];
                    foreach ($service->options as $option) {
                        $is_user_defined_value = (in_array(($option->option_type ?? null), ['text', 'textarea', 'password']));
                        $display_name = ($is_user_defined_value ? ($option->value ?? null) : ($option->option_value_name ?? null));
                    ?>
                    <tr>
                        <td><strong><?php (print (isset($option->option_label) ? $this->Html->safe($option->option_label) : null));?></strong></td>
                        <td><?php echo nl2br((isset($display_name) ? $this->Html->safe($display_name) : ''));?></td>
                        <td>
                            <?php
                            // Hide pricing if disable_pricing is enabled
                            if (!(isset($option->option_disable_pricing) && $option->option_disable_pricing == 1)) {
                                $formatted_option_price = $this->CurrencyFormat->format(($option->option_pricing_price_renews ?? $option->option_pricing_price), ($option->option_pricing_currency ?? null), $currency_options);
                                if (($option->qty ?? false)) {
                                    $this->_('ClientServices.manage.text_price', false, $this->CurrencyFormat->truncateDecimal(($option->qty ?? 1), 0), $formatted_option_price);
                                } else {
                                    echo $formatted_option_price;
                                }
                            }
                            ?>
                        </td>
                    </tr>
                    <?php
                    }
                    ?>
                </tbody>
            </table>
        </div>
        <?php
        }

        // Set button options
        $buttons = [
            'change_service_package' => [
                'enabled' => (($client_change_service_package ?? null) && ($service->status ?? null) == 'active' && empty($service->date_canceled) && !($queued_service_change ?? null)),
                'icon' => 'fas fa-random fa-fw',
                'button' => 'btn-light',
                'lang' => 'ClientServices.manage.button_change_service_package',
                'link' => $this->base_uri . 'services/upgrade/' . ($service->id ?? null)
            ],
            'change_service_term' => [
                'enabled' => (($client_change_service_term ?? null) && !empty($alternate_service_terms) && ($service->status ?? null) == 'active' && empty($service->date_canceled) && !($queued_service_change ?? null)),
                'icon' => 'fas fa-edit fa-fw',
                'button' => 'btn-light',
                'lang' => 'ClientServices.manage.button_change_service_term',
                'link' => $this->base_uri . 'services/changeterm/' . ($service->id ?? null)
            ],
            'renew_service' => [
                'enabled' => (($client_renew_service ?? null) && ($service->status ?? null) == 'active' && empty($service->date_canceled) && !($queued_service_change ?? null)),
                'icon' => 'fas fa-retweet fa-fw',
                'button' => 'btn-light',
                'lang' => 'ClientServices.manage.button_renew'
            ],
            'cancel_service' => [
                'enabled' => (($client_cancel_service ?? null) && !in_array(($service->status ?? null), ['canceled', 'suspended']) && !empty($clients_cancel_options)),
                'icon' => 'fas fa-ban fa-fw',
                'button' => 'btn-danger',
                'lang' => 'ClientServices.manage.button_cancel'
            ],
            'change_configurable_options' => [
                'enabled' => (($available_config_options ?? null) && !($queued_service_change ?? null) && ($service->status ?? null) == 'active'),
                'icon' => 'fas fa-edit fa-fw',
                'button' => 'btn-light',
                'lang' => 'ClientServices.manage.button_config_options',
                'link' => $this->base_uri . 'services/manageoptions/' . ($service->id ?? null)
            ],
            'manage_parent' => [
                'enabled' => (!empty($service->parent) && ($service->parent->status ?? null) == 'active' && ($service->status ?? null) == 'active'),
                'icon' => 'fas fa-cog fa-fw',
                'button' => 'btn-light',
                'lang' => 'ClientServices.manage.button_manage_parent',
                'link' => $this->base_uri . 'services/manage/' . ($service->parent->id ?? null)
            ]
        ];
        $show_options = false;
        foreach ($buttons as $button) {
            if ($button['enabled']) {
                $show_options = true;
                break;
            }
        }

        // Display the Options section
        if ($show_options) {
        ?>
        <hr />
        <h4><?php $this->_('ClientServices.manage.heading_options');?></h4>
            <?php
            // Separate buttons into rows of 3
            $i = 0;
            $row_closed = true;
            foreach ($buttons as $key => $button) {
                // Skip buttons that are not active
                if (!$button['enabled']) {
                    continue;
                }

                // Start a row
                if ($i % 3 == 0) {
                    $row_closed = false;
            ?>
        <div class="row<?php echo $i > 0 ? ' mt-2' : '';?>">
                <?php
                }
                ?>
            <div class="col-md-4">
                <a href="<?php echo (isset($button['link']) ? $this->Html->safe($button['link']) : '#');?>" class="btn btn-med btn-block <?php echo $this->Html->concat(' ', (isset($button['button']) ? $this->Html->safe($button['button']) : null), (isset($key) ? $this->Html->safe($key) : null));?>">
                <?php
                if (!empty($button['icon'])) {
                ?>
                    <i class="<?php (print (isset($button['icon']) ? $this->Html->safe($button['icon']) : null));?>"></i>
                <?php
                }
                $this->_($button['lang']);
                ?>
                </a>
            </div>
                <?php
                // End a row
                if ($i % 3 == 2) {
                    $row_closed = true;
                ?>
        </div>
                <?php
                }

                $i++;
            }

            // Add closing div if the last row has not been closed
            if (!$row_closed) {
            ?>
        </div>
            <?php
            }
            ?>
        <?php
        }
        ?>

<script type="text/javascript">
    $(document).ready(function() {
        $("a.cancel_service").blestaModal({url: "<?php echo $this->Html->safe($this->base_uri . 'services/cancel/' . ($service->id ?? null));?>"});
        $("a.renew_service").blestaModal({url: "<?php echo $this->Html->safe($this->base_uri . 'services/renew/' . ($service->id ?? null));?>"});
    });
</script>
