var __decorate=this&&this.__decorate||function(t,e,i,n){var a,s=arguments.length,o=s<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(t,e,i,n);else for(var r=t.length-1;r>=0;r--)(a=t[r])&&(o=(s<3?a(o):s>3?a(e,i,o):a(e,i))||o);return s>3&&o&&Object.defineProperty(e,i,o),o},__awaiter=this&&this.__awaiter||function(t,e,i,n){return new(i||(i=Promise))(function(a,s){function o(t){try{l(n.next(t))}catch(t){s(t)}}function r(t){try{l(n.throw(t))}catch(t){s(t)}}function l(t){var e;t.done?a(t.value):((e=t.value)instanceof i?e:new i(function(t){t(e)})).then(o,r)}l((n=n.apply(t,e||[])).next())})};import{customElement as t}from"lit/decorators.js";import{WidgetSettings as e}from"../util/widget-settings";import{html as i}from"lit";import{InputType as n}from"@openremote/or-mwc-components/or-mwc-input";import{i18next as a}from"@openremote/or-translate";import{Task as s}from"@lit/task";import o from"@openremote/core";let GatewaySettings=class extends e{constructor(){super(...arguments),this.GATEWAY_ASSET_TYPES=["GatewayAsset"],this.GATEWAY_TUNNEL_TYPES=["HTTPS","HTTP","TCP"],this._fetchAssetsTask=new s(this,{task:(t,e)=>__awaiter(this,[t,e],void 0,function*([],{signal:t}){return yield this._fetchAssets(!0,t)}),args:()=>[]})}connectedCallback(){super.connectedCallback()}render(){let t=!this.widgetConfig.gatewayId;return i`
            <div>
                <settings-panel displayName="gatewayTunnels.settings" expanded="${!0}">
                    <div style="display: flex; flex-direction: column; gap: 8px;">
                        <div>
                            ${this._fetchAssetsTask.render({pending:()=>i`
                                    <or-mwc-input .type="${n.SELECT}" compact style="width: 100%;" disabled
                                                  label="${a.t("gatewayTunnels.selectAsset")}"
                                    ></or-mwc-input>
                                `,complete:t=>{let e=t.map(t=>[t.id,t.name]),s=t.find(t=>t.id===this.widgetConfig.gatewayId),o=s?[s.id,s.name]:void 0;return i`
                                        <or-mwc-input .type="${n.SELECT}" compact style="width: 100%;"
                                                      .options="${e}" .value="${o}"
                                                      label="${a.t("gatewayTunnels.selectAsset")}"
                                                      @or-mwc-input-changed="${t=>this._onAssetSelect(t)}"
                                        ></or-mwc-input>
                                    `},error:()=>i`
                                    <or-mwc-input .type="${n.TEXT}" compact style="width: 100%;" disabled
                                                  label="${a.t("gatewayTunnels.selectAsset")}" .value="${a.t("errorOccurred")}"
                                    ></or-mwc-input>
                                `})}
                        </div>
                        <div>
                            <or-mwc-input .type="${n.SELECT}" compact style="width: 100%;"
                                          .disabled="${t}" .options="${this.GATEWAY_TUNNEL_TYPES}" .value="${this.widgetConfig.type}"
                                          label="${a.t("gatewayTunnels.protocol")}"
                                          @or-mwc-input-changed="${t=>this._onTunnelTypeSelect(t)}"
                            ></or-mwc-input>
                        </div>
                        <div>
                            <or-mwc-input .type="${n.TEXT}" style="width: 100%;"
                                          .disabled="${t}" .value="${this.widgetConfig.target}"
                                          label="${a.t("gatewayTunnels.target")}"
                                          @or-mwc-input-changed="${t=>this._onTunnelTargetSelect(t)}"
                            ></or-mwc-input>
                        </div>
                        <div>
                            <or-mwc-input .type="${n.NUMBER}" style="width: 100%;"
                                          .disabled="${t}" .value="${this.widgetConfig.targetPort}"
                                          label="${a.t("gatewayTunnels.targetPort")}"
                                          @or-mwc-input-changed="${t=>this._onTunnelTargetPortSelect(t)}"
                            ></or-mwc-input>
                        </div>
                    </div>
                </settings-panel>
            </div>
        `}_onAssetSelect(t){this.widgetConfig.gatewayId=t.detail.value,this.widgetConfig.attributeRefs=[{id:t.detail.value,name:void 0}],this.notifyConfigUpdate()}_onTunnelTypeSelect(t){this.widgetConfig.type=t.detail.value,this.notifyConfigUpdate()}_onTunnelTargetSelect(t){this.widgetConfig.target=t.detail.value,this.notifyConfigUpdate()}_onTunnelTargetPortSelect(t){this.widgetConfig.targetPort=t.detail.value,this.notifyConfigUpdate()}_fetchAssets(){return __awaiter(this,arguments,void 0,function*(t=!0,e){let i={realm:{name:o.displayRealm},select:{attributes:["tunnelingSupported"]},types:this.GATEWAY_ASSET_TYPES,attributes:t?{items:[{name:{predicateType:"string",value:"tunnelingSupported"},value:{predicateType:"boolean",value:!0}},{name:{predicateType:"string",value:"gatewayStatus"},value:{predicateType:"string",value:"CONNECTED"}}]}:void 0};return(yield o.rest.api.AssetResource.queryAssets(i)).data})}};GatewaySettings=__decorate([t("gateway-settings")],GatewaySettings);export{GatewaySettings};