<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
use Bookly\Backend\Components\Settings\Inputs;
use Bookly\Backend\Components\Settings\Payments;
use Bookly\Backend\Components\Settings\Selects;
use Bookly\Lib\Utils\DateTime;
?>

<div class="panel panel-default bookly-collapse" data-slug="bookly-addon-stripe">
    <div class="panel-heading">
        <i class="bookly-js-handle bookly-margin-right-sm bookly-icon bookly-icon-draghandle bookly-cursor-move ui-sortable-handle" title="<?php esc_attr_e( 'Reorder', 'bookly' ) ?>"></i>
        <a href="#bookly_pmt_stripe" class="panel-title" role="button" data-toggle="collapse">
            Stripe
        </a>
        <img class="pull-right" src="<?php echo plugins_url( 'frontend/resources/images/stripe.png', \BooklyStripe\Lib\Plugin::getMainFile() ) ?>">
    </div>
    <div id="bookly_pmt_stripe" class="panel-collapse collapse in">
        <div class="panel-body">
            <?php Selects::renderSingle( 'bookly_stripe_enabled' ) ?>
            <div class="bookly-stripe">
                <div class="form-group">
                    <h4><?php esc_html_e( 'Instructions', 'bookly' ) ?></h4>
                    <p><?php printf( __( '1. Provide <b>Secret</b> and <b>Publishable</b> keys which are available in the <a href="%s" target="_blank">Dashboard</a>.', 'bookly' ), 'https://dashboard.stripe.com/account/apikeys' ) ?></p>
                    <p><?php printf( __( '2. In the Dashboard\'s <a href="%s" target="_blank">Webhooks settings</a> section, click <b>Add endpoint</b> to reveal a form to add a new endpoint for receiving events.', 'bookly' ), 'https://dashboard.stripe.com/account/webhooks' ) ?></p>
                    <p><?php printf( __( 'Enter the following URL as the destination for events <b>%s</b> and click <b>Add endpoint</b>.', 'bookly' ), admin_url( 'admin-ajax.php?action=bookly_stripe_ipn' ) ) ?></p>
                </div>
                <?php Inputs::renderText( 'bookly_stripe_secret_key', __( 'Secret Key', 'bookly' ) ) ?>
                <?php Inputs::renderText( 'bookly_stripe_publishable_key', __( 'Publishable Key', 'bookly' ) ) ?>
                <?php Payments::renderPriceCorrection( 'stripe' ) ?>
                <?php
                $values = array( array( '0', __( 'OFF', 'bookly' ) ) );
                foreach ( array_merge( range( 1, 23, 1 ), range( 24, 168, 24 ), array( 336, 504, 672 ) ) as $hour ) {
                    $values[] = array( $hour * HOUR_IN_SECONDS, DateTime::secondsToInterval( $hour * HOUR_IN_SECONDS ) );
                }
                Selects::renderSingle( 'bookly_stripe_timeout', __( 'Time interval of payment gateway', 'bookly' ), __( 'This setting determines the time limit after which the payment made via the payment gateway is considered to be incomplete. This functionality requires a scheduled cron job.', 'bookly' ), $values );
                ?>
            </div>
        </div>
    </div>
</div>