text: define(["exports", "../../../../@polymer/polymer/polymer-element.js", "../../../../@polymer/app-route/app-route.js", "../../../../@polymer/iron-ajax/iron-ajax.js", "../../../../@polymer/app-layout/app-toolbar/app-toolbar.js", "../../../../@polymer/marked-element/marked-element.js", "../../../simple-icon/simple-icon.js", "../../../simple-icon/lib/simple-icons.js", "../../../simple-icon/lib/simple-icon-button.js", "../../../hax-iconset/lib/simple-hax-iconset.js", "../../../../@polymer/paper-dialog/paper-dialog.js", "../../../../@polymer/polymer/lib/elements/dom-if.js", "../../../../@polymer/paper-badge/paper-badge.js", "../../../../@polymer/paper-toast/paper-toast.js", "../../../../@vaadin/vaadin-split-layout/vaadin-split-layout.js", "../../../lrnsys-layout/lib/lrnsys-dialog.js", "../../../lrnsys-button/lrnsys-button.js", "../../../lrnsys-comment/lib/lrnsys-comment-list.js", "../../../elmsln-loading/elmsln-loading.js", "./lrnapp-studio-submission-object.js", "./lrnapp-studio-submission-comments.js", "./lrnapp-studio-submission-comment.js"], function (_exports, _polymerElement, _appRoute, _ironAjax, _appToolbar, _markedElement, _simpleIcon, _simpleIcons, _simpleIconButton, _simpleHaxIconset, _paperDialog, _domIf, _paperBadge, _paperToast, _vaadinSplitLayout, _lrnsysDialog, _lrnsysButton, _lrnsysCommentList, _elmslnLoading, _lrnappStudioSubmissionObject, _lrnappStudioSubmissionComments, _lrnappStudioSubmissionComment) {
    "use strict";
  
    Object.defineProperty(_exports, "__esModule", {
      value: true
    });
    _exports.LrnappStudioSubmissionPage = void 0;
  
    function _templateObject_4be0ce5099b011eb851ed31c596cbbd8() {
      var data = babelHelpers.taggedTemplateLiteral(["\n      <style>\n        [hidden] {\n          display: none !important;\n        }\n        :host {\n          display: block;\n          position: relative;\n        }\n\n        p {\n          font-size: 14px;\n          line-height: 18px;\n        }\n\n        h1 {\n          margin: 0;\n          text-align: left;\n        }\n\n        iron-selector {\n          line-height: 1em;\n        }\n\n        iron-selector lrnsys-button {\n          display: inline-flex;\n        }\n\n        img.image {\n          margin: 0 0.5em;\n        }\n\n        lrnsys-dialog {\n          display: inline;\n        }\n\n        .contain {\n          width: 10em;\n          height: 10em;\n          background: #ddd;\n        }\n\n        .center {\n          margin: auto;\n          width: 100%;\n        }\n\n        .title {\n          color: #222;\n          font-size: 2rem;\n          font-weight: 600;\n          line-height: 2.5rem;\n          padding: 0.25rem 0;\n          white-space: nowrap;\n          overflow-x: hidden;\n          text-overflow: ellipsis;\n          margin-top: 1rem;\n          text-transform: uppercase;\n          text-align: left;\n        }\n\n        .author {\n          color: #555;\n          font-size: 1rem;\n          font-weight: 500;\n          font-style: normal;\n          line-height: 1rem;\n          padding: 0.25rem 0 0.5rem 0;\n          margin: 0;\n          text-transform: capitalize;\n        }\n\n        .comments {\n          text-align: right;\n          margin: 0;\n          font-size: 1.5em;\n        }\n\n        .submission-page-wrapper {\n          padding: 0;\n          --vaadin-split-layout-splitter: {\n            min-width: 0.4em;\n            background: var(--paper-amber-200);\n          }\n        }\n\n        .submission-page {\n          width: 70vw;\n        }\n\n        .submission-page-card {\n          width: 100%;\n          margin: 0;\n          padding: 0 0 2em 1em;\n        }\n\n        .submission-comments {\n          overflow-y: hidden;\n          padding: 0;\n          margin: 0;\n        }\n\n        elmsln-loading {\n          position: absolute;\n          display: none;\n          top: 0;\n          left: 0;\n          width: 100%;\n          height: 100%;\n          background: rgba(255, 255, 255, 0.8);\n          z-index: 10;\n          align-items: flex-end;\n          justify-content: center;\n        }\n\n        :host([saving]) elmsln-loading {\n          display: block;\n        }\n\n        elmsln-loading {\n          top: calc(50% - 5vmax);\n          left: calc(50% - 5vmax);\n          position: fixed;\n          transform-origin: center center;\n          width: 10vmax !important;\n          height: 10vmax !important;\n        }\n\n        iron-pages {\n          width: 100%;\n        }\n\n        paper-dialog {\n          width: 50%;\n          width: 50vmax;\n          padding: 1em;\n          z-index: 99999;\n        }\n\n        lrnapp-studio-submission-object {\n          width: 100%;\n        }\n\n        .assignment-body {\n          padding: 2em;\n        }\n\n        simple-icon {\n          margin: 0.2em;\n        }\n      </style>\n\n      <app-route\n        route=\"{{route}}\"\n        pattern=\"/edit\"\n        tail=\"{{tail}}\"\n        active=\"{{editPage}}\"\n      >\n      </app-route>\n\n      <iron-ajax\n        id=\"ajaxRequest\"\n        auto=\"\"\n        url=\"[[reqUrl]]\"\n        method=\"GET\"\n        params=\"[[reqParams]]\"\n        content-type=\"application/json\"\n        handle-as=\"json\"\n        on-response=\"_handleResponse\"\n      ></iron-ajax>\n      <!-- Update Submission Node -->\n      <iron-ajax\n        id=\"ajaxUpdateRequest\"\n        url=\"[[reqUrl]]\"\n        method=\"PUT\"\n        body=\"[[submission]]\"\n        params=\"[[reqParams]]\"\n        content-type=\"application/json\"\n        handle-as=\"json\"\n        on-response=\"_handleUpdateResponse\"\n      ></iron-ajax>\n      <!-- Delete Submission Node -->\n      <iron-ajax\n        id=\"ajaxDeleteRequest\"\n        url=\"[[reqUrl]]\"\n        method=\"DELETE\"\n        params=\"[[reqParams]]\"\n        content-type=\"application/json\"\n        handle-as=\"json\"\n        on-response=\"_handleDeleteResponse\"\n      ></iron-ajax>\n\n      <app-toolbar class=\"amber lighten-3\" hidden$=\"[[hideMenuBar]]\">\n        <template is=\"dom-if\" if=\"[[showComments]]\">\n          <lrnsys-button\n            on-click=\"_backToStudio\"\n            icon=\"arrow-back\"\n            label=\"See in studio\"\n            hover-class=\"amber darken-4 white-text\"\n          ></lrnsys-button>\n        </template>\n        <template is=\"dom-if\" if=\"[[!showComments]]\">\n          <lrnsys-button\n            on-click=\"_backToKanban\"\n            icon=\"arrow-back\"\n            label=\"Back to project management\"\n            hover-class=\"amber darken-4 white-text\"\n          ></lrnsys-button>\n        </template>\n        <div spacer=\"\" main-title=\"\">[[submission.attributes.title]]</div>\n        <div spacer=\"\">\n          <lrnsys-dialog\n            raised\n            header=\"[[submission.relationships.assignment.attributes.title]]\"\n          >\n            <span slot=\"button\"\n              ><simple-icon icon=\"icons:assignment\"></simple-icon>Assignment\n              Details</span\n            >\n            <div class=\"assignment-body\">\n              <marked-element\n                id=\"assignment-body\"\n                markdown=\"[[submission.relationships.assignment.attributes.body]]\"\n              ></marked-element>\n            </div>\n          </lrnsys-dialog>\n        </div>\n        <div>\n          <simple-icon\n            id=\"comment-count\"\n            icon=\"communication:forum\"\n          ></simple-icon>\n          [[submission.meta.comment_count]] Comments\n          <paper-badge\n            hidden$=\"[[displayNewBadge(submission.meta.comment_new)]]\"\n            for=\"comment-count\"\n            label$=\"[[submission.meta.comment_new]]\"\n          ></paper-badge>\n        </div>\n        <div hidden$=\"[[editPage]]\">\n          <lrnsys-button\n            on-click=\"_setEditRoute\"\n            icon=\"create\"\n            label=\"Edit\"\n            hover-class=\"amber darken-4 white-text\"\n            hidden$=\"[[!submission.meta.canUpdate]]\"\n          ></lrnsys-button>\n        </div>\n        <div hidden$=\"[[!editPage]]\">\n          <lrnsys-button\n            on-click=\"_resetRoute\"\n            icon=\"cancel\"\n            label=\"Cancel\"\n            hover-class=\"amber darken-4 white-text\"\n            hidden$=\"[[!submission.meta.canUpdate]]\"\n          ></lrnsys-button>\n        </div>\n      </app-toolbar>\n\n      <vaadin-split-layout class=\"submission-page-wrapper\">\n        <div\n          id=\"commentcolumn\"\n          class=\"submission-comments\"\n          style=\"min-width: 25%; max-width: 40%; width:30%;\"\n        >\n          <template is=\"dom-if\" if=\"[[showComments]]\">\n            <lrnsys-comment-list\n              comment-ops-base=\"{{commentOpsBase}}\"\n              csrf-token=\"[[csrfToken]]\"\n              source-path=\"{{commentsUrl}}\"\n              create-stub-url=\"{{createStubUrl}}\"\n            ></lrnsys-comment-list>\n          </template>\n        </div>\n        <div id=\"submissioncolumn\" style=\"width:70%;\">\n          <lrnapp-studio-submission-object\n            submission=\"{{submission}}\"\n            edit=\"[[editPage]]\"\n          ></lrnapp-studio-submission-object>\n        </div>\n        <simple-icon class=\"splitter-handle\" icon=\"more-vert\"></simple-icon>\n      </vaadin-split-layout>\n\n      <elmsln-loading></elmsln-loading>\n\n      <paper-dialog id=\"deletedialog\">\n        <h2>Delete submission?</h2>\n        <p>Are you sure you want to delete this submission?</p>\n        <div class=\"buttons\">\n          <button dialog-dismiss=\"\">Cancel</button>\n          <button dialog-confirm=\"\" on-click=\"_submissionDeleteConfirmed\">\n            Delete\n          </button>\n        </div>\n      </paper-dialog>\n      <paper-dialog id=\"publishdialog\">\n        <h2>Ready to publish?</h2>\n        <p>\n          By publishing, the author of this submission will be able to view your\n          feedback. Are you ready to publish?\n        </p>\n        <div class=\"buttons\">\n          <button dialog-dismiss=\"\">Cancel</button>\n          <button dialog-confirm=\"\" on-click=\"_submissionPublishConfirmed\">\n            Yes Publish\n          </button>\n        </div>\n      </paper-dialog>\n\n      <paper-toast id=\"toast\"></paper-toast>\n    "]);
  
      _templateObject_4be0ce5099b011eb851ed31c596cbbd8 = function _templateObject_4be0ce5099b011eb851ed31c596cbbd8() {
        return data;
      };
  
      return data;
    }
  
    function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = babelHelpers.getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = babelHelpers.getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return babelHelpers.possibleConstructorReturn(this, result); }; }
  
    function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
  
    var LrnappStudioSubmissionPage = /*#__PURE__*/function (_PolymerElement) {
      babelHelpers.inherits(LrnappStudioSubmissionPage, _PolymerElement);
  
      var _super = _createSuper(LrnappStudioSubmissionPage);
  
      function LrnappStudioSubmissionPage() {
        babelHelpers.classCallCheck(this, LrnappStudioSubmissionPage);
        return _super.apply(this, arguments);
      }
  
      babelHelpers.createClass(LrnappStudioSubmissionPage, [{
        key: "connectedCallback",
        value: function connectedCallback() {
          babelHelpers.get(babelHelpers.getPrototypeOf(LrnappStudioSubmissionPage.prototype), "connectedCallback", this).call(this);
          this.addEventListener("submissionDeleteClicked", this._submissionDeleteClicked.bind(this));
          this.addEventListener("submissionPublishClicked", this._submissionPublishClicked.bind(this));
          this.addEventListener("submissionSaveDraftClicked", this._submissionSaveDraftClicked.bind(this));
        }
      }, {
        key: "disconnectedCallback",
        value: function disconnectedCallback() {
          this.removeEventListener("submissionDeleteClicked", this._submissionDeleteClicked.bind(this));
          this.removeEventListener("submissionPublishClicked", this._submissionPublishClicked.bind(this));
          this.removeEventListener("submissionSaveDraftClicked", this._submissionSaveDraftClicked.bind(this));
          babelHelpers.get(babelHelpers.getPrototypeOf(LrnappStudioSubmissionPage.prototype), "disconnectedCallback", this).call(this);
        }
      }, {
        key: "_backToStudio",
  
        /**
         * Go back to the studio relative to the app's path.
         */
        value: function _backToStudio(e) {
          window.location.href = this.basePath + "lrnapp-open-studio";
        }
        /**
         * Go back to the studio relative to the app's path.
         */
  
      }, {
        key: "_backToKanban",
        value: function _backToKanban(e) {
          window.location.href = this.basePath + "lrnapp-studio-kanban";
        }
        /**
         * Trigger the page router to invoke edit state.
         */
  
      }, {
        key: "_setEditRoute",
        value: function _setEditRoute(e) {
          this.set("route.path", "edit");
          this.notifyPath("route.path");
        }
        /**
         * Trigger the page router to invoke edit state.
         */
  
      }, {
        key: "_resetRoute",
        value: function _resetRoute(e) {
          this.set("route.path", "");
          this.notifyPath("route.path");
        }
        /**
         * if we should show new badge based on new comment count.
         */
  
      }, {
        key: "displayNewBadge",
        value: function displayNewBadge(count) {
          if (count == 0) {
            return true;
          }
  
          return false;
        }
      }, {
        key: "_computeCommentsUrl",
        value: function _computeCommentsUrl(id, endPoint, csrfToken) {
          return endPoint + "/api/submissions/" + id + "/comments?token=" + csrfToken;
        }
      }, {
        key: "_computeCommentsOpsUrl",
        value: function _computeCommentsOpsUrl(id, endPoint, csrfToken) {
          return endPoint + "/api/submissions/" + id + "/comments";
        }
      }, {
        key: "_computeCommentsStubUrl",
        value: function _computeCommentsStubUrl(id, endPoint, csrfToken) {
          return endPoint + "/api/submissions/" + id + "/comments/create-stub?token=" + csrfToken;
        }
      }, {
        key: "_urlVarsChanged",
        value: function _urlVarsChanged(id, endPoint) {
          this.reqUrl = endPoint + "/api/submissions/" + id;
        }
      }, {
        key: "_paramsChanged",
        value: function _paramsChanged(csrfToken) {
          var params = this.reqParams || {};
          params.token = csrfToken;
          this.reqParams = params;
        }
      }, {
        key: "_handleResponse",
        value: function _handleResponse(data) {
          var _this = this;
  
          // empty response means no access or deleted item
          if (data.detail.response.data) {
            this.set("submission", {});
            setTimeout(function () {
              _this.set("submission", data.detail.response.data);
  
              window.dispatchEvent(new Event("resize"));
            }, 0);
          }
        }
      }, {
        key: "_isReply",
        value: function _isReply(data) {
          this.thread = submission.relationships.comments.data.attributes.thread;
        }
      }, {
        key: "_submissionSaveDraftClicked",
        value: function _submissionSaveDraftClicked(e) {
          this.saving = true;
          this.shadowRoot.querySelector("#ajaxUpdateRequest").generateRequest();
        }
      }, {
        key: "_submissionPublishClicked",
        value: function _submissionPublishClicked(e) {
          this.shadowRoot.querySelector("#publishdialog").open();
        }
      }, {
        key: "_submissionPublishConfirmed",
        value: function _submissionPublishConfirmed(e) {
          this.saving = true;
          this.shadowRoot.querySelector("#ajaxUpdateRequest").generateRequest();
        }
      }, {
        key: "_submissionDeleteClicked",
        value: function _submissionDeleteClicked(e) {
          this.shadowRoot.querySelector("#deletedialog").open();
        }
      }, {
        key: "_submissionDeleteConfirmed",
        value: function _submissionDeleteConfirmed(e) {
          this.saving = true;
          this.$.ajaxDeleteRequest.generateRequest();
        }
      }, {
        key: "_handleUpdateResponse",
        value: function _handleUpdateResponse(res) {
          var root = this;
          var status = res.detail.response.status;
          var submission = res.detail.response.data;
          root.saving = false;
  
          if (status === 200) {
            root.set("submission", {});
            root.set("submission", submission);
            root.set("route.path", ""); // display a submission published notification
  
            if (submission.attributes.state === "submission_ready") {
              this.$.toast.show("Published!");
            } // @todo replace this with the page just being there once we fix the lazy load dilema
  
  
            window.location.href = this.endPoint + "/submissions/" + submission.id;
          }
        }
      }, {
        key: "_handleDeleteResponse",
        value: function _handleDeleteResponse(res) {
          var root = this;
          var status = res.detail.response.status;
          root.saving = false;
  
          if (status === 200) {
            window.location.href = this.basePath + "lrnapp-studio-kanban?deletetoast";
          }
        }
      }, {
        key: "_computeShowComments",
        value: function _computeShowComments(submission) {
          try {
            var type = submission.meta.submissionType;
  
            if (type !== "critique" && submission.attributes.state == "submission_ready") {
              return true;
            }
          } catch (error) {}
  
          return false;
        }
        /**
         * Simple way to convert from object to array.
         */
  
      }, {
        key: "_toArray",
        value: function _toArray(obj) {
          if (babelHelpers.typeof(obj) === "object" && obj !== null) {
            return Object.keys(obj).map(function (key) {
              return obj[key];
            });
          }
  
          return [];
        }
      }], [{
        key: "template",
        get: function get() {
          return (0, _polymerElement.html)(_templateObject_4be0ce5099b011eb851ed31c596cbbd8());
        }
      }, {
        key: "tag",
        get: function get() {
          return "lrnapp-studio-submission-page";
        }
      }, {
        key: "properties",
        get: function get() {
          var _ref;
  
          return _ref = {
            id: {
              type: String
            },
            hideMenuBar: {
              type: Boolean,
              value: false
            },
            elmslnCourse: {
              type: String
            },
            elmslnSection: {
              type: String
            },
            basePath: {
              type: String
            },
            csrfToken: {
              type: String
            },
            endPoint: {
              type: String
            }
          }, babelHelpers.defineProperty(_ref, "endPoint", {
            type: String
          }), babelHelpers.defineProperty(_ref, "basePath", {
            type: String
          }), babelHelpers.defineProperty(_ref, "csrfToken", {
            type: String
          }), babelHelpers.defineProperty(_ref, "reqUrl", {
            type: String
          }), babelHelpers.defineProperty(_ref, "reqParams", {
            type: Object
          }), babelHelpers.defineProperty(_ref, "submission", {
            type: Object,
            notify: true,
            value: null
          }), babelHelpers.defineProperty(_ref, "commentsUrl", {
            type: String,
            computed: "_computeCommentsUrl(id, endPoint, csrfToken)"
          }), babelHelpers.defineProperty(_ref, "createStubUrl", {
            type: String,
            computed: "_computeCommentsStubUrl(id, endPoint, csrfToken)"
          }), babelHelpers.defineProperty(_ref, "commentOpsBase", {
            type: String,
            computed: "_computeCommentsOpsUrl(id, endPoint, csrfToken)"
          }), babelHelpers.defineProperty(_ref, "editPage", {
            type: Boolean,
            reflectToAttribute: true
          }), babelHelpers.defineProperty(_ref, "saving", {
            type: Boolean,
            value: false,
            notify: true,
            reflectToAttribute: true
          }), babelHelpers.defineProperty(_ref, "showComments", {
            type: Boolean,
            computed: "_computeShowComments(submission)"
          }), _ref;
        }
      }, {
        key: "observers",
        get: function get() {
          return ["_urlVarsChanged(id, endPoint)", "_paramsChanged(csrfToken)", "_bodyChanged(title)"];
        }
      }]);
      return LrnappStudioSubmissionPage;
    }(_polymerElement.PolymerElement);
  
    _exports.LrnappStudioSubmissionPage = LrnappStudioSubmissionPage;
    window.customElements.define(LrnappStudioSubmissionPage.tag, LrnappStudioSubmissionPage);
  });