import*as Common from"../../../../core/common/common.js";import*as i18n from"../../../../core/i18n/i18n.js";import{assertNotNullOrUndefined}from"../../../../core/platform/platform.js";import*as SDK from"../../../../core/sdk/sdk.js";import*as DataGrid from"../../../../ui/components/data_grid/data_grid.js";import*as ComponentHelpers from"../../../../ui/components/helpers/helpers.js";import*as IconButton from"../../../../ui/components/icon_button/icon_button.js";import*as LegacyWrapper from"../../../../ui/components/legacy_wrapper/legacy_wrapper.js";import*as LitHtml from"../../../../ui/lit-html/lit-html.js";import*as PreloadingString from"./PreloadingString.js";import preloadingGridStyles from"./preloadingGrid.css.js";const UIStrings={action:"Action",ruleSet:"Rule set",status:"Status"},str_=i18n.i18n.registerUIStrings("panels/application/preloading/components/PreloadingGrid.ts",UIStrings);export const i18nString=i18n.i18n.getLocalizedString.bind(void 0,str_);const{render:render,html:html}=LitHtml;export class PreloadingGrid extends LegacyWrapper.LegacyWrapper.WrappableComponent{static litTagName=LitHtml.literal`devtools-resources-preloading-grid`;#t=this.attachShadow({mode:"open"});#e=null;connectedCallback(){this.#t.adoptedStyleSheets=[preloadingGridStyles],this.#i()}update(t){this.#e=t,this.#i()}#i(){if(null===this.#e)return;const t={columns:[{id:"url",title:i18n.i18n.lockedString("URL"),widthWeighting:40,hideable:!1,visible:!0,sortable:!0},{id:"action",title:i18nString(UIStrings.action),widthWeighting:15,hideable:!1,visible:!0,sortable:!0},{id:"ruleSet",title:i18nString(UIStrings.ruleSet),widthWeighting:20,hideable:!1,visible:!0,sortable:!0},{id:"status",title:i18nString(UIStrings.status),widthWeighting:40,hideable:!1,visible:!0,sortable:!0}],rows:this.#r(),striped:!0};render(html`
      <div class="preloading-container">
        <${DataGrid.DataGridController.DataGridController.litTagName} .data=${t}>
        </${DataGrid.DataGridController.DataGridController.litTagName}>
      </div>
    `,this.#t,{host:this})}#r(){assertNotNullOrUndefined(this.#e);const t=this.#e.pageURL,e=""===t?null:new Common.ParsedURL.ParsedURL(t).securityOrigin();return this.#e.rows.map((i=>({cells:[{columnId:"id",value:i.id},{columnId:"url",value:this.#o(i,e),title:i.attempt.key.url},{columnId:"action",value:PreloadingString.action(i.attempt)},{columnId:"ruleSet",value:0===i.ruleSets.length?"":PreloadingString.ruleSetLocationShort(i.ruleSets[0],t)},{columnId:"status",value:PreloadingString.composedStatus(i.attempt),renderer:t=>function(t,e){return"Failure"!==e?LitHtml.html`<div>${t}</div>`:LitHtml.html`
        <div
          style=${LitHtml.Directives.styleMap({color:"var(--color-error)"})}
        >
          <${IconButton.Icon.Icon.litTagName}
            .data=${{iconName:"cross-circle-filled",color:"var(--color-error)",width:"16px",height:"16px"}}
            style=${LitHtml.Directives.styleMap({"vertical-align":"sub"})}
          >
          </${IconButton.Icon.Icon.litTagName}>
          ${t}
        </div>
      `}(t,i.attempt.status)}]})))}#o(t,e){const i=t.attempt.key.url;return e&&i.startsWith(e)?i.slice(e.length):i}}ComponentHelpers.CustomElements.defineComponent("devtools-resources-preloading-grid",PreloadingGrid);