<?php if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
use Bookly\Backend\Components\Controls\Buttons;
use Bookly\Backend\Components\Controls\Inputs as ControlInputs;
use Bookly\Backend\Components\Settings\Inputs;
use Bookly\Backend\Components\Settings\Selects;
use BooklyOutlookCalendar\Lib\Microsoft;
?>
<div class="tab-pane" id="bookly_settings_outlook_calendar">
    <form method="post" action="<?php echo esc_url( add_query_arg( 'tab', 'outlook_calendar' ) ) ?>">
        <div class="form-group">
            <h4><?php esc_html_e( 'Instructions', 'bookly' ) ?></h4>
            <p><?php _e( 'Important: Your website must use <b>HTTPS</b>. The Outlook Calendar API will not work with your website if there is no valid SSL certificate installed on your web server.', 'bookly' ) ?></p>
            <p><?php esc_html_e( 'To find your Application ID and Application Secret, do the following:', 'bookly' ) ?></p>
            <ol>
                <li><?php printf( __( 'Navigate to the <a href="%s" target="_blank">Microsoft App Registration Portal</a>.', 'bookly' ), 'https://apps.dev.microsoft.com/' ) ?></li>
                <li><?php esc_html_e( 'Sign in with either a personal or work or school Microsoft account. If you don\'t have either, sign up for a new personal account.', 'bookly' ) ?></li>
                <li><?php _e( 'Choose <b>Add an app</b>. Enter a name for the app and choose <b>Create application</b>. The registration page displays, listing the properties of your app.', 'bookly' ) ?></li>
                <li><?php _e( 'Copy the <b>Application ID</b>. This is the unique identifier for your app. You\'ll use it in the form below on this page.', 'bookly' ) ?></li>
                <li><?php _e( 'Under <b>Application Secrets</b>, choose <b>Generate New Password</b>. Copy the app secret from the <b>New password generated</b> dialog box before closing it. You\'ll use the secret in the form below on this page.', 'bookly' ) ?></li>
                <li><?php _e( 'Under <b>Platforms</b>, choose <b>Add Platform</b>, and select <b>Web</b>. In <b>Redirect URLs</b> enter the <b>Redirect URI</b> found below on this page.', 'bookly' ) ?></li>
                <li><?php _e( 'Under <b>Microsoft Graph Permissions</b>, choose <b>Add</b> next to <b>Delegated Permissions</b>, and select <b>Calendars.ReadWrite</b> in the <b>Select Permission</b> dialog box. Close it by clicking <b>Ok</b>.', 'bookly' ) ?></li>
                <li><?php _e( '<b>Save</b> your changes.', 'bookly' ) ?></li>
                <li><?php _e( 'Go to Staff Members, select a staff member and click <b>Connect</b> which is located at the bottom of the page.', 'bookly' ) ?></li>
            </ol>
        </div>
        <?php Inputs::renderText( 'bookly_oc_app_id', esc_html__( 'Application ID', 'bookly' ), esc_html__( 'The Application ID obtained from the Microsoft App Registration Portal.', 'bookly' ) ) ?>
            <?php Inputs::renderText( 'bookly_oc_app_secret', esc_html__( 'Application secret', 'bookly' ), esc_html__( 'The Application Secret password obtained from the Microsoft App Registration Portal.', 'bookly' ) ) ?>
        <div class="form-group">
            <label for="bookly-redirect-uri"><?php esc_html_e( 'Redirect URI', 'bookly' ) ?></label>
            <p class="help-block"><?php esc_html_e( 'Enter this URL as a Redirect URLs in the Microsoft App Registration Portal.', 'bookly' ) ?></p>
            <input id="bookly-redirect-uri" class="form-control" type="text" readonly
                   value="<?php echo Microsoft\Client::generateRedirectURI() ?>" onclick="this.select();"
                   style="cursor: pointer;"/>
        </div>
        <?php Selects::renderSingle( 'bookly_oc_sync_mode', esc_html__( 'Synchronization mode', 'bookly' ), esc_html__( 'With "One-way" sync Bookly pushes new appointments and any further changes to Outlook Calendar. With "Two-way front-end only" sync Bookly will additionally fetch events from Outlook Calendar and remove corresponding time slots before displaying the Time step of the booking form (this may lead to a delay when users click Next to get to the Time step). With "Two-way" sync all bookings created in Bookly Calendar will be automatically copied to Outlook Calendar and vice versa.', 'bookly' ), array( array( '1-way', esc_html__( 'One-way', 'bookly' ) ), array( '1.5-way', esc_html__( 'Two-way front-end only', 'bookly' ) ), array( '2-way', __( 'Two-way', 'bookly' ) ) )) ?>
        <?php Inputs::renderNumber( 'bookly_oc_full_sync_offset_days', esc_html__( 'Sync appointments history', 'bookly' ), esc_html__( 'Specify how many days of past calendar data you wish to sync at the time of initial sync. If you enter 0, synchronization of past events will not be performed.', 'bookly' ), 0, 1 ) ?>
        <?php Selects::renderSingle( 'bookly_oc_full_sync_titles', esc_html__( 'Copy Outlook Calendar event titles', 'bookly' ), esc_html__( 'If enabled then titles of Outlook Calendar events will be copied to Bookly appointments. If disabled, a standard title "Outlook Calendar event" will be used.', 'bookly' ) ) ?>
        <?php Selects::renderSingle( 'bookly_oc_limit_events', esc_html__( 'Limit number of fetched events', 'bookly' ), esc_html__( 'If there is a lot of events in Outlook Calendar sometimes this leads to a lack of memory in PHP when Bookly tries to fetch all events. You can limit the number of fetched events here.', 'bookly' ), $fetch_limits ) ?>
        <?php Inputs::renderText( 'bookly_oc_event_title', esc_html__( 'Template for event title', 'bookly' ), esc_html__( 'Configure what information should be placed in the title of Outlook Calendar event. Available codes are {service_name}, {staff_name} and {client_names}.', 'bookly' ) ) ?>
        <?php Inputs::renderTextArea( 'bookly_oc_event_appointment_info', esc_html__( 'Appointment section', 'bookly' ), esc_html__( 'This section describes information that is displayed about appointment.', 'bookly' ) ) ?>
        <?php $self::renderTemplate( '_appointment_codes', array( 'participants' => 'many' ) ) ?>
        <br>
        <?php Inputs::renderTextArea( 'bookly_oc_event_client_info', esc_html__( 'Customer section', 'bookly' ), esc_html__( 'This section describes information that is displayed about each participant of the appointment.', 'bookly' ) ) ?>
        <?php $self::renderTemplate( '_client_codes', array( 'participants' => 'one' ) ) ?>

        <div class="panel-footer">
            <?php ControlInputs::renderCsrf() ?>
            <?php Buttons::renderSubmit() ?>
            <?php Buttons::renderReset() ?>
        </div>
    </form>
</div>