<?php
/**
 * Social Link - Template
 * 
 * @package OrokuBlocks
 * @author OrokuBlocks (https://orokublocks.com/)
 * 
 * @since 1.0.0
 * 
 * @param array $args {
 *   @type string   $name             Icon name.
 *   @type string   $share_text       Share text.
 *   @type string   $share_url        Share URL.
 * }
 */

// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) {
  exit;
}

global $wp;

$current_page_url = home_url( $wp->request );

$defaults = [
  'share_text'  => '',
  'share_url'   => $current_page_url
];

$options = array_merge( $defaults, $args );

if ( $options['share_url'] === '' ) {
  $options['share_url'] = $current_page_url;
}

$share_url = '#';

if ( $options['name'] === 'x' ) {
  $share_url = 'https://twitter.com/intent/tweet?url=' . $options['share_url'];
  if ($options['share_text'] !== '') {
    $share_url .= '&text=' . $options['share_text'];
  }
} else if ( $options['name'] === 'facebook' ) {
  $share_url = 'https://www.facebook.com/sharer.php?u=' . $options['share_url'];
}

?>
<a class="orokublocks-social-link" href="<?php echo esc_attr( $share_url ); ?>" target="_blank">
<?php

  /**
   * Icon
   */
  orokublocks()->requireTemplate(
    'includes/template/svg',
    [
      'additional_wrapper_classes'  => 'orokublocks-social-link__icon',
      'icon'                        => $options['name']
    ]
  );

?>
</a>

