import { getChromeStorage } from '@/uilts/chromeExtension.js'
import { payAchNoticeUrl } from '@/http/configAPI'

export const closeAchPayNoticeHandler = async () => {
    let res = await getCurrentTab();
    if(res.url.startsWith(payAchNoticeUrl)) {
        chrome.tabs.remove(
            res.id, () => {
                getChromeStorage('achPayInfo', (result) => {
                    let {tab} = result || {};
                    chrome.storage.local.remove("achPayInfo");
                    if(tab) {
                        chrome.tabs.highlight({ windowId: tab.windowId, tabs: tab.index })
                    }
                })
            }
        )
    }
}

const getCurrentTab = async () => {
    let queryOptions = { active: true, lastFocusedWindow: true };
    let [tab] = await chrome.tabs.query(queryOptions);
    return tab || {};
}
