<!DOCTYPE html>
<html lang="en">
{{> head}}

<body>
<div class="i_w">
  <div class="error-page">
    <div>
      <div class="error-page-message">
        <crowdin-h3>{{ message }}</crowdin-h3>
        {{#if owners}}
            <crowdin-p>This integration allows only one connection per project to ensure consistent configuration and prevent file import or synchronization issues.</crowdin-p>
            {{#if owners.[1]}}
                <crowdin-p class="mt-2">Managed by:</crowdin-p>
                <ul>
                    {{#each owners}}
                        <li><crowdin-a href="#" onclick="contactUser({{this.id}})">{{this.name}}</crowdin-a></li>
                    {{/each}}
                </ul>
                <crowdin-p class="mt-2">To request access, please contact one of the project members listed above.</crowdin-p>
            {{else}}
                <crowdin-p class="mt-2">Managed by: <crowdin-a href="#" onclick="contactUser({{owners.[0].id}})">{{owners.[0].name}}</crowdin-a></crowdin-p>
                <crowdin-p class="mt-2">To request access, please contact the project member listed above.</crowdin-p>
            {{/if}}
        {{/if}}
      </div>
      {{#unless hideActions}}
        <div class="error-page-action">
          <crowdin-button outlined onclick="integrationLogout()">Log out</crowdin-button>
          <span> or <crowdin-a href="https://crowdin.com/contacts" target="_blank">contact us</crowdin-a> for help</span>
        </div>
      {{/unless}}
    </div>
  </div>
</div>
</body>

</html>
<script>
  function integrationLogout() {
    checkOrigin()
      .then(queryParams => fetch(`api/logout${queryParams}`, { method: 'POST' }))
      .then(checkResponse)
      .then(reloadLocation)
      .then(localStorage.removeItem('revised_{{name}}'))
      .catch(e => catchRejection(e, 'Looks like you are not logged in'));
  }

  function contactUser(userId) {
    AP.getContext(function(context) {
      AP.redirect(`${context.organization_id ? '/u' : ''}/messages/create/${userId}`);
    });
  }
</script>
