import { BuildableComponent } from '../package/component/buildable_component.js';
import { Reporter } from '../reporter/reporter.js';
import { UUIDRegex, checkPropTypes } from '../lib.js';
import { ConfigurationCategoryType } from './configuration_category_type.js';
// import { Configuration } from './configuration.js';
import { WrappedImage } from '../package/image/wrapped_image.js';
import { Project } from '../project.js';
/** Configuration category */
class ConfigurationCategory extends BuildableComponent {
/**
* @param {Reporter} reporter
* @param {Object} settings
* @param {UUID} [settings.id]
* @param {string} settings.name
* @param {ConfigurationCategoryType} settings.type
* @param {WrappedImage} [settings.thumbnail]
*/
constructor(reporter, settings) {
super(reporter, settings );
checkPropTypes(
settings,
{
name: 'string',
type: ConfigurationCategoryType
},
{
id: UUIDRegex,
}
);
}
static _exportName = {
singular: 'configurationCategory',
plural: 'configurationCategories'
};
_onTreeSet() {
const component = this;
this._tree.on(
'change',
({ cls = [] }) => {
// if ( cls.includes( Configuration ) ) {
// component.report({ msg: 'Configurations changed in package. Rebuilding.' });
// component._rebuild();
// }
},
this.id
);
this._rebuild();
}
_onTreeUnset() {
if (this._tree.hasListener('change', this.id)) {
this._tree.removeListener('change', this.id);
}
}
/**
* Collect blocks in this category (that have this category as a dependency)
* @protected
*/
async _build(part,quality) {
switch (part) {
case 'UI':
if (this._settings.thumbnail) {
this._setContent('UI', quality, this._settings.thumbnail.content.main[quality]);
}
else {
this._setContent('UI', quality, Project.defaultImages.missing.cloneNode(true));
}
break;
case 'main':
const configurations = this._tree
? this._tree.configurations.filter(mat => (mat.settings.categories || []).find(cat => cat === this))
: []
this._setContent('main', quality, configurations);
this.report({ msg: `Built category of ${configurations.length} configurations.` });
break;
default:
this._setContent(part, quality, null);
break;
}
return this;
}
}
export { ConfigurationCategory };