import*as i18n from"../../../core/i18n/i18n.js";import*as Platform from"../../../core/platform/platform.js";import*as SDK from"../../../core/sdk/sdk.js";import*as Buttons from"../../../ui/components/buttons/buttons.js";import*as ComponentHelpers from"../../../ui/components/helpers/helpers.js";import*as LegacyWrapper from"../../../ui/components/legacy_wrapper/legacy_wrapper.js";import*as Coordinator from"../../../ui/components/render_coordinator/render_coordinator.js";import*as ReportView from"../../../ui/components/report_view/report_view.js";import*as LitHtml from"../../../ui/lit-html/lit-html.js";import*as UI from"../../../ui/legacy/legacy.js";const UIStrings={origin:"Origin",topLevelSite:"Top-level site",opaque:"(opaque)",isOpaque:"Is opaque",isThirdParty:"Is third-party",yes:"Yes",no:"No",yesBecauseTopLevelIsOpaque:"Yes, because the top-level site is opaque",yesBecauseKeyIsOpaque:"Yes, because the storage key is opaque",yesBecauseOriginNotInTopLevelSite:"Yes, because the origin is outside of the top-level site",yesBecauseAncestorChainHasCrossSite:"Yes, because the ancestry chain contains a third-party origin",loading:"Loading…",bucketName:"Bucket name",defaultBucket:"Default bucket",persistent:"Is persistent",durability:"Durability",quota:"Quota",expiration:"Expiration",none:"None",deleteBucket:"Delete bucket",confirmBucketDeletion:'Delete the "{PH1}" bucket?'},str_=i18n.i18n.registerUIStrings("panels/application/components/StorageMetadataView.ts",UIStrings),i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_),coordinator=Coordinator.RenderCoordinator.RenderCoordinator.instance();export class StorageMetadataView extends LegacyWrapper.LegacyWrapper.WrappableComponent{static litTagName=LitHtml.literal`devtools-storage-metadata-view`;#t=this.attachShadow({mode:"open"});#e;#i=null;#r=null;getShadow(){return this.#t}setStorageKey(t){this.#i=SDK.StorageKeyManager.parseStorageKey(t),this.render()}setStorageBucket(t){this.#r=t,this.setStorageKey(t.bucket.storageKey)}enableStorageBucketControls(t){this.#e=t,this.#i&&this.render()}render(){return coordinator.write("StorageMetadataView render",(async()=>{LitHtml.render(LitHtml.html`
        <${ReportView.ReportView.Report.litTagName} .data=${{reportTitle:this.getTitle()||i18nString(UIStrings.loading)}}>
          ${await this.renderReportContent()}
        </${ReportView.ReportView.Report.litTagName}>`,this.#t,{host:this})}))}getTitle(){if(!this.#i)return;const t=this.#i.origin,e=this.#r?.bucket.name||i18nString(UIStrings.defaultBucket);return this.#e?`${e} - ${t}`:t}key(t){return LitHtml.html`<${ReportView.ReportView.ReportKey.litTagName}>${t}</${ReportView.ReportView.ReportKey.litTagName}>`}value(t){return LitHtml.html`<${ReportView.ReportView.ReportValue.litTagName}>${t}</${ReportView.ReportView.ReportValue.litTagName}>`}async renderReportContent(){if(!this.#i)return LitHtml.nothing;const t=this.#i.origin,e=Boolean(this.#i.components.get("3")),i=Boolean(this.#i.components.get("1")),r=Boolean(this.#i.components.get("4")),o=this.#i.components.get("0"),s=e?i18nString(UIStrings.yesBecauseAncestorChainHasCrossSite):i?i18nString(UIStrings.yesBecauseKeyIsOpaque):r?i18nString(UIStrings.yesBecauseTopLevelIsOpaque):o&&t!==o?i18nString(UIStrings.yesBecauseOriginNotInTopLevelSite):null;return LitHtml.html`
        ${this.key(i18nString(UIStrings.origin))}
        ${this.value(LitHtml.html`<div class="text-ellipsis" title=${t}>${t}</div>`)}
        ${o||r?this.key(i18nString(UIStrings.topLevelSite)):LitHtml.nothing}
        ${o?this.value(o):LitHtml.nothing}
        ${r?this.value(i18nString(UIStrings.opaque)):LitHtml.nothing}
        ${s?LitHtml.html`${this.key(i18nString(UIStrings.isThirdParty))}${this.value(s)}`:LitHtml.nothing}
        ${i||r?this.key(i18nString(UIStrings.isOpaque)):LitHtml.nothing}
        ${i?this.value(i18nString(UIStrings.yes)):LitHtml.nothing}
        ${r?this.value(i18nString(UIStrings.yesBecauseTopLevelIsOpaque)):LitHtml.nothing}
        ${this.#r?this.#o():LitHtml.nothing}
        ${this.#e?this.#s():LitHtml.nothing}`}#o(){if(!this.#r)throw new Error("Should not call #renderStorageBucketInfo if #bucket is null.");const{bucket:{name:t},persistent:e,durability:i,quota:r}=this.#r;return LitHtml.html`
      ${this.key(i18nString(UIStrings.bucketName))}
      ${this.value(t||"default")}
      ${this.key(i18nString(UIStrings.persistent))}
      ${this.value(i18nString(e?UIStrings.yes:UIStrings.no))}
      ${this.key(i18nString(UIStrings.durability))}
      ${this.value(i)}
      ${this.key(i18nString(UIStrings.quota))}
      ${this.value(Platform.NumberUtilities.bytesToString(r))}
      ${this.key(i18nString(UIStrings.expiration))}
      ${this.value(this.#n())}`}#n(){if(!this.#r)throw new Error("Should not call #getExpirationString if #bucket is null.");const{expiration:t}=this.#r;return 0===t?i18nString(UIStrings.none):new Date(1e3*t).toLocaleString()}#s(){return LitHtml.html`
      <${ReportView.ReportView.ReportSection.litTagName}>
        <${Buttons.Button.Button.litTagName}
          aria-label=${i18nString(UIStrings.deleteBucket)}
          .variant=${"primary"}
          @click=${this.#a}>
          ${i18nString(UIStrings.deleteBucket)}
        </${Buttons.Button.Button.litTagName}>
      </${ReportView.ReportView.ReportSection.litTagName}>`}async#a(){if(!this.#e||!this.#r)throw new Error("Should not call #deleteBucket if #storageBucketsModel or #storageBucket is null.");await UI.UIUtils.ConfirmDialog.show(i18nString(UIStrings.confirmBucketDeletion,{PH1:this.#r.bucket.name||""}),this)&&this.#e.deleteBucket(this.#r.bucket)}}ComponentHelpers.CustomElements.defineComponent("devtools-storage-metadata-view",StorageMetadataView);