{% comment %}
  Renders a share component with links to social media sites.

  Accepts:
  - copy_title: {String} The title of the copy link
  - url: {String} The url to share
  - list: {String} A list of social media sites to include
  - tooltip_placement: {String} The placement of the tooltip

  Usage:
  {% render 'share' %}
{% endcomment %}

{% liquid
  if list == null
    assign list = 'copy, facebook, twitter, pinterest'
  endif
  if tooltip_placement == null
    assign tooltip_placement = 'top-center'
  endif
  assign items = list | split: ','
%}

<div class='xo-share'>
  {% for item in items %}
    {% assign temp = item | strip %}
    {% case temp %}
      {% when 'copy' %}
        <xo-tooltip xo-title='{{ 'general.share.copy_to_clipboard' | t }}' xo-placement='{{ tooltip_placement }}'>
          <xo-copy
            xo-url='{{ url }}'
            class='xo-share__link'
          >
            {% assign message = 'general.share.copy_to_clipboard' | t | append: ': ' | append: copy_title %}
            {% render 'icon', name: 'clipboard', icon_size: '12' %}
            {% render 'toast', type: 'success', name: 'share-copy', message: message %}
            <div class='xo-visually-hidden'>Copy</div>
          </xo-copy>
        </xo-tooltip>
      {% when 'twitter' %}
        <xo-tooltip xo-title='{{ 'general.social.links.twitter' | t }}' xo-placement='{{ tooltip_placement }}'>
          <a
            href='https://twitter.com/share?url={{ url }}'
            target='_blank'
            class='xo-share__link'
            aria-label='{{ 'general.social.links.twitter' | t }}'
          >
            {% render 'icon', name: 'twitter2', icon_size: '15' %}
          </a>
        </xo-tooltip>
      {% when 'facebook' %}
        <xo-tooltip xo-title='{{ 'general.social.links.facebook' | t }}' xo-placement='{{ tooltip_placement }}'>
          <a
            href='https://www.facebook.com/sharer/sharer.php?u={{ url }}'
            target='_blank'
            class='xo-share__link'
            aria-label='{{ 'general.social.links.facebook' | t }}'
          >
            {% render 'icon', name: 'facebook2', icon_size: '17' %}
          </a>
        </xo-tooltip>
      {% when 'pinterest' %}
        <xo-tooltip xo-title='{{ 'general.social.links.pinterest' | t }}' xo-placement='{{ tooltip_placement }}'>
          <a
            href='https://pinterest.com/pin/create/button/?url={{ url }}'
            target='_blank'
            class='xo-share__link'
            aria-label='{{ 'general.social.links.pinterest' | t }}'
          >
            {% render 'icon', name: 'pinterest2', icon_size: '17' %}
          </a>
        </xo-tooltip>
      {% when 'tumblr' %}
        <xo-tooltip xo-title='{{ 'general.social.links.tumblr' | t }}' xo-placement='{{ tooltip_placement }}'>
          <a
            href='https://plus.google.com/share?url={{ url }}'
            target='_blank'
            class='xo-share__link'
            aria-label='{{ 'general.social.links.tumblr' | t }}'
          >
            {% render 'icon', name: 'tumblr' %}
          </a>
        </xo-tooltip>
      {% else %}
        <div class='xo-error'>List support: 'copy, facebook, twitter, pinterest, tumblr'</div>
    {% endcase %}
  {% endfor %}
</div>
