<?php
if (!defined('ABSPATH')) exit;

spl_autoload_register(function ($class) {

    // SS_Shortcodes → includes/Core/shortcodes.php
    if (strpos($class, 'SS_') === 0) {

        $name = strtolower(str_replace('SS_', '', $class));

        // try Core folder first
        $core = SEARCHSHIFTER_PLUGIN_DIR . 'includes/Core/' . $name . '.php';
        if (file_exists($core)) {
            require_once $core;
            return;
        }

        // fallback
        $file = SEARCHSHIFTER_PLUGIN_DIR . 'includes/' . $name . '.php';
        if (file_exists($file)) {
            require_once $file;
            return;
        }
    }

    // Namespaced classes
    if (strpos($class, 'SS\\') === 0) {
        $rel = str_replace('\\', '/', substr($class, 3));
        $file = SEARCHSHIFTER_PLUGIN_DIR . 'includes/' . $rel . '.php';
        if (file_exists($file)) {
            require_once $file;
        }
    }
});