import { fetchAddFinishEvent } from '@/logic/background/fetch/facebook'

/**
 * facebook分享成功逻辑
 */
export function facebookShareSuccess(params, sender) {
    let {data} = params;
    let {id} = sender.tab || {};
    chrome.tabs.remove(id);

    fetchAddFinishEvent({
        eventType: data.type,
        luckdropId: data.taskLuckdropId
    }).then(res => {
        if (res.code == 0) {
            setTimeout(() => {
                sendActivetabMessage({
                    actionType: 'BG_FACEBOOK_SHARE_SUCCESS',
                    data: data
                });
            })
        }
    })
}


function sendActivetabMessage(message = {}) {
    chrome.tabs.query({
        active: true,
        currentWindow: true
    }, (tabs) => {
        chrome.tabs.sendMessage(tabs[0].id, message, res => {
            console.log(res)
        })
    })
}