<?php
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}
?>
<div id="kirilkirkov" class="wrap">
    <div class="create-client-page">
        <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($client['id'])) {
                    esc_html_e('Edit Client', 'kirilkirkov-pdf-invoice-manager' );
                } else {
                    esc_html_e('Create Client', '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($client['id'])) {  // is update
                            esc_html_e('Client updated', 'kirilkirkov-pdf-invoice-manager' );
                        } else {
                            esc_html_e('Client 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_client_action', 'kkwi_create_client_nonce'); ?>

                        <!-- Is Edit -->
                        <?php if(isset($client['id'])) { ?>
                            <input type="hidden" name="id" value="<?php echo esc_attr(sanitize_text_field($client['id'])); ?>">
                        <?php } ?>
                        
                        <div class="form-row">  
                            <label><?php esc_html_e('Client', 'kirilkirkov-pdf-invoice-manager' ) ?> *</label>
                            <input type="text" maxlength="255" value="<?php echo isset($client[$Config::INPUTS_PREFIX.'client']) ? esc_attr(sanitize_text_field($client[$Config::INPUTS_PREFIX.'client'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'client'; ?>">
                            <p class="text-error m-0"><?php echo isset($errors[$Config::INPUTS_PREFIX.'client']) ? esc_html(sanitize_text_field($errors[$Config::INPUTS_PREFIX.'client'])) : ''; ?></p>
                        </div>

                        <div class="form-row">
                            <label>
                                <input type="hidden" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'is_individual'; ?>" value="0">
                                <input type="checkbox" <?php echo isset($client[$Config::INPUTS_PREFIX.'is_individual']) && (int)$client[$Config::INPUTS_PREFIX.'is_individual'] > 0 ? 'checked' : ''; ?> name="<?php echo esc_attr($Config::INPUTS_PREFIX).'is_individual'; ?>" class="is-individual" value="1">
                                <?php esc_html_e( 'Individual', 'kirilkirkov-pdf-invoice-manager' ); ?>
                            </label>
                        </div>

                        <div class="form-row <?php echo isset($client[$Config::INPUTS_PREFIX.'is_individual']) && (int)$client[$Config::INPUTS_PREFIX.'is_individual'] > 0 ? '' : 'hidden'; ?> only-individual">  
                            <label><?php esc_html_e('Identification Number', 'kirilkirkov-pdf-invoice-manager' ) ?> *</label>
                            <input type="text" maxlength="255" value="<?php echo isset($client[$Config::INPUTS_PREFIX.'identification_number']) ? esc_attr(sanitize_text_field($client[$Config::INPUTS_PREFIX.'identification_number'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'identification_number'; ?>">
                            <p class="text-error m-0"><?php echo isset($errors[$Config::INPUTS_PREFIX.'identification_number']) ? esc_html(sanitize_text_field($errors[$Config::INPUTS_PREFIX.'identification_number'])) : ''; ?></p>
                        </div>

                        <div class="form-row <?php echo isset($client[$Config::INPUTS_PREFIX.'is_individual']) && (int)$client[$Config::INPUTS_PREFIX.'is_individual'] > 0 ? 'hidden' : ''; ?> not-individual">
                            <label>
                                <input type="hidden" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'has_vat_registration'; ?>" value="0">
                                <input type="checkbox" <?php echo isset($client[$Config::INPUTS_PREFIX.'has_vat_registration']) && (int)$client[$Config::INPUTS_PREFIX.'has_vat_registration'] > 0 ? 'checked' : ''; ?> name="<?php echo esc_attr($Config::INPUTS_PREFIX).'has_vat_registration'; ?>" class="vat-registration" value="1">
                                <?php esc_html_e( 'VAT registration', 'kirilkirkov-pdf-invoice-manager' ); ?>
                            </label>
                        </div>

                        <div class="form-row <?php echo isset($client[$Config::INPUTS_PREFIX.'has_vat_registration']) && (int)$client[$Config::INPUTS_PREFIX.'has_vat_registration'] > 0 && (!isset($client[$Config::INPUTS_PREFIX.'is_individual']) || (int)$client[$Config::INPUTS_PREFIX.'is_individual'] < 1) ? '' : 'hidden'; ?> has-vat-number">  
                            <label><?php esc_html_e('Vat number', 'kirilkirkov-pdf-invoice-manager' ) ?></label>
                            <input type="text" maxlength="255" value="<?php echo isset($client[$Config::INPUTS_PREFIX.'vat_number']) ? esc_attr(sanitize_text_field($client[$Config::INPUTS_PREFIX.'vat_number'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'vat_number'; ?>">
                        </div>

                        <div class="form-row <?php echo isset($client[$Config::INPUTS_PREFIX.'is_individual']) && (int)$client[$Config::INPUTS_PREFIX.'is_individual'] > 0 ? 'hidden' : ''; ?> not-individual">  
                            <label><?php esc_html_e('Accountable person', 'kirilkirkov-pdf-invoice-manager' ) ?></label>
                            <input type="text" maxlength="255" value="<?php echo isset($client[$Config::INPUTS_PREFIX.'accountable_person']) ? esc_attr(sanitize_text_field($client[$Config::INPUTS_PREFIX.'accountable_person'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'accountable_person'; ?>">
                            <p class="text-error m-0"><?php echo isset($errors[$Config::INPUTS_PREFIX.'accountable_person']) ? esc_html(sanitize_text_field($errors[$Config::INPUTS_PREFIX.'accountable_person'])) : ''; ?></p>
                        </div>

                        <div class="form-row">  
                            <label><?php esc_html_e('City', 'kirilkirkov-pdf-invoice-manager' ) ?></label>
                            <input type="text" maxlength="255" value="<?php echo isset($client[$Config::INPUTS_PREFIX.'city']) ? esc_attr(sanitize_text_field($client[$Config::INPUTS_PREFIX.'city'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'city'; ?>">
                            <p class="text-error m-0"><?php echo isset($errors[$Config::INPUTS_PREFIX.'city']) ? esc_html(sanitize_text_field($errors[$Config::INPUTS_PREFIX.'city'])) : ''; ?></p>
                        </div>

                        <div class="form-row">  
                            <label><?php esc_html_e('Address', 'kirilkirkov-pdf-invoice-manager' ) ?></label>
                            <input type="text" maxlength="255" value="<?php echo isset($client[$Config::INPUTS_PREFIX.'address']) ? esc_attr(sanitize_text_field($client[$Config::INPUTS_PREFIX.'address'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'address'; ?>">
                            <p class="text-error m-0"><?php echo isset($errors[$Config::INPUTS_PREFIX.'address']) ? esc_html(sanitize_text_field($errors[$Config::INPUTS_PREFIX.'address'])) : ''; ?></p>
                        </div>

                        <div class="form-row">  
                            <label><?php esc_html_e('Country', 'kirilkirkov-pdf-invoice-manager' ) ?></label>
                            <input type="text" maxlength="255" value="<?php echo isset($client[$Config::INPUTS_PREFIX.'country']) ? esc_attr(sanitize_text_field($client[$Config::INPUTS_PREFIX.'country'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'country'; ?>">
                            <p class="text-error m-0"><?php echo isset($errors[$Config::INPUTS_PREFIX.'country']) ? esc_html(sanitize_text_field($errors[$Config::INPUTS_PREFIX.'country'])) : ''; ?></p>
                        </div>

                        <div class="form-row">  
                            <label><?php esc_html_e('Beneficiary', 'kirilkirkov-pdf-invoice-manager' ) ?></label>
                            <input type="text" maxlength="255" value="<?php echo isset($client[$Config::INPUTS_PREFIX.'beneficiary']) ? esc_attr(sanitize_text_field($client[$Config::INPUTS_PREFIX.'beneficiary'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'beneficiary'; ?>">
                            <p class="text-error m-0"><?php echo isset($errors[$Config::INPUTS_PREFIX.'beneficiary']) ? esc_html(sanitize_text_field($errors[$Config::INPUTS_PREFIX.'beneficiary'])) : ''; ?></p>
                        </div>

                        <div class="form-row">  
                            <label><?php esc_html_e('Zip Code', 'kirilkirkov-pdf-invoice-manager' ) ?></label>
                            <input type="text" maxlength="200" value="<?php echo isset($client[$Config::INPUTS_PREFIX.'zip_code']) ? esc_attr(sanitize_text_field($client[$Config::INPUTS_PREFIX.'zip_code'])) : ''; ?>" name="<?php echo esc_attr($Config::INPUTS_PREFIX).'zip_code'; ?>">
                            <p class="text-error m-0"><?php echo isset($errors[$Config::INPUTS_PREFIX.'zip_code']) ? esc_html(sanitize_text_field($errors[$Config::INPUTS_PREFIX.'zip_code'])) : ''; ?></p>
                        </div>
                        
                        <div class="flex items-center">  
                            <button class="button-primary" type="submit">
                                <?php if(isset($client['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>
</div>