[% BLOCK _conf_object_row %]
[% SET value = "" %]
[% IF obj_conf.defined(key) %]
  [% SET value = obj_conf.$key %]
[% END %]

[% IF !defaults.exists(key) || defaults.$key.type == 'STRING' || defaults.$key.type == 'INT' %]
  [% IF edit %]
    [% has_wizard = 0 %]
    [% wzd_btn = BLOCK %]
      [% IF key == 'command_line' %][% has_wizard = 1 %][% PROCESS _conf_wizard_commandline.tt id="id_" _ key _ "_wzd" _ nr inp="id_" _ key _ nr %][% END %]
      [% IF key == 'address'      %][% has_wizard = 1 %]<button class="ip_wzd_button px-1" id="[% key %]_btn[% nr %]" title="autofill address from hostname ip lookup."><i class="uil uil-lightbulb mr-0"></i></button>[% END %]
    [% END %]
    <div class="flexrow flex-nowrap gap-1">
      <input
        type="text"
        class="obj_[% key %][% IF has_wizard %] wizard[% END %] grow js-attr-value"
        name="obj.[% key %]"
        id="id_[% key %][% nr %]"
        value="[% IF obj_conf.defined(key) %][% value | html %][% END %]"
        [% IF defaults.exists(key) && defaults.$key.exists('link') %]
          onfocus="this.click()"
          onclick="ajax_search.init(this, '[% defaults.$key.link %]', {url:'conf.cgi?action=json&amp;type=[% defaults.$key.link %]', striped:[% IF defaults.$key.link == "icon" %]true[% ELSE %]false[% END %], autosubmit:false})"
        [% ELSIF key == 'customvariable' || key.substr(0, 1) == '_' %]
          onfocus="this.click()"
          onclick="ajax_search.init(this, 'custom value', {url:'status.cgi?format=search&type=custom%20value&var='+this.name.replace(/^obj\._/, ''), striped:false, autosubmit:false})"
        [% END %]
      >
      [% wzd_btn %]
    </div>
  [% ELSE %]
    [% IF defaults.exists(key) && defaults.$key.exists('link') && defaults.$key.link == 'icon' %]
        [% escape_html(value) %] <img class="not-clickable" src="[% logo_path_prefix %][% value | uri %]" width="20" height="20" alt='[% key %]' title='[% key %]' style="vertical-align: middle;">
    [% ELSIF defaults.exists(key) && defaults.$key.exists('link') %]
        <a class="link" href="conf.cgi?sub=objects&amp;type=[% defaults.$key.link %]&amp;data.name=[% value | uri %]">[% value | html %]</a>
    [% ELSE %]
        [% escape_html(value) %]
    [% END %]
  [% END %]


[% ELSIF defaults.$key.type == 'COMMAND' %]
  [% IF obj_conf.defined(key) %]
      [% cmd = value.split('!') %]
  [% ELSE %]
      [% cmd = ['',''] %]
  [% END %]
  [% IF cmd.size == 0 %][% cmd = ['',''] %][% END %]
  [% IF edit %]
    <div class="flexcol gap-px flex-nowrap">
      <div class="flexrow flex-nowrap gap-1">
        <input class="grow" type="text" name="obj.[% key %].1" id="id_[% key %]_1" value="[% cmd.0 | html %]"[% IF defaults.$key.exists('link') %] onfocus="this.click()" onclick="ajax_search.init(this, '[% defaults.$key.link %]', {url:'conf.cgi?action=json&amp;type=[% defaults.$key.link %]', striped:false, autosubmit:false})"[% END %] placeholder="command name">
        [% PROCESS _conf_wizard_command.tt id="id_" _ key _ "_wzd" _ nr inp1="id_" _ key _ "_1" inp2="id_" _ key _ "_2" %]
      </div>
      <input class="w-full" type="text" name="obj.[% key %].2" id="id_[% key %]_2" value="[% blah = cmd.shift; escape_html(cmd.join('!')) %]" placeholder="command arguments">
    </div>
  [% ELSE %]
    [% IF _check_command && _check_command.line; value = _check_command.line; END %]
    [% IF defaults.$key.exists('link') %]
        <a class="link" href="conf.cgi?sub=objects&amp;type=[% defaults.$key.link %]&amp;data.name=[% cmd.0 | uri %]">[% value | html %]</a>
    [% ELSE %]
        [% escape_html(value) %]
    [% END %]
  [% END %]


[% ELSIF defaults.$key.type == 'BOOL' %]
  [% IF edit %]
    <input type="radio" name="obj.[% key %]" id="id_[% key %][% nr %]" value="0"[% IF obj_conf.defined(key) && value == 0 %] checked[% END %]><label class="ml-1 clickable" for="id_[% key %][% nr %]">No</label>
    <input type="radio" name="obj.[% key %]" id="id_[% key %][% nr %]_1" value="1"[% IF obj_conf.defined(key) && value == 1 %] checked[% END %] class="ml-3"><label class="ml-1 clickable" for="id_[% key %][% nr %]_1">Yes</label>
  [% ELSE %]
    [% IF value %]Yes[% ELSE %]No[% END %]
  [% END %]


[% ELSIF defaults.$key.type == 'ENUM' %]
  [% IF edit %]
    <input type="checkbox" name="obj.[% key %]" value="noop" style="display:none" checked>
    [% FOREACH v = defaults.$key.values %]
      [% ind = loop.index %]
      <input type="checkbox" name="obj.[% key %]" [% IF loop.first %]id="id_[% key %][% nr %]"[% ELSE %]id="id_[% key %][% nr %]_[% loop.index %]"[% END %]value="[% v | html %]"[% IF obj_conf.defined(key) && value.grep(v).size() > 0 %] checked[% END %]><label class="ml-1 mr-3 clickable" for="[% IF loop.first %]id_[% key %][% nr %][% ELSE %]id_[% key %][% nr %]_[% loop.index %][% END %]">[% defaults.$key.keys.$ind %]</label>
    [% END %]
  [% ELSE %]
    [% first = 1 %]
    [% FOREACH v = defaults.$key.values %]
      [% ind = loop.index %]
      [% IF value.grep(v).size() > 0 %][% UNLESS first %], [% END %][% defaults.$key.keys.$ind %][% first = 0 %][% END %]
    [% END %]
  [% END %]

[% ELSIF defaults.$key.type == 'CHOOSE' %]
  [% IF edit %]
    [% IF defaults.$key.keys.size > 2 %]
        <select name="obj.[% key %]" id="id_[% key %][% nr %]" class="w-full">
        [% FOREACH k = defaults.$key.keys %]
        [% SET x = loop.index %]
        [% SET v = defaults.$key.values.$x %]
        <option value="[% v | html %]"[% IF obj_conf.defined(key) && value == v %] selected[% END %]> [% k %]</option>
        [% END %]
        </select>
    [% ELSE %]
        [% FOREACH k = defaults.$key.keys %]
        [% SET x = loop.index %]
        [% SET v = defaults.$key.values.$x %]
        <input type="radio" name="obj.[% key %]" id="id_[% key %][% nr %]" value="[% v | html %]"[% IF defaults.$key.keys.size == 1 || obj_conf.defined(key) && value == v %] checked[% END %]> [% k %]
        [% END %]
    [% END %]
  [% ELSE %]
    [% value | html %]
  [% END %]


[% ELSIF defaults.$key.type == 'LIST' %]
  [% IF edit %]
    [% has_wizard = 0 %]
    [% url = 'conf.cgi?action=json&amp;type=' _ defaults.$key.link _ '&amp;ref=' _ object.get_id() %]
    [% wzd_btn = BLOCK %]
      [% IF    type == 'servicegroup' && key == 'members'        %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",servicemembers,2" %]
      [% ELSIF                           key == 'contact_groups' %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",contactgroups,1" %]
      [% ELSIF                           key == 'use'            %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ "," _ type _ ",1,templates" %]
      [% ELSIF type == 'host'    && key == 'parents'             %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",hosts,1" %]
      [% ELSIF type == 'service' && key == 'host_name'           %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",hosts,1" %]
      [% ELSIF type == 'service' && key == 'parents'             %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",service_descriptions,1" %]
      [% ELSIF type == 'service' && key == 'hostgroup_name'      %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",hostgroups,1" %]
      [% ELSIF type == 'service' && key == 'servicegroups'       %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",servicegroups,1" %]
      [% ELSIF type == 'contactgroup' && key == 'members'        %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",contacts,1" %]
      [% ELSIF type == 'hostgroup'    && key == 'members'        %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",hosts,1" %]
      [% ELSIF type == 'hostgroup'    && key == 'hostgroup_members' %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",hostgroups,1" %]
      [% ELSIF key == 'hostgroups'
            || key == 'contacts'
            || key == 'contactgroups'
      %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ "," _ key _ ",1" %]
      [% ELSIF type == 'hostdependency'    && key == 'dependent_host_name' %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",hosts,1" %]
      [% ELSIF type == 'servicedependency' && key == 'dependent_host_name' %][% has_wizard = 1 %][% PROCESS _wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",hosts,1" %]
      [% END %]
    [% END %]
    <div class="flexrow flex-nowrap gap-1">
      <input type="text" class="obj_[% key %] obj_[% type | html %]_[% key %] w-full" name="obj.[% key %]" id="id_[% key %][% nr %]" value="[% IF obj_conf.defined(key) %][% value.join(', ') | html %][% END %]"[% IF defaults.$key.exists('link') %] onfocus="this.click()" onclick="ajax_search.init(this, '[% defaults.$key.link %]', {url:'[% url %]', striped:false, autosubmit:false, list: '\\s*[,!\+]+\\s*'[% IF key == "use" %], templates:'templates'[% END %][% IF has_wizard %],button_links:[{text: 'use list wizard', id:'id_[% key %]_wzd[% nr %]_btn' , icon:'fa-wand-magic-sparkles' }][% END %]})"[% END %]>
      [% IF has_wizard %]
        <button class="px-1" name="[% wzd_args | html %]" onclick="init_tool_list_wizard('[% id %]_btn', this.name); return false;" title="open list editor">
          <i class="uil uil-sliders-v mx-0"></i>
        </button>
      [% END %]
    </div>
    [% wzd_btn %]
  [% ELSE %]
    [% IF defaults.$key.exists('link') %]
        [% FOREACH o = value %]
          [% IF o != "null" %]
            <a href="conf.cgi?sub=objects&amp;type=[% defaults.$key.link %]&amp;data.name=[% o | uri %]">[% o | html %]</a>
          [% ELSE %]
            [% o | html %]
          [% END %]
        [% UNLESS loop.last %], [% END %]
        [% END %]
    [% ELSE %]
        [% value.join(', ') %]
    [% END %]
  [% END %]
[% END %]
[% END %]
