declare global {
    interface Window {
        umami?: {
            track: (name: string, data?: Record<string, any>) => Promise<void>
            identify: (id: string, data?: Record<string, any>) => Promise<void>
        }
    }
}

export function wtEvent(eventName: string, data?: Record<string, any>) {
    console.log('[WATCHTOWER] Event:', eventName, data)
    window.umami?.track(eventName, data).catch((error) => {
        console.error('[WatchTower] Event Failed:', { eventName, data }, error)
    })
}

// // Do not use, this goes against the privacy policy!
// export function wtIdentify(who: string | number, data?: object) {
//     console.log('[WATCHTOWER] Identify:', who, data)
//     window.umami?.identify(String(who), data).catch((error) => {
//         console.error('[WatchTower] Identify Failed:', { who, data }, error)
//     })
// }

// Not yet in service!
// if (import.meta.env.PROD) {
//     const script = document.createElement('script')
//     script.defer = true
//     script.src = 'https://watchtower.pancakz.net/script.js'
//     script.dataset.websiteId = '...'
//     document.body.appendChild(script)
// }
