{% comment %}
    IMPORTANT: All boolean variables MUST be initialized to false before use.
    Uninitialized variables compared with (== false) cause blank emails in Auth0.
{% endcomment %}
{% assign linkToPodcastApp = false %}
{% assign linkToSettingsApp = false %}
{% assign linkToInsightsApp = false %}
{% assign linkToWorkstationApp = false %}
{% assign linkToMoneyhubApp = false %}
{% assign linkToCollaboratorsApp = false %}
{% assign linkToAudienceApp = false %}
{% assign linkToDocumentsApp = false %}

{% assign smeUser = false %}
{% assign awalUser = false %}
{% assign knrUser = false %}
{% assign orchardUser = false %}
{% assign invitationLink = url or invitation_url %}

{% assign orgName = organization.name %}
{% assign orgDisplayName = organization.display_name %}

{% comment %} sets which app invited via clientId {% endcomment %}
{% if application.clientID == '##PODCAST_CLIENT_ID##' -%}
    {%- assign linkToPodcastApp = true -%}
{% elsif application.clientID == '##SETTINGS_CLIENT_ID##' -%}
    {%- assign linkToSettingsApp = true -%}
{% elsif application.clientID == '##INSIGHTS_CLIENT_ID##' -%}
    {%- assign linkToInsightsApp = true -%}
{% elsif application.clientID == '##WORKSTATION_CLIENT_ID##' -%}
    {%- assign linkToWorkstationApp = true -%}
{% elsif application.clientID == '##MONEYHUB_CLIENT_ID##' -%}
    {%- assign linkToMoneyhubApp = true -%}
{% elsif application.clientID == '##COLLABORATORS_CLIENT_ID##' -%}
    {%- assign linkToCollaboratorsApp = true -%}
{% elsif application.clientID == '##AUDIENCE_CLIENT_ID##' -%}
    {%- assign linkToAudienceApp = true -%}
{% elsif application.clientID == '##DOCUMENTS_CLIENT_ID##' -%}
    {%- assign linkToDocumentsApp = true -%}
{%- endif %}

{% comment %} set brand assignation: TODO: simplify to only orgName {% endcomment %}
{% if orgName == 'sme' -%}
    {%- assign smeUser = true -%}
{%- endif %}
{% if orgName == 'awal' or user.user_metadata.organization == 'awal' -%}
    {%- assign awalUser = true -%}
{%- endif %}
{% if orgName == 'orchard' or user.user_metadata.organization == 'orchard' -%}
    {%- assign orchardUser = true -%}
{%- endif %}
{% if orgName == 'knr' or user.user_metadata.organization == 'knr' -%}
    {%- assign knrUser = true -%}
{%- endif %}

{% comment %}INTERNATIONALIZATION_PLACEHOLDER{% endcomment %}

{% if user.user_metadata.should_send_collaborator_access_email %}
    {% assign invitingAppName = 'collaborators-login' %}
    {% assign vendorName = user.user_metadata.vendor_name %}
{% endif %}
{% if user.user_metadata.use_new_unified_template %}
    {% assign inviterTenantName = null %}
    {% assign tenantName = null %}
    {% if user.user_metadata.invitation_data %}
        {% assign inviterTenantName = user.user_metadata.invitation_data.inviter_tenant_name %}
        {% assign tenantName = user.user_metadata.invitation_data.tenant_name %}
    {% endif %}
{% endif %}

{% comment %} set invitationLink based on app and user type {% endcomment %}
{% comment %} start invitationLink replacements {% endcomment %}
{% if linkToAudienceApp %}
    {% if awalUser %}
        {% assign invitationLink = url
            | replace: '##WORKSTATION_INVITE_URL##', '##AUDIENCE_AWAL_URL##'
        %}
    {% elsif orchardUser %}
        {% assign invitationLink = url
            | replace: '##WORKSTATION_INVITE_URL##', '##AUDIENCE_URL##'
        %}
    {% elsif smeUser %}
        {% assign invitationLink = url
            | replace: '##WORKSTATION_INVITE_URL##', '##AUDIENCE_SME_URL##'
        %}
    {% endif %}
{% endif %}

{% if linkToInsightsApp %}
    {% if awalUser %}
        {% assign invitationLink = url
            | replace: '##WORKSTATION_INVITE_URL##', '##INSIGHTS_AWAL_URL##'
        %}
    {% elsif orchardUser %}
        {% assign invitationLink = url
            | replace: '##WORKSTATION_INVITE_URL##', '##INSIGHTS_URL##'
        %}
    {% elsif smeUser %}
        {% assign invitationLink = url
            | replace: '##WORKSTATION_INVITE_URL##', '##INSIGHTS_SME_URL##'
        %}
    {% endif %}
{% endif %}

{% if linkToWorkstationApp and awalUser %}
    {% assign invitationLink = url
        | replace: '##WORKSTATION_URL##', '##WORKSTATION_AWAL_URL##'
    %}
{% endif %}

{% if linkToMoneyhubApp and awalUser %}
    {% assign invitationLink = url
        | replace: '##WORKSTATION_URL##', '##MONEYHUB_AWAL_URL##'
    %}
{% endif %}

{% if linkToDocumentsApp %}
    {% if awalUser %}
        {% assign invitationLink = url
            | replace: '##WORKSTATION_INVITE_URL##', '##DOCUMENTS_AWAL_URL##'
        %}
    {% elsif orchardUser %}
        {% assign invitationLink = url
            | replace: '##WORKSTATION_INVITE_URL##', '##DOCUMENTS_URL##'
        %}
    {% endif %}
{% endif %}

{% if linkToCollaboratorsApp and awalUser %}
    {% assign invitationLink = url
        | replace: '##WORKSTATION_URL##', '##COLLABORATORS_AWAL_URL##'
    %}
{% endif %}

{% if linkToSettingsApp %}
    {% if awalUser %}
        {% assign invitationLink = url
            | replace: '##SETTINGS_URL##', '##SETTINGS_AWAL_URL##'
        %}
    {% elsif knrUser %}
        {% assign invitationLink = url
            | replace: '##SETTINGS_URL##', '##SETTINGS_KNR_URL##'
        %}
    {% elsif smeUser %}
        {% assign invitationLink = url
            | replace: '##SETTINGS_URL##', '##SETTINGS_SME_URL##'
        %}
    {% endif %}
{% endif %}

{% if linkToMoneyhubApp and knrUser %}
    {% assign invitationLink = url
        | replace: '##WORKSTATION_URL##', '##MONEYHUB_KNR_URL##'
    %}
{% endif %}

{% if linkToPodcastApp and smeUser %}
    {% assign invitationLink = url
        | replace: '##PODCAST_ORCHARD_URL##', '##PODCAST_SONY_URL##'
    %}
{% endif %}
{% comment %} end invitationLink replacements {% endcomment %}

{% assign cdnWebIcons = 'https://cdn.theorchard.io/web-icons/' %}
{% assign cdnAssets = 'https://cdn.theorchard.io/assets/' %}

{% assign social_platforms = 'facebook,youtube,twitter,instagram,linkedin,corporate'
    | split: ','
%}
