var __decorate=this&&this.__decorate||function(e,t,r,o){var n,i=arguments.length,s=i<3?t:null===o?o=Object.getOwnPropertyDescriptor(t,r):o;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(e,t,r,o);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(s=(i<3?n(s):i>3?n(t,r,s):n(t,r))||s);return i>3&&s&&Object.defineProperty(t,r,s),s};import{InputType as e}from"@openremote/or-mwc-components/or-mwc-input";import{getContentWithMenuTemplate as t}from"@openremote/or-mwc-components/or-mwc-menu";import{html as r,LitElement as o}from"lit";import{customElement as n,property as i}from"lit/decorators.js";import{when as s}from"lit/directives/when.js";import{i18next as a}from"@openremote/or-translate";export function intervalToMillis(e){switch(e){case"OFF":default:return;case"ONE_MIN":return 6e4;case"FIVE_MIN":return 3e5;case"QUARTER":return 9e5;case"ONE_HOUR":return 36e5}}export class IntervalSelectEvent extends CustomEvent{constructor(e){super(IntervalSelectEvent.NAME,{bubbles:!0,composed:!0,detail:e})}}IntervalSelectEvent.NAME="interval-select";let DashboardRefreshControls=class extends o{constructor(){super(...arguments),this.interval="OFF",this.readonly=!0,this.intervalOptions=["OFF","ONE_MIN","FIVE_MIN","QUARTER","ONE_HOUR"]}willUpdate(e){super.willUpdate(e),e.has("interval")&&void 0!==this.interval&&this.dispatchEvent(new IntervalSelectEvent(this.interval))}render(){let o=this.getRefreshOptions(),n=this.getIntervalString(this.interval);return r`
            <div style="height: 100%; display: flex; align-items: center;">
                ${s(this.readonly,()=>r`
                    ${s("OFF"===this.interval,()=>r`
                        <or-mwc-input .type="${e.BUTTON}" icon="pause" disabled="true" title="${a.t("dashboard.interval.off")}" style="height: 36px; margin-top: -12px;"></or-mwc-input>
                    `,()=>r`
                        <or-mwc-input .type="${e.BUTTON}" label="${n}" disabled="true" title="${a.t("dashboard.refreshInterval")}"></or-mwc-input>
                    `)}
                `,()=>r`
                    ${t("OFF"===this.interval?r`
                                <or-mwc-input .type="${e.BUTTON}" icon="pause" title="${a.t("dashboard.interval.off")}" style="height: 36px; margin-top: -12px;"></or-mwc-input>
                            `:r`
                                <or-mwc-input .type="${e.BUTTON}" label="${n}" title="${a.t("dashboard.refreshInterval")}"></or-mwc-input>
                            `,o.map(e=>({value:e})),n,e=>this.onIntervalSelect(o,e),void 0,!1,!0,!0)}
                `)}
            </div>
        `}onIntervalSelect(e,t){this.interval=this.intervalOptions[e.indexOf(t)]}getIntervalString(e){return`dashboard.interval.${e.toLowerCase()}`}getRefreshOptions(){return this.intervalOptions.map(e=>this.getIntervalString(e))}};__decorate([i()],DashboardRefreshControls.prototype,"interval",void 0),__decorate([i()],DashboardRefreshControls.prototype,"readonly",void 0),DashboardRefreshControls=__decorate([n("dashboard-refresh-controls")],DashboardRefreshControls);export{DashboardRefreshControls};