<?php

defined( 'ABSPATH' ) || exit;

/**
 * PSR-4 style autoloader for Integrate Google Drive
 */
spl_autoload_register(
	function ( $class ) {

		$prefixes = [
			'IGD\\Updates\\'                    => 'updates/',
			'IGD\\Integrations\\Gutenberg\\'    => 'integrations/gutenberg/',
			'IGD\\Integrations\\Divi\\'         => 'integrations/divi/',
			'IGD\\Integrations\\Elementor\\'    => 'integrations/elementor/',
			'IGD\\Integrations\\MediaLibrary\\' => 'integrations/media-library/',
			'IGD\\Integrations\\Woocommerce\\' => 'integrations/woocommerce/',
			'IGD\\Integrations\\'               => 'integrations/',
			'IGD\\'                             => 'classes/',
		];

		foreach ( $prefixes as $prefix => $base_dir ) {

			if ( strpos( $class, $prefix ) !== 0 ) {
				continue;
			}

			$relative_class = substr( $class, strlen( $prefix ) );

			$file = trailingslashit( plugin_dir_path( __DIR__ ) )
			        . $base_dir
			        . str_replace( '\\', '/', $relative_class )
			        . '.php';

			if ( file_exists( $file ) ) {
				require_once $file;
			}

			return;
		}
	}
);


