import {
ButtonGroup,
Button,
Tooltip,
RangeControl,
__experimentalNumberControl as NumberControl,
} from '@wordpress/components';
import ResponsiveToggle from '../responsive-toggle';
import { __, sprintf } from '@wordpress/i18n';
import styles from './editor.lazy.scss';
import React, { useLayoutEffect } from 'react';
import { limitMax, limitMin } from '@Controls/unitWiseMinMaxOption';
import UAGReset from '../reset';
const isNumberControlSupported = !! NumberControl;
const Range = ( props ) => {
// Add and remove the CSS on the drop and remove of the component.
useLayoutEffect( () => {
styles.use();
return () => {
styles.unuse();
};
}, [] );
const { withInputField, isShiftStepEnabled } = props;
let max = limitMax( props.unit?.value, props );
let min = limitMin( props.unit?.value, props );
const inputValue = isNaN( props?.value ) ? '' : props?.value;
let unitSizes = [
{
name: __( 'Pixel', 'ultimate-addons-for-gutenberg' ),
unitValue: 'px',
},
{
name: __( 'Em', 'ultimate-addons-for-gutenberg' ),
unitValue: 'em',
},
];
if ( props.units ) {
unitSizes = props.units;
}
const handleOnChange = ( newValue ) => {
const parsedValue = parseFloat( newValue );
if ( props.setAttributes ) {
props.setAttributes( {
[ props.data.label ]: parsedValue,
} )
}
if ( props?.onChange ) {
props.onChange( parsedValue );
}
};
const resetValues = ( defaultValues ) => {
if ( props?.onChange ) {
props?.onChange( defaultValues[props?.data?.label] )
}
if ( props.displayUnit ) {
onChangeUnits( defaultValues[props?.unit?.label] )
}
};
const onChangeUnits = ( newValue ) => {
props.setAttributes( { [ props.unit.label ]: newValue } );
max = limitMax( newValue, props );
min = limitMin( newValue, props );
if ( props.value > max ) {
handleOnChange( max );
}
if ( props.value < min ) {
handleOnChange( min );
}
};
const onUnitSizeClick = ( uSizes ) => {
const items = [];
uSizes.map( ( key ) =>
items.push(
{ props.help }
) }