<?php 
global $myUser;
require_once(__DIR__.SLASH.'Sketch.class.php');
require_once(__DIR__.SLASH.'ResourceType.class.php');
$sketch = Sketch::provide();
if(!$sketch) throw new Exception("Sketch supprimé ou inexistant");
if(!$sketch->state &&  $sketch->creator != $myUser->login) throw new Exception("Sketch privé");

$sketchClasses = $sketch->creator != $myUser->login ? "readonly":"editable";
?>
<div class="hackpoint <?php echo $sketchClasses; ?>">
	
	<div id="sketch-form" class="sketch-form" data-action="hackpoint_sketch_save" data-id="<?php echo $sketch->id; ?>">

		<!-- resources bar -->
		<div id="resources-toolbar">
			<div class="resources-menu-container">
				<ul id="resources" data-entity-search="hackpoint_resource_search">
					<li data-id="{{id}}" class="hidden" onclick="hackpoint_resource_edit(this);">
						<i class="far fa-trash-alt delete-resource" onclick="hackpoint_resource_delete(this,event)" ></i>
						<i class="{{type.icon}}"></i>
						<h3 title="Double cliquer pour modifier" ondblclick="hackpoint_resource_title_edit(event,this);"><span>{{label}}</span><input type="text" value="{{label}}" class="hidden"></h3>
						<small style="background:{{type.background}};color:{{type.color}}">{{type.label}}</small>
					</li>
				</ul>
			</div>
			<!--<a href="index.php?module=hackpoint&page=sheet.resource" class="btn btn-dark btn-add-resource"><i class="fas fa-plus"></i></a>-->

			<div class="btn-group dropright w-100 resource-dropdown">
			  <button type="button" class="btn btn-dark btn-add-resource" title="Ajouter une ressource" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
			    <i class="fas fa-plus"></i>
			  </button>
			  <div class="dropdown-menu">
			  	<?php foreach(ResourceType::types() as $type): ?>
			    <a class="dropdown-item pointer" onclick="hackpoint_resource_save(this)" data-slug="<?php echo $type['uid']; ?>"><i class="<?php echo $type['icon']; ?>"></i> <?php echo $type['label']; ?><br/><small class="text-muted"><?php echo $type['description']; ?></small></a>
				<?php endforeach; ?>
			  </div>
			</div>



		</div>

		<div  id="sketch-workspace">
				<div class="row">
					<div class="col-md-8">
						<h3 class="m-0"><input id="label" name="label" class="form-control-plaintext d-inline-block w-50 pt-0 editable-input" placeholder="Nom du sketch ici" onblur="hackpoint_sketch_save();" value="<?php echo $sketch->label; ?>" type="text"></h3>
					</div>
					<div class="col-md-4">
						<!-- toolbar -->
						<div class="btn-toolbar right" role="toolbar" aria-label="Action">

							<div class="btn-group mr-2" role="group" aria-label="First group">
								<div class="btn text-muted"><span class="sketch-preloader"><i class="far fast-spin fas fa-circle-notch"></i> Sauvegarde...</span></div>
								<div class="btn text-muted btn-delete-sketch" title="Supprimer" onclick="hackpoint_sketch_delete(this);"><i class="far fa-trash-alt"></i></div>
							</div>
							<div class="btn-group mr-2" role="group" aria-label="Properties">
								<label for="state" class="input-group-text pointer m-0">
									<input id="state" name="state" class="form-control editable-input" onclick="hackpoint_sketch_save();" <?php echo $sketch->state?'checked="checked"':''; ?> type="checkbox" data-type="checkbox"> Public
								</label>
							</div>
							<div class="btn-group" role="group" aria-label="Save" onclick="$.message('info','En cours d\'implémentation...')">
								<div onclick="" class="btn btn-success"><i class="fas fa-cogs"></i></div>
							</div>
						</div>
					</div>
				</div>
				<input type="text" id="comment" name="comment" onblur="hackpoint_sketch_save();" class="form-control-plaintext text-muted m-0 input-sm editable-input" value="<?php echo $sketch->comment; ?>">

				<div id="sketch-editor"></div>

		</div>



	</div>
</div>

