import*as i18n from"../../../core/i18n/i18n.js";import*as LitHtml from"../../lit-html/lit-html.js";import*as ComponentHelpers from"../helpers/helpers.js";import*as IconButton from"../icon_button/icon_button.js";import linearMemoryNavigatorStyles from"./linearMemoryNavigator.css.js";const UIStrings={enterAddress:"Enter address",goBackInAddressHistory:"Go back in address history",goForwardInAddressHistory:"Go forward in address history",previousPage:"Previous page",nextPage:"Next page",refresh:"Refresh"},str_=i18n.i18n.registerUIStrings("ui/components/linear_memory_inspector/LinearMemoryNavigator.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_),{render:render,html:html}=LitHtml;export class AddressInputChangedEvent extends Event{static eventName="addressinputchanged";data;constructor(t,e){super(AddressInputChangedEvent.eventName),this.data={address:t,mode:e}}}export class PageNavigationEvent extends Event{static eventName="pagenavigation";data;constructor(t){super(PageNavigationEvent.eventName,{}),this.data=t}}export class HistoryNavigationEvent extends Event{static eventName="historynavigation";data;constructor(t){super(HistoryNavigationEvent.eventName,{}),this.data=t}}export class RefreshRequestedEvent extends Event{static eventName="refreshrequested";constructor(){super(RefreshRequestedEvent.eventName,{})}}export class LinearMemoryNavigator extends HTMLElement{static litTagName=LitHtml.literal`devtools-linear-memory-inspector-navigator`;#t=this.attachShadow({mode:"open"});#e="0";#n=void 0;#r=!0;#i=!1;#s=!1;connectedCallback(){this.#t.adoptedStyleSheets=[linearMemoryNavigatorStyles]}set data(t){this.#e=t.address,this.#n=t.error,this.#r=t.valid,this.#i=t.canGoBackInHistory,this.#s=t.canGoForwardInHistory,this.#a();const e=this.#t.querySelector(".address-input");e&&("Submitted"===t.mode?e.blur():"InvalidSubmit"===t.mode&&e.select())}#a(){const t=html`
      <div class="navigator">
        <div class="navigator-item">
          ${this.#o({icon:"undo",title:i18nString(UIStrings.goBackInAddressHistory),event:new HistoryNavigationEvent("Backward"),enabled:this.#i})}
          ${this.#o({icon:"redo",title:i18nString(UIStrings.goForwardInAddressHistory),event:new HistoryNavigationEvent("Forward"),enabled:this.#s})}
        </div>
        <div class="navigator-item">
          ${this.#o({icon:"chevron-left",title:i18nString(UIStrings.previousPage),event:new PageNavigationEvent("Backward"),enabled:!0})}
          ${this.#d()}
          ${this.#o({icon:"chevron-right",title:i18nString(UIStrings.nextPage),event:new PageNavigationEvent("Forward"),enabled:!0})}
        </div>
        ${this.#o({icon:"refresh",title:i18nString(UIStrings.refresh),event:new RefreshRequestedEvent,enabled:!0})}
      </div>
      `;render(t,this.#t,{host:this})}#d(){const t={"address-input":!0,invalid:!this.#r};return html`
      <input class=${LitHtml.Directives.classMap(t)} data-input="true" .value=${this.#e}
        title=${this.#r?i18nString(UIStrings.enterAddress):this.#n} @change=${this.#c.bind(this,"Submitted")} @input=${this.#c.bind(this,"Edit")}/>`}#c(t,e){const n=e.target;this.dispatchEvent(new AddressInputChangedEvent(n.value,t))}#o(t){return html`
      <button class="navigator-button" ?disabled=${!t.enabled}
        data-button=${t.event.type} title=${t.title}
        @click=${this.dispatchEvent.bind(this,t.event)}>
        <${IconButton.Icon.Icon.litTagName} .data=${{iconName:t.icon,color:"var(--icon-default)",width:"20px",height:"20px"}}>
        </${IconButton.Icon.Icon.litTagName}>
      </button>`}}ComponentHelpers.CustomElements.defineComponent("devtools-linear-memory-inspector-navigator",LinearMemoryNavigator);