import './index.css';
import { handleIpc } from 'tur-toolkit'
declare const window: any

//window.document.getElementById('contentFrame').addEventListener('ipc-message', console.log)

handleIpc((event, source) => {
    console.log(event, source)
    switch(event.data.type){
        case "Navigation":
        httxrpNavigate(event.data.data)
        break;

        case "Transaction":
        break;

        default:
        return;
    }
})

const httxrpNavigate = async (resourceHash: string) => {
    try{
        const path = await window.electronAPI.xrpioDownload(resourceHash)
        window.document.getElementById('contentFrame').setAttribute("src", `file://${path}`);
    }catch(err){
        console.log(err)
    }
}
window.httxrpNavigate = httxrpNavigate

window.document.getElementById('searchButton').addEventListener('click', async () => {
    await window.httxrpNavigate(window.document.getElementById('searchBar').value)
})