{% extends 'layout.twig' %}

{% block body %}
	{% if error is defined %}
		<div class="alert alert-danger" role="alert">
  			{{error|nl2br}}
		</div>
	{% endif %}


	<div class="row justify-content-left">
		<div class="col-6">
            {% if ad is defined %}
			<form action="/ads/update/{{ad.id}}" enctype="multipart/form-data" method="post">
            {% else %}
            <form action="/ads/create" enctype="multipart/form-data" method="post">
            {% endif %}
				<div class="form-group">
					<label for="exampleFormControlTextarea1">Titre</label>

					<textarea class="form-control" id="exampleFormControlTextarea1" rows="1" name="titre" style="text-align:left!important;">{% if ad is defined %}{{ad.titre}}{% endif %}</textarea>

				</div>


				<div class="form-group">
					<label for="exampleFormControlTextarea2">Description</label>
					<textarea class="form-control" id="exampleFormControlTextarea2" name="description" rows="3" style="text-align:left!important;">{% if ad is defined %}{{ad.description}}{% endif %}</textarea>
				</div>


				<div class="form-group">
					<label for="exampleFormControlSelect1">Type :
					</label>
					<select class="form-control" id="exampleFormControlSelect1" name="type">
						{% if ad is defined %}
							<option {% if ad.type=="Vente" %} selected {% endif %}>Vente</option>
							<option {% if ad.type=="Location" %} selected {% endif %}>Location</option>
						{% else %}
							<option>Vente</option>
							<option>Location</option>
						{% endif %}
					</select>
				</div>

				<div class="form-group">
					<label for="exampleFormControlSelect2">Statut de publication :</label>
					<select class="form-control" id="exampleFormControlSelect2" name="statusPub">
						{% if ad is defined %}
							<option {% if ad.statusPublication=="publiée" %} selected {% endif %}>publiée</option>
							<option {% if ad.statusPublication=="non publiée" %} selected {% endif %}>non publiée</option>
						{% else %}
							<option>publiée</option>
							<option>non publiée</option>
						{% endif %}
					</select>
				</div>

				<div class="form-group">
					<label for="exampleFormControlSelect3">Statut du bien :</label>
					<select class="form-control" id="exampleFormControlSelect2" name="statusBien">
                    {% if ad is defined %}
                        <option {% if ad.statusBien=="Disponible" %} selected {% endif %}>Disponible</option>
						<option {% if ad.statusBien=="Loué" %} selected {% endif %}>Loué</option>
						<option {% if ad.statusBien=="Vendu" %} selected {% endif %}>Vendu</option>
                    {% else %}
						<option>Disponible</option>
						<option>Loué</option>
						<option>Vendu</option>
                    {% endif %}    
					</select>
				</div>

				<div class="form-group">
					<label for="exampleFormControlTextarea4">Prix</label>
					<input type="number" id="prix" name="prix"
                    {% if ad is defined %} value={{ad.prix}} {% endif %}>
				</div>

				<div class="form-group">
					<label for="date de disponibilité">Date de disponibilité :</label>
					<input type="date" id="date" name="dateDispo"
                    {% if ad is defined %} value={{ad.date|date('Y-m-d')}} {% endif %}>
				</div>


				<div class="form-group">
                    <label for="Images">Images :</label>
                    {% if ad is defined %}
                        <p class="h3" >Image actuelles:<p>
						<input type="text" name="aimages" style="visibility: hidden;display: none;" value="{{ad.images}} ">
                        <div class="row">
                        {% for image in ad.images %}
                        <div class="col-3">
                         <img src="../../uploads/{{image}}" alt="image maison"  class="img-thumbnail">
                        </div>
                        {% endfor %}
                        </div>
                    {% endif %}
					<input type="file" class="form-control-file" 
                    name="uploaded_file" multiple>
				</div>

                {% if ad is defined %}
                <input type="submit" value="Update" class="btn btn-success">
                {% else %}
				<input type="submit" value="Create" class="btn 
                btn-success">
                {% endif %}


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

{% endblock %}
