(function () { var KEY = 'flow_consent_v1'; var TEXT = { ru: {body:'Мы используем технологии для работы сайта и безопасности. С вашего согласия — аналитику для улучшения Flow.', privacy:'Политика конфиденциальности', necessary:'Только необходимые', accept:'Принять'}, en: {body:'We use technologies for website operation and security. With your consent, we use analytics to improve Flow.', privacy:'Privacy Policy', necessary:'Necessary only', accept:'Accept'}, uk: {body:'Ми використовуємо технології для роботи сайту та безпеки. За вашою згодою — аналітику для покращення Flow.', privacy:'Політика конфіденційності', necessary:'Лише необхідні', accept:'Прийняти'}, zh: {body:'我们使用技术来保障网站运行与安全。经您同意,我们会使用分析工具来改进 Flow。', privacy:'隐私政策', necessary:'仅必要', accept:'接受'}, fa: {body:'ما از فناوری‌ها برای عملکرد و امنیت سایت استفاده می‌کنیم. با رضایت شما، تحلیل‌ها را برای بهبود Flow به‌کار می‌گیریم.', privacy:'سیاست حفظ حریم خصوصی', necessary:'فقط ضروری', accept:'پذیرش'} }; function lang() { var raw = String(localStorage.getItem('flow_lang') || localStorage.getItem('fl') || document.documentElement.lang || navigator.language || 'ru').toLowerCase(); if (/^(uk|ua)/.test(raw)) return 'uk'; if (/^(zh|cn)/.test(raw)) return 'zh'; if (/^(fa|per)/.test(raw)) return 'fa'; return /^en/.test(raw) ? 'en' : 'ru'; } function read() { try { return JSON.parse(localStorage.getItem(KEY) || 'null') || null; } catch (e) { return null; } } function normalize(value) { return value ? {necessary:true, analytics:!!value.analytics, ts:Number(value.ts || Date.now()), version:Number(value.version || 1)} : null; } function token() { try { return localStorage.getItem('flow_token') || ''; } catch (e) { return ''; } } function apiBase() { return window.API_BASE || 'https://api.floweb.club'; } function saveLocal(value) { value = normalize(value); localStorage.setItem(KEY, JSON.stringify(value)); window.dispatchEvent(new CustomEvent('flow-consent-change', {detail:value})); return value; } function syncServer(value) { var t = token(); if (!t || !value) return; try { fetch(apiBase() + '/api/consent', {method:'POST', headers:{'Content-Type':'application/json','Authorization':'Bearer ' + t}, body:JSON.stringify(value)}).catch(function () {}); } catch (e) {} } function write(analytics) { var value = saveLocal({necessary:true, analytics:!!analytics, ts:Date.now(), version:1}); syncServer(value); return value; } function analyticsAllowed() { var value = read(); return !!(value && value.analytics); } function hide() { var box = document.getElementById('flowConsentBanner'); if (box) box.remove(); } function languagePickerOpen() { var picker = document.getElementById('langPickerOverlay'); return !!(picker && window.getComputedStyle(picker).display !== 'none'); } function applyServer(value) { value = normalize(value); if (!value) return; var local = read(); if (!local || value.ts >= Number(local.ts || 0)) saveLocal(value); hide(); } function syncFromServer() { var t = token(); if (!t) return; try { fetch(apiBase() + '/api/consent', {headers:{'Authorization':'Bearer ' + t}}).then(function (response) { return response.ok ? response.json() : null; }).then(function (data) { if (data && data.consent) applyServer(data.consent); else if (read()) syncServer(read()); }).catch(function () {}); } catch (e) {} } function injectStyle() { if (document.getElementById('flowConsentStyle')) return; var style = document.createElement('style'); style.id = 'flowConsentStyle'; style.textContent = [ '.flow-consent{position:fixed;z-index:9999;left:0;right:0;bottom:0;box-sizing:border-box;display:flex;align-items:center;gap:14px;padding:11px clamp(16px,3vw,32px) calc(11px + env(safe-area-inset-bottom));background:#0b0f19;color:#c8d8e8;border-top:1px solid rgba(0,240,255,.32);box-shadow:0 -10px 28px rgba(0,0,0,.24);font-family:"Golos Text",Arial,sans-serif}.flow-consent.flow-consent--suppressed{display:none!important}', '.flow-consent::before{content:"";position:absolute;inset:0 0 auto;height:1px;background:linear-gradient(90deg,transparent,#00f0ff,transparent);opacity:.72}', '.flow-consent-text{max-width:760px;font-size:11px;line-height:1.35;font-weight:500;color:#d8e5f2}.flow-consent-text a{color:#00f0ff;text-decoration:none;font-weight:700}.flow-consent-actions{display:flex;gap:8px;margin-left:auto;flex:0 0 auto}', '.flow-consent-btn{min-height:38px;min-width:152px;box-sizing:border-box;border:1px solid rgba(71,96,128,.72);background:#111827;color:#c8d8e8;padding:9px 12px;font-family:"Unbounded",Arial,sans-serif;font-size:7px;font-weight:900;letter-spacing:.4px;text-transform:uppercase;cursor:pointer}.flow-consent-btn.accept{border-color:#00f0ff;background:#00f0ff;color:#0b0f19}', '[data-theme="light"] .flow-consent{background:#f0f4fa;color:#1a2a3a;border-top-color:rgba(0,151,167,.32);box-shadow:0 -12px 32px rgba(40,73,96,.13)}[data-theme="light"] .flow-consent-text{color:#1a2a3a}[data-theme="light"] .flow-consent-text a{color:#0097a7}[data-theme="light"] .flow-consent-btn{border-color:#c7d7e7;background:#fff;color:#5577aa}[data-theme="light"] .flow-consent-btn.accept{border-color:#0097a7;background:#0097a7;color:#fff}', '@media(max-width:720px){.flow-consent{left:0;right:0;bottom:0;border:0;border-top:1px solid rgba(0,240,255,.32);border-radius:0;padding:8px 14px calc(8px + env(safe-area-inset-bottom));align-items:stretch;flex-direction:column;gap:7px}.flow-consent-text{max-width:none;font-size:9px!important;line-height:1.28!important;font-weight:500!important}.flow-consent-actions{width:100%;margin:0;display:grid;grid-template-columns:1fr 1fr;gap:7px}.flow-consent-btn{width:100%;min-width:0;min-height:34px;padding:7px 6px;font-size:6.3px!important;line-height:1.1!important;letter-spacing:.2px!important}}', '@media(max-width:360px){.flow-consent{padding:7px 12px calc(7px + env(safe-area-inset-bottom));gap:6px}.flow-consent-text{font-size:8.5px!important}.flow-consent-btn{min-height:32px;font-size:6px!important}}' ].join(''); document.head.appendChild(style); } function renderText(t) { return t.body + ' ' + t.privacy + '.'; } function show() { if (read() || languagePickerOpen() || document.getElementById('flowConsentBanner')) return; injectStyle(); var t = TEXT[lang()] || TEXT.ru; var box = document.createElement('div'); box.id = 'flowConsentBanner'; box.className = 'flow-consent'; box.innerHTML = ''; box.querySelector('[data-flow-consent="necessary"]').onclick = function () { write(false); hide(); }; box.querySelector('[data-flow-consent="accept"]').onclick = function () { write(true); hide(); }; document.body.appendChild(box); } function refreshText() { var box = document.getElementById('flowConsentBanner'); if (!box) return; var t = TEXT[lang()] || TEXT.ru; box.querySelector('.flow-consent-text').innerHTML = renderText(t); box.querySelector('[data-flow-consent="necessary"]').textContent = t.necessary; box.querySelector('[data-flow-consent="accept"]').textContent = t.accept; } function syncLanguagePicker() { var box = document.getElementById('flowConsentBanner'); if (languagePickerOpen()) { if (box) box.classList.add('flow-consent--suppressed'); return; } if (box) box.classList.remove('flow-consent--suppressed'); else show(); } function observeLanguagePicker() { var picker = document.getElementById('langPickerOverlay'); if (!picker || !window.MutationObserver) return; new MutationObserver(syncLanguagePicker).observe(picker, {attributes:true, attributeFilter:['style','class']}); syncLanguagePicker(); } window.FlowConsent = {read:read, write:write, analyticsAllowed:analyticsAllowed, show:show, hide:hide, refreshText:refreshText, syncFromServer:syncFromServer, applyServer:applyServer}; window.addEventListener('storage', function (event) { if (event.key === 'flow_lang' || event.key === 'fl') refreshText(); }); if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', function () { observeLanguagePicker(); syncFromServer(); show(); }); else { observeLanguagePicker(); syncFromServer(); show(); } })();