<?php
$form_details = maybe_unserialize($form_row->form_details);
$form_template = (!empty($atts['template'])) ? $atts['template'] : $form_details['layout']['template'];
if (!empty($form_details['general']['instant_download'])) {
    $download_button_condition  = (isset($_COOKIE['std_encryption_key']) && $this->check_if_already_subscribed($_COOKIE['std_encryption_key']) && empty($form_details['general']['always_show']));
} else {
    $download_button_condition  = (isset($_COOKIE['std_encryption_key'], $_COOKIE['std_download_verified_key']) && $this->check_if_already_subscribed($_COOKIE['std_encryption_key']) && empty($form_details['general']['always_show']) && $_COOKIE['std_encryption_key'] == $_COOKIE['std_download_verified_key']);
}
if ($download_button_condition) {

    /**
     * Triggers just before displaying the download button
     *
     * @param object $form_row
     *
     * @since 1.0.0
     */
    do_action('std_before_download', $form_row);
    include(STD_PATH . 'inc/views/frontend/download-button.php');

    /**
     * Triggers just after displaying the download button
     *
     * @param object $form_row
     *
     * @since 1.0.0
     */
    do_action('std_after_download', $form_row);
} else {
?>
    <?php
    $alias_class = 'std-' . $form_row->form_alias;
    $popup_alias_class = 'std-popup-' . $form_row->form_alias;
    $heading_show = (!empty($form_details['form']['heading']['show'])) ? true : false;
    $heading_text = $form_details['form']['heading']['text'];
    $sub_heading_show = (!empty($form_details['form']['sub_heading']['show'])) ? true : false;
    $sub_heading_text = $form_details['form']['sub_heading']['text'];
    $name_show = (!empty($form_details['form']['name']['show'])) ? true : false;
    if (!empty($form_details['form']['fields']['name']['label'])) {
        $name_label = $form_details['form']['fields']['name']['label'];
    } else if (!empty($form_details['form']['name']['label'])) {
        $name_label = $form_details['form']['name']['label'];
    } else {
        $name_label = '';
    }
    if (!empty($form_details['form']['fields']['email']['label'])) {
        $email_label = $form_details['form']['fields']['email']['label'];
    } else if (!empty($form_details['form']['email']['label'])) {
        $email_label = $form_details['form']['email']['label'];
    } else {
        $email_label = '';
    }
    $terms_agreement_show = (!empty($form_details['form']['terms_agreement']['show'])) ? true : false;
    $terms_agreement_text = $form_details['form']['terms_agreement']['agreement_text'];
    $gdpr_agreement_show = (!empty($form_details['form']['gdpr_agreement']['show'])) ? true : false;
    $gdpr_agreement_text = (!empty($form_details['form']['gdpr_agreement']['agreement_text'])) ? $form_details['form']['gdpr_agreement']['agreement_text'] : '';
    $subscribe_button_text = $form_details['form']['subscribe_button']['button_text'];
    $footer_show = (!empty($form_details['form']['footer']['show'])) ? true : false;
    $footer_text = $form_details['form']['footer']['footer_text'];
    $display_type = $form_details['layout']['display_type'];
    $popup_trigger_text = $form_details['layout']['popup_trigger_text'];
    if ($display_type == 'direct') {
        include(STD_PATH . 'inc/views/frontend/form-template.php');
    } else {
    ?>
        <div class="std-popup-outerwrap <?php echo esc_attr($popup_alias_class); ?>">
            <?php
            $popup_trigger_type = (!empty($form_details['layout']['popup_trigger_type'])) ? $form_details['layout']['popup_trigger_type'] : 'text';
            if ($popup_trigger_type == 'text') {
            ?>
                <input type="button" class="std-popup-trigger std-popup-<?php echo esc_attr($form_template); ?>" value="<?php echo esc_attr($popup_trigger_text); ?>">
            <?php } else {
            ?>
                <img src="<?php echo esc_url($form_details['layout']['trigger_image']) ?>" class="std-popup-trigger" />
            <?php }
            ?>
            <div class="std-popup-innerwrap" style="display:none;">
                <div class="std-overlay std-popup-wrapper">

                    <div class="std-popup-contetn-wrap">
                        <a href="javascript:void(0)" class="std-popup-close"><i class="fas fa-times"></i></a>
                        <?php include(STD_PATH . 'inc/views/frontend/form-template.php');
                        ?>
                    </div>
                </div>
            </div>
        </div>
<?php
    }

    include(STD_PATH . 'inc/cores/customize.php');
}
