/**
 * Refresh the travel data for an event.
 *
 * @since	1.4
 */
function mdjm_update_event_travel_data_ajax()
{
    $employee_id = $_POST['employee_id'];
    $dest = $_POST['venue'];
    $dest = maybe_unserialize($dest);
    $mdjm_travel = new MDJM_Travel();
    if (!empty($employee_id)) {
        $mdjm_travel->__set('start_address', $mdjm_travel->get_employee_address($employee_id));
    }
    $mdjm_travel->set_destination($dest);
    $mdjm_travel->get_travel_data();
    if (!empty($mdjm_travel->data)) {
        $travel_cost = $mdjm_travel->get_cost();
        $response = array('type' => 'success', 'distance' => mdjm_format_distance($mdjm_travel->data['distance'], false, true), 'time' => mdjm_seconds_to_time($mdjm_travel->data['duration']), 'cost' => !empty($travel_cost) ? mdjm_currency_filter(mdjm_format_amount($travel_cost)) : mdjm_currency_filter(mdjm_format_amount(0)), 'directions_url' => $mdjm_travel->get_directions_url(), 'raw_cost' => $travel_cost);
    } else {
        $response = array('type' => 'error');
    }
    wp_send_json($response);
}
/**
 * Adds the travel data row to the venue details metabox on the event screen.
 *
 * @since	1.4
 * @param	int|arr|obj	$dest			An address array, event ID, event object or venue ID.
 * @param	int			$employee_id	An employee user ID.
 * @return	void
 */
function mdjm_show_travel_data_row($dest, $employee_id = '')
{
    $mdjm_travel = new MDJM_Travel();
    if (!empty($employee_id)) {
        $mdjm_travel->__set('start_address', $mdjm_travel->get_employee_address($employee_id));
    }
    $mdjm_travel->set_destination($dest);
    if (empty($employee_id)) {
        if (is_object($dest)) {
            $mdjm_travel->__set('start_address', $mdjm_travel->get_employee_address($dest->employee_id));
        } elseif (is_numeric($dest)) {
            if ('mdjm-event' == get_post_type($dest)) {
                $mdjm_travel->__set('start_address', $mdjm_travel->get_employee_address(mdjm_get_event_primary_employee_id($dest)));
            }
        }
    }
    $mdjm_travel->get_travel_data();
    $distance = '';
    $duration = '';
    $cost = '';
    $directions_url = '';
    $directions = $mdjm_travel->get_directions_url();
    $class = 'mdjm-hidden';
    if (!empty($mdjm_travel->data)) {
        $distance = mdjm_format_distance($mdjm_travel->data['distance'], false, true);
        $duration = mdjm_seconds_to_time($mdjm_travel->data['duration']);
        $cost = mdjm_currency_filter(mdjm_format_amount($mdjm_travel->get_cost()));
        $directions_url = $directions ? $directions : '';
        $class = '';
    }
    ob_start();
    ?>
	<tr id="mdjm-travel-data" class="<?php 
    echo $class;
    ?>
">
		<td><i class="fa fa-car" aria-hidden="true" title="<?php 
    _e('Distance', 'mobile-dj-manager');
    ?>
"></i>
			<span class="mdjm-travel-distance"><?php 
    echo $distance;
    ?>
</span></td>
		<td><i class="fa fa-clock-o" aria-hidden="true" title="<?php 
    _e('Travel Time', 'mobile-dj-manager');
    ?>
"></i>
			<span class="mdjm-travel-time"><?php 
    echo $duration;
    ?>
</span></td>
		<td><i class="fa fa-money" aria-hidden="true" title="<?php 
    _e('Cost', 'mobile-dj-manager');
    ?>
"></i>
			<span class="mdjm-travel-cost"><?php 
    echo $cost;
    ?>
</span></td>
	</tr>

    <tr id="mdjm-travel-directions" class="<?php 
    echo $class;
    ?>
">
        <td colspan="3"><i class="fa fa-map-signs" aria-hidden="true" title="<?php 
    _e('Directions', 'mobile-dj-manager');
    ?>
"></i>
        <span class="mdjm-travel-directions"><a id="travel_directions" href="<?php 
    echo $directions_url;
    ?>
" target="_blank"><?php 
    _e('Directions', 'mobile-dj-manager');
    ?>
</a></span></td>
    </tr>

	<?php 
    $travel_data_row = ob_get_contents();
    ob_end_clean();
    echo $travel_data_row;
}