// 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 './toolbar_chip_button.js';
import { assertNotReachedCase } from '//resources/js/assert.js';
import { CrLitElement } from '//resources/lit/v3_0/lit.rollup.js';
import { ContentSettingImageType } from '/shared/toolbar_ui_api_data_model.mojom-webui.js';
import { BrowserProxyImpl } from './browser_proxy.js';
import { getCss } from './content_setting_icon.css.js';
import { getHtml } from './content_setting_icon.html.js';
export class ContentSettingIconElement extends CrLitElement {
    static get is() {
        return 'content-setting-icon';
    }
    static get styles() {
        return getCss();
    }
    render() {
        return getHtml.bind(this)();
    }
    static get properties() {
        return {
            state: { type: Object },
            animating: {
                type: Boolean,
                reflect: true,
            },
        };
    }
    #state_accessor_storage = {
        type: ContentSettingImageType.kCookies,
        isBlocked: false,
        tooltip: '',
        accessibilityString: '',
        isBubbleVisible: false,
        shouldRunAnimation: false,
        explanatoryString: '',
    };
    get state() { return this.#state_accessor_storage; }
    set state(value) { this.#state_accessor_storage = value; }
    #animating_accessor_storage = false;
    get animating() { return this.#animating_accessor_storage; }
    set animating(value) { this.#animating_accessor_storage = value; }
    browserProxy_ = BrowserProxyImpl.getInstance();
    willUpdate(changedProperties) {
        super.willUpdate(changedProperties);
        if (changedProperties.has('state')) {
            this.animating = this.state.shouldRunAnimation;
        }
    }
    onLabelAnimationend_() {
        this.animating = false;
    }
    getIconUrl_() {
        const iconType = this.state.type;
        const blocked = this.state.isBlocked;
        let iconName = '';
        switch (iconType) {
            case ContentSettingImageType.kCookies:
                iconName = blocked ? 'database_off' : 'database';
                break;
            case ContentSettingImageType.kImages:
                iconName =
                    blocked ? 'photo_off_chrome_refresh' : 'photo_chrome_refresh';
                break;
            case ContentSettingImageType.kJavaScript:
                iconName = blocked ? 'code_off_chrome_refresh' : 'code_chrome_refresh';
                break;
            case ContentSettingImageType.kMixedScript:
                iconName = blocked ? 'not_secure_warning_off_chrome_refresh' :
                    'not_secure_warning_chrome_refresh';
                break;
            case ContentSettingImageType.kSound:
                iconName =
                    blocked ? 'volume_off_chrome_refresh' : 'volume_up_chrome_refresh';
                break;
            case ContentSettingImageType.kAds:
                iconName = blocked ? 'ads_off_chrome_refresh' : 'ads_chrome_refresh';
                break;
            case ContentSettingImageType.kGeolocation:
                iconName = blocked ? 'location_off_chrome_refresh' :
                    'location_on_chrome_refresh';
                break;
            case ContentSettingImageType.kProtocolHandlers:
                iconName = blocked ? 'protocol_handler_off_chrome_refresh' :
                    'protocol_handler_chrome_refresh';
                break;
            case ContentSettingImageType.kMidiSysex:
                iconName = blocked ? 'midi_off_chrome_refresh' : 'midi_chrome_refresh';
                break;
            case ContentSettingImageType.kAutomaticDownloads:
                iconName = blocked ? 'file_download_off_chrome_refresh' :
                    'file_download_chrome_refresh';
                break;
            case ContentSettingImageType.kClipboardReadWrite:
                iconName = blocked ? 'content_paste_off' : 'content_paste';
                break;
            case ContentSettingImageType.kMediaStream:
                iconName =
                    blocked ? 'videocam_off_chrome_refresh' : 'videocam_chrome_refresh';
                break;
            case ContentSettingImageType.kNotifications:
                iconName = blocked ? 'notifications_off_chrome_refresh' :
                    'notifications_chrome_refresh';
                break;
            case ContentSettingImageType.kSensors:
                iconName =
                    blocked ? 'sensors_off_chrome_refresh' : 'sensors_chrome_refresh';
                break;
            case ContentSettingImageType.kStorageAccess:
                iconName = blocked ? 'storage_access_off' : 'storage_access';
                break;
            case ContentSettingImageType.kPopups:
                iconName = blocked ? 'iframe_off' : 'iframe';
                break;
            case ContentSettingImageType.kFramebust:
                iconName = blocked ? 'open_in_new_off_chrome_refresh' :
                    'open_in_new_chrome_refresh';
                break;
            // 
            // 
            default:
                assertNotReachedCase(iconType);
        }
        return `url('shared/rhs_icons/${iconName}.svg')`;
    }
    getAriaLabel_() {
        return this.state.accessibilityString || this.state.tooltip;
    }
    showContentSettingsBubble_() {
        this.browserProxy_.toolbarUIHandler.showContentSettingsBubble(this.state.type);
    }
    onClick_() {
        this.showContentSettingsBubble_();
    }
    onAuxclick_() {
        // Handles both middle and right clicks.
        this.showContentSettingsBubble_();
    }
    onContextmenu_(e) {
        // Prevent the default browser context menu on right click. The right click
        // action is natively handled as opening the bubble, which we process in
        // onAuxclick_ instead to avoid double-triggering.
        e.preventDefault();
    }
    onPointerenter_() {
        this.fire('chip-pointerenter');
    }
    onPointerleave_() {
        this.fire('chip-pointerleave');
    }
    onPointercancel_() {
        this.fire('chip-pointercancel');
    }
}
customElements.define(ContentSettingIconElement.is, ContentSettingIconElement);
