// 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 'chrome://resources/cr_elements/cr_action_menu/cr_action_menu.js';
import 'chrome://resources/cr_elements/cr_button/cr_button.js';
import 'chrome://resources/cr_elements/cr_icon/cr_icon.js';
import 'chrome://resources/cr_elements/cr_icon_button/cr_icon_button.js';
import 'chrome://resources/cr_elements/cr_link_row/cr_link_row.js';
import 'chrome://resources/cr_elements/cr_lazy_render/cr_lazy_render.js';
import 'chrome://resources/cr_elements/cr_shared_style.css.js';
import '../controls/settings_toggle_button.js';
import '../settings_columned_section.css.js';
import '../settings_page/settings_section.js';
import '../settings_shared.css.js';
import './ai_site_add_dialog.js';
import '/shared/settings/controls/cr_policy_pref_indicator.js';
import { PrefsMixin } from '/shared/settings/prefs/prefs_mixin.js';
import { OpenWindowProxyImpl } from 'chrome://resources/js/open_window_proxy.js';
import { PolymerElement } from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import { getTemplate } from './ai_mode_search_page.html.js';
const SettingsAiModeSearchPageElementBase = PrefsMixin(PolymerElement);
export class SettingsAiModeSearchPageElement extends SettingsAiModeSearchPageElementBase {
    static get is() {
        return 'settings-ai-mode-search-page';
    }
    static get template() {
        return getTemplate();
    }
    static get properties() {
        return {
            siteList_: {
                type: Array,
                value: () => [],
            },
            showAddSiteDialog_: {
                type: Boolean,
                value: false,
            },
            siteToEdit_: {
                type: String,
                value: '',
            },
            enterprisePref_: {
                type: Object,
                computed: `computePref(prefs.contextual_tasks.smart_tab_sharing_settings)`,
            },
        };
    }
    static get observers() {
        return [
            'onSiteExclusionsChanged_(prefs.contextual_tasks.site_exclusions.value.*)',
        ];
    }
    isDisabledByPolicy_() {
        return this.enterprisePref_ && this.enterprisePref_.value === 1;
    }
    onSiteExclusionsChanged_() {
        const exclusions = this.getSiteExclusions();
        this.siteList_ = Object.keys(exclusions).sort();
    }
    hasSites_() {
        return this.siteList_.length > 0;
    }
    onAddSiteClick_() {
        this.siteToEdit_ = '';
        this.showAddSiteDialog_ = true;
    }
    onMenuClick_(e) {
        this.siteToEdit_ = e.model.item;
        this.$.menu.get().showAt(e.target);
    }
    onEditClick_() {
        this.$.menu.get().close();
        this.showAddSiteDialog_ = true;
    }
    onRemoveSiteClick_() {
        this.$.menu.get().close();
        this.removeSiteExclusion(this.siteToEdit_);
    }
    onAddSiteDialogClose_() {
        this.showAddSiteDialog_ = false;
    }
    onAddSite_(e) {
        if (this.siteToEdit_ && this.siteToEdit_ !== e.detail) {
            this.removeSiteExclusion(this.siteToEdit_);
        }
        this.addSiteExclusion(e.detail, Date.now());
    }
    getSiteExclusions() {
        const pref = this.getPref('contextual_tasks.site_exclusions');
        return pref ? pref.value : {};
    }
    addSiteExclusion(domain, timeAddedMs) {
        this.setPrefDictEntry('contextual_tasks.site_exclusions', domain, timeAddedMs);
    }
    removeSiteExclusion(domain) {
        this.deletePrefDictEntry('contextual_tasks.site_exclusions', domain);
    }
    onLearnMoreRowClick_() {
        OpenWindowProxyImpl.getInstance().openUrl('https://support.google.com/chrome?p=ai_mode_search');
    }
    onLearnMoreClick_(event) {
        event.stopPropagation();
    }
}
customElements.define(SettingsAiModeSearchPageElement.is, SettingsAiModeSearchPageElement);
