<% if (code = EasySetting.value(:inline_manual_code)) && !User.current.inline_manual_is_complete %>
  <script type="text/javascript">
    window.inlineManualTracking = {
      uid: "<%= User.current.id %>_<%= request.host %>", // Only this field is mandatory
      email: "<%= User.current.mail %>",
      username: "<%= User.current.login %>",
      name: "<%= User.current.name %>",
      created: <%= User.current.created_on.to_i %>,
      updated: <%= User.current.updated_on.to_i %>
    };
    window.inlineManualOptions = {language: '<%= User.current.language.presence || 'en' %>'};
    !function () {
      var e = document.createElement("script"), t = document.getElementsByTagName("script")[0];
      e.async = 1, e.src = "https://inlinemanual.com/embed/player.<%= code %>.js", e.charset = "UTF-8", t.parentNode.insertBefore(e, t)
    }();
  </script>
  <%= content_for :body_bottom do %>
  <script type="text/javascript">
    $(window).load(function() {
      var topicIds = <%=raw begin; Rails.cache.fetch(:inline_manual_topics, expires_in: 15.minutes) {inline_manual_topics}.to_json; rescue; [];end %>;
      (window.inline_manual_player || window.InlineManualPlayer).setCallbacks({
        onTopicEnd: function (player, _topic_id) {
          if (Object.keys(player.metadata.topics).length === topicIds.length) {
            $.ajax({
              type: "put",
              url: "<%= user_path(User.current, format: 'json', key: User.current.api_key) %>",
              data: {user: {inline_manual_is_complete: true}}
            })
          }
        }
      });
    })
  </script>
<% end %>
<% end %>
