/**
 * Register a shortcode to display an overview of our travels.
 * This shortcode will be used on the primary landing page for our plugin.
 *
 * Usage: [wanderlist-overview], by default will show a dashboard of stats and widgets.
 * If there are no upcoming locations, it will default to most-recently-visited locations.
 *
 * We'll set up a settings page later to fine-tune its output, or
 * potentially allow users to pass parameters. For now, no options.
 */
function wanderlist_overview_shortcode($atts, $content = null)
{
    $a = shortcode_atts(array('show' => 'current'), $atts);
    $widgets[] = array('class' => 'wanderlist-map-widget', 'content' => wanderlist_show_map());
    $widgets[] = array('class' => 'wanderlist-location-widget', 'title' => esc_html__('Coming up!', 'wanderlist'), 'content' => wanderlist_list_locations(10, 'upcoming'));
    $widgets[] = array('class' => 'wanderlist-location-widget', 'title' => esc_html__('Where I’ve been lately', 'wanderlist'), 'content' => wanderlist_list_locations(10, 'past'));
    $widgets[] = array('class' => 'wanderlist-trip-widget', 'title' => esc_html__('Long trips', 'wanderlist'), 'content' => wanderlist_list_trips());
    $widgets[] = array('class' => 'wanderlist-country-widget', 'title' => esc_html__('Countries visited', 'wanderlist'), 'content' => wanderlist_list_countries('list'));
    $widgets[] = array('class' => 'wanderlist-number-widget', 'title' => esc_html__('Stats', 'wanderlist'), 'content' => '<div class="wanderlist-place-count">' . '<span class="wanderlist-number">' . wanderlist_count('places') . '</span><span class="wanderlist-item">' . esc_html__('Places', 'wanderlist') . '</span></div>
			<span class="wanderlist-connector">' . esc_html__('in', 'wanderlist') . '</span>
			<div class="wanderlist-country-count"><span class="wanderlist-number">' . wanderlist_count('countries') . '</span><span class="wanderlist-item">' . esc_html__('Countries', 'wanderlist') . '</span></div>
			<span class="wanderlist-connector">' . esc_html__('on', 'wanderlist') . '</span>
			<div class="wanderlist-continent-count"><span class="wanderlist-number">' . wanderlist_count('continents') . '</span><span class="wanderlist-item">' . esc_html__('Continents', 'wanderlist') . '</span></div>');
    $return = '<div class="wanderlist-overview">';
    foreach ($widgets as $widget) {
        if ('<dl></dl>' !== $widget['content'] && '<ul></ul>' !== $widget['content']) {
            $return .= '<div class="wanderlist-widget ' . $widget['class'] . '">';
            if (isset($widget['title'])) {
                $return .= '<h3 class="widget-title">' . $widget['title'] . '</h3>';
            }
            $return .= $widget['content'];
            $return .= '</div>';
        }
    }
    $return .= '</div>';
    return $return;
}
/**
 * Display a map of some kind.
 * This will need to be automated to draw countries and show points.
 * @todo: Output a helpful error message if the Mapbox API key isn't set properly.
 */
function wanderlist_show_map($overlay = null)
{
    $options = get_option('wanderlist_settings');
    $output = '<div id="wanderlist-map" data-mapboxkey="' . esc_attr($options['wanderlist_mapbox_key']) . '" data-mapid="' . esc_attr($options['wanderlist_map_id']) . '" data-markercolour="' . esc_attr($options['wanderlist_marker_colour']) . '" data-linecolour="' . esc_attr($options['wanderlist_line_colour']) . '">';
    if ('upcoming' === $overlay) {
        $output .= '<div class="wanderlist-widget wanderlist-location-widget">';
        $output .= '<h3>' . esc_html__('Adventure Ahoy!', 'wanderlist') . '</h3>';
        $output .= wanderlist_list_locations('3');
        $output .= '</div><!-- .flare-location-widget -->';
    }
    $output .= '</div><!-- .map -->';
    return $output;
}