<div class="std-settings-each-section" data-tab="constant_contact" <?php echo ($active_tab != 'constant_contact') ? 'style="display:none;"' : ''; ?>>
    <div class="std-field-wrap">
        <label><?php esc_html_e('Enable Constant Contact', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="checkbox" name="std_settings[constant_contact][enable]" value="1" <?php echo (!empty($std_settings['constant_contact']['enable'])) ? 'checked="checked"' : ''; ?> class="std-checkbox-toggle-trigger" data-toggle-class="std-cc-enabled"/>
        </div>
    </div>
    <?php $enable_constant_contact = (!empty($std_settings['constant_contact']['enable'])) ? 1 : 0; ?>
    <div class="std-cc-enabled" <?php $this->display_none($enable_constant_contact, 1); ?>>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Constant Contact API Key', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <input type="text" name="std_settings[constant_contact][api_key]" value="<?php echo (!empty($std_settings['constant_contact']['api_key'])) ? esc_attr($std_settings['constant_contact']['api_key']) : ''; ?>" class="std-constant_contact-api-key"/>
                <p class="description"><?php echo sprintf(esc_html__('Please go %s here %s to generate your api keys', 'subscribe-to-download'), '<a href="https://constantcontact.mashery.com/apps/mykeys" target="_blank">', '</a>'); ?></p>
                <p class="description"><?php echo sprintf(esc_html__('Please go %s here %s to know how to generate necessary keys', 'subscribe-to-download'), '<a href="https://developer.constantcontact.com/home/api-keys.html" target="_blank">', '</a>'); ?></p>
            </div>
        </div>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Constant Contact Access Token', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <input type="text" name="std_settings[constant_contact][access_token]" value="<?php echo (!empty($std_settings['constant_contact']['access_token'])) ? esc_attr($std_settings['constant_contact']['access_token']) : ''; ?>" class="std-constant_contact-access-token"/>
                <p class="description"><?php echo sprintf(esc_html__('Please go %s here %s to generate your access token.', 'subscribe-to-download'), '<a href="https://constantcontact.mashery.com/apps/mykeys" target="_blank">', '</a>'); ?></p>
                <p class="description"><?php echo sprintf(esc_html__('Please go %s here %s to know how to generate necessary keys', 'subscribe-to-download'), '<a href="https://developer.constantcontact.com/home/api-keys.html" target="_blank">', '</a>'); ?></p>


            </div>
        </div>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Status', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <?php
                $constant_contact_status = (!empty($std_settings['constant_contact']['status'])) ? 1 : 0;
                $constant_contact_status_class = ($constant_contact_status == 1) ? 'std-cc-connected' : 'std-cc-disconnected';
                ?>
                <input type="hidden" name="std_settings[constant_contact][status]" value="<?php echo intval($constant_contact_status); ?>" class="std-constant_contact-status-flag"/>

                <span class="std-constant_contact-status <?php echo esc_attr($constant_contact_status_class); ?>"><?php echo ($constant_contact_status == 1) ? esc_html__('Connected', 'subscribe-to-download') : esc_html__('Disconnected', 'subscribe-to-download'); ?></span>
            </div>
        </div>
        <div class="std-field-wrap">
            <label></label>
            <div class="std-field">
                <?php
                $connect_label = (!empty($constant_contact_status)) ? esc_html__('Renew List', 'subscribe-to-download') : esc_html__('Connect', 'subscribe-to-download');
                ?>
                <input type="button" class="std-constant_contact-connect button-secondary" value="<?php echo esc_attr($connect_label); ?>">
                <?php if ($constant_contact_status == 1) {
                    ?>
                    <input type="button" class="std-constant_contact-reset button-secondary" value="<?php esc_html_e("Reset", 'subscribe-to-download'); ?>">
                    <?php
                }
                ?>
                <div class = "std-constant_contact-api-response" style = "display:none;"></div>
            </div>
        </div>
        <div class = "std-constant_contact-lists-wrap">
            <?php
            if (!empty($std_settings['constant_contact']['constant_contact_lists'])) {
                $constant_contact_lists = json_decode($std_settings['constant_contact']['constant_contact_lists']);
                ?>
                <div class="std-field-wrap std-custom-table">
                    <label><?php esc_html_e('Constant Contact Lists', 'subscribe-to-download'); ?></label>
                    <div class="std-field">
                        <div class="std-custom-table">
                            <div class="std-each-list std-list-head">
                                <span class="std-list-col"><?php esc_html_e('ID', 'subscribe-to-download'); ?></span>
                                <span class="std-list-col"><?php esc_html_e('List Name', 'subscribe-to-download'); ?></span>
                            </div>
                            <?php
                            foreach ($constant_contact_lists as $constant_contact_list) {
                                ?>
                                <div class="std-each-list">
                                    <span class="std-list-col"><?php echo esc_attr($constant_contact_list->id); ?></span>
                                    <span class="std-list-col"><?php echo esc_attr($constant_contact_list->name); ?></span>
                                </div>
                            <?php } ?>
                        </div>
                    </div>
                </div>
                <?php
            }
            ?>
        </div>
        <textarea name="std_settings[constant_contact][constant_contact_lists]" class="std-constant_contact-lists-input" style="display:none;"><?php echo (!empty($std_settings['constant_contact']['constant_contact_lists'])) ? $this->sanitize_html($std_settings['constant_contact']['constant_contact_lists']) : ''; ?></textarea>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Last Log', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <textarea name="std_settings[constant_contact][cc_log]"><?php echo (!empty($std_settings['constant_contact']['cc_log'])) ? $this->sanitize_html($std_settings['constant_contact']['cc_log']) : ''; ?></textarea>
                <input type="button" class="std-clear-log-trigger button-secondary" value="<?php esc_html_e('Clear Log', 'subscribe-to-download'); ?>">
            </div>
        </div>
    </div>
</div>
