<?php
/**
 * BuddyPress Check-ins general setting tab file.
 *
 * @package Bp_Checkins
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

global $bpchk_globals;
$bpchk_saved_range = $bpchk_globals->google_places_range;

$bpchk_verify_btn_style = 'display: none;';
if ( ! empty( $bpchk_globals->apikey ) ) {
	$bpchk_verify_btn_style = '';
}

?>
<div class="wbcom-wrapper-admin">
	<div class="wbcom-admin-title-section">
		<h3><?php esc_html_e( 'General Settings', 'bp-check-in' ); ?></h3>
	</div>
	<div class="wbcom-admin-option-wrap wbcom-admin-option-wrap-view">
		<div class="form-table bpchk-admin-page-table">
				<!-- Checkin Tab Visibility  -->
				<div class="wbcom-settings-section-wrap">
					<div class="wbcom-settings-section-options-heading">
						<label for="tab-visibilty">
							<?php esc_html_e( 'Enable Check-ins Tab', 'bp-check-in' ); ?>
						</label>
						<p class="description"><?php esc_html_e( 'Show the Check-ins tab in the activity stream.', 'bp-check-in' ); ?>
					</div>
					<div class="wbcom-settings-section-options">
						<input class="regular-text" type="checkbox" value="1" name="bpchk-tab-visibilty" id="bpchk-tab-visibilty" <?php isset( $bpchk_globals->tab_visibility ) ? checked( $bpchk_globals->tab_visibility, 1 ) : ''; ?>>
					</div>
				</div>
				<!-- Checkin Tab Visibility  -->
				<!-- Rename Checkin Tab  -->
				<div class="wbcom-settings-section-wrap">
					<div class="wbcom-settings-section-options-heading">
						<label for="tab-name">
							<?php esc_html_e( 'Rename Check-ins Tab', 'bp-check-in' ); ?>
						</label>
						<p class="description"><?php esc_html_e( 'Change the name of the Check-ins tab.', 'bp-check-in' ); ?>
					</div>
					<div class="wbcom-settings-section-options">
						<input class="regular-text" type="text" value="<?php echo isset( $bpchk_globals->tab_name ) ? esc_html( $bpchk_globals->tab_name ) : ''; ?>" name="bpchk-tab-name" id="bpchk-tab-name" placeholder="<?php esc_html_e( 'Check-ins', 'bp-check-in' ); ?>">
					</div>
				</div>
				<!-- Rename Checkin Tab  -->
				<!-- Enable Location xProfile Field  -->
				<div class="wbcom-settings-section-wrap">
					<div class="wbcom-settings-section-options-heading">
						<label for="tab-name">
							<?php esc_html_e( 'Manage Location Profile Field Visibility', 'bp-check-in' ); ?>
						</label>
						<p class="description"><?php esc_html_e( 'Enable this option to hide the Location field on the user\'s profile.', 'bp-check-in' ); ?>
					</div>
					<div class="wbcom-settings-section-options">
						<input class="regular-text" type="checkbox" value="1" name="bpchk-enable-xprofile-filed" id="bpchk-enable-xprofile-filed" <?php isset( $bpchk_globals->enable_location_field ) ? checked( $bpchk_globals->enable_location_field, 1 ) : ''; ?> >
					</div>
				</div>
				<!-- Enable Location xProfile Field  -->
				<!-- API Key -->
				<div class="wbcom-settings-section-wrap">
					<div class="wbcom-settings-section-options-heading">
						<label for="api-key">
							<?php esc_html_e( 'API Key', 'bp-check-in' ); ?>
						</label>
						<p class="description"><?php esc_html_e( "Due to changes in Google Maps API it's required to use an API key for the BuddyPress Check-ins plugin to work properly.", 'bp-check-in' ); ?>
					</div>
					<div class="wbcom-settings-section-options">
						<input class="regular-text" type="text" value="<?php echo esc_attr( $bpchk_globals->apikey ); ?>" name="bpchk-api-key" id="bpchk-api-key" placeholder="<?php esc_html_e( 'API Key', 'bp-check-in' ); ?>" required>
						<button type="button" class="button button-secondary" style="<?php echo esc_attr( $bpchk_verify_btn_style ); ?>" id="bpchk-verify-apikey"><?php esc_html_e( 'Verify', 'bp-check-in' ); ?></button>
						<div class='bpchk-notice-wrapper'></div>
						<?php $bpchk_gm_api_url = 'https://console.developers.google.com/henhouse/?pb=["hh-1","maps_backend",null,[],"https://developers.google.com",null,["static_maps_backend","street_view_image_backend","maps_embed_backend","places_backend","geocoding_backend","directions_backend","distance_matrix_backend","geolocation","elevation_backend","timezone_backend","maps_backend"],null]'; ?>
						</p>
						<a id="gd-api-key" onclick='window.open("<?php echo esc_attr( wp_slash( $bpchk_gm_api_url ) ); ?>", "newwindow", "width=600, height=400"); return false;' href='<?php echo esc_url( $bpchk_gm_api_url ); ?>' class="button-primary " name="<?php esc_attr_e( 'Generate API Key - ( MUST be logged in to your Google account )', 'bp-check-in' ); ?>" ><?php esc_html_e( 'Generate API Key', 'bp-check-in' ); ?></a>&nbsp;
						<a href="javascript:void(0);" class="gd-api-link" onClick="window.open('https://wbcomdesigns.com/create-a-google-map-api-key/','pagename','resizable,height=600,width=700'); return false;">
							<?php esc_html_e( '( How to Get Google API Key? )', 'bp-check-in' ); ?>
						</a>
					</div>
				</div>
				<!-- API Key -->
		</div>
<p class="submit">
	<input type="hidden" name="bpci_nonce" value="<?php echo esc_attr( wp_create_nonce( 'bpci_option_nonce' ) ); ?>">
	<?php submit_button( 'Save Changes', 'primary', 'bpchk-submit-general-settings' ); ?>
</p>
</div>
</div>
