<div class="std-settings-each-section" data-tab="general">
    <div class="std-field-wrap">
        <label><?php esc_html_e('Form Status', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="checkbox" name="form_status" value="1" <?php echo (!empty($form_row->form_status)) ? 'checked="checked"' : ''; ?> />
        </div>
    </div>
    <div class="std-field-wrap">
        <label><?php esc_html_e('Form Title', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="text" name="form_title" value="<?php echo (!empty($form_row->form_title)) ? esc_attr($form_row->form_title) : ''; ?>" />
        </div>
    </div>

    <div class="std-field-wrap">
        <label><?php esc_html_e('Form Alias', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="text" name="form_alias" class="std-alias-field" value="<?php echo (!empty($form_row->form_alias)) ? esc_attr($form_row->form_alias) : ''; ?>" <?php echo (!empty($_GET['form_id'])) ? 'readonly="readonly"' : ''; ?> />
            <?php if (!empty($_GET['form_id'])) {
            ?>
                <input type="button" class="button-secondary std-alias-force-edit" value="<?php esc_html_e('Edit Anyway', 'subscribe-to-download'); ?>" />
            <?php
            }
            ?>
            <p class="description">
                <?php
                if (!isset($_GET['form_id'])) {
                    esc_html_e('Alias should be unique and shouldn\'t contain any special characters and please use _ instead of space.', 'subscribe-to-download');
                } else {
                    esc_html_e('Alias cannot be modified once added because it is used as the reference for fetching the subscribers.', 'subscribe-to-download');
                }
                ?>
            </p>
        </div>
    </div>
    <div class="std-field-wrap">
        <label><?php esc_html_e('Download File', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="text" name="form_details[general][download_file]" value="<?php echo (!empty($form_details['general']['download_file'])) ? esc_url($form_details['general']['download_file']) : ''; ?>" />
            <input type="hidden" name="form_details[general][download_file_id]" value="<?php echo (!empty($form_details['general']['download_file_id'])) ? intval($form_details['general']['download_file_id']) : ''; ?>" />
            <input type="button" class="button-secondary std-file-uploader" value="<?php esc_html_e('Upload File', 'subscribe-to-download'); ?>" />
            <p class="description"><?php esc_html_e('Please upload the file directly here or choose from the media library. If you are not using the default media library file then browser will redirect to the provided URL for download.', 'subscribe-to-download'); ?></p>
            <p class="description"><?php esc_html_e("Please leave blank if you don't want to enable the download mechanism for subscribers.", 'subscribe-to-download'); ?></p>
        </div>
    </div>

    <div class="std-field-wrap">
        <label><?php esc_html_e('Encrypt Download Link', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="checkbox" name="form_details[general][encrypt_link]" value="1" <?php echo (!empty($form_details['general']['encrypt_link'])) ? 'checked="checked"' : ''; ?> class="std-checkbox-toggle-trigger" data-toggle-class="std-encrypt-link-ref" />
            <p class="description"><?php esc_html_e('Please check this if you want to send the encrypted link to the subscriber which will then prevent the direct link sharing of file. This will check if link has been clicked from the same IP from which the subscription has been done.', 'subscribe-to-download'); ?></p>
        </div>
    </div>
    <div class="std-encrypt-link-ref <?php echo (empty($form_details['general']['encrypt_link'])) ? 'std-display-none' : ''; ?>">
        <div class="std-field-wrap">
            <label><?php esc_html_e('Link Expire', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <input type="checkbox" name="form_details[general][link_expire]" value="1" <?php echo (!empty($form_details['general']['link_expire'])) ? 'checked="checked"' : ''; ?> class="std-checkbox-toggle-trigger" data-toggle-class="std-link-expire-ref" />
                <p class="description"><?php echo esc_html__('Please check if you want the download link to expire.', 'subscribe-to-download'); ?></p>
            </div>
        </div>
        <div class="std-link-expire-ref <?php echo (empty($form_details['general']['link_expire'])) ? 'std-display-none' : ''; ?>">
            <div class="std-field-wrap">
                <label><?php esc_html_e('Expiry Time', 'subscribe-to-download'); ?></label>
                <div class="std-field">
                    <input type="number" min="0" name="form_details[general][link_expire_time]" value="<?php echo (!empty($form_details['general']['link_expire_time'])) ? esc_attr($form_details['general']['link_expire_time']) : ''; ?>" />
                    <p class="description"><?php esc_html_e('Please enter the time in minutes after which you want the link to expire.', 'subscribe-to-download'); ?></p>
                </div>
            </div>
            <div class="std-field-wrap">
                <label><?php esc_html_e('Link Expire Message', 'subscribe-to-download'); ?></label>
                <div class="std-field">
                    <textarea name="form_details[general][link_expire_message]"><?php echo (!empty($form_details['general']['link_expire_message'])) ? $this->output_converting_br($form_details['general']['link_expire_message']) : ''; ?></textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="std-field-wrap">
        <label><?php esc_html_e('Redirection', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="checkbox" name="form_details[general][redirection]" value="1" class="std-checkbox-toggle-trigger" data-toggle-class="std-redirection-ref" <?php echo (!empty($form_details['general']['redirection'])) ? 'checked="checked"' : ''; ?> />
            <p class="description"><?php esc_html_e('Please check this if you want subscribers to redirect to some URL after successful subscription.', 'subscribe-to-download'); ?></p>
        </div>
    </div>
    <div class="std-field-wrap std-redirection-ref" <?php echo (empty($form_details['general']['redirection'])) ? 'style="display:none";' : ''; ?>>
        <label><?php esc_html_e('Redirection URL', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="text" name="form_details[general][redirection_url]" value="<?php echo (!empty($form_details['general']['redirection_url'])) ? esc_attr($form_details['general']['redirection_url']) : ''; ?>" />
        </div>
    </div>
    <div class="std-field-wrap">
        <label><?php esc_html_e('Instant Download', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="checkbox" name="form_details[general][instant_download]" value="1" <?php echo (!empty($form_details['general']['instant_download'])) ? 'checked="checked"' : ''; ?> class="std-checkbox-toggle-trigger std-instant-download-trigger" data-toggle-class="std-instant-download-ref" data-toggle-type="off" />
            <p class="description"><?php esc_html_e('Please check this if you want users to download the file as soon as they subscribe without any verification. Download button will just show below the subscription success message.', 'subscribe-to-download'); ?></p>
        </div>
    </div>
    <div class="std-field-wrap std-instant-download-button-label" <?php echo (empty($form_details['general']['instant_download'])) ? 'style="display:none;"' : ''; ?>>
        <label><?php esc_html_e('Instant Download Button Label', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="text" name="form_details[general][instant_download_button_label]" value="<?php echo (!empty($form_details['general']['instant_download_button_label'])) ? esc_attr($form_details['general']['instant_download_button_label']) : ''; ?>" />
        </div>
    </div>

    <div class="std-instant-download-ref" <?php echo (!empty($form_details['general']['instant_download'])) ? 'style="display:none;"' : ''; ?>>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Double Opt-In', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <input type="checkbox" name="form_details[general][double_optin]" value="1" class="std-checkbox-toggle-trigger" data-toggle-class="std-double-optin-ref" <?php echo (!empty($form_details['general']['double_optin'])) ? 'checked="checked"' : ''; ?> />
                <p class="description"><?php esc_html_e('Please check this if you want to send the download link to subscriber only after clicking the subscription confirmation link which will be sent in the email as soon as the subscriber subscribe.', 'subscribe-to-download'); ?></p>
            </div>
        </div>
        <div class="std-field-wrap std-double-optin-ref" <?php echo (empty($form_details['general']['double_optin'])) ? 'style="display:none";' : ''; ?>>
            <label><?php esc_html_e('Opt-In Confirmation Message', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <?php
                $optin_confirmation_message = (!empty($form_details['general']['optin_confirmation_message'])) ? wp_kses_post($form_details['general']['optin_confirmation_message']) : $this->get_default_optin_confirmation_message();
                wp_editor(wpautop($optin_confirmation_message), 'std_optin_confirmation_message', ['textarea_name' => 'form_details[general][optin_confirmation_message]']);
                ?>

            </div>
        </div>
    </div>

    <div class="std-field-wrap">
        <label><?php esc_html_e('Form Success Message', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <textarea name="form_details[general][success_message]"><?php echo (!empty($form_details['general']['success_message'])) ? esc_attr($form_details['general']['success_message']) : ''; ?></textarea>
        </div>
    </div>
    <div class="std-field-wrap">
        <label><?php esc_html_e('Form Required Error Message', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <textarea name="form_details[general][required_error_message]"><?php echo (!empty($form_details['general']['required_error_message'])) ? esc_attr($form_details['general']['required_error_message']) : ''; ?></textarea>
            <p class="description"><?php esc_html_e('Please enter the message that needs to be shown when any validation error occurs in form submission.', 'subscribe-to-download'); ?></p>
        </div>
    </div>
    <div class="std-field-wrap">
        <label><?php esc_html_e('Form Error Message', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <textarea name="form_details[general][error_message]"><?php echo (!empty($form_details['general']['error_message'])) ? esc_attr($form_details['general']['error_message']) : ''; ?></textarea>
            <p class="description"><?php esc_html_e("Please enter the message that needs to be shown when email couldn't be sent.", 'subscribe-to-download'); ?></p>
        </div>
    </div>

    <div class="std-field-wrap">
        <label><?php esc_html_e('Always Show', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="checkbox" name="form_details[general][always_show]" value="1" <?php echo (!empty($form_details['general']['always_show'])) ? 'checked="checked"' : ''; ?> class="std-checkbox-toggle-trigger" data-toggle-class="std-download-button" data-toggle-type="off" />
            <p class="description"><?php esc_html_e('Please check if you want to always show the form for subscribed users too.', 'subscribe-to-download'); ?></p>
        </div>
    </div>
    <?php
    $always_show = (!empty($form_details['general']['always_show'])) ? 1 : 0;
    ?>
    <div class="std-field-wrap std-download-button" <?php $this->display_none($always_show, 0); ?>>
        <label><?php esc_html_e('Download Button Text', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="text" name="form_details[general][download_button_text]" value="<?php echo (!empty($form_details['general']['download_button_text'])) ? esc_attr($form_details['general']['download_button_text']) : esc_html__('Download', 'subscribe-to-download'); ?>" />
            <p class="description"><?php esc_html_e('This is the button which will show when already subscribed user visit the site again.', 'subscribe-to-download'); ?></p>
        </div>
    </div>
    <div class="std-field-wrap">
        <label><?php esc_html_e('Unallowed Email Domains', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="button" class="button-secondary std-domain-add-trigger" value="<?php esc_attr_e('Add Domain', 'subscribe-to-download') ?>" />
            <div class="std-unallowed-email-domains-list">
                <?php
                if (!empty($form_details['general']['unallowed_email_domains'])) {
                    foreach ($form_details['general']['unallowed_email_domains'] as $email_domain) {
                ?>
                        <div class="std-each-domain">
                            <input type="text" name="form_details[general][unallowed_email_domains][]" value="<?php echo esc_attr($email_domain); ?>" />
                            <span class="dashicons dashicons-trash std-remove-domain-trigger"></span>
                        </div>
                <?php
                    }
                }
                ?>
            </div>
        </div>
    </div>
    <div class="std-field-wrap">
        <label><?php esc_html_e('Unallowed Email Error Message', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="text" name="form_details[general][unallowed_email_error_message]" value="<?php echo (!empty($form_details['general']['unallowed_email_error_message'])) ? esc_attr($form_details['general']['unallowed_email_error_message']) : ''; ?>" />
            <p class="description"><?php esc_html_e('Please enter the message to show when any unallowed email domain is entered.', 'subscribe-to-download'); ?></p>
        </div>
    </div>
    <?php
    $std_settings = get_option('std_settings');
    if (!empty($std_settings['mailchimp']['enable']) && !empty($std_settings['mailchimp']['status']) && !empty($std_settings['mailchimp']['mailchimp_lists'])) {
    ?>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Mailchimp Lists', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <div class="std-mailchimp-check-lists-wrap">
                    <?php
                    $mailchimp_lists = json_decode($std_settings['mailchimp']['mailchimp_lists']);
                    $selected_mailchimp_lists = (!empty($form_details['general']['mailchimp_id'])) ? $form_details['general']['mailchimp_id'] : array();
                    if (!empty($mailchimp_lists->lists)) {
                        $mailchimp_lists = $mailchimp_lists->lists;
                        foreach ($mailchimp_lists as $mailchimp_list) {
                    ?>
                            <label class="std-block"><input type="checkbox" name="form_details[general][mailchimp_id][]" value="<?php echo esc_attr($mailchimp_list->id); ?>" class="std-disable-checkbox-toggle" <?php echo (in_array($mailchimp_list->id, $selected_mailchimp_lists)) ? 'checked="checked"' : ''; ?> /><span><?php echo esc_attr($mailchimp_list->name); ?></span></label>
                    <?php
                        }
                    } else {
                        esc_html_e('No list found for the mailchimp. Please check the mailchimp settings inside our settings section to fetch the mailchimp lists.', 'subscribe-to-download');
                    }
                    ?>
                </div>
                <p class="description"><?php esc_html_e('Please check desired mailchimp list to send the subscribers directly to the mailchimp.', 'subscribe-to-download'); ?></p>
            </div>
        </div>
    <?php
    }
    if (!empty($std_settings['constant_contact']['enable']) && !empty($std_settings['constant_contact']['status']) && !empty($std_settings['constant_contact']['constant_contact_lists'])) {
    ?>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Constant Contact Lists', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <div class="std-mailchimp-check-lists-wrap">
                    <?php
                    $constant_contact_lists = json_decode($std_settings['constant_contact']['constant_contact_lists']);
                    $selected_constant_contact_lists = (!empty($form_details['general']['constant_contact_id'])) ? $form_details['general']['constant_contact_id'] : array();
                    if (!empty($constant_contact_lists)) {
                        foreach ($constant_contact_lists as $constant_contact_list) {
                    ?>
                            <label class="std-block"><input type="checkbox" name="form_details[general][constant_contact_id][]" value="<?php echo esc_attr($constant_contact_list->id); ?>" class="std-disable-checkbox-toggle" <?php echo (in_array($constant_contact_list->id, $selected_constant_contact_lists)) ? 'checked="checked"' : ''; ?> /><span><?php echo esc_attr($constant_contact_list->name); ?></span></label>
                    <?php
                        }
                    } else {
                        esc_html_e('No list found for the constant contact. Please check the constant contact settings inside our settings section to fetch the constant_contact lists.', 'subscribe-to-download');
                    }
                    ?>
                </div>
                <p class="description"><?php esc_html_e('Please check desired constant contact list to send the subscribers directly to the constant contact.', 'subscribe-to-download'); ?></p>
            </div>
        </div>
    <?php
    }
    if (!empty($std_settings['constant_contact_v3']['enable']) && !empty($std_settings['constant_contact_v3']['access_token']) && !empty($std_settings['constant_contact_v3']['lists'])) {
    ?>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Constant Contact V3 Lists', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <div class="std-mailchimp-check-lists-wrap">
                    <?php
                    $constant_contact_lists = $std_settings['constant_contact_v3']['lists'];
                    $selected_constant_contact_lists = (!empty($form_details['general']['constant_contact_v3_id'])) ? $form_details['general']['constant_contact_v3_id'] : array();
                    if (!empty($constant_contact_lists)) {
                        foreach ($constant_contact_lists as $constant_contact_list) {
                    ?>
                            <label class="std-block"><input type="checkbox" name="form_details[general][constant_contact_v3_id][]" value="<?php echo esc_attr($constant_contact_list['list_id']); ?>" class="std-disable-checkbox-toggle" <?php echo (in_array($constant_contact_list['list_id'], $selected_constant_contact_lists)) ? 'checked="checked"' : ''; ?> /><span><?php echo esc_attr($constant_contact_list['name']); ?></span></label>
                    <?php
                        }
                    } else {
                        esc_html_e('No list found for the constant contact. Please check the constant contact settings inside our settings section to fetch the constant_contact lists.', 'subscribe-to-download');
                    }
                    ?>
                </div>
                <p class="description"><?php esc_html_e('Please check desired constant contact list to send the subscribers directly to the constant contact.', 'subscribe-to-download'); ?></p>
            </div>
        </div>
    <?php
    }
    if (!empty($std_settings['mailerlite']['enable']) && !empty($std_settings['mailerlite']['status']) && !empty($std_settings['mailerlite']['mailerlite_lists'])) {
    ?>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Mailerlite Groups', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <div class="std-mailchimp-check-lists-wrap">
                    <?php
                    $mailerlite_lists = json_decode($std_settings['mailerlite']['mailerlite_lists']);
                    $selected_mailerlite_lists = (!empty($form_details['general']['mailerlite_id'])) ? $form_details['general']['mailerlite_id'] : array();
                    if (!empty($mailerlite_lists)) {
                        $mailerlite_lists = $mailerlite_lists;
                        foreach ($mailerlite_lists as $mailerlite_list) {
                    ?>
                            <label class="std-block"><input type="checkbox" name="form_details[general][mailerlite_id][]" value="<?php echo esc_attr($mailerlite_list->id); ?>" class="std-disable-checkbox-toggle" <?php echo (in_array($mailerlite_list->id, $selected_mailerlite_lists)) ? 'checked="checked"' : ''; ?> /><span><?php echo esc_attr($mailerlite_list->name); ?></span></label>
                    <?php
                        }
                    } else {
                        esc_html_e('No list found for the mailerlite. Please check the mailerlite settings inside our settings section to fetch the mailerlite lists.', 'subscribe-to-download');
                    }
                    ?>
                </div>
                <p class="description"><?php esc_html_e('Please check desired mailerlite list to send the subscribers directly to the mailerlite.', 'subscribe-to-download'); ?></p>
            </div>
        </div>
    <?php
    }
    if (!empty($std_settings['sendinblue']['enable']) && !empty($std_settings['sendinblue']['status']) && !empty($std_settings['sendinblue']['sendinblue_lists'])) {
    ?>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Sendinblue Lists', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <div class="std-mailchimp-check-lists-wrap">
                    <?php
                    $sendinblue_lists = json_decode($std_settings['sendinblue']['sendinblue_lists']);
                    $selected_sendinblue_lists = (!empty($form_details['general']['sendinblue_id'])) ? $form_details['general']['sendinblue_id'] : array();
                    if (!empty($sendinblue_lists->lists)) {
                        $sendinblue_lists = $sendinblue_lists->lists;
                        foreach ($sendinblue_lists as $sendinblue_list) {
                    ?>
                            <label class="std-block"><input type="checkbox" name="form_details[general][sendinblue_id][]" value="<?php echo esc_attr($sendinblue_list->id); ?>" class="std-disable-checkbox-toggle" <?php echo (in_array($sendinblue_list->id, $selected_sendinblue_lists)) ? 'checked="checked"' : ''; ?> /><span><?php echo esc_attr($sendinblue_list->name); ?></span></label>
                    <?php
                        }
                    } else {
                        esc_html_e('No list found for the sendinblue. Please check the sendinblue settings inside our settings section to fetch the sendinblue lists.', 'subscribe-to-download');
                    }
                    ?>
                </div>
                <p class="description"><?php esc_html_e('Please check desired sendinblue list to send the subscribers directly to the sendinblue.', 'subscribe-to-download'); ?></p>
            </div>
        </div>
    <?php
    }
    if (!empty($std_settings['convertkit']['enable']) && !empty($std_settings['convertkit']['status']) && !empty($std_settings['convertkit']['convertkit_lists'])) {
    ?>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Convertkit Lists', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <div class="std-mailchimp-check-lists-wrap">
                    <?php
                    $convertkit_lists = json_decode($std_settings['convertkit']['convertkit_lists']);
                    $selected_convertkit_lists = (!empty($form_details['general']['convertkit_id'])) ? $form_details['general']['convertkit_id'] : array();
                    if (!empty($convertkit_lists->forms)) {
                        $convertkit_lists = $convertkit_lists->forms;
                        foreach ($convertkit_lists as $convertkit_list) {
                    ?>
                            <label class="std-block"><input type="checkbox" name="form_details[general][convertkit_id][]" value="<?php echo esc_attr($convertkit_list->id); ?>" class="std-disable-checkbox-toggle" <?php echo (in_array($convertkit_list->id, $selected_convertkit_lists)) ? 'checked="checked"' : ''; ?> /><span><?php echo esc_attr($convertkit_list->name); ?></span></label>
                    <?php
                        }
                    } else {
                        esc_html_e('No list found for the convertkit. Please check the convertkit settings inside our settings section to fetch the convertkit lists.', 'subscribe-to-download');
                    }
                    ?>
                </div>
                <p class="description"><?php esc_html_e('Please check desired convertkit list to send the subscribers directly to the convertkit.', 'subscribe-to-download'); ?></p>
            </div>
        </div>
    <?php
    }
    ?>
</div>