-- ============================================================
-- NICC Admin Menu - Migracion 0007
-- Agregar plugin de Diagnostico CSS (cssdiagnostic)
-- ============================================================

-- Agregar el item cssdiagnostic a la categoria de herramientas/mantenimiento
INSERT OR IGNORE INTO admin_menu_items (
    category_id,
    code,
    plugin_name,
    name,
    description,
    icon,
    url,
    sort_order,
    is_active,
    is_dangerous,
    requires_confirmation
)
SELECT
    (SELECT id FROM admin_menu_categories WHERE code IN ('tools', 'maintenance', 'system') ORDER BY
        CASE code
            WHEN 'tools' THEN 1
            WHEN 'maintenance' THEN 2
            WHEN 'system' THEN 3
            ELSE 4
        END
    LIMIT 1),
    'cssdiagnostic',
    'cssdiagnostic',
    'Diagnostico CSS',
    'Diagnostica errores de compilacion CSS/LESS paso a paso',
    'palette',
    '?do=admin&page=cssdiagnostic',
    95,
    1,
    0,
    0
WHERE NOT EXISTS (SELECT 1 FROM admin_menu_items WHERE code = 'cssdiagnostic');

-- Permisos para manager (acceso total - herramienta de diagnostico)
INSERT OR REPLACE INTO admin_menu_permissions (item_id, role, can_view, can_execute)
SELECT id, 'manager', 1, 1 FROM admin_menu_items WHERE code = 'cssdiagnostic';

-- Permisos para admin (acceso total)
INSERT OR REPLACE INTO admin_menu_permissions (item_id, role, can_view, can_execute)
SELECT id, 'admin', 1, 1 FROM admin_menu_items WHERE code = 'cssdiagnostic';

-- Permisos para superuser
INSERT OR REPLACE INTO admin_menu_permissions (item_id, role, can_view, can_execute)
SELECT id, 'superuser', 1, 1 FROM admin_menu_items WHERE code = 'cssdiagnostic';

-- Fin de migracion
SELECT 1;
