[% 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 %]
    <input type="text" class="obj_[% key %]" name="obj.[% key %]" id="id_[% key %][% nr %]" value="[% IF obj_conf.defined(key) %][% escape_js(value) %][% END %]" [% IF use_ajax_search && 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:true, autosubmit:false})"[% END %]>
    [% IF key == 'command_line' %][% PROCESS _conf_wizard_commandline.tt id="id_" _ key _ "_wzd" _ nr inp="id_" _ key _ nr %][% END %]
    [% IF key == 'address' %]<button class="conf_button ip_wzd_button" id="[% key %]_btn[% nr %]">&nbsp;</button>[% END %]
  [% ELSE %]
    [% IF defaults.exists(key) && defaults.$key.exists('link') && defaults.$key.link == 'icon' %]
        [% escape_html(value) %] <img class="notclickable" src='[% logo_path_prefix %][% value %]' border="0" width="20" height="20" alt='[% key %]' title='[% key %]' style="vertical-align: middle;">
    [% ELSIF defaults.exists(key) && defaults.$key.exists('link') %]
        <a href="conf.cgi?sub=objects&amp;type=[% defaults.$key.link %]&amp;data.name=[% value | uri %]">[% value %]</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 %]
    <table cellpadding=0 cellspacing=0 border=0 width="100%"><tr>
    <td><input type="text" name="obj.[% key %].1" id="id_[% key %]_1" value="[% cmd.0 %]"[% IF use_ajax_search && 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:true, autosubmit:false})"[% END %]></td>
    <td align="right">&nbsp;&nbsp;args:&nbsp;</td>
    <td>
      <input type="text" name="obj.[% key %].2" id="id_[% key %]_2" value="[% blah = cmd.shift; escape_html(cmd.join('!')) %]">
      [% PROCESS _conf_wizard_command.tt id="id_" _ key _ "_wzd" _ nr inp1="id_" _ key _ "_1" inp2="id_" _ key _ "_2" %]
    </td>
    </tr></table>
  [% ELSE %]
    [% IF defaults.$key.exists('link') %]
        <a href="conf.cgi?sub=objects&amp;type=[% defaults.$key.link %]&amp;data.name=[% cmd.0 | uri %]">[% value %]</a>
    [% ELSE %]
        [% 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 %]> No
    <input type="radio" name="obj.[% key %]" value="1"[% IF obj_conf.defined(key) && value == 1 %] checked[% END %]> Yes
  [% 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 %]"[% END %]value="[% v %]"[% IF obj_conf.defined(key) && value.grep(v).size() > 0 %] checked[% END %]>[% defaults.$key.keys.$ind %]&nbsp;
    [% 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 %]">
        [% FOREACH k = defaults.$key.keys %]
        [% SET x = loop.index %]
        [% SET v = defaults.$key.values.$x %]
        <option value="[% v %]"[% 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 %]"[% IF defaults.$key.keys.size == 1 || obj_conf.defined(key) && value == v %] checked[% END %]> [% k %]
        [% END %]
    [% END %]
  [% ELSE %]
    [% value %]
  [% END %]


[% ELSIF defaults.$key.type == 'LIST' %]
  [% IF edit %]
    <input type="text" class="obj_[% key %] obj_[% type %]_[% key %]" name="obj.[% key %]" id="id_[% key %][% nr %]" value="[% IF obj_conf.defined(key) %][% value.join(', ') %][% END %]"[% IF use_ajax_search && 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:true, autosubmit:false, list:'[ ,!\+]'[% IF key == "use" %], templates:'templates'[% END %]})"[% END %]>
    [% IF type == 'servicegroup' && key == 'members'    %][% PROCESS _conf_wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",servicemembers,2" %][% END %]
    [% IF type == 'host'         && key == 'hostgroups' %][% PROCESS _conf_wizard_list.tt id="id_" _ key _ "_wzd" _ nr wzd_args="id_" _ key _ nr _ ",hostgroups,1" %][% END %]
  [% ELSE %]
    [% IF defaults.$key.exists('link') %]
        [% FOREACH o = value %]
        <a href="conf.cgi?sub=objects&amp;type=[% defaults.$key.link %]&amp;data.name=[% o | uri %]">[% o %]</a>
        [% UNLESS loop.last %], [% END %]
        [% END %]
    [% ELSE %]
        [% value.join(', ') %]
    [% END %]
  [% END %]
[% END %]
