<?php
/* Prohibit direct script loading */
defined('ABSPATH') || die('No direct script access allowed!');
wp_enqueue_style('wpms-tippy-style');
wp_enqueue_style('wpms-mytippy-style');
wp_enqueue_script('wpms-tippy-core');
wp_enqueue_script('wpms-tippy');
wp_enqueue_script('wpms-my-tippy');
?>
<div class="content-box">
    <?php
    // phpcs:ignore WordPress.Security.NonceVerification.Missing -- View request, no action
    if (isset($_POST['_metaseo_addon_sendemail'])) {
        require_once(WPMETASEO_ADDON_PLUGIN_DIR . 'inc/page/saved_info.php');
    }
    ?>
    <h1 class="wpms-top-h1"><?php esc_html_e('Sender Email', 'wpmsPro') ?>
        <i class="material-icons intro-topic-tooltip" data-tippy="<?php esc_html_e('Send SEO Email report to you or your client that includes WP Meta SEO and Google Analytics data', 'wpmsPro') ?>">help_outline</i>
    </h1>
    <form method="post" action="">
        <div class="ju-settings-option height_140">
            <div class="wpms_row_full">
                <label class="ju-setting-label wpms_width_100 wpms_left"
                       data-tippy="<?php esc_html_e('Add the Email identified as sender', 'wpmsPro'); ?>">
                    <?php esc_html_e('Sender Email', 'wpmsPro') ?>
                </label>
                <p class="p-d-20">
                    <label>
                        <input name="_metaseo_addon_sendemail[showEmailSender]" type="text" id="showEmailSender" class="wpms-large-input wpms_width_100"
                               value="<?php echo esc_attr($this->email_settings['showEmailSender']) ?>"/>
                    </label>
                </p>
            </div>
        </div>

        <div class="ju-settings-option wpms_right m-r-0">
            <div class="wpms_row_full">
                <label class="ju-setting-label wpms_width_100 wpms_left"
                       data-tippy="<?php esc_html_e('Add a subject to your report Email', 'wpmsPro'); ?>">
                    <?php esc_html_e('Email subject', 'wpmsPro') ?>
                </label>
                <p class="p-d-20">
                    <label>
                        <input name="_metaseo_addon_sendemail[showEmailTitle]" type="text" id="showEmailTitle" class="wpms-large-input wpms_width_100"
                               value="<?php echo esc_attr($this->email_settings['showEmailTitle']) ?>"/>
                    </label>
                </p>
            </div>
        </div>

        <div class="ju-settings-option height_140">
            <div class="wpms_row_full">
                <label class="ju-setting-label wpms_width_100"
                       data-tippy="<?php esc_html_e('Change the frequency of the Email reports, or use the Single Email Report
                 to send only manual reports', 'wpmsPro'); ?>">
                    <?php esc_html_e('Email frequency', 'wpmsPro') ?>
                </label>
                <p class="p-d-20">
                    <label>
                        <input type="number" <?php echo(empty($this->email_settings['showEmailFrequency']) ? 'disabled' : '') ?>
                               name="_metaseo_addon_sendemail[numberFrequency]" class="wpms-large-input wpms_width_10" id="numberFrequency"
                               value="<?php echo esc_attr($this->email_settings['numberFrequency']) ?>">
                        <select name="_metaseo_addon_sendemail[showEmailFrequency]" id="showEmailFrequency" class="wpms-large-input">
                            <option <?php selected($this->email_settings['showEmailFrequency'], 0) ?>
                                    value="0"><?php esc_html_e('Single email report', 'wpmsPro') ?></option>
                            <option <?php selected($this->email_settings['showEmailFrequency'], 'month') ?>
                                    value="month"><?php esc_html_e('Month', 'wpmsPro') ?></option>
                            <option <?php selected($this->email_settings['showEmailFrequency'], 'week') ?>
                                    value="week"><?php esc_html_e('Week', 'wpmsPro') ?></option>
                            <option <?php selected($this->email_settings['showEmailFrequency'], 'day') ?>
                                    value="day"><?php esc_html_e('Day', 'wpmsPro') ?></option>
                        </select>
                    </label>
                </p>
            </div>
        </div>

        <div class="ju-settings-option wpms_right m-r-0">
            <div class="wpms_row_full">
                <label class="ju-setting-label wpms_width_100 wpms_left"
                       data-tippy="<?php esc_html_e('The Email of the recipient. Can be several Emails
                 separated by comma', 'wpmsPro'); ?>">
                    <?php esc_html_e('Send report to', 'wpmsPro') ?>
                </label>
                <p class="p-d-20">
                    <label>
                        <input name="_metaseo_addon_sendemail[showEmailSend]" type="email" id="showEmailSend" class="wpms-large-input wpms_width_100"
                               value="<?php echo esc_attr($this->email_settings['showEmailSend']) ?>"/>
                    </label>
                </p>
            </div>
        </div>

        <div class="ju-settings-option wpms_width_100">
            <div class="wpms_row_full">
                <label class="ju-setting-label"
                       data-tippy="<?php esc_html_e('Before the Google Analytics data you can add a custom
                 content to your Email', 'wpmsPro'); ?>">
                    <?php esc_html_e('Before text message', 'wpmsPro') ?>
                </label>
                <div class="p-lr-20 wpms_width_100 wpms_left">
                    <label>
                        <?php
                        $params = array(
                            'textarea_name' => '_metaseo_addon_sendemail[showEmailContent]',
                            'editor_class'  => 'wpms_sendemail',
                            'media_buttons' => true
                        );
                        wp_editor(stripslashes_deep($this->email_settings['showEmailContent']), 'wpms_sendemail', $params); ?>
                    </label>
                </div>
            </div>
        </div>


        <div class="wrap wrap_sendemail wpms_width_100 wpms_left">
            <div>
                <h1 class="wpms-top-h1"><?php esc_html_e('Google analytics data to include in Report', 'wpmsPro') ?></h1>
                <div class="list_add_ga">
                    <?php
                    if (!empty($config)) {
                        foreach ($config as $k => $v) {
                            echo '<p class="row_list_ga" data-value="' . esc_html($k) . '">';
                            echo esc_html__('View: ', 'wpmsPro') . esc_html($v[1] . ' / ' . $v[3]);
                            echo '<span class="wpmsemail_remove_list dashicons dashicons-no-alt"></span>';
                            echo '</p>';
                        }
                    }
                    ?>
                </div>
                <div class="wpmsemail-btn-toolbar wpmsemail-btn-toolbar-date">
                    <?php
                    foreach ($toolbar['dateList'] as $k => $v) {
                        echo '<div class="wpmsemail_date" data-value="' . esc_attr($k) . '">' . esc_html($v) . '</div>';
                    }
                    ?>
                </div>

                <div class="wpmsemail-btn-toolbar wpmsemail-btn-toolbar-report">
                    <?php
                    if ($toolbar['property_type'] === 'GA4') {
                        foreach ($toolbar['reportList_ga4'] as $k => $v) {
                            echo '<div class="wpmsemail_report" data-value="' . esc_attr($k) . '">' . esc_html($v) . '</div>';
                        }
                    } else {
                        foreach ($toolbar['reportList'] as $k => $v) {
                            echo '<div class="wpmsemail_report" data-value="' . esc_attr($k) . '">' . esc_html($v) . '</div>';
                        }
                    }
                    ?>
                </div>
                <button type="button" class="wpmsemail_add_view ju-button orange-button m-tb-20"><?php esc_html_e('Add new analytics view', 'wpmsPro') ?></button>
            </div>

            <h2 class="wpms-top-h2"><?php esc_html_e('WP Meta SEO data to include in report', 'wpmsPro') ?></h2>
            <div class="wpms_row_full">
                <?php
                foreach ($list_meta_datas as $k => $v) {
                    ?>
                    <div class="ju-settings-option list_meta_datas">
                        <div class="wpms_row_full">
                            <input type="hidden" name="_metaseo_settings[home_meta_active]" value="0">
                            <label class="ju-setting-label text">
                                <?php echo esc_html($v) ?>
                            </label>
                            <label class="wpms_right p-lr-20" style="line-height: 50px">
                                    <?php if (in_array($k, $this->email_settings['wpms_email_meta'])) : ?>
                                        <input type="checkbox" name="_metaseo_addon_sendemail[wpms_email_meta][]"
                                               class="wpms_email_meta wpms-checkbox" value="<?php echo esc_attr($k) ?>" id="<?php echo esc_attr('wpms_email_meta' . $k) ?>" checked>
                                    <?php else : ?>
                                        <input type="checkbox" name="_metaseo_addon_sendemail[wpms_email_meta][]"
                                               class="wpms_email_meta wpms-checkbox" value="<?php echo esc_attr($k) ?>" id="<?php echo esc_attr('wpms_email_meta' . $k) ?>">
                                    <?php endif; ?>

                            </label>
                        </div>
                    </div>
                    <?php
                }
                ?>
            </div>
            <?php
            $text = esc_html__('Send Email and Save report', 'wpmsPro');
            ?>
            <p class="submit">
                <button type="submit" name="btn_save_report" id="btn_save_report" class="ju-button orange-button"
                        ><?php esc_html_e('Save report', 'wpmsPro') ?></button>
                <button type="button" name="btn_sendemail" id="btn_sendemail" class="ju-button orange-button"
                        ><?php esc_html_e('Send Email now', 'wpmsPro') ?></button>
                <span class="spinner wpmsemail_spinner"></span>
                <span class="sendemail_msg_success wpms-msg-success"></span>
                <span class="sendemail_msg_error wpms-msg-error"></span>
            </p>
        </div>
    </form>
</div>