export function adminApp() {
    return {
        sidebarOpen:      false,
        sidebarCollapsed: localStorage.getItem('sidebarCollapsed') === 'true',
        darkMode:         localStorage.getItem('darkMode') === 'true',
        confirmLogout:    false,
        navTooltip:       { visible: false, text: '', y: 0 },

        init() {
            this.$watch('darkMode',         val => localStorage.setItem('darkMode', val))
            this.$watch('sidebarCollapsed', val => localStorage.setItem('sidebarCollapsed', val))

            const mq = window.matchMedia('(min-width: 1024px)')
            mq.addEventListener('change', e => {
                if (e.matches) this.sidebarOpen = false
            })
        },

        showNavTooltip(text, event) {
            if (!this.sidebarCollapsed || window.innerWidth < 1024) return
            const rect = event.currentTarget.getBoundingClientRect()
            this.navTooltip = { visible: true, text, y: rect.top + rect.height / 2 }
        },

        hideNavTooltip() {
            this.navTooltip.visible = false
        },

        closeSidebar() {
            this.sidebarOpen = false
        },

        isDesktop() {
            return window.innerWidth >= 1024
        },
    }
}
