<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit; // Prevent direct access to the script.
}

$profile_id    = $args['profile_id'] ?? gigneo_active_profile_id();
$online_status = gigneo_online_status();
$offline_until = gigneo_post_meta( $profile_id, '_gigneo_pm_offline_until' );

if ( $online_status ) {
	$placeholder = esc_html__( 'Select duration', 'gigneo' );
} elseif ( 'forever' === $offline_until ) {
		$placeholder = esc_html__( 'Offline Forever', 'gigneo' );
} elseif ( is_numeric( $offline_until ) ) {
	$date_format    = get_option( 'date_format' );
	$time_format    = get_option( 'time_format' );
	$datetime_utc   = wp_date( 'Y-m-d H:i:s', intval( $offline_until ), new DateTimeZone( 'UTC' ) );
	$formatted_time = gigneo_datetime( $datetime_utc, "{$date_format} {$time_format}", $profile_id );
	// translators: %s: formatted date and time
	$placeholder = sprintf( esc_html__( 'Offline until %s', 'gigneo' ), $formatted_time );
} else {
	$placeholder = esc_html__( 'You\'re Offline', 'gigneo' );
}
?>
<div id="gn-account-online-status" class="gn-info-inline">
	<div class="gn-info">
		<h4 class="gn-title"><?php echo esc_html__( 'Go offline', 'gigneo' ); ?></h4>
		<p class="gn-description"><?php echo esc_html__( 'Manage or update your online status.', 'gigneo' ); ?></p>
	</div>
	<div class="gn-actions">
		<div class="gn-select2">
			<label class="gn-select">
				<select id="gn-offline-for" name="offline_for" data-minimum-results-for-search="Infinity" placeholder="<?php echo esc_attr( $placeholder ); ?>">
					<option value=""><?php echo esc_html__( 'None', 'gigneo' ); ?></option>
					<?php if ( $online_status ) { ?>
						<option value="hour"><?php echo esc_html__( '1 Hour', 'gigneo' ); ?></option>
						<option value="week"><?php echo esc_html__( '1 Week', 'gigneo' ); ?></option>
						<option value="month"><?php echo esc_html__( '1 Month', 'gigneo' ); ?></option>
						<option value="forever"><?php echo esc_html__( 'Forever', 'gigneo' ); ?></option>
					<?php } else { ?>
						<option value="online"><?php echo esc_html__( 'Go online', 'gigneo' ); ?></option>
					<?php } ?>
				</select>
			</label>
		</div>
	</div>
</div>