import{LitElement as e,html as t,css as s}from"lit";import{classMap as a}from"lit/directives/class-map.js";import{createRef as i,ref as o}from"lit/directives/ref.js";import{iconRemixFullscreenExitLine as l,iconRemixFullscreenLine as r}from"./assets/cc-remix.icons.js";import{i18n as n}from"./translation.js";import"./cc-loader.js";import"./cc-logs-control.js";import"./cc-logs-date-range-selector.js";import"./cc-logs-instances.js";import{buildLogsLoadingProgressState as c}from"./cc-logs-loading-progress-state-builder.js";import"./cc-logs-loading-progress.js";import"./cc-logs-message-filter.js";import"./cc-notice.js";class g extends e{static get properties(){return{dateRangeSelection:{type:Object,attribute:"date-range-selection"},limit:{type:Number},options:{type:Object},state:{type:Object},_fullscreen:{type:Boolean,state:!0},_messageFilter:{type:Object,state:!0}}}constructor(){super(),this.dateRangeSelection={type:"live"},this.limit=1e3,this.options={"date-display":"datetime-iso","metadata-display":{instance:!1},palette:"default","strip-ansi":!1,timezone:"UTC","wrap-lines":!1},this.state={type:"loaded",streamState:{type:"idle"}},this._logsRef=i(),this._messageFilter={value:"",mode:"loose"},this._fullscreen=!1}appendLogs(e){this._logsRef.value?.appendLogs(e)}clear(){this._logsRef.value?.clear()}_onDateRangeSelectionChange(e){this.dateRangeSelection=e.detail.selection}_onFullscreenToggle(){this._fullscreen=!this._fullscreen}_onMessageFilterChange({detail:e}){this._messageFilter=e}render(){const e={fullscreen:this._fullscreen};return t`
      <div class="overlay ${a(e)}">
        <div class="wrapper ${a(e)}">
          <div class="logs-wrapper">${this._renderLogs()}</div>
          ${this._renderLoadingProgress()}
        </div>
      </div>
    `}_renderLoadingProgress(){const e=c(this.state.streamState);return null==e?null:t`<cc-logs-loading-progress-beta
      class="progress"
      .state=${e}
      limit=${this.limit}
    ></cc-logs-loading-progress-beta>`}_renderLogs(){return"loaded"===this.state.type&&"error"===this.state.streamState.type?t`
        <div class="center-logs-wrapper">
          <cc-notice slot="header" intent="warning" message=${n("cc-logs-addon-runtime.logs.error")}></cc-notice>
        </div>
      `:t`
      <cc-logs-control-beta
        ${o(this._logsRef)}
        class="logs"
        follow
        limit="${this.limit}"
        .dateDisplay=${this.options["date-display"]}
        .messageFilter=${this._messageFilter.value}
        .messageFilterMode=${this._messageFilter.mode}
        .palette=${this.options.palette}
        .stripAnsi=${this.options["strip-ansi"]}
        .timezone=${this.options.timezone}
        .wrapLines=${this.options["wrap-lines"]}
      >
        <div slot="header" class="logs-header">
          <cc-logs-date-range-selector-beta
            .value=${this.dateRangeSelection}
            @cc-logs-date-range-selection-change=${this._onDateRangeSelectionChange}
          ></cc-logs-date-range-selector-beta>

          <cc-logs-message-filter-beta
            class="logs-message-filter"
            .filter=${this._messageFilter}
            @cc-logs-message-filter-change=${this._onMessageFilterChange}
          ></cc-logs-message-filter-beta>

          <cc-button
            class="header-fullscreen-button"
            .icon=${this._fullscreen?l:r}
            a11y-name=${this._fullscreen?n("cc-logs-addon-runtime.fullscreen.exit"):n("cc-logs-addon-runtime.fullscreen")}
            hide-text
            @cc-click=${this._onFullscreenToggle}
          ></cc-button>
        </div>
      </cc-logs-control-beta>

      ${"loaded"===this.state.type&&"completed"===this.state.streamState.type&&0===this.state.streamState.progress.value?t`
            <div class="overlay-logs-wrapper">
              <cc-notice
                intent="info"
                heading=${n("cc-logs-addon-runtime.logs.warning.no-logs.title")}
                message=${n("cc-logs-addon-runtime.logs.warning.no-logs.message")}
              ></cc-notice>
            </div>
          `:""}
      ${"loaded"!==this.state.type||"idle"!==this.state.streamState.type&&"connecting"!==this.state.streamState.type?"":t`
            <div class="overlay-logs-wrapper">
              <cc-notice intent="info" no-icon>
                <div class="overlay-logs-wrapper--loader" slot="message">
                  <cc-loader></cc-loader>
                  <span>${n("cc-logs-addon-runtime.logs.loading")}</span>
                </div>
              </cc-notice>
            </div>
          `}
      ${"loaded"===this.state.type&&"waitingForFirstLog"===this.state.streamState.type?t`
            <div class="overlay-logs-wrapper">
              <cc-notice
                intent="info"
                heading=${n("cc-logs-addon-runtime.logs.warning.waiting.title")}
                message=${n("cc-logs-addon-runtime.logs.warning.waiting.message")}
              ></cc-notice>
            </div>
          `:""}
    `}static get styles(){return[s`
        :host {
          display: block;
        }

        .overlay {
          display: flex;
          height: 100%;
        }

        .overlay.fullscreen {
          backdrop-filter: blur(5px);
          bottom: 0;
          left: 0;
          position: fixed;
          right: 0;
          top: 0;
          z-index: 999;
        }

        .wrapper {
          display: grid;
          flex: 1;
          gap: 0.5em;
          grid-auto-rows: 1fr auto;
        }

        .wrapper.fullscreen {
          background-color: var(--cc-color-bg-default, #fff);
          border: 1px solid var(--cc-color-border-neutral, #aaa);
          border-radius: var(--cc-border-radius-default, 0.25em);
          margin: 1em;
          padding: 1em;
        }

        .logs-wrapper {
          position: relative;
        }

        .logs {
          height: 100%;
        }

        .logs-header {
          align-items: center;
          display: flex;
          gap: 1em;
          width: 100%;
        }

        .logs-message-filter {
          flex: 1;
        }

        .center-logs-wrapper {
          align-items: center;
          display: flex;
          height: 100%;
          justify-content: center;
        }

        .overlay-logs-wrapper {
          left: 50%;
          position: absolute;
          top: 50%;
          transform: translate(-50%, -50%);
        }

        .overlay-logs-wrapper--loader {
          align-items: center;
          display: flex;
          gap: 0.5em;
        }

        .overlay-logs-wrapper--loader cc-loader {
          height: 1.5em;
          width: 1.5em;
        }
      `]}}window.customElements.define("cc-logs-addon-runtime-beta",g);export{g as CcLogsAddonRuntime};
//# sourceMappingURL=cc-logs-addon-runtime.js.map
