define(['handlebars', 'lib/handlebars/helpers'], function (Handlebars, Helpers0) { 'use strict';

    Handlebars = Handlebars && Object.prototype.hasOwnProperty.call(Handlebars, 'default') ? Handlebars['default'] : Handlebars;
    Helpers0 = Helpers0 && Object.prototype.hasOwnProperty.call(Helpers0, 'default') ? Helpers0['default'] : Helpers0;

    if (!Helpers0.__initialized) {
      Helpers0(Handlebars);
      Helpers0.__initialized = true;
    }
    var Template = Handlebars.template(function (Handlebars,depth0,helpers,partials,data) {
      this.compilerInfo = [4,'>= 1.0.0'];
    helpers = this.merge(helpers, Handlebars.helpers);  


      return "<iframe ></iframe>";
      });
    function viewerTpl(data, options, asString) {
      var html = Template(data, options);
      return (asString || true) ? html : $(html);
    }

    /**
     * This program is free software; you can redistribute it and/or
     * modify it under the terms of the GNU General Public License
     * as published by the Free Software Foundation; under version 2
     * of the License (non-upgradable).
     *
     * This program is distributed in the hope that it will be useful,
     * but WITHOUT ANY WARRANTY; without even the implied warranty of
     * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     * GNU General Public License for more details.
     *
     * You should have received a copy of the GNU General Public License
     * along with this program; if not, write to the Free Software
     * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
     *
     * Copyright (c) 2016 (original work) Open Assessment Technologies SA ;
     */

    /**
     * Wraps the component that use the native PDF viewer provided by the browser.
     * @param {jQuery} $container
     * @returns {Object}
     */
    function fallbackViewerFactory($container) {
      var template = viewerTpl();
      var $viewer = null;
      return {
        /**
         * Loads and displays the document
         * @param {String} url
         * @returns {Promise}
         */
        load: function load(url) {
          return new Promise(function (resolve) {
            $viewer = $container.html(template).find('iframe');
            $viewer.one('load.provider', resolve).attr('src', url);
          });
        },
        /**
         * Destroys the component
         */
        unload: function unload() {
          $container.empty();
          $viewer = null;
        },
        /**
         * Sets the size of the component
         * @param {Number} width
         * @param {Number} height
         */
        setSize: function setSize(width, height) {
          if ($viewer) {
            // the browser will adjust the PDF
            $viewer.width(width).height(height);
          }
        }
      };
    }

    return fallbackViewerFactory;

});
