<?php
session_start();
require 'verifica_cookie.php';
require 'conexao.php';
require 'config.php';

$item = (isset($_POST['item'])) ? $_POST['item'] : '';


if (isset($_SESSION['PEDIDO'])):
	
	$id_categoria = $_SESSION['PEDIDO'][$item]['CATEGORIA'];
	$texto        = $_SESSION['PEDIDO'][$item]['TXT_OBSERVACAO'];
	$opcao        = $_SESSION['PEDIDO'][$item]['OPC_OBSERVACAO'];
	$pdo  = Conexao::getInstance();
	$sql = "SELECT observacao FROM observacoes WHERE id_categoria = {$id_categoria}";
	$stm = $pdo->prepare($sql);
	$stm->execute();
	$observacoes = $stm->fetchAll(PDO::FETCH_OBJ);
	?>
	<form>
	<input type='text' id='texto-observacao'  autocomplete='off' class='mdl-textfield__input observacao' placeholder='Digite uma Observação' value="<?=$texto?>"><br>
	<?php if (!empty($observacoes)): ?>
	    <p>OU</p><br>
		<select class='select' id='opcao-observacao' required>
			<option value='<?=$opcao?>'><?=$opcao?></option>
			<option value=''></option>
			<?php foreach($observacoes as $observacao):?>
			<option value='<?=$observacao->observacao?>'><?=strtoupper($observacao->observacao)?></option>
			<?php endforeach; ?>
		</select>
	<?php endif; ?>
</form>
<?php endif; ?>