<?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";

if(isset($_['embeded']) && $_['embeded'] == 1) $sketchClasses .= ' embeded';
if(isset($_['sidebar']) && $_['sidebar'] == 0) $sketchClasses .= ' no-sidebar';

?>
<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>
			

			<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>
							<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" >

								<div class="dropdown">
									<div onclick="" class="btn btn-success" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"><i class="fas fa-cogs"></i></div>
									<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
									    <div class="dropdown-item pointer" onclick="hackpoint_sketch_share();"><i class="fas fa-share-alt"></i> Partager</div>
									    <div class="dropdown-item pointer" onclick="hackpoint_sketch_download();"><i class="far fa-file-archive"></i> Télécharger</div>
									    <div class="btn btn-delete-sketch dropdown-item" title="Supprimer" onclick="hackpoint_sketch_delete(this);"><i class="far fa-trash-alt"></i> Supprimer</div> 
									</div>
								</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>

<!-- MODALES -->

<!-- Modale partage -->
<div id="share-sketch-modal" class="hide" data-id="">
  <div class="modalize-header">
    <h4 class="text-uppercase font-weight-light"><i class="fas fa-share-alt"></i> Gestion des partages</h4>
  </div>
  <div class="modalize-content">
  	<p>Vous pouvez intégrer ce sketch sur votre site web avec le code ci-dessous.<br/>
  		<span class="font-weight-bold text-warning">nb :</span> Le sketch doit être en visibilité publique
  	pour que les internautes puissent le consulter.</p>

	<label><input type="checkbox" data-type="checkbox" class="share-menu-mode form-control"> n'afficher que la ressource courante  </label> 
   	<textarea class="form-control share-input"></textarea>

   	<div class="hidden shareCode"><a href="{{url}}?module=hackpoint&page=sheet.sketch&id={{sketch}}#resource={{resource}}"><small>Voir en taille réelle</small></a><br/><iframe frameborder="0" width="100%" align="center" height="400px" src="{{url}}?module=hackpoint&page=sheet.sketch&id={{sketch}}&embeded=1&sidebar={{menu}}#resource={{resource}}"></iframe></div>
    
    <div class="modalize-footer">
      <div class="btn btn-dark">Fermer</div>
    </div>
  </div>
</div>
