<?php
namespace MediaLibraryInfiniteScrolling;

use WP_PowerSuite\Core\AbstractModule;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

class Module extends AbstractModule {

	private const MODULE_ID = 'media-library-infinite-scrolling';

	public function getId(): string {
		return self::MODULE_ID;
	}

	public function getName(): string {
		return __( 'Media Library Infinite Scroll', 'wp-powersuite' );
	}

	public function getVersion(): string {
		return '1.0.0';
	}

	public function getDescription(): string {
		return __( 'Automatically load more images in the media library when scrolling to the bottom. Loads 80 images at a time until all are loaded.', 'wp-powersuite' );
	}

	public function getContext(): string|array {
		return 'admin';
	}

	protected function registerHooks(): void {
		add_filter( 'media_library_infinite_scrolling', [ $this, 'enableInfiniteScrolling' ] );
	}

	public function enableInfiniteScrolling( bool $enabled ): bool {
		if ( ! is_admin() || ! current_user_can( 'upload_files' ) ) {
			return $enabled;
		}

		return true;
	}
}
