<!DOCTYPE html>
<html lang="fa" dir="rtl">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="Cuba admin is super flexible, powerful, clean &amp; modern responsive bootstrap 5 admin template with unlimited possibilities.">
    <meta name="keywords" content="admin template, Cuba admin template, dashboard template, flat admin template, responsive admin template, web app">
    <meta name="author" content="pixelstrap">
    <link rel="icon" href="../../../adminassets/images/favicon.png" type="image/x-icon">
    <link rel="shortcut icon" href="../../../adminassets/images/favicon.png" type="image/x-icon">
    <title>آنسه تیم</title>
    <!-- Google font-->
    <script src="https://cdn.ckeditor.com/ckeditor5/35.0.1/classic/ckeditor.js"></script>

    <link href="https://fonts.googleapis.com/css?family=Rubik:400,400i,500,500i,700,700i&amp;display=swap" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,500,500i,700,700i,900&amp;display=swap" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../../../adminassets/css/font-awesome.css">
    <!-- ico-font-->
    <link rel="stylesheet" type="text/css" href="../../../adminassets/css/vendors/icofont.css">
    <!-- Themify icon-->
    <link rel="stylesheet" type="text/css" href="../../../adminassets/css/vendors/themify.css">
    <!-- Flag icon-->
    <link rel="stylesheet" type="text/css" href="../../../adminassets/css/vendors/flag-icon.css">
    <!-- Feather icon-->
    <link rel="stylesheet" type="text/css" href="../../../adminassets/css/vendors/feather-icon.css">
    <!-- Plugins css start-->
    <link rel="stylesheet" type="text/css" href="../../../adminassets/css/vendors/scrollbar.css">
    <link rel="stylesheet" type="text/css" href="../../../adminassets/css/vendors/prism.css">
    <!-- Plugins css Ends-->
    <!-- Bootstrap css-->
    <link rel="stylesheet" type="text/css" href="../../../adminassets/css/vendors/bootstrap.css">
    <!-- App css-->
    <link rel="stylesheet" type="text/css" href="../../../adminassets/css/style.css">
    <link id="color" rel="stylesheet" href="../../../adminassets/css/color-1.css" media="screen">
    <!-- Responsive css-->
    <link rel="stylesheet" type="text/css" href="../../../adminassets/css/responsive.css">
  </head>
  <body class="rtl">
    <!-- tap on top starts-->
    <div class="tap-top"><i data-feather="chevrons-up"></i></div>
    <!-- tap on tap ends-->
    <!-- page-wrapper Start-->
    <div class="page-wrapper compact-wrapper" id="pageWrapper">
      <!-- Page Header Start-->

        <%- include('../partials/header') %>

        <!-- Page Sidebar Ends-->
        <div class="page-body">
          <div class="container-fluid">
            <div class="page-title">
              <div class="row">
                <div class="col-6">
                  <h3>مدیریت تخفیف ها
                    </h3>
                </div>
                <div class="col-6">
                  <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="index.html"><i data-feather="home"></i></a></li>
                    <li class="breadcrumb-item">تخفیف ها</li>
                    <li class="breadcrumb-item active">تخفیف ها</li>
                  </ol>
                </div>
              </div>
            </div>
          </div>
          <!-- Container-fluid starts-->
          <!-- Container-fluid starts-->
          <div class="container-fluid">
            <div class="row">
              <div class="col-sm-12 col-xl-12">
                <div class="row">
                  <div class="col-sm-10" style="margin:0 auto">

                    <div class="card">
                      <div class="card-header">
                        <h5>ثبت تخفیف</h5>
                      </div>

                      <div class="card-body">
                       <form class="form-space theme-form row" action="/discount/admin/edit/<%= discount._id %>" method="post">

                         <div class="col-sm-6">
                               <label class="form-label">عنوان</label>
                           <input class="form-control" name="Name" id="Name" type="text" placeholder="عنوان" value="<%= discount.Name %>">
                         </div>

                       <div class="col-sm-6">
                             <label class="form-label">کد تخفیف</label>
                         <input class="form-control" name="Code" id="Code" type="text" placeholder="کد تخفیف" value="<%= discount.Code %>">
                       </div>

                       <div class="col-sm-6">
                             <label class="form-label">کمترین مقدار</label>
                         <input class="form-control" name="MinPrice" id="MinPrice" type="text" placeholder="کمترین مقدار" value="<%= discount.MinPrice %>">
                       </div>

                       <div class="col-sm-6">
                             <label class="form-label">بیشترین مقدار</label>
                         <input class="form-control" name="MaxPrice" id="MaxPrice" type="text" placeholder="بیشترین مقدار" value="<%= discount.MaxPrice %>">
                       </div>

                       <div class="mb-3">
                          <label class="form-label" for="Caption">توضیحات</label>
                          <textarea class="form-control" id="Caption" name="Caption" placeholder="توضیحات" ><%= discount.Caption %></textarea>
                        </div>

                        <div class="col-sm-6">
                              <label class="form-label">تاریخ انقضا</label>
                          <input class="form-control" name="ExpiredDate" id="ExpiredDate" type="date" placeholder="تاریخ انقضا" value="<%= discount.ExpiredDate %>">
                        </div>

                        <div class="col-sm-6">
                               <label class="form-label"> نوع خدمات</label>
                           <select  name="ServiceType" id="ServiceType" class="form-select form-control-lg">
                               <% for (var i = 0; i < serviceTypes.length; i++) { %>
                         <option value="<%= serviceTypes[i]._id %>" ><%= serviceTypes[i].Name %></option>
                                   <%  } %>
                           </select>
                       </div>

                       <div class="col-sm-6">
                              <label class="form-label">خدمات</label>
                          <select  name="Service" id="Service" class="form-select form-control-lg">

                          </select>
                      </div>

                       <div>
                         <input type="checkbox" name="ServiceGiftActive" id="ServiceGiftActive" value="<%= discount.ServiceGift.Active %>">
                         <label class="form-label">هدیه براساس سرویس</label>
                         <div id="ServiceGiftList" class="no-display">
                           <div class="col-sm-6">
                              <label class="form-label"> نوع خدمات</label>
                              <select  name="ServiceTypeGift" id="ServiceTypeGift" class="form-select form-control-lg">
                                  <% for (var i = 0; i < serviceTypes.length; i++) { %>
                                     <option value="<%= serviceTypes[i]._id %>" ><%= serviceTypes[i].Name %></option>
                                  <% } %>
                              </select>
                           </div>

                           <div class="col-sm-6">
                             <label class="form-label">خدمات</label>
                             <select  name="ServiceGift" id="ServiceGift" class="form-select form-control-lg">

                             </select>
                           </div>

                           <div class="col-sm-6">
                             <label class="form-label">تعداد</label>
                             <input class="form-control" name="ServiceGiftNumber" id="ServiceGiftNumber" type="text" placeholder="تعداد" value="<%= discount.ServiceGift.Number %>">
                           </div>

                           <div class="col-sm-6">
                             <label class="form-label">کمترین مبلغ</label>
                             <input class="form-control" name="ServiceGiftMinPrice" id="ServiceGiftMinPrice" type="text" placeholder="کمترین مبلغ" value="<%= discount.ServiceGift.MinPrice %>">
                           </div>

                           <div class="col-sm-6">
                             <label class="form-label">بیشترین مبلغ</label>
                             <input class="form-control" name="ServiceGiftMaxPrice" id="ServiceGiftMaxPrice" type="text" placeholder="بیشترین مبلغ" value="<%= discount.ServiceGift.MaxPrice %>">
                           </div>
                        </div>
                      </div>

                      <div>
                        <input type="checkbox" name="WalletGiftActive" id="WalletGiftActive" value="<%= discount.WalletGift.Active %>">
                        <label class="form-label">هدیه برروی کیف پول</label>
                        <div id="WalletList" class="no-display">

                          <div class="col-sm-6">
                            <label class="form-label">مقدار</label>
                            <input class="form-control" name="WalletGiftValue" id="WalletGiftValue" type="text" placeholder="مقدار" value="<%= discount.WalletGift.Value %>">
                          </div>

                          <div class="col-sm-6">
                            <label class="form-label">کمترین مبلغ</label>
                            <input class="form-control" name="WalletGiftMinPrice" id="WalletGiftMinPrice" type="text" placeholder="کمترین مبلغ" value="<%= discount.WalletGift.MinPrice %>">
                          </div>

                          <div class="col-sm-6">
                            <label class="form-label">بیشترین مبلغ</label>
                            <input class="form-control" name="WalletGiftMaxPrice" id="WalletGiftMaxPrice" type="text" placeholder="بیشترین مبلغ" value="<%= discount.WalletGift.MaxPrice %>">
                          </div>

                        </div>
                     </div>

                     <div>
                       <input type="checkbox" name="CashGiftActive" id="CashGiftActive" value="<%= discount.CashGift.Active %>">
                       <label class="form-label">هدیه نقدی</label>
                       <div id="CashList" class="no-display">

                         <div class="col-sm-6">
                           <label class="form-label">مقدار</label>
                           <input class="form-control" name="CashGiftValue" id="CashGiftValue" type="text" placeholder="مقدار" value="<%= discount.CashGift.Value %>">
                         </div>

                         <div class="col-sm-6">
                           <label class="form-label">کمترین مبلغ</label>
                           <input class="form-control" name="CashGiftMinPrice" id="CashGiftMinPrice" type="text" placeholder="کمترین مبلغ" value="<%= discount.CashGift.MinPrice %>">
                         </div>

                         <div class="col-sm-6">
                           <label class="form-label">بیشترین مبلغ</label>
                           <input class="form-control" name="CashGiftMaxPrice" id="CashGiftMaxPrice" type="text" placeholder="بیشترین مبلغ" value="<%= discount.CashGift.MaxPrice %>">
                         </div>

                       </div>
                    </div>

                    <div>
                      <input type="checkbox" name="PercentGiftActive" id="PercentGiftActive" value="<%= discount.PercentGift.Active %>">
                      <label class="form-label">تخفیف درصدی</label>
                      <div id="PercentList" class="no-display">

                        <div class="col-sm-6">
                          <label class="form-label">مقدار</label>
                          <input class="form-control" name="PercentGiftValue" id="PercentGiftValue" type="text" placeholder="مقدار" value="<%= discount.PercentGift.Value %>">
                        </div>

                        <div class="col-sm-6">
                          <label class="form-label">کمترین مبلغ</label>
                          <input class="form-control" name="PercentGiftMinPrice" id="PercentGiftMinPrice" type="text" placeholder="کمترین مبلغ" value="<%= discount.PercentGift.MinPrice %>">
                        </div>

                        <div class="col-sm-6">
                          <label class="form-label">بیشترین مبلغ</label>
                          <input class="form-control" name="PercentGiftMaxPrice" id="PercentGiftMaxPrice" type="text" placeholder="بیشترین مبلغ" value="<%= discount.PercentGift.MaxPrice %>">
                        </div>

                      </div>
                   </div>

                   <div class="card-footer text-end">
                        <button class="btn btn-primary" type="submit">ثبت</button>
                        <a href="../list" class="btn btn-secondary">بازگشت</a>
                      </div>
                        </form>
                      </div>

                    </div>
                  </div>
                </div>
              </div>
          </div>

          </div>
          <!-- Container-fluid Ends-->

          <!-- Container-fluid Ends-->
        </div>
        <!-- footer start-->
        <%- include("../partials/footer") %>
      </div>

    <!-- latest jquery-->
    <script src="../../../adminassets/js/jquery-3.5.1.min.js"></script>
    <!-- Bootstrap js-->
    <script src="../../../adminassets/js/bootstrap/bootstrap.bundle.min.js"></script>
    <!-- feather icon js-->
    <script src="../../../adminassets/js/icons/feather-icon/feather.min.js"></script>
    <script src="../../../adminassets/js/icons/feather-icon/feather-icon.js"></script>
    <!-- scrollbar js-->
    <script src="../../../adminassets/js/scrollbar/simplebar.js"></script>
    <script src="../../../adminassets/js/scrollbar/custom.js"></script>
    <!-- Sidebar jquery-->
    <script src="../../../adminassets/js/config.js"></script>
    <!-- Plugins JS start-->
    <script src="../../../adminassets/js/sidebar-menu.js"></script>
    <script src="../../../adminassets/js/prism/prism.min.js"></script>
    <script src="../../../adminassets/js/clipboard/clipboard.min.js"></script>
    <script src="../../../adminassets/js/custom-card/custom-card.js"></script>
    <script src="../../../adminassets/js/tooltip-init.js"></script>
    <!-- Plugins JS Ends-->
    <!-- Theme js-->
    <script src="../../../adminassets/js/script.js"></script>
    <!-- login js-->
    <!--error message for inputs-->
    <script src="../../../adminassets/js/input-error.js"></script>
    <!-- Plugin used-->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js"></script>
    <script>
      document.getElementById('ServiceGiftActive').addEventListener('load', function() {
        if($('#ServiceGiftActive').value == true){
          $('#ServiceGiftActive').att("checked")
          $("#ServiceGiftList").removeClass("no-display")
          $("#ServiceGiftList").addClass("display")
        }
      })
      document.getElementById('WalletGiftActive').addEventListener('load', function() {
        if($('#WalletGiftActive').value){
          $('#WalletGiftActive').att("checked")
          $("#WalletGiftActive").removeClass("no-display")
          $("#WalletGiftActive").addClass("display")

        }
      })
      document.getElementById('CashGiftActive').addEventListener('load', function() {
        if($('#CashGiftActive').value){
          $('#CashGiftActive').att("checked")
          $("#CashGiftActive").removeClass("no-display")
          $("#CashGiftActive").addClass("display")
        }
      })
      document.getElementById('PercentGiftActive').addEventListener('load', function() {
        if($('#PercentGiftActive').value){
          $('#PercentGiftActive').att("checked")
          $("#PercentGiftActive").removeClass("no-display")
          $("#PercentGiftActive").addClass("display")
        }
      })
    </script>
    <script>
      document.getElementById('ServiceType').addEventListener('change', function() {

      var serviceType = document.getElementById("ServiceType").value
      // var form = document.getElementById('makeNewProject')
      // let data = new FormData(form);

      console.log(serviceType);

      axios
        .get('/service/admin/list/'+ serviceType +'')
        .then((res) => {
          console.log('hi');
          console.log(res.data);
          for (var i = 0; i < res.data.services.length; i++) {
            $("#Service").append('<option value="'+ res.data.services[i]._id %>+'" >'+ res.data.services[i].Title +'</option>')
          }
        })
    })
    </script>
    <!-- ServiceGiftActive -->
    <script>
      document.getElementById('ServiceGiftActive').addEventListener('change', function() {
        if ($("#ServiceGiftList").hasClass("display")){
          ServiceGiftActive.value = false
          $("#ServiceGiftList").removeClass("display")
          $("#ServiceGiftList").addClass("no-display")
        } else {
          ServiceGiftActive.value = true
          $("#ServiceGiftList").removeClass("no-display")
          $("#ServiceGiftList").addClass("display")


          document.getElementById('ServiceTypeGift').addEventListener('change', function() {

            var serviceType = document.getElementById("ServiceTypeGift").value

            console.log(serviceType);

            axios
              .get('/service/admin/list/'+ serviceType +'' )
              .then((res) => {
                console.log('hi2');
                console.log(res.data);
                for (var i = 0; i < res.data.services.length; i++) {
                  $("#ServiceGift").append('<option value="'+ res.data.services[i]._id %>+'" >'+ res.data.services[i].Title +'</option>')
                }

              })
          })
        }
      })
    </script>
    <!-- WalletGiftActive -->
    <script>
      document.getElementById('WalletGiftActive').addEventListener('change', function() {
        if ($("#WalletList").hasClass("display")){
          WalletGiftActive.value = false
          $("#WalletList").removeClass("display")
          $("#WalletList").addClass("no-display")
        } else {
          WalletGiftActive.value = true
          $("#WalletList").removeClass("no-display")
          $("#WalletList").addClass("display")
        }
      })
    </script>
    <!-- CashGiftActive -->
    <script>
      document.getElementById('CashGiftActive').addEventListener('change', function() {
        if ($("#CashList").hasClass("display")){
          CashGiftActive.value = false
          $("#CashList").removeClass("display")
          $("#CashList").addClass("no-display")
        } else {
          CashGiftActive.value = true
          $("#CashList").removeClass("no-display")
          $("#CashList").addClass("display")
        }
      })
    </script>
    <!-- PercentGiftActive -->
    <script>
      document.getElementById('PercentGiftActive').addEventListener('change', function() {
        if ($("#PercentList").hasClass("display")){
          PercentGiftActive.value = false
          $("#PercentList").removeClass("display")
          $("#PercentList").addClass("no-display")
        } else {
          PercentGiftActive.value = true
          $("#PercentList").removeClass("no-display")
          $("#PercentList").addClass("display")
        }
      })
    </script>
  </body>
</html>
