import { mountThemeToggle } from './ds/theme.js';
import { mountLogo } from './ds/logo.js';
import { link } from './ds/frame.js';
import { prod } from './ds/env.js';
mountThemeToggle(document.querySelector('#themeToggle'));
for (const host of document.querySelectorAll('[data-logo]')) mountLogo(host, { icon: host.dataset.logo === 'icon' });
const base = location.pathname.split('/').slice(0,-1).join('/') || '';
const api = (path) => `${base}/api${path}`;
const els={enabled:document.querySelector('#enabled'),moduleState:document.querySelector('#moduleState'),moduleGrid:document.querySelector('#moduleGrid'),tableCount:document.querySelector('#tableCount'),products:document.querySelector('#products'),payments:document.querySelector('#payments'),orders:document.querySelector('#orders'),save:document.querySelector('#save'),toast:document.querySelector('#toast'),tableUrl:document.querySelector('#tableUrl'),pulse:document.querySelector('#pulse')};
const moduleMeta={order:['Order to Table','Customer ordering','↗'],pay:['Pay Bill','Settle an open order','€'],payandgo:['Just Pay','Pay a paper receipt','€'],booking:['Bookings','Now or later','⌁'],screen:['4K Screen','Pictures and activity','▣'],gallery:['Gallery','Merchant discovery','□'],events:['Events','Nostr events','◌']};
function moduleRows(modules){els.moduleGrid.innerHTML=Object.entries(moduleMeta).map(([id,[name,copy,icon]])=>{const item=modules[id]||{};const url=prod?(id==='booking'?'https://pos.justworks.cash/':`https://${id}.justworks.cash/`):link(id);return `${icon}
${item.status==='coming-soon'?'Coming soon':item.status==='live'?'Live service':'Interactive preview'}`}).join('');document.querySelectorAll('[data-module]').forEach(input=>input.onchange=()=>{if(input.dataset.module==='order')els.enabled.checked=input.checked;save(true)})}
let state=null,lastOrder='',configVersion=0,toggleSaving=false;
function money(c){return `€${(c/100).toFixed(2)}`}
function productRows(products){els.products.innerHTML=products.map(p=>`
`).join('')}
function orderRows(orders){if(!orders.length){els.orders.innerHTML='
`).join('');document.querySelectorAll('[data-order]').forEach(b=>b.onclick=()=>updateOrder(b.dataset.order,b.dataset.status))}
function paymentRows(payments){els.payments.innerHTML=payments.slice(0,3).map(p=>`