<?php
/**
 * Helper for Friedly HTML Output
 * 
 * @todo Replace only if your creating your own Plugin
 * @todo dst - Find all and replace text
 * @todo DST - Find all and replace text
 * @todo dealer - Find all and replace text
 */

// Exit if accessed directly
if( !defined( 'ABSPATH' ) ) exit;

/**
 * Helper for Friedly HTML Output
 *
 * @since 1.0.0
 * @todo To independently call, you can use DST_Friendly_HTML::text_slider($arr);
 */
class DST_Friendly_HTML {

  /**
   * Search Box HTML
   *
   * @access public
   * @since 1.0.0
   * @return void 
   */
  public function search_box(){
    return
      '<form class="form-inline">
        <div class="form-group">
          <label class="sr-only" for="postCodeSearch">Post Code Search</label>
          <div class="input-group">
            <div class="input-group-addon">Postcode</div>
            <input type="text" class="form-control" id="dst-postcode" placeholder="Search">
            <div id="dst_go" class="btn btn-primary input-group-addon">GO</div>
          </div>
        </div>
      </form>
       <div class="clearfix"><br></div>
      <div id="dst-ajax-results" class="dst-ajax-results clearfix"></div>';
   
  }

  /**
   * Search Box HTML
   *
   * @access public
   * @since 1.0.0
   * @return void 
   */
  public function google_map($posts_meta, $map_args){

    // PHP to JSON encode
    $postmeta_js = json_encode($posts_meta);
    $map_key_str = '';
   
    if(!empty($map_args[0])){
        $map_key_str = '&key='.$map_args[0];
    }
    $map_zoom = !empty($map_args[1]) ? $map_args[1]:2;
    $map_lat = !empty($map_args[3]) ? $map_args[3]:"37.4223434";
    $map_lng = !empty($map_args[4]) ? $map_args[4]:"-122.0843689";
  

    return
      '<div id="dst-map" class="dst-map clearfix" style="width: auto; height: 400px;"></div>

<script type="text/javascript">
function initGoogleMap(){
  "use strict";
  var locations = '.$postmeta_js.';

    var map = new google.maps.Map(document.getElementById("dst-map"), {
      zoom: '.$map_zoom.',
      center: new google.maps.LatLng('.$map_lat.', '.$map_lng.'), // default location
      mapTypeId: google.maps.MapTypeId.ROADMAP
    });

     var infoWindow = new google.maps.InfoWindow({map: map});

// Try HTML5 geolocation.

        if (navigator.geolocation) {

          navigator.geolocation.getCurrentPosition(function(position) {
            var pos = {
              lat: position.coords.latitude,
              lng: position.coords.longitude
            };

            infoWindow.setPosition(pos);
            infoWindow.setContent("You\'re here!");
            map.setCenter(pos);
          }, function() {
      handleLocationError(true, infoWindow, map.getCenter());
          });
        } else {
          // Browser doesn\'t support Geolocation
          handleLocationError(false, infoWindow, map.getCenter());
        }

       function handleLocationError(browserHasGeolocation, infoWindow, pos) {
        infoWindow.setPosition(pos);
        infoWindow.setContent(browserHasGeolocation ?
                              "Your location is unknown" :
                              "Error: Your browser doesn\"t support geolocation.");
      }

    var marker, i;
    for (i = 0; i < locations.length; i++) {  
      marker = new google.maps.Marker({
        position: new google.maps.LatLng(locations[i].post_meta[9], locations[i].post_meta[10]),
        map: map,
        title: locations[i].post_title
      });
      google.maps.event.addListener(marker, "click", (function(marker, i) {
        return function() {
          infoWindow.setContent(locations[i].post_title + \' <a class="dst-map-info glyphicon glyphicon-info-sign" aria-hidden="true" target="_blank" href="\'+locations[i].post_uri+\'"><span class="dst-info hide-text">info</span></a>\');
          infoWindow.open(map, marker);
        }
      })(marker, i));
    }
}
// google.maps.event.addDomListener(window, "load", initGoogleMap);
</script>

<script async defer
        src="//maps.googleapis.com/maps/api/js?callback=initGoogleMap'.$map_key_str.'">
</script>';
   
  }

  /**
   * Dealer Profile HTML
   *
   * @access public
   * @since 1.0.0
   * @return void 
   */
  public function dealer_profile($post_title, $get_postmeta){
    ?>
     <div class="dst-profile-wrap">
          <div class="panel panel-info">
            <div class="panel-heading">
              <h3 class="panel-title"><?php echo $post_title; ?></h3>
            </div>
            <div class="panel-body">
              <div class="row">
                <?php if(!empty($get_postmeta[1])): ?>
                <div class="col-md-3 col-lg-3 " align="center"> <img alt="dealer logo" src="<?php echo $get_postmeta[1]; ?>" class="img-square img-responsive"> </div>
                <?php endif ?>
                <div class=" col-md-9 col-lg-9 "> 
                  <table class="table table-user-information">
                    <tbody>
                      <tr>
                        <td><?php _e('About the Dealer:', 'dst-txt'); ?></td>
                        <td><?php echo isset($get_postmeta[0])?$get_postmeta[0]:'' ?></td>
                      </tr>
                      <tr>
                        <td><?php _e('Street Address:', 'dst-txt'); ?></td>
                        <td><?php echo isset($get_postmeta[2])?$get_postmeta[2]:'' ?></td>
                      </tr>
                      <tr>
                        <td><?php _e('City:', 'dst-txt'); ?></td>
                        <td><?php echo isset($get_postmeta[3])?$get_postmeta[3]:'' ?></td>
                      </tr>
                      <tr>
                        <td><?php _e('Postcode:', 'dst-txt'); ?></td>
                        <td><?php echo isset($get_postmeta[4])?$get_postmeta[4]:'' ?></td>
                      </tr>
                      <tr>
                        <td><?php _e('State/County:', 'dst-txt'); ?></td>
                        <td><?php echo isset($get_postmeta[5])?$get_postmeta[5]:'' ?></td>
                      </tr>
                      <tr>
                        <td><?php _e('Country:', 'dst-txt'); ?></td>
                        <td><?php echo isset($get_postmeta[6])?$get_postmeta[6]:'' ?></td>
                      </tr>
                      <tr>
                        <td>Email</td>
                        <td><a href="mailto:<?php echo isset($get_postmeta[7])?$get_postmeta[7]:'' ?>"><?php echo isset($get_postmeta[7])?$get_postmeta[7]:'' ?></a></td>
                      </tr>
                      <tr><td>Phone Number</td>
                        <td><?php echo isset($get_postmeta[8])?$get_postmeta[8]:'' ?><br><br>
                        </td> 
                      </tr>
                   
                     
                    </tbody>
                  </table>
                  
    
                  <a href="#" class="btn btn-primary pull-right hide"><?php _e('View Map:', 'dst-txt'); ?></a>
                </div>
              </div>
            </div>
                 <div class="panel-footer">
                        <a data-original-title="Broadcast Message" data-toggle="tooltip" type="button" class="btn btn-sm btn-primary"><i class="glyphicon glyphicon-envelope"></i></a>
                        <!--
                        <span class="pull-right">
                            <a href="edit.html" data-original-title="Edit this user" data-toggle="tooltip" type="button" class="btn btn-sm btn-warning"><i class="glyphicon glyphicon-edit"></i></a>
                            <a data-original-title="Remove this user" data-toggle="tooltip" type="button" class="btn btn-sm btn-danger"><i class="glyphicon glyphicon-remove"></i></a>
                        </span>
                        -->
                    </div>
            
          </div>
        </div>
    <?php 
  }




}

