<!-- Content Header (Page header) -->
<section class="content-header">
	<div class="container-fluid">
		<div class="row mb-2">
			<div class="col-sm-6">
				<h1 class="m-0">User</h1>
			</div>

			<div class="col-sm-6">
				<ol class="breadcrumb float-sm-right">
					<li class="breadcrumb-item"><a href="dashboard">Dashboard</a></li>
					<li class="breadcrumb-item"><a href="user">User</a></li>
					<li class="breadcrumb-item active"><?php if ( count( $user ) > 0 ): ?>Edit<?php else: ?>Add New<?php endif;?> User</li>
				</ol>
			</div>
		</div>
	</div>
</section>

<!-- Main content -->
<section class="content">
	<div class="container-fluid">
		<!-- Small boxes (Stat box) -->
		<div class="row">
			<div class="col-md-12">
				<form id="frmUser" action="user/save" method="post">
					<div class="card card-primary">
						<div class="card-header">
							<h3 class="card-title"><?php if ( count( $user ) > 0 ): ?>Edit<?php else: ?>Add New<?php endif;?> User</h3>
						</div>

						<div class="card-body">
							<div class="row">
								<div class="col-md-6">
									<div class="form-group">
										<label for="name">Full Name</label>
										<input type="text" name="name" id="name" class="form-control" placeholder="Full name" value="<?php if ( count( $user ) > 0 ) {echo $user['name'];}?>">
									</div>
									<div class="form-group">
										<label for="email">Email</label>
										<input type="text" name="email" id="email" class="form-control" value="<?php if ( count( $user ) > 0 ) {echo $user['email'];}?>" autocomplete=off placeholder="Email">
									</div>
									<div class="form-group">
										<label for="password">Password</label>
										<input type="password" name="password" id="password" class="form-control" placeholder="Password"><?php if ( count( $user ) > 0 ) {echo 'Keep blank for unchange.';}?>
									</div>
									<div class="form-group">
										<label for="password_confirmation">Confirm Password</label>
										<input type="password" name="password_confirmation" id="password_confirmation" class="form-control" placeholder="Confirm Password"><?php if ( count( $user ) > 0 ) {echo 'Keep blank for unchange.';}?>
									</div>
								</div>

								<div class="col-md-6">
									<?php if ( $this->session->user_type == 'Admin' ): ?>
										<div class="form-group">
											<label for="company_id">Company</label>
											<select name="company_id" id="company_id" data-placeholder="Select Company" class="form-control select2">
												<option value=""></option>
												<?php foreach ( $companies as $company ): ?>
													<option value="<?php echo $company['id']; ?>"<?php if ( count( $user ) > 0 && $company['id'] == $user['company_id'] ) {echo 'selected';}?>><?php echo $company['name']; ?></option>
												<?php endforeach;?>
											</select>
										</div>
									<?php endif;?>
									<?php if ( $this->session->user_type != 'User' ): ?>
										<div class="form-group">
											<label for="status">User Type</label>
											<select name="type" id="status" class="form-control select2" data-placeholder="Select User Type">
												<option value=""></option>
												<?php if ( $this->session->user_type == 'Admin' ): ?>
													<option value="Admin"<?php if ( count( $user ) > 0 && $user['type'] == 'Admin' ) {echo 'selected';}?>>Admin User</option>
												<?php endif;?>
												<option value="Power User"<?php if ( count( $user ) > 0 && $user['type'] == 'Power User' ) {echo 'selected';}?>>Power User</option>
												<option value="User"<?php if ( count( $user ) > 0 && $user['type'] == 'User' ) {echo 'selected';}?>>User</option>
											</select>
										</div>
									<?php endif;?>
									<div class="form-group">
										<label for="status">Status</label>
										<select name="status" id="status" class="form-control select2" data-placeholder="Select Status">
											<option value=""></option>
											<option value="Active" <?php if ( count( $user ) > 0 && $user['status'] == 'Active' ) {echo 'selected';}?>>Active</option>
											<option value="Inactive" <?php if ( count( $user ) > 0 && $user['status'] == 'Inactive' ) {echo 'selected';}?>>Inactive</option>
										</select>
									</div>
								</div>
							</div>
						</div>

						<input type="hidden" class="form-control" name="<?php echo $this->security->get_csrf_token_name(); ?>" value="<?php echo $this->security->get_csrf_hash(); ?>" />
						<?php if ( count( $user ) > 0 ): ?>
							<input type="hidden" name="id"  value="<?php echo $user['id']; ?>">
						<?php endif;?>

						<div class="card-footer">
							<input type="submit" class="btn bg-gradient-primary" value="Save Changes">
							<input type="reset" class="btn bg-gradient-danger" value="Cancel">
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
</section>