<?php

$api_key = get_option('swiftype_api_key');
$engine_slug = get_option('swiftype_engine_slug');
$engine_name = get_option('swiftype_engine_name');
$num_indexed_documents = get_option('swiftype_num_indexed_documents');
$client = new SwiftypeClient();
$client->set_api_key($api_key);
?>

<div class="wrap">

  <h2 class="swiftype-header">Swiftype Search Plugin</h2>

  <p><b>To administer your Swiftype Search Engine, visit the <a href="http://swiftype.com/users/sign_in" target="_new">Swiftype Dashboard</a></b>.</p>

  <table class="widefat" style="width: 650px;">
    <thead>
      <tr>
        <th class="row-title" colspan="2">Swiftype Search Plugin Settings</th>
      </tr>
    </thead>
    <tbody>
      <tr>
        <td>API Key:</td>
        <td><?php 
print $api_key;
?>
</td>
      </tr>
      <tr>
<?php

$api_key = get_option('swiftype_api_key');
$client = new SwiftypeClient();
$client->set_api_key($api_key);
$engines = $client->get_engines();
?>

<div class="wrap">
  <h2 class="swiftype-header">Swiftype Search Plugin</h2><br/>

  <form name="swiftype_settings" method="post" action="<?php 
echo str_replace('%7E', '~', $_SERVER['REQUEST_URI']);
?>
">
    <input type="hidden" name="action" value="set_engine">

<?php 
if (count($engines) > 0) {
    ?>

    <table class="widefat" style="width: 650px;">
      <thead>
        <tr>
          <th class="row-title">Configure your Search Engine</th>
        </tr>
      </thead>
      <tbody>
        <tr>
          <td>
            It looks like you have already created an engine in your Swiftype account. If you would like to use one of those existing engines as the