import { BufferGeometry, Float32BufferAttribute } from 'three'

/**
 * Creates a simple 2D arrow geometry
 * Arrow points upward (positive Y) when not rotated
 * Centered at origin for easy rotation
 */
export function createArrowGeometry() {
    const geometry = new BufferGeometry()

    // Define arrow shape vertices
    // Arrow pointing up: tip at (0, 0.5), base at y = -0.5
    const vertices = new Float32Array([
        // Triangle 1: Left side of arrowhead
        0.0, 0.5, 0.0,      // Tip
        -0.2, 0.1, 0.0,     // Left arrowhead point
        -0.1, 0.1, 0.0,     // Left shaft top

        // Triangle 2: Right side of arrowhead
        0.0, 0.5, 0.0,      // Tip
        -0.1, 0.1, 0.0,     // Left shaft top
        0.1, 0.1, 0.0,      // Right shaft top

        // Triangle 3: Right arrowhead point
        0.0, 0.5, 0.0,      // Tip
        0.1, 0.1, 0.0,      // Right shaft top
        0.2, 0.1, 0.0,      // Right arrowhead point

        // Triangle 4: Shaft left side
        -0.05, 0.1, 0.0,     // Left shaft top
        -0.05, -0.3, 0.0,    // Left shaft bottom
        0.05, 0.1, 0.0,      // Right shaft top

        // Triangle 5: Shaft right side
        0.05, 0.1, 0.0,      // Right shaft top
        -0.05, -0.3, 0.0,    // Left shaft bottom
        0.05, -0.3, 0.0,     // Right shaft bottom
    ])

    geometry.setAttribute('position', new Float32BufferAttribute(vertices, 3))

    // Compute normals for proper lighting (if needed later)
    geometry.computeVertexNormals()

    return geometry
}
