<?php 
    $data = array();
    $data['title'] = "Ürün Ekle | ".$config->get('site_title');
    $data['links'] = [];
    $data['styles'] = [];
    $data['header']['scripts'] = [];
    $data['version'] = $config->get('version');
    $data['csrf_token'] = $csrf_generator->create();
    $data['sidebar_menu'] = $menu->get(array('position'=>'sidebar'));
    $data['sidebar_active_menu'] = $menu->getActiveMenuItemId(trim($_SERVER['REQUEST_URI']));
    $data['footer']['scripts'] = ['/admin/public/assets/js/pages/product/edit.js'];
    $menu_items = $menu->get(array('position'=>'footer'));
    foreach($menu_items as $item){
        if($item['col'] == "1"){
            $data['menu']['footer']["1"][] = $item;
        }
        if($item['col'] == "2"){
            $data['menu']['footer']["2"][] = $item;
        }
        if($item['col'] == "3"){
            $data['menu']['footer']["3"][] = $item;
        }
        if($item['col'] == "4"){
            $data['menu']['footer']["4"][] = $item;
        }
    }

    $data['breadcrumbs'] = array();
    $data['breadcrumbs'][] = array(
        'text' => "Pano",
        'href' => "/admin",
        'index' => 1
    );
    $data['breadcrumbs'][] = array(
        'text' => "Ürünler",
        'href' => "/admin/course/list",
        'index' => 2
    );
    $data['breadcrumbs'][] = array(
        'text' => "Yeni Ürün",
        'href' => "#",
        'index' => 3
    );

    if($_SERVER['REQUEST_METHOD'] == 'POST'){
        $status             = $_POST['status'];
        $title              = $_POST['title'];
        $sku                = $_POST['sku'];
        $ean                = $_POST['ean'];
        $brand_id           = isset($_POST['brand_id']) ? $_POST['brand_id'] : 0;
        $supplier_id        = isset($_POST['supplier_id']) && !empty($_POST['supplier_id']) ? (int)$_POST['supplier_id'] : 0;
        $category           = isset($_POST['category']) && !empty($_POST['category']) ? $_POST['category'] : null;
        $delivery_areas     = isset($_POST['delivery_areas']) ? $_POST['delivery_areas'] : null;
        $shipping_agencies  = isset($_POST['shipping_agencies']) ? $_POST['shipping_agencies'] : null;
        $featured           = isset($_POST['featured']) ? 1 : 0;
        $checkout_offer     = isset($_POST['checkout_offer']) ? 1 : 0;
        $free_shipping      = isset($_POST['free_shipping']) ? 1 : 0;
        $new                = isset($_POST['new']) ? 1 : 0;

        $price               = $_POST['price'];
        $discount_rate       = $_POST['discount_rate'];
        $discounted_price    = $_POST['discounted_price'];
        $buying_price        = $_POST['buying_price'];
        $vat                 = $_POST['vat'];
        $cart_discount_rate  = $_POST['cart_discount_rate'];
        $cart_discounted_price = $_POST['cart_discounted_price'];

        //$selling_price       = $discount_rate != 0 ? $discounted_price : $price;
        if($cart_discount_rate != 0) {
            $selling_price = $cart_discounted_price;
        }else if($discount_rate != 0) {
            $selling_price = $discounted_price;
        }else{
            $selling_price = $price;
        }

        $description         = $_POST['description'];
        $short_description   = $_POST['short_description'];
        $info_1              = $_POST['info_1'];
        $info_2              = $_POST['info_2'];
        $info_3              = $_POST['info_3'];
        $return_policy       = $_POST['return_policy'];

        $stock_tracking      = $_POST['stock_tracking'];
        $stock_unit          = $_POST['stock_unit'];
        $stock_level         = $_POST['stock_level'];
        $stock_critical_level = $_POST['stock_critical_level'];
        
        $min_order_quantity  = (int)$_POST['min_order_quantity'];
        $max_order_quantity  = (int)$_POST['max_order_quantity'];
        $search_keywords     = $_POST['search_keywords'];
        $delivery_time       = $_POST['delivery_time'];
        $delivery_description = $_POST['delivery_description'];
        $meta_title          = isset($_POST['meta_title']) && !empty($_POST['meta_title']) ? $_POST['meta_title'] : $title;
        $meta_description    = isset($_POST['meta_description']) && !empty($_POST['meta_description']) ? $_POST['meta_description'] : $title . " fiyatını ve ürün özellikleri incelemek  için hemen tıklayın, en yeni fırsatları kaçırmayın!";

        
        if($max_order_quantity < 1) {
            $max_order_quantity = 9999;
        }

        $seo_url	         = $utils->generateUrl($title);

        if(!isset($_FILES['image']) || !file_exists($_FILES['image']['tmp_name']) || !is_uploaded_file($_FILES['image']['tmp_name'])){
            $image               = "default.jpg";
        } else {
            $image_parts         = pathinfo($_FILES['image']["name"]);
            $image               = $seo_url."-".uniqid().".".$image_parts['extension'];
            $utils->resizeCropImage(500, 500, $_FILES['image']['tmp_name'], "../public/assets/images/products/medium/".$image);
            $utils->resizeCropImage(170, 170, $_FILES['image']['tmp_name'], "../public/assets/images/products/thumb/".$image);
            move_uploaded_file($_FILES['image']['tmp_name'], "../public/assets/images/products/large/".$image);
        }

        $stmt = $db->query("INSERT INTO {$db->prefix}products (`status`, `title`, `short_description`, `description`, info_1, info_2, info_3, `return_policy`, `sku`, `ean`, `free_shipping`, `featured`, `checkout_offer`, `new`, `supplier_id`, `brand_id`, `price`, `discounted_price`, `discount_rate`, `cart_discounted_price`, `cart_discount_rate`, `selling_price`, `buying_price`, `vat`, `stock_unit`, `stock_tracking`, `stock_level`, `stock_critical_level`, `delivery_time`, `delivery_description`, `min_order_quantity`, `max_order_quantity`, `image`, `search_keywords`, `date_added`, `date_modified`) VALUES (:status, :title, :short_description, :description, :info_1, :info_2, :info_3, :return_policy, :sku, :ean, :free_shipping, :featured, :checkout_offer, :new, :supplier_id, :brand_id, :price, :discounted_price, :discount_rate, :cart_discounted_price, :cart_discount_rate, :selling_price, :buying_price, :vat, :stock_unit, :stock_tracking, :stock_level, :stock_critical_level, :delivery_time, :delivery_description, :min_order_quantity, :max_order_quantity, :image, :search_keywords, NOW(), NOW())", 
        array(':status'=>$status, ':title'=>$title, ':short_description'=>$short_description, ':description'=>$description, ':info_1'=>$info_1, ':info_2'=>$info_2, ':info_3'=>$info_3, ':return_policy'=>$return_policy, ':sku'=>$sku, ':ean'=>$ean, ':free_shipping'=>$free_shipping, ':price'=>$price, ':discount_rate'=>$discount_rate, ':discounted_price'=>$discounted_price, ':cart_discount_rate'=>$cart_discount_rate, ':cart_discounted_price'=>$cart_discounted_price, ':vat'=>$vat, ':selling_price'=>$selling_price, ':buying_price'=>$buying_price, ':featured'=>$featured, ':checkout_offer'=>$checkout_offer, ':new'=>$new, ':image'=>$image, ':supplier_id'=>$supplier_id, ':brand_id'=>$brand_id, ':stock_unit'=>$stock_unit, ':stock_tracking'=>$stock_tracking, ':stock_level'=>$stock_level, ':stock_critical_level'=>$stock_critical_level, ':delivery_time'=>$delivery_time, ':delivery_description'=>$delivery_description, ':min_order_quantity'=>$min_order_quantity, ':max_order_quantity'=>$max_order_quantity, ':search_keywords'=>$search_keywords));
        if($stmt->error){
            $utils->errorLog("error", "Cannot add course info. Error: ".$stmt->error_info['message'], $session->data['user_id'], $_SERVER['REQUEST_URI']);
            $session->data['messageType'] = "error"; 
            $session->data['messageTitle'] = "Hata!"; 
            $session->data['message'] = "Bir hata oluştu ve ürün kaydedilemedi."; 
            header("Refresh: 0;");
            exit();
        }else{
            $inserted_id = $db->getLastId();
            $utils->addUrl($seo_url, "product", $inserted_id, "", $meta_title, strip_tags($meta_description));

            if(!empty($category)){
                foreach($category as $c) {
                    $db->query("INSERT INTO {$db->prefix}product_to_category (product_id, category_id) VALUES (:product_id, :category_id)", array(':category_id'=>$c, ':product_id'=>$inserted_id));
                }
            }

            if(!empty($delivery_areas)){
                foreach($delivery_areas as $c) {
                    $db->query("INSERT INTO {$db->prefix}delivery_areas (product_id, city) VALUES (:product_id, :city)", array(':city'=>$c, ':product_id'=>$inserted_id));
                }
            }

            if(!empty($shipping_agencies)){
                foreach($shipping_agencies as $c) {
                    $db->query("INSERT INTO {$db->prefix}product_shipping (product_id, shipping_agency) VALUES (:product_id, :shipping_agency)", array(':shipping_agency'=>$c, ':product_id'=>$inserted_id));
                }
            }

            $session->data['messageType'] = "success"; 
            $session->data['messageTitle'] = "Başarılı!"; 
            $session->data['message'] = "Ürün başarıyla kaydedildi."; 
            header("Location: /admin/product/edit?id=".$inserted_id);
            exit();
        }
	}
    
    $brands 	            = $product->getBrands();
    $suppliers 	            = $product->getSuppliers();
    $categories 	        = $product->getCategories();
    $cities 	            = $utils->getCities();
    $shipping_agencies      = $order->getShippingAgenciesList();
    $sellers 	            = $seller->getSellers(array('status'=>1));
?>
<?php include DIR_VIEWS."parts/header.php"; ?>
        <main class="content">
            <form action="" method="post" enctype="multipart/form-data">
                <div class="container-fluid">
                    <div class="row">
                        <div class="col-md-4 col-xl-3">
                            <div class="card">
                                <div class="list-group list-group-flush" id="profile-settings" role="tablist">
                                    <a class="list-group-item list-group-item-action active" data-bs-toggle="tab" href="#generalTab" aria-selected="true">Genel Bilgiler</a>
                                    <a class="list-group-item list-group-item-action" data-bs-toggle="tab" href="#pricingTab" aria-selected="false">Fiyatlandırma</a>
                                    <a class="list-group-item list-group-item-action" data-bs-toggle="tab" href="#descriptionsTab" aria-selected="false">Açıklamalar</a>
                                    <a class="list-group-item list-group-item-action" data-bs-toggle="tab" href="#stockTab" aria-selected="false">Stok</a>
                                    <a class="list-group-item list-group-item-action" data-bs-toggle="tab" href="#extrasTab" aria-selected="false">Ek Bilgiler</a>
                                </div>
                            </div>
                        </div>

                        <div class="col-md-8 col-xl-9">
                            <div class="tab-content" id="tab-content">
                                <div class="tab-pane fade active show" id="generalTab" role="tabpanel">
                                    <div class="card">
                                        <div class="card-header">
                                            <h5 class="card-title">Genel Bilgiler</h5>
                                        </div>
                                        <div class="card-body">
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="title" class="col-form-label fw-bold">Ürün Adı</label>
                                                </div>
                                                <div class="col-md-9">
                                                    <input type="text" class="form-control" name="title" id="title" placeholder="Ürün adı" value="<?php echo isset($_POST["title"]) ? htmlspecialchars($_POST["title"], ENT_QUOTES) : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="status" class="col-form-label fw-bold">Durum</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <select name="status" id="status" class="form-control form-select">
                                                        <option value="1" <?php echo isset($_POST["status"]) && $_POST["status"] == 1 ? 'selected' : ''; ?>>Satışta</option>
                                                        <option value="0" <?php echo isset($_POST["status"]) && $_POST["status"] == 0 ? 'selected' : ''; ?>>Satışa Kapalı</option>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="sku" class="col-form-label fw-bold">Stok Kodu</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <input type="text" class="form-control" name="sku" id="sku" placeholder="sku" value="<?php echo isset($_POST["sku"]) ? htmlspecialchars($_POST["sku"], ENT_QUOTES) : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="ean" class="col-form-label fw-bold">Barkod</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <input type="text" class="form-control" name="ean" id="ean" placeholder="ör: 98765432198" value="<?php echo isset($_POST["ean"]) ? htmlspecialchars($_POST["ean"], ENT_QUOTES) : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="brand_id" class="col-form-label fw-bold">Marka</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <select name="brand_id" id="brand_id" class="form-control form-select js-choice">
                                                        <option value="">Seçiniz</option>
                                                        <?php foreach ($brands as $b): ?>
                                                            <option value="<?php echo $b['id']; ?>" <?php echo isset($_POST["brand_id"]) && $_POST["brand_id"] == $s['id'] ? 'selected' : ''; ?>><?php echo htmlspecialchars($b['title'], ENT_QUOTES); ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="seller_id" class="col-form-label fw-bold">Satıcı</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <select name="seller_id" id="seller_id" class="form-control form-select js-choice">
                                                        <option value="">Seçiniz</option>
                                                        <?php foreach ($sellers as $b): ?>
                                                            <option value="<?php echo $b['id']; ?>" <?php echo isset($_POST["seller_id"]) && $_POST["seller_id"] == $s['id'] ? 'selected' : ''; ?>><?php echo htmlspecialchars($b['short_name'], ENT_QUOTES); ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="supplier_id" class="col-form-label fw-bold">Tedarikçi</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <select name="supplier_id" id="supplier_id" class="form-control form-select js-choice">
                                                        <?php foreach ($suppliers as $s): ?>
                                                            <option value="<?php echo $s['id']; ?>" <?php echo isset($_POST["supplier_id"]) && $_POST["supplier_id"] == $s['id'] ? 'selected' : ''; ?>><?php echo htmlspecialchars($s['title'], ENT_QUOTES); ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="category" class="col-form-label fw-bold">Kategori</label>
                                                </div>
                                                <div class="col-md-9">
                                                    <select name="category[]" id="category" class="form-control form-select js-choice" multiple>
                                                        <?php foreach ($categories as $c): ?>
                                                            <option value="<?php echo $c['id']; ?>" class="fw-bold"><?php echo htmlspecialchars($c['title'], ENT_QUOTES); ?></option>
                                                            <?php if (!empty($c['sub_items'])): ?>
                                                                <?php foreach ($c['sub_items'] as $s1): ?>
                                                                    <option value="<?php echo $s1['id']; ?>">&nbsp;&nbsp;<?php echo htmlspecialchars($c['title'], ENT_QUOTES); ?> > <?php echo htmlspecialchars($s1['title'], ENT_QUOTES); ?></option>
                                                                    <?php if (!empty($s1['sub_items'])): ?>
                                                                        <?php foreach ($s1['sub_items'] as $s2): ?>
                                                                            <option value="<?php echo $s2['id']; ?>">&nbsp;&nbsp;&nbsp;&nbsp;<?php echo htmlspecialchars($c['title'], ENT_QUOTES); ?> > <?php echo htmlspecialchars($s1['title'], ENT_QUOTES); ?> > <?php echo htmlspecialchars($s2['title'], ENT_QUOTES); ?></option>
                                                                        <?php endforeach; ?>
                                                                    <?php endif; ?>
                                                                <?php endforeach; ?>
                                                            <?php endif; ?>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="shipping_agencies" class="col-form-label fw-bold">Kargo Şirketleri</label>
                                                </div>
                                                <div class="col-md-9">
                                                    <select name="shipping_agencies[]" id="shipping_agencies" class="form-control form-select js-choice" multiple required>
                                                        <?php foreach ($shipping_agencies as $s): ?>
                                                            <option value="<?php echo $s['id']; ?>" <?php echo $s['status'] == 1 ? 'selected' : ''; ?>><?php echo $s['title']; ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="delivery_areas" class="col-form-label fw-bold">Teslimat Bölgeleri</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <select name="delivery_areas[]" id="delivery_areas" class="form-control form-select js-choice" multiple>
                                                        <option value="">Tüm Türkiye</option>
                                                        <?php foreach ($cities as $s): ?>
                                                            <option value="<?php echo $s['plate_no']; ?>"><?php echo $s['name']; ?></option>
                                                        <?php endforeach; ?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="image" class="col-form-label fw-bold">Görsel</label>
                                                </div>
                                                <div class="col-md-4">
                                                    <input type="file" class="form-control" name="image" id="image">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="featured" class="col-form-label fw-bold">Öne Çıkanlar?</label>
                                                </div>
                                                <div class="col-md-9 position-relative">
                                                    <input type="checkbox" class="form-label" name="featured" id="featured" <?php echo isset($_POST["featured"]) && $_POST["featured"] == 1 ? 'checked' : ''; ?>>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="checkout_offer" class="col-form-label fw-bold">Kasa Önü?</label>
                                                </div>
                                                <div class="col-md-9 position-relative">
                                                    <input type="checkbox" class="form-label" name="checkout_offer" id="checkout_offer" <?php echo isset($_POST["checkout_offer"]) && $_POST["checkout_offer"] == 1 ? 'checked' : ''; ?>>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="new" class="col-form-label fw-bold">Yeni Gelenler?</label>
                                                </div>
                                                <div class="col-md-9 position-relative">
                                                    <input type="checkbox" class="form-label" name="new" id="new" <?php echo isset($_POST["new"]) && $_POST["new"] == 1 ? 'checked' : ''; ?>>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="free_shipping" class="col-form-label fw-bold">Ücretsiz Kargo?</label>
                                                </div>
                                                <div class="col-md-9 position-relative">
                                                    <input type="checkbox" class="form-label" name="free_shipping" id="free_shipping" <?php echo isset($_POST["free_shipping"]) && $_POST["free_shipping"] == 1 ? 'checked' : ''; ?>>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-12 text-end">
                                                    <input type="submit" name="update" class="btn btn-primary" value="Kaydet">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="tab-pane fade" id="pricingTab" role="tabpanel">
                                    <div class="card">
                                        <div class="card-header">
                                            <h5 class="card-title">Fiyatlandırma</h5>
                                        </div>
                                        <div class="card-body">
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="price" class="col-form-label fw-bold">Etiket Fiyatı</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="0.01" class="form-control" name="price" id="price" placeholder="00.00" value="<?php echo isset($_POST["price"]) ? $_POST["price"] : ''; ?>">
                                                </div>
                                                <div class="col-md-3">
                                                    <label for="buying_price" class="col-form-label fw-bold">Alış Fiyat</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="0.01" class="form-control" name="buying_price" id="buying_price" placeholder="00.00" value="<?php echo isset($_POST["buying_price"]) ? $_POST["buying_price"] : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="discount_rate" class="col-form-label fw-bold">İndirim Oranı</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="0.01" class="form-control" name="discount_rate" id="discount_rate" placeholder="00.00" value="<?php echo isset($_POST["discount_rate"]) ? $_POST["discount_rate"] : ''; ?>">
                                                </div>
                                                <div class="col-md-3">
                                                    <label for="discounted_price" class="col-form-label fw-bold">Satış Fiyat</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="0.01" class="form-control" name="discounted_price" id="discounted_price" placeholder="00.00" value="<?php echo isset($_POST["discounted_price"]) ? $_POST["discounted_price"] : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="cart_discount_rate" class="col-form-label fw-bold">Sepette İndirim Oranı (opsiyonel)</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="0.01" class="form-control" name="cart_discount_rate" id="cart_discount_rate" placeholder="00.00" value="<?php echo isset($_POST["cart_discount_rate"]) ? $_POST["cart_discount_rate"] : ''; ?>">
                                                </div>
                                                <div class="col-md-3">
                                                    <label for="cart_discounted_price" class="col-form-label fw-bold">Sepette Satış Fiyatı (opsiyonel)</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="0.01" class="form-control" name="cart_discounted_price" id="cart_discounted_price" placeholder="00.00" value="<?php echo isset($_POST["cart_discounted_price"]) ? $_POST["cart_discounted_price"] : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="vat" class="col-form-label fw-bold">KDV Oranı</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="0.01" class="form-control" name="vat" id="vat" placeholder="00.00" value="<?php echo isset($_POST["vat"]) ? $_POST["vat"] : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-12 text-end">
                                                    <input type="submit" name="update" class="btn btn-primary" value="Kaydet">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="tab-pane fade" id="descriptionsTab" role="tabpanel">
                                    <div class="card">
                                        <div class="card-header">
                                            <h5 class="card-title">Açıklamalar</h5>
                                        </div>
                                        <div class="card-body">
                                            <div class="row mb-3">
                                                <div class="col-md-12">
                                                    <label for="short_description" class="col-form-label fw-bold">Kısa Açıklama</label>
                                                </div>
                                                <div class="col-md-12">
                                                    <textarea class="form-control editor" name="short_description" id="short_description" rows="10"><?php echo isset($_POST["short_description"]) ? $_POST["short_description"] : ''; ?></textarea>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-12">
                                                    <label for="description" class="col-form-label fw-bold">Açıklama</label>
                                                </div>
                                                <div class="col-md-12">
                                                    <textarea class="form-control editor" name="description" id="description" rows="10"><?php echo isset($_POST["description"]) ? $_POST["description"] : ''; ?></textarea>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-12">
                                                    <label for="info_1" class="col-form-label fw-bold">Aktif İçerikler</label>
                                                </div>
                                                <div class="col-md-12">
                                                    <textarea class="form-control editor" name="info_1" id="info_1" rows="10"></textarea>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-12">
                                                    <label for="info_2" class="col-form-label fw-bold">Kullanım Şekli</label>
                                                </div>
                                                <div class="col-md-12">
                                                    <textarea class="form-control editor" name="info_2" id="info_2" rows="10"></textarea>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-12">
                                                    <label for="info_3" class="col-form-label fw-bold">Ek Bilgi 3</label>
                                                </div>
                                                <div class="col-md-12">
                                                    <textarea class="form-control editor" name="info_3" id="info_3" rows="10"></textarea>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-12">
                                                    <label for="return_policy" class="col-form-label fw-bold">İade Açıklaması</label>
                                                </div>
                                                <div class="col-md-12">
                                                    <textarea class="form-control editor" name="return_policy" id="return_policy" rows="10"><?php echo isset($_POST["return_policy"]) ? $_POST["return_policy"] : ''; ?></textarea>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-12 text-end">
                                                    <input type="submit" name="update" class="btn btn-primary" value="Kaydet">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="tab-pane fade" id="stockTab" role="tabpanel">
                                    <div class="card">
                                        <div class="card-header">
                                            <h5 class="card-title">Stok</h5>
                                        </div>
                                        <div class="card-body">
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="stock_tracking" class="col-form-label fw-bold">Stok Takibi Yapılsın mı?</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <select name="stock_tracking" id="stock_tracking" class="form-control form-select">
                                                        <option value="1" <?php echo isset($_POST["stock_tracking"]) && $_POST["stock_tracking"] == 1 ? 'selected' : ''; ?>>Evet</option>
                                                        <option value="0" <?php echo isset($_POST["stock_tracking"]) && $_POST["stock_tracking"] == 0 ? 'selected' : ''; ?>>Hayır</option>
                                                    </select>
                                                </div>
                                                <div class="col-md-3">
                                                    <label for="stock_unit" class="col-form-label fw-bold">Stok Birimi</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <select name="stock_unit" id="stock_unit" class="form-control form-select">
                                                        <?php
                                                            $stmt  	= $db->query("SELECT * FROM ".$db->prefix."stock_units");
                                                            foreach ($stmt->rows as $row): ?>
                                                                <option value="<?php echo $row["id"]; ?>" <?php echo isset($_POST["stock_unit"]) && $_POST["stock_unit"] == $row['id'] ? 'selected' : ''; ?>><?php echo $row["title"]; ?></option>
                                                            <?php endforeach; ?>
                                                    </select>
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="stock_level" class="col-form-label fw-bold">Stok Miktarı</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="1" class="form-control" name="stock_level" id="stock_level" placeholder="1" value="<?php echo isset($_POST["stock_level"]) ? $_POST["stock_level"] : '1'; ?>">
                                                </div>
                                                <div class="col-md-3">
                                                    <label for="stock_critical_level" class="col-form-label fw-bold">Kritik Stok Seviyesi</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="1" class="form-control" name="stock_critical_level" id="stock_critical_level" placeholder="0" value="<?php echo isset($_POST["stock_critical_level"]) ? $_POST["stock_critical_level"] : '0'; ?>">
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-12 text-end">
                                                    <input type="submit" name="update" class="btn btn-primary" value="Kaydet">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>

                                <div class="tab-pane fade" id="extrasTab" role="tabpanel">
                                    <div class="card">
                                        <div class="card-header">
                                            <h5 class="card-title">Ek Bilgiler</h5>
                                        </div>
                                        <div class="card-body">
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="min_order_quantity" class="col-form-label fw-bold">Minimum Adet <span class="bi bi-info-circle-fill" role="button" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Müşteriler belirtilen adetin altında bu üründen satın alamaz."></span></label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="1" class="form-control" name="min_order_quantity" id="min_order_quantity" placeholder="1" value="<?php echo isset($_POST["min_order_quantity"]) ? $_POST["min_order_quantity"] : '1'; ?>">
                                                </div>
                                                <div class="col-md-3">
                                                    <label for="max_order_quantity" class="col-form-label fw-bold">Maksimum Adet <span class="bi bi-info-circle-fill" role="button" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Müşteriler bu üründen tek seferde en fazla belirtilen adet kadar satın alabilir"></span></label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="1" class="form-control" name="max_order_quantity" id="max_order_quantity" placeholder="2" value="<?php echo isset($_POST["max_order_quantity"]) ? $_POST["max_order_quantity"] : '2'; ?>">
                                                </div>
                                            </div>
                                            <hr>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="delivery_time" class="col-form-label fw-bold">Teslimat Süresi (gün)</label>
                                                </div>
                                                <div class="col-md-3">
                                                    <input type="number" step="1" class="form-control" name="delivery_time" id="delivery_time" placeholder="1" value="<?php echo isset($_POST["delivery_time"]) ? $_POST["delivery_time"] : '1'; ?>">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="delivery_time" class="col-form-label fw-bold">Teslimat Açıklaması</label>
                                                </div>
                                                <div class="col-md-9">
                                                    <input type="text" class="form-control" name="delivery_description" id="delivery_description" placeholder="" value="<?php echo isset($_POST["delivery_description"]) ? htmlspecialchars($_POST["delivery_description"], ENT_QUOTES) : ''; ?>">
                                                </div>
                                            </div>
                                            <hr>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="search_keywords" class="col-form-label fw-bold">Arama Kelimeleri <span class="bi bi-info-circle-fill" role="button" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Site içi aramada ürünlerin daha kolay bulunmasını sağlar. Kelimeler arasında boşluk kullanabilirsiniz."></span></label>
                                                </div>
                                                <div class="col-md-9">
                                                    <input type="text" class="form-control" name="search_keywords" id="search_keywords" placeholder="" value="<?php echo isset($_POST["search_keywords"]) ? htmlspecialchars($_POST["search_keywords"], ENT_QUOTES) : ''; ?>">
                                                </div>
                                            </div>
                                            <hr>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="meta_title" class="col-form-label fw-bold">Meta Başlığı <span class="bi bi-info-circle-fill" role="button" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Ürünün arama motorları tarafından görüntülenen adı. Boş bırakılırsa ürün adını alır."></span></label>
                                                </div>
                                                <div class="col-md-9">
                                                    <input type="text" class="form-control" name="meta_title" id="meta_title" placeholder="0" value="<?php echo isset($_POST["meta_title"]) ? htmlspecialchars($_POST["meta_title"], ENT_QUOTES) : ''; ?>">
                                                </div>
                                            </div>
                                            <div class="row mb-3">
                                                <div class="col-md-3">
                                                    <label for="meta_title" class="col-form-label fw-bold">Meta Açıklama <span class="bi bi-info-circle-fill" role="button" data-bs-toggle="tooltip" data-bs-placement="top" data-bs-title="Arama motorları tarafından görüntülenen ürün açıklaması. Boş bırakılırsa ürün kısa açıklamasını alır."></span></label>
                                                </div>
                                                <div class="col-md-9">
                                                    <textarea name="meta_description" id="meta_description" rows="2" class="form-control"><?php echo isset($_POST["meta_description"]) ? htmlspecialchars($_POST["meta_description"], ENT_QUOTES) : ''; ?></textarea>
                                                </div>
                                            </div>
                                            <div class="row">
                                                <div class="col-12 text-end">
                                                    <input type="submit" name="update" class="btn btn-primary" value="Kaydet">
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>
        </main>
<?php include DIR_VIEWS."parts/footer.php"; ?>