"use strict";(self.webpackChunkmulti_token_edit=self.webpackChunkmulti_token_edit||[]).push([[126],{1126:(e,t,a)=>{a.d(t,{default:()=>SavedSearches});var s=a(6596),r=a(2370);const{HandlebarsApplicationMixin:i,ApplicationV2:o}=foundry.applications.api;class SavedSearches extends(i(o)){constructor(e){const t=e.position;super({position:{left:t.left+t.width+5,top:t.top}}),this._browserApp=e,this._saveSettings={label:"",color:""}}static DEFAULT_OPTIONS={id:"mass-edit-presets-saved-searches",tag:"form",form:{handler:SavedSearches._onSubmit,submitOnChange:!0,closeOnSubmit:!1},window:{contentClasses:["standard-form"],title:"Saved Searches",resizable:!0,icon:"fa-solid fa-bookmark"},position:{width:325,height:500},actions:{save:SavedSearches._onSaveSearch,toggle:SavedSearches._onToggleSearch,remove:SavedSearches._onRemove}};static PARTS={main:{template:`modules/${s.Do}/templates/preset/saved-searches.hbs`}};updateQuery(e){this.element.querySelector(".search").value=e}async _prepareContext(e){return{searches:foundry.utils.deepClone(r.Gj.CONFIG.savedSearches).map(e=>({...e,textColor:this._getContrastColor(e.color)})),search:{...this._saveSettings,query:this._browserApp.lastSearch}}}_getContrastColor(e){if(!e?.trim())return"white";const t=Color.fromString(e).linear.rgb;return.2126*t[0]+.7152*t[1]+.0722*t[2]>.179?"black":"white"}static async _onSaveSearch(e){const t=new foundry.applications.ux.FormDataExtended(this.form).object;if(["color","label","query"].forEach(e=>t[e]=t[e].trim()),!t.query)return void ui.notifications.warn("Search field cannot be empty.");t.label||(t.label=t.query),t.color||(t.color="#000000");const a=r.Gj.CONFIG.savedSearches;a.find(e=>e.label===t.label)?ui.notifications.warn("Search with this label/query already exists."):(["switchLayer","autoScale","externalCompendiums","virtualDirectory"].forEach(e=>{t[e]=r.Gj.CONFIG[e]}),t.documentName=this._browserApp.documentName,a.push(t),await r.Gj.setSetting("savedSearches",a),this._saveSettings=t,this.render(!0))}static _onToggleSearch(e,t){const a=r.Gj.CONFIG.savedSearches[Number(t.closest(".search").dataset.index)];this._saveSettings=a,this.render(!0),this._browserApp.loadSavedSearch(a)}static async _onRemove(e,t){const a=Number(t.closest(".search").dataset.index),s=r.Gj.CONFIG.savedSearches;s.splice(a,1),await r.Gj.setSetting("savedSearches",s),this.render(!0)}static _onSubmit(e,t,a){this._saveSettings=a.object}_attachFrameListeners(){super._attachFrameListeners();const e=$(this.element);e.on("dragstart",".search",e=>{e.originalEvent.dataTransfer.clearData(),e.originalEvent.dataTransfer.setData("text/plain",`${e.currentTarget.closest(".search").dataset.index}`)}),e.on("drop",".search",e=>{const t=foundry.applications.ux.TextEditor.implementation.getDragEventData(e.originalEvent);Number.isInteger(t)&&this._onSort(t,Number(e.currentTarget.closest(".search").dataset.index))})}async _onSort(e,t){if(e===t)return;const a=r.Gj.CONFIG.savedSearches;t===a.length-1&&t++,a.splice(t,0,a[e]),a.splice(e+(t<e?1:0),1),await r.Gj.setSetting("savedSearches",a),this.render(!0)}async close(e={}){return this._browserApp._savedSearches=null,super.close(e)}}}}]);
//# sourceMappingURL=126.mass-edit.js.map