// Copyright 2025 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
/**
 * @fileoverview 'settings-other-google-data-dialog' is a subpage
 * shown within the Clear Browsing Data dialog to provide links
 * for managing other Google data like passwords and activity.
 */
import 'chrome://resources/cr_elements/cr_button/cr_button.js';
import 'chrome://resources/cr_elements/cr_dialog/cr_dialog.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_shared_style.css.js';
import { SyncBrowserProxyImpl } from '/shared/settings/people_page/sync_browser_proxy.js';
import { WebUiListenerMixin } from 'chrome://resources/cr_elements/web_ui_listener_mixin.js';
import { loadTimeData } from 'chrome://resources/js/load_time_data.js';
import { OpenWindowProxyImpl } from 'chrome://resources/js/open_window_proxy.js';
import { sanitizeInnerHtml } from 'chrome://resources/js/parse_html_subset.js';
import { PolymerElement } from 'chrome://resources/polymer/v3_0/polymer/polymer_bundled.min.js';
import { PasswordManagerImpl, PasswordManagerPage } from '../autofill_page/password_manager_proxy.js';
import { MetricsBrowserProxyImpl } from '../metrics_browser_proxy.js';
import { ClearBrowsingDataBrowserProxyImpl } from './clear_browsing_data_browser_proxy.js';
import { isSignedIn } from './clear_browsing_data_signin_util.js';
import { getTemplate } from './other_google_data_dialog.html.js';
const SettingsOtherGoogleDataDialogElementBase = WebUiListenerMixin(PolymerElement);
export class SettingsOtherGoogleDataDialogElement extends SettingsOtherGoogleDataDialogElementBase {
    static get is() {
        return 'settings-other-google-data-dialog';
    }
    static get template() {
        return getTemplate();
    }
    static get properties() {
        return {
            dialogTitle_: {
                type: String,
                computed: 'computeDialogTitle_(isGoogleDse_)',
            },
            isGoogleDse_: {
                type: Boolean,
                value: false,
            },
            nonGoogleSearchHistorySubLabel_: String,
            syncStatus_: Object,
        };
    }
    clearBrowsingDataBrowserProxy_ = ClearBrowsingDataBrowserProxyImpl.getInstance();
    syncBrowserProxy_ = SyncBrowserProxyImpl.getInstance();
    metricsBrowserProxy_ = MetricsBrowserProxyImpl.getInstance();
    ready() {
        super.ready();
        this.addWebUiListener('sync-status-changed', this.handleSyncStatus_.bind(this));
        this.syncBrowserProxy_.getSyncStatus().then(this.handleSyncStatus_.bind(this));
        this.addWebUiListener('update-sync-state', this.updateDseStatus_.bind(this));
        this.clearBrowsingDataBrowserProxy_.getSyncState().then(this.updateDseStatus_.bind(this));
    }
    updateDseStatus_(event) {
        this.isGoogleDse_ = !event.isNonGoogleDse;
        this.nonGoogleSearchHistorySubLabel_ =
            sanitizeInnerHtml(event.nonGoogleSearchHistoryString);
    }
    handleSyncStatus_(syncStatus) {
        this.syncStatus_ = syncStatus;
    }
    computeDialogTitle_() {
        return this.isGoogleDse_ ? loadTimeData.getString('otherGoogleDataTitle') :
            loadTimeData.getString('otherDataTitle');
    }
    onBackOrCancelClick_() {
        this.$.dialog.cancel();
    }
    onPasswordManagerClick_() {
        PasswordManagerImpl.getInstance().showPasswordManager(PasswordManagerPage.PASSWORDS);
        this.metricsBrowserProxy_.recordAction('Settings.DeleteBrowsingData.PasswordManagerLinkClick');
    }
    onMyActivityLinkClick_() {
        OpenWindowProxyImpl.getInstance().openUrl(loadTimeData.getString('deleteBrowsingDataMyActivityUrl'));
        this.metricsBrowserProxy_.recordAction('Settings.DeleteBrowsingData.MyActivityLinkClick');
    }
    onGoogleSearchHistoryLinkClick_() {
        OpenWindowProxyImpl.getInstance().openUrl(loadTimeData.getString('deleteBrowsingDataSearchHistoryUrl'));
        this.metricsBrowserProxy_.recordAction('Settings.DeleteBrowsingData.GoogleSearchHistoryLinkClick');
    }
    onGeminiAppsActivityClick_() {
        OpenWindowProxyImpl.getInstance().openUrl(loadTimeData.getString('myActivityGeminiAppsUrl'));
        this.metricsBrowserProxy_.recordAction('Settings.DeleteBrowsingData.GeminiAppsActivityLinkClick');
    }
    shouldShowMyActivityLink_() {
        return isSignedIn(this.syncStatus_);
    }
    shouldShowGoogleSearchHistoryLink_() {
        return isSignedIn(this.syncStatus_) && this.isGoogleDse_;
    }
    shouldShowGeminiAppsActivityLink_() {
        return isSignedIn(this.syncStatus_) &&
            loadTimeData.getBoolean('showGlicSettings');
    }
}
customElements.define(SettingsOtherGoogleDataDialogElement.is, SettingsOtherGoogleDataDialogElement);
