/**
 * Konva Transformer style + behavior shared by ImageElement and TextElement.
 *
 * Before this module: both files independently declared identical
 * `ROTATION_SNAPS_15` arrays and identical visual config (anchor size /
 * stroke / fill / corner radius / rotate-anchor offset). Two sites with
 * the same constants is a drift risk — and the brand pink (#ec4899) was
 * spelled as a literal in both rather than referenced from anywhere
 * central.
 *
 * Centralizing here means changing the brand pink, the snap granularity,
 * or the anchor look-and-feel is a one-file edit. Per-element behavior
 * (the bound functions, lock state, ratio-keep logic) stays at the call
 * site since those legitimately differ.
 */

// Pre-computed rotation snap angles — every 15°. Used when the user holds
// shift while rotating, so multi-element layouts can be aligned to common
// angles without pixel-perfect dragging. We exclude 360 because Konva's
// Transformer normalizes 360 → 0 anyway.
export const ROTATION_SNAPS_15 = (() => {
  const out = [];
  for (let a = 0; a < 360; a += 15) out.push(a);
  return out;
})();

// Angular window inside which Konva pulls the rotation to the nearest
// snap when shift is held. 7° gives a comfortable "magnetic" feel
// without making it hard to land between snaps.
export const ROTATION_SNAP_TOLERANCE = 7;

// Corner-only anchors. Combined with `keepRatio` on the consumer this
// gives uniform scaling that always preserves aspect ratio — what we
// want for both photos (no squish) and text (no letter-stretching).
export const CORNER_ANCHORS = ['top-left', 'top-right', 'bottom-left', 'bottom-right'];

// Visual style for selection bbox + handles. Spread into the Transformer
// element at the call site. `borderDash` is intentionally NOT here
// because it varies (solid for unlocked, dashed when locked), and is a
// per-render decision.
//
// `rotateAnchorOffset` controls the distance (in design-coord px) between
// the top edge of the bbox and the rotate handle. Was 28 originally,
// which created a visible gap between the element and its rotate handle
// that read as "the rotate handle belongs to no one" — especially after
// the move to a dedicated transformer layer, where the handle floats
// above unrelated content in z-order and the long offset made the
// association ambiguous. 14 keeps the handle clearly outside the bbox
// border (so it doesn't overlap a corner anchor at typical zoom levels)
// while making the "this handle controls THIS element" association
// unambiguous. Reduce further only if corner anchors and the rotate
// handle start visually colliding for very small elements; the current
// value tested fine across the editor's MIN_ELEMENT_SIZE (20px) range.
export const TRANSFORMER_VISUAL_STYLE = {
  anchorSize: 9,
  anchorCornerRadius: 6,
  borderStroke: '#ec4899',
  borderStrokeWidth: 1.5,
  anchorStroke: '#ec4899',
  anchorFill: '#ffffff',
  rotateAnchorOffset: 14,
};
