// SPDX-FileCopyrightText: 2019-2025 Connor McLaughlin <stenzek@gmail.com>
// SPDX-License-Identifier: CC-BY-NC-ND-4.0

#pragma once

#include "common/progress_callback.h"

#include "types.h"

#include <functional>
#include <memory>
#include <span>
#include <string>
#include <string_view>
#include <vector>

class Error;
class SmallStringBase;

struct GPUSettings;

namespace FullscreenUI {
void Initialize();
bool IsInitialized();
bool HasActiveWindow();
bool HasActiveOrPendingWindow();
void CheckForConfigChanges(const GPUSettings& old_settings);
void OnSystemStarting();
void OnSystemPaused();
void OnSystemResumed();
void OnSystemDestroyed();

void Shutdown();

void DestroyGPUResources();

void Render();
void InvalidateCoverCache(std::string path = {});

float GetBackgroundAlpha();

void UpdateTheme();
void UpdateRunIdleState();

#ifndef __ANDROID__

void OpenPauseMenu();
void OpenCheatsMenu();
void OpenDiscChangeMenu();
void OpenAchievementsWindow();
void OpenLeaderboardsWindow();

class BackgroundProgressCallback final : public ProgressCallback
{
public:
  explicit BackgroundProgressCallback(std::string name);
  ~BackgroundProgressCallback() override;

  void SetCancelled();

protected:
  void StateChanged(StateChange changed) override;

private:
  std::string m_name;
  int m_last_progress_percent = -1;
};

#endif // __ANDROID__

// NOTE: Not in widgets.h so that clients can use it without pulling in imgui etc.
class LoadingScreenProgressCallback final : public ProgressCallback
{
public:
  LoadingScreenProgressCallback();
  ~LoadingScreenProgressCallback() override;

  ALWAYS_INLINE void SetOpenDelay(float delay) { m_open_delay = delay; }

  void Close();

  void SetTitle(const std::string_view title) override;

protected:
  void StateChanged(StateChange changed) override;

private:
  void Redraw(bool force);

  u64 m_open_time = 0;
  float m_open_delay = 1.0f;
  s32 m_last_progress_percent = -1;
  bool m_on_video_thread = false;
  std::string m_image;
  std::string m_title;
};

// Sound effect names.
extern const char* SFX_NAV_ACTIVATE;
extern const char* SFX_NAV_BACK;
extern const char* SFX_NAV_MOVE;

} // namespace FullscreenUI

// Host UI triggers from Big Picture mode.
namespace Host {

#ifndef __ANDROID__

/// Requests shut down and exit of the hosting application. This may not actually exit,
/// if the user cancels the shutdown confirmation.
void RequestExitApplication(bool allow_confirm);

/// Requests Big Picture mode to be shut down, returning to the desktop interface.
void RequestExitBigPicture();

#endif

} // namespace Host
