import { ElMessage } from "element-plus";

const useItem = (itemId: string) => {
    fetch(window.addRFC("https://www.torn.com/item.php"), {
        "headers": {
            "accept": "*/*",
            "content-type": "application/x-www-form-urlencoded;charset=UTF-8",
            "sec-ch-ua-mobile": "?0",
            "sec-fetch-dest": "empty",
            "sec-fetch-mode": "cors",
            "sec-fetch-site": "same-origin",
            "x-requested-with": "XMLHttpRequest"
        },
        "referrer": "https://www.torn.com/item.php",
        "referrerPolicy": "strict-origin-when-cross-origin",
        "body": `step=useItem&id=${ itemId }&itemID=${ itemId }`,
        "method": "POST",
        "mode": "cors",
        "credentials": "include"
    })
        .then(res => res.json())
        .then(res => ElMessage({
            message: res.text,
            type: res.success ? 'success' : 'error',
            dangerouslyUseHTMLString: true
        }))
        .catch(e => ElMessage({
            message: e.toString,
            type: 'error'
        }));
};

export default useItem;
