@if (!Auth::check())
<script>
    window.location = "{{ url('sign-in') }}"
</script>
@endif

    <!DOCTYPE html>
    <html lang="en" style="user-select: none">

    <head>

        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <!-- Primary Meta Tags -->
        <title>Dashboard - DriveTest</title>
        <meta name="msapplication-TileColor" content="#ffffff">
        <meta name="theme-color" content="#ffffff">
        <link rel="shortcut icon" href="{{ asset('assets/images/fav-icon.png') }}">
        <!-- Volt CSS -->
        <link type="text/css" href="{{ asset('admin/css/volt.css') }}" rel="stylesheet">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
        <style>
        .disabledValue{
            background: transparent;
            border: 0px;
            outline: 0;
        }
        </style>
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.0/css/all.min.css" integrity="sha512-iecdLmaskl7CVkqkXNQ/ZH/XLlvWZOJyj7Yy7tcenmpD1ypASozpmT/E0iPtmFIB46ZmdtAc9eNBvH0H/ZpiBw==" crossorigin="anonymous" referrerpolicy="no-referrer" />
        <script>
            let usrstctions = "admin";
        </script>
            <script>
    function preventCopy(event) {
    //   alert('Copying is disabled in Restricted Mode.');
      event.preventDefault();
    }

    // Attach the event handler to the "copy" event on the entire document
    document.addEventListener('copy', preventCopy);
</script>
                <style>
                body{
                    user-select: none; /* This CSS property disables text selection in modern browsers */
      -webkit-user-select: none; /* For Safari */
      -moz-user-select: none; /* For Firefox */
      -ms-user-select: none; /* For Internet Explorer/Edge */
                }
                    .clockdate-wrapper{
            background-color: #223E7B;
            padding:10px;
            width:210px;
            text-align:center;
            border-radius:5px;
            margin:0 auto;
            position: fixed;
            bottom: 70px;
            pointer-events: none;
        }
        #clock{
            background-color:#223E7B;
            font-family: sans-serif;
            font-size:30px;
            text-shadow:0px 0px 1px #fff;
            color:#fff;
            
        }
        #clock span {
            color:#92b5ff;
            text-shadow:0px 0px 1px rgb(119, 119, 119);
            font-size:20px;
            position:relative;
        }
        #date {
            letter-spacing:3px;
            font-size:14px;
            font-family:arial,sans-serif;
            color:#fff;
        }
        input.disabledValue[type=text]{
            background: #223d7a;
            color: #fff;
        }
                </style>
    </head>

    <body>
        <!-- NOTICE: You can use the _analytics.html partial to include production code specific code & trackers -->

        <nav class="navbar navbar-dark navbar-theme-primary px-4 col-12 d-lg-none">
            <a class="navbar-brand me-lg-5" href="{{ url('/') }}">
                <img class="navbar-brand-dark" src="{{ asset('assets/images/fav-icon.png') }}" alt="DriveTest" /> <img
                    class="navbar-brand-light" src="{{ asset('assets/images/fav-icon.png') }}" alt="DriveTest" />
            </a>
            
            <div class="d-flex align-items-center">
                <button class="navbar-toggler d-lg-none collapsed" type="button" data-bs-toggle="collapse"
                    data-bs-target="#sidebarMenu" aria-controls="sidebarMenu" aria-expanded="false"
                    aria-label="Toggle navigation">
                    <span class="navbar-toggler-icon"></span>
                </button>
            </div>
        </nav>

        <nav id="sidebarMenu" class="sidebar d-lg-block bg-gray-800 text-white collapse" data-simplebar>
            <div class="sidebar-inner px-4 pt-3">
                <div
                    class="user-card d-flex d-md-none align-items-center justify-content-between justify-content-md-center pb-4">
                    <div class="d-flex align-items-center">
                        <div class="avatar-lg me-4">
                            <img src="/admin/img/team/profile-picture-3.jpg"
                                class="card-img-top rounded-circle border-white" alt="Bonnie Green">
                        </div>
                        <div class="d-block">
                            <h2 class="h5 mb-3">Hi, Jane</h2>
                            <a href="pages/examples/sign-in.html"
                                class="btn btn-secondary btn-sm d-inline-flex align-items-center">
                                <svg class="icon icon-xxs me-1" fill="none" stroke="currentColor" viewBox="0 0 24 24"
                                    xmlns="http://www.w3.org/2000/svg">
                                    <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
                                        d="M17 16l4-4m0 0l-4-4m4 4H7m6 4v1a3 3 0 01-3 3H6a3 3 0 01-3-3V7a3 3 0 013-3h4a3 3 0 013 3v1">
                                    </path>
                                </svg>
                                Sign Out
                            </a>
                        </div>
                    </div>
                    <div class="collapse-close d-md-none">
                        <a href="#sidebarMenu" data-bs-toggle="collapse" data-bs-target="#sidebarMenu"
                            aria-controls="sidebarMenu" aria-expanded="true" aria-label="Toggle navigation">
                            <svg class="icon icon-xs" fill="currentColor" viewBox="0 0 20 20"
                                xmlns="http://www.w3.org/2000/svg">
                                <path fill-rule="evenodd"
                                    d="M4.293 4.293a1 1 0 011.414 0L10 8.586l4.293-4.293a1 1 0 111.414 1.414L11.414 10l4.293 4.293a1 1 0 01-1.414 1.414L10 11.414l-4.293 4.293a1 1 0 01-1.414-1.414L8.586 10 4.293 5.707a1 1 0 010-1.414z"
                                    clip-rule="evenodd"></path>
                            </svg>
                        </a>
                    </div>
                </div>
                <ul class="nav flex-column pt-3 pt-md-0">
                    <li class="nav-item" style="pointer-events: none">
                        <a href="{{session('userid') == 1 ? url('/folders') : url('sheets') }}" class="nav-link d-flex align-items-center">
                            <span class="sidebar-icon text-center">
                                <img src="{{asset('logo.svg')}}" width="80%" alt="Volt Logo">
                            </span>
                            {{-- <span class="mt-1 ms-1 sidebar-text">DriveTest</span> --}}
                        </a>
                        <a href="" class="nav-link text-center py-1" style="background-color: #223d7a;">

                            <span class="mt-1 ms-1 sidebar-text" style="font-size: 20px">{{Session::get('user_department')}}</span>
                        </a>
                    </li>
                    <li class="nav-item mt-4">
                        <a href="{{session('userid') == 1 ? url('/folders') : url('sheets') }}" class="nav-link">
                            <span class="sidebar-icon">
                                <svg class="icon icon-xs me-2" fill="currentColor" viewBox="0 0 20 20"
                                    xmlns="http://www.w3.org/2000/svg">
                                    <path d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z"></path>
                                    <path fill-rule="evenodd"
                                        d="M4 5a2 2 0 012-2 3 3 0 003 3h2a3 3 0 003-3 2 2 0 012 2v11a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm3 4a1 1 0 000 2h.01a1 1 0 100-2H7zm3 0a1 1 0 000 2h3a1 1 0 100-2h-3zm-3 4a1 1 0 100 2h.01a1 1 0 100-2H7zm3 0a1 1 0 100 2h3a1 1 0 100-2h-3z"
                                        clip-rule="evenodd"></path>
                                </svg>
                            </span>
                            <span class="sidebar-text">{{session('userid') == 1 ? 'Home' : 'All Sheets' }}</span>
                        </a>
                    </li>
                    @if(session('userid') == 1)
                    <li class="nav-item">
                        <a href="{{ url('users') }}" class="nav-link">
                            <span class="sidebar-icon">
                                <svg class="icon icon-xs me-2" fill="currentColor" viewBox="0 0 20 20"
                                    xmlns="http://www.w3.org/2000/svg">
                                    <path d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z"></path>
                                    <path fill-rule="evenodd"
                                        d="M4 5a2 2 0 012-2 3 3 0 003 3h2a3 3 0 003-3 2 2 0 012 2v11a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm3 4a1 1 0 000 2h.01a1 1 0 100-2H7zm3 0a1 1 0 000 2h3a1 1 0 100-2h-3zm-3 4a1 1 0 100 2h.01a1 1 0 100-2H7zm3 0a1 1 0 100 2h3a1 1 0 100-2h-3z"
                                        clip-rule="evenodd"></path>
                                </svg>
                            </span>
                            <span class="sidebar-text">Users</span>
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('login-histories') }}" class="nav-link">
                            <span class="sidebar-icon">
                                <svg class="icon icon-xs me-2" fill="currentColor" viewBox="0 0 20 20"
                                    xmlns="http://www.w3.org/2000/svg">
                                    <path d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z"></path>
                                    <path fill-rule="evenodd"
                                        d="M4 5a2 2 0 012-2 3 3 0 003 3h2a3 3 0 003-3 2 2 0 012 2v11a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm3 4a1 1 0 000 2h.01a1 1 0 100-2H7zm3 0a1 1 0 000 2h3a1 1 0 100-2h-3zm-3 4a1 1 0 100 2h.01a1 1 0 100-2H7zm3 0a1 1 0 100 2h3a1 1 0 100-2h-3z"
                                        clip-rule="evenodd"></path>
                                </svg>
                            </span>
                            <span class="sidebar-text">Login History</span>
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('ips') }}" class="nav-link">
                            <span class="sidebar-icon">
                                <svg class="icon icon-xs me-2" fill="currentColor" viewBox="0 0 20 20"
                                    xmlns="http://www.w3.org/2000/svg">
                                    <path d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z"></path>
                                    <path fill-rule="evenodd"
                                        d="M4 5a2 2 0 012-2 3 3 0 003 3h2a3 3 0 003-3 2 2 0 012 2v11a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm3 4a1 1 0 000 2h.01a1 1 0 100-2H7zm3 0a1 1 0 000 2h3a1 1 0 100-2h-3zm-3 4a1 1 0 100 2h.01a1 1 0 100-2H7zm3 0a1 1 0 100 2h3a1 1 0 100-2h-3z"
                                        clip-rule="evenodd"></path>
                                </svg>
                            </span>
                            <span class="sidebar-text">IP Configuration</span>
                        </a>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('drive-configuration') }}" class="nav-link">
                            <span class="sidebar-icon">
                                <svg class="icon icon-xs me-2" fill="currentColor" viewBox="0 0 20 20"
                                    xmlns="http://www.w3.org/2000/svg">
                                    <path d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z"></path>
                                    <path fill-rule="evenodd"
                                        d="M4 5a2 2 0 012-2 3 3 0 003 3h2a3 3 0 003-3 2 2 0 012 2v11a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm3 4a1 1 0 000 2h.01a1 1 0 100-2H7zm3 0a1 1 0 000 2h3a1 1 0 100-2h-3zm-3 4a1 1 0 100 2h.01a1 1 0 100-2H7zm3 0a1 1 0 100 2h3a1 1 0 100-2h-3z"
                                        clip-rule="evenodd"></path>
                                </svg>
                            </span>
                            <span class="sidebar-text">Drive Configuration</span>
                        </a>
                    </li>
                    @endif
                    <li class="nav-item">
                    
                    </li>
                    <li role="separator" class="dropdown-divider mt-4 mb-3 border-gray-700"></li>
                    <!--<li class="nav-item">-->
                    <!--    <a href="https://docs.google.com/spreadsheets/d/10AHFMKZEXG5JdXVTngxGPGRtxkEQtitbgIV-wkA1cjo/edit?usp=sharing" class="nav-link">-->
                    <!--        <span class="sidebar-icon">-->
                    <!--            <svg class="icon icon-xs me-2" fill="currentColor" viewBox="0 0 20 20"-->
                    <!--                xmlns="http://www.w3.org/2000/svg">-->
                    <!--                <path d="M9 2a1 1 0 000 2h2a1 1 0 100-2H9z"></path>-->
                    <!--                <path fill-rule="evenodd"-->
                    <!--                    d="M4 5a2 2 0 012-2 3 3 0 003 3h2a3 3 0 003-3 2 2 0 012 2v11a2 2 0 01-2 2H6a2 2 0 01-2-2V5zm3 4a1 1 0 000 2h.01a1 1 0 100-2H7zm3 0a1 1 0 000 2h3a1 1 0 100-2h-3zm-3 4a1 1 0 100 2h.01a1 1 0 100-2H7zm3 0a1 1 0 100 2h3a1 1 0 100-2h-3z"-->
                    <!--                    clip-rule="evenodd"></path>-->
                    <!--            </svg>-->
                    <!--        </span>-->
                    <!--        <span class="sidebar-text" >Get Standard Sheet</span>-->
                    <!--    </a>-->
                    <!--</li>-->
                    <li class="nav-item">
                        <div id="clockdate">
                            <div class="clockdate-wrapper">
                              <div id="clock"></div>
                              <div id="date"></div>
                            </div>
                          </div>
                    </li>
                    <li class="nav-item">
                        <a href="{{ url('logout') }}"
                            class="btn btn-secondary d-flex align-items-center justify-content-center btn-upgrade-pro">
                            <span class="sidebar-icon d-inline-flex align-items-center justify-content-center">
                                <svg xmlns="http://www.w3.org/2000/svg" version="1.1"
                                    xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs"
                                    width="15" height="15" x="0" y="0" viewBox="0 0 24 24"
                                    style="enable-background:new 0 0 512 512" xml:space="preserve" class="me-2">
                                    <g>
                                        <g>
                                            <path
                                                d="m15 13c-.553 0-1 .448-1 1v4c0 .551-.448 1-1 1h-3v-15c0-.854-.544-1.617-1.362-1.901l-.296-.099h4.658c.552 0 1 .449 1 1v3c0 .552.447 1 1 1s1-.448 1-1v-3c0-1.654-1.346-3-3-3h-10.75c-.038 0-.07.017-.107.022-.048-.004-.094-.022-.143-.022-1.103 0-2 .897-2 2v18c0 .854.544 1.617 1.362 1.901l6.018 2.006c.204.063.407.093.62.093 1.103 0 2-.897 2-2v-1h3c1.654 0 3-1.346 3-3v-4c0-.552-.447-1-1-1z"
                                                fill="#fff" data-original="#fff"></path>
                                            <path
                                                d="m23.707 9.293-4-4c-.286-.286-.716-.372-1.09-.217-.373.155-.617.52-.617.924v3h-4c-.552 0-1 .448-1 1s.448 1 1 1h4v3c0 .404.244.769.617.924.374.155.804.069 1.09-.217l4-4c.391-.391.391-1.023 0-1.414z"
                                                fill="#fff" data-original="#fff"></path>
                                        </g>
                                    </g>
                                </svg>
                            </span>
                            <span>Sign Out</span>
                        </a>
                    </li>
                </ul>
            </div>
        </nav>
        <main class="content">

            <nav class="navbar navbar-top navbar-expand navbar-dashboard navbar-dark ps-0 pe-2 pb-0">
                <div class="container-fluid px-0">
                    <div class="d-flex justify-content-between w-100" id="navbarSupportedContent">
                        <div class="d-flex align-items-center">

                        </div>

                    </div>
                </div>
            </nav>
            <a href="{{url()->current()}}" class="rounded-pill mb-2 p-0 px-2 py-1 btn btn-secondary text-dark btn-sm me-2"><svg xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" width="20" height="20" x="0" y="0" viewBox="0 0 24 24" style="enable-background:new 0 0 512 512" xml:space="preserve" class=""><g><path d="M19.602 12.635a.99.99 0 0 0-1.134.844 6.402 6.402 0 0 1-1.83 3.618 6.506 6.506 0 0 1-9.192 0 6.507 6.507 0 0 1 0-9.192 6.414 6.414 0 0 1 3.503-1.8 6.187 6.187 0 0 1 1.848-.055 6.414 6.414 0 0 1 2.466.828l-1.302.223a1 1 0 1 0 .338 1.971l3.49-.596a1.002 1.002 0 0 0 .816-1.155l-.597-3.49a1 1 0 1 0-1.97.338l.156.919a8.423 8.423 0 0 0-3.17-1.025 8.102 8.102 0 0 0-2.428.074 8.379 8.379 0 0 0-4.564 2.354c-3.313 3.314-3.313 8.705 0 12.02a8.471 8.471 0 0 0 6.01 2.485 8.471 8.471 0 0 0 6.01-2.485 8.39 8.39 0 0 0 2.394-4.741 1 1 0 0 0-.843-1.135z" fill="#fff" data-original="#fff" class=""></path></g></svg> Refresh</a>
            @yield('content')

        </main>
        <!-- Core -->
        <script src="{{ asset('admin/vendor/@popperjs/core/dist/umd/popper.min.js') }}"></script>
        <script src="{{ asset('admin/vendor/bootstrap/dist/js/bootstrap.min.js') }}"></script>

        <!-- Volt JS -->
        <script src="{{ asset('admin/js/volt.js') }}"></script>
        
<script>
        $(window).on('load',function(){
        return startTime();
    })
    function startTime() {
    var today = new Date();
    var hr = today.getHours();
    var min = today.getMinutes();
    var sec = today.getSeconds();
    ap = (hr < 12) ? "<span>AM</span>" : "<span>PM</span>";
    hr = (hr == 0) ? 12 : hr;
    hr = (hr > 12) ? hr - 12 : hr;
    //Add a zero in front of numbers<10
    hr = checkTime(hr);
    min = checkTime(min);
    sec = checkTime(sec);
    document.getElementById("clock").innerHTML = hr + ":" + min + ":" + sec + " " + ap;
    
    var months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
    var days = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
    var curWeekDay = days[today.getDay()];
    var curDay = today.getDate();
    var curMonth = months[today.getMonth()];
    var curYear = today.getFullYear();
    var date = curWeekDay+", "+curDay+" "+curMonth+" "+curYear;
    document.getElementById("date").innerHTML = date;
    
    var time = setTimeout(function(){ startTime() }, 500);
}
function checkTime(i) {
    if (i < 10) {
        i = "0" + i;
    }
    return i;
}
    // disable right click
    document.addEventListener('contextmenu', event => event.preventDefault());

window.addEventListener("keydown", (e) => {
        if(e.keyCode == 123) {
           
            return false;
        }

        if(e.ctrlKey && e.shiftKey && e.keyCode == 73){
            
            return false;
        }

        if(e.ctrlKey && e.shiftKey && e.keyCode == 74) {
            
            return false;
        }

        if(e.ctrlKey && e.keyCode == 85) {
            
            return false;
        }
    })
</script>

<script>
//    !function() {
// 	function detectDevTool(allow) {
//   	if(isNaN(+allow)) allow = 100;
//     var start = +new Date();
//     debugger;
//     var end = +new Date();
//     if(isNaN(start) || isNaN(end) || end - start > allow) {
//     	alert('DEVTOOLS detected. all operations will be terminated.');
//         window.location="{{url('logout')}}";
//     }
//   }
//   if(window.attachEvent) {
//   	if (document.readyState === "complete" || document.readyState === "interactive") {
//     	detectDevTool();
//       window.attachEvent('onresize', detectDevTool);
//       window.attachEvent('onmousemove', detectDevTool);
//       window.attachEvent('onfocus', detectDevTool);
//       window.attachEvent('onblur', detectDevTool);
//     } else {
//     	setTimeout(argument.callee, 0);
//     }
//   } else {
//   	window.addEventListener('load', detectDevTool);
//     window.addEventListener('resize', detectDevTool);
//     window.addEventListener('mousemove', detectDevTool);
//     window.addEventListener('focus', detectDevTool);
//     window.addEventListener('blur', detectDevTool);
//   }
// }();
$(document).ready(function(){
    $('.userUnableDisable').on('change',function(){
        let ildibs = $(this).val();
        $.ajax({
        type: 'post',
        url: '{{ url('iurtifjfnvmncxlkj') }}',
        data: { 'jhncxkdhfk': ildibs, '_token': '{{ csrf_token() }}'},
        success: function(data) {
           
        }
    })
    })
    setInterval(function(){ 
        $.ajax({
        type: 'post',
        url: '{{ url('logout_check_time') }}',
        data: {'_token': '{{ csrf_token() }}'},
    })
    }, 15000);
})
</script>
@php
    $data = App\Models\Deploy::firstWhere('id', 1);
@endphp
        <script>

            var script_url = "{{$data->deploys_url}}";
            var sheetid = sheetId;
            var sheetName = 'Sheet1';
            const googlesheeticon =
                '<svg style="margin-right:10px" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svgjs="http://svgjs.com/svgjs" width="20" x="0" y="0" viewBox="0 0 510 510" style="enable-background:new 0 0 512 512" xml:space="preserve" class=""><g><linearGradient id="SVGID_1_" gradientUnits="userSpaceOnUse" x1="157.153" x2="399.748" y1="198.847" y2="441.441"><stop offset="0" stop-color="#7faef4"></stop><stop offset="1" stop-color="#4c8df1"></stop></linearGradient><linearGradient id="lg1"><stop offset="0" stop-color="#4c8df1" stop-opacity="0"></stop><stop offset="1" stop-color="#4256ac"></stop></linearGradient><linearGradient id="SVGID_2_" gradientUnits="userSpaceOnUse" x1="410.106" x2="371.606" xlink:href="#lg1" y1="173.728" y2="61.228"></linearGradient><linearGradient id="SVGID_3_" gradientUnits="userSpaceOnUse" x1="343.272" x2="387.993" y1="58.728" y2="103.45"><stop offset="0" stop-color="#a7c5fd"></stop><stop offset="1" stop-color="#7faef4"></stop></linearGradient><linearGradient id="SVGID_4_" gradientTransform="matrix(-1 0 0 1 1574 0)" gradientUnits="userSpaceOnUse" x1="1319" x2="1319" xlink:href="#lg1" y1="463.7" y2="513.288"></linearGradient><g><path d="m68.17 31.88v446.25c0 17.529 14.341 31.87 31.87 31.87h309.91c17.534 0 31.88-14.346 31.88-31.88v-360.725c0-9.787-3.888-19.173-10.808-26.094l-80.493-80.493c-6.921-6.92-16.307-10.808-26.094-10.808h-224.385c-17.534 0-31.88 14.346-31.88 31.88z" fill="url(#SVGID_1_)" data-original="url(#SVGID_1_)"></path><g><g><g><g><path d="m153.111 246.041h203.778c5.079 0 9.196-4.117 9.196-9.196v-22.425c0-5.079-4.117-9.196-9.196-9.196h-203.778c-5.079 0-9.196 4.117-9.196 9.196v22.425c0 5.079 4.117 9.196 9.196 9.196z" fill="#ebeff0" data-original="#ebeff0"></path></g></g></g><g><g><g><path d="m153.111 309.756h203.778c5.079 0 9.196-4.117 9.196-9.196v-22.425c0-5.079-4.117-9.196-9.196-9.196h-203.778c-5.079 0-9.196 4.117-9.196 9.196v22.425c0 5.079 4.117 9.196 9.196 9.196z" fill="#ebeff0" data-original="#ebeff0"></path></g></g></g><g><g><g><path d="m153.111 373.47h203.778c5.079 0 9.196-4.117 9.196-9.196v-22.424c0-5.079-4.117-9.196-9.196-9.196h-203.778c-5.079 0-9.196 4.117-9.196 9.196v22.425c0 5.078 4.117 9.195 9.196 9.195z" fill="#ebeff0" data-original="#ebeff0"></path></g></g></g><g><g><g><path d="m150.573 437.185h103.155c3.677 0 6.658-2.981 6.658-6.658v-27.5c0-3.677-2.981-6.658-6.658-6.658h-103.155c-3.677 0-6.658 2.981-6.658 6.658v27.5c0 3.677 2.981 6.658 6.658 6.658z" fill="#ebeff0" data-original="#ebeff0"></path></g></g></g></g><path d="m350.528 10.808c-4.74-4.74-10.638-8.056-17.028-9.676v103.922l108.33 108.33v-95.99c0-9.787-3.888-19.173-10.808-26.094z" fill="url(#SVGID_2_)" data-original="url(#SVGID_2_)"></path><path d="m440.737 108.443c.118.512.227 1.011.326 1.492h-97.648c-6.914 0-12.52-5.605-12.52-12.52v-96.834c.763.136 1.565.295 2.392.478 7.279 1.61 13.916 5.353 19.188 10.624l77.655 77.655c5.251 5.251 8.938 11.87 10.607 19.105z" fill="url(#SVGID_3_)" data-original="url(#SVGID_3_)"></path><path d="m441.83 447.201v30.919c0 17.534-14.346 31.88-31.88 31.88h-309.91c-17.529 0-31.87-14.342-31.87-31.87v-30.929z" fill="url(#SVGID_4_)" data-original="url(#SVGID_4_)"></path></g></g></svg>';
            
            // print the returned data
            function ctrlq(e) {
                $("#re").html(e.result);
                $("#re").css("visibility", "visible");
            }
            const arrayfromkey = [];
            let updatecheck = '';
            
            $(window).on('load', function() {
                return showData();
            });
            function showData() {
                let idinc = '';
                $('#showData table thead tr').text('');
                // $('#showData table tbody').text('');
                $("#re").css("visibility", "hidden");

                var url = script_url + "?action=read&sheetid=" + sheetid + "&sheetName=" + sheetName + "";

                $.getJSON(url, function(json) {

                    json.records.forEach(async function(e) {
                        await Object.keys(e).map(el => {
                            if (!(arrayfromkey.includes(el))) {
                                arrayfromkey.push(el)
                            }
                        })
                    })
                    if(usrstctions !== 'insert' && usrstctions !== 'view'){
                        arrayfromkey.push('Action');
                    }
                    $('form#insert').text('');
                    arrayfromkey.map((e, i) => {
                        $('#showData table thead tr').append(`<th scope="col">${e}</th>`)

                    })
                    let objectList = [...Array(json.records.length)];
                    
                    const selectElement = $('#objectCategories');
                  
                    
                  
                      $(selectElement).html('')
                      const minValue = Math.min(...objectList.map((_, obj) => obj));
                      const maxValue = Math.max(...objectList.map((_, obj) => obj));
                    
                      const rangeSize = 100;
                      const numCategories = Math.ceil((maxValue - minValue) / rangeSize);
                    
                    
                      for (let i = 0; i < numCategories; i++) {
                        const minRange = minValue + i * rangeSize;
                        const maxRange = Math.min(minRange + rangeSize, maxValue+1);
                    
                    
                        const optionElement = document.createElement('option');
                        optionElement.value = `${minRange}-${maxRange}`;
                        optionElement.textContent = `${minRange}-${maxRange}`;
                        $(selectElement).append(optionElement);
                      }

                         let vll = "0-100"

                        $(selectElement).on('change', function(){
                        let valueSelect = $(this).val();
                            vll = valueSelect 
                             let zz = [...json.records]
                            return ll(zz)
                        })
                        
                        
                        
                        function cutData(array, startIndex, lastIndex) {
                          
                              if (startIndex < 0) {
                                startIndex = 0;
                              }
                              if (lastIndex >= array.length) {
                                lastIndex = array.length - 1;
                              }
                            
                             
                              return array.slice(startIndex, lastIndex + 1);
                            }

                   
                        function ll(xp = [...json.records]){
                          const newArray = [...xp]
                          $('.typewriter').remove();
                            $('#showData table tbody').html('')
                       cutData(xp,Number(vll.split("-")[0]),Number(vll.split("-")[1])).forEach(function(e, i) {

                        $('#showData table tbody').append(`<tr data-row="${i}" class="row_${i}"></tr>`)
                        let sdksd = 1;

                        var last = Object.keys(e)[Object.keys(e).length - 1];

                        $.each(e, function(key, value) {
                            let mcvnkfh = `contenteditable = ${e != 'id'? 'true': 'false' }`;
                            if (key == 'id') {
                                idinc = value;
                                mcvnkfh = '';
                            }
                            $(`#showData table tbody tr.row_${i}`).append(
                                `<td data-columnRange="${sdksd}" data-columnName="${key}" data-id="${idinc}" ${usrstctions !== 'insert' && usrstctions !== 'view' && usrstctions !== 'delete' ? mcvnkfh : ''}  class="${key != 'id'? 'changingElements': '' }">${usrstctions == 'view' && usrstctions == 'delete' ? key.toLowerCase() === "email" || key.toLowerCase() === "phone" ? `<input class="disabledValue" readonly type="password" value="${value}"><i class="fa-solid fa-eye showSiblingData" style="cursor:pointer;"></i>` : value : value}</td>${last == key && usrstctions !== 'insert' && usrstctions !== 'view'? '<td data-columnRange="'+sdksd+'" data-id="'+idinc+'" class="text-center"><svg width="15" class="deleteRow" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 105.7 122.88"><title>Delete This Row</title><path d="M30.46,14.57V5.22A5.18,5.18,0,0,1,32,1.55v0A5.19,5.19,0,0,1,35.68,0H70a5.22,5.22,0,0,1,3.67,1.53l0,0a5.22,5.22,0,0,1,1.53,3.67v9.35h27.08a3.36,3.36,0,0,1,3.38,3.37V29.58A3.38,3.38,0,0,1,102.32,33H98.51l-8.3,87.22a3,3,0,0,1-2.95,2.69H18.43a3,3,0,0,1-3-2.95L7.19,33H3.37A3.38,3.38,0,0,1,0,29.58V17.94a3.36,3.36,0,0,1,3.37-3.37Zm36.27,0V8.51H39v6.06ZM49.48,49.25a3.4,3.4,0,0,1,6.8,0v51.81a3.4,3.4,0,1,1-6.8,0V49.25ZM69.59,49a3.4,3.4,0,1,1,6.78.42L73,101.27a3.4,3.4,0,0,1-6.78-.43L69.59,49Zm-40.26.42A3.39,3.39,0,1,1,36.1,49l3.41,51.8a3.39,3.39,0,1,1-6.77.43L29.33,49.46ZM92.51,33.38H13.19l7.94,83.55H84.56l8-83.55Z"></path></svg></td>': ''}`
                            )
                            sdksd++;
                        });
                    })
                    // $('.showSiblingData.fa-eye').click(function(){
                    //     $('input.disabledValue[type=text]').map((e,i)=>{
                    //                         console.log(e,i);
                    //                     })
                    // })
                $('.showSiblingData').click(function(){
                    if($(this).hasClass('fa-eye')){
                        if($('input.disabledValue[type=text]').length >= 2){
                            return;
                        }
                    }
                                        
                let getAtrr = $(this).siblings('input');
                if(getAtrr.attr('type') == 'password'){
                    getAtrr.attr('type','text')
                    $(this).removeClass('fa-eye')
                    $(this).addClass('fa-eye-slash')
                }else{
                    getAtrr.attr('type','password')
                    $(this).removeClass('fa-eye-slash')
                    $(this).addClass('fa-eye')
                }
                
            })
                    }        
                    
                    ll()


                    $("#re").css("visibility", "visible");
                    
                    $('.fontSize .plus').on('click',function(){
                        let fsize = Number($('.fontSizeno').text())+1;
                        $('.fontSizeno').text(fsize)

                        $('#showData td,#showData th').css('font-size',`${fsize}px`)
                    })
                    $('.fontSize .minus').on('click',function(){

                        if($('.fontSizeno').text() >= 2){
                            let fsize2 = Number($('.fontSizeno').text())-1;
                            $('.fontSizeno').text(fsize2)
                            $('#showData td,#showData th').css('font-size',`${fsize2}px`)
                        }
                        

                        // $('#showData td,#showData th').css('font-size')
                    })
                    return appendeds();
                });

            }

            function style_insert() {
                let kid = Number($('#showData table tbody tr').last().data('row')) + 1;
                let kidd = Number($('#showData table tbody tr').last().find('td').data('id')) + 1;
                $('#showData table tbody').append(`<tr data-row="${kid}" class="row_${kid}"></tr>`)
                let jf = 1;
                var url = script_url + "?callback=ctrlq&sheetid=" + sheetid + "&sheetName=" + sheetName + "&id=" + kidd +
                    "&action=insert";
                var request = jQuery.ajax({
                    crossDomain: true,
                    url: url,
                    method: "GET",
                    dataType: "jsonp"
                });
                arrayfromkey.map((e, i) => {
                    if (e != 'Action') {
                        $(`#showData table tbody tr.row_${kid}`).append(
                            `<td data-columnrange="${jf}" data-columnname="${e}" contenteditable = "${e != 'id'? 'true': 'false' }" data-id="${kidd}" class="changingElements">${e == 'id'? kidd : '' }</th>`
                        );
                    } else {
                        $(`#showData table tbody tr.row_${kid}`).append(
                            `<td data-columnrange="${jf}" data-columnname="${e}" data-id="${kidd}" class="text-center"><svg width="15" class="deleteRow" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 105.7 122.88"><title>Delete This Row</title><path d="M30.46,14.57V5.22A5.18,5.18,0,0,1,32,1.55v0A5.19,5.19,0,0,1,35.68,0H70a5.22,5.22,0,0,1,3.67,1.53l0,0a5.22,5.22,0,0,1,1.53,3.67v9.35h27.08a3.36,3.36,0,0,1,3.38,3.37V29.58A3.38,3.38,0,0,1,102.32,33H98.51l-8.3,87.22a3,3,0,0,1-2.95,2.69H18.43a3,3,0,0,1-3-2.95L7.19,33H3.37A3.38,3.38,0,0,1,0,29.58V17.94a3.36,3.36,0,0,1,3.37-3.37Zm36.27,0V8.51H39v6.06ZM49.48,49.25a3.4,3.4,0,0,1,6.8,0v51.81a3.4,3.4,0,1,1-6.8,0V49.25ZM69.59,49a3.4,3.4,0,1,1,6.78.42L73,101.27a3.4,3.4,0,0,1-6.78-.43L69.59,49Zm-40.26.42A3.39,3.39,0,1,1,36.1,49l3.41,51.8a3.39,3.39,0,1,1-6.77.43L29.33,49.46ZM92.51,33.38H13.19l7.94,83.55H84.56l8-83.55Z"></path></svg></td></th>`
                        );
                    }
                    jf++;
                })

                return appendeds();
            }

            function appendeds() {
                
                $('.changingElements').on('click', function() {
                    updatecheck = $(this).text();
                })
                $('.changingElements').on('change keyup input',function(){
                    $('.instractions').removeClass('d-none');
                })
                $('.changingElements').focusout(function() {
                    $('.instractions').addClass('d-none');
                    if (updatecheck != $(this).text()) {
                        let columnrange = $(this).data('columnrange');
                        let columnname = $(this).data('columnname');
                        let id = $(this).data('id');
                        let text = $(this).text();
                        var url = script_url + "?callback=ctrlq&sheetid=" + sheetid + "&sheetName=" + sheetName +
                            "&name=" + text + "&id=" + id + "&crange=" + columnrange + "&action=update";
                        var request = jQuery.ajax({
                            crossDomain: true,
                            url: url,
                            method: "GET",
                            dataType: "jsonp",
                        });
                    }
                })
                $('.deleteRow').on('click', function() {
                    let idxp = $(this).parent().data('id');
                    var url = script_url + "?callback=ctrlq&sheetid=" + sheetid + "&sheetName=" + sheetName + "&id=" +
                        idxp + "&action=delete";
                    var request = jQuery.ajax({
                        crossDomain: true,
                        url: url,
                        method: "GET",
                        dataType: "jsonp"
                    });
                    $(this).parent().parent().remove();
                })

              $("#myInput").on("keyup", function() {
    var value = $(this).val().toLowerCase();
    $("#showData table tbody tr").filter(function() {
      $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
    });
  });
            }
            $(window).on('load', function() {
                return mnvbm();
            });
            
            function mnvbm() {
                var url = script_url + "?callback=ctrlq&action=driveread&folderId="+folderID;
                $.getJSON(url, function(json) {
                    let vk = 1;
                    const sheetype = 'application/vnd.google-apps.spreadsheet';
                    const ziptype = 'application/x-zip-compressed';
                    json.map((e, i) => {
                        let mimetype = e.mimetype;
                        if (mimetype == sheetype){
                            
                            $('table#driveDataList tbody').append(`<tr class="row_${i}"><tr>`);
                            $(`table#driveDataList tbody tr.row_${i}`).append(
                                `<td>${vk}</td><td>${mimetype == sheetype ? googlesheeticon : ziptype == mimetype ? zipicon: ''}${e.name}</td><td><a class="btn btn-secondary text-dark btn-sm me-2" href="{{ url('spreadsheets/${e.id}/${e.name}') }}">Open</a></td><td><button onclick="share_access(this)" class="shareSheetAccess btn btn-secondary text-dark btn-sm me-2" data-id="${e.id}" data-name="${e.name}"><svg class="icon icon-xxs me-2" fill="currentColor" viewBox="0 0 20 20" xmlns="http://www.w3.org/2000/svg"><path d="M10 12a2 2 0 100-4 2 2 0 000 4z"></path><path fill-rule="evenodd" d="M.458 10C1.732 5.943 5.522 3 10 3s8.268 2.943 9.542 7c-1.274 4.057-5.064 7-9.542 7S1.732 14.057.458 10zM14 10a4 4 0 11-8 0 4 4 0 018 0z" clip-rule="evenodd"></path></svg>Share</button></td>`
                            );
                        }
                        vk++;
                    })
                })
            }

            let accessId;
            let accessName;

            function share_access(e) {
                accessId = $(e).data('id');
                accessName = $(e).data('name');
                $('.selectthesheet').text('Share ‘' + $(e).data('name') + '’ access with..');
                $.ajax({
                    type: 'post',
                    url: '{{ url('check_share_access') }}',
                    data: {
                        'file_id': accessId,
                        '_token': '{{ csrf_token() }}'
                    },
                    beforeSend: function() {
                        $('.userforaccessclass').attr('id','userforaccess');
                    },
                    success: function(data) {
                        $('table.accessxp tbody tr input.accessCheckbox').prop("checked", false);
                        $('table.accessxp tbody tr td .removeAccess').remove();
                        data.map((e, i) => {
                            $('table.accessxp tbody tr').each(function(){
                                const thisval = $(this);
                                if (e.user_id == Number($(this).find('.uid').text())) {
                                    $(thisval).find(`input[value=${e.role}]`).prop("checked", true);
                                    let id = $(thisval).find(`input[value=${e.role}]`).attr('id');
                                    $(thisval).find(`td[data-td=${$(this).find('.uid').text()}]`).append(`<label class="removeAccess btn btn-secondary" data-user="${$(this).find('.uid').text()}">Remove Access</label>`);
                                }
                            })
                        })
                    }
                });

                $('#userforaccess').attr('id', '');
                $('#cofsb').remove();
                return removeaccessheet();
            }

            $('.accessCheckbox').on('change', function() {
                if ($(this).is(':checked')) {
                    let role = $(this).val();
                    let user_id = $(this).data('user');
                    $(`table.accessxp tbody tr td[data-td=${user_id}] .removeAccess`).remove();
                    $(`table.accessxp tbody tr td[data-td=${user_id}]`).append(`<label class="removeAccess btn btn-secondary" data-user="${user_id}">Remove Access</label>`);
                    $.ajax({
                        type: 'post',
                        url: '{{ url('share_access') }}',
                        data: {
                            'file_id': accessId,
                            'file_name': accessName,
                            'user_id': user_id,
                            'role': role,
                            '_token': '{{ csrf_token() }}'
                        },
                        success: function(data) {
                           
                            return removeaccessheet();
                        }
                    });
                }
            });
            function removeaccessheet(){
                setTimeout(function() {
                $('.removeAccess').on('click', function() {
                let user_id = $(this).data('user');
                $.ajax({
                        type: 'post',
                        url: '{{ url('remove-access') }}',
                        data: {
                            'file_id': accessId,
                            'user_id': user_id,
                            '_token': '{{ csrf_token() }}'
                        },
                        success: function(data) {
                           
                        }
                    });
                    $(`table.accessxp tbody tr td.forr_${user_id} input.accessCheckbox`).prop("checked", false);
                    $(this).remove();
            })
        }, 1500);
            }
            
        </script>
        
    </body>
    </html>