// =========================================================================
// KALASUTRA V3 — TRANSIT TARA BALA
// Cross-references the user's birth star (Janma Nakshatra) against the
// current transit Moon's star. Same 9-fold Tara cycle math as v2's
// backtest.js renderTransitTable().
// =========================================================================

import { getNakIdx, getPada, NAK_NAMES } from './kp-core.js';

const TARA = ["Janma (Danger)", "Sampat (Wealth)", "Vipat (Loss)", "Kshema (Prosperity)", "Pratyak (Obstacles)", "Sadhana (Achievement)", "Naidhana (Death/Danger)", "Mitra (Friend)", "Parama Mitra (Great Friend)"];
const FAVORABLE_TARA_IDX = [1, 3, 4, 5, 7, 8]; // Sampat, Kshema, Sadhana, Mitra, Parama Mitra

/**
 * @param {number} birthMoonLong  natal Moon sidereal longitude
 * @param {number} transitMoonLong current transit Moon sidereal longitude
 */
export function getTransitTaraBala(birthMoonLong, transitMoonLong) {
    const birthNak = getNakIdx(birthMoonLong);
    const transitNak = getNakIdx(transitMoonLong);
    const taraIdx = (transitNak - birthNak + 27) % 9;
    return {
        birthNakshatra: NAK_NAMES[birthNak],
        transitNakshatra: NAK_NAMES[transitNak],
        transitPada: getPada(transitMoonLong),
        taraIdx,
        tara: TARA[taraIdx],
        favorable: FAVORABLE_TARA_IDX.includes(taraIdx)
    };
}
