<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <title>ClipboardSlL</title>

    <!-- Favicon and Icons -->
    <link rel="icon" href="https://i.imgur.com/wc0PQyk.png">
    <!-- Apple Touch Icon -->
    <link rel="apple-touch-icon" href="https://i.imgur.com/wc0PQyk.png">
    <!-- Android Icon -->
    <link rel="icon" type="image/png" href="https://i.imgur.com/wc0PQyk.png">
    <!-- Windows 10/11 Icon -->
    <meta name="msapplication-TileColor" content="#000000">
    <meta name="msapplication-TileImage" content="https://i.imgur.com/wc0PQyk.png">
    <meta name="theme-color" content="#000000">
    
    <!-- Manifest for Progressive Web App (PWA) -->
    <link rel="manifest" href="manifest.json">

    <style>
      * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
      }

      body {
        font-family: 'Arial', sans-serif;
        background-color: #000;
        color: #fff;
        display: flex;
        flex-direction: column;
        justify-content: flex-start;
        align-items: center;
        height: 100vh;
        margin: 0;
        padding: 20px;
      }

      .header {
        width: 100%;
        display: flex;
        justify-content: space-between;
        align-items: center;
        margin-bottom: 20px;
      }

      h1 {
        font-size: 24px;
        color: #ff0000;
      }

      .button {
        background-color: #111;
        color: #fff;
        border: 2px solid #ff0000;
        border-radius: 50%;
        width: 50px;
        height: 50px;
        display: flex;
        justify-content: center;
        align-items: center;
        cursor: pointer;
        font-size: 30px;
        box-shadow: 0 0 10px rgba(255, 0, 0, 0.7);
      }

      .items-container {
        width: 100%;
        max-width: 600px;
        text-align: center;
        margin-top: 30px;
      }

      .item {
        background: #111;
        padding: 10px;
        margin: 10px 0;
        border-radius: 5px;
        border: 2px solid #ff0000;
        position: relative;
        display: flex;
        justify-content: space-between;
        align-items: center;
      }

      .item button {
        background: #ff0000;
        color: #000;
        border: none;
        padding: 5px 10px;
        border-radius: 5px;
        cursor: pointer;
      }

      .item .preview {
        display: none;
        margin-top: 10px;
        background: #222;
        padding: 10px;
        border-radius: 5px;
      }

      .item.show-preview .preview {
        display: block;
      }

      .item input[type="checkbox"] {
        margin-left: 10px;
      }

      .footer {
        margin-top: 30px;
        text-align: center;
        color: #ff0000;
      }

      .footer a {
        color: #ff0000;
        text-decoration: none;
      }

      /* Delete button container */
      .delete-container {
        margin-top: 20px;
        text-align: center;
        display: none; /* Initially hidden */
      }

      .delete-container button {
        background-color: #ff0000;
        color: #fff;
        border: none;
        padding: 10px 20px;
        font-size: 16px;
        cursor: pointer;
        border-radius: 5px;
        display: inline-block;
      }

      /* Mobile responsive */
      @media (max-width: 768px) {
        body {
          align-items: flex-start;
        }

        .header {
          flex-direction: column;
        }

        h1 {
          font-size: 20px;
          margin-bottom: 15px;
        }

        .button {
          margin-top: 10px;
        }

        .items-container {
          width: 100%;
        }

        .item {
          padding: 15px;
        }
      }
      
      .footer-i {
      font-size: 0.6em; /* Very small text */
      color: #fff; /* White text */
      text-align: center;
      position: center;
      bottom: 0;
      width: 100%;
      padding: 5px;
    }
    
    .link {
      text-decoration: none;
      color: green;
      }
      .link2 {
      text-decoration: none;
      color: #FF6250;
      }
    </style>
  </head>
  <body>
    <div class="header">
      <h1>ClipboardSlL</h1>
      <div class="button" id="addItemButton">+</div>
    </div>

    <div class="items-container" id="itemsContainer">
      <div class="footer">
        <p id="instructions">There’s no items here please add some first by pressing the (+) button.</p>
      </div>
    </div>

    <div class="delete-container" id="deleteContainer">
      <button id="deleteSelectedButton">Delete Selected Items</button>
    </div>
<div class="footer-i">
    Created by <strong><a class="link" href="https://github.com/Maskedlll">Masked</a></strong> helped by <strong><a class="link2" href="https://github.com/SeojinLove">Seojin Yoon</a></strong>
  </div>
</div>
    <script>
      const addItemButton = document.getElementById('addItemButton');
      const itemsContainer = document.getElementById('itemsContainer');
      const instructions = document.getElementById('instructions');
      const deleteContainer = document.getElementById('deleteContainer');
      const deleteSelectedButton = document.getElementById('deleteSelectedButton');

      const loadItems = () => {
        const items = JSON.parse(localStorage.getItem('clipboardItems')) || [];

        if (items.length === 0) {
          instructions.textContent = "There’s no items here please add some first by pressing the (+) button.";
          deleteContainer.style.display = 'none';
        } else {
          instructions.textContent = "";
          deleteContainer.style.display = 'none'; // Initially hidden
          itemsContainer.innerHTML = items.map((item, index) => `
            <div class="item" data-index="${index}">
              <div>${item}</div>
              <button class="copyButton" onclick="copyItem(${index})">Copy</button>
              <div class="preview">${item}</div>
              <button onclick="togglePreview(${index})">Show full preview</button>
              <input type="checkbox" class="deleteCheckbox" data-index="${index}" onclick="toggleDeleteState()">
            </div>
          `).join('');
        }
      };

      const addItem = () => {
        const newItem = prompt('Enter the item to save:');
        if (newItem) {
          const items = JSON.parse(localStorage.getItem('clipboardItems')) || [];
          items.push(newItem);
          localStorage.setItem('clipboardItems', JSON.stringify(items));
          loadItems(); // Reload items after adding
        }
      };

      const copyItem = (index) => {
        const items = JSON.parse(localStorage.getItem('clipboardItems'));
        const itemToCopy = items[index];
        navigator.clipboard.writeText(itemToCopy).then(() => {
          alert('Item copied to clipboard!');
        });
      };

      const togglePreview = (index) => {
        const itemElement = document.querySelector(`.item[data-index="${index}"]`);
        itemElement.classList.toggle('show-preview');
      };

      // Disable zooming
      const metaViewport = document.querySelector("meta[name=viewport]");
      if (metaViewport) {
        metaViewport.setAttribute("content", "width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no");
      }

      document.addEventListener("touchstart", (event) => {
        if (event.touches.length > 1) {
          event.preventDefault();
        }
      });

      document.addEventListener("gesturestart", (event) => {
        event.preventDefault();
      });

      const toggleDeleteState = () => {
        const checkboxes = document.querySelectorAll('.deleteCheckbox');
        const selectedCount = Array.from(checkboxes).filter(checkbox => checkbox.checked).length;
        deleteSelectedButton.textContent = selectedCount === 0 ? 'Delete Selected Items' : `Delete (${selectedCount})`;

        // Show or hide the delete container based on selected items
        if (selectedCount > 0) {
          deleteContainer.style.display = 'block';
        } else {
          deleteContainer.style.display = 'none';
        }
      };

      const deleteSelectedItems = () => {
        const checkboxes = document.querySelectorAll('.deleteCheckbox:checked');
        const itemsToDelete = Array.from(checkboxes).map(checkbox => parseInt(checkbox.getAttribute('data-index')));

        if (itemsToDelete.length > 0) {
          const confirmation = confirm(`Are you sure you want to delete ${itemsToDelete.length} item(s)?`);
          if (confirmation) {
            let items = JSON.parse(localStorage.getItem('clipboardItems')) || [];
            items = items.filter((_, index) => !itemsToDelete.includes(index));
            localStorage.setItem('clipboardItems', JSON.stringify(items));
            loadItems(); // Reload items immediately after deletion
            if (items.length === 0) {
              window.location.reload(); // Reload the page if the list is empty
            }
          }
        }
      };

      // Button to add item
      addItemButton.addEventListener('click', addItem);

      // Delete selected items
      deleteSelectedButton.addEventListener('click', deleteSelectedItems);

      // Load items when the page loads
      window.onload = loadItems;
    </script>
  </body>
</html>