// /linkstorm/api.js

// Local token storage (browser only for now)
function saveFBToken() {
  const token = document.getElementById("fbToken").value;
  localStorage.setItem("facebook_token", token);
  alert("Facebook token saved!");
}

function saveTwitterToken() {
  const token = document.getElementById("twitterToken").value;
  localStorage.setItem("twitter_token", token);
  alert("Twitter token saved!");
}

function saveLinkedInToken() {
  const token = document.getElementById("linkedinToken").value;
  localStorage.setItem("linkedin_token", token);
  alert("LinkedIn token saved!");
}

// Example API posting functions (you'd plug real APIs / OAuth here)
function postToFacebookAPI(link, token) {
  fetch("https://graph.facebook.com/me/feed", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${token}`,
      "Content-Type": "application/json"
    },
    body: JSON.stringify({
      message: "Check this out!",
      link: link
    })
  })
    .then(r => r.json())
    .then(() => alert("Posted to Facebook via API!"))
    .catch(err => alert("Error posting to Facebook: " + err));
}

function postToTwitterAPI(link, token) {
  // Placeholder for a real Twitter/X API integration
  console.log("Would post to Twitter with token: ", token, "link:", link);
  alert("Twitter API posting not fully implemented (demo).");
}

function postToLinkedInAPI(link, token) {
  // Placeholder for LinkedIn API integration
  console.log("Would post to LinkedIn with token: ", token, "link:", link);
  alert("LinkedIn API posting not fully implemented (demo).");
}
