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