import { Asset } from '../../asset/asset.js';
import { GSplatAssetLoaderBase } from '../../../scene/gsplat-unified/gsplat-asset-loader-base.js';

class GSplatAssetLoader extends GSplatAssetLoaderBase {
		constructor(registry){
				super(), this._urlToAsset = new Map();
				this._registry = registry;
		}
		load(url) {
				let asset = this._urlToAsset.get(url);
				if (!asset) {
						asset = this._registry.getByUrl(url);
						if (!asset) {
								asset = new Asset(url, 'gsplat', {
										url
								});
								this._registry.add(asset);
						}
						this._urlToAsset.set(url, asset);
				}
				if (!asset.loaded && !asset.loading) {
						this._registry.load(asset);
				}
		}
		unload(url) {
				const asset = this._urlToAsset.get(url);
				if (asset) {
						asset.unload();
						this._urlToAsset.delete(url);
				}
		}
		getResource(url) {
				const asset = this._urlToAsset.get(url);
				return asset?.resource;
		}
}

export { GSplatAssetLoader };
