document.addEventListener("DOMContentLoaded",function(e){var t,a,s=document.querySelector(".datatable-project"),n=document.querySelector(".datatable-invoice");if(s&&((t=document.createElement("h5")).classList.add("card-title","mb-0","text-md-start","text-center","pt-md-0","pt-6"),t.innerHTML="Project List",a=new DataTable(s,{ajax:assetsPath+"json/user-profile.json",columns:[{data:"id"},{data:"id",orderable:!1,render:DataTable.render.select()},{data:"project_name"},{data:"project_leader"},{data:"id"},{data:"status"},{data:"id"}],columnDefs:[{className:"control",searchable:!1,orderable:!1,responsivePriority:2,targets:0,render:function(e,t,a,s){return""}},{targets:1,orderable:!1,searchable:!1,responsivePriority:3,checkboxes:!0,checkboxes:{selectAllRender:'<input type="checkbox" class="form-check-input">'},render:function(){return'<input type="checkbox" class="dt-checkboxes form-check-input">'}},{targets:2,responsivePriority:4,render:function(e,t,a,s){var n=a.project_img,r=a.project_name,a=a.date;return'<div class="d-flex justify-content-left align-items-center"><div class="avatar-wrapper"><div class="avatar avatar-sm me-3">'+(n?'<img src="'+assetsPath+"img/icons/brands/"+n+'" alt="Avatar" class="rounded-circle">':'<span class="avatar-initial rounded-circle bg-label-'+["success","danger","warning","info","primary","secondary"][Math.floor(6*Math.random())]+'">'+(n=(((n=r.match(/\b\w/g)||[]).shift()||"")+(n.pop()||"")).toUpperCase())+"</span>")+'</div></div><div class="d-flex flex-column gap-50"><span class="text-truncate fw-medium text-heading">'+r+'</span><small class="text-truncate">'+a+"</small></div></div>"}},{targets:3,render:function(e,t,a,s){return'<span class="text-heading">'+a.project_leader+"</span>"}},{targets:4,orderable:!1,searchable:!1,render:function(e,t,a,s){var n=a.team;let r="",l=0;for(let e=0;e<n.length&&(r+=`
                <li data-bs-toggle="tooltip" data-popup="tooltip-custom" data-bs-placement="top" title="Kim Karlos" class="avatar avatar-sm pull-up">
                  <img class="rounded-circle" src="${assetsPath}img/avatars/${n[e]}" alt="Avatar">
                </li>
              `,!(2<++l));e++);return 2<l&&0<(a=n.length-3)&&(r+=`
                  <li class="avatar avatar-sm">
                    <span class="avatar-initial rounded-circle pull-up" data-bs-toggle="tooltip" data-bs-placement="top" title="${a} more">+${a}</span>
                  </li>
                `),`
              <div class="d-flex align-items-center">
                <ul class="list-unstyled d-flex align-items-center avatar-group mb-0 z-2">
                  ${r}
                </ul>
              </div>
            `}},{targets:-2,render:function(e,t,a,s){a=a.status;return`
              <div class="d-flex align-items-center">
                <div class="progress w-100 me-3" style="height: 6px;">
                  <div class="progress-bar" style="width: ${a}" aria-valuenow="${a}" aria-valuemin="0" aria-valuemax="100"></div>
                </div>
                <span class="text-heading">${a}</span>
              </div>
            `}},{targets:-1,searchable:!1,title:"Action",orderable:!1,render:function(e,t,a,s){return'<div class="d-inline-block"><a href="javascript:;" class="btn btn-icon dropdown-toggle hide-arrow" data-bs-toggle="dropdown"><i class="icon-base ti tabler-dots-vertical icon-22px"></i></a><div class="dropdown-menu dropdown-menu-end m-0"><a href="javascript:;" class="dropdown-item">Details</a><a href="javascript:;" class="dropdown-item">Archive</a><div class="dropdown-divider"></div><a href="javascript:;" class="dropdown-item text-danger delete-record">Delete</a></div></div>'}}],select:{style:"multi",selector:"td:nth-child(2)"},order:[[2,"desc"]],layout:{topStart:{rowClass:"row mx-md-3 my-0 justify-content-between",features:[t]},topEnd:{search:{placeholder:"Search Project",text:"_INPUT_"}},bottomStart:{rowClass:"row mx-3 justify-content-between",features:["info"]},bottomEnd:"paging"},displayLength:7,language:{lengthMenu:"_MENU_",paginate:{next:'<i class="icon-base ti tabler-chevron-right scaleX-n1-rtl icon-18px"></i>',previous:'<i class="icon-base ti tabler-chevron-left scaleX-n1-rtl icon-18px"></i>',first:'<i class="icon-base ti tabler-chevrons-left scaleX-n1-rtl icon-18px"></i>',last:'<i class="icon-base ti tabler-chevrons-right scaleX-n1-rtl icon-18px"></i>'}},responsive:{details:{display:DataTable.Responsive.display.modal({header:function(e){return"Details of "+e.data().project_name}}),type:"column",renderer:function(e,t,a){var s,n,r,a=a.map(function(e){return""!==e.title?`<tr data-dt-row="${e.rowIndex}" data-dt-column="${e.columnIndex}">
                      <td>${e.title}:</td>
                      <td>${e.data}</td>
                    </tr>`:""}).join("");return!!a&&((s=document.createElement("div")).classList.add("table-responsive"),n=document.createElement("table"),s.appendChild(n),n.classList.add("table"),(r=document.createElement("tbody")).innerHTML=a,n.appendChild(r),s)}}}}),document.addEventListener("click",function(e){e.target.classList.contains("delete-record")&&(a.row(e.target.closest("tr")).remove().draw(),e=document.querySelector(".dtr-bs-modal"))&&e.classList.contains("show")&&bootstrap.Modal.getInstance(e)?.hide()})),n){s=document.createElement("h5");s.classList.add("card-title","mb-0","text-md-start","text-center","pt-md-0","pt-6"),s.innerHTML="Invoice List";let a=new DataTable(n,{ajax:assetsPath+"json/invoice-list.json",columns:[{data:"id"},{data:"invoice_id"},{data:"invoice_status"},{data:"total"},{data:"issued_date"},{data:"action"}],columnDefs:[{className:"control",orderable:!1,searchable:!1,responsivePriority:2,targets:0,render:function(e,t,a,s){return""}},{targets:1,render:(e,t,a,s)=>`<a href="app-invoice-preview.html"><span>#${a.invoice_id}</span></a>`},{targets:2,render:(e,t,a,s)=>{var n=a.invoice_status;return`
              <span class='d-inline-block' data-bs-toggle='tooltip' data-bs-html='true'
                    title='<span>${n}<br>
                           <span class="fw-medium">Balance:</span> ${a.balance}<br>
                           <span class="fw-medium">Due Date:</span> ${a.due_date}</span>'>
                ${{Sent:'<span class="badge badge-center d-flex align-items-center justify-content-center rounded-pill bg-label-success w-px-30 h-px-30"><i class="ti tabler-check icon-xs"></i></span>',Draft:'<span class="badge badge-center d-flex align-items-center justify-content-center rounded-pill bg-label-primary w-px-30 h-px-30"><i class="ti tabler-folder icon-xs"></i></span>',"Past Due":'<span class="badge badge-center d-flex align-items-center justify-content-center rounded-pill bg-label-danger w-px-30 h-px-30"><i class="ti tabler-alert-triangle icon-xs"></i></span>',"Partial Payment":'<span class="badge badge-center d-flex align-items-center justify-content-center rounded-pill bg-label-secondary w-px-30 h-px-30"><i class="ti tabler-mail icon-xs"></i></span>',Paid:'<span class="badge badge-center d-flex align-items-center justify-content-center rounded-pill bg-label-warning w-px-30 h-px-30"><i class="ti tabler-chart-pie icon-xs"></i></span>',Downloaded:'<span class="badge badge-center d-flex align-items-center justify-content-center rounded-pill bg-label-info w-px-30 h-px-30"><i class="ti tabler-arrow-down icon-xs"></i></span>'}[n]}
              </span>
            `}},{targets:3,render:function(e,t,a,s){return"$"+a.total}},{targets:-1,title:"Actions",orderable:!1,render:(e,t,a,s)=>`
              <div class="d-flex align-items-center">
                <a href="javascript:;" class="btn btn-text-secondary rounded-pill waves-effect btn-icon delete-record"><i class="ti tabler-trash icon-22px"></i></a>
                <a href="app-invoice-preview.html" class="btn btn-text-secondary rounded-pill waves-effect btn-icon" data-bs-toggle="tooltip" title="Preview">
                  <i class="icon-base ti tabler-eye icon-22px"></i>
                </a>
                <div class="d-inline-block">
                  <a href="javascript:;" class="btn btn-text-secondary rounded-pill waves-effect btn-icon dropdown-toggle hide-arrow" data-bs-toggle="dropdown">
                    <i class="icon-base ti tabler-dots-vertical icon-22px"></i>
                  </a>
                  <div class="dropdown-menu dropdown-menu-end m-0">
                    <a href="javascript:;" class="dropdown-item">Download</a>
                    <a href="app-invoice-edit.html" class="dropdown-item">Edit</a>
                    <a href="javascript:;" class="dropdown-item">Duplicate</a>
                  </div>
                </div>
              </div>
            `}],order:[[1,"desc"]],layout:{topStart:{rowClass:"row border-bottom mx-0 px-3",features:[s]},topEnd:{features:[{pageLength:{menu:[10,25,50,100],text:"_MENU_"}},{buttons:[{extend:"collection",className:"btn btn-label-secondary dropdown-toggle float-sm-end mb-3 mb-md-0 mt-md-0 mt-5",text:'<i class="icon-base ti tabler-upload icon-sm me-2"></i>Export',buttons:[{extend:"print",text:'<i class="icon-base ti tabler-printer me-2"></i>Print',className:"dropdown-item",exportOptions:{columns:[1,2,3,4]}},{extend:"csv",text:'<i class="icon-base ti tabler-file me-2"></i>Csv',className:"dropdown-item",exportOptions:{columns:[1,2,3,4]}},{extend:"excel",text:'<i class="icon-base ti tabler-upload me-2"></i>Excel',className:"dropdown-item",exportOptions:{columns:[1,2,3,4]}},{extend:"pdf",text:'<i class="icon-base ti tabler-file-text me-2"></i>Pdf',className:"dropdown-item",exportOptions:{columns:[1,2,3,4]}},{extend:"copy",text:'<i class="icon-base ti tabler-copy me-2"></i>Copy',className:"dropdown-item",exportOptions:{columns:[1,2,3,4]}}]}]}]},bottomStart:{rowClass:"row mx-3 justify-content-between",features:["info"]},bottomEnd:"paging"},language:{paginate:{next:'<i class="icon-base ti tabler-chevron-right scaleX-n1-rtl icon-18px"></i>',previous:'<i class="icon-base ti tabler-chevron-left scaleX-n1-rtl icon-18px"></i>',first:'<i class="icon-base ti tabler-chevrons-left scaleX-n1-rtl icon-18px"></i>',last:'<i class="icon-base ti tabler-chevrons-right scaleX-n1-rtl icon-18px"></i>'}},responsive:{details:{display:DataTable.Responsive.display.modal({header:function(e){return"Details of "+e.data().invoice_id}}),type:"column",renderer:function(e,t,a){var s,n,r,a=a.map(function(e){return""!==e.title?`<tr data-dt-row="${e.rowIndex}" data-dt-column="${e.columnIndex}">
                      <td>${e.title}:</td>
                      <td>${e.data}</td>
                    </tr>`:""}).join("");return!!a&&((s=document.createElement("div")).classList.add("table-responsive"),n=document.createElement("table"),s.appendChild(n),n.classList.add("table"),(r=document.createElement("tbody")).innerHTML=a,n.appendChild(r),s)}}}});function r(e){let t=document.querySelector(".dtr-expanded");(t=e?e.target.parentElement.closest("tr"):t)&&a.row(t).remove().draw()}function l(){var e=document.querySelector(".datatable-invoice");let t=document.querySelector(".dtr-bs-modal");e&&e.classList.contains("collapsed")?t&&t.addEventListener("click",function(e){e.target.parentElement.classList.contains("delete-record")&&(r(),e=t.querySelector(".btn-close"))&&e.click()}):(e=e?.querySelector("tbody"))&&e.addEventListener("click",function(e){e.target.parentElement.classList.contains("delete-record")&&r(e)})}l(),document.addEventListener("show.bs.modal",function(e){e.target.classList.contains("dtr-bs-modal")&&l()}),document.addEventListener("hide.bs.modal",function(e){e.target.classList.contains("dtr-bs-modal")&&l()}),a.on("draw.dt",function(){[].slice.call(document.querySelectorAll('[data-bs-toggle="tooltip"]')).map(function(e){return new bootstrap.Tooltip(e,{boundary:document.body})})})}setTimeout(()=>{[{selector:".dt-search .form-control",classToRemove:"form-control-sm"},{selector:".dt-length .form-select",classToRemove:"form-select-sm",classToAdd:"ms-0"},{selector:".dt-length",classToAdd:"mb-md-6 mb-0"},{selector:".dt-buttons",classToAdd:"justify-content-center"},{selector:".dt-layout-table",classToRemove:"row mt-2"},{selector:".dt-layout-end",classToAdd:"gap-md-2 gap-0 mt-0"},{selector:".dt-layout-full",classToRemove:"col-md col-12",classToAdd:"table-responsive"}].forEach(({selector:e,classToRemove:a,classToAdd:s})=>{document.querySelectorAll(e).forEach(t=>{a&&a.split(" ").forEach(e=>t.classList.remove(e)),s&&s.split(" ").forEach(e=>t.classList.add(e))})})},100)});