text: define(["exports", "../../../@polymer/polymer/polymer-element.js", "../../../@polymer/polymer/lib/utils/render-status.js", "../../../@polymer/polymer/lib/legacy/polymer.dom.js", "../../../@polymer/polymer/lib/utils/async.js", "../../../@polymer/iron-ajax/iron-ajax.js", "../../../@polymer/paper-spinner/paper-spinner.js", "../../hax-body-behaviors/lib/HAXWiring.js", "../../hax-body/lib/haxutils.js"], function (_exports, _polymerElement, _renderStatus, _polymerDom, _async, _ironAjax, _paperSpinner, _HAXWiring, _haxutils) {
    "use strict";
  
    Object.defineProperty(_exports, "__esModule", {
      value: true
    });
    _exports.CMSEntity = void 0;
  
    function _templateObject_99c5d700cf4a11e9b8b15bd4e98e0211() {
      var data = babelHelpers.taggedTemplateLiteral(["\n      <style>\n        :host {\n          display: block;\n          min-width: 112px;\n          min-height: 112px;\n          transition: 0.6s all ease;\n          background-color: transparent;\n        }\n        paper-spinner {\n          visibility: hidden;\n          opacity: 0;\n          height: 80px;\n          width: 80px;\n          padding: 16px;\n        }\n        #replacementcontent {\n          visibility: visible;\n          opacity: 1;\n        }\n        :host([loading]) {\n          text-align: center;\n        }\n        :host([loading]) paper-spinner {\n          visibility: visible;\n          opacity: 1;\n        }\n        :host([loading]) #replacementcontent {\n          opacity: 0;\n          visibility: hidden;\n        }\n      </style>\n      <iron-ajax\n        id=\"entityrequest\"\n        method=\"GET\"\n        params=\"[[bodyData]]\"\n        url=\"[[entityEndPoint]]\"\n        handle-as=\"json\"\n        last-response=\"{{entityData}}\"\n      ></iron-ajax>\n      <paper-spinner active=\"[[loading]]\"></paper-spinner>\n      <span id=\"replacementcontent\"><slot></slot></span>\n    "]);
  
      _templateObject_99c5d700cf4a11e9b8b15bd4e98e0211 = function _templateObject_99c5d700cf4a11e9b8b15bd4e98e0211() {
        return data;
      };
  
      return data;
    }
  
    /**
     * `cms-entity`
     * `Render and process a  / entity from a content management system.`
     */
    var CMSEntity =
    /*#__PURE__*/
    function (_PolymerElement) {
      babelHelpers.inherits(CMSEntity, _PolymerElement);
  
      function CMSEntity() {
        babelHelpers.classCallCheck(this, CMSEntity);
        return babelHelpers.possibleConstructorReturn(this, babelHelpers.getPrototypeOf(CMSEntity).apply(this, arguments));
      }
  
      babelHelpers.createClass(CMSEntity, [{
        key: "_generateBodyData",
  
        /**
         * Generate body data.
         */
        value: function _generateBodyData(entityType, entityId, entityDisplayMode) {
          if (entityType !== null && entityType !== "" && entityId !== null && entityId !== "") {
            return {
              type: "".concat(entityType),
              id: "".concat(entityId),
              display_mode: "".concat(entityDisplayMode)
            };
          }
        }
        /**
         * Handle the response from the entity processing endpoint
         */
  
      }, {
        key: "_handleEntityResponse",
        value: function _handleEntityResponse(newValue, oldValue) {
          var _this = this;
  
          if (newValue !== null && babelHelpers.typeof(newValue.content) !== (typeof undefined === "undefined" ? "undefined" : babelHelpers.typeof(undefined))) {
            // store the text and url callbacks
            if (document.getElementById("cmstokenidtolockonto") != null) {
              document.getElementById("cmstokenidtolockonto").setAttribute("href", newValue.editEndpoint);
              document.getElementById("cmstokenidtolockonto").innerHTML = newValue.editText;
            } // wipe our own slot here
  
  
            (0, _haxutils.wipeSlot)((0, _polymerDom.dom)(this)); // now inject the content we got
  
            _async.microTask.run(function () {
              var frag = document.createElement("span");
              frag.innerHTML = newValue.content;
              var newNode = frag.cloneNode(true);
              (0, _polymerDom.dom)(_this).appendChild(newNode);
              setTimeout(function () {
                _this.loading = false;
              }, 600);
            });
          }
        }
        /**
         * entity end point changed
         */
  
      }, {
        key: "_entityChanged",
        value: function _entityChanged(newValue, oldValue) {
          var _this2 = this;
  
          // ensure we have something and are not loading currently
          if (babelHelpers.typeof(newValue) !== (typeof undefined === "undefined" ? "undefined" : babelHelpers.typeof(undefined)) && newValue !== "" && !this.loading) {
            // support going from a null element to a real one
            if (babelHelpers.typeof(this.entityEndPoint) === (typeof undefined === "undefined" ? "undefined" : babelHelpers.typeof(undefined)) && babelHelpers.typeof(window.cmsentityEndPoint) !== (typeof undefined === "undefined" ? "undefined" : babelHelpers.typeof(undefined))) {
              this.entityEndPoint = window.cmsentityEndPoint;
            }
  
            if (this.entityEndPoint) {
              this.loading = true;
  
              _async.microTask.run(function () {
                _this2.$.entityrequest.generateRequest();
              });
            }
          }
        }
        /**
         * Attached to the DOM, now fire.
         */
  
      }, {
        key: "connectedCallback",
        value: function connectedCallback() {
          var _this3 = this;
  
          babelHelpers.get(babelHelpers.getPrototypeOf(CMSEntity.prototype), "connectedCallback", this).call(this);
  
          if (babelHelpers.typeof(this.entity) !== (typeof undefined === "undefined" ? "undefined" : babelHelpers.typeof(undefined)) && this.entity !== null && this.entity !== "") {
            var slot = (0, _polymerDom.dom)(this).getEffectiveChildNodes(); // only kick off request if there's nothing in it
            // if it has something in it that means we did some
            // remote rendering ahead of time
  
            if (slot.length === 0 && !this.loading) {
              // support for autoloading the entity data needed for the request from globals
              if (babelHelpers.typeof(this.entityEndPoint) === (typeof undefined === "undefined" ? "undefined" : babelHelpers.typeof(undefined)) && babelHelpers.typeof(window.cmsentityEndPoint) !== (typeof undefined === "undefined" ? "undefined" : babelHelpers.typeof(undefined))) {
                this.entityEndPoint = window.cmsentityEndPoint;
              }
  
              if (this.entityEndPoint) {
                this.loading = true;
  
                _async.microTask.run(function () {
                  _this3.$.entityrequest.generateRequest();
                });
              }
            }
          }
  
          (0, _renderStatus.afterNextRender)(this, function () {
            this.HAXWiring = new _HAXWiring.HAXWiring();
            this.HAXWiring.setup(CMSEntity.haxProperties, CMSEntity.tag, this);
          });
        }
      }, {
        key: "postProcessgetHaxJSONSchema",
  
        /**
         * Implements getHaxJSONSchema post processing callback.
         */
        value: function postProcessgetHaxJSONSchema(schema) {
          schema.properties["__editThis"] = {
            type: "string",
            component: {
              name: "a",
              properties: {
                id: "cmstokenidtolockonto",
                href: "",
                target: "_blank"
              },
              slot: "Edit this content"
            }
          };
          return schema;
        }
      }], [{
        key: "template",
        get: function get() {
          return (0, _polymerElement.html)(_templateObject_99c5d700cf4a11e9b8b15bd4e98e0211());
        }
      }, {
        key: "tag",
        get: function get() {
          return "cms-entity";
        }
      }, {
        key: "properties",
        get: function get() {
          return {
            /**
             * Loading state
             */
            loading: {
              type: Boolean,
              reflectToAttribute: true,
              value: false
            },
  
            /**
             * Type of entity to load
             */
            entityType: {
              type: String,
              reflectToAttribute: true
            },
  
            /**
             * ID of the item to load
             */
            entityId: {
              type: String,
              reflectToAttribute: true
            },
  
            /**
             * Display mode of the entity
             */
            entityDisplayMode: {
              type: String,
              reflectToAttribute: true
            },
  
            /**
             * entity end point updated, change the way we do processing.
             */
            entityEndPoint: {
              type: String
            },
  
            /**
             * Body data which is just entity with some encapsulation.
             */
            bodyData: {
              type: Object,
              computed: "_generateBodyData(entityType, entityId, entityDisplayMode)",
              observer: "_entityChanged"
            },
  
            /**
             * entity data from the end point.
             */
            entityData: {
              type: String,
              observer: "_handleEntityResponse"
            },
  
            /**
             * Prefix for the entity to be processed
             */
            entityPrefix: {
              type: String,
              observer: "["
            },
  
            /**
             * Suffix for the entity to be processed
             */
            entitySuffix: {
              type: String,
              observer: "]"
            }
          };
        }
      }, {
        key: "haxProperties",
        get: function get() {
          return {
            canScale: true,
            canPosition: true,
            canEditSource: false,
            gizmo: {
              title: "CMS Entity",
              description: "CMS entity rendered on the backend",
              icon: "places:spa",
              color: "light-blue",
              groups: ["CMS"],
              handles: [{
                type: "cmsentity",
                entity: "entity"
              }],
              meta: {
                author: "LRNWebComponents"
              }
            },
            settings: {
              quick: [],
              configure: [{
                property: "entityType",
                title: "Type",
                description: "type from our CMS",
                inputMethod: "select",
                options: {
                  node: "Node",
                  user: "User",
                  file: "File"
                },
                icon: "editor:title"
              }, {
                property: "entityID",
                title: "ID",
                description: "id from our CMS",
                inputMethod: "textfield",
                icon: "editor:title"
              }, {
                property: "entityDisplayMode",
                title: "Display mode",
                description: "display mode from our CMS",
                inputMethod: "textfield",
                icon: "editor:title"
              }],
              advanced: []
            },
            saveOptions: {
              wipeSlot: true,
              unsetAttributes: ["loading", "entity-data", "body-data", "entity-end-point"]
            }
          };
        }
      }]);
      return CMSEntity;
    }(_polymerElement.PolymerElement);
  
    _exports.CMSEntity = CMSEntity;
    window.customElements.define(CMSEntity.tag, CMSEntity);
  });