/**
 * Admin — Report Subscriptions.
 *
 * Handles frequency and monthly-type select interactions.
 */
(function () {
    'use strict';

    /* ── freq-select: show/hide weekly/monthly config ──────────────── */
    document.querySelectorAll('.freq-select').forEach(function (sel) {
        sel.addEventListener('change', function () {
            var rk  = this.dataset.rk;
            var v   = this.value;
            var dow = document.querySelector('.dow-cfg[data-rk="' + rk + '"]');
            var mon = document.querySelector('.month-cfg[data-rk="' + rk + '"]');
            if (dow) dow.style.display = v === 'weekly' ? '' : 'none';
            if (mon) mon.style.display = v === 'monthly' ? 'inline-flex' : 'none';
        });
    });

    /* ── mtype-select: toggle numeric / logical monthly config ─────── */
    document.querySelectorAll('.mtype-select').forEach(function (sel) {
        sel.addEventListener('change', function () {
            var rk        = this.dataset.rk;
            var isLogical = this.value === 'logical';
            var dom       = document.querySelector('.dom-cfg[data-rk="' + rk + '"]');
            var log       = document.querySelector('.logical-cfg[data-rk="' + rk + '"]');
            if (dom) dom.style.display = isLogical ? 'none' : '';
            if (log) log.style.display = isLogical ? '' : 'none';
        });
    });
})();
