// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_BUBBLE_HANDLER_IMPL_H_
#define CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_BUBBLE_HANDLER_IMPL_H_

#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "chrome/browser/ui/autofill/autofill_bubble_handler.h"
#include "components/autofill/core/browser/ui/payments/payments_ui_closed_reasons.h"
#include "components/autofill/core/browser/ui/payments/save_payment_method_and_virtual_card_enroll_confirmation_ui_params.h"
#include "components/signin/public/base/signin_buildflags.h"
#include "ui/views/bubble/bubble_dialog_delegate_view.h"

class BrowserWindowInterface;
class ToolbarButtonProvider;

namespace content {
class WebContents;
}

namespace autofill {
class AutofillBubbleBase;
class FilledCardInformationBubbleController;
class SaveCardBubbleController;
class IbanBubbleController;
class OmniboxAutofillBubbleController;
class PaymentsChurnedUsersBubbleController;
class WalletReminderNoticeBubbleController;
enum class IbanBubbleType;

class AutofillBubbleHandlerImpl : public AutofillBubbleHandler {
 public:
  AutofillBubbleHandlerImpl(BrowserWindowInterface* browser,
                            ToolbarButtonProvider* toolbar_button_provider);

  AutofillBubbleHandlerImpl(const AutofillBubbleHandlerImpl&) = delete;
  AutofillBubbleHandlerImpl& operator=(const AutofillBubbleHandlerImpl&) =
      delete;

  ~AutofillBubbleHandlerImpl() override;

  // AutofillBubbleHandler:
  AutofillBubbleBase* ShowSaveCreditCardBubble(
      content::WebContents* web_contents,
      SaveCardBubbleController* controller,
      bool is_user_gesture) override;
  AutofillBubbleBase* ShowIbanBubble(content::WebContents* web_contents,
                                     IbanBubbleController* controller,
                                     bool is_user_gesture,
                                     IbanBubbleType bubble_type) override;

  AutofillBubbleBase* ShowOfferNotificationBubble(
      content::WebContents* contents,
      OfferNotificationBubbleController* controller,
      bool is_user_gesture) override;
  AutofillBubbleBase* ShowSaveAutofillAiDataBubble(
      content::WebContents* web_contents,
      AutofillAiImportDataController* controller) override;
  AutofillBubbleBase* ShowAutofillAiLocalSaveNotification(
      content::WebContents* web_contents,
      AutofillAiImportDataController* controller) override;
  AutofillBubbleBase* ShowSaveAddressProfileBubble(
      content::WebContents* web_contents,
      std::unique_ptr<SaveAddressBubbleController> controller,
      bool is_user_gesture) override;
#if BUILDFLAG(ENABLE_DICE_SUPPORT)
  AutofillBubbleBase* ShowAddressSignInPromo(
      content::WebContents* web_contents,
      const AutofillProfile& autofill_profile) override;
#endif  // BUILDFLAG(ENABLE_DICE_SUPPORT)
  AutofillBubbleBase* ShowUpdateAddressProfileBubble(
      content::WebContents* web_contents,
      std::unique_ptr<UpdateAddressBubbleController> controller,
      bool is_user_gesture) override;
  AutofillBubbleBase* ShowFilledCardInformationBubble(
      content::WebContents* web_contents,
      FilledCardInformationBubbleController* controller,
      bool is_user_gesture) override;
  AutofillBubbleBase* ShowVirtualCardEnrollBubble(
      content::WebContents* web_contents,
      VirtualCardEnrollBubbleController* controller,
      bool is_user_gesture) override;
  AutofillBubbleBase* ShowVirtualCardEnrollConfirmationBubble(
      content::WebContents* web_contents,
      VirtualCardEnrollBubbleController* controller) override;
  AutofillBubbleBase* ShowMandatoryReauthBubble(
      content::WebContents* web_contents,
      MandatoryReauthBubbleController* controller,
      bool is_user_gesture,
      MandatoryReauthBubbleType bubble_type) override;
  AutofillBubbleBase* ShowSaveCardConfirmationBubble(
      content::WebContents* web_contents,
      SaveCardBubbleController* controller) override;
  AutofillBubbleBase* ShowSaveIbanConfirmationBubble(
      content::WebContents* web_contents,
      IbanBubbleController* controller) override;
  AutofillBubbleBase* ShowOmniboxAutofillBubble(
      content::WebContents* web_contents,
      OmniboxAutofillBubbleController* controller) override;
  AutofillBubbleBase* ShowPaymentsChurnedUsersBubble(
      content::WebContents* web_contents,
      PaymentsChurnedUsersBubbleController* controller,
      bool is_user_gesture) override;
  AutofillBubbleBase* ShowPaymentsChurnedUsersConfirmationBubble(
      content::WebContents* web_contents,
      PaymentsChurnedUsersBubbleController* controller) override;
  AutofillBubbleBase* ShowWalletReminderNoticeBubble(
      content::WebContents* web_contents,
      WalletReminderNoticeBubbleController* controller,
      bool is_user_gesture) override;

 private:
  // Show the save card and virtual card enrollment confirmation bubble.
  AutofillBubbleBase* ShowSaveCardAndVirtualCardEnrollConfirmationBubble(
      views::BubbleAnchor anchor,
      content::WebContents* web_contents,
      base::OnceCallback<void(PaymentsUiClosedReason)> controller_hide_callback,
      ui::ElementIdentifier highlight_element,
      SavePaymentMethodAndVirtualCardEnrollConfirmationUiParams ui_params);

  raw_ptr<ToolbarButtonProvider> toolbar_button_provider_ = nullptr;

  ui::ScopedUnownedUserData<AutofillBubbleHandler> scoped_user_data_;
};

}  // namespace autofill

#endif  // CHROME_BROWSER_UI_VIEWS_AUTOFILL_AUTOFILL_BUBBLE_HANDLER_IMPL_H_
