/*
RSK World – Tower Defense 3D (Path)
For support, licensing, or custom development inquiries: help@rskworld.in • Phone/WhatsApp: +91 9330539277
Website: RSK World • Business Inquiries: help@rskworld.in
🤝 Contributing: Suggestions and improvements are welcome!
*/

import * as THREE from 'three';

export function createDefaultPath() {
	const points = [
		new THREE.Vector3(-50, 0, -40),
		new THREE.Vector3(-40, 0, -20),
		new THREE.Vector3(-30, 0, 0),
		new THREE.Vector3(-10, 0, 10),
		new THREE.Vector3(10, 0, 8),
		new THREE.Vector3(25, 0, -5),
		new THREE.Vector3(35, 0, -20),
		new THREE.Vector3(45, 0, -5),
		new THREE.Vector3(40, 0, 15),
		new THREE.Vector3(20, 0, 30),
		new THREE.Vector3(0, 0, 40),
		new THREE.Vector3(-10, 0, 45),
		new THREE.Vector3(-30, 0, 50),
	];
	return points;
}

export function createPathLine(points) {
	const geometry = new THREE.BufferGeometry().setFromPoints(points);
	const material = new THREE.LineBasicMaterial({ color: 0x334155 });
	const line = new THREE.Line(geometry, material);
	line.position.y = 0.05;
	return line;
}

export function createOffsetPath(points, offset) {
	const result = [];
	for (let i = 0; i < points.length; i++) {
		const prev = points[Math.max(0, i - 1)];
		const next = points[Math.min(points.length - 1, i + 1)];
		const dir = new THREE.Vector3().subVectors(next, prev).setY(0);
		if (dir.lengthSq() < 1e-6) { result.push(points[i].clone()); continue; }
		dir.normalize();
		const normal = new THREE.Vector3(-dir.z, 0, dir.x).normalize();
		const p = points[i].clone().addScaledVector(normal, offset);
		result.push(p);
	}
	return result;
}
