[%# This Source Code Form is subject to the terms of the Mozilla Public
  # License, v. 2.0. If a copy of the MPL was not distributed with this
  # file, You can obtain one at http://mozilla.org/MPL/2.0/.
  #
  # This Source Code Form is "Incompatible With Secondary Licenses", as
  # defined by the Mozilla Public License, v. 2.0.
  #%]

[%

PROCESS "global/field-descs.none.tmpl";

_initial = {
  j_top       => default.j_top.0 || "AND",
  conditions  => default.custom_search || [],
};

_fields = [];

FOREACH field = fields;
  _fields.push({ value => field.name, label => field_descs.${field.name} || field.description});
END;

types = [
  "noop",
  "equals", "notequals",
  "anyexact",
  "substring", "casesubstring", "notsubstring",
  "anywordssubstr", "allwordssubstr", "nowordssubstr",
  "regexp", "notregexp",
  "lessthan", "lessthaneq", "greaterthan", "greaterthaneq",
  "anywords", "allwords", "nowords",
  "everchanged", "changedbefore", "changedafter",
  "changedfrom", "changedto",
  "changedby",
  "matches", "notmatches",
  "isempty", "isnotempty",
];
_types = [];

FOREACH type = types;
  _types.push({ value => type, label => search_descs.$type });
END;

# Use single quotes because some strings contain variables to be replaced in the code
_strings = {
  add_group         => 'Add New Group',
  add_row           => 'Add New Row',
  field             => 'Field',
  grab              => 'Drag to Move',
  group             => 'Group',
  group_name        => 'Group { $count }',
  join_options      => 'Join Options',
  match_all         => 'Match All',
  match_all_hint    => 'Match all of the following separately',
  match_all_g       => 'Match All (Same Field)',
  match_all_g_hint  => 'Match all of the following against the same field',
  match_any         => 'Match Any',
  match_any_hint    => 'Match any of the following separately',
  'not'             => 'Not',
  operator          => 'Operator',
  remove            => 'Remove',
  row               => 'Row',
  row_name          => 'Row { $count }',
  value             => 'Value',
};

%]

<div class="bz_section_title" id="custom_search_filter">
  <div id="custom_search_query_controller" class="arrow">&#9660;</div>
  <a id="chart" href="javascript:TUI_toggle_class('custom_search_query')">Custom Search</a>
  <span class="section_help">
    Didn’t find what you’re looking for above? This area allows for ANDs, ORs, and other more complex searches.
  </span>
</div>

<div id="custom-search" class="bz_search_section custom_search_query"
     data-initial="[% json_encode(_initial) FILTER html %]"
     data-fields="[% json_encode(_fields) FILTER html %]"
     data-types="[% json_encode(_types) FILTER html %]"
     data-strings="[% json_encode(_strings) FILTER html %]">
</div>
