<?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_entity( $id );
$countries = esi_get_all_countries();
$entity_types = esi_get_all_entity_type_id();

add_thickbox();
?>

<div class="wrap">
    <h1><?php _e( 'Add entity', 'esi' ); ?></h1>

    <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 entity name', '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-country">
                    <th scope="row">
                        <label for="entity_type_id"><?php _e( 'Entity Type', 'esi' ); ?></label>
                    </th>
                    <td>
                        <select id="entity_type_id" name="entity_type_id">
                            <option value="0">Select an Entity Type</option>
                            <?php foreach ($entity_types as $entity_type) : ?>
                                <option value="<?= $entity_type->id ?>" <?= ($entity_type->id == $item->entity_type_id)?'selected="selected"':'' ?>><?= $entity_type->name ?></option>
                            <?php endforeach; ?>
                        </select>
                    </td>
                </tr>
                <tr class="row-url">
                    <th scope="row">
                        <label for="url"><?php _e( 'URL', 'esi' ); ?></label>
                    </th>
                    <td>
                        <input type="text" name="url" id="url" class="regular-text" placeholder="<?php echo esc_attr( 'Add entity URL', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( $item->url ):''; ?>" required="required" />
                    </td>
                </tr>
                <tr class="row-country">
                    <th scope="row">
                        <label for="country"><?php _e( 'Country', 'esi' ); ?></label>
                    </th>
                    <td>
                        <select id="country" name="country">
                            <option value="0">Select a country</option>
                            <?php foreach ($countries as $country) : ?>
                                <option value="<?= $country->country_code ?>" <?= ($country->country_code == $item->country)?'selected="selected"':'' ?>><?= $country->country_name ?></option>
                            <?php endforeach; ?>
                        </select>
                    </td>
                </tr>
                <tr class="row-city">
                    <th scope="row">
                        <label for="url"><?php _e( 'City', 'esi' ); ?></label>
                    </th>
                    <td>
                        <input type="text" name="city" id="city" class="regular-text" placeholder="<?php echo esc_attr( 'Add city', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( $item->city ):''; ?>" required="required" />
                    </td>
                </tr>
                <tr class="row-is-investor">
                    <th scope="row">
                        <?php _e( 'Is Investor', 'esi' ); ?>
                    </th>
                    <td>
                        <label for="is_investor"><input type="checkbox" name="is_investor" id="is_investor" value="on" <?php ($item)?checked( $item->is_investor, '1' ):''; ?> /> <?php _e( '', 'esi' ); ?></label>
                    </td>
                </tr>
                <tr class="row-founded-date">
                    <th scope="row">
                        <label for="founded-date"><?php _e( 'Founded In', 'esi' ); ?></label>
                    </th>
                    <td>
                        <input type="date" name="founded-date" id="founded-date" class="regular-text" placeholder="<?php echo esc_attr( '', 'esi' ); ?>" value="<?php echo ($item)?esc_attr($item->founded_in):''; ?>" />
                    </td>
                </tr>
                <tr class="row-employees">
                    <th scope="row">
                        <label for="employees"><?php _e( 'Number of Employees', 'esi' ); ?></label>
                    </th>
                    <td>
                        <input type="text" name="employees" id="employees" class="regular-text" placeholder="<?php echo esc_attr( 'Enter number employees', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( $item->employees ):''; ?>" />
                    </td>
                </tr>
                <tr class="row-acquired-by">
                    <th scope="row">
                        <label for="acquired-by"><?php _e( 'Acquired by', 'esi' ); ?></label>
                    </th>
                    <td>
                        <select id="acquired" name="acquired">
                            <option value="0">Select an entity</option>
                        </select>
                    </td>
                </tr>
                <tr class="row-acquired-date">
                    <th scope="row">
                        <label for="acquired-date"><?php _e( 'Acquired Date', 'esi' ); ?></label>
                    </th>
                    <td>
                        <input type="date" name="acquired-date" id="acquired-date" class="regular-text" placeholder="<?php echo esc_attr( '', 'esi' ); ?>" value="<?php echo ($item)?esc_attr($item->acquired_at):''; ?>" />
                    </td>
                </tr>
                <tr class="row-acquired-amount">
                    <th scope="row">
                        <label for="acquired-amount"><?php _e( 'Acquired Amount', 'esi' ); ?></label>
                    </th>
                    <td>
                        <input type="text" name="acquired-amount" id="acquired-amount" class="regular-text" placeholder="<?php echo esc_attr( 'Acquired Amount', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( $item->acquired_amount ):''; ?>" />
                    </td>
                </tr>
                <tr class="row-total-raised">
                    <th scope="row">
                        <label for="total-raised"><?php _e( 'Total Raised', 'esi' ); ?></label>
                    </th>
                    <td>
                        <input type="text" name="total-raised" id="total-raised" class="regular-text" placeholder="<?php echo esc_attr( 'Total Raised', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( $item->total_raised ):''; ?>" />
                    </td>
                </tr>
                <tr class="row-latest-round-type">
                    <th scope="row">
                        <label for="latest-round-type"><?php _e( 'Latest Round Type', 'esi' ); ?></label>
                    </th>
                    <td>
                        <input type="text" name="latest-round-type" id="latest-round-type" class="regular-text" placeholder="<?php echo esc_attr( 'Latest Round Type', 'esi' ); ?>" value="<?php echo ($item)?esc_attr( $item->latest_round_type ):''; ?>" />
                    </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 entity', 'esi' ), 'primary', 'submit entity' ); ?>
        <?php else: ?>
            <?php submit_button( __( 'Add entity', 'esi' ), 'primary', 'submit entity' ); ?>
        <?php endif; ?>
    </form>
</div>
