import { EDITOR_CONSTANTS } from "@/features/editor/config/constants";

export function splitLines(content: string): string[] {
  return content.split(/\r?\n/);
}

export function calculateLineHeight(
  fontSize: number,
  lineHeight: number = EDITOR_CONSTANTS.LINE_HEIGHT_MULTIPLIER,
): number {
  // Use Math.ceil to match getLineHeight() in position.ts
  // Fractional line-height causes subpixel misalignment between layers
  return Math.ceil(fontSize * lineHeight);
}

export function calculateLineOffset(lines: string[], lineIndex: number): number {
  return lines.slice(0, lineIndex).reduce((acc, line) => acc + line.length + 1, 0);
}

export function isMarkdownFile(filePath: string): boolean {
  const extension = filePath.split(".").pop()?.toLowerCase();
  return extension === "md" || extension === "markdown";
}
