text: define(["exports","../../../@polymer/polymer/polymer-element.js","../../../@polymer/iron-flex-layout/iron-flex-layout-classes.js","../../../@polymer/iron-icons/image-icons.js","../../../@polymer/iron-icons/iron-icons.js","../../../@polymer/iron-icons/editor-icons.js","../../../@polymer/iron-pages/iron-pages.js","../../../@polymer/app-layout/app-toolbar/app-toolbar.js","../../../@polymer/paper-menu-button/paper-menu-button.js","../../../@polymer/paper-icon-button/paper-icon-button.js","../../../@polymer/app-localize-behavior/app-localize-behavior.js","../../../@polymer/polymer/lib/legacy/class.js","./eco-json-schema-object.js","./eco-json-schema-array.js","./eco-json-schema-boolean.js","./eco-json-schema-enum.js","./eco-json-schema-file.js","./eco-json-schema-input.js"],(function(e,t,o,a,r,i,s,n,l,p,c,h,m,u,d,y,b,f){"use strict";Object.defineProperty(e,"__esModule",{value:!0}),e.EcoJsonSchemaWizard=void 0;class EcoJsonSchemaWizard extends((0,h.mixinBehaviors)([c.AppLocalizeBehavior],t.PolymerElement)){static get tag(){return"eco-json-schema-wizard"}static get template(){return t.html`
        <style is="custom-style" include="iron-flex iron-flex-alignment">
          :host {
            display: block;
            @apply --layout-vertical;
          }
  
          paper-input {
            padding: 2px;
            --paper-input-container-label: {
              white-space: normal;
              position: static;
              font-size: 22px;
              color: #fff;
            }
          }
  
          .box,
          #form {
            display: -webkit-box;
            display: -webkit-flex;
            display: -moz-box;
            display: -ms-flexbox;
            display: flex;
            -webkit-flex-align: center;
            -ms-flex-align: center;
            -webkit-align-items: center;
            align-items: center;
          }
  
          .fullbleed {
            z-index: 1;
          }
  
          app-toolbar.bottom {
            --app-toolbar-color: var(--app-primary-color);
            --app-toolbar-background: var(--dark-theme-text-color);
          }
  
          app-toolbar.bottom paper-icon-button {
            --app-toolbar-color: var(--dark-theme-text-color);
            --app-toolbar-background: var(--app-primary-color);
          }
        </style>
        <div class="vertical flex layout fullbleed">
          <!--
          paper-icon-button id="camButton" icon="editor:insert-photo" raised>add photo</paper-icon-button
        -->
          <app-toolbar>
            <paper-icon-button
              id="prevButton"
              icon="arrow-back"
              hidden\$="{{!hasPrev}}"
              on-click="prev"
              raised=""
              >{{localize('prev')}}</paper-icon-button
            ><span
              class="title layout horizontal flex"
              style="white-space: normal"
              >[[title]]</span
            >
            <paper-icon-button
              id="nextButton"
              icon="arrow-forward"
              hidden\$="{{!hasNext}}"
              on-click="next"
              raised=""
              >{{localize('next')}}</paper-icon-button
            >
            <paper-icon-button
              id="submitButton"
              icon="cloud-upload"
              on-click="submit"
              raised=""
              >{{localize('submit')}}</paper-icon-button
            >
          </app-toolbar>
          <iron-pages
            id="form"
            class="layout horizontal flex start-justified"
            role="main"
            selected="[[page]]"
            attr-for-selected="name"
          ></iron-pages>
          <app-toolbar class="bottom">
            <div hidden\$="{{!hasPrev}}" on-click="prev">
              <paper-icon-button id="prevButton" icon="arrow-back" raised=""
                >{{localize('prev')}}</paper-icon-button
              >
              <span class="title layout" style="white-space: normal"
                >{{localize('prev')}}</span
              >
            </div>
            <span
              class="title layout horizontal flex"
              style="white-space: normal"
            ></span>
            <div hidden\$="{{!hasNext}}" on-click="next">
              <span class="title layout" style="white-space: normal"
                >{{localize('next')}}</span
              >
              <paper-icon-button id="nextButton" icon="arrow-forward" raised=""
                >{{localize('next')}}</paper-icon-button
              >
            </div>
          </app-toolbar>
        </div>
      `}static get properties(){return{language:{type:String,notify:!0},resources:{type:Object,notify:!0},schema:{type:Object,notify:!0,observer:"_schemaChanged"},label:{type:String},value:{type:Object,notify:!0,value:()=>({})},page:{type:String,notify:!0,observer:"_pageChanged"},pages:{type:Array,notify:!0,value:[]},error:{type:Object,observer:"_errorChanged"},isReview:{type:Boolean,value:!1,notify:!0},canSubmit:{type:Boolean,notify:!0},hasNext:{type:Boolean,notify:!0},hasPrev:{type:Boolean,notify:!0},titles:{type:Array,notify:!0,value:[]},title:{type:String,value:"",notify:!0}}}disconnectedCallback(){this._clearForm(),super.disconnectedCallback()}_buildSchemaProperties(){var e=this;this._schemaProperties=Object.keys(this.schema.properties||[]).map((function(t){var o=e.schema.properties[t],a={property:t,label:o.title||t,schema:o,component:o.component||{}};if(a.component.valueProperty||(a.component.valueProperty="value"),e._isSchemaEnum(o))a.component.name=a.component.name||"eco-json-schema-enum",a.value="";else if(e._isSchemaBoolean(o.type))a.component.name=a.component.name||"eco-json-schema-boolean",a.value=!1;else if(e._isSchemaFile(o.type))a.component.name=a.component.name||"eco-json-schema-file",a.value="";else if(e._isSchemaValue(o.type))a.component.name=a.component.name||"eco-json-schema-input",a.value="";else if(e._isSchemaObject(o.type))a.component.name=a.component.name||"eco-json-schema-object",a.component.wizard=!0,a.value={};else{if(!e._isSchemaArray(o.type))return console.error("Unknown property type %s",o.type);a.component.name=a.component.name||"eco-json-schema-array",a.value=[]}return e.push("pages",t),e.push("titles",o.title),a}))}_schemaPropertyChanged(e,t){if(!t.path||!/\.length$/.test(t.path)){var o=this,a=e.target.schemaProperty,r=["value",a.property];if(t.path&&/\.splices$/.test(t.path)){for(var i=t.path.split(".").slice(1,-1);i.length;)r.push(i.shift()),a.keyMap&&a.keyMap[r.join(".")]&&(r=a.keyMap[r.join(".")].split("."));t.value.keySplices&&a.keyMap&&t.value.keySplices.forEach((function(e){e.removed.forEach((function(e){delete a.keyMap[r.concat([e]).join(".")]}))})),t.value.indexSplices.forEach((function(e){var t=[r.join("."),e.index,e.removed.length];if(e.addedCount)for(var i=0,s=e.addedCount;i<s;i++)e.addedKeys&&e.addedKeys[i]&&(a.keyMap=a.keyMap||{},a.keyMap[r.concat([e.addedKeys[i]]).join(".")]=r.concat([i+e.index]).join(".")),t.push(o._deepClone(e.object[i+e.index]));o.splice.apply(o,t)}))}else if(t.path){i=t.path.split(".").slice(1);for(this.value.hasOwnProperty(a.property)||this.set("value."+a.property,{});i.length;){var s=i.shift();r.push(s),a.keyMap&&a.keyMap[r.join(".")]&&(r=a.keyMap[r.join(".")].split("."))}this.set(r.join("."),this._deepClone(t.value)),console.log("value: "+JSON.stringify(this.value))}}}_setValue(){var e=this,t={};this._schemaProperties.forEach((function(o){t[o.property]=e._deepClone(o.value)})),this.value=t}_buildForm(){var e=this;this._schemaProperties.forEach(t=>{var o=e.create(t.component.name,{label:t.label,schema:t.schema,schemaProperty:t,language:this.language,resources:this.resources});o.setAttribute("name",t.property),o.className="flex start-justified",t.value=o[t.component.valueProperty],e.listen(o,t.component.valueProperty.replace(/([A-Z])/g,"-$1").toLowerCase()+"-changed","_schemaPropertyChanged"),e.shadowRoot.querySelector("#form").appendChild(o)})}_removePropertyEl(e){void 0!==e.schemaProperty&&this.unlisten(e,e.schemaProperty.component.valueProperty.replace(/([A-Z])/g,"-$1").toLowerCase()+"-changed","_schemaPropertyChanged"),e.schemaProperty=null,this.shadowRoot.querySelector("#form").removeChild(e)}_clearForm(){for(var e=this.shadowRoot.querySelector("#form");e.firstChild;)this._removePropertyEl(e.firstChild)}_schemaChanged(){this._clearForm(),this._buildSchemaProperties(),this._buildForm(),this._setValue(),this.pages.length>0&&this.set("page",this.pages[0]),this.set("title",this.titles[0])}next(){var e=this.pages.indexOf(this.page),t=e;-1!==e?(e<this.pages.length-1&&(t=e+1),this.set("page",this.pages[t]),this.set("title",this.titles[t])):console.log("Invalid current page in wizard")}prev(){var e=this.pages.indexOf(this.page),t=e;-1!==e?(e>0&&(t=e-1),this.set("page",this.pages[t]),this.set("title",this.titles[t])):console.log("Invalid current page in wizard")}submit(){this.dispatchEvent(new CustomEvent("submit",{bubbles:!0,cancelable:!0,composed:!0,detail:!0}))}_pageChanged(){var e=this.pages.indexOf(this.page);0===e?this.set("hasPrev",!1):this.set("hasPrev",!0),e===this.pages.length-1?this.set("hasNext",!1):this.set("hasNext",!0)}_errorChanged(){var e=this;this.shadowRoot.querySelector("#form").childNodes.forEach((function(t){var o=t.getAttribute("name");e.error&&e.error[o]?t.error=e.error[o]:t.error=null}))}_deepClone(e){return JSON.parse(JSON.stringify(e))}_isSchemaValue(e){return this._isSchemaBoolean(e)||this._isSchemaNumber(e)||this._isSchemaString(e)||this._isSchemaFile(e)}_isSchemaFile(e){return Array.isArray(e)?-1!==e.indexOf("file"):"file"===e}_isSchemaBoolean(e){return Array.isArray(e)?-1!==e.indexOf("boolean"):"boolean"===e}_isSchemaEnum(e){return!!e.enum}_isSchemaNumber(e){return Array.isArray(e)?-1!==e.indexOf("number")||-1!==e.indexOf("integer"):"number"===e||"integer"===e}_isSchemaString(e){return Array.isArray(e)?-1!==e.indexOf("string"):"string"===e}_isSchemaObject(e){return"object"===e}_isSchemaArray(e){return"array"===e}}e.EcoJsonSchemaWizard=EcoJsonSchemaWizard,window.customElements.define(EcoJsonSchemaWizard.tag,EcoJsonSchemaWizard)}));