<?php
// phpcs:disable WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedVariableFound
/**
 * Social credit partial.
 *
 * @package Ugcify
 *
 * Expected vars:
 * @var string $platform
 * @var string $handle
 * @var string $source_url
 */

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

$platform   = isset( $platform ) ? sanitize_key( (string) $platform ) : '';
$handle     = isset( $handle ) ? sanitize_text_field( (string) $handle ) : '';
$source_url = isset( $source_url ) ? esc_url( (string) $source_url ) : '';

if ( '' === $platform ) {
	return;
}

$platform_label = ucfirst( $platform );
?>
<div class="ugcify-social-credit">
	<span class="ugcify-social-credit__text">
		<?php if ( '' !== $handle ) : ?>
			<?php
			echo esc_html(
				sprintf(
					/* translators: 1: username, 2: social platform */
					__( 'Post by @%1$s on %2$s', 'ugcify' ),
					$handle,
					$platform_label
				)
			);
			?>
		<?php else : ?>
			<?php
			echo esc_html(
				sprintf(
					/* translators: %s: social platform */
					__( 'Post from %s', 'ugcify' ),
					$platform_label
				)
			);
			?>
		<?php endif; ?>
	</span>
	<?php if ( '' !== $source_url ) : ?>
		<a href="<?php echo esc_url( $source_url ); ?>" class="ugcify-social-credit__link" target="_blank" rel="nofollow noopener">
			<?php esc_html_e( 'View source', 'ugcify' ); ?>
		</a>
	<?php endif; ?>
</div>
