<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<table class="form-table">
    <tr valign="top">
        <th scope="row" class="align-middle">
        </th>

        <td>
            <div class="premium-feature-box">
                <div class="text-center px-4">
                    <div class="flex items-center justify-center mb-2">
                        <img class="w-6 h-6" src="<?php echo esc_url(plugins_url('../../Assets/Img/crown.svg', __FILE__ )); ?>" alt="<?php echo esc_attr( 'WP Invoices' ) ?>" />
                        <h3><?php esc_html_e( 'Premium Feature', 'kirilkirkov-pdf-invoice-manager' ); ?></h3>
                    </div>
                    <p class="mb-4"><?php esc_html_e( 'Api Integration is available in the premium version of the plugin.', 'kirilkirkov-pdf-invoice-manager' ); ?></p>
                    <a href="<?php echo esc_url($Config::PREMIUM_LINK); ?>" target="_blank" class="kkinv-btn-primary"><?php esc_html_e( 'Get Premium Now', 'kirilkirkov-pdf-invoice-manager' ); ?></a>
                </div>
            </div>
        </td>
    </tr>

    <tr valign="top" class="premium-feature-container">
        <th scope="row" class="align-middle">
            <div class="th-div">
                <span class="mr-5"><?php esc_html_e( 'General settings', 'kirilkirkov-pdf-invoice-manager' ); ?></span>
                <a class="show-info" data-info="<?php esc_attr_e( 'Enable Rest Api to handle requests. The Api Token is used to securely authorize your requests', 'kirilkirkov-pdf-invoice-manager' ) ?>" href="javascript:;"></a>
            </div>
        </th>

        <td>
            <?php 
                $kirilkirkovwipdf_api_enabled = get_option($Config::INPUTS_PREFIX.'api_enabled');
            ?>
            
            <div class="<?php if((int)$kirilkirkovwipdf_api_enabled > 0) { echo 'mb-4'; } ?>">
                
                <input type="hidden" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'api_enabled'; ?>" value="0" />
                <label>
                    <input type="checkbox" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'api_enabled'; ?>" value="1" <?php echo $kirilkirkovwipdf_api_enabled && (int)$kirilkirkovwipdf_api_enabled === 1 ? 'checked' : ''; ?>>
                    <?php esc_html_e( 'Enable Rest Api', 'kirilkirkov-pdf-invoice-manager' ); ?>
                </label>
            </div>

            <?php 
                // ONLY IF HAS ENABLED API
                if((int)$kirilkirkovwipdf_api_enabled === 1) {
            ?>
 
            <div class="mb-4">
                <label><?php esc_html_e( 'Api Token (generate token to prevent unauthorized users)', 'kirilkirkov-pdf-invoice-manager' ); ?></label>
                <input type="text" class="wp-invoices-rest-api-token-field" name="<?php echo esc_attr($Config::INPUTS_PREFIX); ?>api_token" value="<?php echo esc_attr(sanitize_text_field(get_option( $Config::INPUTS_PREFIX.'api_token' ))); ?>" />
            </div>

            <a href="javascript:;" class="generate-token accent-button bg-main--important inline-block--important">
                <?php esc_html_e( 'Generate Token', 'kirilkirkov-pdf-invoice-manager' ); ?>
            </a> 

            <?php } ?>
        </td>
    </tr>
</table>

<?php
    require 'Api_Documentation.php'
?>

<input type="hidden" name="page_options" value="<?php echo esc_attr(sanitize_text_field($Config::API_INTEGRATION_INPUT_GROUP)); ?>" />
<?php settings_fields($Config::API_INTEGRATION_INPUT_GROUP); ?>