use eyre::Result;
use reqwest;
use scraper::{Html, Selector};
pub(crate) async fn extract_etherscan_tx_details(tx_hash: &str,chain : String ) -> Result<(String, u64)> {
let url = format!("https://{}.etherscan.io/tx/{}", chain, tx_hash);
println!("The url : {}", url);
let client = reqwest::Client::new();
let response = client.get(&url)
.header("User-Agent", "Mozilla/5.0")
.send()
.await
.map_err(|e| eyre::eyre!("Failed to fetch Etherscan page: {}", e))?;
println!("Response status: {}", response.status());
let body = response.text().await
.map_err(|e| eyre::eyre!("Failed to read response body: {}", e))?;
let document = Html::parse_document(&body);
let timestamp = 0;
let input_selector = Selector::parse("#inputdata").unwrap();
let input_elem = document.select(&input_selector).next()
.ok_or_else(|| eyre::eyre!("Could not find input data"))?;
let input_text = input_elem.text().collect::<String>();
println!("Found Transaction input: {:#?}", &input_text);
let input = &input_text[8..];
Ok((input.to_string(), timestamp))
}