import {__, _x} from '@wordpress/i18n'
import {upperFirst} from 'lodash'

import TailwindFeature from './TailwindFeature'

import type {
	SkaBlocks,
	TailwindFeatureConfig,
} from '../../types'

import type {
	tBlockAttributes,
	tBlockNameOrType,
} from '@ska/shared'

export interface TailwindFeatureGroupConfig {
	id: string
	label: string
	features: TailwindFeatureConfig[]
}

export default class TailwindFeatureGroup {

	readonly skaBlocks
	readonly config
	readonly features
	public id

	constructor(skaBlocks: SkaBlocks, config: TailwindFeatureGroupConfig) {
		this.skaBlocks = skaBlocks
		this.config = config
		this.id = `skaBlocks${upperFirst(this.groupId)}Group`
		this.features = this.config.features.map(featureConfig => {
			return new TailwindFeature(skaBlocks, {
				...featureConfig,
				groupId: this.id,
			})
		})
	}

	get groupId(): string {
		return this.config.id
	}

	get label(): string {
		return this.config.label
	}

	hasSupport = (block: tBlockNameOrType): boolean => {
		return this.features.some(feature => feature.hasSupport(block))
	}

	hasValue = (attributes: tBlockAttributes = {}, includingSelectors = true): boolean => {
		return this.features.some(feature => feature.hasValue(attributes, includingSelectors))
	}
}
