const outputContainer = document.getElementById("outputContainer");
const userInput = document.getElementById("userInput");
const initialMessage = document.getElementById("initialMessage");
const infoPopup = document.getElementById("infoPopup");
const popupText = document.getElementById("popupText");
const closeButton = document.getElementById("closeButton");


let lastCommandTime = 0;
let fadeTimeout = null;

function appendText(text, isNewCommand = false, isRisky = false) {
  // Create the message div
  const message = document.createElement("div");
  message.innerHTML = `<span>C:\\></span> ${text}`;
  
  // Apply risky styling if needed
  if (isRisky) {
    message.classList.add("risky");
  }

  // Add the message to the container
  outputContainer.appendChild(message);

  // Ensure that the new message stays at the bottom
  outputContainer.scrollTop = outputContainer.scrollHeight;
  
  // Focus back to the input
  userInput.focus();  

  // Handle new command and fading
  if (isNewCommand) {
    // Clear any previous fade-out timeout
    clearTimeout(fadeTimeout);
    fadeTimeout = setTimeout(fadeOldMessages, 0); // Start fade-out in 5 seconds
  }
}

function fadeOldMessages() {
  const allMessages = outputContainer.getElementsByTagName("div");
  const messageArray = Array.from(allMessages);

  // Remove all except the last command (the newest one)
  for (let i = 0; i < messageArray.length - 1; i++) {
    const message = messageArray[i];
    message.classList.add("fade-out"); // Fade the previous message
  }

  // After the fade-out completes, remove the faded ones
  setTimeout(() => {
    // Remove all the faded messages
    const fadedMessages = outputContainer.getElementsByClassName("fade-out");
    while (fadedMessages.length > 0) {
      fadedMessages[0].remove(); // Remove each faded message
    }
  }, 2000); // Time for fade-out to complete
}

function showTabFeatures(tab) {
  let output = '';
  switch (tab) {
    case "main":
      output = `
1. Main
<ul class="feature-list">
    <li>+ Silent aim</li>
    <li>- Fov (Color picker)</li>
    <li>- Hit Parts ( UpperTorso, Random, Head )</li>
    <li>- Prediction</li>
    <li>- Team-Check</li>
    <li>- Target NPCS</li>
    <li>- FOV CIRCLE SIZE(1-350)</li>
    <li>- Snapline</li>
    <li>- Prediction Dot</li>
    <li>____________________________</li>
    <li>+ Gun Mods</li>
    <li>- No Recoil</li>
    <li>- recoil % (1-100)</li>
    <li>- No Spread</li>
    <li>- No Spread % (1-100)</li>
    <li>- Fast Firerate (1x - 2x)</li>
    <li>- Fast Bullet</li>
    <li>- No gun slowdown</li>
    <li>- No bullet drop</li>
    <li>- Instant Aim-Downsights</li>
    <li>- Instant bolt</li>
    <li>- always automatic</li>
    <li>- always hit headshot</li>
    
</ul>`;
      break;
    case "visuals":
      output = `
2. Visuals
<ul class="feature-list">
    <li>+ ESP (Box, Name, Healthbar, Skeletons)</li>
    <li>- Chams</li>
    <li>- Chams Transparency Slider</li>
    <li>- Chams outline transparency slider</li>
    <li>- Chams mode ( Always on top, Visible only )</li>
    <li>_________________________________________________</li>
    <li>+ Objects ESP</li>
    <li>- Animal ESP</li>
    <li>- Dropped item ESP</li>
    <li>- Plants ESP</li>
    <li>- Soldier ESP</li>
    <li>- BOSS ESP</li>
    <li>- Body Bag ESP</li>
    <li>- Crates ESP</li>
    <li>- Gifts ESP</li>
    <li>- Node ESP</li>
    <li>- Object distance slider</li>
    <li>_____________________________ </li>
    <li>+ World</li>
    <li>- No Fog</li>
    <li>- Fullbright</li>
    <li>- Ambience</li>
    <li>- No Grass</li>
    <li>_____________________________</li>
    <li>+ Trace</li>
    <li>- Hitmarkers</li>
    <li>- Hitmarker Lifetime (1-15s)</li>
    <li>- Melee Tracers</li>
    <li>- melee Tracers Lifetime(1-15s)</li>
    <li>- Bullet Tracers</li>
</ul>`;
      break;
    case "misc":
      output = `
3. Misc
<ul class="feature-list">
    <li>+ Exploits</li>
    <li>- No Viewmodel bob</li>
    <li>- No camera shake</li>
    <li>- Instant equip</li>
    <li>- Sprint while attacking</li>
    <li>- Instant loot</li>
    <li>- Always perfect farm</li>
    <li>- Silent walk</li>
    <li>- clapping cheeks (wont be on menu on release)</li>
    <li>- No trap damage</li>
    <li>- No touch parts damage</li>
    <li>_____________________________</li>
    <li>+ Melee</li>
    <li>- Extend melee range</li>
    <li>- Extend melee range slider ( 1x to 2x )</li>
    <li>_______________________________________________</li>
    <li>+ miscellaneous</li>
    <li>- Mod Detector ( Kick / Notify )</li>
    <li>- Xray</li>
    <li>- Xray keybind</li>
    <li>- Loot through door</li>
    <li>- Loot through door keybind</li>
</ul>`;
      break;
    case "localplayer":
      output = `
4. LocalPlayer
<ul class="feature-list">
    <li>+ Movement</li>
    <li>- Spiderman</li>
    <li>- Spiderman Keybind</li>
    <li>- Lagback Visualizer</li>
    <li>_______________________</li>
    <li>+ Local Chams</li>
    <li>- Local chams enabled</li>
    <li>- Local Chams material</li>
    <li>- Local Chams color enabled</li>
    <li>- Local Chams color</li>
</ul>`;
      break;
    case "settings":
      output = `
5. Settings
<ul class="feature-list">
    <li>+ Configs</li>
    <li>- Save Config</li>
    <li>- Delete Config</li>
    <li>- Load Config</li>
    <li>- Create Config</li>
    <li>____________________</li>
    <li>+ UI keybind</li>
    <li>- UI keybind - Keybind</li>
</ul>`;
      break;
    default:
      output = `'${tab}' is not recognized as an internal or external command, operable program or batch file.`;
  }
  appendText(output, true); // Mark it as a new command
}

function displayFishyInfo() {
  // Display information about Fishy in the popup
  const fishyInfo = `
Information about Fishy:
<ul>
    <li>Fishy is a undetected script for Fallen Survival.</li>
    <li>Fishy Works for awp.gg And Wave.</li>
    <li>Fishy strives to provide user satisfaction and safety. As you may have seen the website has a code..</li>
    <li>We are a team of developers who want to provide nothing but the best for our community.</li>
    <li>Please note that nothing on this page is final and fishy resides the right to remove or discontiue at any time.</li>
    <li>WARNING: Fishy is undetected, And we would never amount to anything less.</li>
</ul>
`;

  popupText.innerHTML = fishyInfo;  // Set the info text inside the popup
  infoPopup.classList.add("show");  // Show the popup with fade-in effect
}



function handleInput(input) {
  const trimmedInput = input.trim().toLowerCase();

  if (trimmedInput === "help") {
    appendText(`
Available options:
1. Main
2. Visuals
3. Misc
4. LocalPlayer
5. Settings
Type 'info' for Fishy info.
Select Number:`, true);
  } else if (["1", "main"].includes(trimmedInput)) {
    showTabFeatures("main");
  } else if (["2", "visuals"].includes(trimmedInput)) {
    showTabFeatures("visuals");
  } else if (["3", "misc"].includes(trimmedInput)) {
    showTabFeatures("misc");
  } else if (["4", "localplayer"].includes(trimmedInput)) {
    showTabFeatures("localplayer");
  } else if (["5", "settings"].includes(trimmedInput)) {
    showTabFeatures("settings");
  } else if (trimmedInput === "clear") {
    clearConsole();
  } else if (trimmedInput === "info") {
    displayFishyInfo();  // New 'info' command
  } else if (trimmedInput === "") {
    appendText("", true);  // Do nothing if input is empty
  } else {
    appendText(`'${input}' is not recognized as an internal or external command, operable program or batch file.`, true, true);
  }
}

function clearConsole() {
  outputContainer.innerHTML = '';  // Clear everything inside the output container
}

function init() {
  appendText("Type Help");
  initialMessage.style.display = 'none';  // Hide initial message after it's been shown once
}

userInput.addEventListener("keydown", function(event) {
  if (event.key === "Enter") {
    const input = userInput.value.trim();
    if (input !== "") {
      handleInput(input);
      userInput.value = "";  // Clear the input after each command
      lastCommandTime = Date.now();  // Update the timestamp for the last command
    }
  }
});

// Close the info popup when the button is clicked
closeButton.addEventListener("click", function() {
  infoPopup.classList.remove("show");  // Hide the popup with fade-out effect
});


init();
