<div class="panel panel-default">
  <div class="panel-heading">
    <h3 class="panel-title"><i class="fa fa-search"></i> {{ heading_title }}</h3>
  </div>
  <div class="panel-body">
      <div class="row">
          <div class="col-sm-4">
          <div class="form-group">
            <label class="control-label" for="input-pname">{{ entry_pname }}</label>
            <div class="input-group input-group-sm">
              <input type="text" name="filter_pname" value="{{ filter_pname }}" placeholder="{{ entry_pname }}" id="input-pname" class="form-control" />
              <span class="input-group-btn"><button class="btn btn-primary" onclick="meadminsearch('catalog/product','filter_name','filter_pname')"><i class="fa fa-search"></i></button></span>
            </div>
          </div>
        </div>
        
        <div class="col-sm-4">
        <div class="form-group">
          <label class="control-label" for="input-cname">{{ entry_cname }}</label>
          <div class="input-group input-group-sm">
            <input type="text" name="filter_cname" value="{{ filter_cname }}" placeholder="{{ entry_cname }}" id="input-cname" class="form-control" />
            <span class="input-group-btn"><button class="btn btn-primary" onclick="meadminsearch('catalog/category','filter_name','filter_cname')"><i class="fa fa-search"></i></button></span>
          </div>
        </div>
      </div>
        
          <div class="col-sm-4">
          <div class="form-group">
            <label class="control-label" for="input-manufacturer">{{ entry_manufacturer }}</label>
            <div class="input-group input-group-sm">
              <input type="text" name="filter_pmanufacturer" value="{{ filter_pmanufacturer }}" placeholder="{{ entry_manufacturer }}" id="input-manufacturer" class="form-control" />
              <span class="input-group-btn"><button class="btn btn-primary" onclick="meadminsearch('catalog/manufacturer','filter_name','filter_pmanufacturer')"><i class="fa fa-search"></i></button></span>
            </div>
          </div>
        </div>
        
        <div class="col-sm-4">
        <div class="form-group">
          <label class="control-label" for="input-customer_name">{{ entry_customer }}</label>
          <div class="input-group input-group-sm">
            <input type="text" name="filter_customer_name" value="{{ filter_customer_name }}" placeholder="{{ entry_customer }}" id="input-customer_name" class="form-control" />
            <span class="input-group-btn"><button class="btn btn-primary" onclick="meadminsearch('customer/customer','filter_name','filter_customer_name')"><i class="fa fa-search"></i></button></span>
          </div>
        </div>
      </div>
        
        <div class="col-sm-4">
        <div class="form-group">
          <label class="control-label" for="input-customer_email">{{ entry_customer_email }}</label>
          <div class="input-group input-group-sm">
            <input type="text" name="filter_customer_email" value="{{ filter_customer_email }}" placeholder="{{ entry_customer_email }}" id="input-customer_email" class="form-control" />
            <span class="input-group-btn"><button class="btn btn-primary" onclick="meadminsearch('customer/customer','filter_email','filter_customer_email')"><i class="fa fa-search"></i></button></span>
          </div>
        </div>
      </div>
      
      <div class="col-sm-4">
        <div class="form-group">
          <label class="control-label" for="input-customer_telephone">{{ entry_customer_telephone }}</label>
          <div class="input-group input-group-sm">
            <input type="text" name="filter_customer_telephone" value="{{ filter_customer_telephone }}" placeholder="{{ entry_customer_telephone }}" id="input-customer_telephone" class="form-control" />
            <span class="input-group-btn"><button class="btn btn-primary" onclick="meadminsearch('customer/customer','filter_telephone','filter_customer_telephone')"><i class="fa fa-search"></i></button></span>
          </div>
        </div>
      </div>
      
      <div class="col-sm-4">
        <div class="form-group">
          <label class="control-label" for="input-orderid">{{ entry_orderid }}</label>
          <div class="input-group input-group-sm">
            <input type="text" name="filter_orderid" value="{{ filter_orderid }}" placeholder="{{ entry_orderid }}" id="input-orderid" class="form-control" />
            <span class="input-group-btn"><button class="btn btn-primary" onclick="meadminsearch('sale/order','filter_order_id','filter_orderid')"><i class="fa fa-search"></i></button></span>
          </div>
        </div>
      </div>
      
      <div class="col-sm-4">
        <div class="form-group">
          <label class="control-label" for="input-orderbycustomer">{{ entry_orderbycustomer }}</label>
          <div class="input-group input-group-sm">
            <input type="text" name="filter_orderbycustomer" value="{{ filter_orderbycustomer }}" placeholder="{{ entry_orderbycustomer }}" id="input-orderbycustomer" class="form-control" />
            <span class="input-group-btn"><button class="btn btn-primary" onclick="meadminsearch('sale/order','filter_customer','filter_orderbycustomer')"><i class="fa fa-search"></i></button></span>
          </div>
        </div>
      </div>
      
      <div class="col-sm-4">
        <div class="form-group">
          <label class="control-label" for="input-orderbycustomertel">{{ entry_orderbycustomertel }}</label>
          <div class="input-group input-group-sm">
            <input type="text" name="filter_orderbycustomertel" value="{{ filter_orderbycustomertel }}" placeholder="{{ entry_orderbycustomertel }}" id="input-orderbycustomertel" class="form-control" />
            <span class="input-group-btn"><button class="btn btn-primary" onclick="meadminsearch('sale/order','filter_telephone','filter_orderbycustomertel')"><i class="fa fa-search"></i></button></span>
          </div>
        </div>
      </div>
      </div>
  </div>
</div>

<script type="text/javascript"><!--
$('.search-toggle').on('click', function(event){
    event.preventDefault();
  $('.me_dropdown_menu').toggle();
});
$(document).on("click", function(event){
  var $trigger = $("#me_admin_search");
  if($trigger !== event.target && !$trigger.has(event.target).length){
    $('.me_dropdown_menu').css('display','none');
  }            
});

$('#button-searchdate').on('click', function() {
  var url = '';
  
  var filter_from_date = $('input[name=\'filter_from_date\']').val();

  if (filter_from_date) {
    url += '&filter_from_date=' + encodeURIComponent(filter_from_date);
  }
  
  var filter_to_date = $('input[name=\'filter_to_date\']').val();

  if (filter_to_date) {
    url += '&filter_to_date=' + encodeURIComponent(filter_to_date);
  }
  
  location = 'index.php?route=sale/order&user_token={{ user_token }}' + url;
});

//Category
$('input[name=\'filter_cname\']').autocomplete({
  'source': function(request, response) {
    $.ajax({
      url: 'index.php?route=catalog/category/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
      dataType: 'json',
      success: function(json) {
        response($.map(json, function(item) {
          return {
            label: item['name'],
            value: item['category_id']
          }
        }));
      }
    });
  },
  'select': function(item) {
    $('input[name=\'filter_cname\']').val(item['label']);
  }
});

//Product Name
$('input[name=\'filter_pname\']').autocomplete({
  'source': function(request, response) {
    $.ajax({
      url: 'index.php?route=catalog/product/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
      dataType: 'json',
      success: function(json) {
        response($.map(json, function(item) {
          return {
            label: item['name'],
            value: item['product_id']
          }
        }));
      }
    });
  },
  'select': function(item) {
    $('input[name=\'filter_pname\']').val(item['label']);
  }
});

$('input[name=\'filter_orderbyproduct\']').autocomplete({
  'source': function(request, response) {
    $.ajax({
      url: 'index.php?route=catalog/product/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
      dataType: 'json',
      success: function(json) {
        response($.map(json, function(item) {
          return {
            label: item['name'],
            value: item['product_id']
          }
        }));
      }
    });
  },
  'select': function(item) {
    $('input[name=\'filter_orderbyproduct\']').val(item['label']);
  }
});

//Product Model
  $('input[name=\'filter_pmodel\']').autocomplete({
  'source': function(request, response) {
    $.ajax({
      url: 'index.php?route=catalog/product/autocomplete&user_token={{ user_token }}&filter_model=' +  encodeURIComponent(request),
      dataType: 'json',
      success: function(json) {
        response($.map(json, function(item) {
          return {
            label: item['model'],
            value: item['product_id']
          }
        }));
      }
    });
  },
  'select': function(item) {
    $('input[name=\'filter_pmodel\']').val(item['label']);
  }
});

//Product SKU
  $('input[name=\'filter_psku\']').autocomplete({
  'source': function(request, response) {
    $.ajax({
      url: 'index.php?route=extension/module/me_admin_search/pautocomplete&user_token={{ user_token }}&filter_sku=' +  encodeURIComponent(request),
      dataType: 'json',
      success: function(json) {
        response($.map(json, function(item) {
          return {
            label: item['sku'],
            value: item['product_id']
          }
        }));
      }
    });
  },
  'select': function(item) {
    $('input[name=\'filter_psku\']').val(item['label']);
  }
});

//Manufacturer
$('input[name=\'filter_pmanufacturer\']').autocomplete({
  'source': function(request, response) {
    $.ajax({
      url: 'index.php?route=catalog/manufacturer/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
      dataType: 'json',
      success: function(json) {
        response($.map(json, function(item) {
          return {
            label: item['name'],
            value: item['manufacturer_id']
          }
        }));
      }
    });
  },
  'select': function(item) {
    $('input[name=\'filter_pmanufacturer\']').val(item['label']);
  }
});

//Option
$('input[name=\'filter_poption\']').autocomplete({
  'source': function(request, response) {
    $.ajax({
      url: 'index.php?route=catalog/option/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
      dataType: 'json',
      success: function(json) {
        response($.map(json, function(item) {
          return {
            label: item['name'],
            value: item['option_id']
          }
        }));
      }
    });
  },
  'select': function(item) {
    $('input[name=\'filter_poption\']').val(item['label']);
  }
});

//Customer
$('input[name=\'filter_customer_name\']').autocomplete({
    'source': function(request, response) {
      $.ajax({
        url: 'index.php?route=customer/customer/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
        dataType: 'json',
        success: function(json) {
          response($.map(json, function(item) {
            return {
              label: item['name'],
              value: item['customer_id']
            }
          }));
        }
      });
    },
    'select': function(item) {
      $('input[name=\'filter_customer_name\']').val(item['label']);
    }
});

$('input[name=\'filter_orderbycustomer\']').autocomplete({
    'source': function(request, response) {
      $.ajax({
        url: 'index.php?route=customer/customer/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
        dataType: 'json',
        success: function(json) {
          response($.map(json, function(item) {
            return {
              label: item['name'],
              value: item['customer_id']
            }
          }));
        }
      });
    },
    'select': function(item) {
      $('input[name=\'filter_orderbycustomer\']').val(item['label']);
    }
});

$('input[name=\'filter_customer_email\']').autocomplete({
    'source': function(request, response) {
      $.ajax({
        url: 'index.php?route=customer/customer/autocomplete&user_token={{ user_token }}&filter_email=' +  encodeURIComponent(request),
        dataType: 'json',
        success: function(json) {
          response($.map(json, function(item) {
            return {
              label: item['email'],
              value: item['customer_id']
            }
          }));
        }
      });
    },
    'select': function(item) {
      $('input[name=\'filter_customer_email\']').val(item['label']);
    }
});

$('input[name=\'filter_mcoupon\']').autocomplete({
  'source': function(request, response) {
    $.ajax({
      url: 'index.php?route=extension/module/me_admin_search/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
      dataType: 'json',
      success: function(json) {
        response($.map(json, function(item) {
          return {
            label: item['name'],
            value: item['coupon_id']
          }
        }));
      }
    });
  },
  'select': function(item) {
    $('input[name=\'filter_mcoupon\']').val(item['label']);
  }
});

$('#me_admin_search input').on('keydown', function(e) {
  if (e.keyCode == 13) {
    $(this).parent().find('button').trigger('click');
  }
});

function meadminsearch(route,key,filter_key){
  var url = '';
  
  if(key == 'filter_order_status_id'){
    var filter_key_value = $('select[name=\''+ filter_key +'\']').val();
  }else{
    var filter_key_value = $('input[name=\''+ filter_key +'\']').val();
  }
  
  if (filter_key_value) {
    url += '&'+ key +'=' + encodeURIComponent(filter_key_value);
  }
  
  location = 'index.php?route='+ route +'&user_token={{ user_token }}' + url;
}
//--></script>
<script type="text/javascript"><!--
$('.date').datetimepicker({
  language: '{{ datepicker }}',
  pickTime: false
});
//--></script>