// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.

#pragma once

#include <memory>

#include "wpi/util/FunctionExtras.hpp"

namespace wpi::glass {

/**
 * A view is the contents of a window (1:1 mapping).
 * It may reference multiple models.
 *
 * Typically a view is constructed by a Provider and the View's constructor
 * is given the corresponding Model(s).
 *
 * A view may retain a reference to its parent window for dynamic
 * window configuration.
 */
class View {
 public:
  virtual ~View() = default;

  /**
   * Displays the window contents.  Called by Window::Display() from within an
   * ImGui::Begin() / ImGui::End() block.
   */
  virtual void Display() = 0;

  /**
   * Called instead of Display() when the window is hidden (e.g. when
   * ImGui::Begin() returns false).
   */
  virtual void Hidden();

  /**
   * Called from within ImGui::BeginContextPopupItem() and ImGui::EndPopup().
   * Used to display the settings for the view
   */
  virtual void Settings();

  /**
   * If the view has settings and if the result of Settings should be displayed.
   */
  virtual bool HasSettings();
};

/**
 * Make a View for a display functor.
 *
 * @param display Display function
 * @return unique_ptr to View
 */
std::unique_ptr<View> MakeFunctionView(
    wpi::util::unique_function<void()> display);

}  // namespace wpi::glass
