exports.remToPx = value => `${Number.parseFloat(value) * 16}px`;

const unsupportedProperties = new Set([
	'box-sizing',
	'float',
	'clear',
	'object-fit',
	'object-position',
	'overflow-x',
	'overflow-y',
	'-webkit-overflow-scrolling',
	'overscroll-behavior',
	'overscroll-behavior-x',
	'overscroll-behavior-y',
	'visibility',
	'order',
	'grid-template-columns',
	'grid-column',
	'grid-column-start',
	'grid-column-end',
	'grid-template-rows',
	'grid-row',
	'grid-row-start',
	'grid-row-end',
	'grid-auto-flow',
	'grid-auto-columns',
	'grid-auto-rows',
	'gap',
	'column-gap',
	'row-gap',
	'justify-items',
	'justify-self',
	'place-content',
	'place-items',
	'place-self',
	'font-family',
	'list-style-type',
	'list-style-position',
	'text-decoration',
	'vertical-align',
	'white-space',
	'word-break',
	'background-attachment',
	'background-clip',
	'background-position',
	'background-repeat',
	'background-size',
	'background-image',
	'border-collapse',
	'table-layout',
	'box-shadow',
	'transition-property',
	'transition-duration',
	'transition-timing-function',
	'transition-delay',
	'animation',
	'transform',
	'transform-origin',
	'appearance',
	'cursor',
	'outline',
	'resize',
	'user-select',
	'fill',
	'stroke',
  'stroke-width',
  'pointer-events',
  'text-overflow',
  'font-style',
  'font-variant-numeric',
  'overflow-wrap'
]);

exports.isUtilitySupported = (utility, rule) => {
	// Skip utilities with pseudo-selectors
	if (utility.includes(':')) {
		return false;
	}

	// Skip unsupported utilities
	if (
		[
			'clearfix',
			'antialiased',
			'subpixel-antialiased',
			'sr-only',
			'not-sr-only',
			'isolate',
			'filter'
		].includes(utility) ||
		/^(space|placeholder|from|via|to|divide|ring|decoration|mix-blend|bg-blend|backdrop|filter)-/.test(utility) ||
		/^-?(scale|rotate|translate|skew)-/.test(utility) ||
		/^(\*)$/.test(utility)
	) {
		return false;
	}

	// Skip utilities with unsupported properties
	for (const {property, value} of rule.declarations) {
		if (unsupportedProperties.has(property)) {
			return false;
		}

		if (property === 'display' && !['flex', 'none'].includes(value)) {
			return false;
		}

		if (
			property === 'overflow' &&
			!['visible', 'hidden', 'scroll'].includes(value)
		) {
			return false;
		}

		if (property === 'position' && !['absolute', 'relative'].includes(value)) {
			return false;
		}

		if (property === 'line-height' && !value.endsWith('rem')) {
			return false;
		}
	
		// RN not support border-style: double
		if (property === 'border-style' && ['double', 'none'].includes(value)) {
			return false;
		}

		// flex alignment unsupported specify values
		if (['space-evenly', 'stretch'].includes(value)) {
			return false;
		}

		if (
			value === 'auto' ||
			value.endsWith('vw') ||
			value.endsWith('vh') ||
			value === 'currentColor'
		) {
			return false;
		}
	}

	return true;
};
