<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<div id="kirilkirkov" class="wrap">
    
    <div class="header p-4 flex items-center space-between">
        <div class="flex items-center">
            <img class="logo" src="<?php echo esc_url(plugins_url('../../Assets/Img/logo.svg', __FILE__ )); ?>" alt="<?php echo esc_attr( 'WP Invoices' ) ?>" />
        </div>
        <h1 class="text-white uppercase text-sm font-lighter p-0">
            <?php if(isset($item['id'])) {
                esc_html_e('Edit Item', 'kirilkirkov-pdf-invoice-manager' );
            } else {
                esc_html_e('Add Item', 'kirilkirkov-pdf-invoice-manager' );
            } ?>
        </h1>
    </div>

    <div class="flex flex-wrap">
        <div class="w-full">
            <div class="section-body bg-white p-4">
                
                <?php if($success === true) { ?>
                <div class="alert alert-success w-full md:w-1/4 mx-auto mb-4">
                    <?php if(isset($item['id'])) {  // is update
                        esc_html_e('Item updated', 'kirilkirkov-pdf-invoice-manager' );
                     } else {
                        esc_html_e('Item created', 'kirilkirkov-pdf-invoice-manager' );
                     } ?>
                </div>
                <?php } ?>

                <?php if($success === false) { ?>
                <div class="alert alert-danger w-full md:w-1/4 mx-auto mb-4">
                    <?php esc_html_e('There are errors received', 'kirilkirkov-pdf-invoice-manager' ); ?>
                </div>
                <?php } ?>
                
                <form class="w-full md:w-2/3 mx-auto p-0 md:p-4 rounded-sm" method="post" action="">
                    <?php wp_nonce_field('kkwi_create_item_action', 'kkwi_create_item_nonce'); ?>
                    
                    <!-- Is Edit -->
                    <?php if(isset($item['id'])) { ?>
                        <input type="hidden" name="id" value="<?php echo esc_attr(sanitize_text_field($item['id'])); ?>">
                    <?php } ?>
                    
                    <div class="form-row">  
                        <label><?php esc_html_e('Name', 'kirilkirkov-pdf-invoice-manager' ) ?> *</label>
                        <input type="text" maxlength="255" value="<?php echo isset($item[$Config::INPUTS_PREFIX.'name']) ? esc_attr(sanitize_text_field($item[$Config::INPUTS_PREFIX.'name'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'name'; ?>">
                        <p class="text-error m-0"><?php echo isset($errors[$Config::INPUTS_PREFIX.'name']) ? esc_html(sanitize_text_field($errors[$Config::INPUTS_PREFIX.'name'])) : ''; ?></p>
                    </div>

                    <div class="form-row">  
                        <label><?php esc_html_e('Price', 'kirilkirkov-pdf-invoice-manager' ) ?></label>
                        <input type="text" maxlength="255" value="<?php echo isset($item[$Config::INPUTS_PREFIX.'price']) ? esc_attr(sanitize_text_field($item[$Config::INPUTS_PREFIX.'price'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'price'; ?>">
                    </div>

                    <div class="form-row">  
                        <label><?php esc_html_e('Available Quantity', 'kirilkirkov-pdf-invoice-manager' ) ?></label>
                        <input type="text" value="<?php echo isset($item[$Config::INPUTS_PREFIX.'available_quantity']) ? esc_attr(sanitize_text_field($item[$Config::INPUTS_PREFIX.'available_quantity'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'available_quantity'; ?>">
                        <p class="text-error m-0"><?php echo isset($errors[$Config::INPUTS_PREFIX.'available_quantity']) ? esc_html(sanitize_text_field($errors[$Config::INPUTS_PREFIX.'available_quantity'])) : ''; ?></p>
                    </div>
                    
                    <div class="flex items-center">  
                        <button class="button-primary" type="submit">
                            <?php if(isset($item['id'])) { 
                                esc_html_e('Edit', 'kirilkirkov-pdf-invoice-manager' );
                            } else {
                                esc_html_e('Add', 'kirilkirkov-pdf-invoice-manager' );
                            } ?>
                        </button>
                    </div>  

                </form>
            </div>
        </div>
    </div>
</div>