#ifndef THIRD_PARTY_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_TIMELINE_CONSTANTS_H_
#define THIRD_PARTY_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_TIMELINE_CONSTANTS_H_

#include "imgui.h"
#include "frontend/app/components/trace_viewer_v2/color/colors.h"
#include "frontend/app/components/trace_viewer_v2/trace_helper/trace_event.h"

namespace traceviewer {

// ImGUI uses float for drawing, so we use float for all pixel values.
using Pixel = float;

// Default colors
// go/keep-sorted start

// Black color with 100% opacity, rgba(0, 0, 0, 1).
inline constexpr ImU32 kBlackColor = IM_COL32(0, 0, 0, 255);
// Blue color with 100% opacity, rgba(0, 0, 255, 1).
inline constexpr ImU32 kBlueColor = IM_COL32(0, 0, 255, 255);
// Dark gray color for timing marker edges.
inline constexpr ImU32 kDarkGrayColor = IM_COL32(100, 100, 100, 255);
// A light gray line,  #E3E3E3 (GM3 Grey 90)
inline constexpr ImU32 kLightGrayColor = IM_COL32(0xE3, 0xE3, 0xE3, 255);
// Red color with 100% opacity, rgba(255, 0, 0, 1).
inline constexpr ImU32 kRedColor = IM_COL32(255, 0, 0, 255);
// Black color with 30% opacity for subtle dimming.
inline constexpr ImU32 kSubtleDimmingColor = IM_COL32(0, 0, 0, 77);
// White color with 30% opacity, rgba(255, 255, 255, 0.3).
inline constexpr ImU32 kTransparentWhiteColor = IM_COL32(255, 255, 255, 77);
// White color with 100% opacity, rgba(255, 255, 255, 1).
inline constexpr ImU32 kWhiteColor = IM_COL32(255, 255, 255, 255);
// go/keep-sorted end

// Counter Track Constants
// go/keep-sorted start
inline constexpr ImU32 kCounterTrackColor = kBlue80;
inline constexpr Pixel kCounterTrackHeight = 40.0f;
// go/keep-sorted end

// Ruler Constants
// These constants are used for drawing the timeline ruler.
// go/keep-sorted start
inline constexpr ImU32 kRulerLineColor = kOutlineVariantColor;
inline constexpr ImU32 kRulerTextColor = kOutlineColor;
inline constexpr ImU32 kTraceVerticalLineColor = kInverseOnSurfaceColor;
inline constexpr Pixel kMinTickDistancePx = 80.0f;
inline constexpr Pixel kRulerHeight = 20.0f;
// The height of the minor ticks on the ruler. Major ticks span the full height
// of the ruler.
inline constexpr Pixel kRulerMinorTickHeight = 8.0f;
// The buffer for drawing elements slightly off-screen to avoid pop-in.
inline constexpr Pixel kRulerScreenBuffer = 5.0f;
inline constexpr Pixel kRulerTextPadding = 2.0f;
inline constexpr int kMinorTickDivisions = 5;
// go/keep-sorted end

// Rendering Constants
// These constants are used for rendering flame chart events and track layout.
// go/keep-sorted start
inline constexpr ImDrawFlags kImDrawFlags = ImDrawFlags_RoundCornersDefault_;
inline constexpr ImU32 kDefaultTextColor = kBlackColor;
inline constexpr Microseconds kMinVisibleEventDuration = 1000.0;
inline constexpr Pixel kButtonGap = 4.0f;
inline constexpr Pixel kCornerRounding = 0.0f;
inline constexpr Pixel kDefaultLabelWidth = 250.0f;
inline constexpr Pixel kEventHeight = 23.0f;
inline constexpr Pixel kEventMinimumDrawWidth = 2.0f;
inline constexpr Pixel kEventPaddingBottom = 1.0f;
inline constexpr Pixel kEventPaddingRight = 1.0f;
// The size of the visual indent for nested groups in the timeline, indicating
// their nesting level.
inline constexpr Pixel kIndentSize = 10.0f;
inline constexpr Pixel kInstantEventChevronHalfWidth = 4.5f;
inline constexpr Pixel kInstantEventChevronHeight = 15.5f;
inline constexpr Pixel kInstantEventHoverChevronHalfWidth = 7.0f;
inline constexpr Pixel kInstantEventHoverChevronHeight = 20.0f;
inline constexpr Pixel kLabelPaddingLeft = 4.0f;
inline constexpr Pixel kMinTextWidth = 5.0f;
inline constexpr Pixel kMinUtilizationNormalization = 1.0f;
inline constexpr Pixel kProcessTrackGap = 7.0f;
inline constexpr Pixel kSplitterOffset = 4.0f;
inline constexpr Pixel kSplitterWidth = 8.0f;
inline constexpr Pixel kThreadTrackGap = 4.0f;
// Padding on the right to prevent content from touching the window edge.
inline constexpr Pixel kTimelinePaddingRight = 1.0f;
inline constexpr Pixel kToastCornerRounding = 4.0f;
inline constexpr Pixel kVirtualHeaderHeight = 30.0f;
inline constexpr double kEpsilon = 0.001;
// The scale factor applied to the font size to determine the arrow / icon size.
inline constexpr float kIconSizeScale = 0.7f;
// go/keep-sorted end

// Highlighting Constants
// go/keep-sorted start
inline constexpr ImU32 kCounterHoverColor = kBlue80;
inline constexpr ImU32 kHoverMaskColor = kTransparentWhiteColor;
inline constexpr ImU32 kSelectedBorderColor = kBlueColor;
inline constexpr Pixel kCounterHoverThickness = 3.5f;
inline constexpr Pixel kHoverCornerRounding = 4.0f;
inline constexpr Pixel kHoverPadding = 2.0f;
// The radius of the circle used to draw points in the counter track.
inline constexpr Pixel kPointRadius = 3.0f;
inline constexpr Pixel kSelectedBorderThickness = 2.0f;
inline constexpr Pixel kSelectedDataPointRadius = 4.0f;
// The opacity of the group preview (aggregated view) background.
inline constexpr float kGroupPreviewOpacity = 0.6f;
// go/keep-sorted end

// Process Track Constants
// go/keep-sorted start
inline constexpr ImU32 kProcessTrackCollapsedColor = kInverseOnSurfaceColor;
inline constexpr ImU32 kProcessTrackExpandedColor = kSecondaryContainerColor;
inline constexpr Pixel kProcessTrackHeight = 50.0f;
// go/keep-sorted end

// Nesting Level Constants
// go/keep-sorted start
inline constexpr int kCounterNestingLevel = 2;
inline constexpr int kHeaderNestingLevel = 0;
inline constexpr int kProcessNestingLevel = 1;
inline constexpr int kThreadNestingLevel = 2;
// go/keep-sorted end

// Virtual Header ID Constants
// go/keep-sorted start
inline constexpr int kAllHeaderId = 100000;
inline constexpr int kHiddenHeaderId = 200000;
inline constexpr int kPinnedHeaderId = 300000;
// go/keep-sorted end

// Time Range Selection Constants
// go/keep-sorted start
// A solid blue for the curtain border. #A1C9FFFF at 100% opacity.
inline constexpr ImU32 kSelectedTimeRangeColor = 0xFFFFC9A1;
inline constexpr ImU32 kSelectedTimeRangeResizeColor = kRedColor;
inline constexpr Pixel kSelectedTimeRangeTextBottomPadding = 10.0f;
inline constexpr Pixel kSelectedTimeRangeTextTopPadding = 5.0f;
// Default element dimensions
inline constexpr Pixel kSelectedTimeRangeThickness = 1.0f;
// The threshold in pixels within which the mouse is considered to be over an
// edge of a selected time range for resizing.
inline constexpr Pixel kSelectionEdgeThreshold = 5.0f;
// go/keep-sorted end

// Bookmark Constants
// go/keep-sorted start
inline constexpr ImU32 kBookmarkColor = kPink80;
inline constexpr Pixel kBookmarkLabelPadding = 4.0f;
inline constexpr Pixel kBookmarkThickness = 2.0f;
// go/keep-sorted end

// Close Button Constants
// go/keep-sorted start
inline constexpr ImU32 kCloseButtonColor = IM_COL32(128, 128, 128, 255);
inline constexpr ImU32 kCloseButtonHoverColor = IM_COL32(100, 100, 100, 255);
inline constexpr Pixel kCloseButtonPadding = 4.0f;
inline constexpr Pixel kCloseButtonSize = 14.0f;
inline constexpr Pixel kSelectedTimeRangeArrowHeadSize = 5.0f;
inline constexpr Pixel kSelectedTimeRangeArrowPadding = 4.0f;
// go/keep-sorted end

// Mouse Interaction Constants
// go/keep-sorted start
// If the mouse moves more than 5 pixels (5*5=25) between mouse down and mouse
// up, it's considered a drag, not a click.
inline constexpr float kClickDistanceThresholdSquared = 25.0f;
// go/keep-sorted end

// Zooming and Panning Constants
// These constants control the zooming and panning behavior of the timeline.
// go/keep-sorted start
// The rate at which panning/zooming speed increases per second after the
// initial delay.
inline constexpr float kAccelerateRate = 10.0f;
// The delay in seconds before panning/zooming acceleration takes effect.
inline constexpr float kAccelerateThreshold = 0.1f;
// The maximum factor by which the panning/zooming speed can be accelerated.
inline constexpr float kMaxAccelerateFactor = 30.0f;
// The minimum allowed zoom factor for the timeline. This prevents zooming in
// too much that time durations (mathmatically) become zero or negative.
inline constexpr float kMinZoomFactor = 0.001f;
// The sensitivity of zooming with the mouse wheel, measured in units per pixel.
inline constexpr float kMouseWheelZoomSpeed = 0.2f;
// The base speed of timeline panning, measured in pixels per second.
inline constexpr float kPanningSpeed = 1000.0f;
// The base speed of timeline scrolling, measured in pixels per second.
inline constexpr float kScrollSpeed = 160.0f;
// The multiplier applied to panning speed when Shift is held down (matches v1
// ratio: 0.5 / 0.3).
inline constexpr float kShiftPanAccelerateFactor = 0.5f / 0.3f;
// The multiplier applied to zooming speed when Shift is held down (matches v1
// ratio: 10 / 1.5).
inline constexpr float kShiftZoomAccelerateFactor = 10.0f / 1.5f;
// The base speed of timeline zooming, measured in units per second.
inline constexpr float kZoomSpeed = 1.5f;
// go/keep-sorted end

// Time Range Constants
// These constants are used for constraining the time range of the timeline.
// go/keep-sorted start
// The minimum duration of the visible time range in microseconds (= 1
// picosecond). This limits the maximum zoom-in level: time range duration
// cannot shrink below this value when zooming in.
inline constexpr Microseconds kMinDurationMicros = 1e-6;
// The minimum duration of a fetch request in microseconds.
// This is to prevent fetching too small chunks of data when the user
// zooms in very deep.
inline constexpr Microseconds kMinFetchDurationMicros = 1000.0;
// The ratio of the viewport width to fetch data for.
inline constexpr float kFetchRatio = 3.0f;
// The ratio of the viewport width to keep data loaded for.
inline constexpr float kPreserveRatio = 2.0f;
// If user zooms in more than this ratio from the time range of fetched data,
// refetch data to get higher resolution.
inline constexpr float kRefetchZoomRatio = 8.0f;
// go/keep-sorted end

// Event Navigation Constants
// These constants are used for zooming to an event.
// go/keep-sorted start
// The maximum duration to zoom to when navigating to an event (=5s).
inline constexpr Microseconds kEventNavigationMaxDurationMicros = 5000000.0;
// The minimum duration to zoom to when navigating to an event (=10us).
inline constexpr Microseconds kEventNavigationMinDurationMicros = 10.0;
// The factor by which to multiply event duration to determine viewport size.
inline constexpr double kEventNavigationZoomFactor = 2.5;
// go/keep-sorted end

// UI Strings Constants
// go/keep-sorted start
inline constexpr char kAllHeaderName[] = "All";
inline constexpr char kCannotHideLastProcessNotification[] =
    "Cannot hide the last visible process.";
inline constexpr char kCounterTooltipFormat[] = "Time: %s\nValue: %.2f";
inline constexpr char kHiddenHeaderName[] = "Hidden";
inline constexpr char kHiddenProcessNotificationPrefix[] = "Hidden process: ";
inline constexpr char kHideTrackTooltip[] = "Hide track";
inline constexpr char kPinTrackTooltip[] = "Pin track";
inline constexpr char kPinnedHeaderName[] = "Pinned";
inline constexpr char kPinnedProcessNotificationPrefix[] = "Pinned process: ";
inline constexpr char kUnhiddenProcessNotificationPrefix[] =
    "Unhidden process: ";
inline constexpr char kUnhideTrackTooltip[] = "Unhide track";
inline constexpr char kUnpinTrackTooltip[] = "Unpin track";
inline constexpr char kUnpinnedProcessNotificationPrefix[] =
        "Unpinned process: ";
// go/keep-sorted end
}  // namespace traceviewer

#endif  // THIRD_PARTY_XPROF_FRONTEND_APP_COMPONENTS_TRACE_VIEWER_V2_TIMELINE_CONSTANTS_H_
