body {
font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
margin: 0;
padding: 0;
background-color: #f4f4f4;
color: #333;
display: flex;
flex-direction: column;
min-height: 100vh;
}
header {
background-color: #e06666; /* Ciemniejszy czerwony */
color: white;
padding: 1rem 0;
text-align: center;
box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}
h1, h2, h3 {
text-align: center;
color: #c00; /* Czysta czerwień */
}
.container {
display: flex;
flex-wrap: wrap; /* Pozwala na zawijanie elementów na mniejszych ekranach */
flex-grow: 1; /* Pozwala sekcji content zająć całą dostępną przestrzeń */
padding: 20px;
gap: 20px; /* Odstępy między panelami */
}
.panel {
background-color: white;
padding: 15px;
border-radius: 8px;
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
overflow-y: auto; /* Dodaje pasek przewijania, jeśli zawartość jest za długa */
}
/* Panele boczne */
.guest-panel, .table-panel {
flex: 1; /* Zajmują równą ilość miejsca */
min-width: 250px; /* Minimalna szerokość */
max-height: 70vh; /* Ograniczenie wysokości */
}
/* Główny panel wizualny */
.visual-panel {
flex: 3; /* Zajmuje 3 razy więcej miejsca niż boczne */
min-width: 400px;
max-height: 70vh; /* Ograniczenie wysokości */
background-color: #fff3e0; /* Jasny kolor tła sali */
position: relative; /* Potrzebne do pozycjonowania stołów */
}
#venue-layout {
position: relative; /* Pozwala na absolutne pozycjonowanie stołów wewnątrz */
width: 100%;
height: 100%;
padding: 20px;
box-sizing: border-box;
}
.table {
background-color: #b7410e; /* Kolor stołu (brązowy) */
border: 2px solid #800000; /* Ciemniejsza obwódka */
border-radius: 50%; /* Okrągły stół */
width: 120px; /* Rozmiar stołu */
height: 120px;
position: absolute; /* Pozwala na pozycjonowanie stołów wewnątrz venue-layout */
display: flex;
flex-wrap: wrap; /* Zwijanie miejsc dla gości */
justify-content: center;
align-items: center;
cursor: grab; /* Wskaźnik, że można łapać */
box-shadow: 0 4px 10px rgba(0,0,0,0.3);
transition: transform 0.2s ease; /* Płynne animacje */
}
.table.dragging {
cursor: grabbing;
transform: scale(1.1);
z-index: 1000; /* Na wierzchu podczas przeciągania */
}
.table h3 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
font-size: 0.8em;
color: white;
background-color: rgba(0, 0, 0, 0.5);
padding: 3px 6px;
border-radius: 4px;
margin: 0;
white-space: nowrap; /* Zapobiega łamaniu tekstu */
}
.guest-spot {
width: 25px;
height: 25px;
background-color: rgba(255, 255, 255, 0.6);
border: 1px dashed white;
border-radius: 50%;
margin: 5px; /* Odstępy między miejscami */
box-sizing: border-box;
}
.guest-spot.occupied {
background-color: rgba(255, 0, 0, 0.7); /* Czerwone, gdy zajęte */
border-color: red;
cursor: default;
}
.guest-spot.full {
background-color: rgba(0, 0, 0, 0.3); /* Ciemniejsze, gdy stół pełny */
border-color: grey;
cursor: not-allowed;
}
.guest-item {
background-color: #6fa8dc; /* Jasny niebieski */
color: white;
padding: 5px 10px;
margin: 5px;
border-radius: 15px;
cursor: grab; /* Wskaźnik, że można przeciągać */
list-style: none;
display: inline-block; /* Umożliwia układanie w linii */
white-space: nowrap;
transition: transform 0.2s ease;
}
.guest-item.dragging {
opacity: 0.5;
cursor: grabbing;
transform: scale(1.1);
}
/* Formularze i listy */
.add-guest-form, .add-table-form {
display: flex;
gap: 5px;
margin-bottom: 10px;
}
.add-guest-form input,
.add-table-form input {
flex: 1;
padding: 8px;
border: 1px solid #ccc;
border-radius: 4px;
}
.add-guest-form button,
.add-table-form button,
.controls button {
padding: 8px 12px;
background-color: #c00;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
transition: background-color 0.2s ease;
}
.add-guest-form button:hover,
.add-table-form button:hover,
.controls button:hover {
background-color: #800000; /* Ciemniejsza czerwień */
}
#unassigned-guests, #table-list {
list-style: none;
padding: 0;
max-height: 400px; /* Ograniczenie wysokości listy */
overflow-y: scroll; /* Przewijanie, jeśli lista jest długa */
border: 1px solid #eee;
padding: 10px;
border-radius: 4px;
}
#unassigned-guests li, #table-list li {
padding: 6px 10px;
margin-bottom: 5px;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 4px;
cursor: grab; /* dla gości */
}
#unassigned-guests li:last-child {
margin-bottom: 0;
}
#table-list li {
cursor: default; /* dla listy stołów */
}
.controls {
margin-top: 20px;
display: flex;
flex-direction: column;
gap: 10px;
}
/* Dodatkowe style dla przeciągania */
.guest-item.dragging-active {
border: 2px dashed #888;
background-color: #ddd;
}
.guest-spot.drag-over {
background-color: #90ee90; /* Jasnozielony, gdy cel jest aktywny */
border-color: green;
}
footer {
text-align: center;
padding: 1rem 0;
margin-top: auto; /* Przypina stopkę na dole */
background-color: #e06666;
color: white;
font-size: 0.9em;
}
/* Responsywność */
@media (max-width: 768px) {
.container {
flex-direction: column; /* Ustawienie kolumnowe na małych ekranach */
align-items: center; /* Wyśrodkowanie */
}
.visual-panel {
width: 95%; /* Zajmuje prawie cały ekran */
flex: none; /* Wyłączenie elastyczności, żeby działała szerokość */
min-height: 400px; /* Minimum wysokości dla planu */
}
.guest-panel, .table-panel {
width: 95%;
flex: none; /* Wyłączenie elastyczności */
max-height: none; /* Zezwolenie na pełną wysokość */
}
}
let draggedGuest = null; // Przechowuje element gościa, który jest przeciągany
let guestIdCounter = 0;
let tableIdCounter = 0;
// --- Funkcje dodawania ---
function addGuest() {
const guestNameInput = document.getElementById('guest-name');
const guestName = guestNameInput.value.trim();
if (guestName) {
guestIdCounter++;
const guestId = `guest-${guestIdCounter}`;
const guestList = document.getElementById('unassigned-guests');
const li = document.createElement('li');
li.className = 'guest-item';
li.setAttribute('draggable', 'true');
li.id = guestId;
li.textContent = guestName;
li.dataset.name = guestName; // Przechowujemy nazwę w data attribute
// Dodajemy obsługę zdarzeń przeciągania
li.addEventListener('dragstart', handleDragStart);
li.addEventListener('dragend', handleDragEnd);
guestList.appendChild(li);
guestNameInput.value = ''; // Wyczyść pole input
guestNameInput.focus();
} else {
alert('Proszę podać imię i nazwisko gościa.');
}
}
function addTable() {
const capacityInput = document.getElementById('table-capacity');
const capacity = parseInt(capacityInput.value) || 8; // Domyślnie 8 miejsc
tableIdCounter++;
const tableId = `table-${tableIdCounter}`;
const venueLayout = document.getElementById('venue-layout');
const tableList = document.getElementById('table-list');
// Tworzenie elementu stołu
const tableDiv = document.createElement('div');
tableDiv.className = 'table';
tableDiv.id = tableId;
tableDiv.dataset.capacity = capacity;
tableDiv.style.left = `${(Math.random() * 80)}%`; // Losowe pozycjonowanie X
tableDiv.style.top = `${(Math.random() * 70)}%`; // Losowe pozycjonowanie Y
const tableHeader = document.createElement('h3');
tableHeader.textContent = `Stół ${tableIdCounter} (0/${capacity})`;
tableDiv.appendChild(tableHeader);
// Tworzenie miejsc dla gości
for (let i = 0; i < capacity; i++) {
const spot = document.createElement('div');
spot.className = 'guest-spot';
spot.dataset.tableId = tableId;
spot.dataset.spotIndex = i; // Indeks miejsca przy stole
spot.addEventListener('dragenter', handleDragEnter);
spot.addEventListener('dragover', handleDragOver);
spot.addEventListener('dragleave', handleDragLeave);
spot.addEventListener('drop', handleDrop);
tableDiv.appendChild(spot);
}
venueLayout.appendChild(tableDiv);
// Dodawanie do listy stołów
const tableListItem = document.createElement('li');
tableListItem.id = `table-list-${tableId}`;
tableListItem.textContent = `Stół ${tableIdCounter} (0/${capacity})`;
tableListItem.dataset.tableId = tableId; // Link do elementu stołu
tableList.appendChild(tableListItem);
// Dodaj obsługę przeciągania dla samego stołu
tableDiv.addEventListener('dragstart', handleTableDragStart);
tableDiv.addEventListener('dragend', handleTableDragEnd);
}
// --- Funkcje obsługi przeciągania ---
function handleDragStart(e) {
draggedGuest = e.target; // Zapamiętaj przeciągany element
e.dataTransfer.setData('text/plain', e.target.id); // Potrzebne dla niektórych przeglądarek
e.dataTransfer.effectAllowed = 'move';
setTimeout(() => {
e.target.classList.add('dragging-active'); // Efekt wizualny
}, 0);
console.log('Rozpoczęto przeciąganie gościa:', e.target.id);
}
function handleDragEnd(e) {
e.target.classList.remove('dragging-active'); // Usuń efekt wizualny
draggedGuest = null;
// Usuń klasy pomocnicze z miejsc, jeśli pozostały
document.querySelectorAll('.guest-spot.drag-over').forEach(spot => {
spot.classList.remove('drag-over');
});
console.log('Zakończono przeciąganie gościa');
}
function handleTableDragStart(e) {
// Sprawdzamy czy na pewno przeciągamy stół, a nie gościa z niego
if (e.target.classList.contains('table')) {
draggedGuest = e.target; // Przechwytujemy element stołu
e.dataTransfer.setData('text/plain', e.target.id);
e.dataTransfer.effectAllowed = 'move';
setTimeout(() => {
e.target.classList.add('dragging');
}, 0);
console.log('Rozpoczęto przeciąganie stołu:', e.target.id);
}
}
function handleTableDragEnd(e) {
if (e.target.classList.contains('table')) {
e.target.classList.remove('dragging');
draggedGuest = null; // Resetujemy, bo skończyliśmy ruszać stołem
console.log('Zakończono przeciąganie stołu');
}
}
function handleDragEnter(e) {
e.preventDefault(); // Musi być, aby drop zadziałał
if (draggedGuest && draggedGuest.classList.contains('guest-item') && e.target.classList.contains('guest-spot')) {
// Sprawdź, czy miejsce nie jest już zajęte
if (!e.target.classList.contains('occupied')) {
e.target.classList.add('drag-over');
}
}
// Obsługa przeciągania stołu na inny stół (np. do zamiany miejsc) - bardziej zaawansowane
// if (draggedGuest && draggedGuest.classList.contains('table') && e.target.classList.contains('table')) {
// e.target.style.border = '2px dashed blue'; // Wizualizacja
// }
}
function handleDragOver(e) {
e.preventDefault(); // Kluczowe dla działania 'drop'
if (draggedGuest && draggedGuest.classList.contains('guest-item') && e.target.classList.contains('guest-spot')) {
// Sprawdź, czy miejsce nie jest już zajęte i czy nie jest to ten sam stół (jeśli już tam jest)
const isOccupied = e.target.classList.contains('occupied');
const currentlyAtThisTable = draggedGuest.parentNode === e.target;
if (!isOccupied || currentlyAtThisTable) {
e.dataTransfer.dropEffect = 'move';
// Dodajemy klasę tylko jeśli można tam upuścić
if (!isOccupied || currentlyAtThisTable) {
e.target.classList.add('drag-over');
}
} else {
e.dataTransfer.dropEffect = 'none'; // Nie można upuścić
}
} else if (draggedGuest && draggedGuest.classList.contains('table')) {
// Pozwól na przeciąganie stołu nad innym stołem (do potencjalnej zmiany pozycji)
e.dataTransfer.dropEffect = 'move';
}
}
function handleDragLeave(e) {
// Usuwamy klasę, gdy element wyjeżdża z obszaru docelowego
if (e.target.classList.contains('guest-spot')) {
e.target.classList.remove('drag-over');
}
// if (e.target.classList.contains('table')) {
// e.target.style.border = ''; // Resetuj border dla stołu
// }
}
function handleDrop(e) {
e.preventDefault();
e.target.classList.remove('drag-over'); // Usuń wizualne oznaczenie
// Sprawdź, czy upuszczamy gościa na miejsce
if (draggedGuest && draggedGuest.classList.contains('guest-item') && e.target.classList.contains('guest-spot')) {
const targetSpot = e.target;
const targetTable = targetSpot.parentNode; // Element .table
const targetTableId = targetTable.id;
const capacity = parseInt(targetTable.dataset.capacity);
const currentGuestCount = targetTable.querySelectorAll('.guest-spot.occupied').length;
// Sprawdź, czy miejsce jest wolne
if (!targetSpot.classList.contains('occupied')) {
// Usuń gościa z poprzedniego miejsca (jeśli istnieje)
if (draggedGuest.parentNode && draggedGuest.parentNode.classList.contains('guest-spot')) {
draggedGuest.parentNode.classList.remove('occupied');
// Zmniejsz licznik, jeśli przenosimy z innego stołu
const prevTable = draggedGuest.parentNode.parentNode;
const prevCount = prevTable.querySelectorAll('.guest-spot.occupied').length;
const prevTableCapacity = parseInt(prevTable.dataset.capacity);
updateTableList(prevTable.id, prevCount, prevTableCapacity);
}
// Dodaj gościa do nowego miejsca
targetSpot.classList.add('occupied');
targetSpot.appendChild(draggedGuest); // Przenieś DOM element gościa
draggedGuest.style.position = 'static'; // Resetuj pozycjonowanie
draggedGuest.style.margin = '5px'; // Dodaj margin z powrotem
// Zaktualizuj licznik gości przy stole
const newGuestCount = currentGuestCount + 1;
updateTableList(targetTableId, newGuestCount, capacity);
// Sprawdź, czy stół jest pełny
checkTableFullness(targetTable, capacity);
console.log(`Przeniesiono ${draggedGuest.dataset.name} na ${targetTableId}`);
} else {
console.log('Miejsce jest już zajęte.');
// Jeśli próbowano umieścić zajęte miejsce, cofnij efekt wizualny przeciągania
if (draggedGuest.parentNode) draggedGuest.parentNode.classList.remove('occupied');
if (draggedGuest.parentNode) draggedGuest.parentNode.appendChild(draggedGuest); // Wraca na poprzednie miejsce
}
}
// Tutaj można dodać logikę przenoszenia samych stołów (bardziej skomplikowane)
else if (draggedGuest && draggedGuest.classList.contains('table')) {
// Logika zamiany pozycji stołów - np. zamień style left/top
console.log('Potencjalnie zamiana pozycji stołów:', draggedGuest.id, 'z', e.target.id);
// Prosta zamiana pozycji:
const tempLeft = draggedGuest.style.left;
const tempTop = draggedGuest.style.top;
draggedGuest.style.left = e.target.style.left;
draggedGuest.style.top = e.target.style.top;
e.target.style.left = tempLeft;
e.target.style.top = tempTop;
}
// Reset stanu przeciągania
if (draggedGuest) {
draggedGuest.classList.remove('dragging-active');
draggedGuest.classList.remove('dragging');
}
draggedGuest = null;
}
// Funkcja aktualizująca licznik i nagłówek stołu
function updateTableList(tableId, guestCount, capacity) {
const tableHeader = document.querySelector(`#${tableId} h3`);
if (tableHeader) {
tableHeader.textContent = `Stół ${tableId.split('-')[1]} (${guestCount}/${capacity})`;
}
const tableListItem = document.getElementById(`table-list-${tableId}`);
if (tableListItem) {
tableListItem.textContent = `Stół ${tableId.split('-')[1]} (${guestCount}/${capacity})`;
}
}
// Funkcja sprawdzająca, czy stół jest pełny
function checkTableFullness(tableElement, capacity) {
const occupiedSpots = tableElement.querySelectorAll('.guest-spot.occupied').length;
const spots = tableElement.querySelectorAll('.guest-spot');
if (occupiedSpots >= capacity) {
spots.forEach(spot => spot.classList.add('full'));
} else {
spots.forEach(spot => spot.classList.remove('full'));
}
}
// --- Funkcje dodatkowe ---
function saveArrangement() {
const data = {
guests: [],
tables: []
};
// Zapisz gości
document.querySelectorAll('#unassigned-guests .guest-item').forEach(guestEl => {
data.guests.push({ id: guestEl.id, name: guestEl.dataset.name });
});
// Zapisz stoły i ich przypisania
document.querySelectorAll('.table').forEach(tableEl => {
const tableData = {
id: tableEl.id,
capacity: parseInt(tableEl.dataset.capacity),
position: { left: tableEl.style.left, top: tableEl.style.top },
guests: []
};
tableEl.querySelectorAll('.guest-spot.occupied').forEach(spotEl => {
if (spotEl.firstChild && spotEl.firstChild.classList.contains('guest-item')) {
const guestEl = spotEl.firstChild;
tableData.guests.push({
id: guestEl.id,
name: guestEl.dataset.name
});
}
});
data.tables.push(tableData);
});
localStorage.setItem('weddingSeating', JSON.stringify(data));
alert('Ustawienie stołów zostało zapisane w Local Storage!');
}
function loadArrangement() {
// Wyczyść poprzednie dane, aby wczytać nowe
document.getElementById('unassigned-guests').innerHTML = '';
document.getElementById('venue-layout').innerHTML = '';
document.getElementById('table-list').innerHTML = '';
draggedGuest = null; // Resetuj stan przeciągania
guestIdCounter = 0; // Resetuj liczniki
tableIdCounter = 0;
const savedData = localStorage.getItem('weddingSeating');
if (savedData) {
const data = JSON.parse(savedData);
// Wczytaj gości
data.guests.forEach(guestInfo => {
guestIdCounter++;
const guestId = `guest-${guestIdCounter}`; // Użyj nowego ID, aby uniknąć konfliktów
const guestList = document.getElementById('unassigned-guests');
const li = document.createElement('li');
li.className = 'guest-item';
li.setAttribute('draggable', 'true');
li.id = guestId; // Ustaw nowe ID
li.textContent = guestInfo.name;
li.dataset.name = guestInfo.name;
li.dataset.originalId = guestInfo.id; // Opcjonalnie: zachowaj oryginalne ID
li.addEventListener('dragstart', handleDragStart);
li.addEventListener('dragend', handleDragEnd);
guestList.appendChild(li);
});
// Wczytaj stoły i przypisania
data.tables.forEach(tableInfo => {
tableIdCounter++;
const tableId = `table-${tableIdCounter}`; // Nowe ID dla stołu
const venueLayout = document.getElementById('venue-layout');
const tableList = document.getElementById('table-list');
const tableDiv = document.createElement('div');
tableDiv.className = 'table';
tableDiv.id = tableId;
tableDiv.dataset.capacity = tableInfo.capacity;
tableDiv.style.left = tableInfo.position.left;
tableDiv.style.top = tableInfo.position.top;
const tableHeader = document.createElement('h3');
tableHeader.textContent = `Stół ${tableIdCounter} (${tableInfo.guests.length}/${tableInfo.capacity})`;
tableDiv.appendChild(tableHeader);
for (let i = 0; i < tableInfo.capacity; i++) {
const spot = document.createElement('div');
spot.className = 'guest-spot';
spot.dataset.tableId = tableId;
spot.dataset.spotIndex = i;
spot.addEventListener('dragenter', handleDragEnter);
spot.addEventListener('dragover', handleDragOver);
spot.addEventListener('dragleave', handleDragLeave);
spot.addEventListener('drop', handleDrop);
tableDiv.appendChild(spot);
}
venueLayout.appendChild(tableDiv);
const tableListItem = document.createElement('li');
tableListItem.id = `table-list-${tableId}`;
tableListItem.textContent = `Stół ${tableIdCounter} (${tableInfo.guests.length}/${tableInfo.capacity})`;
tableListItem.dataset.tableId = tableId;
tableList.appendChild(tableListItem);
tableDiv.addEventListener('dragstart', handleTableDragStart);
tableDiv.addEventListener('dragend', handleTableDragEnd);
// Przypisz gości do stołu
tableInfo.guests.forEach((guestInfo, index) => {
// Znajdź odpowiednie miejsce (zakładając, że kolejność miejsc jest stała)
const targetSpot = tableDiv.children[index + 1]; // +1 bo pierwszy jest h3
if (targetSpot && targetSpot.classList.contains('guest-spot') && !targetSpot.classList.contains('occupied')) {
guestIdCounter++;
const guestId = `guest-${guestIdCounter}`; // Nowe ID dla gościa
const guestLi = document.createElement('li');
guestLi.className = 'guest-item';
guestLi.setAttribute('draggable', 'true');
guestLi.id = guestId; // Nowe ID
guestLi.textContent = guestInfo.name;
guestLi.dataset.name = guestInfo.name;
guestLi.dataset.originalId = guestInfo.id; // Zachowaj oryginalne ID
guestLi.addEventListener('dragstart', handleDragStart);
guestLi.addEventListener('dragend', handleDragEnd);
targetSpot.classList.add('occupied');
targetSpot.appendChild(guestLi);
} else {
console.warn(`Nie można było umieścić gościa ${guestInfo.name} na stole ${tableId} na miejscu ${index + 1}`);
}
});
// Sprawdź, czy stół jest pełny po wczytaniu
checkTableFullness(tableDiv, tableInfo.capacity);
});
alert('Dane zostały wczytane!');
} else {
alert('Nie znaleziono zapisanych danych.');
}
}
function clearArrangement() {
if (confirm('Czy na pewno chcesz wyczyścić wszystkie dane i zacząć od nowa?')) {
document.getElementById('unassigned-guests').innerHTML = '';
document.getElementById('venue-layout').innerHTML = '';
document.getElementById('table-list').innerHTML = '';
localStorage.removeItem('weddingSeating');
guestIdCounter = 0;
tableIdCounter = 0;
console.log('Wyczyszczono dane.');
}
}
// Dodaj początkowe stoły dla przykładu (opcjonalnie)
// window.onload = () => {
// addTable();
// addTable();
// };