(function () {
    'use strict';

    function initDensity() {
        var sel = document.getElementById('masseur-density');
        var root = document.getElementById('masseur-admin');
        if (!sel || !root) return;
        var key = 'fate_masseur_admin_density';
        var saved = '';
        try {
            saved = localStorage.getItem(key) || '';
        } catch (e) {}
        if (saved === 'compact' || saved === 'comfortable') {
            sel.value = saved;
            root.setAttribute('data-density', saved);
        }
        sel.addEventListener('change', function () {
            var v = sel.value === 'compact' ? 'compact' : 'comfortable';
            root.setAttribute('data-density', v);
            try {
                localStorage.setItem(key, v);
            } catch (e) {}
        });
    }

    function initReviewExpand() {
        document.querySelectorAll('[data-review-expand]').forEach(function (btn) {
            btn.addEventListener('click', function () {
                var row = btn.closest('.masseur-review-row');
                if (!row) return;
                var expanded = row.classList.toggle('is-expanded');
                btn.textContent = expanded ? '收合' : '展開全文';
                btn.setAttribute('aria-expanded', expanded ? 'true' : 'false');
            });
        });
    }

    initDensity();
    initReviewExpand();
})();
