<?php

defined('ABSPATH') || die;

$license = get_option('advgb_pro_license_key');
$status  = get_option('advgb_pro_license_status');
?>
<!-- License -->
<?php
if (! $license) : ?>
    <p>
        <?php
        printf(
            __('For updates to PublishPress Blocks Pro, %sactivate your license key%s.', 'advanced-gutenberg-pro'),
            '<a href="https://publishpress.com/checkout/purchase-history/" target="_blank">',
            '</a>'
        );
        ?>
    </p>
    <?php
endif; ?>
<form method="post" action="options.php">
    <?php
    settings_fields('advgb_pro_license'); ?>
    <table class="form-table">
        <tbody>
        <tr valign="top">
            <th scope="row" valign="top">
                <?php
                _e('License Key', 'advanced-gutenberg-pro'); ?>
            </th>
            <td>
                <input id="advgb_pro_license_key" name="advgb_pro_license_key" type="text" class="regular-text"
                       value="<?php
                        esc_attr_e($license); ?>"/>
                <p class="description">
                    <?php
                    if (! $license && ! isset($_GET['message'])) {
                        _e('Enter your license key', 'advanced-gutenberg-pro');
                    } elseif ($status !== false && $status == 'valid') {
                        echo sprintf(
                            __('License key is %sactive%s.', 'advanced-gutenberg-pro'),
                            '<span style="color:#1a844f;">',
                            '</span>'
                        );
                    } elseif (isset($_GET['message'])) {
                        $message = urldecode($_GET['message']); // phpcs:ignore WordPress.Security.ValidatedSanitizedInput.InputNotSanitized
                        $message = sanitize_text_field($message);
                        echo $message;
                    } else {
                        _e('License key is inactive. Click on "Activate License".', 'advanced-gutenberg-pro');
                    }
                    ?>
                </p>
            </td>
        </tr>
        <?php
        if (false !== $license) : ?>
            <tr valign="top">
                <th scope="row" valign="top">
                    <?php
                    _e('License Action', 'advanced-gutenberg-pro'); ?>
                </th>
                <td>
                    <?php
                    if ($status !== false && $status == 'valid') { ?>
                        <?php
                        wp_nonce_field('advgb_pro_nonce', 'advgb_pro_nonce'); ?>
                        <input type="submit"
                               class="button"
                               name="advgb_pro_license_deactivate"
                               value="<?php
                                _e('Deactivate License', 'advanced-gutenberg-pro'); ?>"
                        />
                        <?php
                    } else {
                        wp_nonce_field('advgb_pro_nonce', 'advgb_pro_nonce'); ?>
                        <input type="submit"
                               class="button"
                               name="advgb_pro_license_activate"
                               value="<?php
                                _e('Activate License', 'advanced-gutenberg-pro'); ?>"
                        />
                        <?php
                    } ?>
                </td>
            </tr>
            <?php
        endif; ?>
        </tbody>
    </table>
    <p class="submit">
        <input type="submit"
               name="submit"
               id="submit"
               class="button button-primary"
               value="<?php
                esc_attr_e('Save Changes', 'advanced-gutenberg-pro'); ?>"
        />
    </p>
</form>
