<?php
/** @var NewsletterSubscriptionAdmin $this */
/** @var NewsletterControls $controls */
/** @var NewsletterLogger $logger */

defined('ABSPATH') || exit;

if (!$controls->is_action()) {
    $controls->data = $this->get_main_options('htmlforms');
}

if ($controls->is_action('save')) {
    if (!$this->is_html_allowed()) {
        $controls->data = wp_kses_post_deep($controls->data);
    }
    $this->save_main_options($controls->data, 'htmlforms');
    $controls->add_toast_saved();
}
?>

<div class="wrap" id="tnp-wrap">

    <?php include NEWSLETTER_ADMIN_HEADER; ?>

    <div id="tnp-heading">

        <?php $controls->title_help('/subscription/newsletter-forms/') ?>
        <?php include __DIR__ . '/nav-forms.php' ?>

    </div>

    <div id="tnp-body">
        <p>
            <strong>Old feature</strong>. To inject an HTML form use the shortcode <code>[newsletter_form form="X"]</code> where
            <code>X</code> is the form number.
        </p>

        <?php $controls->show(); ?>

        <form method="post" action="">
            <?php $controls->init(); ?>

            <div id="tabs">

                <ul>
                    <li><a href="#tabs-forms">Forms</a></li>
                    <li><a href="#tabs-html">HTML sample</a></li>
                </ul>

                <div id="tabs-forms">
                    <table class="form-table">
                        <?php for ($i = 1; $i <= 10; $i++) { ?>
                            <tr>
                                <th>Form <?php echo $i; ?></th>
                                <td>
                                    <?php $controls->textarea('form_' . $i); ?>
                                </td>
                            </tr>
                        <?php } ?>
                    </table>
                </div>

                <div id="tabs-html">

                    <p>This panel shows the form HTML code generated by Newsletter if you want to copy it as starting point for a custom form.</p>

                    <h3>Standard form code</h3>
                    <textarea readonly style="width: 100%; height: 500px; font-family: monospace"><?php echo esc_html(NewsletterSubscription::instance()->get_subscription_form()); ?></textarea>

                    <h3>Widget form code</h3>
                    <textarea readonly style="width: 100%; height: 500px; font-family: monospace"><?php echo esc_html(NewsletterSubscription::instance()->get_subscription_form()); ?></textarea>

                </div>

            </div>

            <p><?php $controls->button_save(); ?></p>
        </form>

    </div>

    <?php include NEWSLETTER_ADMIN_FOOTER; ?>

</div>
