#pragma once
// Spec: SPEC.md UX-VIEWS-02. Form-style controls: Toggle, menu Picker, compact DatePicker, Form sections,
// TabView, character counter helpers. Metrics in spec/Layout.hpp.
#include <functional>
#include <string>
#include <vector>
#include "ui/Overlays.hpp"
#include "ui/Views.hpp"
namespace dp::ui {
// Wrap a view so a tap reports its on-screen rect (anchors for menus and popovers).
ViewPtr OnTapRect(ViewPtr content, std::function<void(Rect)> handler);
ViewPtr Switch(BoolBinding value, Color tint);
ViewPtr Toggle(ViewPtr label, BoolBinding value, Color tint);
struct PickerOption {
std::string title;
int tag = 0;
};
// SwiftUI Picker with the default (menu) style inside a form row.
ViewPtr MenuPicker(ViewPtr label, std::vector<PickerOption> options, int selectedTag, std::function<void(int)> onSelect);
struct CivilDate {
int year = 2000;
unsigned month = 1;
unsigned day = 1;
bool operator==(const CivilDate&) const = default;
static CivilDate today();
bool after(const CivilDate& o) const;
};
// Compact date picker; selection limited to dates up to `maxDate`.
ViewPtr DatePicker(ViewPtr label, std::function<CivilDate()> get, std::function<void(CivilDate)> set, CivilDate maxDate);
struct FormSection {
std::string header;
std::string footer;
std::vector<ViewPtr> rows;
};
// Inset grouped form (rounded cards on BG_2, rows on BG_1) inside a vertical ScrollView.
ViewPtr Form(std::vector<FormSection> sections, ScrollOptions scroll = {});
// A card of stacked rows (separators between), used by Form and by custom screens.
ViewPtr GroupedCard(std::vector<ViewPtr> rows, Color background);
ViewPtr FormRow(ViewPtr content); // horizontal padding 16, min height 44
struct TabItem {
std::string title;
std::string icon;
int badge = 0;
std::function<ViewPtr()> content;
};
// Bottom tab bar plus selected content. `onReselect` fires when the selected tab is tapped again.
ViewPtr TabView(std::vector<TabItem> tabs, int selected, std::function<void(int)> onSelect,
std::function<void(int)> onReselect);
// "12/500" character counter (monospaced 12, FG_2, red when out of range).
ViewPtr CharacterCounter(int count, int maxCount, int minCount = -1);
} // namespace dp::ui