{{ header }}{{ column_left }}
<div id="content">
  <div class="page-header">
    <div class="container-fluid">
      <div class="pull-right">
        <button type="button" data-toggle="tooltip" title="{{ button_filter }}" onclick="$('#filter-product').toggleClass('hidden-sm hidden-xs');" class="btn btn-default hidden-md hidden-lg"><i class="fa fa-filter"></i></button>
        {% if config_product_download == 1 %}
        <a href="{{ download }}" data-toggle="tooltip" title="{{ button_download }}" class="btn btn-warning"><i class="fa fa-download"></i></a>
        {% endif %}
        <a href="{{ add }}" data-toggle="tooltip" title="{{ button_add }}" class="btn btn-primary"><i class="fa fa-plus"></i></a>
        <button type="submit" form="form-product" formaction="{{ copy }}" data-toggle="tooltip" title="{{ button_copy }}" class="btn btn-default"><i class="fa fa-copy"></i></button>
        <button type="button" form="form-product" formaction="{{ delete }}" data-toggle="tooltip" title="{{ button_delete }}" class="btn btn-danger" onclick="confirm('{{ text_confirm }}') ? $('#form-product').submit() : false;"><i class="fa fa-trash-o"></i></button>
      </div>
      <h1>{{ heading_title }}</h1>
      <ul class="breadcrumb">
        {% for breadcrumb in breadcrumbs %}
        <li><a href="{{ breadcrumb.href }}">{{ breadcrumb.text }}</a></li>
        {% endfor %}
      </ul>
    </div>
  </div>
  <div class="container-fluid">{% if error_warning %}
    <div class="alert alert-danger alert-dismissible"><i class="fa fa-exclamation-circle"></i> {{ error_warning }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    {% if success %}
    <div class="alert alert-success alert-dismissible"><i class="fa fa-check-circle"></i> {{ success }}
      <button type="button" class="close" data-dismiss="alert">&times;</button>
    </div>
    {% endif %}
    
    <div class="row">
        <div id="filter-product" class="col-md-12 col-sm-12 hidden-sm hidden-xs">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title"><i class="fa fa-filter"></i> {{ text_filter }}</h3>
          </div>
          <div class="panel-body">
              
            <div class="row">
                <div class="col-md-2">
                    <div class="form-group">
                      <label class="control-label" for="input-id">{{ entry_id }}</label>
                      <input type="text" name="filter_id" value="{{ filter_id }}" placeholder="{{ entry_id }}" id="input-id" class="form-control" />
                    </div>
                </div>
                <div class="col-md-4">
                    <div class="form-group">
                      <label class="control-label" for="input-name">{{ entry_name }}</label>
                      <input type="text" name="filter_name" value="{{ filter_name }}" placeholder="{{ entry_name }}" id="input-name" class="form-control" />
                    </div>
                </div>
                
                <div class="col-md-2">
                    <div class="form-group">
                        <label class="control-label" for="input-parent">{{ entry_category }}</label>
                        <input type="text" name="path" value="{{ path }}" placeholder="{{ entry_category }}" id="input-parent" class="form-control" />
                        <input type="hidden" name="filter_category_id" value="{{ filter_category_id }}" />
                      </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                        <label class="control-label" for="input-stock-status">{{ column_stock_status }}</label>
                        <select name="filter_stock_status" id="input-stock-status" class="form-control">
                          <option value="*">-- Select Stock Status --</option>
                          {% for status in stock_statuses %}
                            <option value="{{ status.stock_status_id }}" {% if status.stock_status_id == filter_stock_status %}selected{% endif %}>{{ status.name }}</option>
                          {% endfor %}
                        </select>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                        <label class="control-label" for="input-manufacturer">{{ entry_manufacturer }}</label>
                        <input type="text" name="manufacturer" value="{{ manufacturer }}" placeholder="{{ entry_manufacturer }}" id="input-manufacturer" class="form-control"/> 
                        <input type="hidden" name="filter_manufacture" value="{{ filter_manufacture }}"/>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                      <label class="control-label" for="input-model">{{ entry_model }}</label>
                      <input type="text" name="filter_model" value="{{ filter_model }}" placeholder="{{ entry_model }}" id="input-model" class="form-control" />
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                      <label class="control-label" for="input-price">{{ entry_price }}</label>
                      <input type="text" name="filter_price" value="{{ filter_price }}" placeholder="{{ entry_price }}" id="input-price" class="form-control" />
                    </div>
                </div>
                {#<div class="col-md-2">#}
                {#    <div class="form-group">#}
                {#      <label class="control-label" for="input-quantity">{{ entry_quantity }}</label>#}
                {#      <input type="text" name="filter_quantity" value="{{ filter_quantity }}" placeholder="{{ entry_quantity }}" id="input-quantity" class="form-control" />#}
                {#    </div>#}
                {#</div>#}
                <div class="col-md-2">
                    <div class="form-group">
                      <label class="control-label" for="input-status">{{ entry_status }}</label>
                      <select name="filter_status" id="input-status" class="form-control">
                        <option value=""></option>
                          {% if filter_status == '1' %}
                        <option value="1" selected="selected">{{ text_enabled }}</option>
                          {% else %}
                        <option value="1">{{ text_enabled }}</option>
                          {% endif %}
                          {% if filter_status == '0' %}
                        <option value="0" selected="selected">{{ text_disabled }}</option>
                          {% else %}
                        <option value="0">{{ text_disabled }}</option>
                          {% endif %}
                      </select>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                      <label class="control-label" for="input-user">{{ entry_users }}</label>
                      <input type="text" name="users" value="{{ users }}" placeholder="{{ entry_users }}" id="input-user" class="form-control" />
                      <input type="hidden" name="filter_added_by" value="{{ filter_added_by }}" />
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                      <label class="control-label" for="filter_date_added_from">{{ entry_date_added_from }}</label>
                      <input type="date" name="filter_date_added_from" value="{{ filter_date_added_from }}" id="filter_date_added_from" class="form-control"/>
                    </div>
                </div>
                <div class="col-md-2">
                    <div class="form-group">
                      <label class="control-label" for="filter_date_added_to">{{ entry_date_added_to }}</label>
                      <input type="date" name="filter_date_added_to" value="{{ filter_date_added_to }}" id="filter_date_added_to" class="form-control"/>
                    </div>
                </div>
            </div>
            <div class="form-group text-right">
              <button type="button" id="button-filter" class="btn btn-default"><i class="fa fa-filter"></i> {{ button_filter }}</button>
              <button type="button" id="button-clear" class="btn btn-danger">{{ button_clear }}</button>
            </div>
          </div>
        </div>
      </div>
    </div>
    
    <div class="row">
      <div class="col-md-12 col-sm-12">
        <div class="panel panel-default">
          <div class="panel-heading">
            <h3 class="panel-title"><i class="fa fa-list"></i> {{ text_list }}</h3>
          </div>
          <div class="panel-body">
            <form action="{{ delete }}" method="post" enctype="multipart/form-data" id="form-product">
              <div class="table-responsive">
                <table class="table table-bordered table-hover">
                  <thead>
                    <tr>
                      <td style="width: 1px;" class="text-center"><input type="checkbox" onclick="$('input[name*=\'selected\']').prop('checked', this.checked);" /></td>
                      <td class="text-center">{{ column_id }}</td>
                      <td class="text-center">{{ column_image }}</td>
                      <td class="text-left">{% if sort == 'pd.name' %} <a href="{{ sort_name }}" class="{{ order|lower }}">{{ column_name }}</a> {% else %} <a href="{{ sort_name }}">{{ column_name }}</a> {% endif %}</td>
                      <td class="text-left">{{ entry_category }}</td>
                      <td class="text-left">{% if sort == 'p.price' %} <a href="{{ sort_price }}" class="{{ order|lower }}">{{ column_price }}</a> {% else %} <a href="{{ sort_price }}">{{ column_price }}</a> {% endif %}</td>
                      <td class="text-left">{% if sort == 'p.quantity' %} <a href="{{ sort_quantity }}" class="{{ order|lower }}">{{ column_quantity }}</a> {% else %} <a href="{{ sort_quantity }}">{{ column_quantity }}</a> {% endif %}</td>
                      <td class="text-left">{% if sort == 'p.status' %} <a href="{{ sort_status }}" class="{{ order|lower }}">{{ column_status }}</a> {% else %} <a href="{{ sort_status }}">{{ column_status }}</a> {% endif %}</td>
                      <td class="text-left">{{ text_viewed }}</td>
                      <td class="text-left">{{ column_seo_score }}</td>
                      <td class="text-left">{{ column_product_strength }}</td>
                      <td class="text-left">{{ text_date_added }}</td>
                      <td class="text-right">{{ column_action }}</td>
                    </tr>
                  </thead>
                  <tbody>
                  
                  {% if products %}
                  {% for product in products %}
                  <tr>
                    <td class="text-center">{% if product.product_id in selected %}
                      <input type="checkbox" name="selected[]" value="{{ product.product_id }}" checked="checked" />
                      {% else %}
                      <input type="checkbox" name="selected[]" value="{{ product.product_id }}" />
                      {% endif %}</td>
                    <td class="text-center">{{ product.product_id }}</td>
                    <td class="text-center">{% if product.image %} <img src="{{ product.image }}" alt="{{ product.name }}" class="img-thumbnail" /> {% else %} <span class="img-thumbnail list"><i class="fa fa-camera fa-2x"></i></span> {% endif %}</td>
                    <td class="text-left"><a href="{{ product.view }}" target="_blank">{{ product.name }}</a></td>
                    <td class="text-left">{% for category in categories %}{% if category.category_id in product.category %}{{ category.name }}<br>{% endif %}{% endfor %}</td>
                    <td class="text-left">{% if product.special %} <span style="text-decoration: line-through;">{{ product.price }}</span><br/>
                      <div class="text-danger">{{ product.special }}</div>
                      {% else %}
                      {{ product.price }}
                      {% endif %}</td>
                    <td class="text-left">
                        {% if product.subtract %}
                        <small class="text-success">Yes</small>
                        {% else %}
                        <small class="text-danger">No</small>
                        {% endif %}
                        {% if product.quantity <= 0 %} <span class="label label-warning">{{ product.quantity }}</span> 
                        {% elseif product.quantity <= 5 %} <span class="label label-danger">{{ product.quantity }}</span> 
                        {% else %} <span class="label label-success">{{ product.quantity }}</span> 
                        {% endif %}
                        
                    </td>
                    <td class="text-left">
					    {{ product.stock_status }}<br/>
					    {% if product.status %}
                          <small class="text-success">{{ text_enabled }}</small>
                        {% else %}
                          <small class="text-danger">{{ text_disabled }}</small>
                        {% endif %}
					</td>
					<td class="text-left">
						{% if product.viewed <= 50 %}
						<span class="text-danger"><font title="{{ help_chart }}" data-toggle="tooltip"><i class="fa fa-line-chart"><i class="fa fa-level-down" style="margin-left: 5px;margin-right: 5px;"></i></i> {{ product.viewed }}</font></span>
						{% elseif product.viewed <= 100 %}
						<span class="text-warning"><font title="{{ help_chart_down }}" data-toggle="tooltip"><i class="fa fa-line-chart"></i> {{ product.viewed }}</font></span>
						{% else %}
						<span class="text-success"><font title="{{ help_chart_up }}" data-toggle="tooltip"><i class="fa fa-line-chart"></i><i class="fa fa-level-up" style="margin-left: 5px;margin-right: 5px;"></i> {{ product.viewed }}</font></span>
						{% endif %}
					</td>
					<td>
                      <button type="button" class="btn btn-info btn-sm view-seo-issues"
                            data-toggle="modal"
                            data-target="#productSeoScorehModal"
                            data-issues='{{ product.product_seo_details|json_encode()|e('html_attr') }}'>
                            {{ product.product_seo_total_score }}/{{ product.product_seo_out_of }}
                        </button>
                    </td>
                    
                    <td>
                      <button type="button" class="btn btn-info btn-sm view-product-strngth-issues"
                            data-toggle="modal"
                            data-target="#productStrengthModal"
                            data-issues='{{ product.product_strength_details|json_encode()|e('html_attr') }}'>
                            {{ product.product_strength_total_score }}/{{ product.product_strength_out_of }}
                        </button>
                    </td>
                    <td class="text-left">
						<i class="fa fa-calendar" data-toggle="tooltip" title="{{ text_date_added }}"></i> {{ product.date_added }} {% if product.added_by %} ({{ product.added_by }}) {% endif %} <br/>
						<i class="fa fa-refresh" data-toggle="tooltip" title="{{ text_date_modified }}"></i> {{ product.date_modified }} {% if product.updated_by %} ({{ product.updated_by }}) {% endif %}
					</td>
                    <td class="text-right">
                        <div style="min-width: 120px;">
                          <div class="btn-group"><a href="{{ product.edit }}" target="_blank" data-toggle="tooltip" title="{{ button_edit }}" class="btn btn-primary"><i class="fa fa-pencil"></i></a>
                            <button type="button" data-toggle="dropdown" class="btn btn-primary dropdown-toggle"><span class="caret"></span></button>
                            <ul class="dropdown-menu dropdown-menu-right">
                              <li><a href="{{ constant('HTTP_CATALOG') }}?route=product/product&product_id={{ product.product_id }}" target="_blank"><i class="fa fa-eye"></i> {{ button_view }}</a></li>
                              <li><a href="{{ product.google_search }}" target="_blank"><i class="fa fa-search"></i> Search Google</a></li>
                              <li><a href="{{ product.google_index_check }}" target="_blank"><i class="fa fa-globe"></i> Check Google Index</a></li>
                            </ul>
                          </div>
                        </div>
                    </td>
                  </tr>
                  {% endfor %}
                  {% else %}
                  <tr>
                    <td class="text-center" colspan="8">{{ text_no_results }}</td>
                  </tr>
                  {% endif %}
                    </tbody>
                  
                </table>
              </div>
            </form>
            <div class="row">
              <div class="col-sm-6 text-left">{{ pagination }}</div>
              <div class="col-sm-6 text-right">{{ results }}</div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
  
  <div class="modal fade" id="productSeoScorehModal" tabindex="-1" role="dialog" aria-labelledby="productSeoScorehModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="productSeoScorehModalLabel">SEO Score</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <table class="table table-bordered table-striped">
          <thead>
            <tr>
              <th>#</th>
              <th>Check</th>
              <th>Score</th>
              <th>Out Of</th>
              <th>Issue</th>
            </tr>
          </thead>
          <tbody id="seo-details-body">
            <!-- JS will populate this -->
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>


  <div class="modal fade" id="productStrengthModal" tabindex="-1" role="dialog" aria-labelledby="productStrengthModalLabel" aria-hidden="true">
  <div class="modal-dialog modal-lg" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="productStrengthModalLabel">Product Strength</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
        <table class="table table-bordered table-striped">
          <thead>
            <tr>
              <th>#</th>
              <th>Check</th>
              <th>Score</th>
              <th>Out Of</th>
              <th>Issue</th>
            </tr>
          </thead>
          <tbody id="product-strength-body">
            <!-- JS will populate this -->
          </tbody>
        </table>
      </div>
    </div>
  </div>
</div>

<script>
document.addEventListener('DOMContentLoaded', function () {
  const buttons = document.querySelectorAll('.view-product-strngth-issues');

  buttons.forEach(button => {
    button.addEventListener('click', function () {
      const data = this.getAttribute('data-issues');
      let details = [];

      try {
        details = JSON.parse(data);
      } catch (e) {
        alert('Failed to parse SEO details.');
        return;
      }

      const tbody = document.getElementById('product-strength-body');
      tbody.innerHTML = '';

      if (details.length === 0) {
        tbody.innerHTML = '<tr><td colspan="5">No details available.</td></tr>';
        return;
      }

      details.forEach((item, index) => {
        const tr = document.createElement('tr');
        tr.innerHTML = `
          <td>${index + 1}</td>
          <td>${item.label}</td>
          <td>${item.earned}</td>
          <td>${item.max}</td>
          <td>${item.note ?? '-'}</td>
        `;
        tbody.appendChild(tr);
      });
    });
  });
});
</script>

<script>
document.addEventListener('DOMContentLoaded', function () {
  const buttons = document.querySelectorAll('.view-seo-issues');

  buttons.forEach(button => {
    button.addEventListener('click', function () {
      const data = this.getAttribute('data-issues');
      let details = [];

      try {
        details = JSON.parse(data);
      } catch (e) {
        alert('Failed to parse SEO details.');
        return;
      }

      const tbody = document.getElementById('seo-details-body');
      tbody.innerHTML = '';

      if (details.length === 0) {
        tbody.innerHTML = '<tr><td colspan="5">No details available.</td></tr>';
        return;
      }

      details.forEach((item, index) => {
        const tr = document.createElement('tr');
        tr.innerHTML = `
          <td>${index + 1}</td>
          <td>${item.title}</td>
          <td>${item.score}</td>
          <td>${item.out_of}</td>
          <td>${item.issue ?? '-'}</td>
        `;
        tbody.appendChild(tr);
      });
    });
  });
});
</script>
  
  <script type="text/javascript"><!--
$('#button-filter').on('click', function() {
	var url = '';
    
    var filter_id = $('input[name=\'filter_id\']').val();

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

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

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

	if (filter_added_by) {
		url += '&filter_added_by=' + encodeURIComponent(filter_added_by);
	}
    
    var filter_stock_status = $('select[name=\'filter_stock_status\']').val();

    if (filter_stock_status != '*') {
        url += '&filter_stock_status=' + encodeURIComponent(filter_stock_status);
    }
    
    var filter_manufacture = $('input[name=\'filter_manufacture\']').val();

	if (filter_manufacture) {
		url += '&filter_manufacture=' + encodeURIComponent(filter_manufacture);
	}

	var filter_model = $('input[name=\'filter_model\']').val();

	if (filter_model) {
		url += '&filter_model=' + encodeURIComponent(filter_model);
	}

	var filter_price = $('input[name=\'filter_price\']').val();

	if (filter_price) {
		url += '&filter_price=' + encodeURIComponent(filter_price);
	}

	var filter_quantity = $('input[name=\'filter_quantity\']').val();

	if (filter_quantity) {
		url += '&filter_quantity=' + encodeURIComponent(filter_quantity);
	}

	var filter_status = $('select[name=\'filter_status\']').val();

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

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

	if (filter_date_added_to) {
		url += '&filter_date_added_to=' + encodeURIComponent(filter_date_added_to);
	}

	location = 'index.php?route=catalog/product&user_token={{ user_token }}' + url;
});
$('#button-clear').on('click', function() {
	 location ='index.php?route=catalog/product&user_token={{ user_token }}';
	});	
//--></script> 
  <script type="text/javascript"><!--
// IE and Edge fix!
$('button[form=\'form-product\']').on('click', function(e) {
	$('#form-product').attr('action', $(this).attr('formaction'));
});
  
$('input[name=\'filter_name\']').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_name\']').val(item['label']);
	}
});

$('input[name=\'path\']').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) {
				json.unshift({
					category_id: '',
					name: '{{ text_none }}'
				});

				response($.map(json, function(item) {
					return {
						label: item['name'],
						value: item['category_id']
					}
				}));
			}
		});
	},
	'select': function(item) {
		$('input[name=\'path\']').val(item['label']);
		$('input[name=\'filter_category_id\']').val(item['value']);
	}
});

$('input[name=\'users\']').autocomplete({
	'source': function(request, response) {
		$.ajax({
			url: 'index.php?route=user/user/autocomplete&user_token={{ user_token }}&filter_name=' +  encodeURIComponent(request),
			dataType: 'json',
			success: function(json) {
				json.unshift({
					user_id: '',
					name: '{{ text_none }}'
				});

				response($.map(json, function(item) {
					return {
						label: item['name'],
						value: item['user_id']
					}
				}));
			}
		});
	},
	'select': function(item) {
		$('input[name=\'users\']').val(item['label']);
		$('input[name=\'filter_added_by\']').val(item['value']);
	}
});

// Manufacturer
$('input[name=\'manufacturer\']').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) {
			  json.unshift({
				  manufacturer_id: '',
				  name: '{{ text_none }}'
			  });

			  response($.map(json, function(item) {
				  return {
					  label: item['name'],
					  value: item['manufacturer_id']
				  }
			  }));
		  }
	  });
  },
  'select': function(item) {
	  $('input[name=\'manufacturer\']').val(item['label']);
	  $('input[name=\'filter_manufacture\']').val(item['value']);
  }
});

$('input[name=\'filter_model\']').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_model\']').val(item['label']);
	}
});
//--></script></div>
{{ footer }} 