import { _ } from './bm.util'

interface IBaseStyles {
	mouse?: string | string[]
	position?: string | string[]
	display?: string | string[]
	text?: string | string[]
	visual?: string | string[]
	transform?: string | string[]
	animation?: string | string[]
}

interface IExtraStyles {
	hover?: string | string[] | (IBaseStyles & IExtraStyles)
	focus?: string | string[] | (IBaseStyles & IExtraStyles)
	active?: string | string[] | (IBaseStyles & IExtraStyles)
	disabled?: string | string[] | (IBaseStyles & IExtraStyles)
	placeholder?: string | string[] | (IBaseStyles & IExtraStyles)
	attrs?: string | string[] | (IBaseStyles & IExtraStyles)
	childs?: string | string[] | (IBaseStyles & IExtraStyles)
	adaptive?: string | string[] | (IBaseStyles & IExtraStyles)
	dark?: string | string[] | (IBaseStyles & IExtraStyles)
	after?: string | string[] | (IBaseStyles & IExtraStyles)
}

interface ITwJoin extends IBaseStyles, IExtraStyles {
	tw?: string | string[]
	vars?: string | string[]
}

const stylesFlat = (styles: ITwJoin): string[] => {
	if (_.isObject(styles)) {
		return (Object.values(styles) as ITwJoin[]).flatMap(stylesFlat)
	}
	//
	if (_.isArray(styles)) {
		return styles as string[]
	}
	//
	if (_.isString(styles)) {
		return [styles]
	}
	//
	return []
}

export function twJoin(styles: ITwJoin): string {
	return Object.values(styles).flatMap(stylesFlat).filter(Boolean).join(' ')
}
