<?php 
if ( !defined( 'ABSPATH' ) ) {
    exit;
}

$has_subscription_meta = false;

echo '<div class="cv-dashboard-container">';

    $current_user = wp_get_current_user();
    echo '<div class="wpcv-account-header hide-on-desktop">';
        echo '<div class="account-title">';
            echo '<h2>'.esc_html__('Welcome to', 'cv-builder').' '.get_bloginfo('name').'</h2>';
        echo '</div>';
        echo '<div class="wpcv-account-user">';
            echo '<div class="wpcv-greeting">';
                echo esc_html__( 'Hello', 'cv-builder' ).' <span class="wave-emoji"> 👋</span>';
                echo '<span class="wpcv-user-name">'.$current_user->user_login.'</span>';
            echo '</div>';
            echo '<div class="wpcv-avatar">';
                $placeholder_image_url = plugin_dir_url(__FILE__) . '../../includes/assets/img/profile-image.png';
                $user_id = get_current_user_id();
                $uploaded_image_url = get_user_meta( $user_id, 'dashboard_uploaded_image', true );
                $userImage = $uploaded_image_url?$uploaded_image_url:$placeholder_image_url;
                echo '<img src="'.esc_url( $userImage ).'" alt="User Profile">';
            echo '</div>';
        echo '</div>';
    echo '</div>';

    echo '<div class="cv-dashboard-wrapper">';
        
        echo '<div class="tabs">';
        $tab_index = 0;
        echo '<div class="tab active-tab" onclick="showContent(' . $tab_index . ')"><i class="fa-solid fa-house"></i> '.esc_html__( 'Dashboard', 'cv-builder' ).'</div>';
        $tab_index++;
        $bwdcv_show_download_tab = apply_filters('bwdcv_download_tab', true);
        if($bwdcv_show_download_tab){
            echo '<div class="tab" onclick="showContent(' . $tab_index . ')"><i class="fa-solid fa-download"></i> '.esc_html__( 'Download', 'cv-builder' ).'</div>';
            $tab_index++;
        }
        echo '<div class="tab" onclick="showContent(' . $tab_index . ')"><i class="fa-solid fa-user"></i> '.esc_html__( 'Profile', 'cv-builder' ).'</div>';
        $tab_index++;
        $signature = apply_filters('bwdcv_signature', true);
        if ($signature) {
            echo '<div class="tab" onclick="showContent(' . $tab_index . ')"><i class="fa-solid fa-signature"></i> '.esc_html__( 'Signature Maker', 'cv-builder' ).'</div>';
            $tab_index++;
            echo '<div class="tab" onclick="showContent(' . $tab_index . ')"><i class="fa-solid fa-file-signature"></i> '.esc_html__( 'Cover Letter ✨', 'cv-builder' ).'</div>';
            $tab_index++;
        }
        echo '<div class="tab">';
        echo '<a href="' . esc_url( wp_logout_url( site_url() ) ) . '" class="logout-link"><i class="fa-solid fa-right-from-bracket"></i> '.esc_html__( 'Log out', 'cv-builder' ).'</a>';
        echo '</div>';
        echo '</div>';

        echo '<div class="wpcv-tab-content-wrap">';

            echo '<div class="wpcv-account-header hide-on-mobile">';
                echo '<div class="account-title">';
                    echo '<h2>'.esc_html__( 'Welcome to', 'cv-builder' ).' '.get_bloginfo('name').'</h2>';
                echo '</div>';
                echo '<div class="wpcv-account-user">';
                    echo '<div class="wpcv-greeting">';
                        echo esc_html__( 'Hello', 'cv-builder' ).' <span class="wave-emoji"> 👋</span>';
                        echo '<span class="wpcv-user-name">'.$current_user->user_login.'</span>';
                    echo '</div>';
                    echo '<div class="wpcv-avatar">';
                        $placeholder_image_url = plugin_dir_url(__FILE__) . '../../includes/assets/img/profile-image.png';
                        $user_id = get_current_user_id();
                        $uploaded_image_url = get_user_meta( $user_id, 'dashboard_uploaded_image', true );
                        $userImage = $uploaded_image_url?$uploaded_image_url:$placeholder_image_url;
                        echo '<img src="'.esc_url( $userImage ).'" alt="User Profile">';
                    echo '</div>';
                echo '</div>';
            echo '</div>';

            echo '<div class="tab-content active-content" data-index="0">';
                echo '<div class="wpcv-dashboard-wrap">';
                echo '<img src="' . BWDCV_ASFSK_ASSETS_PUBLIC_DIR_FILE . '/img/dash.png" alt="dashboard" class="wpcv-dashboard-img">';
                echo '<span>'.esc_html__( 'Create a professional CV effortlessly with our easy-to-use tool. Showcase your skills, experience, and achievements in a stunning design. Let\'s build your perfect resume today!', 'cv-builder' ).'</span>';
                echo '<div>';
                    $user_id = esc_html( $current_user->ID );
                    $cv_page_id = get_user_meta( $current_user->ID, 'cv_page_id', true );
                    $edit_cv_url = '';
                    if ( $cv_page_id ) {
                        $edit_cv_url = add_query_arg( array(
                            'post'   => $cv_page_id,
                            'action' => 'edit',
                        ), admin_url( 'post.php' ) );
                    }
                    $user_id    = get_current_user_id();
                    $cv_page_id = get_user_meta( $user_id, 'cv_page_id', true );
                    if ( empty( $cv_page_id )) {
                        $edit_cv_url = admin_url( 'admin-post.php?action=bwdcv_past_user_create_edit_page' );
                    }
                    echo '<a href="' . esc_url( $edit_cv_url ) . '" target="_blank" class="button wer dash-edit-cv">' . esc_html( get_option( 'cv_edit_bwd', esc_html__( 'Edit CV', 'cv-builder' ) ) ) . '</a>';
                echo '</div>';
                echo '</div>';
            echo '</div>';
                
            // Download Tab
            if($bwdcv_show_download_tab){
            echo '<div class="tab-content download-tab" data-index="1">';
                echo '<div class="wpcv-download-wrap">';
                if ( !current_user_can('administrator') ) {
                    // ffffff
                    $current_user = wp_get_current_user();
                    $user_id = esc_html( $current_user->ID );
                    $cv_page_id = get_user_meta( $current_user->ID, 'cv_page_id', true );
                    $edit_cv_url = '';
                    if ( $cv_page_id ) {
                        $edit_cv_url = add_query_arg( array(
                            'post'   => $cv_page_id,
                            'action' => 'edit',
                        ), admin_url( 'post.php' ) );
                    }
                    if (is_user_logged_in()) {
                        $user_id = $current_user->ID;
                        $orders = wc_get_orders([
                            'customer_id' => $user_id,
                            'limit' => -1,
                            'status' => ['completed', 'processing'],
                        ]);
                        if (!empty($orders)) {
                            echo '<table id="dataTable" class="display responsive nowrap" style="width:100%">';
        
                            // For download button
                            $options = get_option( 'bwd_userfronted_options' );
                            if($options['subscription_page'] == 'It\'s Free'){
                                $get_permalink = '';
                                $get_class ='bwd-download-text';
                            } elseif ( isset( $options['subscription_page'] ) && !empty( $options['subscription_page'] ) ) {
                                $get_permalink = get_permalink( $options['subscription_page'] );
                                $get_class ='';
                            }
        
                            // Table header
                            echo '<thead>
                                <tr>
                                    <th>' . esc_html__('Plan Name', 'cv-builder') . '</th>
                                    <th>' . esc_html__('Download Limit', 'cv-builder') . '</th>
                                    <th>' . esc_html__('Billing Period', 'cv-builder') . '</th>
                                    <th>' . esc_html__('Total Downloads', 'cv-builder') . '</th>
                                    <th>' . esc_html__('Purchase Date', 'cv-builder') . '</th>
                                    <th>' . esc_html__('Expire Date', 'cv-builder') . '</th>
                                    <th>' . esc_html__('Action', 'cv-builder') . '</th>
                                </tr>
                            </thead>';
                            echo '<tbody>';
        
                            $total_downloads = 0;
                            foreach ($orders as $order) {
                                $order_id = $order->get_id();
                                $order_total = $order->get_total();
                                
                                $purchase_date = $order->get_date_created();
                                $formatted_purchase_date = $purchase_date ?
                                    $purchase_date->setTimezone(new \DateTimeZone(wp_timezone_string()))->format('Y-m-d') : esc_html__('N/A', 'cv-builder');
        
                                $items = $order->get_items();
                                foreach ($items as $item) {
                                    $product_id = $item->get_product_id();
                                    $product_name = $item->get_name();
                                    $plan_name = get_post_meta($product_id, '_subscription_plan_name', true);
        
                                    $cv_download = $order->get_meta( '_subscription_per_download', true );
                                    if ( $cv_download === '' || $cv_download === null || $cv_download === false ) {
                                        $cv_download = get_post_meta( $product_id, '_subscription_per_download', true );
                                        $cv_download = is_numeric( $cv_download ) ? (int) $cv_download : 0;
                                        $order->update_meta_data( '_subscription_per_download', $cv_download );
                                        $order->save();
                                    } else {
                                        $cv_download = is_numeric( $cv_download ) ? (int) $cv_download : 0;
                                    }
                                    
                                    $order_total_downloads = (int) $order->get_meta('_total_downloads', true);
                                    $total_downloads += $order_total_downloads;
        
                                    $subscription_billing_period = (int) $order->get_meta('_subscription_billing_period', true);
                                    if (!$subscription_billing_period) {
                                        $subscription_billing_period = get_post_meta($product_id, '_subscription_billing_period', true);
                                        $order->update_meta_data('_subscription_billing_period', $subscription_billing_period);
                                        $order->save();
                                    }
                                    echo '<tr>';
                                    if($plan_name){
                                        echo '<td>' . esc_html($plan_name ? $plan_name : esc_html__('N/A', 'cv-builder')) . ' (' . wp_kses_post(wc_price($order_total)) . ') </td>';
                                        $subValid = empty( $subscription_billing_period ) ? $cv_download : esc_html__( 'Unlimited', 'cv-builder' );
                                        echo '<td class="cv-download-cell">' . esc_html($cv_download ? $subValid : esc_html__('N/A', 'cv-builder')) . '</td>';
                                        $dayValid = $subscription_billing_period>=2?' Days':' Day';
                                        echo '<td>' . esc_html($subscription_billing_period ? ucfirst($subscription_billing_period) : esc_html__('N/A', 'cv-builder')) . $dayValid.'</td>';
                                        echo '<td class="total-download-cell">' . esc_html($order_total_downloads) . '</td>';
                                        echo '<td>' . esc_html($formatted_purchase_date) . '</td>';
        
                                        $expire_date = '';
                                        if($subscription_billing_period){
                                            $billing_days = 0;
                                            if ($subscription_billing_period == '1') {
                                                $billing_days = 1;
                                            } elseif ($subscription_billing_period == '30') {
                                                $billing_days = 30;
                                            } elseif ($subscription_billing_period == '90') {
                                                $billing_days = 90;
                                            } elseif ($subscription_billing_period == '183') {
                                                $billing_days = 183;
                                            } elseif ($subscription_billing_period == '365') {
                                                $billing_days = 365;
                                            }
                                            if ($purchase_date && $billing_days) {
                                                $purchase_date_obj = new \DateTime($formatted_purchase_date);
                                                $purchase_date_obj->modify("+$billing_days days");
                                                $newDate = $purchase_date_obj->format('Y-m-d');
                                                $expire_date = $subscription_billing_period?$newDate:'';
                                            }
                                        } else{
                                            $expire_date = esc_html__('Unlimited', 'cv-builder');
                                        }
                                        echo '<td>' . esc_html($expire_date) . '</td>';
                                        echo '<td>';
                                        
                                            // Get cv page link
                                            $current_user_id = get_current_user_id();
                                            if (!$current_user_id) {
                                                return false;
                                            }
                                            $args = array(
                                                'post_type'      => 'cv',
                                                'author'         => $current_user_id,
                                                'posts_per_page' => 1,
                                                'order'          => 'ASC',
                                                'orderby'        => 'date'
                                            );
                                            $query = new WP_Query($args);
                                            if ($query->have_posts()) {
                                                $query->the_post();
                                                echo '<a href="'.get_permalink().'" class="bwdcv-view">View CV</a>';
                                            }
                                        echo '</td>';
                                        
                                        $expireCheck = '';
                                        if(\DateTime::createFromFormat('Y-m-d', $expire_date) !== false){
                                            $expireCheck = $expire_date;
                                        }
                                        $current_date = date("Y-m-d");
                                        if (!$cv_download >= 1 || !$current_date <= $expireCheck) {
                                            if (!empty($cv_download) || !empty($subscription_billing_period)) {
                                                $has_subscription_meta = true;
                                                break 2;
                                            }
                                        }



                                    }
                                    echo '</tr>';
                                }
                            }
        
                            echo '</tbody>';
                            echo '</table>';
                        }else {
                            echo '<p>'.esc_html__('Download Not Available Yet', 'cv-builder').'</p>';
                        }
                    }
                }
                echo '</div>';
            echo '</div>';
            }
            //Profile Tab
            echo '<div class="tab-content" data-index="2">';
                echo '<div class="wpcv-page-title-wrap">';
                    // Change page title
                    if ( in_array( 'cv_editor', (array) $current_user->roles ) ) {
                        $pages = get_posts( array(
                            'post_type'   => 'cv',
                            'author'      => $current_user->ID,
                            'post_status' => 'publish',
                        ) );
                    
                        if ( ! empty( $pages ) ) {
                            echo '<form method="post" action="">';
                            foreach ( $pages as $page ) {
                                ?>
                                <p>
                                    <label for="custom_title_<?php echo esc_attr( $page->ID ); ?>">
                                        <?php 
                                        echo '<span>Current Title: '.esc_html( $page->post_title ) . '</span>';
                                        ?>

                                        <input type="text" id="custom_title_<?php echo esc_attr( $page->ID ); ?>" name="custom_titles[<?php echo esc_attr( $page->ID ); ?>]" value="<?php echo esc_attr( $page->post_title ); ?>" placeholder="<?php esc_html_e('Enter new title', 'cv-builder'); ?>">
                                    </label>
                                    
                                </p>
                                <?php
                            }
                            wp_nonce_field( 'save_custom_titles', 'custom_titles_nonce' );
                            echo '<button type="submit" class="button">'.esc_html__('Change Title', 'cv-builder').'</button>';
                            echo '</form>';
                        } else {
                            echo '<p>'.esc_html__('You have not created any pages yet.', 'cv-builder').'</p>';
                        }
                    
                        if ( isset( $_POST['custom_titles'] ) && isset( $_POST['custom_titles_nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['custom_titles_nonce'] ) ), 'save_custom_titles' ) ) {
                            foreach ( $_POST['custom_titles'] as $page_id => $new_title ) {
                                if ( ! empty( $new_title ) ) {
                                    wp_update_post( array(
                                        'ID'         => intval( $page_id ),
                                        'post_title' => sanitize_text_field( $new_title ),
                                    ) );
                                }
                            }
                            echo '<p>'.esc_html__('Page titles have been updated successfully.', 'cv-builder').'</p>';
                        }
                    }
                echo '</div>';

                echo '<div class="wpcv-profile-wrap">';
                // Upload image
                $user_id = get_current_user_id();
                $uploaded_image_url = get_user_meta( $user_id, 'dashboard_uploaded_image', true );
                echo '<h3>'.esc_html__('Profile Information', 'cv-builder').'</h3>';
                if ( $current_user->ID ) {
                    echo '<div class="cv-user-profile-info">';
                    $bwdcv_avoid_username = apply_filters('bwdcv_avoid_username', true);
                    if($bwdcv_avoid_username){
                        echo '<p><strong>'.esc_html__('Username:', 'cv-builder').'</strong> ' . esc_html( $current_user->user_login ) . '</p>';
                    }
                    echo '<p><strong>'.esc_html__('Email:', 'cv-builder').'</strong> ' . esc_html( $current_user->user_email ) . '</p>';
                    echo '</div>';
                }
                echo '<form class="cv-user-img-upload" method="post" enctype="multipart/form-data">
                        <input type="file" name="custom_dashboard_image" accept="image/*" required />
                        <button type="submit" name="submit_dashboard_image">'.esc_html__('Save Image', 'cv-builder').'</button>
                </form>';
            
                echo '</div>';

                echo '<div class="bwdcv-loss-pass-wrap">';
                    echo '<div class="wc-lost-password-form">';
                    
                    // User profile update form
                    if (is_user_logged_in() && isset($_POST['cv_update_profile'])) {
                        $current_user = wp_get_current_user();

                        $new_username = sanitize_user($_POST['cv_username'] ?? '');
                        $new_email = sanitize_email($_POST['cv_email'] ?? '');
                        $new_password = sanitize_text_field($_POST['cv_password'] ?? '');

                        // Username update
                        if (!empty($new_username) && $new_username !== $current_user->user_login) {
                            $result = bwdcv_change_username($current_user->ID, $new_username);
                            if (is_wp_error($result)) {
                                echo "<p style='color:red;'>".esc_html__('Error changing username: ', 'cv-builder').esc_html($result->get_error_message())."</p>";
                            } else {
                                echo "<p style='color:green;'>".esc_html__('Username changed successfully.', 'cv-builder')."</p>";
                            }
                        }

                        // Email update
                        if (!empty($new_email) && $new_email !== $current_user->user_email) {
                            $update_email = wp_update_user([
                                'ID' => $current_user->ID,
                                'user_email' => $new_email,
                            ]);
                            if (is_wp_error($update_email)) {
                                echo "<p style='color:red;'>".esc_html__('Error updating email: ', 'cv-builder').esc_html($update_email->get_error_message())."</p>";
                            } else {
                                echo "<p style='color:green;'>".esc_html__('Email updated successfully.', 'cv-builder')."</p>";
                            }
                        }

                        // Password update
                        if (!empty($new_password)) {
                            // Send email before password change
                            wp_mail(
                                $current_user->user_email,
                                esc_html__('Your CV Profile Has Been Updated', 'cv-builder'),
                                "Hello " . $current_user->display_name . ",\n\nYour profile has been updated successfully.\n\nUsername: {$new_username}\nNew Password: {$new_password}\n\nPlease log in again using your new credentials.",
                                ['Content-Type: text/plain; charset=UTF-8']
                            );

                            // Change password
                            wp_set_password($new_password, $current_user->ID);
                            echo "<p style='color:green;'>".esc_html__('Password changed. Please log in again.', 'cv-builder')."</p>";
                            wp_logout();
                            $options = get_option( 'bwd_userfronted_options' );
                            $getLogPageID = $options['login_page'];
                            wp_redirect(get_permalink($getLogPageID));
                        }
                    }

                    // Already logged in: show update form & hide register button 3
                    if (is_user_logged_in()) {
                        $current_user = wp_get_current_user();
                        ?>
                        <h3><?php echo esc_html__('Update your information?', 'cv-builder'); ?></h3>
                        <form method="post" id="bwdcv-wc-lost-password-ajax">
                            <label><strong><?php echo esc_html__('Username:', 'cv-builder'); ?></strong><br>
                                <input type="text" name="cv_username" value="<?php echo esc_attr($current_user->user_login); ?>" required>
                            </label><br><br>

                            <label><strong><?php echo esc_html__('Email:', 'cv-builder'); ?></strong><br>
                                <input type="email" name="cv_email" value="<?php echo esc_attr($current_user->user_email); ?>" required>
                            </label><br><br>

                            <label><strong><?php echo esc_html__('New Password:', 'cv-builder'); ?></strong><br>
                                <input type="password" name="cv_password" placeholder="<?php echo esc_html__('Leave blank to keep current', 'cv-builder'); ?>">
                            </label><br><br>

                            <button type="submit" name="cv_update_profile"><?php echo esc_html__('Update User', 'cv-builder'); ?></button>
                        </form>
                        <?php
                    }
                    
                    echo '</div>';
                echo '</div>';

            echo '</div>';
            echo '<div class="tab-content" data-index="3">';
                echo '<div id="signatureComboContainer">';
                    echo '<div class="tab-col-wrap">';
                        echo '<h2>'.esc_html__('Text To Signature', 'cv-builder').'</h2>';
                        echo '<input type="text" id="signatureInput" placeholder="'.esc_html__('Type your name', 'cv-builder').'">';

                        echo '<link href="https://fonts.googleapis.com/css2?family=Style+Script&family=Pacifico&family=Great+Vibes&family=Dancing+Script&family=Satisfy&family=Alex+Brush&family=Allura&family=Bad+Script&family=Clicker+Script&family=Damion&family=Handlee&family=Homemade+Apple&family=Kalam&family=Kristi&family=Nothing+You+Could+Do&family=Over+the+Rainbow&family=Parisienne&family=Petit+Formal+Script&family=Sacramento&family=Yellowtail&display=swap" rel="stylesheet">';
                        echo '<div id="custom-font-select">';
                            echo '<div class="selected-font">Select a font</div>';
                            echo '<ul class="font-options" id="fontOption">';
                                $fonts = [
                                    'Style Script', 'Pacifico', 'Great Vibes', 'Dancing Script', 'Satisfy', 'Alex Brush',
                                    'Allura', 'Bad Script', 'Clicker Script', 'Damion', 'Handlee', 'Homemade Apple',
                                    'Kalam', 'Kristi', 'Nothing You Could Do', 'Over the Rainbow', 'Parisienne',
                                    'Petit Formal Script', 'Sacramento', 'Yellowtail'
                                ];
                                foreach ($fonts as $font) {
                                    echo '<li data-font="' . esc_attr($font) . '" style="font-family: \'' . esc_attr($font) . '\';">' . esc_html($font) . '</li>';
                                }
                            echo '</ul>';
                        echo '</div>';
                        echo '<input type="hidden" id="fontSelect" name="fontSelect" value="">';

                        echo '<div class="cv-generate-sig">';
                        echo '<label>';
                        echo '<input type="color" id="textSignatureColor" value="#353535">';
                        echo '<span class="cv-color-picker-label">353535</span>';
                        echo '</label>';
                        echo '</div>';

                        echo '<canvas id="textCanvas" width="300" height="100"></canvas>';
                        echo '<br>';
                        echo '<button id="saveTextSignature">'.esc_html__( 'Save', 'cv-builder' ).'</button>';
                    echo '</div>';
                    echo '<div class="tab-col-wrap">';
                        echo '<h2>'.esc_html__( 'Draw Signature', 'cv-builder' ).'</h2>';

                        echo '<div class="cv-draw-sig">';
                        echo '<label>';
                        echo '<input type="color" id="drawSignatureColor" value="#353535">';
                        echo '<span class="cv-color-picker-drawlabel">353535</span>';
                        echo '</label>';
                        echo '<button id="clearDrawSignature"><i class="fa-solid fa-eraser"></i> '.esc_html__( 'Clear', 'cv-builder' ).'</button>';
                        echo '</div>';

                        echo '<canvas id="drawCanvas" width="300" height="100"></canvas>';
                        echo '<br>';
                    
                        echo '<button id="saveDrawSignature">'.esc_html__( 'Save', 'cv-builder' ).'</button>';
                        
                    echo '</div>';
                echo '</div>';
                echo '<div id="signatureResponse" style="text-align: center;color: #23ad00;align-items: center;"></div>';
            echo '</div>';

            echo '<div class="tab-content" data-index="4">';
                ?>
                <div class="open-ai-cover-letter">
                    <h1><?php esc_html_e( 'Build a Cover Letter with AI', 'cv-builder' ); ?></h1>
                    <div class="openai-wrap-cover-letter">
                        <div class="form-row">
                        <input type="text" id="userName" placeholder="<?php esc_html_e( 'Enter your name', 'cv-builder' ); ?>" value="John Doe" required />
                        </div>
                        <div class="form-row">
                        <input type="email" id="userEmail" placeholder="<?php esc_html_e( 'Enter your email', 'cv-builder' ); ?>" value="info@example.com" required />
                        </div>
                        <div class="form-row">
                        <input type="text" id="userDesignation" placeholder="<?php esc_html_e( 'Enter your designation', 'cv-builder' ); ?>" value="Software Developer" required />
                        </div>
                        <div class="form-row">
                        <input type="text" id="companyName" placeholder="<?php esc_html_e( 'Enter company name', 'cv-builder' ); ?>" value="BWD" required />
                        </div>
                        <div class="form-row">
                        <input type="text" id="receiverName" placeholder="<?php esc_html_e( 'Enter receiver\'s name', 'cv-builder' ); ?>" value="Receiver" required />
                        </div>
                        <div class="form-row">
                        <input type="text" id="tags" placeholder="<?php esc_html_e( 'Enter keywords (e.g., PHP, WordPress)', 'cv-builder' ); ?>" value="PHP, WordPress, JS" required />
                        </div>
                        <div class="form-row  fit-col">
                        <textarea id="userInput" placeholder="<?php esc_html_e( 'Short Description, tags etc', 'cv-builder' ); ?>" value="Short Description"></textarea>
                        <?php
                        if ($has_subscription_meta==true || get_option('cv_cover_letter_allow','on')=='on') {
                            echo '<button id="sendCoverLetterPrompt">'.esc_html__( 'Generate Cover Letter', 'cv-builder' ).'</button>';
                            echo '<div id="cover-letter-result" contenteditable="true"></div>';
                            echo '<button id="printBtn" onclick="printCoverLetter()">'.esc_html__( 'Download as PDF', 'cv-builder' ).'</button>';
                        } else{
                            echo '<button id="free-user-cover-letter">'.esc_html__( 'Generate Cover Letter', 'cv-builder' ).'</button>';
                            echo '<div class="overlay" id="overlay"></div>';
                            echo '<div class="popup" id="popup">';
                                echo '<div class="text"><h1>'.esc_html__( 'Oops!', 'cv-builder' ).'</h1> '.esc_html__('To generate a cover letter with', 'cv-builder').'<strong>✦ '.esc_html__('AI', 'cv-builder').' ✦</strong> '.esc_html__('you have to subscribe.', 'cv-builder').'</div>';
                                echo '<button class="close-btn">'.esc_html__( 'Close', 'cv-builder' ).'</button>';
                                $options = get_option( 'bwd_userfronted_options' );
                                $getPageID = $options['subscription_page'];
                                echo '<a href="'.get_permalink($getPageID).'" class="subscribe-btn">'.esc_html__( 'Subscribe Now', 'cv-builder' ).'</a>';
                            echo '</div>';
                        }
                        ?>
                        </div>
                    </div>
                </div>
                <?php
            echo '</div>';
        echo '</div>';
    echo '</div>';

echo '</div>';




