{#
Flask-Discussion
https://github.com/rmed/flask-discussion

MIT License

Copyright (c) 2020 Rafael Medina García <rafamedgar@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
#}

{# Isso macros #}

{# Embed Isso script.

This can either be used to globally include the script (e.g. in the head of the page) or called
as part of  the `render_comments()` macro.
#}
{% macro embed_client() -%}
{% if config.DISCUSSION_ISSO_URL %}
    <script data-isso="//{{ config.DISCUSSION_ISSO_URL }}"
            {% if config.DISCUSSION_ISSO_CSS is defined %}data-isso-css="{{ config.DISCUSSION_ISSO_CSS | string | lower }}"{% endif %}
            {% if config.DISCUSSION_ISSO_LANG is defined %}data-isso-lang="{{ config.DISCUSSION_ISSO_LANG | lower }}"{% endif %}
            {% if config.DISCUSSION_ISSO_REPLY_TO_SELF is defined %}data-isso-reply-to-self="{{ config.DISCUSSION_ISSO_REPLY_TO_SELF | string | lower }}"{% endif %}
            {% if config.DISCUSSION_ISSO_REQUIRE_AUTHOR is defined %}data-isso-require-author="{{ config.DISCUSSION_ISSO_REQUIRE_AUTHOR | string | lower }}"{% endif %}
            {% if config.DISCUSSION_ISSO_REQUIRE_EMAIL is defined %}data-isso-require-email="{{ config.DISCUSSION_ISSO_REQUIRE_EMAIL | string | lower }}"{% endif %}
            {% if config.DISCUSSION_ISSO_REPLY_NOTIFICATIONS is defined %}data-isso-reply-notifications="{{ config.DISCUSSION_ISSO_REPLY_NOTIFICATIONS | string | lower }}"{% endif %}
            {% if config.DISCUSSION_ISSO_MAX_COMMENTS_TOP %}data-isso-max-comments-top="{{ config.DISCUSSION_ISSO_MAX_COMMENTS_TOP }}"{% endif %}
            {% if config.DISCUSSION_ISSO_MAX_COMMENTS_NESTED %}data-isso-max-comments-nested="{{ config.DISCUSSION_ISSO_MAX_COMMENTS_NESTED }}"{% endif %}
            {% if config.DISCUSSION_ISSO_REVEAL_ON_CLICK %}data-isso-reveal-on-click="{{ config.DISCUSSION_ISSO_REVEAL_ON_CLICK }}"{% endif %}
            {% if config.DISCUSSION_ISSO_AVATAR is defined %}data-isso-avatar="{{ config.DISCUSSION_ISSO_AVATAR | string | lower }}"{% endif %}
            {% if config.DISCUSSION_ISSO_AVATAR_BG %}data-isso-avatar-bg="{{ config.DISCUSSION_ISSO_AVATAR_BG }}"{% endif %}
            {% if config.DISCUSSION_ISSO_AVATAR_FG %}data-isso-avatar-fg="{{ config.DISCUSSION_ISSO_AVATAR_FG }}"{% endif %}
            {% if config.DISCUSSION_ISSO_VOTE is defined %}data-isso-vote="{{ config.DISCUSSION_ISSO_VOTE | string | lower }}"{% endif %}
            {% if config.DISCUSSION_ISSO_VOTE_LEVELS %}data-isso-vote-levels="{{ config.DISCUSSION_ISSO_VOTE_LEVELS }}"{% endif %}
            {% if config.DISCUSSION_ISSO_FEED is defined %}data-isso-feed="{{ config.DISCUSSION_ISSO_FEED | string | lower }}"{% endif %}
            src="//{{ config.DISCUSSION_ISSO_URL }}/js/embed.min.js"></script>
{% else %}
    <p>Missing <code>DISCUSSION_ISSO_URL</code> configuration value.</p>
{% endif %}
{%- endmacro %}


{# Render Isso comments #}
{% macro render_comments(identifier="", title="", include_script=true) -%}
{% if include_script %}
    {{ embed_client() }}
{% endif %}

<section id="isso-thread" {% if title %}data-title="{{ title }}"{% endif %} {% if identifier %}data-isso-id="{{ identifier }}"{% endif %}></section>
{%- endmacro %}


{# Render Isso comment count.

This **cannot be included at the same time as the full Isso client**. Make sure to include `#isso_thread` in the
`href` attribute of the link for which to show the comment count.
#}
{% macro render_comment_count() -%}
{% if config.DISCUSSION_ISSO_URL %}
    <script data-isso="//{{ config.DISCUSSION_ISSO_URL }}" src="//{{ config.DISCUSSION_ISSO_URL }}/js/count.min.js"></script>
{% else %}
    <p>Missing <code>DISCUSSION_ISSO_URL</code> configuration value.</p>
{% endif %}
{%- endmacro %}
