(function(){ const deck = window.TAROT_DECK || []; const lang = document.documentElement.lang === 'ru' ? 'ru' : 'az'; const isRu = lang === 'ru'; const rootPrefix = isRu ? '/ru' : ''; const texts = { az: { chooseThree: '3 kart seçin', selected: 'Seçilmiş kartlar', max: 'Yalnız 3 kart seçmək olar', need: 'Nəticəni görmək üçün 3 kart seçin', fate: 'Taleyə etibar et', get: 'Fal nəticəsini al', card: 'kart', noCards: 'Kartlar seçilməyib. Sizin üçün 3 kart təsadüfi seçildi.', next: 'Növbəti karta keç', prev: 'Əvvəlki karta qayıt', restart: 'Yenidən kart seç', positions: ['Birinci kart', 'İkinci kart', 'Üçüncü kart'], posText: ['Sualın başlanğıcı və hazırkı vəziyyət', 'Gizli mövzu və diqqət istəyən hissə', 'Nəticənin istiqaməti və əsas mesaj'] }, ru: { chooseThree: 'Выберите 3 карты', selected: 'Выбранные карты', max: 'Можно выбрать только 3 карты', need: 'Чтобы получить предсказание, выберите 3 карты', fate: 'Положиться на судьбу', get: 'Получить предсказание', card: 'карта', noCards: 'Карты не были выбраны. Мы случайно выбрали 3 карты для вас.', next: 'Перейти к следующей карте', prev: 'Вернуться к предыдущей карте', restart: 'Выбрать карты заново', positions: ['Первая карта', 'Вторая карта', 'Третья карта'], posText: ['Начало вопроса и текущее состояние', 'Скрытая тема и то, что просит внимания', 'Направление результата и главный смысл'] } }[lang]; function sampleThree(){ const ids = [...Array(deck.length).keys()]; for(let i=ids.length-1;i>0;i--){ const j=Math.floor(Math.random()*(i+1)); [ids[i],ids[j]]=[ids[j],ids[i]]; } return ids.slice(0,3); } function setSelection(ids){ localStorage.setItem('tarotSelectedCards', ids.join(',')); } function getSelection(){ const qp = new URLSearchParams(location.search).get('cards'); const raw = qp || localStorage.getItem('tarotSelectedCards') || ''; const ids = raw.split(',').map(x=>parseInt(x,10)).filter(x=>Number.isInteger(x)&&x>=0&&x{ btn.disabled = ids.length !== 3; }); const counter = document.querySelector('[data-selected-counter]'); if(counter) counter.textContent = ids.length + '/3'; } const board = document.querySelector('[data-tarot-board]'); if(board){ const selected = []; const status = document.querySelector('[data-board-status]'); const count = parseInt(board.dataset.count || '78', 10); deck.slice(0,count).forEach(card=>{ const button = document.createElement('button'); button.type = 'button'; button.className = 'tarot-card-back'; button.setAttribute('aria-label', (isRu ? 'Выбрать карту ' : 'Kart seç ') + (card.id+1)); button.dataset.id = card.id; button.innerHTML = ''; button.addEventListener('click', () => { const id = card.id; const idx = selected.indexOf(id); if(idx >= 0){ selected.splice(idx,1); button.classList.remove('is-selected'); } else if(selected.length < 3){ selected.push(id); button.classList.add('is-selected'); } else { if(status) status.textContent = texts.max; } if(status && selected.length <= 3) status.textContent = texts.selected + ': ' + selected.length + '/3'; updateResultButtons(selected); }); board.appendChild(button); }); updateResultButtons(selected); document.querySelectorAll('[data-action="random-cards"]').forEach(btn=>{ btn.addEventListener('click', () => { selected.splice(0, selected.length, ...sampleThree()); board.querySelectorAll('.tarot-card-back').forEach(el=>el.classList.toggle('is-selected', selected.includes(parseInt(el.dataset.id,10)))); if(status) status.textContent = texts.selected + ': 3/3'; updateResultButtons(selected); }); }); document.querySelectorAll('[data-action="get-reading"]').forEach(btn=>{ btn.addEventListener('click', () => { if(selected.length !== 3){ if(status) status.textContent = texts.need; return; } setSelection(selected); location.href = rootPrefix + '/result/1/?cards=' + selected.join(','); }); }); } const result = document.querySelector('[data-result-page]'); if(result){ let ids = getSelection(); const notice = document.querySelector('[data-result-notice]'); if(ids.length !== 3){ ids = sampleThree(); setSelection(ids); if(notice) notice.textContent = texts.noCards; } const step = Math.max(1, Math.min(3, parseInt(result.dataset.step || '1', 10))); const card = deck[ids[step-1]] || deck[0]; const name = isRu ? card.ru : card.az; const meaning = isRu ? card.ruMeaning : card.azMeaning; const img = document.querySelector('[data-result-image]'); if(img){ img.src = card.image; img.alt = name; } const title = document.querySelector('[data-result-title]'); if(title) title.textContent = texts.positions[step-1] + ': ' + name; const pos = document.querySelector('[data-result-position]'); if(pos) pos.textContent = texts.posText[step-1]; const txt = document.querySelector('[data-result-meaning]'); if(txt) txt.textContent = meaning; const current = document.querySelector('[data-current-step]'); if(current) current.textContent = step + '/3'; const next = document.querySelector('[data-next-result]'); if(next){ if(step < 3){ next.href = rootPrefix + '/result/' + (step+1) + '/?cards=' + ids.join(','); next.textContent = texts.next; } else { next.href = rootPrefix + '/'; next.textContent = texts.restart; } } const prev = document.querySelector('[data-prev-result]'); if(prev){ if(step > 1){ prev.href = rootPrefix + '/result/' + (step-1) + '/?cards=' + ids.join(','); prev.hidden = false; } else { prev.href = rootPrefix + '/'; prev.hidden = false; } prev.textContent = step > 1 ? texts.prev : texts.restart; } } })();