<?php

/**
 * Provide a admin area view for the plugin
 *
 * This file is used to markup the admin-facing aspects of the plugin.
 *
 * @link       http://www.exapartners.com/
 * @since      1.0.0
 *
 * @package    Esi_Management
 * @subpackage Esi_Management/admin/partials
 */
global $wpdb;

$item = esi_get_patent( $id );
$patent_list = esi_get_all_patent(array('number' => 1000));
$entity_list = esi_get_all_entity(array('number' => 1000));

add_thickbox();
?>

<div class="wrap">
    <?php if ($_GET['action'] == 'view'): ?>
        <h1><?php _e( 'Update Patent', 'esi' ); ?> : <?= $item->name ?></h1>
    <?php else: ?>
        <h1><?php _e( 'Add Patent', 'esi' ); ?></h1>
    <?php endif; ?>

    <form action="" method="post">

        <table class="form-table">
            <tbody>
            <tr class="row-code">
                <th scope="row">
                    <label for="code"><?php _e( 'Name', 'esi' ); ?></label>
                </th>
                <td>
                    <input type="text" name="code" id="code" class="regular-text" placeholder="<?php echo esc_attr( 'Add patent code', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( $item->code ):''; ?>" required="required" />
                </td>
            </tr>
            <tr class="row-description">
                <th scope="row">
                    <label for="description"><?php _e( 'Description', 'esi' ); ?></label>
                </th>
                <td>
                    <textarea name="description" id="description"placeholder="<?php echo esc_attr( '', 'esi' ); ?>" rows="5" cols="30" required="required"><?php echo ($item)?esc_attr( $item->description ):''; ?></textarea>
                </td>
            </tr>
            <tr class="row-entity-id">
                <th scope="row">
                    <label for="entity_id"><?php _e( 'Entity\'s patent assigned' , 'esi' ); ?></label>
                </th>
                <td>
                    <select id="entity_id" name="entity_id" class="chosen-select">
                        <option value="0">Select a entity</option>
                        <?php foreach ($entity_list as $entity) : ?>
                            <option value="<?= $entity->id ?>" <?= (isset($item) && $item->entity_id == $entity->id)?'selected="selected"':'' ?>><?= $entity->name ?></option>
                        <?php endforeach; ?>
                    </select>
                </td>
            </tr>
            </tbody>
        </table>

        <input type="hidden" name="field_id" value="<?php echo ($item)?$item->id:0; ?>">

        <?php wp_nonce_field( '' ); ?>
        <?php if ($_GET['action'] == 'view'): ?>
            <?php submit_button( __( 'Update patent', 'esi' ), 'primary', 'submit patent' ); ?>
        <?php else: ?>
            <?php submit_button( __( 'Add patent', 'esi' ), 'primary', 'submit patent' ); ?>
        <?php endif; ?>
    </form>
</div>
