<?php
echo '<div id="search_console" class="content-box">';
echo '<div class="ju-settings-option p-lrb-20 wpms_width_100">';
echo '<div class="wpms_row_full">';
// Check if there is an access token.
if (null === $this->service->getClient()->getAccessToken()) { ?>
    <h2 style="font-weight: 400;"><?php esc_html_e('Google account authentication', 'wpmsPro') ?></h2>
    <table class="form-table">
        <tbody>
        <tr>
            <th scope="row"><label
                        for="googleClientId"><?php esc_html_e('Google Client ID', 'wpmsPro') ?></label>
            </th>
            <td>
                <label>
                    <input name="gscapi[googleClientId]" type="text" class="regular-text"
                           value="<?php echo esc_attr($googleClientId) ?>">
                </label>
            </td>
        </tr>
        <tr>
            <th scope="row"><label
                        for="googleClientSecret">
                    <?php esc_html_e('Google Client Secret', 'wpmsPro') ?></label>
            </th>
            <td>
                <label>
                    <input name="gscapi[googleClientSecret]" type="text" class="regular-text"
                           value="<?php echo esc_attr($googleClientSecret) ?>">
                </label>
            </td>
        </tr>
        <tr>
            <th scope="row"><label
                        for="googleJsOrigins">
                    <?php esc_html_e('JavaScript origins', 'wpmsPro') ?></label>
            </th>
            <td>
                <label>
                    <input name="gscapi[googleJsOrigins]" readonly type="text" class="regular-text"
                           value="<?php echo esc_attr(site_url()); ?>">
                </label>
            </td>
        </tr>
        <tr>
            <th scope="row"><label
                        for="googleRedirectUris">
                    <?php esc_html_e('Redirect URIs', 'wpmsPro') ?></label>
            </th>
            <td>
                <label>
                    <input name="gscapi[googleRedirectUris]" readonly size="140" type="text" class="regular-text"
                           value="<?php echo esc_attr(admin_url('admin.php?page=metaseo_settings&task=wpms_gsc&tab=settings')) ?>">
                </label>
            </td>
        </tr>
        <tr>
            <th scope="row"><label for="googleClientSecret"></label></th>
            <td>
                <input name="gscapi[save]" type="submit" class="wpmsbtn ju-button orange-button"
                       value="<?php esc_attr_e('Save and Connect', 'wpmsPro') ?>">
            </td>
        </tr>
        </tbody>
    </table>
    <?php
} else {
    echo '<h3>', esc_html__('Current profile', 'wpmsPro'), '</h3>';
    $profile  = WpmsGsc::getProfile();
    $profiles = $this->service->getSites();
    echo "<input type='hidden' name='wpms-gsc-pf[gsc_pf_nonce]' value='" . esc_attr(wp_create_nonce('gsc_pf_nonce')) . "' />";
    echo '<select name="wpms-gsc-pf[profile]" class="wpms-large-input">';
    echo '<option value="0">' . esc_html__('Select a profile', 'wpmsPro') . '</option>';
    foreach ($profiles as $k => $v) {
        $value = trim($k, '/');
        if ($value === $profile) {
            echo '<option selected value="' . esc_attr($value) . '">' . esc_html($v) . '</option>';
        } else {
            echo '<option value="' . esc_attr($value) . '">' . esc_html($v) . '</option>';
        }
    }
    echo '</select>';
    echo '<p class="submit"><button type="submit" name="wpms-gsc-pf[submit]" id="submit" value="1"
 class="ju-button orange-button">' . esc_html__('Save Changes', 'wpmsPro') . '</button></p>';
    echo '<button type="submit" name="wpms-gsc-pf[reauthenticate]" id="reauthenticate" value="1" class="ju-button">' .
        esc_html__('Reauthenticate with Google ', 'wpmsPro') . '</button>';
}

echo '</div></div></div>';
?>