<?php
$noticiasDao = new \Dao\Noticias();
$noticiasDao->getNoticiaPorId($conecta, base64_decode(filter_input(INPUT_GET, 'id')));
?>
<div class="breadcrumb-holder">
    <div class="container-fluid">
        <ul class="breadcrumb">
            <li class="breadcrumb-item"><a href="./">Home</a></li>
            <li class="breadcrumb-item"><a href="noticias.php">Noticias</a></li>
            <li class="breadcrumb-item active"><?php echo ($noticiasDao->id == 0 ? 'Adicionar Noticia' : 'Editar Noticia'); ?></li>
        </ul><!--/.breadcrumb -->
    </div><!---/.container-fluid -->
</div><!--/.breadcrumb-holder -->
<section class="dashboard-counts section-padding">
    <div class="container-fluid">
        <div class="row">
            <div class="col-lg-12">
                <div class="card">
                    <div class="card-header d-flex align-items-center">
                        <h2 class="h5 display"><?php echo ($noticiasDao->id == 0 ? 'Adicionar Noticia' : 'Editar - ' . $noticiasDao->titulo); ?></h2>
                    </div><!--/.card-header -->
                    <div class="card-body">
                        <form class="form-horizontal" method="post" action="?p=salvar" enctype="multipart/form-data">
                            <input type="hidden" name="id" id="id" value="<?php echo $noticiasDao->id; ?>">
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Data</label>
                                <div class="col-sm-3">
                                    <div class="input-group" id="datePicker">
                                        <input type="text" name="data" id="data" placeholder="Data" value="<?php echo date('d/m/Y', strtotime($noticiasDao->data)); ?>" maxlength="10" class="form-control" required>
                                        <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                                    </div><!--/.input-group -->
                                </div><!--/.col-sm-3 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Título</label>
                                <div class="col-sm-7">
                                    <input type="text" name="titulo" id="titulo" placeholder="Título" value="<?php echo $noticiasDao->titulo; ?>" maxlength="120" class="form-control" required autofocus>
                                </div><!--/.col-sm-3 -->
                            </div><!--/.form-group -->
                            
                            
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Texto</label>
                                <div class="col-sm-10">
                                    <textarea cols="13" rows="5" id="texto" name="texto" class="editor_textarea"><?php echo stripslashes($noticiasDao->texto); ?></textarea>
                                </div><!--/.col-sm-10 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label">Imagem</label>
                                <div class="col-sm-5">
                                    <input type="file" name="image" id="image" class="file-input">
                                </div><!--/.col-sm-5 -->
                            </div><!--/.form-group -->
                            <div class="form-group row">
                                <label class="col-sm-2 form-label"></label>
                                <div class="col-sm-12">
                                    <div class="img-container">
                                        <?php
                                        if ($noticiasDao->image != '' && file_exists($pasta . $noticiasDao->image))
                                            echo '<img id="imagem" src="' . $pasta . $noticiasDao->image . '" class="height200" alt="">';
                                        else
                                            echo '<img id="imagem" src="https://placehold.it/1000x600" class="height200" alt="">';
                                        ?>
                                    </div><!--/.img-container -->
                                </div><!--/.col-sm-12 -->
                            </div><!--/.cropper -->
                            <div class="form-group row">
                                <label class="col-sm-2"></label>
                                <div class="col-sm-2">
                                    <button class="btn btn-sm btn-primary"><i class="fa fa-database"></i> Salvar</button>
                                </div><!--/.col-sm-2 -->
                            </div><!--/.form-group -->
                        </form>
                    </div><!--/.card-body -->
                </div><!--/.card -->
            </div><!--/.col-lg-12 -->
        </div><!--/.row -->
    </div><!--/.container-fluid -->
</section><!--/.dashboard-counts -->