import Toastify from"../../../lib/toastify/toastify-es.js";import{filesize}from"../../../lib/filesize.esm.js";import{Tabulator,TooltipModule,ValidateModule,EditModule,InteractionModule,FrozenColumnsModule,MenuModule,ResizeColumnsModule,SortModule,FilterModule,FormatModule,SelectRowModule,SelectRangeModule,KeybindingsModule}from"../../../lib/tabulator/tabulator_esm.js";Tabulator.registerModule([TooltipModule,ValidateModule,EditModule,MenuModule,InteractionModule,FrozenColumnsModule,ResizeColumnsModule,SortModule,FilterModule,FormatModule,SelectRowModule,SelectRangeModule,KeybindingsModule]);const tr=function(){const args=arguments;return chrome?.i18n?.getMessage?chrome.i18n.getMessage.apply(null,args):args[0]||""},removeTempRule=rule=>new Promise((resolve=>{window.OmegaTargetPopup.addTempRule(rule.domain,rule.profileName,-1,(()=>{resolve()}))})),createTabulator=()=>{const createFooterElement=()=>{const footerEl=document.createElement("div");footerEl.className="tabulator-footer";const footerContentsEl=document.createElement("div");footerContentsEl.className="tabulator-footer-contents",footerEl.append(footerContentsEl);const paginatorEl=document.createElement("span");paginatorEl.className="tabulator-paginator",footerContentsEl.append(paginatorEl);const paginatorBtnsEl=document.createElement("span");paginatorBtnsEl.classList.add("btn-group");const clearBtnEl=document.createElement("button");return clearBtnEl.classList.add("btn","btn-default","btn-sm"),clearBtnEl.innerHTML='\n      <span class="glyphicon glyphicon-trash" aria-hidden="true"></span>\n      Delete all temp rules\n    ',clearBtnEl.onclick=async()=>{tabulatorInstance.alert("Processing...");const rules=tabulatorInstance.getData();for(let _i=0;_i<rules.length;_i++)await removeTempRule(rules[_i]);tabulatorInstance.clearData(),tabulatorInstance.clearAlert()},paginatorBtnsEl.append(clearBtnEl),paginatorEl.append(paginatorBtnsEl),footerEl},tempProfileRules=window.OmegaPopup.tempProfileRules,rules=Object.keys(tempProfileRules).map((domain=>({...tempProfileRules[domain],domain:domain}))),tabulatorInstance=new Tabulator(".list-container",{height:"100%",data:rules,layout:"fitColumns",index:"domain",columnDefaults:{headerClick:(e,column)=>{if(!column.getDefinition().headerSort)return;tabulatorInstance.getSorters().find((sorter=>{if(sorter.column===column&&"asc"===sorter.dir){const currSort=sorter.field+"_"+sorter.dir;return tabulatorInstance.__prevSort===currSort?(tabulatorInstance.clearSort(),tabulatorInstance.__prevSort=null):tabulatorInstance.__prevSort=currSort,!0}return!1}))}},footerElement:createFooterElement(),resizableColumnGuide:!0,placeholder:"No Data",columns:[{title:"#",width:20,maxWidth:100,field:"domain",hozAlign:"center",headerHozAlign:"center",formatter:"rownum",headerSort:!1,frozen:!0},{title:"Domain",field:"domain"},{title:"Pattern",field:"condition.pattern",hozAlign:"center",headerHozAlign:"center",headerSort:!0},{title:"Profile",field:"profileName",width:300},{field:"domain",formatter:"buttonCross",topCalc:"count",width:30,hozAlign:"center",headerSort:!1,cellClick:function(e,cell){const rule=cell.getRow().getData();removeTempRule(rule),cell.getRow().delete()}}]});return new Promise((resolve=>{const onTableBuilt=()=>{tabulatorInstance.off("tableBuilt",onTableBuilt),resolve(tabulatorInstance)};tabulatorInstance.on("tableBuilt",onTableBuilt)}))},init=async()=>{await createTabulator()};init();