<?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_ability( $id );
$ability_list = esi_get_all_ability(array('number' => 1000));

add_thickbox();
?>

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

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

        <table class="form-table">
            <tbody>
            <tr class="row-name">
                <th scope="row">
                    <label for="name"><?php _e( 'Name', 'esi' ); ?></label>
                </th>
                <td>
                    <input type="text" name="name" id="name" class="regular-text" placeholder="<?php echo esc_attr( 'Add ability', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( $item->name ):''; ?>" 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-technology-id">
                <th scope="row">
                    <label for="parent"><?php _e( 'Parent', 'esi' ); ?></label>
                </th>
                <td>
                    <select id="parent" class="chosen-select" name="parent">
                        <?php foreach ($ability_list as $ability) : ?>
                            <option value="<?= $ability->id ?>" <?= ($ability->id == $item->parent) ? "selected='selected'" : ""?>><?= $ability->name ?></option>
                        <?php endforeach; ?>
                    </select><br />
                </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 ability', 'esi' ), 'primary', 'submit ability' ); ?>
        <?php else: ?>
            <?php submit_button( __( 'Add ability', 'esi' ), 'primary', 'submit ability' ); ?>
        <?php endif; ?>
    </form>
</div>
