<!--Add new company  -->

<div class="row">
	<div class="col s12">
<div class="widget-holder hoverable fadeIn" id="dashboard-add-company">
	<div class="widget-heading">
		<h2 class="widget-heading-thick"><?php echo isset($title) ? $title : null; ?></h2>
	</div>
	<div class="widget-content">
		<?php echo Form::open(array('route' => $postRoute, 'role' => 'form', 'class' => 'form-horizontal', 'autocomplete' => 'off')); ?>

		<?php if($mode == 'edit'): ?>

			<?php echo Form::hidden('city_id',$cities[Session::get("city_id")],array('id'=>'city_id')); ?>

			<?php echo Form::hidden('id', $company->id, array('id' => 'id')); ?>

		<?php endif; ?>
		<div class="row">
			<div class="col l12 m12 s12">
				<div class="inputs-wrapper">
					<div class="row">
						<div class="input-field col s12 m6">
							<?php echo Form::text('company_name', isset($company->name) ? $company->name : null, array('id' => 'company_name')); ?>

							<?php if(isset($errors) && ($errors->first('company_name') != '' || $errors->first('company_name') != null)): ?>
								<p><small class="error"><?php echo $errors->first('company_name'); ?></small></p>
							<?php endif; ?>

							<label for="company_name"><?php echo Lang::get('company.label_company_name'); ?>*</label>
						</div>

						<div class="input-field col s12 m6">
							<?php echo Form::text('company_email', isset($company->email) ? $company->email : null, array('id' => 'company_email')); ?>

							<?php if(isset($errors) && ($errors->first('company_email') != '' || $errors->first('company_email') != null)): ?>
								<p><small class="error"><?php echo $errors->first('company_email'); ?></small></p>
							<?php endif; ?>

							<label for="company_email"><?php echo Lang::get('company.label_company_email'); ?>*</label>
						</div>

						<div class="input-field col s12 m6">
							<?php echo Form::text('company_phone_number', isset($company->phone) ? $company->phone : null, array('id' => 'company_phone_number')); ?>

							<?php if(isset($errors) && ($errors->first('company_phone_number') != '' || $errors->first('company_phone_number') != null)): ?>
								<p><small class="error"><?php echo $errors->first('company_phone_number'); ?></small></p>
							<?php endif; ?>

							<label for="company_phone_number"><?php echo Lang::get('company.label_company_phone_number'); ?></label>
						</div>

						<div class="input-field col s12 m6">
							<?php echo Form::text('company_address', isset($company->address) ? $company->address : null, array('id' => 'company_address')); ?>

							<?php if(isset($errors) && ($errors->first('company_address') != '' || $errors->first('company_address') != null)): ?>
								<p><small class="error"><?php echo $errors->first('company_address'); ?></small></p>
							<?php endif; ?>

							<label for="company_address"><?php echo Lang::get('company.label_company_address'); ?></label>
						</div>

						<div class="input-field col s12 m6">

							<?php if(Entrust::hasRole('superadmin')): ?>
								<?php echo Form::text('city_id', null, array('id' => 'add-city', 'class'=>'autocomplete')); ?>

								<?php if(isset($errors) && ($errors->first('city_id') != '' || $errors->first('city_id') != null)): ?>
									<p><small class="error"><?php echo $errors->first('city_id'); ?></small></p>
								<?php endif; ?>
							<?php else: ?>
								<?php echo Form::text('city',   $cities[Session::get("city_id")], array('id' => 'add-city', 'disabled'=>'disabled')); ?>

								<?php echo Form::hidden('city_id',  $cities[Session::get("city_id")]); ?>


							<?php endif; ?>
							<label for="add-city"><?php echo Lang::get('company.label_cityname'); ?></label>


						</div>

					</div>
				</div>

				<div class="inputs-wrapper">
					<div class="row">
						<div class="input-field col s12 m6">
							<?php echo Form::text('fb_page_id', isset($company->fb_page_id) ? $company->fb_page_id : null, array('id' => 'fb-page-id', 'onkeyup' => 'checkIfFbPageExists()')); ?>


							<a href="#fb-info-modal" id="add-manager-button"><i class="material-icons">info_outline</i></a>

							<div class="fb-loader" style="display: none; position: absolute; right: 25px; top: 5px;"><i class="fa fa-spinner fa-spin"></i></div>
							<?php if(isset($errors) && ($errors->first('fb_page_id') != '' || $errors->first('fb_page_id') != null)): ?>
								<p><small><?php echo $errors->first('fb_page_id'); ?></small></p>
							<?php endif; ?>
							<label for="fb-page-id"><?php echo Lang::get('company.fb_page_id'); ?></label>
						</div>



						<div class="input-field col s12 m6">
							<?php echo Form::textarea('company_description', isset($company->description) ? $company->description : null, array('id' => 'company_description', 'class'=>'materialize-textarea')); ?>

							<?php if(isset($errors) && ($errors->first('company_description') != '' || $errors->first('company_description') != null)): ?>
								<p><small class="error"><?php echo $errors->first('company_description'); ?></small></p>
							<?php endif; ?>
							<label for="company_description"><?php echo Lang::get('company.label_company_description'); ?></label>


						</div>


					</div>
					<div class="row">
						<div class="input-field col s12 m6">
							<ul class="collapsible" data-collapsible="accordion">
								<li>
									<div class="collapsible-header <?php echo (Session::get('cas') OR (isset($cityAdmins) AND count($cityAdmins)>0))?'active':''; ?>"><label><?php echo Lang::get('city.label_city_admin'); ?></label></div>
									<div class="collapsible-body">
										<?php if(Session::get('cas')): ?>
											<?php echo Form::select('cityAdmins[]', Session::pull('cas'),  null, array('id' => 'city-admins', 'multiple')); ?>

										<?php elseif(isset($cityAdmins)): ?>

											<?php echo Form::select('cityAdmins[]', $admins,  $cityAdmins, array('id' => 'city-admins', 'multiple')); ?>

										<?php else: ?>
											<?php echo Form::select('cityAdmins[]', (Session::get('cas'))?Session::pull('cas'):[],  null, array('id' => 'city-admins', 'multiple')); ?>


										<?php endif; ?>
									</div>
								</li>

							</ul>

							<?php if(isset($errors) && ($errors->first('cityAdmins') != '' || $errors->first('cityAdmins') != null)): ?>
								<p><small class="error"><?php echo $errors->first('cityAdmins'); ?></small></p>
							<?php endif; ?>

							<?php /*autoselect for adding existing admins to the city, event listener is in newUser.js*/ ?>
							<div class="input-field col s12">
								<?php echo Form::text('addAdmin',  null, array('id' => 'add-admin', 'class'=>'autocomplete')); ?>

								<label for="add-admin"><?php echo ucfirst(Lang::get('city.add_existing_user')); ?></label>

							</div>

							<?php if(Entrust::hasRole('superadmin') OR Entrust::hasRole('admin')): ?>
							<a class="btn-floating waves-effect waves-light btn-primary new-manager-btn modal-trigger" href="#add-company-manager-modal" id="add-manager-button"><i class="material-icons">add</i></a>
							<?php endif; ?>

							<div id="add-company-manager-modal" class="modal modal-fixed-footer add-user-progressbar">
								<div class="modal-content">
									<h4><?php echo Lang::get('user.title_add_user'); ?></h4>
									<div class="inputs-wrapper">
										<div class="row">
											<div class="input-field col l6 m12 s12">
												<?php echo Form::text('email',  null, array('id' => 'email')); ?>

												<small class="error" id="error_email"></small>

												<label for="email"><?php echo Lang::get('user.label_email'); ?>*</label>
											</div>

											<div class="input-field col l6 m12 s12">
												<?php echo Form::password('password', array('id' => 'password', "autocomplete"=>"new-password")); ?>

												<small class="error" id="error_password"></small>

												<label for="password"><?php echo Lang::get('user.label_password'); ?>*</label>
											</div>
										</div>


										<div class="row">
											<div class="input-field col l6 m12 s12">


												<?php echo Form::text('first_name',  null, array('id' => 'first_name')); ?>

												<small class="error" id="error_first_name"></small>

												<label for="first_name"><?php echo Lang::get('user.label_first_name'); ?>*</label>
											</div>

											<div class="input-field col l6 m12 s12">
												<?php echo Form::text('last_name',  null, array('id' => 'last_name')); ?>

												<small class="error" id="error_last_name"></small>

												<label for="last_name"><?php echo Lang::get('user.label_last_name'); ?>*</label>
											</div>
										</div>
									</div>
									<div class="inputs-wrapper">

										<div class="row">

											<div class="input-field col l6 m12 s12">
												<?php echo Form::select('languageUser', $languages,  null, array('id' => 'language')); ?>


												<label for="language"><?php echo Lang::get('user.label_language'); ?></label>
											</div>
										</div>
									</div>

									<div class="input-field col s3">
										<?php echo Form::select('role', $roles, isset($user->role_id) ? $user->role_id : null, array('id' => 'role', 'class' => 'form-control')); ?>

										<?php if(isset($errors) && ($errors->first('role') != '' || $errors->first('role') != null)): ?>
											<p><small class="error"><?php echo $errors->first('role'); ?></small></p>
										<?php endif; ?>
										<label><?php echo Lang::get('user.label_role'); ?></label>
									</div>
								</div>
								<div class="modal-footer right-align">
									<a class="modal-action modal-close waves-effect waves-light btn-flat modal-cancel"><?php echo Lang::get('core.cancel'); ?></a>
									<a onclick="postNewUser()"
									   class="modal-action waves-effect waves-light btn-flat modal-save"><?php echo Lang::get('core.save'); ?></a>

								</div>
								<div id="preloader-bar" class="animated fadeIn progress">
									<div class="indeterminate"></div>
								</div>
							</div>

							<div id="fb-info-modal" class="modal">
								<div class="modal-content">
									<h4>Upute</h4>
									<?php echo HTML::image('img/modules/cityNews/step1.jpg'); ?>

									<?php echo HTML::image('img/modules/cityNews/step2.jpg'); ?>

									<?php echo HTML::image('img/modules/cityNews/step3.jpg'); ?>

								</div>
								<div class="modal-footer right-align">
									<a href="#!" class="modal-action modal-close waves-effect waves-light btn-flat modal-cancel"><?php echo Lang::get('core.close'); ?></a>

								</div>
							</div>

						</div>
					</div>
				</div>
			</div>
		</div>
		<div class="row center-align">
			<div class="col s12">

				<span id="cancel_button" new_users="">
                            <a href="<?php echo URL::route('getCompaniesList'); ?>" class="waves-effect waves-light btn btn-cancel"><span class="icon icon-block"></span> <?php echo Lang::get('core.cancel'); ?></a>
						</span>
				<?php echo Form::button('<span class="icon icon-done"></span> ' . Lang::get('core.save'), array('type' => 'submit', 'class' => 'waves-effect waves-light btn btn-primary')); ?>



			</div>
		</div>
		<?php echo Form::close(); ?>


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

<style>
.fb-error-border {
	border-color: red!important;
}
.fb-success-border {
	border-color: green!important;
}

#fb-helper {
	position: absolute;
	right: -5px;
	top: 7px;
}
</style>
<script type="application/javascript", charset="utf-8">
    var allCities=JSON.parse('<?php echo $allCities; ?>');

    console.log(allCities);
    var back_url ="https://"+window.location.host+"/companies";
    var lang_loading = '<?php echo Lang::get('core.loading'); ?>';
    var lang_no_managers = '<?php echo Lang::get('core.loading'); ?>';
    var lang_loading_error = '<?php echo Lang::get('company.error_loading_managers'); ?>';
    var lang_loading_fail = '<?php echo Lang::get('company.error_loading_managers_fail'); ?>';
    var cancel_label= '<?php echo Lang::get('core.cancel'); ?>';
    // for newUser.js
    var lang_create_user_fail ='<?php echo Lang::get('messages.error_creating_new_user'); ?>';
    var view='company';



</script>
