{extends file="views/layout.tpl"}

{block name="content"}
<section class="container mt-4">
   {if isset($smarty.session.user)}
    <form class="m-2" method="POST" enctype="multipart/form-data" onsubmit="return confirm('Êtes-vous certain de vouloir poster votre projet ?')">
        
        <div class="mb-3">
            <label class="form-label">Titre</label>
            <input type="text" name="title" class="form-control {if (isset($arrError['title'])) } is-invalid {/if} " value="{if $objProject}{$objProject->getTitle()}{/if}" required>
        </div>

        <div class="mb-3">
            <label class="form-label">Description (courte)</label>
            <textarea name="description" class="form-control {if (isset($arrError['descProject'])) } is-invalid {/if} " rows="2">{if $objProject}{$objProject->getDescription()}{/if}</textarea>
        </div>

        <div class="mb-3">
            <label class="form-label">Texte complet du Portfolio</label>
            <textarea name="content" class="form-control {if (isset($arrError['content'])) } is-invalid {/if}" rows="5">{if $objProject}{$objProject->getContent()}{/if}</textarea>
        </div>

        <div class="col-6 mb-3">
            <fieldset class="border p-2 rounded">
                <legend class="form-label h6">Catégorie</legend>
                <select class="form-select" id="category" name="category">
				<option value="0" {if $objProject->getCategory() == 0}selected{/if}>Toutes les catégories</option>
				{foreach $arrCategory as $arrDetCategory}
				<option value="{$arrDetCategory['category_id']}" 
					{if $objProject->getCategory() == $arrDetCategory['category_id']}selected{/if}>
					{$arrDetCategory['category_name']}
				</option>
				{/foreach}
				</select>
            </fieldset>
        </div>

        <div class="mb-3">
            <label class="h5">Miniature de votre projet</label>
            <input name="thumbnail" class="form-control" type="file">
			{if $objProject && $objProject->getId()}
				<label class="h5">Miniature actuelle :</label>
				<img src="uploads/projects/{$objProject->getThumbnail()}" alt="Miniature">
			{/if}
        </div>

        <div class="mb-3">
            <label class="h5">Images de votre projet</label>
            <input name="imageProject" class="form-control" type="file" multiple>
        </div>

        <div class="mt-4">
            <button type="submit" class="btn btn-primary btn-md" name="sendProject">Envoyer</button>
        </div>
    </form>
	{else}
		<div class="alert alert-danger mt-5">
			<p class="mb-0">Vous devez vous connecter pour accéder à cette fonctionnalité</p>
		</div>
	{/if}
</section>
{/block}