import*as i18n from"../../../core/i18n/i18n.js";import*as ComponentHelpers from"../../../ui/components/helpers/helpers.js";import*as IconButton from"../../../ui/components/icon_button/icon_button.js";import*as LitHtml from"../../../ui/lit-html/lit-html.js";import sharedStorageMetadataViewStyles from"./sharedStorageMetadataView.css.js";import sharedStorageMetadataViewResetBudgetButtonStyles from"./sharedStorageMetadataViewResetBudgetButton.css.js";import{StorageMetadataView}from"./StorageMetadataView.js";const UIStrings={sharedStorage:"Shared storage",creation:"Creation Time",notYetCreated:"Not yet created",numEntries:"Number of Entries",entropyBudget:"Entropy Budget for Fenced Frames",budgetExplanation:"Remaining data leakage allowed within a 24-hour period for this origin in bits of entropy",resetBudget:"Reset Budget"},str_=i18n.i18n.registerUIStrings("panels/application/components/SharedStorageMetadataView.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);class SharedStorageResetBudgetButton extends HTMLElement{static litTagName=LitHtml.literal`devtools-shared-storage-reset-budget-button`;#t=this.attachShadow({mode:"open"});#e=()=>{};connectedCallback(){this.#t.adoptedStyleSheets=[sharedStorageMetadataViewResetBudgetButtonStyles]}set data(t){this.#e=t.resetBudgetHandler,this.#a()}#a(){LitHtml.render(LitHtml.html`
      <button class="reset-budget-button"
        title=${i18nString(UIStrings.resetBudget)}
        @click=${()=>this.#e()}>
      <${IconButton.Icon.Icon.litTagName} .data=${{iconName:"undo",color:"var(--icon-default)",width:"16px",height:"16px"}}>
        </${IconButton.Icon.Icon.litTagName}>
      </button>`,this.#t,{host:this})}}export class SharedStorageMetadataView extends StorageMetadataView{static litTagName=LitHtml.literal`devtools-shared-storage-metadata-view`;#r;#i=null;#n=0;#o=0;constructor(t,e){super(),this.#r=t,this.classList.add("overflow-auto"),this.setStorageKey(e)}async#s(){await this.#r.resetBudget(),await this.render()}connectedCallback(){this.getShadow().adoptedStyleSheets=[sharedStorageMetadataViewStyles]}getTitle(){return i18nString(UIStrings.sharedStorage)}async renderReportContent(){const t=await this.#r.getMetadata();return this.#i=t?.creationTime??null,this.#n=t?.length??0,this.#o=t?.remainingBudget??0,LitHtml.html`
      ${await super.renderReportContent()}
      ${this.key(i18nString(UIStrings.creation))}
      ${this.value(this.#d())}
      ${this.key(i18nString(UIStrings.numEntries))}
      ${this.value(String(this.#n))}
      ${this.key(LitHtml.html`${i18nString(UIStrings.entropyBudget)}<${IconButton.Icon.Icon.litTagName} class="info-icon" title=${i18nString(UIStrings.budgetExplanation)}
           .data=${{iconName:"info",color:"var(--icon-default)",width:"16px"}}>
         </${IconButton.Icon.Icon.litTagName}>`)}
      ${this.value(LitHtml.html`${this.#o}${this.#g()}`)}`}#d(){if(!this.#i)return LitHtml.html`${i18nString(UIStrings.notYetCreated)}`;const t=new Date(1e3*this.#i);return LitHtml.html`${t.toLocaleString()}`}#g(){return LitHtml.html`<${SharedStorageResetBudgetButton.litTagName}
     .data=${{resetBudgetHandler:this.#s.bind(this)}}
    ></${SharedStorageResetBudgetButton.litTagName}>`}}ComponentHelpers.CustomElements.defineComponent("devtools-shared-storage-reset-budget-button",SharedStorageResetBudgetButton),ComponentHelpers.CustomElements.defineComponent("devtools-shared-storage-metadata-view",SharedStorageMetadataView);