<div class="std-settings-each-section" data-tab="mailchimp" <?php echo ($active_tab != 'mailchimp') ? 'style="display:none;"' : ''; ?>>
    <div class="std-field-wrap">
        <label><?php esc_html_e('Enable Mailchimp', 'subscribe-to-download'); ?></label>
        <div class="std-field">
            <input type="checkbox" name="std_settings[mailchimp][enable]" value="1" <?php echo (!empty($std_settings['mailchimp']['enable'])) ? 'checked="checked"' : ''; ?> class="std-checkbox-toggle-trigger" data-toggle-class="std-mc-enabled" />
        </div>
    </div>
    <?php $enable_mailchimp = (!empty($std_settings['mailchimp']['enable'])) ? 1 : 0; ?>
    <div class="std-mc-enabled" <?php $this->display_none($enable_mailchimp, 1); ?>>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Mailchimp API Key', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <input type="text" name="std_settings[mailchimp][api_key]" value="<?php echo (!empty($std_settings['mailchimp']['api_key'])) ? esc_attr($std_settings['mailchimp']['api_key']) : ''; ?>" class="std-mailchimp-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://mailchimp.com/help/about-api-keys/#Find_or_Generate_Your_API_Key" 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
                $mailchimp_status = (!empty($std_settings['mailchimp']['status'])) ? 1 : 0;
                $mailchimp_status_class = ($mailchimp_status == 1) ? 'std-mc-connected' : 'std-mc-disconnected';
                ?>
                <input type="hidden" name="std_settings[mailchimp][status]" value="<?php echo intval($mailchimp_status); ?>" class="std-mailchimp-status-flag" />

                <span class="std-mailchimp-status <?php echo esc_attr($mailchimp_status_class); ?>"><?php echo ($mailchimp_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($mailchimp_status)) ? esc_html__('Renew List', 'subscribe-to-download') : esc_html__('Connect', 'subscribe-to-download');
                ?>
                <input type="button" class="std-mailchimp-connect button-secondary" value="<?php echo esc_attr($connect_label); ?>">
                <?php if ($mailchimp_status == 1) {
                ?>
                    <input type="button" class="std-mailchimp-reset button-secondary" value="<?php esc_html_e("Reset", 'subscribe-to-download'); ?>">
                <?php
                }
                ?>
                <div class="std-mailchimp-api-response" style="display:none;"></div>
            </div>
        </div>

        <?php

        ?>
        <div class="std-field-wrap">
            <label><?php esc_html_e('Mailchimp Lists', 'subscribe-to-download'); ?></label>
            <div class="std-field">
                <div class="std-mailchimp-lists-wrap">
                    <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
                        if (!empty($std_settings['mailchimp']['mailchimp_lists'])) {
                            $mailchimp_lists = json_decode(rtrim($std_settings['mailchimp']['mailchimp_lists']));
                            if (!empty($mailchimp_lists->lists)) {
                                foreach ($mailchimp_lists->lists as $mailchimp_list) {
                        ?>
                                    <div class="std-each-list">
                                        <span class="std-list-col"><?php echo esc_attr($mailchimp_list->id); ?></span>
                                        <span class="std-list-col"><?php echo esc_attr($mailchimp_list->name); ?></span>
                                    </div>
                        <?php }
                            }
                        }
                        ?>
                    </div>
                </div>
            </div>
        </div>
        <?php

        ?>

        <textarea name="std_settings[mailchimp][mailchimp_lists]" class="std-mailchimp-lists-input" style="display:none;"><?php echo (!empty($std_settings['mailchimp']['mailchimp_lists'])) ? rtrim($std_settings['mailchimp']['mailchimp_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[mailchimp][mc_log]"><?php echo (!empty($std_settings['mailchimp']['mc_log'])) ? $this->sanitize_html($std_settings['mailchimp']['mc_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>