<?php
	global $wpcargo;
	$user_roles 		= wpcfe_current_user_role();
	$wpcargo_employee 	= wpcfe_get_users('wpcargo_employee');
	$wpcargo_agent 		= wpcfe_get_users('cargo_agent');
	$wpcargo_client 	= wpcfe_get_users('wpcargo_client');
?>
<?php if( in_array( 'wpcargo_client', (array)$user_roles ) && empty( array_intersect( $user_roles, wpcfe_assign_driver_roles() ) ) ): ?>
	<input type="hidden" name="registered_shipper" id="registered_shipper" value="<?php echo get_current_user_id(); ?>">
<?php else: ?>
	<div id="wpcfe-misc-assign-user" class="card mb-4">
		<section class="card-header">
			<?php echo apply_filters( 'wpcfe_registered_shipper_label', esc_html__('Assign shipment to','wpcargo-frontend-manager') ); ?>
		</section>
		<section class="card-body">
			<?php if( can_wpcfe_assign_client() ): ?>
				<div class="form-group">
					<div class="select-no-margin">
						<label><?php esc_html_e('Client','wpcargo-frontend-manager'); ?></label>
						<select name="registered_shipper" class="mdb-select mt-0 form-control browser-default" id="registered_client" >
							<option value=""><?php esc_html_e('-- Select Client --','wpcargo-frontend-manager'); ?></option>
							<?php if( !empty( $wpcargo_client ) ): ?>
								<?php foreach( $wpcargo_client as $key => $value ): ?>
									<option value="<?php echo $key; ?>" <?php selected( get_post_meta( $shipment->ID, 'registered_shipper', TRUE ), $key ); ?>><?php echo $value; ?></option>
								<?php endforeach; ?>	
							<?php  endif; ?>	                
						</select>
					</div>
				</div>
			<?php endif; ?>
			<?php if( can_wpcfe_assign_agent() ): ?>
				<div class="form-group">
					<div class="select-no-margin">
						<label><?php esc_html_e('Agent','wpcargo-frontend-manager'); ?></label>
						<select name="registered_agent" class="mdb-select mt-0 form-control browser-default" id="registered_agent" >
							<option value=""><?php esc_html_e('-- Select Agent --','wpcargo-frontend-manager'); ?></option>
							<?php if( !empty( $wpcargo_agent ) ): ?>
								<?php foreach( $wpcargo_agent as $agentID => $agentName ): ?>
									<option value="<?php echo $agentID; ?>" <?php selected( get_post_meta( $shipment->ID, 'agent_fields', TRUE ), $agentID ); ?>><?php echo $agentName; ?></option>
								<?php endforeach; ?>	
							<?php  endif; ?>	                
						</select>
					</div>
				</div>
			<?php endif; ?>
			<?php if( in_array( 'administrator', (array)$user_roles ) ): ?>
				<div class="form-group">
					<div class="select-no-margin">
						<label><?php esc_html_e('Employee','wpcargo-frontend-manager'); ?></label>
						<select name="registered_employee" class="mdb-select mt-0 form-control browser-default" id="registered_employee" >
							<option value=""><?php esc_html_e('-- Select Employee --','wpcargo-frontend-manager'); ?></option>
							<?php if( !empty( $wpcargo_employee ) ): ?>
								<?php foreach( $wpcargo_employee as $empID => $empName ): ?>
									<option value="<?php echo $empID; ?>" <?php selected( get_post_meta( $shipment->ID, 'wpcargo_employee', TRUE ), $empID ); ?>><?php echo $empName; ?></option>
								<?php endforeach; ?>	
							<?php endif; ?>	                
						</select>
					</div>
				</div>
			<?php endif; ?>
			<?php if( in_array( 'editor', (array)$user_roles ) ): ?>
				<div class="form-group">
					<div class="select-no-margin">
						<label><?php esc_html_e('Employee','wpcargo-frontend-manager'); ?></label>
						<select name="registered_employee" class="mdb-select mt-0 form-control browser-default" id="registered_employee" >
							<option value=""><?php esc_html_e('-- Select Employee --','wpcargo-frontend-manager'); ?></option>
							<?php if( !empty( $wpcargo_employee ) ): ?>
								<?php foreach( $wpcargo_employee as $empID => $empName ): ?>
									<option value="<?php echo $empID; ?>" <?php selected( get_post_meta( $shipment->ID, 'wpcargo_employee', TRUE ), $empID ); ?>><?php echo $empName; ?></option>
								<?php endforeach; ?>	
							<?php endif; ?>	                
						</select>
					</div>
				</div>
			<?php endif; ?>
			<?php do_action( 'wpcfe_after_designation_dropdown', $shipment->ID ); ?>
		</section>
	</div>
<?php  endif; ?>	