<!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-->
    <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><span>برای مشاهده لیست آموزش ها میتوانید از  <a href="#">اینجا </a> کلیک کنید</span>
                      </div>
                      <div class="card-body">
                       <form class="form-space theme-form row" action="/guideType/admin/edit/<%= guideType._id %>" method="post">
                          <div class="col-sm-6">
                            <label class="form-label"> نام دسته بندی</label>
                            <input class="form-control" name="Name" id="Name" type="text" placeholder="نام دسته بندی" required value="<%= guideType.Name %>">
                          </div>

                          <div class="col-sm-6">
                              <label class="form-label">URL</label>
                            <input class="form-control" name="Url" id="Url" type="text" placeholder="URL" required value="<%= guideType.Url %>">
                          </div>

                          <div class="col-sm-6">
                            <label class="form-label">توضیحات</label>
                            <input class="form-control" name="Caption" id="Caption" type="text" placeholder="توضیحات" value="<%= guideType.Caption %>" required>
                          </div>
                          <div class="col-sm-6">
                              <label class="form-label"> نوع نمایش</label>
                          <select  name="Parts" id="Parts" class="form-select form-control-lg">
                            <option value="0">داخلی</option>
                            <option value="1">نمایش عمومی</option>
                          </select>
                      </div>

                      <div class="col-sm-6">
                          <label class="form-label"> دسته بندی پیش فرض </label>
                          <select  name="Default" id="Default" class="form-select form-control-lg">
                            <option value="0"> دسته بندی پیش فرض نیست</option>
                            <option value="1">دسته بندی پیش فرض هست</option>
                          </select>
                      </div>

                         <div class="col-sm-3">
                           <a href="#" class="btn btn-info" data-bs-toggle="modal" data-bs-target="#printModal">انتخاب تصاویر</a>
                         </div>
                         <div id="AlbumFiles">
                           <% for(var i=0; i < guideType.Files.length; i++) { %>
                            <% if(guideType.Files[i].Url !== "default") { %>
                             <% if(guideType.Files[i].Type == 0) { %>
                               <div id="<%= guideType.Files[i]._id %>" class="profile-mail m-2 p-0" style="width: 15%; max-height: 75px; display: inline-block;">
                                 <input type="text" name="Files" id="Files" class="d-none" value="<%= guideType.Files[i]._id %>" />
                                 <img style="width: 100%; " src="/assets/file/album/<%= guideType.Files[i].Url %>/<%= guideType.Files[i].Name %>">
                                 <button class="btn btn-info img-tag m-2" data-file-url="<%= guideType.Files[i].Url %>" data-file-name="<%= guideType.Files[i].Name %>" type="button" onclick="copyText(this)" name="button">کپی لینک</button>
                               </div>
                             <% } else if(guideType.Files[i].Type == 1){ %>
                               <div id="<%= guideType.Files[i]._id %>" class="profile-mail m-2 p-0" style="width: 15%; max-height: 75px; display: inline-block;">
                                 <input type="text" name="Files" id="Files" class="d-none" value="<%= guideType.Files[i]._id %>" />
                                 <video src="/assets/file/album/<%= guideType.Files[i].Url %>/<%= guideType.Files[i].Name %>"></video>
                                 <button class="btn btn-info img-tag m-2" data-file-url="<%= guideType.Files[i].Url %>" data-file-name="<%= guideType.Files[i].Name %>" type="button" onclick="copyText(this)" name="button">کپی لینک</button>
                               </div>
                             <% } %>
                            <% } %>
                           <% } %>
                         </div>

                         <div class="card-footer text-end">
                        <button class="btn btn-primary" type="submit">ثبت دسته بندی</button>
                        <a href="/guideType/admin/list" class="btn btn-secondary">بازگشت</a>
                        <a href="/guideType/admin/list" class="btn btn-success">مشاهده دسته‌بندی آموزش ها</a>
                      </div>

                        </form>
                      </div>

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


          </div>

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

          <!-- Container-fluid Ends-->
        </div>
        <!-- popup -->
        <div class="modal fade modal-bookmark" id="printModal" tabindex="-1" role="dialog" aria-hidden="true">
          <div class="modal-dialog modal-dialog-centered" role="document">
            <div class="modal-content">
              <div class="modal-header">
                <h5 class="modal-title">انتخاب عکس</h5>
                <button class="btn-close" type="button" data-bs-dismiss="modal" aria-label="Close"></button>
              </div>

              <div class="modal-body list-persons" id="showAlbums">
                <% for(var i=0; i < albums.length; i++) { %>
                  <div class="profile-mail pt-0" id="DivIdToPrint" style="width: 15%; display: inline-block;">
                    <div class="media">
                      <div onclick="showSubAlbums(this)" data-id="<%= albums[i]._id %>" data-parent="<%= albums[i].Parent %>">
                        <img class="img-fluid" src="/assets/img/image/video-file.png" alt="">
                      </div>

                      <div class="media-body mt-0 text-center">
                        <p class="m-0"><%= albums[i].Name %></p>
                      </div>
                    </div>

                  </div>
                <% } %>
              </div>
            </div>
          </div>
        </div>
        <!-- popup-->
        <!-- 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-->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/axios/0.19.0/axios.min.js"></script>
    <!-- Plugin used-->

    <script>
      var albumFilesData = []
      function showSubAlbums(albums) {
        console.log(albums)
        console.log(albums.getAttribute("data-id"))

        var album = albums.getAttribute("data-id")
        var albumParent = albums.getAttribute("data-parent")

        axios
                .get('/guidetype/admin/file/<%= guideType._id %>')
                .then((resp) => {
                  var currentFiles = resp.data.files

                  axios
                          .get('/album/admin/getsubalbums/' + album)
                          .then((res) => {
                            console.log(res.data)
                            albumFilesData = res.data.files
                            console.log("albumFilesData")
                            console.log(albumFilesData)
                            $("#showAlbums").empty()
                            for(var i=0; i < res.data.albums.length; i++) {
                              console.log("hi")
                              console.log(res.data.albums[i])
                              $('#showAlbums').append('<div class="profile-mail pt-0" id="DivIdToPrint" style="width: 15%; display: inline-block;"><div class="media"><div onclick="showSubAlbums(this)" data-id="'+ res.data.albums[i]._id +'"><img class="img-fluid" src="/assets/img/image/video-file.png" alt=""></div><div class="media-body mt-0 text-center"> <p class="m-0">'+ res.data.albums[i].Name +'</p></div></div></div>')
                            }
                            for(var i=0; i < res.data.files.length; i++) {
                              if(currentFiles.includes(res.data.files[i]._id)) {
                                console.log("has")
                                if(res.data.files[i].Type == 0) {
                                  $('#showAlbums').append('<div onclick="selectFile(this)" data-id="'+ i +'" class="profile-mail m-2 p-0 fileslist activefile" style="width: 15%; max-height: 75px; display: inline-block;"><img style="width: 100%; " src="/assets/file/album/'+ res.data.files[i].Url +'/'+ res.data.files[i].Name +'"></div>')
                                } else if(res.data.files[i].Type == 1) {
                                  $('#showAlbums').append('<div onclick="selectFile(this)" data-id="'+ i +'" class="profile-mail m-2 p-0 fileslist activefile" style="width: 15%; max-height: 75px; display: inline-block;"><video style="width: 100%; " src="/assets/file/album/'+ res.data.files[i].Url +'/'+ res.data.files[i].Name +'"></video></div>')
                                }
                              } else {
                                console.log('has not')
                                if(res.data.files[i].Type == 0) {
                                  $('#showAlbums').append('<div onclick="selectFile(this)" data-id="'+ i +'" class="profile-mail m-2 p-0 fileslist" style="width: 15%; max-height: 75px; display: inline-block;"><img style="width: 100%; " src="/assets/file/album/'+ res.data.files[i].Url +'/'+ res.data.files[i].Name +'"></div>')
                                } else if(res.data.files[i].Type == 1) {
                                  $('#showAlbums').append('<div onclick="selectFile(this)" data-id="'+ i +'" class="profile-mail m-2 p-0 fileslist" style="width: 15%; max-height: 75px; display: inline-block;"><video style="width: 100%; " src="/assets/file/album/'+ res.data.files[i].Url +'/'+ res.data.files[i].Name +'"></video></div>')
                                }
                              }
                            }
                            // $('#showAlbums').append('<button class="btn btn-primary d-block" onclick="returnfunction('+ albumParent +')" type="button" data-bs-dismiss="modal">بازگشت</button>')
                          })

                })

      }

      function selectFile(files){
        console.log(files)
        console.log(files.classList.contains("activefile"))
        var index = files.getAttribute("data-id")

        if(files.classList.contains("activefile")) {
          console.log("have class")
          files.classList.remove("activefile")
          $("#" + albumFilesData[index]._id).remove()
        } else {
          files.classList.add("activefile")

          if(albumFilesData[index].Type == 0) {
            $('#AlbumFiles').append('<div id="'+ albumFilesData[index]._id +'" class="profile-mail m-2 p-0" style="width: 15%; max-height: 75px; display: inline-block;"><input type="text" name="Files" id="Files" class="d-none" value="'+ albumFilesData[index]._id +'" /><img style="width: 100%; " src="/assets/file/album/'+ albumFilesData[index].Url +'/'+ albumFilesData[index].Name +'"><button class="btn btn-info img-tag m-2" data-file-url="'+ albumFilesData[index].Url +'" data-file-name="'+ albumFilesData[index].Name +'" type="button" onclick="copyText(this)" name="button">کپی لینک</button></div>')
          } else if(albumFilesData[index].Type == 1){
            $('#AlbumFiles').append('<div id="'+ albumFilesData[index]._id +'" class="profile-mail m-2 p-0" style="width: 15%; max-height: 75px; display: inline-block;"><input type="text" name="Files" id="Files" class="d-none" value="'+ albumFilesData[index]._id +'" /><video style="width: 100%; " src="/assets/file/album/'+ albumFilesData[index].Url +'/'+ albumFilesData[index].Name +'"></video><button class="btn btn-info img-tag m-2" data-file-url="'+ albumFilesData[index].Url +'" data-file-name="'+ albumFilesData[index].Name +'" type="button" onclick="copyText(this)" name="button">کپی لینک</button></div>')
          }
        }

      }

      function copyText(copybtn){
        console.log("copybtn")
        console.log(copybtn);

        var fileUrl = copybtn.getAttribute("data-file-url");
        var fileName = copybtn.getAttribute("data-file-name");

        console.log("fileUrl")
        console.log(fileUrl)

        console.log("fileName")
        console.log(fileName)

        var url = "/assets/file/album/"+ fileUrl +"/" + fileName;
        navigator.clipboard.writeText(url);
        alert("متن کپی شد!");
      }

    </script>

  </body>
</html>
