<?php
if (!defined('ABSPATH'))
    exit;
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
$pro_enabled = dspp_check_api_connection_settings();
$method = "Paypal";
$details = array_shift(dspp_check_payment_method_enabled($method));
$enabled = 0;
$method_id = 0;
$stripe_publishable_key = '';
$stripe_secret_key = '';
if (isset($details) && !empty($details)) {
    $enabled = ($details->enable == "true") ? true : false;
    $method_id = $details->methode_id;
    $settings = $details->methode_details;
    $decoded = json_decode($settings);
    $stripe_publishable_key = $decoded->client_or_strip;
    $stripe_secret_key = $decoded->secret_key;
}
if (!$pro_enabled) {
    ?>
    <div class="dspp-disabled-section">
        <strong>Premium Features (Disabled)</strong>
        <p>Upgrade to unlock these features. Visit our <a href="<?php echo DSPP_WEB_API_URL;?>" target="_blank" style="pointer-events: auto;">website</a> for more info.</p>
    </div>
    <?php
}
?>
<!-- Fullscreen Loader Overlay -->
<div id="fullpage-loader" class="dspp-loader-overlay" style="display: none;">
    <div class="dspp-loader-spinner">
        <div class="spinner-border text-light" role="status">
            <span class="visually-hidden">Loading...</span>
        </div>
        <div class="dspp-loader-text mt-2">Updating...</div>
    </div>
</div>
<div id="paypal_tab" class="payment-method-tab-content" style="margin-top: 1%">
    <table>
        <tr>
            <td><label class="<?php echo ($pro_enabled) ? '' : 'dspp-disabled-content' ?>" for="enable_paypal"><?php echo esc_html_e('Enable PayPal:', 'digital-service-provider-crm') ?></label></td>
            <td>
                <input type="checkbox" id="enable_paypal" name="enable_stripe"
                <?php echo $enabled ? 'checked="checked"' : ''; ?>
                       <?php echo!$pro_enabled ? 'disabled' : ''; ?>>

                <?php if (!$pro_enabled): ?>
                    <span style="margin-left: 10px;">
                        (Available in <a href="<?php echo DSPP_WEB_API_URL;?>" target="_blank">Pro Version</a>)
                    </span>
                <?php endif; ?>
            </td>
        </tr>
        <tr>
            <td><label class="<?php echo ($pro_enabled) ? '' : 'dspp-disabled-content' ?>" for="stripe_publishable_key"><?php echo esc_html_e('PayPal User ID:', 'digital-service-provider-crm') ?></label></td>
            <td><input type="text" id="stripe_publishable_key" name="stripe_publishable_key" value="<?php echo esc_attr($stripe_publishable_key); ?>" required="required" <?php echo ($pro_enabled) ? '' : 'disabled' ?>><br></td>
        </tr>
        <tr>
            <td><label class="<?php echo ($pro_enabled) ? '' : 'dspp-disabled-content' ?>"  for="stripe_secret_key"><?php echo esc_html_e('PayPal Secret Key:', 'digital-service-provider-crm') ?></label></td>
            <td><input type="text" id="stripe_secret_key" name="stripe_secret_key" value="<?php echo esc_attr($stripe_secret_key); ?>" required="required" <?php echo ($pro_enabled) ? '' : 'disabled' ?>><br></td>
        </tr>
        <tr>
        <input type="hidden" id="method_id" name="method_id" value="<?php echo esc_attr($method_id); ?>">
        <td><button id="dspp-paypal_save" class="paypal_save btn btn-primary <?php echo ($pro_enabled) ? '' : 'dspp-disabled-content' ?>" <?php echo ($pro_enabled) ? '' : 'disabled' ?>><?php echo esc_html_e('Save', 'digital-service-provider-crm') ?></button></td>
        </tr>
    </table>
    <span class="success"></span>
</div>