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

    $transferMethod = get_transient('transferito_transfer_method');
    $isLocalMigration = $transferMethod === 'localSiteMigration';
?>

<div class="transferito-navigation">

    <?php if (isset($data['sidebarNavigation']['destinationURL'])): ?>
        <div class="transferito-navigation__item">
            <?php if ($data['sidebarNavigation']['destinationURL'] === 'completed'): ?>
                <div class="transferito-navigation__item-connector"></div>
            <?php endif; ?>
            <div class="transferito-navigation__item-icon <?php echo ($data['sidebarNavigation']['destinationURL'] === 'disabled') ? 'transferito-navigation__item-icon--disabled' : ''; ?>">
                <div class="transferito-icon <?php echo ($data['sidebarNavigation']['destinationURL'] === 'completed') ? 'transferito-icon--completed' : 'transferito-icon--link'; ?>"></div>
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-anchor transferito-text__p1--bold">
                    Destination URL
                </div>
                <?php if ($data['sidebarNavigation']['destinationURL'] === 'completed'): ?>
                    <div class="transferito-navigation__item-information">
                        <div class="transferito-navigation__content transferito-text__small">
                            <?php echo esc_html(get_transient('transferito_migration_domain')); ?>
                        </div>
                        <?php if (isset($data['sidebarNavigation']['startMigration']) && $data['sidebarNavigation']['startMigration'] !== 'active'): ?>
                        <div data-screen-route="destinationURL" class="transferito-navigation__link transferito__screen-routing transferito-text__small--semi-bold">Update</div>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['chooseMethod'])): ?>
        <div class="transferito-navigation__item">
            <?php if ($data['sidebarNavigation']['chooseMethod'] === 'completed'): ?>
                <div class="transferito-navigation__item-connector"></div>
            <?php endif; ?>
            <div class="transferito-navigation__item-icon <?php echo ($data['sidebarNavigation']['chooseMethod'] === 'disabled') ? 'transferito-navigation__item-icon--disabled' : ''; ?>">
                <div class="transferito-icon <?php echo ($data['sidebarNavigation']['chooseMethod'] === 'completed') ? 'transferito-icon--completed' : 'transferito-icon--choose'; ?>"></div>
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-anchor transferito-text__p1--bold">
                    Choose Method
                </div>
                <?php if ($data['sidebarNavigation']['chooseMethod'] === 'completed'): ?>
                    <div class="transferito-navigation__item-information">
                        <div class="transferito-navigation__content transferito-text__small">
                            <?php if ($transferMethod === 'cpanel'): ?>cPanel<?php endif; ?>
                            <?php if ($transferMethod === 'manual'): ?>FTP<?php endif; ?>
                            <?php if ($transferMethod === 'localSiteMigration'): ?>Local<?php endif; ?>
                        </div>
                        <?php if (isset($data['sidebarNavigation']['startMigration']) && $data['sidebarNavigation']['startMigration'] !== 'active'): ?>
                        <div data-screen-route="migrationMethodSelection" class="transferito-navigation__link transferito__screen-routing transferito-text__small--semi-bold">Update</div>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['connectToServer'])): ?>
        <div class="transferito-navigation__item">
            <?php if ($data['sidebarNavigation']['connectToServer'] === 'completed'): ?>
                <div class="transferito-navigation__item-connector"></div>
            <?php endif; ?>
            <div class="transferito-navigation__item-icon <?php echo ($data['sidebarNavigation']['connectToServer'] === 'disabled') ? 'transferito-navigation__item-icon--disabled' : ''; ?>">
                <div class="transferito-icon <?php echo ($data['sidebarNavigation']['connectToServer'] === 'completed') ? 'transferito-icon--completed' : 'transferito-icon--choose'; ?>"></div>
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-anchor transferito-text__p1--bold">
                    Connect To Server
                </div>
                <?php if ($data['sidebarNavigation']['connectToServer'] === 'completed'): ?>
                    <div class="transferito-navigation__item-information">
                        <div class="transferito-navigation__content transferito-text__small">Connected</div>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['cPanelAuthentication']) && !$isLocalMigration): ?>
        <div class="transferito-navigation__item">
            <?php if ($data['sidebarNavigation']['cPanelAuthentication'] === 'completed'): ?>
                <div class="transferito-navigation__item-connector"></div>
            <?php endif; ?>
            <div class="transferito-navigation__item-icon <?php echo ($data['sidebarNavigation']['cPanelAuthentication'] === 'disabled') ? 'transferito-navigation__item-icon--disabled' : ''; ?>">
                <div class="transferito-icon <?php echo ($data['sidebarNavigation']['cPanelAuthentication'] === 'completed') ? 'transferito-icon--completed' : 'transferito-icon--authentication'; ?>"></div>
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-anchor transferito-text__p1--bold">
                    cPanel Authentication
                </div>
                <?php if ($data['sidebarNavigation']['cPanelAuthentication'] === 'completed'): ?>
                    <?php
                    /**
                     * cPanel details
                     */
                    $cpanelDetails = get_transient('transferito_cpanel_auth_details');
                    ?>
                    <div class="transferito-navigation__item-information">
                        <div class="transferito-navigation__title transferito-text__small--semi-bold">cPanel Username:</div>
                        <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($cpanelDetails['cpanelUser']);?></div>
                        <?php if (!$cpanelDetails['cPanelUseApiToken']) : ?>
                            <div class="transferito-navigation__title transferito-text__small--semi-bold">cPanel Password:</div>
                            <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($cpanelDetails['cpanelPass']);?></div>
                        <?php endif; ?>
                        <?php if ($cpanelDetails['cPanelUseApiToken']) : ?>
                            <div class="transferito-navigation__title transferito-text__small--semi-bold">cPanel API Token:</div>
                            <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($cpanelDetails['cPanelApiToken']);?></div>
                        <?php endif; ?>
                        <?php if (isset($data['sidebarNavigation']['startMigration']) && $data['sidebarNavigation']['startMigration'] !== 'active'): ?>
                        <div data-screen-route="cpanelAuthentication" class="transferito-navigation__link transferito__screen-routing transferito-text__small--semi-bold">Update</div>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['selectDomain']) && !$isLocalMigration): ?>
        <div class="transferito-navigation__item">
            <?php if ($data['sidebarNavigation']['selectDomain'] === 'completed'): ?>
                <div class="transferito-navigation__item-connector"></div>
            <?php endif; ?>
            <div class="transferito-navigation__item-icon <?php echo ($data['sidebarNavigation']['selectDomain'] === 'disabled') ? 'transferito-navigation__item-icon--disabled' : ''; ?>">
                <div class="transferito-icon <?php echo ($data['sidebarNavigation']['selectDomain'] === 'completed') ? 'transferito-icon--completed' : 'transferito-icon--domain'; ?>"></div>
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-anchor transferito-text__p1--bold">
                    Select Domain
                </div>
                <?php if ($data['sidebarNavigation']['selectDomain'] === 'completed'): ?>
                    <div class="transferito-navigation__item-information">
                        <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html(get_transient('transferito_migration_domain')); ?></div>
                        <?php if (isset($data['sidebarNavigation']['startMigration']) && $data['sidebarNavigation']['startMigration'] !== 'active'): ?>
                        <div class="transferito-navigation__link transferito-text__small--semi-bold">Update</div>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['ftpAuthentication']) && !$isLocalMigration): ?>
        <div class="transferito-navigation__item">
            <?php if ($data['sidebarNavigation']['ftpAuthentication'] === 'completed'): ?>
                <div class="transferito-navigation__item-connector"></div>
            <?php endif; ?>
            <div class="transferito-navigation__item-icon <?php echo ($data['sidebarNavigation']['ftpAuthentication'] === 'disabled') ? 'transferito-navigation__item-icon--disabled' : ''; ?>">
                <div class="transferito-icon <?php echo ($data['sidebarNavigation']['ftpAuthentication'] === 'completed') ? 'transferito-icon--completed' : 'transferito-icon--authentication'; ?>"></div>
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-anchor transferito-text__p1--bold">
                    FTP Details
                </div>
                <?php if ($data['sidebarNavigation']['ftpAuthentication'] === 'completed'): ?>
                    <?php
                        /**
                         * FTP Details
                         */
                        $ftpDetail = get_transient('transferito_manual_server_detail');
                        $ftpPassword = stripslashes(sanitize_text_field($ftpDetail['ftpPass']));
                    ?>
                    <div class="transferito-navigation__item-information">

                        <div class="transferito-navigation__title transferito-text__small--semi-bold">Connection Type:</div>
                        <div class="transferito-navigation__content transferito-text__small"><?php echo ($ftpDetail['useSFTP']) == '0' ? 'FTP' : 'SFTP';?></div>
                        <div class="transferito-navigation__title transferito-text__small--semi-bold">FTP Host:</div>
                        <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($ftpDetail['ftpHost']);?></div>
                        <div class="transferito-navigation__title transferito-text__small--semi-bold">FTP Username:</div>
                        <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($ftpDetail['ftpUser']);?></div>
                        <div class="transferito-navigation__title transferito-text__small--semi-bold">FTP Password:</div>
                        <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($ftpPassword);?></div>
                        <div class="transferito-navigation__title transferito-text__small--semi-bold">FTP Port:</div>
                        <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($ftpDetail['ftpPort']);?></div>
                        <?php if (isset($data['sidebarNavigation']['startMigration']) && $data['sidebarNavigation']['startMigration'] !== 'active'): ?>
                        <div data-screen-route="ftpAuthentication" class="transferito-navigation__link transferito__screen-routing transferito-text__small--semi-bold">Update</div>
                        <?php endif; ?>

                    </div>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['selectDirectory']) && !$isLocalMigration): ?>
        <div class="transferito-navigation__item">
            <?php if ($data['sidebarNavigation']['selectDirectory'] === 'completed'): ?>
                <div class="transferito-navigation__item-connector"></div>
            <?php endif; ?>
            <div class="transferito-navigation__item-icon <?php echo ($data['sidebarNavigation']['selectDirectory'] === 'disabled') ? 'transferito-navigation__item-icon--disabled' : ''; ?>">
                <div class="transferito-icon <?php echo ($data['sidebarNavigation']['selectDirectory'] === 'completed') ? 'transferito-icon--completed' : 'transferito-icon--folder'; ?>"></div>
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-anchor transferito-text__p1--bold">
                    Select Directory
                </div>
                <?php if ($data['sidebarNavigation']['selectDirectory'] === 'completed'): ?>
                    <div class="transferito-navigation__item-information">
                        <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($ftpDetail['ftpPath']);?></div>
                        <?php if (isset($data['sidebarNavigation']['startMigration']) && $data['sidebarNavigation']['startMigration'] !== 'active'): ?>
                        <div data-screen-route="directorySelector" class="transferito-navigation__link transferito__screen-routing transferito-text__small--semi-bold">Update</div>
                        <?php endif; ?>

                    </div>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['databaseAuthentication']) && !$isLocalMigration): ?>
        <div class="transferito-navigation__item">
            <?php if ($data['sidebarNavigation']['databaseAuthentication'] === 'completed'): ?>
                <div class="transferito-navigation__item-connector"></div>
            <?php endif; ?>
            <div class="transferito-navigation__item-icon <?php echo ($data['sidebarNavigation']['databaseAuthentication'] === 'disabled') ? 'transferito-navigation__item-icon--disabled' : ''; ?>">
                <div class="transferito-icon <?php echo ($data['sidebarNavigation']['databaseAuthentication'] === 'completed') ? 'transferito-icon--completed' : 'transferito-icon--database'; ?>"></div>
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-anchor transferito-text__p1--bold">
                    Database Details
                </div>
                <?php if ($data['sidebarNavigation']['databaseAuthentication'] === 'completed'): ?>
                    <?php
                    /**
                     * FTP Details
                     */
                    $ftpDetail = get_transient('transferito_manual_server_detail');
                    $dbPassword = stripslashes(sanitize_text_field($ftpDetail['dbPass']));

                    ?>
                    <div class="transferito-navigation__item-information">

                        <?php if (isset($ftpDetail['use_existing_database'])) :?>
                            <div class="transferito-navigation__content transferito-text__small">Use Existing Database</div>
                        <?php endif; ?>

                        <?php if (isset($ftpDetail['exclude_database_transfer'])) :?>
                            <div class="transferito-navigation__content transferito-text__small">Exclude Database</div>
                        <?php endif; ?>

                        <?php if (!isset($ftpDetail['use_existing_database']) && !isset($ftpDetail['exclude_database_transfer'])) : ?>

                            <?php if (isset($ftpDetail['dbHost']) && $ftpDetail['dbHost']) :?>
                                <div class="transferito-navigation__title transferito-text__small--semi-bold">Database Host:</div>
                                <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($ftpDetail['dbHost']);?></div>
                            <?php endif; ?>

                            <div class="transferito-navigation__title transferito-text__small--semi-bold">Database Name:</div>
                            <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($ftpDetail['dbName']);?></div>
                            <div class="transferito-navigation__title transferito-text__small--semi-bold">Database User:</div>
                            <div class="transferito-navigation__content transferito-text__small"><?php echo esc_html($ftpDetail['dbUser']);?></div>
                            <div class="transferito-navigation__title transferito-text__small--semi-bold">Database Password:</div>
                            <div class="transferito-navigation__content transferito-text__small">
                                <?php echo esc_html(htmlspecialchars(base64_decode($dbPassword), ENT_QUOTES, 'UTF-8'));?>
                            </div>
                        <?php endif; ?>

                        <?php if (isset($data['sidebarNavigation']['startMigration']) && $data['sidebarNavigation']['startMigration'] !== 'active'): ?>
                        <div class="transferito-navigation__link transferito-text__small--semi-bold">Update</div>
                        <?php endif; ?>
                    </div>
                <?php endif; ?>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['startMigration'])): ?>
        <div class="transferito-navigation__item">
            <?php if ($data['sidebarNavigation']['startMigration'] === 'completed'): ?>
                <div class="transferito-navigation__item-connector"></div>
            <?php endif; ?>
            <div class="transferito-navigation__item-icon <?php echo ($data['sidebarNavigation']['startMigration'] === 'disabled') ? 'transferito-navigation__item-icon--disabled' : ''; ?>">
                <div class="transferito-icon <?php echo ($data['sidebarNavigation']['startMigration'] === 'completed') ? 'transferito-icon--completed' : 'transferito-icon--reload'; ?>"></div>
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-anchor transferito-text__p1--bold">
                    Start Migration
                </div>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['emptyItem1'])) : ?>
        <div class="transferito-navigation__item">
            <div class="transferito-navigation__item-icon transferito-navigation__item-icon--disabled">
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-empty"></div>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['emptyItem2'])) : ?>
        <div class="transferito-navigation__item">
            <div class="transferito-navigation__item-icon transferito-navigation__item-icon--disabled">
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-empty"></div>
            </div>
        </div>
    <?php endif; ?>

    <?php if (isset($data['sidebarNavigation']['emptyItem3'])) : ?>
        <div class="transferito-navigation__item">
            <div class="transferito-navigation__item-icon transferito-navigation__item-icon--disabled">
            </div>
            <div class="transferito-navigation__item-details">
                <div class="transferito-navigation__item-empty"></div>
            </div>
        </div>
    <?php endif; ?>
    
</div>
