<?php defined( 'ABSPATH' ) || die( 'Cheating uh?' ); ?>
<?php if ( ! isset( $view ) ) {
    return;
} ?>
<?php if ( HMWP_Classes_Tools::getOption( 'test_frontend' ) && HMWP_Classes_Tools::getOption( 'hmwp_mode' ) <> 'default' ) {
    add_action(
            'home_url',
            array(
                    HMWP_Classes_ObjController::getClass( 'HMWP_Models_Rewrite' ),
                    'home_url',
            ),
            PHP_INT_MAX,
            1
    );
    ?>
    <div class="col-sm-12 p-0 mx-0 mt-0 mb-3">

        <div class="col-sm-12 border-danger bg-white border py-3 mx-0 my-0">

            <div class="text-center my-4">
                <div class="hmwp_confirm" style="display: inline-block; margin-right: 5px;">
                    <form class="hmwp_frontendcheck_form" method="POST">
                        <?php wp_nonce_field( 'hmwp_frontendcheck', 'hmwp_nonce' ) ?>
                        <input type="hidden" name="action" value="hmwp_frontendcheck"/>
                        <button type="button" class="btn rounded-0 btn-default btn-lg px-4 frontend_test"><?php echo esc_html__( 'Frontend Test', 'hide-my-wp' ); ?></button>
                    </form>
                </div>
                <div class="text-center" style="display: inline-block; margin-right: 5px;">
                    <button type="button" class="btn rounded-0 btn-default btn-lg px-4 login_test hmwp_modal" data-remote="<?php echo esc_url( site_url() . '/' . HMWP_Classes_Tools::getOption( 'hmwp_login_url' ) . '?nordt=1&hmwp_preview=' . HMWP_Classes_Tools::getOption( 'hmwp_disable_name' ) ) ?>" data-target="#frontend_test_modal"><?php echo esc_html__( 'Login Test', 'hide-my-wp' ); ?></button>
                </div>
            </div>
            <div id="hmwp_frontendcheck_content" class="my-3"></div>
            <div id="hmwp_solutions" style="display: none">
                <div class="my-3 pt-3 border-top border-white text-center">
                    <div class="mb-2" style="font-weight:700;font-size:1rem;"><?php echo esc_html__( 'How to fix this', 'hide-my-wp' ); ?></div>
                    <div class="mb-3 mx-auto" style="max-width:620px;font-size:0.9rem;"><?php echo esc_html__( "The hidden paths return 404, which means the rewrite rules are not active on your server. Follow the setup guide for your server below, clear your cache, then run the Frontend Test again.", 'hide-my-wp' ); ?></div>
                    <?php if ( HMWP_Classes_Tools::isLitespeed() ) { ?>
                        <div class="mb-2">
                            <a href="<?php echo esc_url( HMWP_Classes_Tools::getSettingsUrl( 'litespeed-toolbox' ) ) ?>" target="_blank">Make sure you purge
                                <strong>LiteSpeed cache</strong></a></div>
                    <?php } ?>
                    <?php if ( HMWP_Classes_Tools::isApache() && ! HMWP_Classes_Tools::isWpengine() ) { ?>
                        <div class="mb-2">
                            <a href="<?php echo esc_url( HMWP_Classes_Tools::getOption('hmwp_plugin_website') . '/kb/how-to-set-allowoverride-all/' ) ?>" target="_blank">Make sure to activate
                                <strong>AllowOverride All</strong> for your website directory</a></div>
                    <?php } ?>
                    <?php if ( HMWP_Classes_Tools::isNginx() ) { ?>
                        <div class="mb-2">
                            <a href="<?php echo esc_url( HMWP_Classes_Tools::getSettingsUrl( 'hmwp_advanced&tab=compatibility', true ) ) ?>" target="_blank">Select Server Type</a>
                        </div>
                        <div class="mb-2">
                            <a href="<?php echo esc_url( HMWP_Classes_Tools::getOption('hmwp_plugin_website') . '/kb/setup-wp-ghost-on-nginx-server/' ) ?>" target="_blank">Setup The Plugin On Nginx Server</a>
                        </div>
                        <div class="mb-2">
                            <a href="<?php echo esc_url( HMWP_Classes_Tools::getOption('hmwp_plugin_website') . '/kb/setup-wp-ghost-on-nginx-web-server-with-virtual-private-server/' ) ?>" target="_blank">Setup The Plugin On Nginx Server with Virtual Private Server</a>
                        </div>
                    <?php } ?>
                    <?php if ( HMWP_Classes_Tools::isWpengine() ) { ?>
                        <div class="mb-2">
                            <a href="<?php echo esc_url( HMWP_Classes_Tools::getOption('hmwp_plugin_website') . '/kb/wp-engine-wp-ghost-setup/' ) ?>" target="_blank">Setup The Plugin On WP Engine</a>
                        </div>
                    <?php } ?>
                    <?php if ( HMWP_Classes_Tools::isGodaddy() ) { ?>
                        <div class="mb-2">
                            <a href="<?php echo esc_url( HMWP_Classes_Tools::getOption('hmwp_plugin_website') . '/kb/godaddy-hosting-wp-ghost-setup/' ) ?>" target="_blank">Setup The Plugin On Godaddy</a>
                        </div>
                    <?php } ?>
                    <?php if ( HMWP_Classes_Tools::isIIS() ) { ?>
                        <div class="mb-2">
                            <a href="<?php echo esc_url( HMWP_Classes_Tools::getOption('hmwp_plugin_website') . '/kb/setup-wp-ghost-on-windows-iis-server/' ) ?>" target="_blank">Setup The Plugin On Windows IIS Server</a>
                        </div>
                    <?php } ?>
                    <?php if ( HMWP_Classes_Tools::isInmotion() ) { ?>
                        <div class="mb-2">
                            <a href="<?php echo esc_url( HMWP_Classes_Tools::getOption('hmwp_plugin_website') . '/kb/inmotion-wordpress-hosting-wp-ghost-setup/' ) ?>" target="_blank">Setup The Plugin On Inmotion Server</a>
                        </div>
                    <?php } ?>
                </div>
            </div>

            <ol>
                <li>
                    <?php
                    echo wp_kses_post(
                            sprintf(
                            /* translators: 1: Opening <strong> tag. 2: Closing </strong> tag. */
                                    __( 'Run %1$sFrontend Test%2$s to check if the new paths are working.', 'hide-my-wp' ),
                                    '<strong>',
                                    '</strong>'
                            )
                    );
                    ?>
                </li>
                <li>
                    <?php
                    echo wp_kses_post(
                            sprintf(
                            /* translators: 1: Opening <strong> tag. 2: Closing </strong> tag. */
                                    __( 'Run %1$sLogin Test%2$s and log in inside the popup.', 'hide-my-wp' ),
                                    '<strong>',
                                    '</strong>'
                            )
                    );
                    ?>
                </li>
                <li><?php echo esc_html__( "If you're able to log in, you've set the new paths correctly.", 'hide-my-wp' ); ?></li>
                <li><?php echo esc_html__( 'Do not log out from this browser until you are confident that the Log in page is working and you will be able to login again.', 'hide-my-wp' ); ?></li>
                <li>
                    <?php
                    echo wp_kses_post(
                            sprintf(
                            /* translators: 1: Plugin name. 2: Opening anchor tag. 3: Closing anchor tag. */
                                    __( 'If you can\'t configure %1$s, switch to Deactivated Mode and %2$scontact us%3$s.', 'hide-my-wp' ),
                                    esc_html( HMWP_Classes_Tools::getOption( 'hmwp_plugin_name' ) ),
                                    '<a href="' . esc_url( HMWP_Classes_Tools::getOption( 'hmwp_plugin_website' ) . '/contact/' ) . '" target="_blank" rel="noopener">',
                                    '</a>'
                            )
                    );
                    ?>
                </li>
            </ol>

            <?php
            if ( defined( 'HMWP_DEFAULT_LOGIN' ) && HMWP_DEFAULT_LOGIN ) {
                if ( stripos( HMWP_DEFAULT_LOGIN, home_url() ) !== false ) {
                    $custom_login = HMWP_DEFAULT_LOGIN;
                } else {
                    $custom_login = home_url( HMWP_DEFAULT_LOGIN );
                }
                ?>
                <div class="wp-admin_warning col-sm-12 my-4 text-danger p-0 text-center">
                    <div class="mb-3">
                        <?php
                        echo wp_kses_post(
                                sprintf(
                                /* translators: %s: Login URL rendered as a clickable link. */
                                        __( 'Your login URL is: %s', 'hide-my-wp' ),
                                        '<br /><a href="' . esc_url( $custom_login ) . '" target="_blank" rel="noopener">' . esc_url( $custom_login ) . '</a>'
                                )
                        );
                        ?>
                    </div>
                </div>
            <?php } else { ?>
                <div class="wp-admin_warning col-sm-12 my-4 text-danger p-0 text-center">
                    <div class="mb-3">
                        <?php
                        $login_url = site_url() . '/' . HMWP_Classes_Tools::getOption( 'hmwp_login_url' );
                        $safe_url  = site_url() . '/wp-login.php?' . HMWP_Classes_Tools::getOption( 'hmwp_disable_name' );

                        echo wp_kses_post(
                                sprintf(
                                /* translators: 1: Login URL rendered as a clickable link. 2: Safe URL rendered as a clickable link. */
                                        __( 'Your login URL will be: %1$s In case you can\'t log in, use the safe URL: %2$s', 'hide-my-wp' ),
                                        '<br /><a href="' . esc_url( $login_url ) . '" target="_blank" rel="noopener">' . esc_url( $login_url ) . '</a><br /><br />',
                                        '<br /><a href="' . esc_url( $safe_url ) . '" target="_blank" rel="noopener">' . esc_url( $safe_url ) . '</a>'
                                )
                        );
                        ?>
                    </div>
                </div>
            <?php } ?>

            <div class="p-0 text-center">
                <div class="hmwp_confirm">
                    <form method="POST">
                        <?php wp_nonce_field( 'hmwp_confirm', 'hmwp_nonce' ); ?>
                        <input type="hidden" name="action" value="hmwp_confirm"/>
                        <input type="submit" class="btn btn-success" value="<?php echo esc_attr__( 'Yes, it\'s working', 'hide-my-wp' ) ?>"/>
                    </form>
                </div>
                <div class="hmwp_abort" style="display: inline-block; margin-left: 5px;">
                    <form method="POST">
                        <?php wp_nonce_field( 'hmwp_abort', 'hmwp_nonce' ); ?>
                        <input type="hidden" name="action" value="hmwp_abort"/>
                        <input type="submit" class="btn btn-secondary" value="<?php echo esc_attr__( 'No, abort', 'hide-my-wp' ) ?>"/>
                    </form>
                </div>
            </div>
        </div>
        <div class="modal" id="frontend_test_modal" tabindex="-1" role="dialog" aria-hidden="true">
            <div class="modal-dialog modal-lg" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <h5 class="modal-title" id="exampleModalLabel"><?php echo esc_html__( 'Frontend Login Test', 'hide-my-wp' ); ?></h5>
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                    </div>
                    <iframe class="modal-body" style="min-height: 500px;"></iframe>
                </div>
            </div>
        </div>

    </div>
<?php } ?>