// Copyright 2026 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import '//resources/cr_elements/cr_checkbox/cr_checkbox.js';
import { CrLitElement } from '//resources/lit/v3_0/lit.rollup.js';
import { getCss } from './app.css.js';
import { getHtml } from './app.html.js';
import { BrowserProxy } from './browser_proxy.js';
export class SubresourceInternalsAppElement extends CrLitElement {
    static get is() {
        return 'subresource-internals-app';
    }
    static get styles() {
        return getCss();
    }
    render() {
        return getHtml.bind(this)();
    }
    static get properties() {
        return {
            shouldHighlightAds_: { type: Boolean },
        };
    }
    #shouldHighlightAds__accessor_storage = false;
    get shouldHighlightAds_() { return this.#shouldHighlightAds__accessor_storage; }
    set shouldHighlightAds_(value) { this.#shouldHighlightAds__accessor_storage = value; }
    proxy_ = BrowserProxy.getInstance();
    listenerId_ = null;
    async connectedCallback() {
        super.connectedCallback();
        this.listenerId_ =
            this.proxy_.callbackRouter.onInternalsPageSettingsChanged.addListener(this.onInternalsPageSettingsChanged_.bind(this));
        this.proxy_.handler.observeInternalsPageSettings(this.proxy_.callbackRouter.$.bindNewPipeAndPassRemote());
        const { settings } = await this.proxy_.handler.getInternalsPageSettings();
        this.shouldHighlightAds_ = settings.shouldHighlightAds;
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        if (this.listenerId_ !== null) {
            this.proxy_.callbackRouter.removeListener(this.listenerId_);
            this.listenerId_ = null;
        }
    }
    onHighlightAdsCheckboxChange_(e) {
        const target = e.target;
        this.shouldHighlightAds_ = target.checked;
        this.proxy_.handler.setInternalsPageSettings({
            shouldHighlightAds: this.shouldHighlightAds_,
        });
    }
    onInternalsPageSettingsChanged_(settings) {
        this.shouldHighlightAds_ = settings.shouldHighlightAds;
    }
}
customElements.define(SubresourceInternalsAppElement.is, SubresourceInternalsAppElement);
