// 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_button/cr_button.js';
import '//resources/cr_elements/cr_icon/cr_icon.js';
import '//resources/cr_elements/icons.html.js';
import '/shared/icon_from_table.js';
import { CrLitElement } from '//resources/lit/v3_0/lit.rollup.js';
import { AvatarToolbarButtonState } from '/shared/toolbar_ui_api_data_model.mojom-webui.js';
import { getCss } from './avatar_button.css.js';
import { getHtml } from './avatar_button.html.js';
import { BrowserProxyImpl } from './browser_proxy.js';
import { HelpBubbleAnchorMixin } from './toolbar_button.js';
const AvatarButtonElementBase = HelpBubbleAnchorMixin(CrLitElement);
export class AvatarButtonElement extends AvatarButtonElementBase {
    static get is() {
        return 'avatar-button';
    }
    static get styles() {
        return getCss();
    }
    render() {
        return getHtml.bind(this)();
    }
    static get properties() {
        return {
            ...super.properties,
            state: { type: Object },
        };
    }
    updated(changedProperties) {
        super.updated(changedProperties);
        if (changedProperties.has('hasHelpBubble')) {
            BrowserProxyImpl.getInstance()
                .toolbarUIHandler.setAvatarButtonIphPromoShowing(this.hasHelpBubble);
        }
    }
    #state_accessor_storage = {
        state: AvatarToolbarButtonState.kNormal,
        icon: { handleId: 0n },
        text: '',
        tooltip: '',
        accessibilityName: '',
        accessibilityDescription: '',
        enabled: true,
    };
    get state() { return this.#state_accessor_storage; }
    set state(value) { this.#state_accessor_storage = value; }
    getTooltip_() {
        return this.adjustTooltipForHelpBubble(this.state?.tooltip || '');
    }
    shouldPaintBorder() {
        return !!this.state.text &&
            this.state.state === AvatarToolbarButtonState.kGuestSession;
    }
    getButtonClass_() {
        if (!this.state.text) {
            return '';
        }
        switch (this.state.state) {
            case AvatarToolbarButtonState.kSyncError:
                return 'highlight-sync-error';
            case AvatarToolbarButtonState.kGuestSession:
                return 'highlight-guest';
            case AvatarToolbarButtonState.kIncognitoProfile:
                return 'highlight-incognito';
            default:
                return 'highlight-default';
        }
    }
    onClick_(_) {
        // TODO(behamilton): Log an error if this fails.
        BrowserProxyImpl.getInstance().toolbarUIHandler.showAvatarMenu();
    }
    onMouseenter_() {
        BrowserProxyImpl.getInstance().toolbarUIHandler.setAvatarButtonHovered(true);
    }
    onMouseleave_() {
        BrowserProxyImpl.getInstance().toolbarUIHandler.setAvatarButtonHovered(false);
    }
    onFocus_() {
        BrowserProxyImpl.getInstance().toolbarUIHandler.setAvatarButtonFocused(true);
    }
    onBlur_() {
        BrowserProxyImpl.getInstance().toolbarUIHandler.setAvatarButtonFocused(false);
    }
}
customElements.define(AvatarButtonElement.is, AvatarButtonElement);
