require 'tk'

def show_game(id)
#puts " id: #{id}"
$console.send_command("review wantto_observe #{id}")
end

class Reviews
 attr_reader :not_opened, :list

 def initialize
    @not_opened= false

 open_win if Defaults.get_default_value('auto_start_Reviews').value == '1'
end

 def open_win
  if @top
      @top.deiconify
    else

  @top= GoWindow.new(self)
   @top.protocol('WM_DELETE_WINDOW', proc { close })

  @top.help_add('command','label'=>'The reviews list','command'=>proc { TkHtml.new("file://#{$current_path}/../help/client.html#reviews") })

  tools= HTexturedPane.new(@top,Defaults::DEFS['CommonBackground'],10,5,4,0).pack('fill'=>'x')
   opts=TkDefaults::GUI['Reviews.button.reload'].update('command'=>proc {  @lock_update= false; $igsClient.send('review games')})
      b_reload = TkButton.new(tools,opts)
      b_reload.pack('side'=> 'left','padx'=>5,'pady'=>3)

  @list= ReviewList.new(@top)

 end	

      Defaults.set_default_value('auto_start_Reviews', '1')
end

 def close
    if @top
      @top.withdraw 
    end
    @not_opened= true
    Defaults.set_default_value('auto_start_Reviews', '0')
  end

  def quit
    @top.destroy if @top
  end


def add(toks)
	return unless @list
	@list.add(toks.join(' '))
end
def refresh
	return unless @list
	@list.refresh 
end
end

class ReviewList

# wrapper class

def initialize( parent)
$ip._eval("
	source #{$current_path}/tcl/reviewlist.tcl
	Rent::create #{parent.path} #{$current_path} #{Defaults::DEFS['IGSList_background'].path}
	")
end

def add(line)
	$ip._eval("Rent::add {#{line}}")
end

def refresh
	$ip._eval("Rent::refresh")
end
end


