- api_enabled = Setting.rest_api_enabled == '1'

- content_for :header_tags do
  = stylesheet_link_tag 'swagger-ui', plugin: Hourglass::PLUGIN_NAME, media: 'screen'
  = javascript_include_tag 'swagger-ui-bundle', plugin: Hourglass::PLUGIN_NAME
  javascript:
      $(function () {
          var initiated = false;
          window.swaggerUi = new SwaggerUIBundle({
              url: "#{hourglass_rswag_api_path}/v1/swagger.json",
              dom_id: "#swagger-ui-container",
              presets: [SwaggerUIBundle.presets.apis],
              supportedSubmitMethods: ['get', 'post', 'put', 'delete', 'patch'],
              onFailure: function () {
                  hourglass.Utils.showErrorMessage("#{t('hourglass.ui.api_docs.error_json_missing', task: 'redmine:plugins:hourglass:api_docs')}");
              },
              onComplete: function() {
                  window.swaggerUi.preauthorizeApiKey("api_key", "#{User.current.api_key}");
              },
              docExpansion: 'list'
          });
      });

= render layout: 'hourglass_ui/layouts/hourglass' do
  - html_title t('hourglass.ui.api_docs.title')

  p = t('hourglass.ui.api_docs.description')

  - if api_enabled
    .swagger-section
      #message-bar.swagger-ui-wrap
      #auth_container
      #swagger-ui-container.swagger-ui-wrap

      .swagger-note
        = t('hourglass.ui.api_docs.swagger_note')
        | :
        .swagger-link
          a href="http://swagger.io"
            img.logo__img alt="" height="30" width="30" src=Hourglass::Assets.path('swagger.png', type: 'image')
            span.logo__title Swagger
  - else
    = t('hourglass.ui.api_docs.error_api_disabled')
    ' :
    = link_to t('hourglass.ui.api_docs.api_settings'), settings_path(tab: 'api')
