// 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.

#ifndef CHROME_BROWSER_UI_READ_ANYTHING_READ_ANYTHING_ENTRY_POINT_CONTROLLER_H_
#define CHROME_BROWSER_UI_READ_ANYTHING_READ_ANYTHING_ENTRY_POINT_CONTROLLER_H_

#include "chrome/browser/ui/browser_window/public/browser_window_interface.h"
#include "chrome/browser/ui/read_anything/read_anything_enums.h"
#include "components/tabs/public/tab_interface.h"
#include "components/user_education/common/feature_promo/feature_promo_result.h"
#include "ui/actions/actions.h"

using read_anything::mojom::ReadAnythingOpenTrigger;

class ReadAnythingController;

namespace read_anything {

// Maintains and handles entry points for the ReadAnythingController.
class ReadAnythingEntryPointController {
 public:
  ReadAnythingEntryPointController(const ReadAnythingEntryPointController&) =
      delete;
  ReadAnythingEntryPointController& operator=(
      const ReadAnythingEntryPointController&) = delete;
  ~ReadAnythingEntryPointController();

  // Toggles Reading Mode on or off.
  // This and other methods below can handle null `bwi`.
  static void InvokePageAction(BrowserWindowInterface* bwi,
                               const actions::ActionInvocationContext& context);

  // Returns whether Reading Mode is currently showing. This handles both
  // Immersive and Side Panel reading mode.
  static bool IsUIShowing(BrowserWindowInterface* bwi);

  // Shows Reading Mode.
  static void ShowUI(BrowserWindowInterface* bwi,
                     ReadAnythingOpenTrigger open_trigger);

  // Shows or hides the omnibox entry point and the IPH for it.
  // show_promo_callback is called with the result of whether the IPH was shown.
  static void UpdatePageActionVisibility(
      bool should_show_page_action,
      tabs::TabInterface* tab,
      base::OnceCallback<void(user_education::FeaturePromoResult promo_result)>
          show_promo_callback = {});

  // Updates the number of times the omnibox entry point has been ignored by the
  // user.
  static void OnPageActionIgnored(BrowserWindowInterface* bwi);

  // Does the necessary setup to get the signal from the optimization guide on
  // whether the current page is a good candidate for reading mode. This must be
  // called before CheckIfShouldSuggestReadingMode.
  static void RegisterForSuggestReadingMode(Profile* profile);

  // Checks whether to suggest reading mode to the user on the current page and
  // asynchronously returns the result via `result_callback`. This is
  // asynchronous because it runs some heuristics to determine if the page is a
  // good candidate for reading mode.
  static void CheckIfShouldSuggestReadingMode(
      BrowserWindowInterface* bwi,
      base::OnceCallback<void(bool)> result_callback);

  static base::AutoReset<size_t> SetMinPdfTextLengthForTesting(size_t length);

  static int CheckCountForTesting();
  static void ResetCheckCountForTesting();

  // Toggles Reading Mode between shown and hidden. ToggleUI will close Reading
  // Mode if it is already open. Skips ActionInvocationContext processing and
  // receives a ReadAnythingOpenTrigger directly.
  static void ToggleUI(BrowserWindowInterface* bwi,
                       ReadAnythingOpenTrigger open_trigger);

 private:
  // Returns false if the reading mode suggestion should be hidden immediately
  // for the current page. This check uses very basic information about the
  // browser and checks for any explicitly blocked sites.
  static bool CheckIfShouldSuggestReadingModeNaive(BrowserWindowInterface* bwi);
};

}  // namespace read_anything

#endif  // CHROME_BROWSER_UI_READ_ANYTHING_READ_ANYTHING_ENTRY_POINT_CONTROLLER_H_
