// 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_components/composebox/composebox_dropdown.js';
import '//resources/cr_components/composebox/composebox_file_inputs.js';
import '//resources/cr_components/composebox/composebox_submit.js';
import '//resources/cr_components/composebox/contextual_entrypoint_and_menu.js';
import '//resources/cr_components/composebox/composebox_input.js';
import '//resources/cr_components/composebox/error_scrim.js';
import '//resources/cr_components/composebox/file_carousel.js';
import '//resources/cr_components/composebox/composebox_tool_chip.js';
import '//resources/cr_elements/cr_icon_button/cr_icon_button.js';
import '//resources/cr_components/composebox/composebox_voice_search.js';
import '//resources/cr_components/search/animated_glow.js';
import '//resources/cr_components/localized_link/localized_link.js';
import { getLoadTimeBoolean } from '//resources/cr_components/composebox/common.js';
import { ComposeboxEmbedderMixin } from '//resources/cr_components/composebox/composebox_mixin.js';
import { ComposeboxProxyImpl } from '//resources/cr_components/composebox/composebox_proxy.js';
import { GlowAnimationState } from '//resources/cr_components/search/constants.js';
import { DragAndDropHandler } from '//resources/cr_components/search/drag_drop_handler.js';
import { EventTracker } from '//resources/js/event_tracker.js';
import { CrLitElement } from '//resources/lit/v3_0/lit.rollup.js';
import { getCss } from './ntp_composebox.css.js';
import { getHtml } from './ntp_composebox.html.js';
export class NtpComposeboxElement extends ComposeboxEmbedderMixin(CrLitElement) {
    static get is() {
        return 'ntp-composebox';
    }
    static get styles() {
        return getCss();
    }
    render() {
        return getHtml.bind(this)();
    }
    static get properties() {
        return {
            /*
            `expanding_` property is used in composebox.css styles. It is added
            so that the imported styles work well. Remove this property once each
            embedder has its own styles.
            */
            expanding_: {
                reflect: true,
                type: Boolean,
            },
            isDark: {
                reflect: true,
                type: Boolean,
            },
        };
    }
    #isDark_accessor_storage = false;
    get isDark() { return this.#isDark_accessor_storage; }
    set isDark(value) { this.#isDark_accessor_storage = value; }
    searchboxCallbackRouter_;
    pageHandler_;
    searchboxHandler_;
    eventTracker_ = new EventTracker();
    dragAndDropHandler_;
    #expanding__accessor_storage = true;
    get expanding_() { return this.#expanding__accessor_storage; }
    set expanding_(value) { this.#expanding__accessor_storage = value; }
    get keepMenuOpenOnTabSelect() {
        return getLoadTimeBoolean('keepMenuOpenOnTabSelectForRealbox', false);
    }
    getPageHandler() {
        return this.pageHandler_;
    }
    getSearchboxHandler() {
        return this.searchboxHandler_;
    }
    getSearchboxCallbackRouter() {
        return this.searchboxCallbackRouter_;
    }
    getActiveElement() {
        return this.shadowRoot?.activeElement || null;
    }
    getInputElement() {
        return this.$.composeboxInput;
    }
    getDropdownElement() {
        return this.$.matches;
    }
    getContextEntrypointElement() {
        return this.shadowRoot?.querySelector('#contextEntrypoint') ||
            null;
    }
    constructor() {
        super();
        this.pageHandler_ = ComposeboxProxyImpl.getInstance().handler;
        this.searchboxCallbackRouter_ =
            ComposeboxProxyImpl.getInstance().searchboxCallbackRouter;
        this.searchboxHandler_ = ComposeboxProxyImpl.getInstance().searchboxHandler;
        this.dragAndDropHandler_ =
            new DragAndDropHandler(this, this.dragAndDropEnabled);
    }
    connectedCallback() {
        super.connectedCallback();
        this.animationState = GlowAnimationState.EXPANDING;
        this.focusInput();
        this.refreshTabSuggestions(/*forceRefresh=*/ true);
    }
    disconnectedCallback() {
        super.disconnectedCallback();
        this.eventTracker_.removeAll();
    }
    /* Used by drag/drop host interface so the
    drag and drop handler can access addDroppedFiles(). */
    getDropTarget() {
        return this;
    }
    shouldShowDivider() {
        const hasNonTabFiles = Array.from(this.files.values()).some(f => !f.url);
        if (this.hasTabs() && !hasNonTabFiles) {
            return this.showDropdown;
        }
        return super.shouldShowDivider();
    }
    deleteFile(uuidToDelete, fromUserAction) {
        const file = super.deleteFile(uuidToDelete, fromUserAction);
        if (file) {
            this.queryAutocomplete(/* clearMatches= */ true);
        }
        return file;
    }
}
customElements.define(NtpComposeboxElement.is, NtpComposeboxElement);
