<?php
include "../db.php";

if(isset($_POST['submit'])){

$name=$_POST['name'];
$link=$_POST['link'];
$stream=$_POST['stream'];
$type=$_POST['stream_type'];
$status=$_POST['status'];

$imageName=$_FILES['image']['name'];
$tmpName=$_FILES['image']['tmp_name'];

$newImage=time()."_".$imageName;
$uploadPath="../uploads/".$newImage;
$img="uploads/".$newImage;

move_uploaded_file($tmpName,$uploadPath);

$conn->query("
INSERT INTO menus
(menu_name,menu_image,menu_link,stream_url,stream_type,status)
VALUES
('$name','$img','$link','$stream','$type','$status')
");

header("Location: menus.php");
exit;

}
?>

<!DOCTYPE html>
<html>
<head>

<meta name="viewport" content="width=device-width,initial-scale=1">
<title>Add Radio Station</title>

<style>

/* GLOBAL */

body{
margin:0;
font-family:Arial;
background:#f2f2f2;
display:flex;
}

/* SIDEBAR */

.sidebar{
width:220px;
background:#009688;
color:white;
min-height:100vh;
padding:20px 10px;
box-sizing:border-box;
}

.sidebar h2{
text-align:center;
margin-bottom:20px;
}

.sidebar a{
display:block;
color:white;
text-decoration:none;
padding:10px;
border-radius:4px;
margin-bottom:6px;
}

.sidebar a:hover{
background:rgba(255,255,255,0.2);
}

/* MAIN */

.main{
flex:1;
padding:30px;
}

/* CARD */

.card{
background:white;
border-radius:10px;
padding:25px;
box-shadow:0 2px 10px rgba(0,0,0,0.08);
}

/* HEADER */

.page-header{
display:flex;
justify-content:space-between;
align-items:center;
margin-bottom:25px;
}

.page-header h2{
margin:0;
}

/* BUTTON */

.btn{
background:#009688;
color:white;
padding:10px 18px;
border:none;
border-radius:6px;
cursor:pointer;
font-size:14px;
text-decoration:none;
}

/* FORM GRID */

.form-grid{
display:grid;
grid-template-columns:1fr 1fr;
gap:20px;
}

/* FULL WIDTH */

.full{
grid-column:1/3;
}

/* LABEL */

label{
display:block;
margin-bottom:6px;
font-weight:bold;
font-size:14px;
}

/* INPUT */

input,select{
width:100%;
padding:10px;
border:1px solid #ddd;
border-radius:6px;
box-sizing:border-box;
}

/* MOBILE */

@media(max-width:768px){

.form-grid{
grid-template-columns:1fr;
}

.full{
grid-column:1;
}

}

</style>

</head>

<body>

<?php include "sidebar.php"; ?>

<div class="main">

<div class="card">

<div class="page-header">

<h2>Add Radio Station</h2>

<a href="menus.php" class="btn">← Back</a>

</div>


<form method="post" enctype="multipart/form-data" class="form-grid">

<div>

<label>Radio Name</label>
<input type="text" name="name" required>

</div>


<div>

<label>Stream Type</label>

<select name="stream_type">

<option value="AUTO">Auto Detect</option>
<option value="MP3">MP3</option>
<option value="HLS">HLS (.m3u8)</option>
<option value="Icecast">Icecast</option>

</select>

</div>


<div class="full">

<label>Streaming URL</label>
<input type="text" name="stream" required>

</div>


<div>

<label>Menu Link</label>
<input type="text" name="link">

</div>


<div>

<label>Status</label>

<select name="status">
<option value="1">Active</option>
<option value="0">Disabled</option>
</select>

</div>


<div class="full">

<label>Radio Image</label>
<input type="file" name="image" required>

</div>


<div class="full">

<button class="btn" name="submit">

Add Radio Station

</button>

</div>

</form>

</div>

</div>

</body>
</html>