"use strict";(self.webpackChunk_aidoop_aidoop_r=self.webpackChunk_aidoop_aidoop_r||[]).push([[4999],{24999:(e,t,i)=>{i.r(t),i.d(t,{DomainManagement:()=>$});var a=i(50493),o=i(62392),n=(i(49005),i(68677),i(14410),i(94430)),r=i(56765),d=i(15633);let s=class extends n.oi{render(){var e,t;return n.dy`<form>
      <h2>${(null===(e=this.attributeSet)||void 0===e?void 0:e.entity)||""}</h2>
      <h3>${(null===(t=this.attributeSet)||void 0===t?void 0:t.description)||""}</h3>
      ${this.buildEntryViews()}
    </form> `}buildEntryViews(){var e;return(((null===(e=this.attributeSet)||void 0===e?void 0:e.items)||[]).filter((e=>e.active))||[]).map((e=>{const{name:t,description:i,tag:a,type:o,options:r={}}=e,d=this.value&&this.value[a];switch(o){case"select":var s=n.dy` <select .name=${a} disabled>
            <option value=""></option>
            ${(r.options||[]).map((e=>n.dy`<option value=${e.value} ?selected=${e.value===d}>${e.text}</option>`))}
          </select>`;break;case"boolean":s=n.dy` <input type="checkbox" name=${a} .checked=${d} disabled />`;break;case"number":s=n.dy` <input type="number" name=${a} value=${d} disabled />`;break;case"file":s=n.dy`<ox-input-file
            name=${a}
            label="Attach Files"
            accept="*/*"
            multiple="true"
            hide-filelist
            disabled
          ></ox-input-file>`;default:s=n.dy` <input type="text" name=${a} value=${d} disabled />`}return n.dy` <label .title=${i}>
        <div name>${t}</div>
        <div description><mwc-icon>info_outline</mwc-icon> ${i}</div>
        <div elements>${s}</div>
      </label>`}))}};s.styles=[d.Ix,n.iv`
      :host {
        display: flex;
        flex-direction: row;

        --item-description-font: normal 0.8rem/1rem var(--theme-font);
        --item-description-color: var(--page-description-color);
      }

      h2 {
        margin: var(--title-margin);
        font: var(--title-font);
        color: var(--title-text-color);
        text-transform: capitalize;
        text-align: center;
      }

      h3 {
        margin: var(--page-description-margin);
        font: var(--page-description-font);
        color: var(--page-description-color);
        text-transform: capitalize;
        text-align: center;
      }

      form {
        flex: 1;

        display: flex;
        flex-direction: column;

        overflow-y: auto;
        padding: var(--padding-default);
      }

      label {
        display: grid;

        grid-template-rows: auto 1fr;
        grid-template-columns: 1fr 5fr;
        grid-template-areas: 'name description' 'empty inputs';

        grid-gap: 9px;
        align-items: center;
        margin-bottom: var(--margin-default);
      }

      label:nth-child(odd) {
        background-color: var(--main-section-background-color);
        padding: var(--padding-default) 0;
      }

      div[name] {
        grid-area: name;
        font: var(--label-font);
        color: var(--label-color);
        text-align: right;
      }

      div[description] {
        grid-area: description;
        opacity: 0.7;
        font: var(--item-description-font);
        color: var(--item-description-color);
        text-align: left;
      }

      div[description] * {
        vertical-align: middle;
      }

      div[description] mwc-icon {
        margin-top: -3px;
        font-size: 0.9rem;
      }

      div[elements] {
        grid-area: inputs;
        display: flex;
        flex-direction: row;
        flex-wrap: wrap;
        gap: 10px;
        padding-right: var(--padding-default);
      }

      div[elements] * {
        flex: 1;
      }

      div[elements] input,
      div[elements] select {
        border: var(--input-field-border);
        border-radius: var(--input-field-border-radius);
        padding: var(--input-field-padding);
        font: var(--input-field-font);
      }

      @media only screen and (max-width: 460px) {
        label {
          display: grid;

          grid-template-rows: auto auto 1fr;
          grid-template-columns: 1fr;
          grid-template-areas: 'name' 'description' 'inputs';

          grid-gap: 9px;
          align-items: center;
          margin-bottom: var(--margin-default);
        }

        div[name] {
          text-align: left;
        }
      }
    `],(0,a.gn)([(0,r.Cb)({type:Object})],s.prototype,"attributeSet",void 0),(0,a.gn)([(0,r.Cb)({type:Object})],s.prototype,"value",void 0),s=(0,a.gn)([(0,r.Mo)("ox-attribute-view")],s);i(39663);var l=i(16682),c=i(27805),m=i(53421),p=i(80692);let u=class extends((0,m.NC)(m.z2)(n.oi)){render(){return n.dy`
      <div field grid-span>
        <label
          >${m.z2.t("label.x name",{x:m.z2.t("label.domain")})}<input
            type="text"
            name="name"
            @input=${this.checkValidation}
            autofocus
        /></label>
      </div>

      <div field grid-span>
        <label>${m.z2.t("label.description")}<input type="text" name="description" /></label>
      </div>

      <div buttons>
        <mwc-button raised @click=${e=>this.onCreateDomain()}>${m.z2.t("button.create")}</mwc-button>
      </div>
    `}firstUpdated(){this.nameInput.focus()}get inputData(){return this.renderRoot.querySelectorAll("input")}checkValidation(e){const t=e.currentTarget;/^[a-zA-Z ]+$/.test(t.value)?t.classList.remove("checkValidName"):t.classList.add("checkValidName")}async onCreateDomain(){const e={};this.inputData.forEach((t=>e[t.name]=t.value));if(!/^[a-zA-z0-9- ]+$/.test(e.name))return this.showToast(m.z2.t("error: domain name should consist only of letters or dashes"));(await c.Lp.mutate({mutation:l.ZP`
        mutation domainRegister($domainInput: DomainGeneratorInput!) {
          domainRegister(domainInput: $domainInput) {
            id
            name
          }
        }
      `,variables:{domainInput:e}})).errors||(await(0,p.ID)({type:"success",title:m.z2.t("text.completed"),text:m.z2.t("text.x_created_successfully",{x:m.z2.t("label.domain")}),confirmButton:{text:m.z2.t("button.confirm")}}),history.back(),this.dispatchEvent(new CustomEvent("fetch-data")))}showToast(e){document.dispatchEvent(new CustomEvent("notify",{detail:{message:e}}))}};u.styles=[n.iv`
      :host {
        display: flex;
        flex-direction: column;
        background-color: var(--main-section-background-color);
        padding: var(--padding-wide);
        overflow: auto;
      }
      input.checkValidName {
        background-color: #fce6e6;
      }
      mwc-button {
        display: flex;
        justify-content: center;
      }
      label {
        display: flex;
        flex-direction: column;

        font: var(--label-font);
        color: var(--label-color);
        text-transform: var(--label-text-transform);
      }
      input {
        border: var(--border-dark-color);
        border-radius: var(--border-radius);
        margin: var(--input-margin);
        padding: var(--input-padding);
        background-color: var(--theme-white-color);
        font: var(--input-font);

        flex: 1;
      }
      [field] {
        grid-column: span 2;
      }
      [buttons] {
        margin-top: auto;
      }
    `],(0,a.gn)([(0,r.IO)('input[name="name"]'),(0,a.w6)("design:type",HTMLInputElement)],u.prototype,"nameInput",void 0),u=(0,a.gn)([(0,r.Mo)("create-domain-popup")],u);var h=i(50383),f=i.n(h),g=i(28120),v=i(37077),b=i(77675),y=i(36179);const w=Intl.DateTimeFormat().resolvedOptions().timeZone,x=["",w,...f().tz.names().filter((e=>e!==w))];let $=class extends((0,g.$)(b.h)((0,m.NC)(m.z2)(b.B4))){constructor(){super(...arguments),this.active=!1,this.mode=(0,y.s2)()?"CARD":"GRID"}get context(){var e;return{title:m.z2.t("text.domain management"),search:{handler:e=>{this.grist.searchText=e},value:(null===(e=this.grist)||void 0===e?void 0:e.searchText)||""},filter:{handler:()=>{this.grist.toggleHeadroom()}},actions:[Object.assign({title:m.z2.t("button.save"),action:this.onUpdateDomains.bind(this)},d.jO.save)]}}render(){return n.dy`
      <ox-grist .mode=${this.mode} .config=${this.config} .fetchHandler=${this.fetchHandler.bind(this)}>
        <div slot="headroom">
          <div id="filters">
            <ox-filters-form autofocus without-search></ox-filters-form>
          </div>

          <div id="sorters">
            Sort
            <mwc-icon
              @click=${e=>{const t=e.currentTarget;this.renderRoot.querySelector("#sorter-control").open({right:0,top:t.offsetTop+t.offsetHeight})}}
              >expand_more</mwc-icon
            >
            <ox-popup id="sorter-control">
              <ox-sorters-control> </ox-sorters-control>
            </ox-popup>
          </div>

          <div id="modes">
            <mwc-icon @click=${()=>this.mode="GRID"} ?active=${"GRID"==this.mode}>grid_on</mwc-icon>
            <mwc-icon @click=${()=>this.mode="LIST"} ?active=${"LIST"==this.mode}
              >format_list_bulleted</mwc-icon
            >
            <mwc-icon @click=${()=>this.mode="CARD"} ?active=${"CARD"==this.mode}>apps</mwc-icon>
          </div>

          <div id="add">
            <button><mwc-icon @click=${this.onCreateDomain.bind(this)}>add</mwc-icon></button>
          </div>
        </div>
      </ox-grist>
    `}async pageInitialized(){this.config={rows:{appendable:!1},columns:[{type:"gutter",gutterName:"sequence"},{type:"gutter",gutterName:"button",icon:"assignment",title:m.z2.t("title.open attributes view"),handlers:{click:async(e,t,i,a,o)=>{const r=await this.getAttributeSetForDomain();(0,v.Mw)(n.dy`
                  <ox-attribute-view
                    .attributeSet=${r}
                    .value=${a.attributes}
                    style="background-color: white;"
                  ></ox-attribute-view>
                `,{backdrop:!0,size:"large",title:a.name+" "+m.z2.t("title.attributes")})}}},{type:"gutter",gutterName:"button",icon:"domain",title:m.z2.t("title.move to this domain"),handlers:{click:(e,t,i,a,o)=>{if(a.id){const e=a.subdomain;location.pathname=`/domain/${e}/users`}}}},{type:"string",name:"name",header:m.z2.t("field.name"),record:{editable:!1},filter:"search",sortable:!0,width:200},{type:"string",name:"description",header:m.z2.t("field.description"),record:{editable:!0},filter:"search",width:200},{type:"string",name:"subdomain",header:m.z2.t("field.subdomain"),record:{editable:!1},filter:"search",width:200},{type:"resource-object",name:"parent",header:m.z2.t("field.parent-domain"),record:{editable:!0,options:{title:m.z2.t("text.select domain"),queryName:"domains",nameField:"name",descriptionField:"description",select:[{name:"id",hidden:!0},{name:"name",header:m.z2.t("field.name"),filter:"search"},{name:"description",header:m.z2.t("field.description"),filter:"search"}],list:{fields:["name","description"]}}},width:140},{type:"resource-object",name:"ownerUser",header:m.z2.t("field.owner-user"),record:{editable:!0,options:{title:m.z2.t("title.lookup user"),queryName:"users",nameField:"name",descriptionField:"email",select:[{name:"id",hidden:!0},{name:"name",header:m.z2.t("field.name"),filter:"search"},{name:"email",header:m.z2.t("field.email"),filter:"search"}],filters:[{name:"userType",operator:"eq",value:"user"}],list:{fields:["name","email"]}}},width:140},{type:"select",name:"extType",header:m.z2.t("field.type"),record:{editable:!0,options:[]},width:70},{type:"select",name:"timezone",header:m.z2.t("field.timezone"),record:{editable:!0,options:x},width:120},{type:"attributes",name:"attributes",header:m.z2.t("field.attributes"),record:{editable:!0,options:async()=>({objectified:!0,attributeSet:await this.getAttributeSetForDomain()})},width:120},{type:"datetime",name:"updatedAt",header:m.z2.t("field.updated_at"),width:180}]},await this.updateComplete,this.grist.fetch()}async pageUpdated(e,t){this.active&&(await this.updateComplete,this.grist.fetch())}async fetchHandler({page:e,limit:t,sortings:i=[],filters:a=[]}){const o=await c.Lp.query({query:l.ZP`
        query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
          domains(filters: $filters, pagination: $pagination, sortings: $sortings) {
            items {
              id
              name
              description
              subdomain
              parent {
                id
                name
              }
              ownerUser {
                id
                name
                email
              }
              extType
              timezone
              attributes
              updatedAt
            }
            total
          }
        }
      `,variables:{filters:a,pagination:{page:e,limit:t},sortings:i}});return{total:o.data.domains.total||0,records:o.data.domains.items||[]}}async onUpdateDomains(){let e=this.grist.dirtyRecords;if(e&&e.length){e=e.map((e=>{let t=e.id?{id:e.id}:{};const i=e.__dirtyfields__;for(let e in i)if("ownerUser"==e){const a=i[e].after;t.owner=a.id||""}else t[e]=i[e].after;return Object.assign({},t)}));if(!(await c.Lp.mutate({mutation:l.ZP`
          mutation updateDomains($patches: [DomainPatch!]!) {
            updateDomains(patches: $patches)
          }
        `,variables:{patches:e}})).errors)return this.grist.fetch(),this.showToast(m.z2.t("text.updated_successfully"))}}async onCreateDomain(){(0,v.Mw)(n.dy`
        <create-domain-popup
          @fetch-data=${async()=>{this.grist.fetch()}}
        ></create-domain-popup>
      `,{size:"small",title:`${m.z2.t("title.create_domain")}`})}async getAttributeSetForDomain(){var e;return(null===(e=(await c.Lp.query({query:l.ZP`
        query {
          attributeSet: attributeSetByEntity(entity: "Domain") {
            entity
            description
            items {
              name
              description
              tag
              type
              active
              hidden
              options
            }
          }
        }
      `})).data)||void 0===e?void 0:e.attributeSet)||{}}showToast(e){document.dispatchEvent(new CustomEvent("notify",{detail:{message:e}}))}};$.styles=[d.Pn,d.Ix,n.iv`
      :host {
        display: flex;
        flex-direction: column;

        overflow: hidden;
      }
    `],(0,a.gn)([(0,r.Cb)({type:Boolean}),(0,a.w6)("design:type",Boolean)],$.prototype,"active",void 0),(0,a.gn)([(0,r.Cb)({type:Object}),(0,a.w6)("design:type",Object)],$.prototype,"config",void 0),(0,a.gn)([(0,r.Cb)({type:String}),(0,a.w6)("design:type",String)],$.prototype,"mode",void 0),(0,a.gn)([(0,r.IO)("ox-grist"),(0,a.w6)("design:type",o.N)],$.prototype,"grist",void 0),$=(0,a.gn)([(0,r.Mo)("domain-management")],$)}}]);