text: /**
   * Copyright 2018 The Pennsylvania State University
   * @license Apache-2.0, see License.md for full text.
   */
  import{html as e,PolymerElement as t}from"../../../../../@polymer/polymer/polymer-element.js";import"../../../../hax-logo/hax-logo.js";import"../../../../../@polymer/iron-ajax/iron-ajax.js";import"../../../../jwt-login/jwt-login.js";import"../../../../hexagon-loader/hexagon-loader.js";import"../../../../json-outline-schema/json-outline-schema.js";import"../../../../simple-toast/simple-toast.js";import"../../../../simple-modal/simple-modal.js";import"../../../../simple-datetime/simple-datetime.js";import"../../../../simple-fields/simple-fields.js";import"../../../../simple-fields/lib/simple-fields-field.js";import"../../../../simple-modal/lib/simple-modal-template.js";import{SimpleColorsPolymer as i}from"../../../../simple-colors/lib/simple-colors-polymer.js";import"../../../../../@vaadin/vaadin-upload/vaadin-upload.js";import"../../../../../@vaadin/vaadin-grid/vaadin-grid.js";import"../../../../../@vaadin/vaadin-grid/vaadin-grid-column.js";import"../../../../../@vaadin/vaadin-grid/vaadin-grid-sort-column.js";import"../../../../../@vaadin/vaadin-grid/vaadin-grid-filter-column.js";import"../../../../../@vaadin/vaadin-grid/vaadin-grid-selection-column.js";import"../../../../simple-login/simple-login.js";import"../../../../simple-login/lib/simple-login-avatar.js";import"../../../../simple-colors/lib/simple-colors-picker.js";import"../../../../../@polymer/paper-dialog/paper-dialog.js";import"../../../../md-block/md-block.js";import"../../../../simple-fields/simple-fields.js";import"../../../../simple-picker/simple-picker.js";import"../../../../simple-icon-picker/simple-icon-picker.js";import"../../../../simple-tooltip/simple-tooltip.js";import"../../../../portal-launcher/portal-launcher.js";import"../../../../json-outline-schema/lib/jos-render.js";import"../../../../a11y-collapse/a11y-collapse.js";import"../../../../a11y-collapse/lib/a11y-collapse-group.js";import"../../../../simple-icon/lib/simple-icon-button.js";import"../../../../simple-icon/lib/simple-icons.js";import"../../../../simple-icon/simple-icon.js";import"../../../../hax-iconset/lib/simple-hax-iconset.js";import"../haxcms-site-store.js";import{HaxSchematizer as o,HaxElementizer as a}from"../../../../hax-body-behaviors/lib/HAXFields.js";import{normalizeEventPath as s}from"../../../../utils/utils.js";class HAXCMSSiteListing extends t{constructor(){super(),this.SimpleColors=new i,this.HaxSchematizer=o,this.HaxElementizer=a}static get tag(){return"haxcms-site-listing"}static get template(){return e`
        <style include="simple-colors-shared-styles-polymer">
          simple-icon-button {
            --simple-icon-button-ink-color: var(--haxcms-system-action-color);
          }
          .toolbar div.main-title {
            margin-left: 50px;
            font-size: 24px;
          }
          .toolbar {
            display: flex;
            padding: 8px;
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            color: var(--simple-colors-default-theme-accent-11, #111111);
            background-color: var(
              --simple-colors-default-theme-accent-2,
              #eeeeee
            );
            z-index: 1;
            line-height: 120%;
            align-items: center;
          }
          a11y-collapse-group {
            margin-top: 64px;
          }
          a11y-collapse div[slot="heading"] {
            height: 64px;
            line-height: 64px;
            font-size: 30px;
            cursor: pointer;
          }
          jos-render {
            --jos-render-margin: 0px;
            --jos-render-padding: 8px;
          }
          course-card {
            height: 350px;
            width: 150px;
            overflow: hidden;
            --course-card-filter: grayscale(80%);
          }
          course-card:active,
          course-card:hover {
            --course-card-filter-hover: grayscale(0%);
          }
          vaadin-grid {
            margin-top: 24px;
            height: calc(100vh - 64px);
          }
          simple-datetime {
            color: black;
          }
          vaadin-checkbox {
            border: 1px solid black;
            background-color: var(--simple-colors-default-theme-blue-1);
          }
          .login-prompt {
            margin: 80px auto 0;
            display: flex;
            justify-content: center;
          }
          .login-prompt[hidden] {
            display: none;
          }
          .login-prompt div#selfie {
            position: absolute;
            margin: 0;
          }
          .has-snap {
            z-index: 3;
          }
          .hide-camera {
            display: none;
          }
          .login-prompt div#selfie img {
            z-index: 2;
            position: absolute;
            margin: 0 0 0 -138px;
            height: 355px;
            display: block;
          }
          simple-login {
            background: #eeeeee;
            color: var(--haxcms-system-bg);
            --primary-color: var(--haxcms-system-bg);
            --primary-text-color: var(--haxcms-system-bg);
            --simple-fields-accent-color: var(--haxcms-system-action-color);
            --login-btn-background-color: var(--haxcms-system-bg);
            --login-btn-raised-background-color: var(
              --haxcms-system-action-color
            );
            --login-form-color: var(--haxcms-system-bg);
            --login-btn-width: 80%;
            --login-btn-display: block;
            text-align: center;
          }
          .forgot {
            margin: 32px 0 -16px 0;
            padding: 0;
            font-size: 12px;
            text-align: center;
          }
          hax-logo {
            margin-top: -50px;
            margin-bottom: 16px;
            text-align: center;
            --hax-logo-font-size: 24px;
            --hax-logo-letter-spacing: 0px;
          }
          .camera-buttons {
            width: 100%;
            justify-content: center;
            display: flex;
          }
          simple-modal-template[modal-id="help"] {
            --simple-modal-width: 60vw;
          }
          paper-dialog {
            width: 60vw;
          }
          div.scrollable {
            overflow: scroll;
            height: 40vh;
          }
          h2.dialog-header {
            background-color: var(--haxcms-site-listing-color-dark);
            margin: 0;
            padding: 28px;
            color: var(--haxcms-site-listing-color-light);
          }
          .buttons {
            text-align: center;
            margin: 0 auto;
            display: flex;
            justify-content: center;
            margin-top: 2em;
            color: var(--haxcms-site-listing-color-dark);
            font-weight: 500;
          }
          .action-button {
            height: 48px;
            background-color: var(--haxcms-site-listing-color-dark);
            color: var(--haxcms-site-listing-color-light);
            margin-right: 48px;
          }
          .action-button:hover,
          .action-button:active,
          .action-button:focus {
            background-color: var(--haxcms-site-listing-color-hover);
          }
          button simple-icon {
            margin-right: 4px;
          }
          simple-fields-field {
            --simple-fields-accent-color: var(--haxcms-site-listing-color-hover);
          }
          .small-location {
            font-size: 11px;
            font-style: italic;
          }
          #grid {
            font-size: 13px;
          }
          #loading {
            z-index: 1000;
            opacity: 1;
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0%;
            padding: 50vh calc(50% - 127.5px);
            transition: all linear 1s;
            visibility: visible;
            background-color: rgba(250, 250, 250, 0.8);
          }
          #loading[data-loading] {
            opacity: 0;
            visibility: hidden;
            --hexagon-color: var(
              --simple-colors-default-theme-light-blue-7,
              #007ffc
            );
          }
          a {
            text-decoration: none;
            color: black;
          }
          .site-title {
            display: block;
            font-size: 20px;
            width: 100%;
            min-width: unset;
            text-decoration: underline;
          }
          .site-title:hover,
          .site-title:active,
          .site-title:focus {
            text-decoration: none;
          }
          .operations button {
            font-weight: 500;
            color: black;
            background-color: var(--haxcms-site-listing-color-light);
            margin: 0 8px;
            padding: 4px;
            display: inline-flex;
            font-size: 12px;
            line-height: 24px;
            cursor: pointer;
          }
          .operations button:hover,
          .operations button:active,
          .operations button:focus {
            background-color: var(--haxcms-site-listing-color-light);
            color: var(--haxcms-site-listing-color-hover);
          }
          .operations button span {
            height: 24px;
          }
          .operations.right {
            right: 0;
            position: absolute;
            display: inline-flex;
          }
          #add {
            background-color: var(--haxcms-site-listing-color-hover);
            color: var(--haxcms-site-listing-color-light);
            transition: 0.2s all linear;
          }
          #add:hover,
          #add:active,
          #add:focus {
            background-color: var(--haxcms-site-listing-color-light);
            color: var(--haxcms-site-listing-color-hover);
          }
          .selected-operations {
            margin: 0 16px;
            transition: 0.3s linear all;
            display: inline-flex;
            visibility: visible;
            opacity: 1;
            align-content: center;
            justify-content: space-evenly;
            width: 100%;
          }
          *[hidden] {
            visibility: hidden;
            opacity: 0;
            display: none;
          }
          .selected-operations button {
            background-color: var(--haxcms-site-listing-color-light);
            font-weight: 500;
            font-size: 16px;
            color: var(--haxcms-site-listing-color-dark);
            margin: 0;
            min-width: unset;
            margin: 8px;
            height: 48px;
          }
          .selected-operations button:active,
          .selected-operations button:hover,
          .selected-operations button:focus {
            background-color: var(--haxcms-site-listing-color-hover);
            color: var(--haxcms-site-listing-color-light) !important;
          }
          .danger {
            color: var(--simple-colors-default-theme-red-7) !important;
          }
          .danger:hover {
            color: var(--haxcms-site-listing-color-light) !important;
          }
          #userphoto {
            width: 24px;
            height: 24px;
            margin-right: 4px;
            border-radius: 50%;
          }
          @media screen and (max-width: 1080px) {
            .selected-operations .small-hide {
              display: none;
            }
          }
          @media screen and (max-width: 800px) {
            .main-title {
              display: none;
            }
          }
          @media screen and (max-width: 700px) {
            .small-hide {
              display: none;
            }
          }
        </style>
        <jwt-login
          id="jwt"
          method="[[method]]"
          url="[[__loginPath]]"
          refresh-url="[[__refreshPath]]"
          logout-url="[[__logoutPath]]"
          jwt="{{jwt}}"
        ></jwt-login>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="loaddata"
          auto=""
          loading="{{__loading}}"
          url="[[dataSource]]"
          handle-as="json"
          debounce-duration="250"
          last-response="{{sitesResponse}}"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="createrequest"
          method="[[method]]"
          body="[[createParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__createNewSitePath]]"
          handle-as="json"
          on-response="handleCreateResponse"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="gitimportrequest"
          method="[[method]]"
          body="[[gitImportParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__gitImportSitePath]]"
          handle-as="json"
          on-response="handleGitImportResponse"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="downloadrequest"
          method="[[method]]"
          body="[[downloadParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__downloadSitePath]]"
          handle-as="json"
          on-response="handleDownloadResponse"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="archiverequest"
          method="[[method]]"
          body="[[archiveParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__archiveSitePath]]"
          handle-as="json"
          on-response="handleArchiveResponse"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="deleterequest"
          method="[[method]]"
          body="[[deleteParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__deleteSitePath]]"
          handle-as="json"
          on-response="handleDeleteResponse"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="clonerequest"
          method="[[method]]"
          body="[[cloneParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__cloneSitePath]]"
          handle-as="json"
          on-response="handleCloneResponse"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="publishrequest"
          method="[[method]]"
          body="[[publishParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__publishSitePath]]"
          handle-as="json"
          on-response="handlePublishResponse"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="syncrequest"
          method="[[method]]"
          body="[[syncParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__syncSitePath]]"
          handle-as="json"
          on-response="handleSyncResponse"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="getconfigrequest"
          method="[[method]]"
          body="[[configParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__getConfigPath]]"
          handle-as="json"
          on-response="handleConfigResponse"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="setconfigrequest"
          method="[[method]]"
          body="[[setConfigParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__setConfigPath]]"
          handle-as="json"
          on-response="handleSetConfigResponse"
        ></iron-ajax>
        <iron-ajax
          reject-with-request
          on-last-error-changed="lastErrorChanged"
          id="getuserdatarequest"
          method="[[method]]"
          body="[[getUserDataParams]]"
          headers='{"Authorization": "Bearer [[jwt]]"}'
          content-type="application/json"
          url="[[__getUserDataPath]]"
          handle-as="json"
          on-response="handleGetUserDataResponse"
        ></iron-ajax>
        <div id="loading" data-loading$="[[!__loading]]">
          <hexagon-loader item-count="4" loading size="large"></hexagon-loader>
        </div>
        <div class="toolbar">
          <slot name="app-header-pre"></slot>
          <div class="operations">
            <button
              on-click="_addTap"
              id="add"
              raised
              hidden$="[[!loggedIn]]"
              title="Create new site"
            >
              <simple-icon icon="icons:add" dark></simple-icon>
              <span class="small-hide">New site</span>
            </button>
            <button
              on-click="_importTap"
              id="import"
              raised
              hidden$="[[!loggedIn]]"
              title="Import site"
            >
              <simple-icon icon="icons:cloud-download"></simple-icon>
              <span class="small-hide">Import</span>
            </button>
          </div>
          <div class="main-title" hidden$="[[!loggedIn]]">[[title]]</div>
          <div class="operations right">
            <button
              on-click="_helpTap"
              id="help"
              raised
              title="Help"
              hidden$="[[!showSpecialButtons(hideGlobalSettings,loggedIn)]]"
            >
              <simple-icon icon="icons:help"></simple-icon>
              <span class="small-hide">Help</span>
            </button>
            <button
              on-click="_settingsTap"
              id="settings"
              raised
              title="Settings"
              hidden$="[[!showSpecialButtons(hideGlobalSettings,loggedIn)]]"
            >
              <simple-icon icon="icons:settings"></simple-icon>
              <span class="small-hide">Settings</span>
            </button>
            <button
              hidden$="[[!showSpecialButtons(hideLogin,loggedIn)]]"
              id="login"
              on-click="_logoutUserRoutine"
              title="Logout"
            >
              <template is="dom-if" if="[[!logoutPhoto]]">
                <simple-icon
                  icon="[[__loginIcon]]"
                  class="small-hide"
                ></simple-icon>
              </template>
              <template is="dom-if" if="[[logoutPhoto]]">
                <img id="userphoto" src="[[logoutPhoto]]" class="small-hide" />
              </template>
              [[__loginText]]
            </button>
          </div>
        </div>
        <a11y-collapse-group heading-button expanded hidden$="[[!loggedIn]]">
          <a11y-collapse>
            <div slot="heading">Card view</div>
            <jos-render slot="content"></jos-render>
          </a11y-collapse>
          <a11y-collapse>
            <div slot="heading">Table view / bulk operations</div>
            <div slot="content">
              <div class="selected-operations" id="ops">
                <button
                  title="Publish"
                  on-click="_bulkSitesConfirm"
                  id="publish"
                  raised
                  data-op="publish"
                >
                  <simple-icon
                    icon="editor:publish"
                    data-op="publish"
                  ></simple-icon>
                  <span class="small-hide" data-op="publish">Publish site</span>
                </button>
                <button
                  title="Sync git"
                  on-click="_bulkSitesConfirm"
                  id="sync"
                  data-op="sync"
                  raised
                >
                  <simple-icon
                    icon="notification:sync"
                    data-op="sync"
                  ></simple-icon>
                  <span class="small-hide" data-op="sync">Sync git</span>
                </button>
                <button
                  title="Copy site"
                  on-click="_bulkSitesConfirm"
                  id="clone"
                  raised
                  data-op="copy"
                >
                  <simple-icon
                    icon="icons:content-copy"
                    data-op="copy"
                  ></simple-icon>
                  <span class="small-hide" data-op="copy">Copy site</span>
                </button>
                <button
                  title="Download zip"
                  on-click="_bulkSitesConfirm"
                  id="download"
                  raised
                  data-op="download"
                >
                  <simple-icon
                    icon="icons:file-download"
                    data-op="download"
                  ></simple-icon>
                  <span class="small-hide" data-op="download">Download zip</span>
                </button>
                <button
                  title="Archive"
                  on-click="_bulkSitesConfirm"
                  id="archive"
                  raised
                  data-op="archive"
                >
                  <simple-icon
                    icon="icons:archive"
                    data-op="archive"
                  ></simple-icon>
                  <span class="small-hide" data-op="archive">Archive site</span>
                </button>
                <button
                  on-click="_bulkSitesConfirm"
                  id="delete"
                  data-op="delete"
                  raised
                  class="danger"
                  title="Delete forever"
                >
                  <simple-icon
                    icon="icons:delete-forever"
                    data-op="delete"
                  ></simple-icon>
                  <span class="small-hide" data-op="delete">Delete forever</span>
                </button>
              </div>
              <vaadin-grid
                id="grid"
                items="[[sites]]"
                theme="row-dividers"
                column-reordering-allowed
                multi-sort
              >
                <vaadin-grid-selection-column
                  width="5em"
                  auto-select
                  frozen
                ></vaadin-grid-selection-column>
                <vaadin-grid-filter-column
                  header="Site name"
                  width="240px"
                  path="title"
                >
                  <template>
                    <portal-launcher>
                      <a class="site-title" href$="[[item.slug]]">
                        <div>[[item.title]]</div>
                        <div class="small-location">
                          [[cleanLocation(item.slug)]]
                        </div>
                      </a>
                    </portal-launcher>
                  </template>
                </vaadin-grid-filter-column>
                <vaadin-grid-filter-column
                  path="metadata.theme.name"
                  header="Theme"
                  width="80px"
                ></vaadin-grid-filter-column>
                <vaadin-grid-sort-column header="Updated" path="metadata.updated">
                  <template>
                    <template is="dom-if" if="[[item.metadata.site.updated]]">
                      <simple-datetime
                        format="M jS, Y"
                        timestamp="[[item.metadata.site.updated]]"
                        unix
                      ></simple-datetime>
                    </template>
                  </template>
                </vaadin-grid-sort-column>
                <vaadin-grid-sort-column header="Created" path="metadata.created">
                  <template>
                    <template is="dom-if" if="[[item.metadata.site.created]]">
                      <simple-datetime
                        format="M jS, Y"
                        timestamp="[[item.metadata.site.created]]"
                        unix
                      ></simple-datetime>
                    </template>
                  </template>
                </vaadin-grid-sort-column>
                <vaadin-grid-column header="Icon">
                  <template
                    ><simple-icon
                      icon="[[item.metadata.theme.variables.icon]]"
                    ></simple-icon
                  ></template>
                </vaadin-grid-column>
                <vaadin-grid-sort-column
                  header="Last published"
                  path="metadata.lastPublished"
                >
                  <template>
                    <template
                      is="dom-if"
                      if="[[item.metadata.site.static.lastPublished]]"
                    >
                      <simple-datetime
                        format="M jS, Y"
                        timestamp="[[item.metadata.site.static.lastPublished]]"
                        unix
                      ></simple-datetime>
                    </template>
                  </template>
                </vaadin-grid-sort-column>
                <vaadin-grid-sort-column
                  path="metadata.pageCount"
                  header="Pages"
                ></vaadin-grid-sort-column>
                <vaadin-grid-column header="Color">
                  <template>
                    <div
                      style$="border:1px solid black;width:64px;height:48px;background-color:[[item.metadata.theme.variables.hexCode]];"
                    ></div>
                  </template>
                </vaadin-grid-column>
                <vaadin-grid-column header="Logo" width="64px">
                  <template
                    ><img
                      loading="lazy"
                      src$="[[item.slug]][[item.metadata.site.logo]]"
                      style="width:64px; height:64px;"
                    />
                  </template>
                </vaadin-grid-column>
              </vaadin-grid>
            </div>
          </a11y-collapse>
        </a11y-collapse-group>
        <div class="login-prompt" hidden$="[[loggedIn]]">
          <simple-login>
            <hax-logo size="mini" hide-hax><span>HAXcms login</span></hax-logo>
            <div class="camera-buttons">
              <simple-icon-button
                id="snap"
                icon="image:camera-alt"
                title="Snap photo"
              ></simple-icon-button>
              <simple-icon-button
                id="newsnap"
                icon="icons:cancel"
                title="Clear photo"
              ></simple-icon-button>
            </div>
            <simple-login-avatar>
              <div id="selfie"></div>
              <simple-login-camera id="camera" autoplay></simple-login-camera>
            </simple-login-avatar>
            <p class="forgot" slot="buttons">
              Forget your login? Check <strong>_config/config.php</strong>
            </p>
          </simple-login>
          <vaadin-upload
            capture
            headers='{"Authorization": "Bearer [[jwt]]"}'
            method="[[method]]"
            form-data-name="file-upload"
            hidden
            id="fileupload"
          ></vaadin-upload>
        </div>
        <simple-modal-template modal-id="help" title="Help">
          <div slot="header">Help directions</div>
          <p slot="content">
            <md-block
              style="overflow:auto;max-height: 50vh;font-size:12px;"
              source="https://raw.githubusercontent.com/elmsln/HAXcms/master/HAXDocs.md"
            ></md-block>
          </p>
        </simple-modal-template>
        <paper-dialog id="confirm">
          <h2 class="dialog-header">
            [[activeOpertion]] these [[selectedItems.length]] sites
          </h2>
          <div class="scrollable">
            <ul>
              <dom-repeat items="[[selectedItems]]" as="site">
                <template>
                  <li>[[site.title]]</li>
                </template>
              </dom-repeat>
            </ul>
          </div>
          <div class="buttons">
            <button
              on-click="_confirmBulkOperation"
              dialog-confirm
              id="bulksites"
              class="action-button"
              raised
            >
              <simple-icon icon="icons:thumb-up"></simple-icon> Yes,
              [[activeOpertion]]
            </button>
            <button class="action-button" dialog-dismiss>
              <simple-icon icon="icons:cancel"></simple-icon> Cancel
            </button>
          </div>
        </paper-dialog>
        <paper-dialog id="createsite">
          <h2 class="dialog-header">Create new site</h2>
          <div class="scrollable">
            <form>
              <simple-fields
                id="createsitefields"
                autofocus
                schematizer="[[HaxSchematizer]]"
                elementizer="[[HaxElementizer]]"
              >
              </simple-fields>
            </form>
          </div>
          <div class="buttons">
            <button
              on-click="_createSite"
              class="action-button"
              dialog-confirm
              id="create"
              raised
            >
              <simple-icon icon="icons:home" dark></simple-icon> Create your new
              site!
            </button>
            <button class="action-button" dialog-dismiss>
              <simple-icon dark icon="icons:cancel"></simple-icon> Cancel
            </button>
          </div>
        </paper-dialog>
        <paper-dialog id="importsite">
          <h2 class="dialog-header">Import site from git repo</h2>
          <simple-fields-field
            id="importurl"
            label="Git url"
            type="text"
          ></simple-fields-field>
          <div class="buttons">
            <button
              on-click="_gitImportSite"
              class="action-button"
              dialog-confirm
              id="importsite"
              raised
            >
              <simple-icon icon="icons:home" dark></simple-icon> Import
            </button>
            <button class="action-button" dialog-dismiss>
              <simple-icon dark icon="icons:cancel"></simple-icon> Cancel
            </button>
          </div>
        </paper-dialog>
        <paper-dialog id="settingsdialog">
          <h2 class="dialog-header">Edit HAXCMS configuration</h2>
          <div class="scrollable">
            <simple-fields
              id="settingsform"
              schematizer="[[HaxSchematizer]]"
              elementizer="[[HaxElementizer]]"
            >
            </simple-fields>
          </div>
          <div class="buttons">
            <button
              on-click="_saveConfig"
              dialog-confirm
              id="saveconfig"
              class="action-button"
              raised
            >
              <simple-icon icon="icons:save" dark></simple-icon> Save
            </button>
            <button class="action-button" dialog-dismiss>
              <simple-icon icon="icons:cancel" dark></simple-icon> Cancel
            </button>
          </div>
        </paper-dialog>
      `}_sitesResponseChanged(e,t){e&&void 0!==e.items&&(this.title=e.title,this.set("sites",[]),this.set("sites",e.items),this.shadowRoot.querySelector("jos-render").items=e.items,this.notifyPath("sites.*"))}cleanLocation(e){return e?e.replace("/_sites/","").replace("/sites/","").replace("/",""):e}static get properties(){return{__loading:{type:Boolean},sitesResponse:{type:Object,notify:!0,observer:"_sitesResponseChanged"},method:{type:String,value:"POST"},title:{type:String,value:"My sites"},sites:{type:Array,notify:!0},basePath:{type:String},hideLogin:{type:Boolean,value:!1},hideGlobalSettings:{type:Boolean,value:!1},dataSource:{type:String,observer:"_dataSourceChanged"},jwt:{type:String,notify:!0,observer:"_jwtChanged"},userData:{type:Object,value:{},observer:"_userDataChanged"},createParams:{type:Object,value:{}},downloadParams:{type:Object,value:{}},deleteParams:{type:Object,value:{}},cloneParams:{type:Object,value:{}},publishParams:{type:Object,value:{}},syncParams:{type:Object,value:{}},archiveParams:{type:Object,value:{}},configParams:{type:Object,value:{}},setConfigParams:{type:Object,value:{}},getUserDataParams:{type:Object,value:{}},activeOpertion:{type:String},HaxSchematizer:{type:Object},HaxElementizer:{type:Object},selectedItems:{type:Array,value:[],observer:"_selectedItemsChanged"},activeItem:{type:Object,notify:!0},loggedIn:{type:Boolean,value:!1,notify:!0,reflectToAttribute:!0,observer:"_loggedInChanged"},editMode:{type:Boolean,notify:!0,reflectToAttribute:!0,value:!1,observer:"_editModeChanged"},hideCamera:{type:Boolean,value:!1},logoutPhoto:{type:String,value:!1}}}_userDataChanged(e){e.userName&&(this.title=e.userName+" sites"),e.userPicture&&(this.logoutPhoto=e.userPicture)}showSpecialButtons(e,t){return!e&&!!t}_selectedItemsChanged(e){e&&e.length>0?this.shadowRoot.querySelector("#ops").removeAttribute("hidden"):this.shadowRoot.querySelector("#ops").setAttribute("hidden","hidden")}_dataSourceChanged(e){e&&(this._dataSource=e+"?"+Math.floor(Date.now()/1e3))}_jwtLoggedIn(e){e.detail?this.loggedIn=!0:this.loggedIn=!1}_tokenRefreshFailed(e){this.jwt=null,this.loggedIn=!1,this.dispatchEvent(new CustomEvent("jwt-login-logout",{composed:!0,bubbles:!0,cancelable:!1,detail:{}}))}_editModeChanged(e){this.__editIcon=e?"icons:check":"icons:create"}_addTap(){this._resetNewSiteForm(),this.shadowRoot.querySelector("#createsite").opened=!0}_importTap(){this.shadowRoot.querySelector("#importurl").value="",this.shadowRoot.querySelector("#importsite").opened=!0}_loggedInChanged(e,t){void 0!==t&&(e?(document.body.setAttribute("data-logged-in","data-logged-in"),this.__loginText="Log out",this.__loginIcon="icons:account-circle",this.standardResponse("Welcome, log in successful!"),this.shadowRoot.querySelector("#add").hidden=!1):(document.body.removeAttribute("data-logged-in"),this.__loginText="Log in",this.__loginIcon="icons:power-settings-new",this.standardResponse("You logged out"),this.shadowRoot.querySelector("#add").hidden=!0))}_jwtChanged(e){if(e){if(this.__loginText="Log out",this.__loginIcon="icons:account-circle",this.__cameraBlob){let t=new File([this.__cameraBlob],"userPhoto"+Date.now()+".jpg");this.shadowRoot.querySelector("#fileupload").target=this.__setUserPhotoPath+"&jwt="+e,this.shadowRoot.querySelector("#fileupload")._addFile(t),this.shadowRoot.querySelector("#fileupload").uploadFiles()}setTimeout((()=>{this.set("getUserDataParams",{}),this.set("getUserDataParams",{jwt:e}),this.notifyPath("getUserDataParams.*"),this.shadowRoot.querySelector("#getuserdatarequest").generateRequest()}),500)}else this.__loginText="Log in",this.__loginIcon="icons:power-settings-new"}_editTap(e){this.editMode=!this.editMode}_settingsTap(e){this._loadConfig(),this.shadowRoot.querySelector("#settingsdialog").opened=!0}refreshData(e){this.shadowRoot.querySelector("#loaddata").generateRequest()}_gridSelectedItemsChanged(e){this.set("selectedItems",[]),this.set("selectedItems",this.shadowRoot.querySelector("#grid").selectedItems)}connectedCallback(){super.connectedCallback(),window.addEventListener("jwt-login-refresh-error",this._tokenRefreshFailed.bind(this)),window.addEventListener("jwt-token",this.updateJwt.bind(this)),navigator.mediaDevices||(this.shadowRoot.querySelector("#snap").style.display="none",this.shadowRoot.querySelector("#newsnap").style.display="none"),this.shadowRoot.querySelector("#fileupload").addEventListener("upload-response",this.handleSetUserPhotoResponse.bind(this)),this.jwt&&(this.loggedIn=!0),window.addEventListener("sites-listing-refresh-data",this.refreshData.bind(this)),setTimeout((()=>{if(document.head.createShadowRoot||document.head.attachShadow);else{console.warn("Shadow DOM missing, ALL YOUR IE R BELONG TO US"),console.warn("HAXCMS DOES NOT LOVE YOUR OLD BROWSER FOR EDITING JUST VIEWING"),console.warn("You get no authoring experience. Good day to you!");const e=new CustomEvent("simple-toast-show",{bubbles:!0,composed:!0,cancelable:!0,detail:{text:"WARNING: You are using a polyfilled browser. HAXcms requires modern browsers, please upgrade or switch to a modern browser to edit in HAXcms!",duration:1e4}});this.dispatchEvent(e)}this.hideCamera?(this.shadowRoot.querySelector("#newsnap").classList.add("hide-camera"),this.shadowRoot.querySelector("#snap").classList.add("hide-camera"),this.shadowRoot.querySelector("#camera").classList.add("hide-camera")):import("../../../../simple-login/lib/simple-login-camera.js"),this.addEventListener("simple-login-login",this.loginPromptEvent.bind(this)),this.shadowRoot.querySelector("#grid").addEventListener("selected-items-changed",this._gridSelectedItemsChanged.bind(this)),this.__loginPath=window.appSettings.login,this.__refreshPath=window.appSettings.refreshUrl,this.__logoutPath=window.appSettings.logout,this.__setConfigPath=window.appSettings.setConfigPath,this.__getUserDataPath=window.appSettings.getUserDataPath,this.__setUserPhotoPath=window.appSettings.setUserPhotoPath,this.__getConfigPath=window.appSettings.getConfigPath,this.__createNewSitePath=window.appSettings.createNewSitePath,this.__gitImportSitePath=window.appSettings.gitImportSitePath,this.__downloadSitePath=window.appSettings.downloadSitePath,this.__archiveSitePath=window.appSettings.archiveSitePath,this.__cloneSitePath=window.appSettings.cloneSitePath,this.__publishSitePath=window.appSettings.publishSitePath,this.__syncSitePath=window.appSettings.syncSitePath,this.__revertSitePath=window.appSettings.revertSitePath,this.__deleteSitePath=window.appSettings.deleteSitePath,window.appSettings.jwt&&this.set("jwt",window.appSettings.jwt),document.body.addEventListener("haxcms-load-site",this.loadActiveSite.bind(this)),this.permissionsListen(),this.shadowRoot.querySelector("#snap").addEventListener("click",(()=>{this.dispatchEvent(new CustomEvent("simple-login-camera-icon-click",{detail:this,bubbles:!0,composed:!0})),this.snapPhoto.bind(this)})),this.shadowRoot.querySelector("#newsnap").addEventListener("click",(()=>{this.dispatchEvent(new CustomEvent("simple-login-cancel-icon-click",{detail:this,bubbles:!0,composed:!0})),this.clearPhoto.bind(this)}))}),0)}permissionsListen(){window.addEventListener("simple-login-camera-icon-click",(async()=>{await this.snapPhoto()})),window.addEventListener("simple-login-cancel-icon-click",(async()=>{await this.clearPhoto()}))}async snapPhoto(e){const t=this.shadowRoot.querySelector("#camera");this.__cameraBlob=await t.takeASnap().then(t.imageBlob);let i=document.createElement("img");i.src=URL.createObjectURL(this.__cameraBlob),t.removeAttribute("autoplay");const o=this.shadowRoot.querySelector("#selfie");o.innerHTML="",o.appendChild(i),o.classList.add("has-snap")}clearPhoto(e){this.shadowRoot.querySelector("#camera").setAttribute("autoplay","autoplay");const t=this.shadowRoot.querySelector("#selfie");t.innerHTML="",t.classList.remove("has-snap")}loginPromptEvent(e){this._loginUserRoutine({u:e.detail.u,p:e.detail.p})}_logoutUserRoutine(){this.dispatchEvent(new CustomEvent("jwt-login-logout",{composed:!0,bubbles:!0,cancelable:!1,detail:{}}))}_loginUserRoutine(e){this.dispatchEvent(new CustomEvent("jwt-login-login",{composed:!0,bubbles:!0,cancelable:!1,detail:e}))}_resetNewSiteForm(){let e=[],t=null;for(var i in window.appSettings.themes)e[i]=window.appSettings.themes[i].name,t||(t=i);const o=this.shadowRoot.querySelector("#createsitefields");o.fields=[{property:"id",title:"id",description:"",inputMethod:"boolean",hidden:!0},{property:"manifest",inputMethod:"tabs",properties:[{property:"site",title:"Site details",properties:[{property:"name",title:"Site name",description:"This forms the folder name and metadata title for the site",inputMethod:"textfield",required:!0},{property:"theme",title:"Theme",description:"Design for presenting your new site",inputMethod:"select",allowNull:!1,options:e,required:!0},{property:"description",title:"Description (optional)",description:"Addition detail, for personal use as well as search engine optimization",inputMethod:"textfield"}]},{property:"theme",title:"Theme settings",properties:[{property:"icon",title:"Pick an icon.",description:"The icon is used in some designs areas to help you know what site your on",inputMethod:"iconpicker"},{property:"color",title:"Color",description:"Choose a primary color to tint the UI or be used in the theme",inputMethod:"colorpicker"}]}]}],o.value={id:!1,manifest:{site:{name:"",description:"",theme:t},theme:{color:"blue",icon:"icons:add-circle-outline"}}}}disconnectedCallback(){window.removeEventListener("jwt-login-refresh-error",this._tokenRefreshFailed.bind(this)),window.removeEventListener("jwt-token",this.updateJwt.bind(this)),window.removeEventListener("sites-listing-refresh-data",this.refreshData.bind(this)),document.body.removeEventListener("haxcms-load-site",this.loadActiveSite.bind(this)),this.removeEventListener("simple-login-login",this.loginPromptEvent.bind(this)),this.shadowRoot.querySelector("#snap").removeEventListener("click",this.snapPhoto.bind(this)),this.shadowRoot.querySelector("#newsnap").removeEventListener("click",this.clearPhoto.bind(this)),this.shadowRoot.querySelector("#grid").removeEventListener("selected-items-changed",this._gridSelectedItemsChanged.bind(this)),this.shadowRoot.querySelector("#jwt").removeEventListener("jwt-logged-in",this._jwtLoggedIn.bind(this)),super.disconnectedCallback()}ready(){super.ready(),this.shadowRoot.querySelector("#jwt").addEventListener("jwt-logged-in",this._jwtLoggedIn.bind(this)),setTimeout((()=>{this.shadowRoot.querySelector('[modal-id="help"]').associateEvents(this.shadowRoot.querySelector("#help"))}),0),window.JSONOutlineSchema.requestAvailability(),window.SimpleModal.requestAvailability(),window.SimpleToast.requestAvailability();this.shadowRoot.querySelector("jos-render").map={tag:"course-card",path:"@lrnwebcomponents/product-card/lib/course-card.js",properties:{number:"title",name:function(e){return e.slug?e.slug.replace("/_sites/","").replace("/sites/","").replace("/",""):""},zoom:!0,url:"location",image:function(e){return e.metadata.site&&e.metadata.site.logo?e.slug+e.metadata.site.logo.replace(" ","%20"):e.slug+"assets/banner.jpg"},icon:function(e){return e.metadata.theme&&e.metadata.theme.variables&&e.metadata.theme.variables.icon?e.metadata.theme.variables.icon:"icons:android"},author:function(e){return e.metadata.author&&e.metadata.author.name?e.metadata.author.name:""},accentColor:function(e){return e.metadata.theme&&e.metadata.theme.variables&&e.metadata.theme.variables.cssVariable?e.metadata.theme.variables.cssVariable.replace("--simple-colors-default-theme-","").replace("-7",""):""},size:"small",dark:!0,alt:function(e){return"Select to access "+e.title}}}}loadActiveSite(e){let t=this.sites.filter((t=>t.id===e.detail.id)).pop();t.slug?window.open(t.slug):window.open(this.basePath+"_sites/"+t.metadata.site.name+"/")}_gitImportSite(e){let t=Object.assign({jwt:this.jwt,site:{git:{url:this.shadowRoot.querySelector("#importurl").value}}});this.set("gitImportParams",{}),this.set("gitImportParams",t),this.notifyPath("gitImportParams.*"),this.shadowRoot.querySelector("#gitimportrequest").generateRequest()}_createSite(e){let t=Object.assign({jwt:this.jwt},this.shadowRoot.querySelector("#createsitefields").value.manifest);this.set("createParams",{}),this.set("createParams",t),this.notifyPath("createParams.*"),this.shadowRoot.querySelector("#createrequest").generateRequest()}async _downloadSites(e){for(var t in this.set("downloadParams",{}),this.set("downloadParams",{jwt:this.jwt,site:{}}),this.notifyPath("downloadParams.*"),this.selectedItems)this.set("activeItem",{}),this.set("activeItem",this.selectedItems[t]),this.set("downloadParams.site.name",this.selectedItems[t].metadata.site.name),this.notifyPath("downloadParams.site.name"),await this.shadowRoot.querySelector("#downloadrequest").generateRequest()}async _archiveSites(e){for(var t in this.set("archiveParams",{}),this.set("archiveParams",{jwt:this.jwt,site:{}}),this.notifyPath("archiveParams.*"),this.selectedItems)this.set("activeItem",{}),this.set("activeItem",this.selectedItems[t]),this.set("archiveParams.site.name",this.selectedItems[t].metadata.site.name),this.notifyPath("archiveParams.site.name"),await this.shadowRoot.querySelector("#archiverequest").generateRequest()}_bulkSitesConfirm(e){let t,i=s(e);for(;!t&&i&&i.length>0;)i[0].getAttribute("data-op")&&(t=i[0].getAttribute("data-op")),i.shift();this.activeOpertion=t,this.shadowRoot.querySelector("#confirm").opened=!0}async _confirmBulkOperation(e){await this["_"+this.activeOpertion+"Sites"](),this.activeOpertion="",this.shadowRoot.querySelector("#grid").set("selectedItems",[])}async _deleteSites(e){for(var t in this.set("deleteParams",{}),this.set("deleteParams",{jwt:this.jwt,site:{}}),this.notifyPath("deleteParams.*"),this.selectedItems)this.set("activeItem",{}),this.set("activeItem",this.selectedItems[t]),this.set("deleteParams.site.name",this.selectedItems[t].metadata.site.name),this.notifyPath("deleteParams.site.name"),await this.shadowRoot.querySelector("#deleterequest").generateRequest()}async _cloneSites(e){for(var t in this.set("cloneParams",{}),this.set("cloneParams",{jwt:this.jwt,site:{}}),this.notifyPath("cloneParams.*"),this.selectedItems)this.set("activeItem",{}),this.set("activeItem",this.selectedItems[t]),this.set("cloneParams.site.name",this.selectedItems[t].metadata.site.name),this.notifyPath("cloneParams.site.name"),await this.shadowRoot.querySelector("#clonerequest").generateRequest()}async _publishSites(e){for(var t in this.set("publishParams",{}),this.set("publishParams",{jwt:this.jwt,site:{}}),this.notifyPath("publishParams.*"),this.selectedItems)this.set("activeItem",{}),this.set("activeItem",this.selectedItems[t]),this.set("publishParams.site.name",this.selectedItems[t].metadata.site.name),this.notifyPath("publishParams.site.name"),await this.shadowRoot.querySelector("#publishrequest").generateRequest()}async _syncSites(e){for(var t in this.set("syncParams",{}),this.set("syncParams",{jwt:this.jwt,site:{}}),this.notifyPath("syncParams.*"),this.selectedItems)this.set("activeItem",{}),this.set("activeItem",this.selectedItems[t]),this.set("syncParams.site.name",this.selectedItems[t].metadata.site.name),this.notifyPath("syncParams.site.name"),await this.shadowRoot.querySelector("#syncrequest").generateRequest()}_loadConfig(){this.set("configParams",{}),this.set("configParams",{jwt:this.jwt,token:this.createParams.token}),this.notifyPath("configParams.*"),this.shadowRoot.querySelector("#getconfigrequest").generateRequest()}_saveConfig(e){window.HAXCMS.config.values=this.shadowRoot.querySelector("#settingsform").value,this.set("setConfigParams",{}),this.set("setConfigParams",{jwt:this.jwt,token:this.createParams.token,values:window.HAXCMS.config.values}),this.notifyPath("setConfigParams.*"),this.shadowRoot.querySelector("#setconfigrequest").generateRequest()}standardResponse(e,t=!0){t&&this.dispatchEvent(new CustomEvent("sites-listing-refresh-data",{bubbles:!0,composed:!0,cancelable:!1,detail:!0})),this.dispatchEvent(new CustomEvent("simple-toast-show",{bubbles:!0,composed:!0,cancelable:!0,detail:{text:e,duration:2e3}}))}handleCreateResponse(e){this._dataSource=this.dataSource+"?"+Math.floor(Date.now()/1e3),this.standardResponse(e.detail.response.title+" created!")}handleGitImportResponse(e){this._dataSource=this.dataSource+"?"+Math.floor(Date.now()/1e3),this.standardResponse(e.detail.response.title+" imported!")}handleConfigResponse(e){window.HAXCMS.config=e.detail.response,this.shadowRoot.querySelector("#settingsform").schema={},this.shadowRoot.querySelector("#settingsform").schema=window.HAXCMS.config.schema,this.shadowRoot.querySelector("#settingsform").value={},this.shadowRoot.querySelector("#settingsform").value=window.HAXCMS.config.values,window.dispatchEvent(new Event("resize"))}handleSetConfigResponse(e){this.shadowRoot.querySelector("#settingsdialog").opened=!1,this.standardResponse("HAXCMS configuration updated!")}handleGetUserDataResponse(e){this.userData=e.detail.response.data}handleSetUserPhotoResponse(e){delete this.__cameraBlob,this.standardResponse("User photo saved!",!1)}handleDownloadResponse(e){let t=document.createElement("a");t.setAttribute("href",e.detail.response.link),t.style.display="none",document.body.appendChild(t),t.click(),document.body.removeChild(t),this.standardResponse(this.activeItem.title+" downloaded!")}handleArchiveResponse(e){this.standardResponse(this.activeItem.title+" archived!")}handleDeleteResponse(e){this.standardResponse(this.activeItem.title+" deleted!")}handleCloneResponse(e){this.standardResponse(this.activeItem.title+" cloned!")}handlePublishResponse(e){this.standardResponse(this.activeItem.title+" published!")}handleSyncResponse(e){this.standardResponse(this.activeItem.title+" published!")}lastErrorChanged(e){if(e.detail.value){var t=s(e)[0];switch(parseInt(e.detail.value.status)){case 401:this.dispatchEvent(new CustomEvent("jwt-login-logout",{composed:!0,bubbles:!0,cancelable:!1,detail:{redirect:!0}}));break;case 403:this.dispatchEvent(new CustomEvent("jwt-login-refresh-token",{composed:!0,bubbles:!0,cancelable:!1,detail:{element:{obj:this,callback:"refreshRequest",params:[t]}}}));break;default:console.error(e);const i=new CustomEvent("simple-toast-show",{bubbles:!0,composed:!0,cancelable:!0,detail:{text:e.detail.value.status+" "+e.detail.value.statusText}});window.dispatchEvent(i)}}}updateJwt(e){this.jwt=e.detail}refreshRequest(e,t){this.jwt=e,t.body.jwt=e,setTimeout((()=>{t.generateRequest()}),0)}}window.customElements.define(HAXCMSSiteListing.tag,HAXCMSSiteListing);export{HAXCMSSiteListing};