<?php 
$jsondata = file_get_contents("./api/main.json");
$data = json_decode($jsondata, true);
$json = $data['app'];
$message = '<div class="alert alert-success" id="flash-msg"><h4><i class="icon fa fa-check"></i>Items Updated!</h4></div>';
if(isset($_POST['submit'])){
$jsonData = file_get_contents("./api/main.json");

$arrayData = json_decode($jsonData, true);
	$replacementData = array('app' =>  array(
	'theme'		=>	$_POST["theme"]));
$newArrayData = array_replace_recursive($arrayData, $replacementData);
$newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
file_put_contents("./api/main.json", $newJsonData);
header("Location: theme.php?message=$message");
		}
include ('includes/header.php');
?>

<div class="content-wrapper">
    <div class="container-fluid">
      <?if(isset($_GET['message'])){echo $_GET['message'];}?>
        <div class="card mb-3">
            <div class="card-header">
                <i class="fa fa-unlock fa-lg"></i> Alterar Temas</div>
            <div class="card-body">
                <div class="alert alert-light" role="alert">
                    <div class="row">
                        <div class="col-12">
                            <h3>Temas Disponiveis</h3>
                        </div>
                        <div class="col-md-8">
                            <form method="post">
							<div class="form-group ">
                                    <label class="control-label requiredField" for="theme" >
                                        Escolha seu tema
                                    </label>
                                    <select class="select form-control" id="select" name="theme">
									    <option value="theme_d" <?=$json['theme']=='theme_d'?'selected':'' ?>>Original</option>
                                        <option value="theme_1" <?=$json['theme']=='theme_1'?'selected':'' ?>>Tema 1</option>
										<option value="theme_2" <?=$json['theme']=='theme_2'?'selected':'' ?>>Tema 2</option>
										<option value="theme_3" <?=$json['theme']=='theme_3'?'selected':'' ?>>Tema 3</option>
										<option value="theme_4" <?=$json['theme']=='theme_4'?'selected':'' ?>>Tema 4</option>
                                    </select>
									</div>
                                <div class="form-group">
                                    <div>
                                        <button class="btn btn-info " name="submit" type="submit">
                                            <i class="fa fa-check"></i> Aceitar
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div style="width:700px; margin:0 auto;">
		         <div class="row">
		          <div class="center">
			    <div style="width:700px; margin:0 auto;">
				<form method="post"> 
				  <div class="container">
				    <div class="row">
					<div class="col-sm-6">
					  <div class="card">
					    <div class="card-block">
						<h4 class="card-title text-center card card bg-light text-dark">Original</h4>
						  </div>
						    <img class="card-img-bottom" src="./img/d.jpg" alt="Card image" style="width:100%">
							</div>
							</div>
					<div class="col-sm-6">
					<div class="card">
					<div class="card-block">
						  <h4 class="card-title text-center card card bg-light text-dark">Tema 1</h4>
						    </div>
						      <img class="card-img-bottom" src="./img/1.jpg" alt="Card image" style="width:100%">
						        </div>
							  </div>
                                                           
					<div class="col-sm-6">
					<div class="card">
					<div class="card-block">
						   <h4 class="card-title text-center card card bg-light text-dark">Tema 2</h4>
						     </div>
							<img class="card-img-bottom" src="./img/2.jpg" alt="Card image" style="width:100%">
							  </div>
							   </div>
							    <div class="col-sm-6">
							      <div class="card">
					<div class="card-block">
						    <h4 class="card-title text-center card card bg-light text-dark">Tema 3</h4>
						      </div>
							<img class="card-img-bottom" src="./img/3.jpg" alt="Card image" style="width:100%">
							  </div>
							   </div>
						            <div class="container">
							     <div class="row">		
						              <div class="col-sm-6">
								<div class="card">
					<div class="card-block">
						     <h4 class="card-title text-center card card bg-light text-dark">Tema 4</h4>
							</div>
							  <img class="card-img-bottom" src="./img/4.jpg" alt="Card image" style="width:100%">
							    </div>
							     </div>
                                                           </div>
                                                        </div>
                                                      </div>
                                                    </div>
                                                   </div>
                                         <br><br><br>
                <?php include ('includes/footer.php');?>
                <script> 
$(document).ready(function () {
    $("#flash-msg").delay(3000).fadeOut("slow");
});
  </script>
</body>

</html>