<?= $this->extend('layouts/form.php') ?>

<?= $this->section('content') ?>
<?php

$bugid = "";
$bugtitle = "";
$bugstatus = "";
$bugdetail = "";

foreach($bugs as $data) {
	$bugid = $data['bugid'];
    $bugtitle = $data['bugtitle'];
    $bugdetail = $data['bugdetail'];
    $bugstatus = $data['bugstatus'];
    $bugpriority = $data['bugpriority'];
}

?>
<div class="form-body">
	<h3 class="card-title">Bugs Editor</h3>
	<hr>
	<?php 
	if(isset($validation)) {
	?>
		<div class='alert alert-danger alert-dismissible'>
			<?= $validation->listErrors(); ?>
			<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"> <span aria-hidden="true"></span> </button>
		</div>
	<?php
	}
	?>
	<form method='post'>
		<div class="form-group row">
			<label class="col-2 col-form-label">Bug Priority</label>
			<div class="col-10">
				<select class="form-control form-select" name='bugpriority'>
					<?php
					foreach ($bugpriorities as $qbugpriority => $qtext) {
						if($bugpriority == $qbugpriority) { echo "<option value='$qbugpriority' selected>$qtext</option>"; }
						else { echo "<option value='$qbugpriority'>$qtext</option>"; }
					}
					?>
				</select>
			</div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Bug Name</label>
			<div class="col-10"><input class="form-control" type="text" name='bugtitle' value="<?= $bugtitle; ?>"></div>
		</div>
        <div class="form-group row">
			<label class="col-2 col-form-label">Status</label>
			<div class="col-10">
				<select name='bugstatus' class='form-control'>
					<?php 
					
					if ($bugstatus == 'C') { 
                        echo "<option value='C' selected>Closed</option>";
                        echo "<option value='O' >Open</option>"; 
                    } else { 
                        echo "<option value='O' selected>Open</option>";
                        echo "<option value='C'>Closed</option>"; 
                    }
					
					?>
				</select>
			</div>
		</div>
		<div class="form-group row">
			<label class="col-2 col-form-label">Bug Detail</label>
            
            <div class="col-10">
                <textarea class="form-control mb-1 editor" id="bugdetail_textarea" name="bugdetail"><?=$bugdetail; ?></textarea>
            </div>
		</div>

		<a type="button" class="btn btn-dark float-start" href="<?='/bugs/view/'.$bugid?>">Cancel</a>
		<button type="submit" class="btn btn-success text-white float-end"> <i class="fa fa-check"></i> Submit</button>
	</form>
</div>

<?= $this->endSection() ?>

<?= $this->section('script') ?>
<script src="<?=base_url();?>/assets/tinymce/tinymce.min.js"></script>
<script>
    // config = {
    //     selector:'#bugdetail_textarea',
    //     promotion:false,
    //     menubar:false,
    //     forced_root_block : 'pre',
	// 	plugins: 'lists',
	// 	// plugins: 'emoticons',
	// 	// relative_urls: true,
	// 	toolbar: 'insertfile undo redo styles styleselect | bold italic | forecolor backcolor emoticons | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image',
    // };
    // tinymce.init(config);

	// config
	config = {
		selector:'textarea',
		height:'350',
		promotion:false,
		// forced_root_block : 'pre',
		paste_data_images:false,
		content_style: "p { margin: 0; }",
		plugins: 'preview importcss searchreplace autolink autosave save code visualblocks visualchars fullscreen link template codesample table charmap pagebreak nonbreaking anchor insertdatetime advlist lists wordcount charmap emoticons',
		menubar: 'file edit view insert format tools table',
		toolbar: 'undo redo | bold italic underline strikethrough | fontfamily fontsize blocks | alignleft aligncenter alignright alignjustify | outdent indent |  numlist bullist | forecolor backcolor removeformat | pagebreak | charmap emoticons | fullscreen  preview save print | template link anchor codesample',
		autosave_ask_before_unload: true,
		autosave_interval: '30s',
		automatic_uploads: false,
	};
	tinymce.init(config);
</script>
<?= $this->endSection() ?>