Choose wisely.
', + * onYes: () => 'YES Result' + * onNo: () => 'NO Result' + * }); + * + * // Logs 'YES result', 'NO Result', or null if the user closed the dialog without making a selection. + * console.log(result); + */ + static async confirm({ onYes, onNo, ...data2 } = {}, options = {}) { + const mergedButtons = deepMerge({ + yes: { + icon: "fas fa-check", + label: "Yes" + }, + no: { + icon: "fas fa-times", + label: "No" + } + }, data2.buttons ?? {}); + return this.wait({ + ...data2, + buttons: deepMerge(mergedButtons, { + yes: { + onPress: (application) => this.#invokeFn(onYes, application, true) + }, + no: { + onPress: (application) => this.#invokeFn(onNo, application, false) + } + }), + default: data2.default ?? "yes" + }, options); + } + /** + * A helper method to invoke a callback function directly or lookup an exported function with the same name from any + * content Svelte component to invoke. This is used internally to apply default values for `confirm` and `prompt`. + * + * @param {string|((application: TJSDialog) => any)} callback - Callback function to invoke; may be an async + * function. When defined as a string any matching function by name exported from content Svelte component is + * invoked. + * + * @param {TJSDialog} application - TJSDialog instance passed to callback. + * + * @param {*} [defaultResult] - An optional default result to return; undefined if not specified. + * + * @returns {*} Result. + */ + static #invokeFn(callback, application, defaultResult = void 0) { + let result = defaultResult; + switch (typeof callback) { + case "function": + result = callback(application); + break; + case "string": { + const dialogComponent = application?.svelte?.dialogComponent; + if (dialogComponent !== void 0 && typeof dialogComponent?.[callback] === "function") { + result = dialogComponent?.[callback](application); + } else { + if (dialogComponent === void 0) { + console.warn(`[TRL] TJSDialog warning: 'onPress' defined as a string with no associated content Svelte component.`); + } else if (typeof dialogComponent?.[callback] !== "function") { + console.warn(`[TRL] TJSDialog warning: The content Svelte component does not contain an associated function '${callback}'. Did you remember to add 'Are you OK?.
', + * label: 'Feeling Fine!' + * onOk: () => 'OK' + * }); + * + * // Logs 'OK' or null if the user closed the dialog without making a selection. + * console.log(result); + */ + static async prompt({ onOk, label, icon = "fas fa-check", ...data2 } = {}, options = {}) { + return this.wait({ + ...data2, + buttons: { + ok: { + icon, + label, + onPress: (application) => this.#invokeFn(onOk, application, true) + } + }, + default: "ok" + }, options); + } + /** + * Creates an anonymous data defined TJSDialog returning a Promise that can be awaited upon for the user to make a + * choice. + * + * Note: By default `null` is returned if the dialog is closed without a user making a choice. + * + * @template T + * + * @param {TJSDialogOptions} data - Dialog data passed to the TJSDialog constructor. + * + * @param {SvelteApplicationOptions} [options] SvelteApplication options passed to the TJSDialog constructor. + * + * @returns {Promise${txt}
`; + div.style.display = "none"; + div.style.position = "fixed"; + div.style.zIndex = "-5"; + return div; +} +__name(instructionToHiddenDiv, "instructionToHiddenDiv"); +function alertToScreenReader(txt) { + if (isOnServer) + return; + if (!alertsDiv) { + initAriaOnBrowser(); + } + alertsDiv.innerHTML = ""; + const alertText = document.createTextNode(txt); + alertsDiv.appendChild(alertText); + alertsDiv.style.display = "none"; + alertsDiv.style.display = "inline"; +} +__name(alertToScreenReader, "alertToScreenReader"); +const DEFAULT_DROP_ZONE_TYPE = "--any--"; +const DEFAULT_DROP_TARGET_STYLE = { + outline: "rgba(255, 255, 102, 0.7) solid 2px" +}; +let isDragging = false; +let draggedItemType; +let focusedDz; +let focusedDzLabel = ""; +let focusedItem; +let focusedItemId; +let focusedItemLabel = ""; +const allDragTargets = /* @__PURE__ */ new WeakSet(); +const elToKeyDownListeners = /* @__PURE__ */ new WeakMap(); +const elToFocusListeners = /* @__PURE__ */ new WeakMap(); +const dzToHandles = /* @__PURE__ */ new Map(); +const dzToConfig = /* @__PURE__ */ new Map(); +const typeToDropZones = /* @__PURE__ */ new Map(); +let INSTRUCTION_IDs; +function registerDropZone(dropZoneEl, type) { + if (typeToDropZones.size === 0) { + INSTRUCTION_IDs = initAria(); + window.addEventListener("keydown", globalKeyDownHandler); + window.addEventListener("click", globalClickHandler); + } + if (!typeToDropZones.has(type)) { + typeToDropZones.set(type, /* @__PURE__ */ new Set()); + } + if (!typeToDropZones.get(type).has(dropZoneEl)) { + typeToDropZones.get(type).add(dropZoneEl); + incrementActiveDropZoneCount(); + } +} +__name(registerDropZone, "registerDropZone"); +function unregisterDropZone(dropZoneEl, type) { + if (focusedDz === dropZoneEl) { + handleDrop(); + } + typeToDropZones.get(type).delete(dropZoneEl); + decrementActiveDropZoneCount(); + if (typeToDropZones.get(type).size === 0) { + typeToDropZones.delete(type); + } + if (typeToDropZones.size === 0) { + window.removeEventListener("keydown", globalKeyDownHandler); + window.removeEventListener("click", globalClickHandler); + INSTRUCTION_IDs = void 0; + destroyAria(); + } +} +__name(unregisterDropZone, "unregisterDropZone"); +function globalKeyDownHandler(e) { + if (!isDragging) + return; + switch (e.key) { + case "Escape": { + handleDrop(); + break; + } + } +} +__name(globalKeyDownHandler, "globalKeyDownHandler"); +function globalClickHandler() { + if (!isDragging) + return; + if (!allDragTargets.has(document.activeElement)) { + handleDrop(); + } +} +__name(globalClickHandler, "globalClickHandler"); +function handleZoneFocus(e) { + if (!isDragging) + return; + const newlyFocusedDz = e.currentTarget; + if (newlyFocusedDz === focusedDz) + return; + focusedDzLabel = newlyFocusedDz.getAttribute("aria-label") || ""; + const { items: originItems } = dzToConfig.get(focusedDz); + const originItem = originItems.find((item) => item[ITEM_ID_KEY] === focusedItemId); + const originIdx = originItems.indexOf(originItem); + const itemToMove = originItems.splice(originIdx, 1)[0]; + const { items: targetItems, autoAriaDisabled } = dzToConfig.get(newlyFocusedDz); + if (newlyFocusedDz.getBoundingClientRect().top < focusedDz.getBoundingClientRect().top || newlyFocusedDz.getBoundingClientRect().left < focusedDz.getBoundingClientRect().left) { + targetItems.push(itemToMove); + if (!autoAriaDisabled) { + alertToScreenReader(`Moved item ${focusedItemLabel} to the end of the list ${focusedDzLabel}`); + } + } else { + targetItems.unshift(itemToMove); + if (!autoAriaDisabled) { + alertToScreenReader(`Moved item ${focusedItemLabel} to the beginning of the list ${focusedDzLabel}`); + } + } + const dzFrom = focusedDz; + dispatchFinalizeEvent(dzFrom, originItems, { trigger: TRIGGERS.DROPPED_INTO_ANOTHER, id: focusedItemId, source: SOURCES.KEYBOARD }); + dispatchFinalizeEvent(newlyFocusedDz, targetItems, { trigger: TRIGGERS.DROPPED_INTO_ZONE, id: focusedItemId, source: SOURCES.KEYBOARD }); + focusedDz = newlyFocusedDz; +} +__name(handleZoneFocus, "handleZoneFocus"); +function triggerAllDzsUpdate() { + dzToHandles.forEach(({ update: update2 }, dz) => update2(dzToConfig.get(dz))); +} +__name(triggerAllDzsUpdate, "triggerAllDzsUpdate"); +function handleDrop(dispatchConsider = true) { + if (!dzToConfig.get(focusedDz).autoAriaDisabled) { + alertToScreenReader(`Stopped dragging item ${focusedItemLabel}`); + } + if (allDragTargets.has(document.activeElement)) { + document.activeElement.blur(); + } + if (dispatchConsider) { + dispatchConsiderEvent(focusedDz, dzToConfig.get(focusedDz).items, { + trigger: TRIGGERS.DRAG_STOPPED, + id: focusedItemId, + source: SOURCES.KEYBOARD + }); + } + styleInactiveDropZones( + typeToDropZones.get(draggedItemType), + (dz) => dzToConfig.get(dz).dropTargetStyle, + (dz) => dzToConfig.get(dz).dropTargetClasses + ); + focusedItem = null; + focusedItemId = null; + focusedItemLabel = ""; + draggedItemType = null; + focusedDz = null; + focusedDzLabel = ""; + isDragging = false; + triggerAllDzsUpdate(); +} +__name(handleDrop, "handleDrop"); +function dndzone$1(node, options) { + const config = { + items: void 0, + type: void 0, + dragDisabled: false, + zoneTabIndex: 0, + dropFromOthersDisabled: false, + dropTargetStyle: DEFAULT_DROP_TARGET_STYLE, + dropTargetClasses: [], + autoAriaDisabled: false + }; + function swap(arr, i, j) { + if (arr.length <= 1) + return; + arr.splice(j, 1, arr.splice(i, 1, arr[j])[0]); + } + __name(swap, "swap"); + function handleKeyDown(e) { + switch (e.key) { + case "Enter": + case " ": { + if ((e.target.disabled !== void 0 || e.target.href || e.target.isContentEditable) && !allDragTargets.has(e.target)) { + return; + } + e.preventDefault(); + e.stopPropagation(); + if (isDragging) { + handleDrop(); + } else { + handleDragStart(e); + } + break; + } + case "ArrowDown": + case "ArrowRight": { + if (!isDragging) + return; + e.preventDefault(); + e.stopPropagation(); + const { items } = dzToConfig.get(node); + const children2 = Array.from(node.children); + const idx = children2.indexOf(e.currentTarget); + if (idx < children2.length - 1) { + if (!config.autoAriaDisabled) { + alertToScreenReader(`Moved item ${focusedItemLabel} to position ${idx + 2} in the list ${focusedDzLabel}`); + } + swap(items, idx, idx + 1); + dispatchFinalizeEvent(node, items, { trigger: TRIGGERS.DROPPED_INTO_ZONE, id: focusedItemId, source: SOURCES.KEYBOARD }); + } + break; + } + case "ArrowUp": + case "ArrowLeft": { + if (!isDragging) + return; + e.preventDefault(); + e.stopPropagation(); + const { items } = dzToConfig.get(node); + const children2 = Array.from(node.children); + const idx = children2.indexOf(e.currentTarget); + if (idx > 0) { + if (!config.autoAriaDisabled) { + alertToScreenReader(`Moved item ${focusedItemLabel} to position ${idx} in the list ${focusedDzLabel}`); + } + swap(items, idx, idx - 1); + dispatchFinalizeEvent(node, items, { trigger: TRIGGERS.DROPPED_INTO_ZONE, id: focusedItemId, source: SOURCES.KEYBOARD }); + } + break; + } + } + } + __name(handleKeyDown, "handleKeyDown"); + function handleDragStart(e) { + setCurrentFocusedItem(e.currentTarget); + focusedDz = node; + draggedItemType = config.type; + isDragging = true; + const dropTargets = Array.from(typeToDropZones.get(config.type)).filter((dz) => dz === focusedDz || !dzToConfig.get(dz).dropFromOthersDisabled); + styleActiveDropZones( + dropTargets, + (dz) => dzToConfig.get(dz).dropTargetStyle, + (dz) => dzToConfig.get(dz).dropTargetClasses + ); + if (!config.autoAriaDisabled) { + let msg = `Started dragging item ${focusedItemLabel}. Use the arrow keys to move it within its list ${focusedDzLabel}`; + if (dropTargets.length > 1) { + msg += `, or tab to another list in order to move the item into it`; + } + alertToScreenReader(msg); + } + dispatchConsiderEvent(node, dzToConfig.get(node).items, { trigger: TRIGGERS.DRAG_STARTED, id: focusedItemId, source: SOURCES.KEYBOARD }); + triggerAllDzsUpdate(); + } + __name(handleDragStart, "handleDragStart"); + function handleClick(e) { + if (!isDragging) + return; + if (e.currentTarget === focusedItem) + return; + e.stopPropagation(); + handleDrop(false); + handleDragStart(e); + } + __name(handleClick, "handleClick"); + function setCurrentFocusedItem(draggableEl) { + const { items } = dzToConfig.get(node); + const children2 = Array.from(node.children); + const focusedItemIdx = children2.indexOf(draggableEl); + focusedItem = draggableEl; + focusedItem.tabIndex = 0; + focusedItemId = items[focusedItemIdx][ITEM_ID_KEY]; + focusedItemLabel = children2[focusedItemIdx].getAttribute("aria-label") || ""; + } + __name(setCurrentFocusedItem, "setCurrentFocusedItem"); + function configure({ + items = [], + type: newType = DEFAULT_DROP_ZONE_TYPE, + dragDisabled = false, + zoneTabIndex = 0, + dropFromOthersDisabled = false, + dropTargetStyle = DEFAULT_DROP_TARGET_STYLE, + dropTargetClasses = [], + autoAriaDisabled = false + }) { + config.items = [...items]; + config.dragDisabled = dragDisabled; + config.dropFromOthersDisabled = dropFromOthersDisabled; + config.zoneTabIndex = zoneTabIndex; + config.dropTargetStyle = dropTargetStyle; + config.dropTargetClasses = dropTargetClasses; + config.autoAriaDisabled = autoAriaDisabled; + if (config.type && newType !== config.type) { + unregisterDropZone(node, config.type); + } + config.type = newType; + registerDropZone(node, newType); + if (!autoAriaDisabled) { + node.setAttribute("aria-disabled", dragDisabled); + node.setAttribute("role", "list"); + node.setAttribute("aria-describedby", dragDisabled ? INSTRUCTION_IDs.DND_ZONE_DRAG_DISABLED : INSTRUCTION_IDs.DND_ZONE_ACTIVE); + } + dzToConfig.set(node, config); + if (isDragging) { + node.tabIndex = node === focusedDz || focusedItem.contains(node) || config.dropFromOthersDisabled || focusedDz && config.type !== dzToConfig.get(focusedDz).type ? -1 : 0; + } else { + node.tabIndex = config.zoneTabIndex; + } + node.addEventListener("focus", handleZoneFocus); + for (let i = 0; i < node.children.length; i++) { + const draggableEl = node.children[i]; + allDragTargets.add(draggableEl); + draggableEl.tabIndex = isDragging ? -1 : 0; + if (!autoAriaDisabled) { + draggableEl.setAttribute("role", "listitem"); + } + draggableEl.removeEventListener("keydown", elToKeyDownListeners.get(draggableEl)); + draggableEl.removeEventListener("click", elToFocusListeners.get(draggableEl)); + if (!dragDisabled) { + draggableEl.addEventListener("keydown", handleKeyDown); + elToKeyDownListeners.set(draggableEl, handleKeyDown); + draggableEl.addEventListener("click", handleClick); + elToFocusListeners.set(draggableEl, handleClick); + } + if (isDragging && config.items[i][ITEM_ID_KEY] === focusedItemId) { + focusedItem = draggableEl; + focusedItem.tabIndex = 0; + draggableEl.focus(); + } + } + } + __name(configure, "configure"); + configure(options); + const handles = { + update: (newOptions) => { + configure(newOptions); + }, + destroy: () => { + unregisterDropZone(node, config.type); + dzToConfig.delete(node); + dzToHandles.delete(node); + } + }; + dzToHandles.set(node, handles); + return handles; +} +__name(dndzone$1, "dndzone$1"); +function dndzone(node, options) { + validateOptions(options); + const pointerZone = dndzone$2(node, options); + const keyboardZone = dndzone$1(node, options); + return { + update: (newOptions) => { + validateOptions(newOptions); + pointerZone.update(newOptions); + keyboardZone.update(newOptions); + }, + destroy: () => { + pointerZone.destroy(); + keyboardZone.destroy(); + } + }; +} +__name(dndzone, "dndzone"); +function validateOptions(options) { + const { + items, + flipDurationMs: flipDurationMs2, + type, + dragDisabled, + morphDisabled, + dropFromOthersDisabled, + zoneTabIndex, + dropTargetStyle, + dropTargetClasses, + transformDraggedElement, + autoAriaDisabled, + centreDraggedOnCursor, + ...rest + } = options; + if (Object.keys(rest).length > 0) { + console.warn(`dndzone will ignore unknown options`, rest); + } + if (!items) { + throw new Error("no 'items' key provided to dndzone"); + } + const itemWithMissingId = items.find((item) => !{}.hasOwnProperty.call(item, ITEM_ID_KEY)); + if (itemWithMissingId) { + throw new Error(`missing '${ITEM_ID_KEY}' property for item ${toString(itemWithMissingId)}`); + } + if (dropTargetClasses && !Array.isArray(dropTargetClasses)) { + throw new Error(`dropTargetClasses should be an array but instead it is a ${typeof dropTargetClasses}, ${toString(dropTargetClasses)}`); + } + if (zoneTabIndex && !isInt(zoneTabIndex)) { + throw new Error(`zoneTabIndex should be a number but instead it is a ${typeof zoneTabIndex}, ${toString(zoneTabIndex)}`); + } +} +__name(validateOptions, "validateOptions"); +function isInt(value) { + return !isNaN(value) && function(x) { + return (x | 0) === x; + }(parseFloat(value)); +} +__name(isInt, "isInt"); +function setupCaches() { + Hooks.on(CONSTANTS.HOOKS.PILE.DELETE, (doc) => { + const uuid = getUuid(doc); + let actor = getActor(doc); + if (actor instanceof Actor) { + actor = actor.toObject(); + } + deletedActorCache.set(uuid, actor); + }); +} +__name(setupCaches, "setupCaches"); +class DebouncedCache extends Map { + #debounceClear = {}; + #timeout = {}; + constructor(timeout = 50) { + super(); + this.#timeout = timeout; + } + set(key, value) { + this.#setDebounce(key); + return super.set(key, value); + } + #setDebounce(key) { + if (!this.#debounceClear[key]) { + this.#debounceClear[key] = foundry.utils.debounce(() => { + delete this.#debounceClear[key]; + this.delete(key); + }, this.#timeout); + } + this.#debounceClear[key](); + } +} +__name(DebouncedCache, "DebouncedCache"); +const deletedActorCache = new DebouncedCache(5e3); +const cachedActorCurrencies = new DebouncedCache(); +const cachedFilterList = new DebouncedCache(); +const cachedCurrencyList = new DebouncedCache(); +function getActivePlayers(onlyActive = false) { + return Array.from(game.users).filter((u) => (u.active || !onlyActive) && u.character); +} +__name(getActivePlayers, "getActivePlayers"); +function getPlayersForItemPile(target) { + const targetActor = getActor(target); + if (!isValidItemPile(targetActor)) + return []; + const pileData = getActorFlagData(targetActor); + return getActivePlayers(pileData.activePlayers); +} +__name(getPlayersForItemPile, "getPlayersForItemPile"); +function canItemPileBeSplit(target) { + const pileData = getActorFlagData(target); + const shareData = getItemPileSharingData(target); + const playerActors = getPlayersForItemPile(target).map((player) => getUserCharacter(player)); + const items = pileData.shareItemsEnabled ? getActorItems(target) : []; + const currencies = pileData.shareCurrenciesEnabled || pileData.splitAllEnabled ? getActorCurrencies(target) : []; + for (const item of items) { + if (playerActors.every((character) => getItemSharesLeftForActor(target, item, character, { + shareData, + floor: true, + players: playerActors.length + }))) { + return true; + } + } + for (const currency of currencies) { + if (currency.type === "item") { + if (playerActors.every((character) => getItemSharesLeftForActor(target, currency.item, character, { + shareData, + floor: true, + players: playerActors.length + }))) { + return true; + } + } else { + if (playerActors.every((character) => getAttributeSharesLeftForActor(target, currency.path, character, { + shareData, + floor: true, + players: playerActors.length + }))) { + return true; + } + } + } + return false; +} +__name(canItemPileBeSplit, "canItemPileBeSplit"); +function getItemPileSharingData(target) { + const targetActor = getActor(target); + return foundry.utils.duplicate(getProperty(targetActor, CONSTANTS.FLAGS.SHARING) ?? {}); +} +__name(getItemPileSharingData, "getItemPileSharingData"); +function updateItemPileSharingData(target, incomingSharingData) { + const targetActor = getActor(target); + const currentSharingData = getItemPileSharingData(targetActor); + const newSharingData = foundry.utils.mergeObject(currentSharingData, incomingSharingData); + return targetActor.update({ + [CONSTANTS.FLAGS.SHARING]: newSharingData + }); +} +__name(updateItemPileSharingData, "updateItemPileSharingData"); +function clearItemPileSharingData(target) { + const targetActor = getActor(target); + return targetActor.update({ + [CONSTANTS.FLAGS.SHARING]: null + }); +} +__name(clearItemPileSharingData, "clearItemPileSharingData"); +async function setItemPileSharingData(sourceUuid, targetUuid, { items = [], attributes = [] } = {}) { + const sourceActor = getActor(sourceUuid); + const targetActor = getActor(targetUuid); + const sourceIsItemPile = isValidItemPile(sourceActor); + const targetIsItemPile = isValidItemPile(targetActor); + if (sourceIsItemPile && targetIsItemPile) + return; + if (items.length) { + items = items.map((itemData) => { + setItemQuantity(itemData.item, Math.abs(itemData.quantity)); + return itemData.item; + }); + } + if (!Array.isArray(attributes) && typeof attributes === "object") { + attributes = Object.entries(attributes).map((entry) => { + return { + path: entry[0], + quantity: Math.abs(entry[1]) + }; + }); + } + if (sourceIsItemPile) { + if (isItemPileEmpty(sourceIsItemPile)) { + return clearItemPileSharingData(sourceIsItemPile); + } + const sharingData2 = addToItemPileSharingData(sourceActor, targetActor.uuid, { items, attributes }); + return updateItemPileSharingData(sourceActor, sharingData2); + } + const sharingData = removeFromItemPileSharingData(targetActor, sourceActor.uuid, { items, attributes }); + return updateItemPileSharingData(targetActor, sharingData); +} +__name(setItemPileSharingData, "setItemPileSharingData"); +function addToItemPileSharingData(itemPile, actorUuid, { + sharingData = false, + items = [], + attributes = [] +} = {}) { + const pileData = getActorFlagData(itemPile); + const pileCurrencies = getActorCurrencies(itemPile, { getAll: true }); + const filteredItems = items.filter((item) => !pileCurrencies.some((currency) => item.id !== currency.id)); + const currencies = items.filter((item) => !pileCurrencies.some((currency) => item.id === currency.id)); + let pileSharingData = {}; + if (!sharingData && (pileData.shareItemsEnabled && filteredItems.length || pileData.shareCurrenciesEnabled && (attributes.length || currencies.length))) { + pileSharingData = getItemPileSharingData(itemPile); + } + if (pileData.shareItemsEnabled && filteredItems.length || pileData.shareCurrenciesEnabled && currencies.length) { + if (!pileSharingData.items) { + pileSharingData.items = []; + } + for (const item of filteredItems.concat(currencies)) { + let existingItem = findSimilarItem(pileSharingData.items, item); + if (!existingItem) { + let itemIndex = pileSharingData.items.push(setSimilarityProperties({ + actors: [{ uuid: actorUuid, quantity: 0 }] + }, item)); + existingItem = pileSharingData.items[itemIndex - 1]; + } else if (!existingItem.actors) { + existingItem.actors = []; + existingItem._id = item.id; + } + let actorData = existingItem.actors.find((data2) => data2.uuid === actorUuid); + const itemQuantity = getItemQuantity(item); + if (!actorData) { + if (itemQuantity > 0) { + existingItem.actors.push({ uuid: actorUuid, quantity: itemQuantity }); + } + } else { + actorData.quantity += itemQuantity; + if (actorData.quantity <= 0) { + existingItem.actors.splice(existingItem.actors.indexOf(actorData), 1); + } + if (existingItem.actors.length === 0) { + pileSharingData.items.splice(pileSharingData.items.indexOf(existingItem), 1); + } + } + } + } + if (pileData.shareCurrenciesEnabled && attributes.length) { + if (!pileSharingData.attributes) { + pileSharingData.attributes = []; + } + for (const attribute of attributes) { + let existingCurrency = pileSharingData.attributes.find((sharingCurrency) => sharingCurrency.path === attribute.path); + if (!existingCurrency) { + let itemIndex = pileSharingData.attributes.push({ + path: attribute.path, + actors: [{ uuid: actorUuid, quantity: 0 }] + }); + existingCurrency = pileSharingData.attributes[itemIndex - 1]; + } else { + if (!existingCurrency.actors) { + existingCurrency.actors = []; + } + } + let actorData = existingCurrency.actors.find((data2) => data2.uuid === actorUuid); + if (!actorData) { + if (attribute.quantity > 0) { + existingCurrency.actors.push({ uuid: actorUuid, quantity: attribute.quantity }); + } + } else { + actorData.quantity += attribute.quantity; + if (actorData.quantity <= 0) { + existingCurrency.actors.splice(existingCurrency.actors.indexOf(actorData), 1); + } + if (existingCurrency.actors.length === 0) { + pileSharingData.attributes.splice(pileSharingData.attributes.indexOf(existingCurrency), 1); + } + } + } + } + return pileSharingData; +} +__name(addToItemPileSharingData, "addToItemPileSharingData"); +function removeFromItemPileSharingData(itemPile, actorUuid, { items = [], attributes = [] } = {}) { + items = items.map((item) => { + setItemQuantity(item, getItemQuantity(item) * -1); + return item; + }); + attributes = attributes.map((attribute) => { + attribute.quantity = attribute.quantity * -1; + return attribute; + }); + return addToItemPileSharingData(itemPile, actorUuid, { items, attributes }); +} +__name(removeFromItemPileSharingData, "removeFromItemPileSharingData"); +function getItemSharesLeftForActor(pile, item, recipient, { + currentQuantity = null, + floor = null, + players = null, + shareData = null +} = {}) { + if (item instanceof String) { + item = pile.items.get(item); + } + let previouslyTaken = 0; + let recipientUuid = getUuid(recipient); + currentQuantity = currentQuantity ?? Math.abs(getItemQuantity(item)); + let totalShares = currentQuantity; + shareData = shareData ?? getItemPileSharingData(pile); + if (shareData?.items?.length) { + const foundItem = findSimilarItem(shareData.items, item); + if (foundItem) { + totalShares = foundItem.actors.reduce((acc, actor) => acc + actor.quantity, currentQuantity); + const quantityTakenBefore = foundItem.actors.find((actor) => actor.uuid === recipientUuid); + previouslyTaken = quantityTakenBefore ? quantityTakenBefore.quantity : 0; + } + } + players = players ?? getPlayersForItemPile(pile).length; + let totalActorShare = totalShares / players; + if (!Number.isInteger(totalActorShare) && !floor) { + totalActorShare += 1; + } + return Math.max(0, Math.min(currentQuantity, Math.floor(totalActorShare - previouslyTaken))); +} +__name(getItemSharesLeftForActor, "getItemSharesLeftForActor"); +function getAttributeSharesLeftForActor(pile, path, recipient, { + currentQuantity = null, + floor = null, + players = null, + shareData = null +} = {}) { + let previouslyTaken = 0; + let recipientUuid = getUuid(recipient); + currentQuantity = currentQuantity ?? Number(getProperty(pile, path) ?? 0); + let totalShares = currentQuantity; + shareData = shareData ?? getItemPileSharingData(pile); + if (shareData?.attributes?.length) { + const existingCurrency = shareData.attributes.find((storedCurrency) => storedCurrency.path === path); + if (existingCurrency) { + totalShares = existingCurrency.actors.reduce((acc, actor) => acc + actor.quantity, currentQuantity); + const quantityTakenBefore = existingCurrency?.actors?.find((actor) => actor.uuid === recipientUuid); + previouslyTaken = quantityTakenBefore ? quantityTakenBefore.quantity : 0; + } + } + players = players ?? getPlayersForItemPile(pile).length; + let totalActorShare = totalShares / players; + if (!Number.isInteger(totalActorShare) && !floor) { + totalActorShare += 1; + } + return Math.max(0, Math.min(currentQuantity, Math.floor(totalActorShare - previouslyTaken))); +} +__name(getAttributeSharesLeftForActor, "getAttributeSharesLeftForActor"); +function create_if_block_3$m(ctx) { + let p; + let t_value = localize(`ITEM-PILES.Applications.${/*application*/ + ctx[5].options.localizationTitle}.Content`, { target_name: ( + /*target*/ + ctx[2].name + ) }) + ""; + let t; + return { + c() { + p = element("p"); + t = text(t_value); + attr(p, "class", "item-piles-text-center"); + }, + m(target, anchor) { + insert(target, p, anchor); + append(p, t); + }, + p(ctx2, dirty) { + if (dirty & /*target*/ + 4 && t_value !== (t_value = localize(`ITEM-PILES.Applications.${/*application*/ + ctx2[5].options.localizationTitle}.Content`, { target_name: ( + /*target*/ + ctx2[2].name + ) }) + "")) + set_data(t, t_value); + }, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_if_block_3$m, "create_if_block_3$m"); +function create_if_block_1$C(ctx) { + let div; + let label; + let t0_value = localize( + `ITEM-PILES.Applications.${/*application*/ + ctx[5].options.localizationTitle}.${/*unlimitedQuantity*/ + ctx[6] ? "ContentInfiniteQuantity" : "ContentMultipleQuantity"}`, + { + target_name: ( + /*target*/ + ctx[2]?.name ?? "" + ), + quantity: ( + /*itemQuantity*/ + ctx[7] + ), + itemName: ( + /*item*/ + ctx[1].name + ) + } + ) + ""; + let t0; + let t1; + let current_block_type_index; + let if_block; + let if_block_anchor; + let current; + const if_block_creators = [create_if_block_2$r, create_else_block_1$8]; + const if_blocks = []; + function select_block_type(ctx2, dirty) { + if ( + /*unlimitedQuantity*/ + ctx2[6] + ) + return 0; + return 1; + } + __name(select_block_type, "select_block_type"); + current_block_type_index = select_block_type(ctx); + if_block = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx); + return { + c() { + div = element("div"); + label = element("label"); + t0 = text(t0_value); + t1 = space(); + if_block.c(); + if_block_anchor = empty(); + attr(div, "class", "form-group item-piles-text-center"); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, label); + append(label, t0); + insert(target, t1, anchor); + if_blocks[current_block_type_index].m(target, anchor); + insert(target, if_block_anchor, anchor); + current = true; + }, + p(ctx2, dirty) { + if ((!current || dirty & /*target, item*/ + 6) && t0_value !== (t0_value = localize( + `ITEM-PILES.Applications.${/*application*/ + ctx2[5].options.localizationTitle}.${/*unlimitedQuantity*/ + ctx2[6] ? "ContentInfiniteQuantity" : "ContentMultipleQuantity"}`, + { + target_name: ( + /*target*/ + ctx2[2]?.name ?? "" + ), + quantity: ( + /*itemQuantity*/ + ctx2[7] + ), + itemName: ( + /*item*/ + ctx2[1].name + ) + } + ) + "")) + set_data(t0, t0_value); + if_block.p(ctx2, dirty); + }, + i(local) { + if (current) + return; + transition_in(if_block); + current = true; + }, + o(local) { + transition_out(if_block); + current = false; + }, + d(detaching) { + if (detaching) + detach(div); + if (detaching) + detach(t1); + if_blocks[current_block_type_index].d(detaching); + if (detaching) + detach(if_block_anchor); + } + }; +} +__name(create_if_block_1$C, "create_if_block_1$C"); +function create_else_block_1$8(ctx) { + let sliderinput; + let updating_value; + let current; + function sliderinput_value_binding(value) { + ctx[13](value); + } + __name(sliderinput_value_binding, "sliderinput_value_binding"); + let sliderinput_props = { + min: 1, + max: ( + /*sliderQuantity*/ + ctx[8] + ), + maxInput: ( + /*sliderQuantity*/ + ctx[8] + ), + divideBy: 1 + }; + if ( + /*quantity*/ + ctx[4] !== void 0 + ) { + sliderinput_props.value = /*quantity*/ + ctx[4]; + } + sliderinput = new SliderInput({ props: sliderinput_props }); + binding_callbacks.push(() => bind(sliderinput, "value", sliderinput_value_binding)); + return { + c() { + create_component(sliderinput.$$.fragment); + }, + m(target, anchor) { + mount_component(sliderinput, target, anchor); + current = true; + }, + p(ctx2, dirty) { + const sliderinput_changes = {}; + if (!updating_value && dirty & /*quantity*/ + 16) { + updating_value = true; + sliderinput_changes.value = /*quantity*/ + ctx2[4]; + add_flush_callback(() => updating_value = false); + } + sliderinput.$set(sliderinput_changes); + }, + i(local) { + if (current) + return; + transition_in(sliderinput.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(sliderinput.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(sliderinput, detaching); + } + }; +} +__name(create_else_block_1$8, "create_else_block_1$8"); +function create_if_block_2$r(ctx) { + let input; + let mounted; + let dispose; + return { + c() { + input = element("input"); + attr(input, "type", "number"); + attr(input, "min", "1"); + }, + m(target, anchor) { + insert(target, input, anchor); + set_input_value( + input, + /*quantity*/ + ctx[4] + ); + if (!mounted) { + dispose = listen( + input, + "input", + /*input_input_handler*/ + ctx[12] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*quantity*/ + 16 && to_number(input.value) !== /*quantity*/ + ctx2[4]) { + set_input_value( + input, + /*quantity*/ + ctx2[4] + ); + } + }, + i: noop, + o: noop, + d(detaching) { + if (detaching) + detach(input); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_2$r, "create_if_block_2$r"); +function create_else_block$k(ctx) { + let button; + let i; + let t0; + let t1_value = localize(`ITEM-PILES.Applications.${/*application*/ + ctx[5].options.localizationTitle}.SubmitNoTarget`) + ""; + let t1; + let mounted; + let dispose; + return { + c() { + button = element("button"); + i = element("i"); + t0 = space(); + t1 = text(t1_value); + attr(i, "class", "fas fa-box"); + attr(button, "type", "button"); + }, + m(target, anchor) { + insert(target, button, anchor); + append(button, i); + append(button, t0); + append(button, t1); + if (!mounted) { + dispose = listen( + button, + "click", + /*requestSubmit*/ + ctx[10], + { once: true } + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(button); + mounted = false; + dispose(); + } + }; +} +__name(create_else_block$k, "create_else_block$k"); +function create_if_block$P(ctx) { + let button; + let i; + let t0; + let t1_value = localize(`ITEM-PILES.Applications.${/*application*/ + ctx[5].options.localizationTitle}.Submit`) + ""; + let t1; + let mounted; + let dispose; + return { + c() { + button = element("button"); + i = element("i"); + t0 = space(); + t1 = text(t1_value); + attr(i, "class", "fas fa-download"); + attr(button, "type", "button"); + }, + m(target, anchor) { + insert(target, button, anchor); + append(button, i); + append(button, t0); + append(button, t1); + if (!mounted) { + dispose = listen( + button, + "click", + /*requestSubmit*/ + ctx[10], + { once: true } + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(button); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block$P, "create_if_block$P"); +function create_default_slot$n(ctx) { + let form_1; + let h3; + let t0_value = localize(`ITEM-PILES.Applications.${/*application*/ + ctx[5].options.localizationTitle}.Header`, { item_name: ( + /*item*/ + ctx[1].name + ) }) + ""; + let t0; + let t1; + let t2; + let t3; + let footer; + let t4; + let button; + let i; + let t5; + let t6_value = localize("Cancel") + ""; + let t6; + let current; + let mounted; + let dispose; + let if_block0 = ( + /*target*/ + ctx[2] && create_if_block_3$m(ctx) + ); + let if_block1 = ( + /*itemQuantity*/ + (ctx[7] > 1 || /*unlimitedQuantity*/ + ctx[6]) && /*canItemStack*/ + ctx[9] && create_if_block_1$C(ctx) + ); + function select_block_type_1(ctx2, dirty) { + if ( + /*target*/ + ctx2[2] + ) + return create_if_block$P; + return create_else_block$k; + } + __name(select_block_type_1, "select_block_type_1"); + let current_block_type = select_block_type_1(ctx); + let if_block2 = current_block_type(ctx); + return { + c() { + form_1 = element("form"); + h3 = element("h3"); + t0 = text(t0_value); + t1 = space(); + if (if_block0) + if_block0.c(); + t2 = space(); + if (if_block1) + if_block1.c(); + t3 = space(); + footer = element("footer"); + if_block2.c(); + t4 = space(); + button = element("button"); + i = element("i"); + t5 = space(); + t6 = text(t6_value); + set_style(h3, "text-align", "center"); + attr(i, "class", "fas fa-times"); + attr(button, "type", "button"); + attr(footer, "class", "sheet-footer item-piles-flexrow"); + set_style(footer, "margin-top", "1rem"); + attr(form_1, "autocomplete", "off"); + attr(form_1, "class", "item-piles-flexcol"); + set_style(form_1, "padding", "0.5rem"); + }, + m(target, anchor) { + insert(target, form_1, anchor); + append(form_1, h3); + append(h3, t0); + append(form_1, t1); + if (if_block0) + if_block0.m(form_1, null); + append(form_1, t2); + if (if_block1) + if_block1.m(form_1, null); + append(form_1, t3); + append(form_1, footer); + if_block2.m(footer, null); + append(footer, t4); + append(footer, button); + append(button, i); + append(button, t5); + append(button, t6); + ctx[15](form_1); + current = true; + if (!mounted) { + dispose = [ + listen( + button, + "click", + /*click_handler*/ + ctx[14] + ), + listen(form_1, "submit", prevent_default( + /*submit*/ + ctx[11] + ), { once: true }) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if ((!current || dirty & /*item*/ + 2) && t0_value !== (t0_value = localize(`ITEM-PILES.Applications.${/*application*/ + ctx2[5].options.localizationTitle}.Header`, { item_name: ( + /*item*/ + ctx2[1].name + ) }) + "")) + set_data(t0, t0_value); + if ( + /*target*/ + ctx2[2] + ) { + if (if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0 = create_if_block_3$m(ctx2); + if_block0.c(); + if_block0.m(form_1, t2); + } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; + } + if ( + /*itemQuantity*/ + (ctx2[7] > 1 || /*unlimitedQuantity*/ + ctx2[6]) && /*canItemStack*/ + ctx2[9] + ) + if_block1.p(ctx2, dirty); + if (current_block_type === (current_block_type = select_block_type_1(ctx2)) && if_block2) { + if_block2.p(ctx2, dirty); + } else { + if_block2.d(1); + if_block2 = current_block_type(ctx2); + if (if_block2) { + if_block2.c(); + if_block2.m(footer, t4); + } + } + }, + i(local) { + if (current) + return; + transition_in(if_block1); + current = true; + }, + o(local) { + transition_out(if_block1); + current = false; + }, + d(detaching) { + if (detaching) + detach(form_1); + if (if_block0) + if_block0.d(); + if (if_block1) + if_block1.d(); + if_block2.d(); + ctx[15](null); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$n, "create_default_slot$n"); +function create_fragment$13(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[16](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot$n] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, [dirty]) { + const applicationshell_changes = {}; + if (dirty & /*$$scope, form, target, quantity, item*/ + 131102) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment$13, "create_fragment$13"); +function instance$13($$self, $$props, $$invalidate) { + const { application } = getContext("#external"); + let { item } = $$props; + let { elementRoot } = $$props; + let { target = false } = $$props; + const unlimitedQuantity = application.options?.unlimitedQuantity ?? false; + let form; + let quantity = 1; + const itemQuantity = getItemQuantity(item); + const sliderQuantity = itemQuantity + (application.options?.quantityAdjustment ?? 0); + const canItemStack$1 = canItemStack(item, target); + function requestSubmit() { + form.requestSubmit(); + } + __name(requestSubmit, "requestSubmit"); + function submit() { + application.options.resolve(quantity); + application.close(); + } + __name(submit, "submit"); + function input_input_handler() { + quantity = to_number(this.value); + $$invalidate(4, quantity); + } + __name(input_input_handler, "input_input_handler"); + function sliderinput_value_binding(value) { + quantity = value; + $$invalidate(4, quantity); + } + __name(sliderinput_value_binding, "sliderinput_value_binding"); + const click_handler = /* @__PURE__ */ __name(() => { + application.close(); + }, "click_handler"); + function form_1_binding($$value) { + binding_callbacks[$$value ? "unshift" : "push"](() => { + form = $$value; + $$invalidate(3, form); + }); + } + __name(form_1_binding, "form_1_binding"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("item" in $$props2) + $$invalidate(1, item = $$props2.item); + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + if ("target" in $$props2) + $$invalidate(2, target = $$props2.target); + }; + return [ + elementRoot, + item, + target, + form, + quantity, + application, + unlimitedQuantity, + itemQuantity, + sliderQuantity, + canItemStack$1, + requestSubmit, + submit, + input_input_handler, + sliderinput_value_binding, + click_handler, + form_1_binding, + applicationshell_elementRoot_binding + ]; +} +__name(instance$13, "instance$13"); +class Drop_item_dialog_shell extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$13, create_fragment$13, safe_not_equal, { item: 1, elementRoot: 0, target: 2 }); + } + get item() { + return this.$$.ctx[1]; + } + set item(item) { + this.$$set({ item }); + flush(); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } + get target() { + return this.$$.ctx[2]; + } + set target(target) { + this.$$set({ target }); + flush(); + } +} +__name(Drop_item_dialog_shell, "Drop_item_dialog_shell"); +class DropItemDialog extends SvelteApplication { + /** + * + * @param item + * @param target + * @param options + */ + constructor(item, target, options = { + localizationTitle: "DropItem" + }) { + super({ + title: game.i18n.localize(`ITEM-PILES.Applications.${options.localizationTitle}.Title`), + id: `item-pile-drop-item-${item.id}${target ? "-" + target.id : ""}-${randomID()}`, + svelte: { + class: Drop_item_dialog_shell, + target: document.body, + props: { + item, + target + } + }, + close: () => this.options.resolve?.(null), + ...options + }); + this.item = item; + this.target = target; + } + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + width: 430, + height: "auto", + classes: ["item-piles-app"] + }); + } + static getActiveApps(id) { + return getActiveApps(`item-pile-drop-item-${id}`); + } + static async show(item, target, options = {}) { + if (!options?.localizationTitle) { + options.localizationTitle = "DropItem"; + } + const apps = this.getActiveApps(item.uuid + (target ? "-" + target.uuid : "")); + if (apps.length) { + for (let app of apps) { + app.render(false, { focus: true }); + } + return; + } + return new Promise((resolve) => { + options.resolve = resolve; + new this(item, target, options).render(true, { focus: true }); + }); + } +} +__name(DropItemDialog, "DropItemDialog"); +function create_if_block_5$a(ctx) { + let span; + let t0; + let t1; + let t2; + return { + c() { + span = element("span"); + t0 = text("(x"); + t1 = text( + /*$quantity*/ + ctx[6] + ); + t2 = text(")"); + attr(span, "class", "item-piles-small-text"); + }, + m(target, anchor) { + insert(target, span, anchor); + append(span, t0); + append(span, t1); + append(span, t2); + }, + p(ctx2, dirty) { + if (dirty & /*$quantity*/ + 64) + set_data( + t1, + /*$quantity*/ + ctx2[6] + ); + }, + d(detaching) { + if (detaching) + detach(span); + } + }; +} +__name(create_if_block_5$a, "create_if_block_5$a"); +function create_if_block_2$q(ctx) { + let div; + function select_block_type(ctx2, dirty) { + if ( + /*$editQuantities*/ + ctx2[4] + ) + return create_if_block_3$l; + if ( + /*$quantityLeft*/ + ctx2[5] && /*$quantity*/ + ctx2[6] + ) + return create_if_block_4$e; + return create_else_block$j; + } + __name(select_block_type, "select_block_type"); + let current_block_type = select_block_type(ctx); + let if_block = current_block_type(ctx); + return { + c() { + div = element("div"); + if_block.c(); + attr(div, "class", "item-piles-quantity-container"); + set_style(div, "flex", "2.5"); + }, + m(target, anchor) { + insert(target, div, anchor); + if_block.m(div, null); + }, + p(ctx2, dirty) { + if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block) { + if_block.p(ctx2, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx2); + if (if_block) { + if_block.c(); + if_block.m(div, null); + } + } + }, + d(detaching) { + if (detaching) + detach(div); + if_block.d(); + } + }; +} +__name(create_if_block_2$q, "create_if_block_2$q"); +function create_else_block$j(ctx) { + let span; + let t_value = localize(`ITEM-PILES.Inspect.${/*entry*/ + ctx[1].toShare && /*$quantity*/ + ctx[6] ? "NoShareLeft" : "NoneLeft"}`) + ""; + let t; + return { + c() { + span = element("span"); + t = text(t_value); + }, + m(target, anchor) { + insert(target, span, anchor); + append(span, t); + }, + p(ctx2, dirty) { + if (dirty & /*entry, $quantity*/ + 66 && t_value !== (t_value = localize(`ITEM-PILES.Inspect.${/*entry*/ + ctx2[1].toShare && /*$quantity*/ + ctx2[6] ? "NoShareLeft" : "NoneLeft"}`) + "")) + set_data(t, t_value); + }, + d(detaching) { + if (detaching) + detach(span); + } + }; +} +__name(create_else_block$j, "create_else_block$j"); +function create_if_block_4$e(ctx) { + let div; + let input; + let input_disabled_value; + let t0; + let span; + let t1; + let t2; + let mounted; + let dispose; + return { + c() { + div = element("div"); + input = element("input"); + t0 = space(); + span = element("span"); + t1 = text("/ "); + t2 = text( + /*$quantityLeft*/ + ctx[5] + ); + attr(input, "class", "item-piles-quantity"); + attr(input, "type", "number"); + attr(input, "min", "1"); + attr( + input, + "max", + /*$quantity*/ + ctx[6] + ); + input.disabled = input_disabled_value = !/*$quantity*/ + ctx[6]; + attr(span, "class", "item-piles-input-divider"); + toggle_class(span, "item-piles-text-right", !/*store*/ + ctx[0].recipient); + attr(div, "class", "item-piles-quantity-input-container"); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, input); + set_input_value( + input, + /*$currentQuantity*/ + ctx[10] + ); + append(div, t0); + append(div, span); + append(span, t1); + append(span, t2); + if (!mounted) { + dispose = listen( + input, + "input", + /*input_input_handler_1*/ + ctx[24] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*$quantity*/ + 64) { + attr( + input, + "max", + /*$quantity*/ + ctx2[6] + ); + } + if (dirty & /*$quantity*/ + 64 && input_disabled_value !== (input_disabled_value = !/*$quantity*/ + ctx2[6])) { + input.disabled = input_disabled_value; + } + if (dirty & /*$currentQuantity*/ + 1024 && to_number(input.value) !== /*$currentQuantity*/ + ctx2[10]) { + set_input_value( + input, + /*$currentQuantity*/ + ctx2[10] + ); + } + if (dirty & /*$quantityLeft*/ + 32) + set_data( + t2, + /*$quantityLeft*/ + ctx2[5] + ); + if (dirty & /*store*/ + 1) { + toggle_class(span, "item-piles-text-right", !/*store*/ + ctx2[0].recipient); + } + }, + d(detaching) { + if (detaching) + detach(div); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_4$e, "create_if_block_4$e"); +function create_if_block_3$l(ctx) { + let div; + let input; + let mounted; + let dispose; + return { + c() { + div = element("div"); + input = element("input"); + attr(input, "class", "item-piles-quantity"); + attr(input, "type", "number"); + attr(input, "min", "0"); + attr(input, "draggable", "true"); + attr(div, "class", "item-piles-quantity-input-container"); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, input); + set_input_value( + input, + /*$quantity*/ + ctx[6] + ); + if (!mounted) { + dispose = [ + listen( + input, + "input", + /*input_input_handler*/ + ctx[23] + ), + listen(input, "dragstart", stop_propagation(prevent_default( + /*dragstart_handler*/ + ctx[21] + ))) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*$quantity*/ + 64 && to_number(input.value) !== /*$quantity*/ + ctx2[6]) { + set_input_value( + input, + /*$quantity*/ + ctx2[6] + ); + } + }, + d(detaching) { + if (detaching) + detach(div); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_if_block_3$l, "create_if_block_3$l"); +function create_if_block_1$B(ctx) { + let button; + let t_value = localize("Remove") + ""; + let t; + let button_disabled_value; + let mounted; + let dispose; + return { + c() { + button = element("button"); + t = text(t_value); + attr(button, "class", "item-piles-item-take-button"); + attr(button, "type", "button"); + button.disabled = button_disabled_value = !/*$quantityLeft*/ + ctx[5]; + }, + m(target, anchor) { + insert(target, button, anchor); + append(button, t); + if (!mounted) { + dispose = listen( + button, + "click", + /*click_handler_2*/ + ctx[26] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*$quantityLeft*/ + 32 && button_disabled_value !== (button_disabled_value = !/*$quantityLeft*/ + ctx2[5])) { + button.disabled = button_disabled_value; + } + }, + d(detaching) { + if (detaching) + detach(button); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_1$B, "create_if_block_1$B"); +function create_if_block$O(ctx) { + let button; + let t_value = localize("ITEM-PILES.Inspect.Take") + ""; + let t; + let button_disabled_value; + let mounted; + let dispose; + return { + c() { + button = element("button"); + t = text(t_value); + attr(button, "class", "item-piles-item-take-button"); + attr(button, "type", "button"); + button.disabled = button_disabled_value = !/*$quantityLeft*/ + ctx[5] || !/*$quantity*/ + ctx[6]; + }, + m(target, anchor) { + insert(target, button, anchor); + append(button, t); + if (!mounted) { + dispose = listen( + button, + "click", + /*click_handler_1*/ + ctx[25] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*$quantityLeft, $quantity*/ + 96 && button_disabled_value !== (button_disabled_value = !/*$quantityLeft*/ + ctx2[5] || !/*$quantity*/ + ctx2[6])) { + button.disabled = button_disabled_value; + } + }, + d(detaching) { + if (detaching) + detach(button); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block$O, "create_if_block$O"); +function create_fragment$12(ctx) { + let div3; + let div0; + let img_1; + let img_1_src_value; + let t0; + let div2; + let div1; + let p; + let t1; + let t2; + let t3; + let t4; + let div3_draggable_value; + let div3_transition; + let current; + let mounted; + let dispose; + let if_block0 = !/*$editQuantities*/ + ctx[4] && /*entry*/ + ctx[1].canStack && !/*currency*/ + ctx[2] && create_if_block_5$a(ctx); + let if_block1 = ( + /*entry*/ + (ctx[1].canStack || !/*entry*/ + ctx[1].id) && create_if_block_2$q(ctx) + ); + function select_block_type_1(ctx2, dirty) { + if (!/*$editQuantities*/ + ctx2[4]) + return create_if_block$O; + if (!/*entry*/ + ctx2[1].canStack && !/*entry*/ + ctx2[1].isCurrency) + return create_if_block_1$B; + } + __name(select_block_type_1, "select_block_type_1"); + let current_block_type = select_block_type_1(ctx); + let if_block2 = current_block_type && current_block_type(ctx); + return { + c() { + div3 = element("div"); + div0 = element("div"); + img_1 = element("img"); + t0 = space(); + div2 = element("div"); + div1 = element("div"); + p = element("p"); + t1 = text( + /*$name*/ + ctx[9] + ); + t2 = space(); + if (if_block0) + if_block0.c(); + t3 = space(); + if (if_block1) + if_block1.c(); + t4 = space(); + if (if_block2) + if_block2.c(); + attr(img_1, "class", "item-piles-img"); + if (!src_url_equal(img_1.src, img_1_src_value = /*$img*/ + ctx[7])) + attr(img_1, "src", img_1_src_value); + attr(div0, "class", "item-piles-img-container"); + set_style( + p, + "color", + /*$rarityColor*/ + ctx[8] || "inherit" + ); + toggle_class( + p, + "item-piles-clickable-link", + /*canInspectItems*/ + ctx[3] + ); + attr(div1, "class", "item-piles-name-container"); + attr(div2, "class", "item-piles-name"); + attr(div3, "class", "item-piles-flexrow item-piles-item-row item-piles-even-color"); + attr(div3, "draggable", div3_draggable_value = !!/*entry*/ + ctx[1].id); + toggle_class(div3, "item-piles-disabled", !/*$editQuantities*/ + ctx[4] && (!/*$quantityLeft*/ + ctx[5] || !/*$quantity*/ + ctx[6])); + }, + m(target, anchor) { + insert(target, div3, anchor); + append(div3, div0); + append(div0, img_1); + append(div3, t0); + append(div3, div2); + append(div2, div1); + append(div1, p); + append(p, t1); + append(div1, t2); + if (if_block0) + if_block0.m(div1, null); + append(div3, t3); + if (if_block1) + if_block1.m(div3, null); + append(div3, t4); + if (if_block2) + if_block2.m(div3, null); + current = true; + if (!mounted) { + dispose = [ + listen( + p, + "click", + /*click_handler*/ + ctx[22] + ), + listen( + div3, + "dragstart", + /*dragstart_handler_1*/ + ctx[27] + ) + ]; + mounted = true; + } + }, + p(ctx2, [dirty]) { + if (!current || dirty & /*$img*/ + 128 && !src_url_equal(img_1.src, img_1_src_value = /*$img*/ + ctx2[7])) { + attr(img_1, "src", img_1_src_value); + } + if (!current || dirty & /*$name*/ + 512) + set_data( + t1, + /*$name*/ + ctx2[9] + ); + if (!current || dirty & /*$rarityColor*/ + 256) { + set_style( + p, + "color", + /*$rarityColor*/ + ctx2[8] || "inherit" + ); + } + if (!current || dirty & /*canInspectItems*/ + 8) { + toggle_class( + p, + "item-piles-clickable-link", + /*canInspectItems*/ + ctx2[3] + ); + } + if (!/*$editQuantities*/ + ctx2[4] && /*entry*/ + ctx2[1].canStack && !/*currency*/ + ctx2[2]) { + if (if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0 = create_if_block_5$a(ctx2); + if_block0.c(); + if_block0.m(div1, null); + } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; + } + if ( + /*entry*/ + ctx2[1].canStack || !/*entry*/ + ctx2[1].id + ) { + if (if_block1) { + if_block1.p(ctx2, dirty); + } else { + if_block1 = create_if_block_2$q(ctx2); + if_block1.c(); + if_block1.m(div3, t4); + } + } else if (if_block1) { + if_block1.d(1); + if_block1 = null; + } + if (current_block_type === (current_block_type = select_block_type_1(ctx2)) && if_block2) { + if_block2.p(ctx2, dirty); + } else { + if (if_block2) + if_block2.d(1); + if_block2 = current_block_type && current_block_type(ctx2); + if (if_block2) { + if_block2.c(); + if_block2.m(div3, null); + } + } + if (!current || dirty & /*entry*/ + 2 && div3_draggable_value !== (div3_draggable_value = !!/*entry*/ + ctx2[1].id)) { + attr(div3, "draggable", div3_draggable_value); + } + if (!current || dirty & /*$editQuantities, $quantityLeft, $quantity*/ + 112) { + toggle_class(div3, "item-piles-disabled", !/*$editQuantities*/ + ctx2[4] && (!/*$quantityLeft*/ + ctx2[5] || !/*$quantity*/ + ctx2[6])); + } + }, + i(local) { + if (current) + return; + add_render_callback(() => { + if (!current) + return; + if (!div3_transition) + div3_transition = create_bidirectional_transition(div3, fade, { duration: 250 }, true); + div3_transition.run(1); + }); + current = true; + }, + o(local) { + if (!div3_transition) + div3_transition = create_bidirectional_transition(div3, fade, { duration: 250 }, false); + div3_transition.run(0); + current = false; + }, + d(detaching) { + if (detaching) + detach(div3); + if (if_block0) + if_block0.d(); + if (if_block1) + if_block1.d(); + if (if_block2) { + if_block2.d(); + } + if (detaching && div3_transition) + div3_transition.end(); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_fragment$12, "create_fragment$12"); +function instance$12($$self, $$props, $$invalidate) { + let canInspectItems; + let $pileData; + let $editQuantities; + let $quantityLeft; + let $quantity; + let $img; + let $rarityColor; + let $name; + let $currentQuantity; + let { store } = $$props; + let { entry } = $$props; + let { currency = false } = $$props; + const name = entry.name; + component_subscribe($$self, name, (value) => $$invalidate(9, $name = value)); + const img = entry.img; + component_subscribe($$self, img, (value) => $$invalidate(7, $img = value)); + const rarityColor = entry.rarityColor; + component_subscribe($$self, rarityColor, (value) => $$invalidate(8, $rarityColor = value)); + const quantityLeft = entry.quantityLeft; + component_subscribe($$self, quantityLeft, (value) => $$invalidate(5, $quantityLeft = value)); + const quantity = entry.quantity; + component_subscribe($$self, quantity, (value) => $$invalidate(6, $quantity = value)); + const currentQuantity = entry.currentQuantity; + component_subscribe($$self, currentQuantity, (value) => $$invalidate(10, $currentQuantity = value)); + const pileData = store.pileData; + component_subscribe($$self, pileData, (value) => $$invalidate(20, $pileData = value)); + const editQuantities = store.editQuantities; + component_subscribe($$self, editQuantities, (value) => $$invalidate(4, $editQuantities = value)); + function dragStart(event) { + event.dataTransfer.setData("text/plain", JSON.stringify({ type: "Item", uuid: entry.item.uuid })); + } + __name(dragStart, "dragStart"); + function dragstart_handler(event) { + bubble.call(this, $$self, event); + } + __name(dragstart_handler, "dragstart_handler"); + const click_handler = /* @__PURE__ */ __name(() => { + entry.preview(); + }, "click_handler"); + function input_input_handler() { + $quantity = to_number(this.value); + quantity.set($quantity); + } + __name(input_input_handler, "input_input_handler"); + function input_input_handler_1() { + $currentQuantity = to_number(this.value); + currentQuantity.set($currentQuantity); + } + __name(input_input_handler_1, "input_input_handler_1"); + const click_handler_1 = /* @__PURE__ */ __name(() => { + entry.take(); + }, "click_handler_1"); + const click_handler_2 = /* @__PURE__ */ __name(() => { + entry.remove(); + }, "click_handler_2"); + const dragstart_handler_1 = /* @__PURE__ */ __name((event) => { + dragStart(event); + }, "dragstart_handler_1"); + $$self.$$set = ($$props2) => { + if ("store" in $$props2) + $$invalidate(0, store = $$props2.store); + if ("entry" in $$props2) + $$invalidate(1, entry = $$props2.entry); + if ("currency" in $$props2) + $$invalidate(2, currency = $$props2.currency); + }; + $$self.$$.update = () => { + if ($$self.$$.dirty & /*entry, $pileData*/ + 1048578) { + $$invalidate(3, canInspectItems = entry.id && $pileData.canInspectItems); + } + }; + return [ + store, + entry, + currency, + canInspectItems, + $editQuantities, + $quantityLeft, + $quantity, + $img, + $rarityColor, + $name, + $currentQuantity, + name, + img, + rarityColor, + quantityLeft, + quantity, + currentQuantity, + pileData, + editQuantities, + dragStart, + $pileData, + dragstart_handler, + click_handler, + input_input_handler, + input_input_handler_1, + click_handler_1, + click_handler_2, + dragstart_handler_1 + ]; +} +__name(instance$12, "instance$12"); +class ListEntry extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$12, create_fragment$12, safe_not_equal, { store: 0, entry: 1, currency: 2 }); + } +} +__name(ListEntry, "ListEntry"); +function get_each_context$y(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[6] = list[i]; + child_ctx[7] = list; + child_ctx[8] = i; + return child_ctx; +} +__name(get_each_context$y, "get_each_context$y"); +function create_if_block$N(ctx) { + let div1; + let div0; + let h3; + let t1; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let div1_intro; + let current; + let each_value = ( + /*$items*/ + ctx[2] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*item*/ + ctx2[6].identifier + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$y(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$y(key, child_ctx)); + } + return { + c() { + div1 = element("div"); + div0 = element("div"); + h3 = element("h3"); + h3.textContent = `${localize("ITEM-PILES.Items")}`; + t1 = space(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + attr(div0, "class", "item-piles-flexrow"); + }, + m(target, anchor) { + insert(target, div1, anchor); + append(div1, div0); + append(div0, h3); + append(div1, t1); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(div1, null); + } + } + current = true; + }, + p(ctx2, dirty) { + if (dirty & /*store, $items*/ + 5) { + each_value = /*$items*/ + ctx2[2]; + group_outros(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, div1, outro_and_destroy_block, create_each_block$y, null, get_each_context$y); + check_outros(); + } + }, + i(local) { + if (current) + return; + for (let i = 0; i < each_value.length; i += 1) { + transition_in(each_blocks[i]); + } + if (local) { + if (!div1_intro) { + add_render_callback(() => { + div1_intro = create_in_transition(div1, fade, { duration: 150 }); + div1_intro.start(); + }); + } + } + current = true; + }, + o(local) { + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + current = false; + }, + d(detaching) { + if (detaching) + detach(div1); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + } + }; +} +__name(create_if_block$N, "create_if_block$N"); +function create_each_block$y(key_1, ctx) { + let first; + let listentry; + let updating_entry; + let current; + function listentry_entry_binding(value) { + ctx[5]( + value, + /*item*/ + ctx[6], + /*each_value*/ + ctx[7], + /*item_index*/ + ctx[8] + ); + } + __name(listentry_entry_binding, "listentry_entry_binding"); + let listentry_props = { store: ( + /*store*/ + ctx[0] + ) }; + if ( + /*item*/ + ctx[6] !== void 0 + ) { + listentry_props.entry = /*item*/ + ctx[6]; + } + listentry = new ListEntry({ props: listentry_props }); + binding_callbacks.push(() => bind(listentry, "entry", listentry_entry_binding)); + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(listentry.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(listentry, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const listentry_changes = {}; + if (dirty & /*store*/ + 1) + listentry_changes.store = /*store*/ + ctx[0]; + if (!updating_entry && dirty & /*$items*/ + 4) { + updating_entry = true; + listentry_changes.entry = /*item*/ + ctx[6]; + add_flush_callback(() => updating_entry = false); + } + listentry.$set(listentry_changes); + }, + i(local) { + if (current) + return; + transition_in(listentry.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(listentry.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(first); + destroy_component(listentry, detaching); + } + }; +} +__name(create_each_block$y, "create_each_block$y"); +function create_fragment$11(ctx) { + let if_block_anchor; + let current; + let if_block = ( + /*$numItems*/ + ctx[1] > 0 && create_if_block$N(ctx) + ); + return { + c() { + if (if_block) + if_block.c(); + if_block_anchor = empty(); + }, + m(target, anchor) { + if (if_block) + if_block.m(target, anchor); + insert(target, if_block_anchor, anchor); + current = true; + }, + p(ctx2, [dirty]) { + if ( + /*$numItems*/ + ctx2[1] > 0 + ) { + if (if_block) { + if_block.p(ctx2, dirty); + if (dirty & /*$numItems*/ + 2) { + transition_in(if_block, 1); + } + } else { + if_block = create_if_block$N(ctx2); + if_block.c(); + transition_in(if_block, 1); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + } else if (if_block) { + group_outros(); + transition_out(if_block, 1, 1, () => { + if_block = null; + }); + check_outros(); + } + }, + i(local) { + if (current) + return; + transition_in(if_block); + current = true; + }, + o(local) { + transition_out(if_block); + current = false; + }, + d(detaching) { + if (if_block) + if_block.d(detaching); + if (detaching) + detach(if_block_anchor); + } + }; +} +__name(create_fragment$11, "create_fragment$11"); +function instance$11($$self, $$props, $$invalidate) { + let $numItems; + let $items; + let { store } = $$props; + const items = store.items; + component_subscribe($$self, items, (value) => $$invalidate(2, $items = value)); + const numItems = store.numItems; + component_subscribe($$self, numItems, (value) => $$invalidate(1, $numItems = value)); + function listentry_entry_binding(value, item, each_value, item_index) { + each_value[item_index] = value; + items.set($items); + } + __name(listentry_entry_binding, "listentry_entry_binding"); + $$self.$$set = ($$props2) => { + if ("store" in $$props2) + $$invalidate(0, store = $$props2.store); + }; + return [store, $numItems, $items, items, numItems, listentry_entry_binding]; +} +__name(instance$11, "instance$11"); +class ItemList extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$11, create_fragment$11, safe_not_equal, { store: 0 }); + } +} +__name(ItemList, "ItemList"); +function get_each_context$x(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[9] = list[i]; + child_ctx[10] = list; + child_ctx[11] = i; + return child_ctx; +} +__name(get_each_context$x, "get_each_context$x"); +function create_if_block_1$A(ctx) { + let h3; + return { + c() { + h3 = element("h3"); + h3.textContent = `${localize("ITEM-PILES.Currencies")}:`; + }, + m(target, anchor) { + insert(target, h3, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(h3); + } + }; +} +__name(create_if_block_1$A, "create_if_block_1$A"); +function create_if_block$M(ctx) { + let div; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let current; + let each_value = ( + /*$currencies*/ + ctx[2] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*currency*/ + ctx2[9].identifier + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$x(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$x(key, child_ctx)); + } + return { + c() { + div = element("div"); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + }, + m(target, anchor) { + insert(target, div, anchor); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(div, null); + } + } + current = true; + }, + p(ctx2, dirty) { + if (dirty & /*store, $currencies*/ + 5) { + each_value = /*$currencies*/ + ctx2[2]; + group_outros(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, div, outro_and_destroy_block, create_each_block$x, null, get_each_context$x); + check_outros(); + } + }, + i(local) { + if (current) + return; + for (let i = 0; i < each_value.length; i += 1) { + transition_in(each_blocks[i]); + } + current = true; + }, + o(local) { + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + current = false; + }, + d(detaching) { + if (detaching) + detach(div); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + } + }; +} +__name(create_if_block$M, "create_if_block$M"); +function create_each_block$x(key_1, ctx) { + let first; + let listentry; + let updating_entry; + let current; + function listentry_entry_binding(value) { + ctx[6]( + value, + /*currency*/ + ctx[9], + /*each_value*/ + ctx[10], + /*index*/ + ctx[11] + ); + } + __name(listentry_entry_binding, "listentry_entry_binding"); + let listentry_props = { store: ( + /*store*/ + ctx[0] + ), currency: true }; + if ( + /*currency*/ + ctx[9] !== void 0 + ) { + listentry_props.entry = /*currency*/ + ctx[9]; + } + listentry = new ListEntry({ props: listentry_props }); + binding_callbacks.push(() => bind(listentry, "entry", listentry_entry_binding)); + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(listentry.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(listentry, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const listentry_changes = {}; + if (dirty & /*store*/ + 1) + listentry_changes.store = /*store*/ + ctx[0]; + if (!updating_entry && dirty & /*$currencies*/ + 4) { + updating_entry = true; + listentry_changes.entry = /*currency*/ + ctx[9]; + add_flush_callback(() => updating_entry = false); + } + listentry.$set(listentry_changes); + }, + i(local) { + if (current) + return; + transition_in(listentry.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(listentry.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(first); + destroy_component(listentry, detaching); + } + }; +} +__name(create_each_block$x, "create_each_block$x"); +function create_fragment$10(ctx) { + let div1; + let div0; + let t0; + let a; + let i; + let t1; + let t2_value = localize("ITEM-PILES.Inspect.AddCurrency") + ""; + let t2; + let t3; + let current; + let mounted; + let dispose; + let if_block0 = ( + /*$numCurrencies*/ + ctx[1] > 0 && create_if_block_1$A() + ); + let if_block1 = ( + /*$numCurrencies*/ + ctx[1] > 0 && create_if_block$M(ctx) + ); + return { + c() { + div1 = element("div"); + div0 = element("div"); + if (if_block0) + if_block0.c(); + t0 = space(); + a = element("a"); + i = element("i"); + t1 = space(); + t2 = text(t2_value); + t3 = space(); + if (if_block1) + if_block1.c(); + attr(i, "class", "fas fa-plus"); + attr(a, "class", "item-piles-clickable item-piles-text-right item-piles-small-text item-piles-middle"); + attr(div0, "class", "item-piles-flexrow"); + }, + m(target, anchor) { + insert(target, div1, anchor); + append(div1, div0); + if (if_block0) + if_block0.m(div0, null); + append(div0, t0); + append(div0, a); + append(a, i); + append(a, t1); + append(a, t2); + append(div1, t3); + if (if_block1) + if_block1.m(div1, null); + current = true; + if (!mounted) { + dispose = listen( + a, + "click", + /*click_handler*/ + ctx[5] + ); + mounted = true; + } + }, + p(ctx2, [dirty]) { + if ( + /*$numCurrencies*/ + ctx2[1] > 0 + ) { + if (if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0 = create_if_block_1$A(); + if_block0.c(); + if_block0.m(div0, t0); + } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; + } + if ( + /*$numCurrencies*/ + ctx2[1] > 0 + ) { + if (if_block1) { + if_block1.p(ctx2, dirty); + if (dirty & /*$numCurrencies*/ + 2) { + transition_in(if_block1, 1); + } + } else { + if_block1 = create_if_block$M(ctx2); + if_block1.c(); + transition_in(if_block1, 1); + if_block1.m(div1, null); + } + } else if (if_block1) { + group_outros(); + transition_out(if_block1, 1, 1, () => { + if_block1 = null; + }); + check_outros(); + } + }, + i(local) { + if (current) + return; + transition_in(if_block1); + current = true; + }, + o(local) { + transition_out(if_block1); + current = false; + }, + d(detaching) { + if (detaching) + detach(div1); + if (if_block0) + if_block0.d(); + if (if_block1) + if_block1.d(); + mounted = false; + dispose(); + } + }; +} +__name(create_fragment$10, "create_fragment$10"); +function instance$10($$self, $$props, $$invalidate) { + let $numCurrencies; + let $currencies; + let { store } = $$props; + const currencies = store.currencies; + component_subscribe($$self, currencies, (value) => $$invalidate(2, $currencies = value)); + store.numItems; + const numCurrencies = store.numCurrencies; + component_subscribe($$self, numCurrencies, (value) => $$invalidate(1, $numCurrencies = value)); + store.editQuantities; + const click_handler = /* @__PURE__ */ __name(() => store.addCurrency(store.recipient), "click_handler"); + function listentry_entry_binding(value, currency, each_value, index2) { + each_value[index2] = value; + currencies.set($currencies); + } + __name(listentry_entry_binding, "listentry_entry_binding"); + $$self.$$set = ($$props2) => { + if ("store" in $$props2) + $$invalidate(0, store = $$props2.store); + }; + return [ + store, + $numCurrencies, + $currencies, + currencies, + numCurrencies, + click_handler, + listentry_entry_binding + ]; +} +__name(instance$10, "instance$10"); +let CurrencyList$1 = /* @__PURE__ */ __name(class CurrencyList2 extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$10, create_fragment$10, safe_not_equal, { store: 0 }); + } +}, "CurrencyList"); +function get_each_context$w(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[13] = list[i]; + child_ctx[15] = i; + return child_ctx; +} +__name(get_each_context$w, "get_each_context$w"); +function create_else_block$i(ctx) { + let div; + let t; + let if_block0 = !/*changingActor*/ + ctx[3] && create_if_block_3$k(ctx); + let if_block1 = ( + /*playerActors*/ + ctx[7].length > 1 && create_if_block_1$z(ctx) + ); + return { + c() { + div = element("div"); + if (if_block0) + if_block0.c(); + t = space(); + if (if_block1) + if_block1.c(); + attr( + div, + "style", + /*style*/ + ctx[1] + ); + }, + m(target, anchor) { + insert(target, div, anchor); + if (if_block0) + if_block0.m(div, null); + append(div, t); + if (if_block1) + if_block1.m(div, null); + }, + p(ctx2, dirty) { + if (!/*changingActor*/ + ctx2[3]) { + if (if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0 = create_if_block_3$k(ctx2); + if_block0.c(); + if_block0.m(div, t); + } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; + } + if ( + /*playerActors*/ + ctx2[7].length > 1 + ) + if_block1.p(ctx2, dirty); + if (dirty & /*style*/ + 2) { + attr( + div, + "style", + /*style*/ + ctx2[1] + ); + } + }, + d(detaching) { + if (detaching) + detach(div); + if (if_block0) + if_block0.d(); + if (if_block1) + if_block1.d(); + } + }; +} +__name(create_else_block$i, "create_else_block$i"); +function create_if_block$L(ctx) { + let div; + let t_value = localize("ITEM-PILES.Inspect.Owner") + ""; + let t; + return { + c() { + div = element("div"); + t = text(t_value); + attr( + div, + "style", + /*style*/ + ctx[1] + ); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, t); + }, + p(ctx2, dirty) { + if (dirty & /*style*/ + 2) { + attr( + div, + "style", + /*style*/ + ctx2[1] + ); + } + }, + d(detaching) { + if (detaching) + detach(div); + } + }; +} +__name(create_if_block$L, "create_if_block$L"); +function create_if_block_3$k(ctx) { + let t_value = localize( + /*localization*/ + ctx[0], + { actorName: ( + /*$recipientDoc*/ + ctx[2].name + ) } + ) + ""; + let t; + return { + c() { + t = text(t_value); + }, + m(target, anchor) { + insert(target, t, anchor); + }, + p(ctx2, dirty) { + if (dirty & /*localization, $recipientDoc*/ + 5 && t_value !== (t_value = localize( + /*localization*/ + ctx2[0], + { actorName: ( + /*$recipientDoc*/ + ctx2[2].name + ) } + ) + "")) + set_data(t, t_value); + }, + d(detaching) { + if (detaching) + detach(t); + } + }; +} +__name(create_if_block_3$k, "create_if_block_3$k"); +function create_if_block_1$z(ctx) { + let if_block_anchor; + function select_block_type_1(ctx2, dirty) { + if (!/*changingActor*/ + ctx2[3]) + return create_if_block_2$p; + return create_else_block_1$7; + } + __name(select_block_type_1, "select_block_type_1"); + let current_block_type = select_block_type_1(ctx); + let if_block = current_block_type(ctx); + return { + c() { + if_block.c(); + if_block_anchor = empty(); + }, + m(target, anchor) { + if_block.m(target, anchor); + insert(target, if_block_anchor, anchor); + }, + p(ctx2, dirty) { + if (current_block_type === (current_block_type = select_block_type_1(ctx2)) && if_block) { + if_block.p(ctx2, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx2); + if (if_block) { + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + } + }, + d(detaching) { + if_block.d(detaching); + if (detaching) + detach(if_block_anchor); + } + }; +} +__name(create_if_block_1$z, "create_if_block_1$z"); +function create_else_block_1$7(ctx) { + let select; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let mounted; + let dispose; + let each_value = ( + /*playerActors*/ + ctx[7] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*index*/ + ctx2[15] + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$w(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$w(key, child_ctx)); + } + return { + c() { + select = element("select"); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + attr(select, "class", "item-piles-change-actor-select"); + set_style(select, "height", "auto"); + if ( + /*recipientUuid*/ + ctx[4] === void 0 + ) + add_render_callback(() => ( + /*select_change_handler*/ + ctx[12].call(select) + )); + toggle_class( + select, + "active", + /*changingActor*/ + ctx[3] + ); + }, + m(target, anchor) { + insert(target, select, anchor); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(select, null); + } + } + select_option( + select, + /*recipientUuid*/ + ctx[4], + true + ); + if (!mounted) { + dispose = [ + listen( + select, + "change", + /*select_change_handler*/ + ctx[12] + ), + listen( + select, + "change", + /*changeRecipientActor*/ + ctx[9] + ) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*Utilities, playerActors*/ + 128) { + each_value = /*playerActors*/ + ctx2[7]; + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, select, destroy_block, create_each_block$w, null, get_each_context$w); + } + if (dirty & /*recipientUuid, Utilities, playerActors*/ + 144) { + select_option( + select, + /*recipientUuid*/ + ctx2[4] + ); + } + if (dirty & /*changingActor*/ + 8) { + toggle_class( + select, + "active", + /*changingActor*/ + ctx2[3] + ); + } + }, + d(detaching) { + if (detaching) + detach(select); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + mounted = false; + run_all(dispose); + } + }; +} +__name(create_else_block_1$7, "create_else_block_1$7"); +function create_if_block_2$p(ctx) { + let a; + let mounted; + let dispose; + return { + c() { + a = element("a"); + a.textContent = "Change."; + attr(a, "class", "item-piles-highlight"); + toggle_class(a, "active", !/*changingActor*/ + ctx[3]); + }, + m(target, anchor) { + insert(target, a, anchor); + if (!mounted) { + dispose = listen( + a, + "click", + /*click_handler*/ + ctx[11] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*changingActor*/ + 8) { + toggle_class(a, "active", !/*changingActor*/ + ctx2[3]); + } + }, + d(detaching) { + if (detaching) + detach(a); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_2$p, "create_if_block_2$p"); +function create_each_block$w(key_1, ctx) { + let option; + let t_value = ( + /*actor*/ + ctx[13].name + "" + ); + let t; + return { + key: key_1, + first: null, + c() { + option = element("option"); + t = text(t_value); + option.__value = getUuid( + /*actor*/ + ctx[13].uuid + ); + option.value = option.__value; + this.first = option; + }, + m(target, anchor) { + insert(target, option, anchor); + append(option, t); + }, + p(new_ctx, dirty) { + ctx = new_ctx; + }, + d(detaching) { + if (detaching) + detach(option); + } + }; +} +__name(create_each_block$w, "create_each_block$w"); +function create_fragment$$(ctx) { + let if_block_anchor; + function select_block_type(ctx2, dirty) { + if ( + /*$editQuantities*/ + ctx2[5] + ) + return create_if_block$L; + return create_else_block$i; + } + __name(select_block_type, "select_block_type"); + let current_block_type = select_block_type(ctx); + let if_block = current_block_type(ctx); + return { + c() { + if_block.c(); + if_block_anchor = empty(); + }, + m(target, anchor) { + if_block.m(target, anchor); + insert(target, if_block_anchor, anchor); + }, + p(ctx2, [dirty]) { + if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block) { + if_block.p(ctx2, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx2); + if (if_block) { + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + } + }, + i: noop, + o: noop, + d(detaching) { + if_block.d(detaching); + if (detaching) + detach(if_block_anchor); + } + }; +} +__name(create_fragment$$, "create_fragment$$"); +function instance$$($$self, $$props, $$invalidate) { + let $recipientDoc; + let $editQuantities; + let { store } = $$props; + let { localization = "ITEM-PILES.Inspect.AsActor" } = $$props; + let { style = "text-align: center; flex: 0 1 auto; height: 27px;" } = $$props; + let editQuantities = store.editQuantities; + component_subscribe($$self, editQuantities, (value) => $$invalidate(5, $editQuantities = value)); + let changingActor = false; + let playerActors = game.actors.filter((actor) => actor.isOwner && actor !== store.pileActor && actor.prototypeToken.actorLink); + let recipientUuid = getUuid(store.recipient); + const recipientDoc = store.recipientDocument; + component_subscribe($$self, recipientDoc, (value) => $$invalidate(2, $recipientDoc = value)); + function changeRecipientActor() { + $$invalidate(10, store.recipient = playerActors.find((actor) => getUuid(actor) === recipientUuid), store); + store.update(); + $$invalidate(3, changingActor = false); + } + __name(changeRecipientActor, "changeRecipientActor"); + const click_handler = /* @__PURE__ */ __name(() => { + $$invalidate(3, changingActor = true); + }, "click_handler"); + function select_change_handler() { + recipientUuid = select_value(this); + $$invalidate(4, recipientUuid), $$invalidate(2, $recipientDoc), $$invalidate(10, store); + $$invalidate(7, playerActors); + } + __name(select_change_handler, "select_change_handler"); + $$self.$$set = ($$props2) => { + if ("store" in $$props2) + $$invalidate(10, store = $$props2.store); + if ("localization" in $$props2) + $$invalidate(0, localization = $$props2.localization); + if ("style" in $$props2) + $$invalidate(1, style = $$props2.style); + }; + $$self.$$.update = () => { + if ($$self.$$.dirty & /*$recipientDoc, store*/ + 1028) { + { + $$invalidate(4, recipientUuid = store.recipient ? getUuid(store.recipient) : false); + } + } + }; + return [ + localization, + style, + $recipientDoc, + changingActor, + recipientUuid, + $editQuantities, + editQuantities, + playerActors, + recipientDoc, + changeRecipientActor, + store, + click_handler, + select_change_handler + ]; +} +__name(instance$$, "instance$$"); +class ActorPicker extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$$, create_fragment$$, safe_not_equal, { store: 10, localization: 0, style: 1 }); + } +} +__name(ActorPicker, "ActorPicker"); +class BasePlugin { + invalidVersionError = ""; + minVersionError = ""; + constructor(pluginName, minVersion, invalidVersion) { + this.pluginName = pluginName; + this.minVersion = minVersion; + this.invalidVersion = invalidVersion; + this.initialized = false; + this.initialize(); + } + initialize() { + if (!game.modules.get(this.pluginName)?.active) { + return; + } + if (game.modules.get(this.pluginName).version === this.invalidVersion) { + if (this.invalidVersionError) { + throw custom_error(this.invalidVersionError); + } + return; + } + if (isNewerVersion(this.minVersion, game.modules.get(this.pluginName).version)) { + if (this.minVersionError) { + throw custom_error(this.minVersionError); + } + return; + } + this.registerHooks(); + this.initialized = true; + } + registerHooks() { + } +} +__name(BasePlugin, "BasePlugin"); +class Transaction { + constructor(actor) { + this.actor = actor; + this.itemsToCreate = []; + this.itemsToUpdate = []; + this.itemsToDelete = []; + this.itemsToForceDelete = /* @__PURE__ */ new Set(); + this.itemsToNotDelete = /* @__PURE__ */ new Set(); + this.actorUpdates = {}; + this.attributeDeltas = /* @__PURE__ */ new Map(); + this.attributeTypeMap = /* @__PURE__ */ new Map(); + this.itemDeltas = /* @__PURE__ */ new Map(); + this.itemTypeMap = /* @__PURE__ */ new Map(); + this.itemFlagMap = /* @__PURE__ */ new Map(); + this.preCommitted = false; + } + async appendItemChanges(items, { + remove = false, + type = "item", + keepIfZero = false, + onlyDelta = false + } = {}) { + for (let data2 of items) { + let item = data2.item ?? data2; + type = isItemCurrency(item, { target: this.actor }) ? "currency" : type; + let flags = data2.flags ?? false; + let itemData = item instanceof Item ? item.toObject() : foundry.utils.duplicate(item); + if (SYSTEMS.DATA.ITEM_TRANSFORMER && !remove) { + itemData = await SYSTEMS.DATA.ITEM_TRANSFORMER(itemData); + } + const incomingQuantity = Math.abs(data2.quantity ?? getItemQuantity(itemData)) * (remove ? -1 : 1); + let itemId = itemData._id ?? itemData.id; + const actorHasItem = this.actor.items.get(itemId); + const actorExistingItem = actorHasItem || findSimilarItem(this.actor.items, itemData, getActorFlagData(this.actor), type === "currency"); + const canItemStack$1 = canItemStack(actorExistingItem || itemData, this.actor); + if (!canItemStack$1) { + if (remove && actorExistingItem) { + this.itemTypeMap.set(actorExistingItem.id, type); + if (!onlyDelta) { + this.itemsToForceDelete.add(actorExistingItem.id); + } + this.itemDeltas.set(actorExistingItem.id, -1); + } else { + if (!itemId) { + itemId = randomID(); + } + setItemQuantity(itemData, incomingQuantity); + this.itemTypeMap.set(itemId, type); + this.itemsToCreate.push(itemData); + } + } else if (actorExistingItem) { + const existingItemUpdate = remove ? this.itemsToUpdate.find((item2) => item2._id === itemId) : findSimilarItem(this.itemsToUpdate, itemData); + if (keepIfZero || type === "currency") { + this.itemsToNotDelete.add(item.id); + } + if (!onlyDelta) { + if (existingItemUpdate) { + const newQuantity = getItemQuantity(existingItemUpdate) + incomingQuantity; + setItemQuantity(existingItemUpdate, newQuantity); + if (keepIfZero && type !== "currency") { + setProperty(existingItemUpdate, CONSTANTS.FLAGS.ITEM + ".notForSale", newQuantity === 0); + } + } else { + const newQuantity = getItemQuantity(actorExistingItem) + incomingQuantity; + const update2 = setItemQuantity(actorExistingItem.toObject(), newQuantity); + if (keepIfZero && type !== "currency") { + setProperty(update2, CONSTANTS.FLAGS.ITEM + ".notForSale", newQuantity === 0); + } + this.itemTypeMap.set(actorExistingItem.id, type); + this.itemsToUpdate.push(update2); + } + } + this.itemDeltas.set( + actorExistingItem.id, + (this.itemDeltas.has(actorExistingItem.id) ? this.itemDeltas.get(actorExistingItem.id) : 0) + incomingQuantity + ); + } else { + if (!itemData._id) { + itemData._id = randomID(); + } + const existingItemCreation = findSimilarItem(this.itemsToCreate, itemData); + if (existingItemCreation) { + const newQuantity = getItemQuantity(existingItemCreation) + incomingQuantity; + setItemQuantity(existingItemCreation, newQuantity); + } else { + setItemQuantity(itemData, incomingQuantity); + this.itemsToCreate.push(itemData); + this.itemTypeMap.set(itemData._id, type); + } + } + if (flags) { + this.itemFlagMap.set(itemData._id, flags); + } + } + } + async appendActorChanges(attributes, { set = false, remove = false, type = "attribute", onlyDelta = false } = {}) { + if (!Array.isArray(attributes)) { + attributes = Object.entries(attributes).map((entry) => ({ path: entry[0], quantity: entry[1] })); + } + this.actorUpdates = attributes.reduce((acc, attribute) => { + const incomingQuantity = Math.abs(attribute.quantity) * (remove ? -1 : 1); + acc[attribute.path] = acc[attribute.path] ?? Number(getProperty(this.actor, attribute.path) ?? 0); + if (set) { + if (!onlyDelta) { + acc[attribute.path] = incomingQuantity; + } + this.attributeDeltas.set( + attribute.path, + (this.attributeDeltas.has(attribute.path) ? this.attributeDeltas.get(attribute.path) : acc[attribute.path]) + incomingQuantity + ); + } else { + if (!onlyDelta) { + acc[attribute.path] += incomingQuantity; + } + this.attributeDeltas.set( + attribute.path, + (this.attributeDeltas.has(attribute.path) ? this.attributeDeltas.get(attribute.path) : 0) + incomingQuantity + ); + } + this.attributeTypeMap.set(attribute.path, type); + return acc; + }, this.actorUpdates); + } + prepare() { + this.actorUpdates = Object.fromEntries(Object.entries(this.actorUpdates).filter((entry) => { + if (this.attributeDeltas.get(entry[0]) === 0) { + this.attributeDeltas.delete(entry[0]); + } + return Number(getProperty(this.actor, entry[0])) !== entry[1]; + })); + this.itemsToCreate = this.itemsToCreate.filter((item) => { + return !canItemStack(item, this.actor) || getItemQuantity(item) > 0 || this.itemTypeMap.get(item._id) === "currency"; + }); + this.itemsToDelete = this.itemsToUpdate.filter((item) => { + return getItemQuantity(item) <= 0 && this.itemTypeMap.get(item._id) !== "currency"; + }).map((item) => item._id).concat(Array.from(this.itemsToForceDelete)); + for (const itemId of this.itemsToDelete) { + if (this.itemsToNotDelete.has(itemId)) { + this.itemsToDelete.splice(this.itemsToDelete.indexOf(itemId), 1); + } + } + this.itemDeltas = Array.from(this.itemDeltas).map(([id, quantity]) => { + const item = this.actor.items.get(id).toObject(); + const existingFlags = getItemFlagData(item); + setProperty(item, CONSTANTS.FLAGS.ITEM, foundry.utils.mergeObject( + existingFlags, + this.itemFlagMap.get(id) ?? {} + )); + const type = this.itemTypeMap.get(id); + setItemQuantity(item, quantity, true); + return { item, quantity, type }; + }).filter((delta) => delta.quantity); + this.itemsToUpdate = this.itemsToUpdate.filter((item) => getItemQuantity(item) > 0 || this.itemsToNotDelete.has(item._id) || this.itemTypeMap.get(item._id) === "currency").filter((itemData) => { + const item = this.actor.items.get(itemData._id); + return getItemQuantity(item) !== getItemQuantity(itemData); + }); + this.attributeDeltas = Object.fromEntries(this.attributeDeltas); + this.preCommitted = true; + return { + actorUpdates: this.actorUpdates, + itemsToCreate: this.itemsToCreate, + itemsToDelete: this.itemsToDelete, + itemsToUpdate: this.itemsToUpdate, + attributeDeltas: this.attributeDeltas, + itemDeltas: this.itemDeltas + }; + } + async commit() { + if (!this.preCommitted) { + this.prepare(); + } + let itemsCreated; + const actorUuid = getUuid(this.actor); + if (this.actor.isOwner) { + itemsCreated = await PrivateAPI._commitActorChanges(actorUuid, { + actorUpdates: this.actorUpdates, + itemsToUpdate: this.itemsToUpdate, + itemsToDelete: this.itemsToDelete, + itemsToCreate: this.itemsToCreate + }); + } else { + itemsCreated = await ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.COMMIT_ACTOR_CHANGES, actorUuid, { + actorUpdates: this.actorUpdates, + itemsToUpdate: this.itemsToUpdate, + itemsToDelete: this.itemsToDelete, + itemsToCreate: this.itemsToCreate + }); + } + return { + attributeDeltas: this.attributeDeltas, + itemDeltas: this.itemDeltas.concat(itemsCreated.map((item) => { + return { + item, + quantity: canItemStack(item) ? getItemQuantity(item) : 1 + }; + })) + }; + } +} +__name(Transaction, "Transaction"); +let previousState; +class SimpleCalendarPlugin extends BasePlugin { + invalidVersionError = "Simple Calendar version 1.3.75 is installed, but Item Piles requires version 2.0.0 or above. The author made a mistake, and you will need to reinstall the Simple Calendar module."; + minVersionError = "Simple Calendar is out of date to be compatible with Item Piles, please update as soon as possible."; + registerHooks() { + previousState = { + dateTime: window.SimpleCalendar.api.currentDateTime(), + weekday: window.SimpleCalendar.api.getCurrentWeekday(), + timestamp: window.SimpleCalendar.api.dateToTimestamp({}) + }; + Hooks.on(window.SimpleCalendar.Hooks.DateTimeChange, () => { + ItemPileStore.notifyAllOfChanges("updateOpenCloseStatus"); + this.handleTimePassed(); + }); + } + async handleTimePassed() { + const newState = { + dateTime: window.SimpleCalendar.api.currentDateTime(), + weekday: window.SimpleCalendar.api.getCurrentWeekday(), + timestamp: window.SimpleCalendar.api.dateToTimestamp({}) + }; + const currentCalendar = window.SimpleCalendar.api.getCurrentCalendar(); + const numWeekdays = currentCalendar.weekdays.length; + const notes = window.SimpleCalendar.api.getNotes().filter((note) => getProperty(note, "flags.foundryvtt-simple-calendar.noteData.categories")?.length).map((note) => { + const flags = getProperty(note, "flags.foundryvtt-simple-calendar.noteData"); + let timestampData = { + year: flags.startDate.year, + month: flags.startDate.month, + day: flags.startDate.day, + hour: flags.allDay ? 0 : flags.startDate.hour, + minute: flags.allDay ? 0 : flags.startDate.minute, + seconds: flags.allDay ? 0 : flags.startDate.seconds + }; + switch (flags?.repeats) { + case window.SimpleCalendar.api.NoteRepeat.Weekly: + const noteWeekDay = window.SimpleCalendar.api.timestampToDate(window.SimpleCalendar.api.dateToTimestamp(timestampData)).dayOfTheWeek - 1; + const currentWeekDay = window.SimpleCalendar.api.timestampToDate(newState.timestamp).dayOfTheWeek - 1; + let weekdayCountDifference = currentWeekDay - noteWeekDay; + if (weekdayCountDifference < 0) { + weekdayCountDifference += numWeekdays; + } + timestampData.year = newState.dateTime.year; + timestampData.month = newState.dateTime.month; + timestampData.day = newState.dateTime.day; + const weekInSeconds = SimpleCalendar.api.timestampPlusInterval(0, { day: 1 }) * weekdayCountDifference; + const timestamp = window.SimpleCalendar.api.dateToTimestamp(timestampData) - weekInSeconds; + timestampData.day = window.SimpleCalendar.api.timestampToDate(timestamp).day; + break; + case window.SimpleCalendar.api.NoteRepeat.Monthly: + timestampData.year = newState.dateTime.year; + timestampData.month = newState.dateTime.month; + break; + case window.SimpleCalendar.api.NoteRepeat.Yearly: + timestampData.year = newState.dateTime.year; + break; + } + return { + document: note, + flags, + dateTime: timestampData, + timestamp: window.SimpleCalendar.api.dateToTimestamp(timestampData) + }; + }).filter((note) => { + return note.timestamp > previousState.timestamp && note.timestamp <= newState.timestamp; + }); + const categories = new Set(notes.map((note) => note.flags?.categories ?? []).deepFlatten()); + const actors = getItemPileActors((actor) => { + const flags = getActorFlagData(actor, getProperty(actor, CONSTANTS.FLAGS.PILE)); + if (flags.type !== CONSTANTS.PILE_TYPES.MERCHANT) + return false; + return merchantRefreshFilter(flags, newState, previousState, categories); + }); + const { validTokensOnScenes } = getItemPileTokens((token) => { + const flags = getActorFlagData(token, getProperty(token, CONSTANTS.FLAGS.PILE)); + if (flags.type !== CONSTANTS.PILE_TYPES.MERCHANT) + return false; + return merchantRefreshFilter(flags, newState, previousState, categories); + }); + previousState = newState; + for (const actor of actors) { + await this.refreshActorItems(actor); + } + for (const [_, tokens] of validTokensOnScenes) { + for (const token of tokens) { + await this.refreshActorItems(token.actor); + } + } + } + async refreshActorItems(actor) { + const actorTransaction = new Transaction(actor); + const actorItems = game.itempiles.API.getActorItems(actor); + const newActorItems = await rollMerchantTables({ actor }); + await actorTransaction.appendItemChanges(actorItems.filter((item) => { + const itemFlags = getItemFlagData(item); + return !itemFlags.keepOnMerchant && !itemFlags.keepIfZero; + }), { remove: true }); + await actorTransaction.appendItemChanges(actorItems.filter((item) => { + const itemFlags = getItemFlagData(item); + return !itemFlags.keepOnMerchant && itemFlags.keepIfZero; + }), { remove: true, keepIfZero: true }); + await actorTransaction.appendItemChanges(newActorItems.map((entry) => ({ + item: entry.item, + quantity: entry.quantity, + flags: entry.flags + }))); + await actorTransaction.commit(); + } +} +__name(SimpleCalendarPlugin, "SimpleCalendarPlugin"); +function merchantRefreshFilter(flags, newState, previousState2, categories) { + const openTimesEnabled = flags.openTimes.enabled; + if (!openTimesEnabled) + return false; + const openTimes = flags.openTimes.open; + const closeTimes = flags.openTimes.close; + const openHour = openTimesEnabled ? openTimes.hour : 0; + const openMinute = openTimesEnabled ? openTimes.minute : 0; + const closeHour = openTimesEnabled ? closeTimes.hour : 0; + const closeMinute = openTimesEnabled ? closeTimes.minute : 0; + const openingTime = Number(openHour.toString() + "." + openMinute.toString()); + const closingTime = Number(closeHour.toString() + "." + closeMinute.toString()); + const previousTime = Number(previousState2.dateTime.hour.toString() + "." + previousState2.dateTime.minute.toString()); + const currentTime = Number(newState.dateTime.hour.toString() + "." + newState.dateTime.minute.toString()); + const wasOpen = openingTime > closingTime ? previousTime >= openingTime || previousTime <= closingTime : previousTime >= openingTime && previousTime <= closingTime; + const isOpen = openingTime > closingTime ? currentTime >= openingTime || currentTime <= closingTime : currentTime >= openingTime && currentTime <= closingTime; + const allWeekdays = window.SimpleCalendar.api.getAllWeekdays(); + const dayLength = SimpleCalendar.api.timestampPlusInterval(0, { day: 1 }); + const daysPassed = Math.floor((newState.timestamp - previousState2.timestamp) / dayLength); + const currentWeekday = newState.weekday; + const shouldRefreshOnCurrentWeekday = flags.refreshItemsDays.includes(currentWeekday.name); + const shouldRefreshPastWeekday = flags.refreshItemsDays.length > 0 && daysPassed >= allWeekdays.length; + const shouldRefresh = flags.refreshItemsOnOpen || shouldRefreshOnCurrentWeekday || shouldRefreshPastWeekday || categories.intersection(new Set(flags.refreshItemsHolidays)).size > 0; + return !wasOpen && isOpen && shouldRefresh; +} +__name(merchantRefreshFilter, "merchantRefreshFilter"); +class Levels3dPreview extends BasePlugin { + registerHooks() { + Hooks.on("3DCanvasConfig", (config) => { + config.INTERACTIONS.dropFunctions.Item = async function(event, data2) { + canvas.tokens.activate(); + return PrivateAPI._dropData(canvas, data2); + }; + }); + } +} +__name(Levels3dPreview, "Levels3dPreview"); +class RarityColors extends BasePlugin { + getItemColor(item) { + if (game.system.id !== "dnd5e") + return false; + const itemType = item.type; + const rarity = item.system.rarity ? item.system.rarity.replaceAll(/\s/g, "").toLowerCase().trim() : itemType; + const isSpell = itemType === "spell"; + const spellFlag = game.settings.get(this.pluginName, "spellFlag"); + const isFeat = itemType === "feat"; + const featFlag = game.settings.get(this.pluginName, "featFlag"); + let doColor = false; + if (item.system.rarity && item.system.rarity !== "common") { + doColor = true; + } else if (isSpell && spellFlag) { + doColor = true; + } else if (isFeat && featFlag) { + doColor = true; + } + if (!doColor) + return false; + try { + return game.settings.get(this.pluginName, rarity); + } catch (err) { + return false; + } + } +} +__name(RarityColors, "RarityColors"); +const Plugins = { + "foundryvtt-simple-calendar": { + on: "ready", + data: null, + class: SimpleCalendarPlugin, + minVersion: "2.0.0", + invalidVersion: "v1.3.75" + }, + "levels-3d-preview": { + on: "init", + data: null, + class: Levels3dPreview, + minVersion: "4.9.6" + }, + "rarity-colors": { + on: "init", + data: null, + class: RarityColors, + minVersion: "0.2.4" + } +}; +function setupPlugins(hook) { + for (const [plugin, pluginData] of Object.entries(Plugins).filter((e) => e[1].on === hook)) { + if (!game.modules.get(plugin)?.active) { + continue; + } + pluginData.data = new pluginData.class(plugin, pluginData.minVersion, pluginData?.invalidVersion); + } +} +__name(setupPlugins, "setupPlugins"); +class PileBaseItem { + constructor(store, data2, isCurrency = false, isSecondaryCurrency = false) { + this.store = store; + this.subscriptions = []; + this.isCurrency = isCurrency; + this.isSecondaryCurrency = isSecondaryCurrency; + this.setup(data2); + } + setupStores() { + this.category = writable$1({ service: false, type: "", label: "" }); + this.quantity = writable$1(1); + this.currentQuantity = writable$1(1); + this.quantityLeft = writable$1(1); + this.filtered = writable$1(true); + this.presentFromTheStart = writable$1(false); + this.rarityColor = writable$1(false); + } + setupSubscriptions() { + } + setup(data2) { + this.unsubscribe(); + this.setupStores(data2); + this.setupSubscriptions(data2); + } + subscribeTo(target, callback) { + this.subscriptions.push(target.subscribe(callback)); + } + unsubscribe() { + this.subscriptions.forEach((unsubscribe) => unsubscribe()); + this.subscriptions = []; + } + preview() { + } +} +__name(PileBaseItem, "PileBaseItem"); +class PileItem extends PileBaseItem { + setupStores(item) { + super.setupStores(); + this.item = item; + this.itemDocument = new TJSDocument(this.item); + this.canStack = canItemStack(this.item, this.actor); + this.presentFromTheStart.set(getItemQuantity(this.item) > 0 || !this.canStack); + this.quantity.set(this.canStack ? getItemQuantity(this.item) : 1); + this.currentQuantity.set(Math.min(get_store_value(this.currentQuantity), get_store_value(this.quantityLeft), get_store_value(this.quantity))); + this.id = this.item.id; + this.type = this.item.type; + this.name = writable$1(this.item.name); + this.img = writable$1(this.item.img); + this.abbreviation = writable$1(""); + this.identifier = randomID(); + this.itemFlagData = writable$1(getItemFlagData(this.item)); + } + setupSubscriptions() { + super.setupSubscriptions(); + this.subscribeTo(this.store.pileData, () => { + this.setupProperties(); + }); + this.subscribeTo(this.store.pileCurrencies, () => { + this.setupProperties(); + }); + this.subscribeTo(this.store.shareData, () => { + if (!this.toShare) { + this.quantityLeft.set(get_store_value(this.quantity)); + return; + } + const quantityLeft = getItemSharesLeftForActor(this.store.actor, this.item, this.store.recipient); + this.quantityLeft.set(quantityLeft); + }); + this.subscribeTo(this.itemDocument, () => { + const { data: data2 } = this.itemDocument.updateOptions; + this.name.set(this.item.name); + this.img.set(this.item.img); + this.similarities = setSimilarityProperties({}, this.item); + if (canItemStack(this.item, this.store.actor) && hasItemQuantity(data2)) { + this.quantity.set(getItemQuantity(data2)); + const quantity = Math.min(get_store_value(this.currentQuantity), get_store_value(this.quantityLeft), get_store_value(this.quantity)); + this.currentQuantity.set(quantity); + } + if (hasProperty(data2, CONSTANTS.FLAGS.ITEM)) { + this.itemFlagData.set(getItemFlagData(this.item)); + this.updateCategory(); + this.store.refreshItems(); + } + }); + this.updateCategory(); + this.subscribeTo(this.quantity, this.filter.bind(this)); + this.subscribeTo(this.store.search, this.filter.bind(this)); + this.subscribeTo(this.category, this.filter.bind(this)); + } + setupProperties() { + const actorIsItemPile = isValidItemPile(this.store.actor, get_store_value(this.store.pileData)); + const pileActor = actorIsItemPile ? this.store.actor : this.store.recipient; + const pileActorData = actorIsItemPile ? this.store.pileData : this.store.recipientPileData; + const pileCurrencies = actorIsItemPile ? get_store_value(this.store.pileCurrencies) : get_store_value(this.store.recipientCurrencies); + this.isCurrency = isItemCurrency(this.item, { + target: pileActor, + actorCurrencies: pileCurrencies + }); + const currency = this.isCurrency ? getItemCurrencyData(this.item, { + target: pileActor, + actorCurrencies: pileCurrencies + }) : {}; + this.isSecondaryCurrency = !!currency?.secondary; + this.abbreviation.set(currency?.abbreviation ?? ""); + this.similarities = setSimilarityProperties({}, this.item); + this.name.set(this.isCurrency ? currency.name : this.item.name); + this.img.set(this.isCurrency ? currency.img : this.item.img); + this.toShare = this.isCurrency ? get_store_value(pileActorData).shareCurrenciesEnabled && !!this.store.recipient : get_store_value(pileActorData).shareItemsEnabled && !!this.store.recipient; + } + updateCategory() { + const pileData = get_store_value(this.store.pileData); + const itemFlagData = get_store_value(this.itemFlagData); + this.category.update((cat) => { + cat.service = itemFlagData?.isService; + if (itemFlagData.customCategory) { + cat.type = itemFlagData.customCategory.toLowerCase(); + cat.label = itemFlagData.customCategory; + } else if (cat.service && pileData.enabled && pileData.type === CONSTANTS.PILE_TYPES.MERCHANT) { + cat.type = "item-piles-service"; + cat.label = "ITEM-PILES.Merchant.Service"; + } else { + cat.type = this.type; + cat.label = CONFIG.Item.typeLabels[this.type]; + } + return cat; + }); + } + filter() { + const name = get_store_value(this.name).trim(); + const search = get_store_value(this.store.search).trim(); + const presentFromTheStart = get_store_value(this.presentFromTheStart); + const quantity = get_store_value(this.quantity); + if (quantity === 0 && !presentFromTheStart) { + this.filtered.set(true); + } else if (search) { + this.filtered.set(!name.toLowerCase().includes(search.toLowerCase())); + } else { + this.filtered.set(!presentFromTheStart && quantity === 0); + } + } + take() { + const quantity = Math.min(get_store_value(this.currentQuantity), get_store_value(this.quantityLeft)); + if (!quantity) + return; + return game.itempiles.API.transferItems( + this.store.actor, + this.store.recipient, + [{ _id: this.id, quantity }], + { interactionId: this.store.interactionId } + ); + } + async remove() { + return game.itempiles.API.removeItems(this.store.actor, [this.id]); + } + updateQuantity(quantity, add = false) { + let total = typeof quantity === "string" ? new Roll(quantity).evaluate({ async: false }).total : quantity; + if (add) { + total += get_store_value(this.quantity); + } + this.quantity.set(total); + return this.item.update(setItemQuantity({}, total)); + } + async updateFlags() { + await this.item.update({ + [CONSTANTS.FLAGS.ITEM]: get_store_value(this.itemFlagData), + [CONSTANTS.FLAGS.VERSION]: getModuleVersion() + }); + } + preview() { + const pileData = get_store_value(this.store.pileData); + if (!pileData.canInspectItems && !game.user.isGM) + return; + if (SYSTEMS.DATA?.PREVIEW_ITEM_TRANSFORMER) { + if (!SYSTEMS.DATA?.PREVIEW_ITEM_TRANSFORMER(this.item)) { + return; + } + } + if (game.user.isGM || this.item.permission[game.user.id] === 3) { + return this.item.sheet.render(true); + } + const cls = this.item._getSheetClass(); + const sheet = new cls(this.item, { editable: false }); + return sheet._render(true); + } +} +__name(PileItem, "PileItem"); +class PileAttribute extends PileBaseItem { + setupStores(attribute) { + super.setupStores(); + this.attribute = attribute; + this.path = this.attribute.path; + this.name = writable$1(this.attribute.name); + this.img = writable$1(this.attribute.img); + this.abbreviation = writable$1(this.attribute.abbreviation); + this.identifier = randomID(); + const startingQuantity = Number(getProperty(this.store.actor, this.path) ?? 0); + this.presentFromTheStart.set(startingQuantity > 0); + this.quantity.set(startingQuantity); + this.currentQuantity.set(Math.min(get_store_value(this.currentQuantity), get_store_value(this.quantityLeft), get_store_value(this.quantity))); + this.category.set({ type: "currency", label: "ITEM-PILES.Currency" }); + } + setupSubscriptions() { + super.setupSubscriptions(); + this.subscribeTo(this.store.pileData, this.setupProperties.bind(this)); + this.subscribeTo(this.store.shareData, (val) => { + if (!this.toShare) { + this.quantityLeft.set(get_store_value(this.quantity)); + return; + } + const quantityLeft = getAttributeSharesLeftForActor(this.store.actor, this.path, this.store.recipient); + this.quantityLeft.set(quantityLeft); + }); + this.subscribeTo(this.store.document, () => { + const { data: data2 } = this.store.document.updateOptions; + this.path = this.attribute.path; + this.name.set(this.attribute.name); + this.img.set(this.attribute.img); + if (hasProperty(data2, this.path)) { + this.quantity.set(Number(getProperty(data2, this.path) ?? 0)); + this.currentQuantity.set(Math.min(get_store_value(this.currentQuantity), get_store_value(this.quantityLeft), get_store_value(this.quantity))); + this.store.refreshItems(); + } + }); + this.subscribeTo(this.quantity, this.filter.bind(this)); + this.subscribeTo(this.store.search, this.filter.bind(this)); + } + setupProperties() { + this.toShare = get_store_value(this.store.pileData).shareCurrenciesEnabled && !!this.store.recipient; + } + filter() { + const name = get_store_value(this.name); + const search = get_store_value(this.store.search); + const presentFromTheStart = get_store_value(this.presentFromTheStart); + const quantity = get_store_value(this.quantity); + if (quantity === 0 && !presentFromTheStart) { + this.filtered.set(true); + } else if (search) { + this.filtered.set(!name.toLowerCase().includes(search.toLowerCase())); + } else { + this.filtered.set(!presentFromTheStart && quantity === 0); + } + } + take() { + const quantity = Math.min(get_store_value(this.currentQuantity), get_store_value(this.quantityLeft)); + return game.itempiles.API.transferAttributes( + this.store.actor, + this.store.recipient, + { [this.path]: quantity }, + { interactionId: this.store.interactionId } + ); + } + updateQuantity() { + return this.store.actor.update({ + [this.path]: get_store_value(this.quantity) + }); + } +} +__name(PileAttribute, "PileAttribute"); +function get_each_context$v(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[32] = list[i]; + child_ctx[33] = list; + child_ctx[34] = i; + return child_ctx; +} +__name(get_each_context$v, "get_each_context$v"); +function get_each_context_1$f(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[35] = list[i]; + child_ctx[36] = list; + child_ctx[34] = i; + return child_ctx; +} +__name(get_each_context_1$f, "get_each_context_1$f"); +function get_each_context_2$7(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[32] = list[i]; + child_ctx[37] = list; + child_ctx[34] = i; + return child_ctx; +} +__name(get_each_context_2$7, "get_each_context_2$7"); +function get_each_context_3$4(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[35] = list[i]; + child_ctx[38] = list; + child_ctx[34] = i; + return child_ctx; +} +__name(get_each_context_3$4, "get_each_context_3$4"); +function create_else_block_4(ctx) { + let p; + let t_value = localize(`ITEM-PILES.Applications.${/*localization*/ + ctx[2]}.NoCurrency`, { actor_name: ( + /*sourceActor*/ + ctx[1].name + ) }) + ""; + let t; + return { + c() { + p = element("p"); + t = text(t_value); + set_style(p, "text-align", "center"); + }, + m(target, anchor) { + insert(target, p, anchor); + append(p, t); + }, + p(ctx2, dirty) { + if (dirty[0] & /*localization, sourceActor*/ + 6 && t_value !== (t_value = localize(`ITEM-PILES.Applications.${/*localization*/ + ctx2[2]}.NoCurrency`, { actor_name: ( + /*sourceActor*/ + ctx2[1].name + ) }) + "")) + set_data(t, t_value); + }, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_else_block_4, "create_else_block_4"); +function create_if_block_1$y(ctx) { + let p; + let t0_value = ( + /*settings*/ + (ctx[3]?.content ?? localize(`ITEM-PILES.Applications.${/*localization*/ + ctx[2]}.Content`)) + "" + ); + let t0; + let t1; + let each_blocks_1 = []; + let each0_lookup = /* @__PURE__ */ new Map(); + let t2; + let each_blocks = []; + let each1_lookup = /* @__PURE__ */ new Map(); + let t3; + let show_if = ( + /*attributes*/ + ctx[4].filter(func$2).length || /*items*/ + ctx[5].filter(func_1).length + ); + let if_block_anchor; + let each_value_3 = ( + /*attributes*/ + ctx[4].filter(func_2$1) + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*attribute*/ + ctx2[35].path + ), "get_key"); + for (let i = 0; i < each_value_3.length; i += 1) { + let child_ctx = get_each_context_3$4(ctx, each_value_3, i); + let key = get_key(child_ctx); + each0_lookup.set(key, each_blocks_1[i] = create_each_block_3$4(key, child_ctx)); + } + let each_value_2 = ( + /*items*/ + ctx[5].filter(func_3) + ); + const get_key_1 = /* @__PURE__ */ __name((ctx2) => ( + /*item*/ + ctx2[32].id + ), "get_key_1"); + for (let i = 0; i < each_value_2.length; i += 1) { + let child_ctx = get_each_context_2$7(ctx, each_value_2, i); + let key = get_key_1(child_ctx); + each1_lookup.set(key, each_blocks[i] = create_each_block_2$7(key, child_ctx)); + } + let if_block = show_if && create_if_block_2$o(ctx); + return { + c() { + p = element("p"); + t0 = text(t0_value); + t1 = space(); + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].c(); + } + t2 = space(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + t3 = space(); + if (if_block) + if_block.c(); + if_block_anchor = empty(); + set_style(p, "text-align", "center"); + set_style(p, "margin", "0"); + attr(p, "class", "item-piles-bottom-divider"); + }, + m(target, anchor) { + insert(target, p, anchor); + append(p, t0); + insert(target, t1, anchor); + for (let i = 0; i < each_blocks_1.length; i += 1) { + if (each_blocks_1[i]) { + each_blocks_1[i].m(target, anchor); + } + } + insert(target, t2, anchor); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(target, anchor); + } + } + insert(target, t3, anchor); + if (if_block) + if_block.m(target, anchor); + insert(target, if_block_anchor, anchor); + }, + p(ctx2, dirty) { + if (dirty[0] & /*settings, localization*/ + 12 && t0_value !== (t0_value = /*settings*/ + (ctx2[3]?.content ?? localize(`ITEM-PILES.Applications.${/*localization*/ + ctx2[2]}.Content`)) + "")) + set_data(t0, t0_value); + if (dirty[0] & /*attributes, settings*/ + 24) { + each_value_3 = /*attributes*/ + ctx2[4].filter(func_2$1); + each_blocks_1 = update_keyed_each(each_blocks_1, dirty, get_key, 1, ctx2, each_value_3, each0_lookup, t2.parentNode, destroy_block, create_each_block_3$4, t2, get_each_context_3$4); + } + if (dirty[0] & /*items, settings*/ + 40) { + each_value_2 = /*items*/ + ctx2[5].filter(func_3); + each_blocks = update_keyed_each(each_blocks, dirty, get_key_1, 1, ctx2, each_value_2, each1_lookup, t3.parentNode, destroy_block, create_each_block_2$7, t3, get_each_context_2$7); + } + if (dirty[0] & /*attributes, items*/ + 48) + show_if = /*attributes*/ + ctx2[4].filter(func$2).length || /*items*/ + ctx2[5].filter(func_1).length; + if (show_if) { + if (if_block) { + if_block.p(ctx2, dirty); + } else { + if_block = create_if_block_2$o(ctx2); + if_block.c(); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + } else if (if_block) { + if_block.d(1); + if_block = null; + } + }, + d(detaching) { + if (detaching) + detach(p); + if (detaching) + detach(t1); + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].d(detaching); + } + if (detaching) + detach(t2); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(detaching); + } + if (detaching) + detach(t3); + if (if_block) + if_block.d(detaching); + if (detaching) + detach(if_block_anchor); + } + }; +} +__name(create_if_block_1$y, "create_if_block_1$y"); +function create_else_block_3(ctx) { + let input0; + let input0_max_value; + let t0; + let input1; + let t1; + let div; + let t2; + let t3_value = abbreviateNumbers( + /*attribute*/ + ctx[35].quantity + ) + ""; + let t3; + let mounted; + let dispose; + function input0_change_input_handler() { + ctx[12].call( + input0, + /*each_value_3*/ + ctx[38], + /*index*/ + ctx[34] + ); + } + __name(input0_change_input_handler, "input0_change_input_handler"); + function input1_input_handler() { + ctx[13].call( + input1, + /*each_value_3*/ + ctx[38], + /*index*/ + ctx[34] + ); + } + __name(input1_input_handler, "input1_input_handler"); + function click_handler() { + return ( + /*click_handler*/ + ctx[14]( + /*attribute*/ + ctx[35], + /*each_value_3*/ + ctx[38], + /*index*/ + ctx[34] + ) + ); + } + __name(click_handler, "click_handler"); + return { + c() { + input0 = element("input"); + t0 = space(); + input1 = element("input"); + t1 = space(); + div = element("div"); + t2 = text("/ "); + t3 = text(t3_value); + attr(input0, "class", "item-piles-range-slider"); + set_style(input0, "flex", "5"); + attr(input0, "type", "range"); + attr(input0, "min", "0"); + attr(input0, "max", input0_max_value = /*attribute*/ + ctx[35].quantity); + attr(input1, "class", "item-piles-range-input"); + set_style(input1, "flex", "2"); + set_style(input1, "margin-left", "1rem"); + attr(input1, "type", "number"); + set_style(div, "flex", "0 1 50px"); + set_style(div, "margin", "0 5px"); + }, + m(target, anchor) { + insert(target, input0, anchor); + set_input_value( + input0, + /*attribute*/ + ctx[35].currentQuantity + ); + insert(target, t0, anchor); + insert(target, input1, anchor); + set_input_value( + input1, + /*attribute*/ + ctx[35].currentQuantity + ); + insert(target, t1, anchor); + insert(target, div, anchor); + append(div, t2); + append(div, t3); + if (!mounted) { + dispose = [ + listen(input0, "change", input0_change_input_handler), + listen(input0, "input", input0_change_input_handler), + listen(input1, "input", input1_input_handler), + listen(input1, "click", click_handler) + ]; + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*attributes*/ + 16 && input0_max_value !== (input0_max_value = /*attribute*/ + ctx[35].quantity)) { + attr(input0, "max", input0_max_value); + } + if (dirty[0] & /*attributes*/ + 16) { + set_input_value( + input0, + /*attribute*/ + ctx[35].currentQuantity + ); + } + if (dirty[0] & /*attributes*/ + 16 && to_number(input1.value) !== /*attribute*/ + ctx[35].currentQuantity) { + set_input_value( + input1, + /*attribute*/ + ctx[35].currentQuantity + ); + } + if (dirty[0] & /*attributes*/ + 16 && t3_value !== (t3_value = abbreviateNumbers( + /*attribute*/ + ctx[35].quantity + ) + "")) + set_data(t3, t3_value); + }, + d(detaching) { + if (detaching) + detach(input0); + if (detaching) + detach(t0); + if (detaching) + detach(input1); + if (detaching) + detach(t1); + if (detaching) + detach(div); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_else_block_3, "create_else_block_3"); +function create_if_block_6$7(ctx) { + let input; + let mounted; + let dispose; + function input_input_handler() { + ctx[11].call( + input, + /*each_value_3*/ + ctx[38], + /*index*/ + ctx[34] + ); + } + __name(input_input_handler, "input_input_handler"); + return { + c() { + input = element("input"); + attr(input, "class", "item-piles-range-input"); + set_style(input, "flex", "2"); + set_style(input, "margin-left", "1rem"); + attr(input, "type", "number"); + }, + m(target, anchor) { + insert(target, input, anchor); + set_input_value( + input, + /*attribute*/ + ctx[35].currentQuantity + ); + if (!mounted) { + dispose = listen(input, "input", input_input_handler); + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*attributes*/ + 16 && to_number(input.value) !== /*attribute*/ + ctx[35].currentQuantity) { + set_input_value( + input, + /*attribute*/ + ctx[35].currentQuantity + ); + } + }, + d(detaching) { + if (detaching) + detach(input); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_6$7, "create_if_block_6$7"); +function create_each_block_3$4(key_1, ctx) { + let div3; + let div0; + let img; + let img_src_value; + let t0; + let div2; + let div1; + let t1_value = ( + /*attribute*/ + ctx[35].name + "" + ); + let t1; + let t2; + function select_block_type_1(ctx2, dirty) { + if ( + /*settings*/ + ctx2[3]?.unlimitedCurrencies + ) + return create_if_block_6$7; + return create_else_block_3; + } + __name(select_block_type_1, "select_block_type_1"); + let current_block_type = select_block_type_1(ctx); + let if_block = current_block_type(ctx); + return { + key: key_1, + first: null, + c() { + div3 = element("div"); + div0 = element("div"); + img = element("img"); + t0 = space(); + div2 = element("div"); + div1 = element("div"); + t1 = text(t1_value); + t2 = space(); + if_block.c(); + attr(img, "class", "item-piles-img"); + if (!src_url_equal(img.src, img_src_value = /*attribute*/ + ctx[35].img)) + attr(img, "src", img_src_value); + attr(div0, "class", "item-piles-img-container"); + attr(div2, "class", "item-piles-name item-piles-text"); + attr(div3, "class", "form-group item-piles-slider-group item-piles-odd-color"); + this.first = div3; + }, + m(target, anchor) { + insert(target, div3, anchor); + append(div3, div0); + append(div0, img); + append(div3, t0); + append(div3, div2); + append(div2, div1); + append(div1, t1); + append(div3, t2); + if_block.m(div3, null); + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*attributes*/ + 16 && !src_url_equal(img.src, img_src_value = /*attribute*/ + ctx[35].img)) { + attr(img, "src", img_src_value); + } + if (dirty[0] & /*attributes*/ + 16 && t1_value !== (t1_value = /*attribute*/ + ctx[35].name + "")) + set_data(t1, t1_value); + if (current_block_type === (current_block_type = select_block_type_1(ctx)) && if_block) { + if_block.p(ctx, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx); + if (if_block) { + if_block.c(); + if_block.m(div3, null); + } + } + }, + d(detaching) { + if (detaching) + detach(div3); + if_block.d(); + } + }; +} +__name(create_each_block_3$4, "create_each_block_3$4"); +function create_else_block_2$3(ctx) { + let input0; + let input0_max_value; + let t0; + let input1; + let t1; + let div; + let t2; + let t3_value = abbreviateNumbers( + /*item*/ + ctx[32].quantity + ) + ""; + let t3; + let mounted; + let dispose; + function input0_change_input_handler_1() { + ctx[16].call( + input0, + /*each_value_2*/ + ctx[37], + /*index*/ + ctx[34] + ); + } + __name(input0_change_input_handler_1, "input0_change_input_handler_1"); + function input1_input_handler_1() { + ctx[17].call( + input1, + /*each_value_2*/ + ctx[37], + /*index*/ + ctx[34] + ); + } + __name(input1_input_handler_1, "input1_input_handler_1"); + function click_handler_1() { + return ( + /*click_handler_1*/ + ctx[18]( + /*item*/ + ctx[32], + /*each_value_2*/ + ctx[37], + /*index*/ + ctx[34] + ) + ); + } + __name(click_handler_1, "click_handler_1"); + return { + c() { + input0 = element("input"); + t0 = space(); + input1 = element("input"); + t1 = space(); + div = element("div"); + t2 = text("/ "); + t3 = text(t3_value); + attr(input0, "class", "item-piles-range-slider"); + set_style(input0, "flex", "5"); + attr(input0, "type", "range"); + attr(input0, "min", "0"); + attr(input0, "max", input0_max_value = /*item*/ + ctx[32].quantity); + attr(input1, "class", "item-piles-range-input"); + set_style(input1, "flex", "1.5"); + set_style(input1, "margin-left", "1rem"); + attr(input1, "type", "number"); + set_style(div, "flex", "0 1 50px"); + set_style(div, "margin", "0 5px"); + }, + m(target, anchor) { + insert(target, input0, anchor); + set_input_value( + input0, + /*item*/ + ctx[32].currentQuantity + ); + insert(target, t0, anchor); + insert(target, input1, anchor); + set_input_value( + input1, + /*item*/ + ctx[32].currentQuantity + ); + insert(target, t1, anchor); + insert(target, div, anchor); + append(div, t2); + append(div, t3); + if (!mounted) { + dispose = [ + listen(input0, "change", input0_change_input_handler_1), + listen(input0, "input", input0_change_input_handler_1), + listen(input1, "input", input1_input_handler_1), + listen(input1, "click", click_handler_1) + ]; + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*items*/ + 32 && input0_max_value !== (input0_max_value = /*item*/ + ctx[32].quantity)) { + attr(input0, "max", input0_max_value); + } + if (dirty[0] & /*items*/ + 32) { + set_input_value( + input0, + /*item*/ + ctx[32].currentQuantity + ); + } + if (dirty[0] & /*items*/ + 32 && to_number(input1.value) !== /*item*/ + ctx[32].currentQuantity) { + set_input_value( + input1, + /*item*/ + ctx[32].currentQuantity + ); + } + if (dirty[0] & /*items*/ + 32 && t3_value !== (t3_value = abbreviateNumbers( + /*item*/ + ctx[32].quantity + ) + "")) + set_data(t3, t3_value); + }, + d(detaching) { + if (detaching) + detach(input0); + if (detaching) + detach(t0); + if (detaching) + detach(input1); + if (detaching) + detach(t1); + if (detaching) + detach(div); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_else_block_2$3, "create_else_block_2$3"); +function create_if_block_5$9(ctx) { + let input; + let mounted; + let dispose; + function input_input_handler_1() { + ctx[15].call( + input, + /*each_value_2*/ + ctx[37], + /*index*/ + ctx[34] + ); + } + __name(input_input_handler_1, "input_input_handler_1"); + return { + c() { + input = element("input"); + attr(input, "class", "item-piles-range-input"); + set_style(input, "flex", "2"); + set_style(input, "margin-left", "1rem"); + attr(input, "type", "number"); + }, + m(target, anchor) { + insert(target, input, anchor); + set_input_value( + input, + /*item*/ + ctx[32].currentQuantity + ); + if (!mounted) { + dispose = listen(input, "input", input_input_handler_1); + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*items*/ + 32 && to_number(input.value) !== /*item*/ + ctx[32].currentQuantity) { + set_input_value( + input, + /*item*/ + ctx[32].currentQuantity + ); + } + }, + d(detaching) { + if (detaching) + detach(input); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_5$9, "create_if_block_5$9"); +function create_each_block_2$7(key_1, ctx) { + let div3; + let div0; + let img; + let img_src_value; + let t0; + let div2; + let div1; + let t1_value = ( + /*item*/ + ctx[32].name + "" + ); + let t1; + let t2; + function select_block_type_2(ctx2, dirty) { + if ( + /*settings*/ + ctx2[3]?.unlimitedCurrencies + ) + return create_if_block_5$9; + return create_else_block_2$3; + } + __name(select_block_type_2, "select_block_type_2"); + let current_block_type = select_block_type_2(ctx); + let if_block = current_block_type(ctx); + return { + key: key_1, + first: null, + c() { + div3 = element("div"); + div0 = element("div"); + img = element("img"); + t0 = space(); + div2 = element("div"); + div1 = element("div"); + t1 = text(t1_value); + t2 = space(); + if_block.c(); + attr(img, "class", "item-piles-img"); + if (!src_url_equal(img.src, img_src_value = /*item*/ + ctx[32].img)) + attr(img, "src", img_src_value); + attr(div0, "class", "item-piles-img-container"); + attr(div2, "class", "item-piles-name item-piles-text"); + attr(div3, "class", "form-group item-piles-slider-group item-piles-odd-color"); + this.first = div3; + }, + m(target, anchor) { + insert(target, div3, anchor); + append(div3, div0); + append(div0, img); + append(div3, t0); + append(div3, div2); + append(div2, div1); + append(div1, t1); + append(div3, t2); + if_block.m(div3, null); + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*items*/ + 32 && !src_url_equal(img.src, img_src_value = /*item*/ + ctx[32].img)) { + attr(img, "src", img_src_value); + } + if (dirty[0] & /*items*/ + 32 && t1_value !== (t1_value = /*item*/ + ctx[32].name + "")) + set_data(t1, t1_value); + if (current_block_type === (current_block_type = select_block_type_2(ctx)) && if_block) { + if_block.p(ctx, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx); + if (if_block) { + if_block.c(); + if_block.m(div3, null); + } + } + }, + d(detaching) { + if (detaching) + detach(div3); + if_block.d(); + } + }; +} +__name(create_each_block_2$7, "create_each_block_2$7"); +function create_if_block_2$o(ctx) { + let div; + let t0; + let each_blocks_1 = []; + let each0_lookup = /* @__PURE__ */ new Map(); + let t1; + let each_blocks = []; + let each1_lookup = /* @__PURE__ */ new Map(); + let each1_anchor; + let each_value_1 = ( + /*attributes*/ + ctx[4].filter(func_4) + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*attribute*/ + ctx2[35].path + ), "get_key"); + for (let i = 0; i < each_value_1.length; i += 1) { + let child_ctx = get_each_context_1$f(ctx, each_value_1, i); + let key = get_key(child_ctx); + each0_lookup.set(key, each_blocks_1[i] = create_each_block_1$f(key, child_ctx)); + } + let each_value = ( + /*items*/ + ctx[5].filter(func_5) + ); + const get_key_1 = /* @__PURE__ */ __name((ctx2) => ( + /*item*/ + ctx2[32].id + ), "get_key_1"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$v(ctx, each_value, i); + let key = get_key_1(child_ctx); + each1_lookup.set(key, each_blocks[i] = create_each_block$v(key, child_ctx)); + } + return { + c() { + div = element("div"); + t0 = space(); + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].c(); + } + t1 = space(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + each1_anchor = empty(); + attr(div, "class", "item-piles-top-divider"); + }, + m(target, anchor) { + insert(target, div, anchor); + insert(target, t0, anchor); + for (let i = 0; i < each_blocks_1.length; i += 1) { + if (each_blocks_1[i]) { + each_blocks_1[i].m(target, anchor); + } + } + insert(target, t1, anchor); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(target, anchor); + } + } + insert(target, each1_anchor, anchor); + }, + p(ctx2, dirty) { + if (dirty[0] & /*attributes, settings*/ + 24) { + each_value_1 = /*attributes*/ + ctx2[4].filter(func_4); + each_blocks_1 = update_keyed_each(each_blocks_1, dirty, get_key, 1, ctx2, each_value_1, each0_lookup, t1.parentNode, destroy_block, create_each_block_1$f, t1, get_each_context_1$f); + } + if (dirty[0] & /*items, settings*/ + 40) { + each_value = /*items*/ + ctx2[5].filter(func_5); + each_blocks = update_keyed_each(each_blocks, dirty, get_key_1, 1, ctx2, each_value, each1_lookup, each1_anchor.parentNode, destroy_block, create_each_block$v, each1_anchor, get_each_context$v); + } + }, + d(detaching) { + if (detaching) + detach(div); + if (detaching) + detach(t0); + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].d(detaching); + } + if (detaching) + detach(t1); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(detaching); + } + if (detaching) + detach(each1_anchor); + } + }; +} +__name(create_if_block_2$o, "create_if_block_2$o"); +function create_else_block_1$6(ctx) { + let input0; + let input0_max_value; + let t0; + let input1; + let t1; + let div; + let t2; + let t3_value = abbreviateNumbers( + /*attribute*/ + ctx[35].quantity + ) + ""; + let t3; + let mounted; + let dispose; + function input0_change_input_handler_2() { + ctx[20].call( + input0, + /*each_value_1*/ + ctx[36], + /*index*/ + ctx[34] + ); + } + __name(input0_change_input_handler_2, "input0_change_input_handler_2"); + function input1_input_handler_2() { + ctx[21].call( + input1, + /*each_value_1*/ + ctx[36], + /*index*/ + ctx[34] + ); + } + __name(input1_input_handler_2, "input1_input_handler_2"); + function click_handler_2() { + return ( + /*click_handler_2*/ + ctx[22]( + /*attribute*/ + ctx[35], + /*each_value_1*/ + ctx[36], + /*index*/ + ctx[34] + ) + ); + } + __name(click_handler_2, "click_handler_2"); + return { + c() { + input0 = element("input"); + t0 = space(); + input1 = element("input"); + t1 = space(); + div = element("div"); + t2 = text("/ "); + t3 = text(t3_value); + attr(input0, "class", "item-piles-range-slider"); + set_style(input0, "flex", "5"); + attr(input0, "type", "range"); + attr(input0, "min", "0"); + attr(input0, "max", input0_max_value = /*attribute*/ + ctx[35].quantity); + attr(input1, "class", "item-piles-range-input"); + set_style(input1, "flex", "2"); + set_style(input1, "margin-left", "1rem"); + attr(input1, "type", "number"); + set_style(div, "flex", "0 1 50px"); + set_style(div, "margin", "0 5px"); + }, + m(target, anchor) { + insert(target, input0, anchor); + set_input_value( + input0, + /*attribute*/ + ctx[35].currentQuantity + ); + insert(target, t0, anchor); + insert(target, input1, anchor); + set_input_value( + input1, + /*attribute*/ + ctx[35].currentQuantity + ); + insert(target, t1, anchor); + insert(target, div, anchor); + append(div, t2); + append(div, t3); + if (!mounted) { + dispose = [ + listen(input0, "change", input0_change_input_handler_2), + listen(input0, "input", input0_change_input_handler_2), + listen(input1, "input", input1_input_handler_2), + listen(input1, "click", click_handler_2) + ]; + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*attributes*/ + 16 && input0_max_value !== (input0_max_value = /*attribute*/ + ctx[35].quantity)) { + attr(input0, "max", input0_max_value); + } + if (dirty[0] & /*attributes*/ + 16) { + set_input_value( + input0, + /*attribute*/ + ctx[35].currentQuantity + ); + } + if (dirty[0] & /*attributes*/ + 16 && to_number(input1.value) !== /*attribute*/ + ctx[35].currentQuantity) { + set_input_value( + input1, + /*attribute*/ + ctx[35].currentQuantity + ); + } + if (dirty[0] & /*attributes*/ + 16 && t3_value !== (t3_value = abbreviateNumbers( + /*attribute*/ + ctx[35].quantity + ) + "")) + set_data(t3, t3_value); + }, + d(detaching) { + if (detaching) + detach(input0); + if (detaching) + detach(t0); + if (detaching) + detach(input1); + if (detaching) + detach(t1); + if (detaching) + detach(div); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_else_block_1$6, "create_else_block_1$6"); +function create_if_block_4$d(ctx) { + let input; + let mounted; + let dispose; + function input_input_handler_2() { + ctx[19].call( + input, + /*each_value_1*/ + ctx[36], + /*index*/ + ctx[34] + ); + } + __name(input_input_handler_2, "input_input_handler_2"); + return { + c() { + input = element("input"); + attr(input, "class", "item-piles-range-input"); + set_style(input, "flex", "2"); + set_style(input, "margin-left", "1rem"); + attr(input, "type", "number"); + }, + m(target, anchor) { + insert(target, input, anchor); + set_input_value( + input, + /*attribute*/ + ctx[35].currentQuantity + ); + if (!mounted) { + dispose = listen(input, "input", input_input_handler_2); + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*attributes*/ + 16 && to_number(input.value) !== /*attribute*/ + ctx[35].currentQuantity) { + set_input_value( + input, + /*attribute*/ + ctx[35].currentQuantity + ); + } + }, + d(detaching) { + if (detaching) + detach(input); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_4$d, "create_if_block_4$d"); +function create_each_block_1$f(key_1, ctx) { + let div3; + let div0; + let img; + let img_src_value; + let t0; + let div2; + let div1; + let t1_value = ( + /*attribute*/ + ctx[35].name + "" + ); + let t1; + let t2; + function select_block_type_3(ctx2, dirty) { + if ( + /*settings*/ + ctx2[3]?.unlimitedCurrencies + ) + return create_if_block_4$d; + return create_else_block_1$6; + } + __name(select_block_type_3, "select_block_type_3"); + let current_block_type = select_block_type_3(ctx); + let if_block = current_block_type(ctx); + return { + key: key_1, + first: null, + c() { + div3 = element("div"); + div0 = element("div"); + img = element("img"); + t0 = space(); + div2 = element("div"); + div1 = element("div"); + t1 = text(t1_value); + t2 = space(); + if_block.c(); + attr(img, "class", "item-piles-img"); + if (!src_url_equal(img.src, img_src_value = /*attribute*/ + ctx[35].img)) + attr(img, "src", img_src_value); + attr(div0, "class", "item-piles-img-container"); + attr(div2, "class", "item-piles-name item-piles-text"); + attr(div3, "class", "form-group item-piles-slider-group item-piles-odd-color"); + this.first = div3; + }, + m(target, anchor) { + insert(target, div3, anchor); + append(div3, div0); + append(div0, img); + append(div3, t0); + append(div3, div2); + append(div2, div1); + append(div1, t1); + append(div3, t2); + if_block.m(div3, null); + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*attributes*/ + 16 && !src_url_equal(img.src, img_src_value = /*attribute*/ + ctx[35].img)) { + attr(img, "src", img_src_value); + } + if (dirty[0] & /*attributes*/ + 16 && t1_value !== (t1_value = /*attribute*/ + ctx[35].name + "")) + set_data(t1, t1_value); + if (current_block_type === (current_block_type = select_block_type_3(ctx)) && if_block) { + if_block.p(ctx, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx); + if (if_block) { + if_block.c(); + if_block.m(div3, null); + } + } + }, + d(detaching) { + if (detaching) + detach(div3); + if_block.d(); + } + }; +} +__name(create_each_block_1$f, "create_each_block_1$f"); +function create_else_block$h(ctx) { + let input0; + let input0_max_value; + let t0; + let input1; + let t1; + let div; + let t2; + let t3_value = abbreviateNumbers( + /*item*/ + ctx[32].quantity + ) + ""; + let t3; + let mounted; + let dispose; + function input0_change_input_handler_3() { + ctx[24].call( + input0, + /*each_value*/ + ctx[33], + /*index*/ + ctx[34] + ); + } + __name(input0_change_input_handler_3, "input0_change_input_handler_3"); + function input1_input_handler_3() { + ctx[25].call( + input1, + /*each_value*/ + ctx[33], + /*index*/ + ctx[34] + ); + } + __name(input1_input_handler_3, "input1_input_handler_3"); + function click_handler_32() { + return ( + /*click_handler_3*/ + ctx[26]( + /*item*/ + ctx[32], + /*each_value*/ + ctx[33], + /*index*/ + ctx[34] + ) + ); + } + __name(click_handler_32, "click_handler_3"); + return { + c() { + input0 = element("input"); + t0 = space(); + input1 = element("input"); + t1 = space(); + div = element("div"); + t2 = text("/ "); + t3 = text(t3_value); + attr(input0, "class", "item-piles-range-slider"); + set_style(input0, "flex", "5"); + attr(input0, "type", "range"); + attr(input0, "min", "0"); + attr(input0, "max", input0_max_value = /*item*/ + ctx[32].quantity); + attr(input1, "class", "item-piles-range-input"); + set_style(input1, "flex", "1.5"); + set_style(input1, "margin-left", "1rem"); + attr(input1, "type", "number"); + set_style(div, "flex", "0 1 50px"); + set_style(div, "margin", "0 5px"); + }, + m(target, anchor) { + insert(target, input0, anchor); + set_input_value( + input0, + /*item*/ + ctx[32].currentQuantity + ); + insert(target, t0, anchor); + insert(target, input1, anchor); + set_input_value( + input1, + /*item*/ + ctx[32].currentQuantity + ); + insert(target, t1, anchor); + insert(target, div, anchor); + append(div, t2); + append(div, t3); + if (!mounted) { + dispose = [ + listen(input0, "change", input0_change_input_handler_3), + listen(input0, "input", input0_change_input_handler_3), + listen(input1, "input", input1_input_handler_3), + listen(input1, "click", click_handler_32) + ]; + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*items*/ + 32 && input0_max_value !== (input0_max_value = /*item*/ + ctx[32].quantity)) { + attr(input0, "max", input0_max_value); + } + if (dirty[0] & /*items*/ + 32) { + set_input_value( + input0, + /*item*/ + ctx[32].currentQuantity + ); + } + if (dirty[0] & /*items*/ + 32 && to_number(input1.value) !== /*item*/ + ctx[32].currentQuantity) { + set_input_value( + input1, + /*item*/ + ctx[32].currentQuantity + ); + } + if (dirty[0] & /*items*/ + 32 && t3_value !== (t3_value = abbreviateNumbers( + /*item*/ + ctx[32].quantity + ) + "")) + set_data(t3, t3_value); + }, + d(detaching) { + if (detaching) + detach(input0); + if (detaching) + detach(t0); + if (detaching) + detach(input1); + if (detaching) + detach(t1); + if (detaching) + detach(div); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_else_block$h, "create_else_block$h"); +function create_if_block_3$j(ctx) { + let input; + let mounted; + let dispose; + function input_input_handler_3() { + ctx[23].call( + input, + /*each_value*/ + ctx[33], + /*index*/ + ctx[34] + ); + } + __name(input_input_handler_3, "input_input_handler_3"); + return { + c() { + input = element("input"); + attr(input, "class", "item-piles-range-input"); + set_style(input, "flex", "2"); + set_style(input, "margin-left", "1rem"); + attr(input, "type", "number"); + }, + m(target, anchor) { + insert(target, input, anchor); + set_input_value( + input, + /*item*/ + ctx[32].currentQuantity + ); + if (!mounted) { + dispose = listen(input, "input", input_input_handler_3); + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*items*/ + 32 && to_number(input.value) !== /*item*/ + ctx[32].currentQuantity) { + set_input_value( + input, + /*item*/ + ctx[32].currentQuantity + ); + } + }, + d(detaching) { + if (detaching) + detach(input); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_3$j, "create_if_block_3$j"); +function create_each_block$v(key_1, ctx) { + let div3; + let div0; + let img; + let img_src_value; + let t0; + let div2; + let div1; + let t1_value = ( + /*item*/ + ctx[32].name + "" + ); + let t1; + let t2; + let t3; + function select_block_type_4(ctx2, dirty) { + if ( + /*settings*/ + ctx2[3]?.unlimitedCurrencies + ) + return create_if_block_3$j; + return create_else_block$h; + } + __name(select_block_type_4, "select_block_type_4"); + let current_block_type = select_block_type_4(ctx); + let if_block = current_block_type(ctx); + return { + key: key_1, + first: null, + c() { + div3 = element("div"); + div0 = element("div"); + img = element("img"); + t0 = space(); + div2 = element("div"); + div1 = element("div"); + t1 = text(t1_value); + t2 = space(); + if_block.c(); + t3 = space(); + attr(img, "class", "item-piles-img"); + if (!src_url_equal(img.src, img_src_value = /*item*/ + ctx[32].img)) + attr(img, "src", img_src_value); + attr(div0, "class", "item-piles-img-container"); + attr(div2, "class", "item-piles-name item-piles-text"); + attr(div3, "class", "form-group item-piles-slider-group item-piles-odd-color"); + this.first = div3; + }, + m(target, anchor) { + insert(target, div3, anchor); + append(div3, div0); + append(div0, img); + append(div3, t0); + append(div3, div2); + append(div2, div1); + append(div1, t1); + append(div3, t2); + if_block.m(div3, null); + append(div3, t3); + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*items*/ + 32 && !src_url_equal(img.src, img_src_value = /*item*/ + ctx[32].img)) { + attr(img, "src", img_src_value); + } + if (dirty[0] & /*items*/ + 32 && t1_value !== (t1_value = /*item*/ + ctx[32].name + "")) + set_data(t1, t1_value); + if (current_block_type === (current_block_type = select_block_type_4(ctx)) && if_block) { + if_block.p(ctx, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx); + if (if_block) { + if_block.c(); + if_block.m(div3, t3); + } + } + }, + d(detaching) { + if (detaching) + detach(div3); + if_block.d(); + } + }; +} +__name(create_each_block$v, "create_each_block$v"); +function create_if_block$K(ctx) { + let button; + let i; + let t0; + let t1_value = localize( + /*settings*/ + ctx[3]?.button ?? `ITEM-PILES.Applications.${/*localization*/ + ctx[2]}.Submit` + ) + ""; + let t1; + let mounted; + let dispose; + return { + c() { + button = element("button"); + i = element("i"); + t0 = space(); + t1 = text(t1_value); + attr(i, "class", "fas fa-download"); + attr(button, "type", "button"); + }, + m(target, anchor) { + insert(target, button, anchor); + append(button, i); + append(button, t0); + append(button, t1); + if (!mounted) { + dispose = listen( + button, + "click", + /*requestSubmit*/ + ctx[8], + { once: true } + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty[0] & /*settings, localization*/ + 12 && t1_value !== (t1_value = localize( + /*settings*/ + ctx2[3]?.button ?? `ITEM-PILES.Applications.${/*localization*/ + ctx2[2]}.Submit` + ) + "")) + set_data(t1, t1_value); + }, + d(detaching) { + if (detaching) + detach(button); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block$K, "create_if_block$K"); +function create_default_slot$m(ctx) { + let form_1; + let t0; + let footer; + let t1; + let button; + let i; + let t2; + let t3_value = localize("Cancel") + ""; + let t3; + let mounted; + let dispose; + function select_block_type(ctx2, dirty) { + if ( + /*attributes*/ + ctx2[4].length || /*items*/ + ctx2[5].length + ) + return create_if_block_1$y; + return create_else_block_4; + } + __name(select_block_type, "select_block_type"); + let current_block_type = select_block_type(ctx); + let if_block0 = current_block_type(ctx); + let if_block1 = ( + /*attributes*/ + (ctx[4].length || /*items*/ + ctx[5].length) && create_if_block$K(ctx) + ); + return { + c() { + form_1 = element("form"); + if_block0.c(); + t0 = space(); + footer = element("footer"); + if (if_block1) + if_block1.c(); + t1 = space(); + button = element("button"); + i = element("i"); + t2 = space(); + t3 = text(t3_value); + attr(i, "class", "fas fa-times"); + attr(button, "type", "button"); + attr(footer, "class", "sheet-footer item-piles-flexrow"); + set_style(footer, "margin-top", "1rem"); + attr(form_1, "autocomplete", "off"); + attr(form_1, "class", "item-piles-flexcol"); + set_style(form_1, "padding", "0.5rem"); + }, + m(target, anchor) { + insert(target, form_1, anchor); + if_block0.m(form_1, null); + append(form_1, t0); + append(form_1, footer); + if (if_block1) + if_block1.m(footer, null); + append(footer, t1); + append(footer, button); + append(button, i); + append(button, t2); + append(button, t3); + ctx[28](form_1); + if (!mounted) { + dispose = [ + listen( + button, + "click", + /*click_handler_4*/ + ctx[27], + { once: true } + ), + listen(form_1, "submit", prevent_default( + /*submit*/ + ctx[9] + ), { once: true }) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0.d(1); + if_block0 = current_block_type(ctx2); + if (if_block0) { + if_block0.c(); + if_block0.m(form_1, t0); + } + } + if ( + /*attributes*/ + ctx2[4].length || /*items*/ + ctx2[5].length + ) { + if (if_block1) { + if_block1.p(ctx2, dirty); + } else { + if_block1 = create_if_block$K(ctx2); + if_block1.c(); + if_block1.m(footer, t1); + } + } else if (if_block1) { + if_block1.d(1); + if_block1 = null; + } + }, + d(detaching) { + if (detaching) + detach(form_1); + if_block0.d(); + if (if_block1) + if_block1.d(); + ctx[28](null); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$m, "create_default_slot$m"); +function create_fragment$_(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[29](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot$m] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, dirty) { + const applicationshell_changes = {}; + if (dirty[0] & /*form, settings, localization, attributes, items, sourceActor*/ + 126 | dirty[1] & /*$$scope*/ + 256) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty[0] & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment$_, "create_fragment$_"); +const func$2 = /* @__PURE__ */ __name((currency) => currency.secondary, "func$2"); +const func_1 = /* @__PURE__ */ __name((currency) => currency.secondary, "func_1"); +const func_2$1 = /* @__PURE__ */ __name((currency) => !currency.secondary, "func_2$1"); +const func_3 = /* @__PURE__ */ __name((currency) => !currency.secondary, "func_3"); +const func_4 = /* @__PURE__ */ __name((currency) => currency.secondary, "func_4"); +const func_5 = /* @__PURE__ */ __name((currency) => currency.secondary, "func_5"); +function instance$_($$self, $$props, $$invalidate) { + const { application } = getContext("#external"); + let { sourceActor } = $$props; + let { targetActor } = $$props; + let { localization } = $$props; + let { settings } = $$props; + let { elementRoot } = $$props; + const targetCurrencyData = getCurrencyList(targetActor); + const currencies = getActorCurrencies(sourceActor, { + currencyList: targetActor ? targetCurrencyData.currencies : false, + getAll: settings?.unlimitedCurrencies + }); + let attributes = currencies.filter((entry) => entry.type === "attribute").map((currency) => { + currency.currentQuantity = 0; + return currency; + }); + if (settings?.existingCurrencies) { + attributes.forEach((currency) => { + const existingCurrency = settings?.existingCurrencies.find((existingCurrency2) => existingCurrency2.id === currency.id); + if (existingCurrency) { + currency.currentQuantity = existingCurrency.quantity; + } + }); + } + let items = currencies.filter((entry) => entry.type !== "attribute").map((currency) => { + currency.create = !currency.id; + currency.id = currency.id ?? randomID(); + currency.currentQuantity = 0; + return currency; + }); + if (settings?.existingCurrencies) { + items.forEach((currency) => { + const existingCurrency = settings?.existingCurrencies.find((existingCurrency2) => existingCurrency2.id === currency.id); + if (existingCurrency) { + currency.currentQuantity = existingCurrency.quantity; + } + }); + } + let form; + function requestSubmit() { + form.requestSubmit(); + } + __name(requestSubmit, "requestSubmit"); + function submit() { + const itemsToUpdate = items.filter((item) => (settings.unlimitedCurrencies || item.currentQuantity) && !item.create).map((item) => { + return { + _id: item.id, + quantity: settings.getUpdates && item.quantity ? Math.min(item.quantity, item.currentQuantity - item.quantity) : item.currentQuantity + }; + }); + const itemsToCreate = items.filter((item) => item.currentQuantity && item.create).map((item) => ({ + item: item.data.item, + quantity: settings.unlimitedCurrencies ? item.currentQuantity : Math.max(0, Math.min(item.quantity, item.currentQuantity)) + })); + application.options.resolve({ + attributes: Object.fromEntries(attributes.filter((attribute) => settings.unlimitedCurrencies || attribute.currentQuantity).map((attribute) => [ + attribute.path, + settings.unlimitedCurrencies ? attribute.currentQuantity : Math.max(0, Math.min(attribute.quantity, attribute.currentQuantity)) + ])), + items: itemsToUpdate.concat(itemsToCreate) + }); + application.close(); + } + __name(submit, "submit"); + function input_input_handler(each_value_3, index2) { + each_value_3[index2].currentQuantity = to_number(this.value); + $$invalidate(4, attributes); + } + __name(input_input_handler, "input_input_handler"); + function input0_change_input_handler(each_value_3, index2) { + each_value_3[index2].currentQuantity = to_number(this.value); + $$invalidate(4, attributes); + } + __name(input0_change_input_handler, "input0_change_input_handler"); + function input1_input_handler(each_value_3, index2) { + each_value_3[index2].currentQuantity = to_number(this.value); + $$invalidate(4, attributes); + } + __name(input1_input_handler, "input1_input_handler"); + const click_handler = /* @__PURE__ */ __name((attribute, each_value_3, index2) => { + $$invalidate(4, each_value_3[index2].currentQuantity = Math.max(0, Math.min(attribute.quantity, attribute.currentQuantity)), attributes); + }, "click_handler"); + function input_input_handler_1(each_value_2, index2) { + each_value_2[index2].currentQuantity = to_number(this.value); + $$invalidate(5, items); + } + __name(input_input_handler_1, "input_input_handler_1"); + function input0_change_input_handler_1(each_value_2, index2) { + each_value_2[index2].currentQuantity = to_number(this.value); + $$invalidate(5, items); + } + __name(input0_change_input_handler_1, "input0_change_input_handler_1"); + function input1_input_handler_1(each_value_2, index2) { + each_value_2[index2].currentQuantity = to_number(this.value); + $$invalidate(5, items); + } + __name(input1_input_handler_1, "input1_input_handler_1"); + const click_handler_1 = /* @__PURE__ */ __name((item, each_value_2, index2) => { + $$invalidate(5, each_value_2[index2].currentQuantity = Math.max(0, Math.min(item.quantity, item.currentQuantity)), items); + }, "click_handler_1"); + function input_input_handler_2(each_value_1, index2) { + each_value_1[index2].currentQuantity = to_number(this.value); + $$invalidate(4, attributes); + } + __name(input_input_handler_2, "input_input_handler_2"); + function input0_change_input_handler_2(each_value_1, index2) { + each_value_1[index2].currentQuantity = to_number(this.value); + $$invalidate(4, attributes); + } + __name(input0_change_input_handler_2, "input0_change_input_handler_2"); + function input1_input_handler_2(each_value_1, index2) { + each_value_1[index2].currentQuantity = to_number(this.value); + $$invalidate(4, attributes); + } + __name(input1_input_handler_2, "input1_input_handler_2"); + const click_handler_2 = /* @__PURE__ */ __name((attribute, each_value_1, index2) => { + $$invalidate(4, each_value_1[index2].currentQuantity = Math.max(0, Math.min(attribute.quantity, attribute.currentQuantity)), attributes); + }, "click_handler_2"); + function input_input_handler_3(each_value, index2) { + each_value[index2].currentQuantity = to_number(this.value); + $$invalidate(5, items); + } + __name(input_input_handler_3, "input_input_handler_3"); + function input0_change_input_handler_3(each_value, index2) { + each_value[index2].currentQuantity = to_number(this.value); + $$invalidate(5, items); + } + __name(input0_change_input_handler_3, "input0_change_input_handler_3"); + function input1_input_handler_3(each_value, index2) { + each_value[index2].currentQuantity = to_number(this.value); + $$invalidate(5, items); + } + __name(input1_input_handler_3, "input1_input_handler_3"); + const click_handler_32 = /* @__PURE__ */ __name((item, each_value, index2) => { + $$invalidate(5, each_value[index2].currentQuantity = Math.max(0, Math.min(item.quantity, item.currentQuantity)), items); + }, "click_handler_3"); + const click_handler_4 = /* @__PURE__ */ __name(() => { + application.close(); + }, "click_handler_4"); + function form_1_binding($$value) { + binding_callbacks[$$value ? "unshift" : "push"](() => { + form = $$value; + $$invalidate(6, form); + }); + } + __name(form_1_binding, "form_1_binding"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("sourceActor" in $$props2) + $$invalidate(1, sourceActor = $$props2.sourceActor); + if ("targetActor" in $$props2) + $$invalidate(10, targetActor = $$props2.targetActor); + if ("localization" in $$props2) + $$invalidate(2, localization = $$props2.localization); + if ("settings" in $$props2) + $$invalidate(3, settings = $$props2.settings); + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + }; + return [ + elementRoot, + sourceActor, + localization, + settings, + attributes, + items, + form, + application, + requestSubmit, + submit, + targetActor, + input_input_handler, + input0_change_input_handler, + input1_input_handler, + click_handler, + input_input_handler_1, + input0_change_input_handler_1, + input1_input_handler_1, + click_handler_1, + input_input_handler_2, + input0_change_input_handler_2, + input1_input_handler_2, + click_handler_2, + input_input_handler_3, + input0_change_input_handler_3, + input1_input_handler_3, + click_handler_32, + click_handler_4, + form_1_binding, + applicationshell_elementRoot_binding + ]; +} +__name(instance$_, "instance$_"); +class Drop_currency_dialog_shell extends SvelteComponent { + constructor(options) { + super(); + init( + this, + options, + instance$_, + create_fragment$_, + safe_not_equal, + { + sourceActor: 1, + targetActor: 10, + localization: 2, + settings: 3, + elementRoot: 0 + }, + null, + [-1, -1] + ); + } + get sourceActor() { + return this.$$.ctx[1]; + } + set sourceActor(sourceActor) { + this.$$set({ sourceActor }); + flush(); + } + get targetActor() { + return this.$$.ctx[10]; + } + set targetActor(targetActor) { + this.$$set({ targetActor }); + flush(); + } + get localization() { + return this.$$.ctx[2]; + } + set localization(localization) { + this.$$set({ localization }); + flush(); + } + get settings() { + return this.$$.ctx[3]; + } + set settings(settings) { + this.$$set({ settings }); + flush(); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } +} +__name(Drop_currency_dialog_shell, "Drop_currency_dialog_shell"); +class DropCurrencyDialog extends SvelteApplication { + /** + * + * @param sourceActor + * @param targetActor + * @param settings + * @param options + */ + constructor(sourceActor, targetActor, settings = {}, options = {}) { + const localization = settings.localization || "DropCurrencies"; + super({ + id: `item-pile-drop-currency-${sourceActor ? sourceActor.id + (targetActor ? "-" + targetActor.id : "") : ""}-${randomID()}`, + title: settings.title ?? game.i18n.localize(`ITEM-PILES.Applications.${localization}.Title`), + svelte: { + class: Drop_currency_dialog_shell, + target: document.body, + props: { + sourceActor, + targetActor, + localization, + settings + } + }, + close: () => this.options.resolve?.(null), + ...options + }); + } + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + width: 430, + height: "auto", + classes: ["item-piles-app"] + }); + } + static getActiveApps(id) { + return getActiveApps(`item-pile-drop-currency-${id}`); + } + static async show(sourceActor, targetActor, settings = {}, options = {}) { + if (sourceActor) { + const apps = this.getActiveApps(targetActor ? sourceActor.uuid + "-" + targetActor.uuid : sourceActor.uuid); + if (apps.length) { + for (let app of apps) { + app.render(false, { focus: true }); + } + return; + } + } + return new Promise((resolve) => { + options.resolve = resolve; + new this(sourceActor, targetActor, settings, options).render(true, { focus: true }); + }); + } +} +__name(DropCurrencyDialog, "DropCurrencyDialog"); +const __STORES__ = /* @__PURE__ */ new Map(); +class ItemPileStore { + constructor(application, source, recipient = false, { recipientPileData = false } = {}) { + this.subscriptions = []; + this.interactionId = randomID(); + this.application = application; + this.uuid = getUuid(source); + this.actor = getActor(source); + this.document = new TJSDocument(this.actor); + this.recipient = recipient ? getActor(recipient) : false; + this.recipientDocument = recipient ? new TJSDocument(this.recipient) : new TJSDocument(); + this.recipientPileData = writable$1(recipientPileData); + this.pileData = writable$1({}); + this.shareData = writable$1({}); + this.recipientPileData = writable$1({}); + this.recipientShareData = writable$1({}); + this.deleted = writable$1(false); + this.search = writable$1(""); + this.editQuantities = writable$1(true); + this.allItems = writable$1([]); + this.attributes = writable$1([]); + this.items = writable$1([]); + this.visibleItems = writable$1([]); + this.pileCurrencies = writable$1([]); + this.recipientCurrencies = writable$1([]); + this.currencies = writable$1([]); + this.allCurrencies = writable$1([]); + this.itemsPerCategory = writable$1({}); + this.categories = writable$1([]); + this.itemCategories = writable$1([]); + this.numItems = writable$1(0); + this.numCurrencies = writable$1(0); + this.name = writable$1(""); + this.img = writable$1(""); + __STORES__.set(this.uuid, this); + } + get ItemClass() { + return PileItem; + } + get AttributeClass() { + return PileAttribute; + } + get searchDelay() { + return 200; + } + static make(...args) { + const store = new this(...args); + store.setupStores(); + store.setupSubscriptions(); + return store; + } + static getStore(actor) { + const uuid = getUuid(actor); + return __STORES__.get(uuid); + } + static notifyChanges(event, actor, ...args) { + const store = this.getStore(actor); + if (store) { + store[event](...args); + } + } + static notifyAllOfChanges(event, ...args) { + for (const store of __STORES__.values()) { + if (store[event]) { + store[event](...args); + } + } + } + setupStores() { + this.pileData.set(getActorFlagData(this.actor)); + this.shareData.set(getItemPileSharingData(this.actor)); + this.recipientPileData.set(this.recipient ? getActorFlagData(this.recipient) : {}); + this.recipientShareData.set(this.recipient ? getItemPileSharingData(this.recipient) : {}); + this.deleted.set(false); + this.search.set(""); + this.editQuantities.set(!this.recipient); + this.allItems.set([]); + this.attributes.set([]); + this.items.set([]); + this.visibleItems.set([]); + this.pileCurrencies.set(getActorCurrencies(this.actor, { getAll: true })); + this.recipientCurrencies.set(this.recipient ? getActorCurrencies(this.recipient, { getAll: true }) : []); + this.currencies.set([]); + this.allCurrencies.set([]); + this.itemsPerCategory.set({}); + this.categories.set([]); + this.itemCategories.set([]); + this.numItems.set(0); + this.numCurrencies.set(0); + this.name.set(""); + this.img.set(""); + } + getActorImage() { + return this.actor.img; + } + setupSubscriptions() { + this.subscribeTo(this.document, () => { + const { data: data2 } = this.document.updateOptions; + if (hasProperty(data2, CONSTANTS.FLAGS.SHARING)) { + this.shareData.set(getItemPileSharingData(this.actor)); + this.refreshItems(); + } + if (hasProperty(data2, CONSTANTS.FLAGS.PILE)) { + this.pileData.set(getActorFlagData(this.actor)); + this.pileCurrencies.set(getActorCurrencies(this.actor, { getAll: true })); + this.refreshItems(); + } + this.name.set(this.actor.name); + this.img.set(this.getActorImage()); + }); + if (this.recipientDocument) { + this.subscribeTo(this.recipientDocument, () => { + const { data: data2 } = this.document.updateOptions; + if (hasProperty(data2, CONSTANTS.FLAGS.SHARING)) { + this.recipientShareData.set(getItemPileSharingData(this.recipient)); + this.refreshItems(); + } + if (hasProperty(data2, CONSTANTS.FLAGS.PILE)) { + this.recipientPileData.set(getActorFlagData(this.recipient)); + this.recipientCurrencies.set(getActorCurrencies(this.recipient, { getAll: true })); + this.refreshItems(); + } + }); + } + const items = []; + const attributes = []; + const pileData = isValidItemPile(this.actor) || !this.recipient ? get_store_value(this.pileData) : get_store_value(this.recipientPileData); + getActorItems(this.actor, { itemFilters: pileData.overrideItemFilters }).map((item) => { + items.push(new this.ItemClass(this, item)); + }); + getActorCurrencies(this.actor, { forActor: this.recipient, getAll: true }).forEach((currency) => { + if (currency.type === "item") { + if (!currency.item) + return; + items.push(new this.ItemClass(this, currency.item, true, !!currency?.secondary)); + } else { + attributes.push(new this.AttributeClass(this, currency, true, !!currency?.secondary)); + } + }); + this.allItems.set(items); + this.attributes.set(attributes); + this.subscribeTo(this.allItems, () => { + this.refreshItems(); + }); + this.subscribeTo(this.attributes, () => { + this.refreshItems(); + }); + const filterDebounce = foundry.utils.debounce(() => { + this.refreshItems(); + }, this.searchDelay); + this.subscribeTo(this.search, (val) => { + filterDebounce(); + }); + } + updateSource(newSource) { + this.uuid = getUuid(newSource); + this.actor = getActor(newSource); + this.document.set(this.actor); + __STORES__.set(this.uuid, this); + this.unsubscribe(); + this.setupStores(); + this.setupSubscriptions(); + } + updateRecipient(newRecipient) { + this.recipient = newRecipient; + this.recipientDocument.set(this.recipient); + this.unsubscribe(); + this.setupStores(); + this.setupSubscriptions(); + } + visibleItemFilterFunction(entry, actorIsMerchant, pileData, recipientPileData) { + const itemFlagData = entry.itemFlagData ? get_store_value(entry.itemFlagData) : {}; + return !entry.isCurrency && (this.actor.isOwner || !actorIsMerchant || !itemFlagData?.hidden); + } + itemSortFunction(a, b, inverse) { + return (b.item.name > a.item.name ? -1 : 1) * (inverse ? -1 : 1); + } + refreshItems() { + const allItems = get_store_value(this.allItems); + const pileData = get_store_value(this.pileData); + const recipientPileData = this.recipient ? getActorFlagData(this.recipient) : {}; + const actorIsMerchant = isItemPileMerchant(this.actor, pileData); + const visibleItems = allItems.filter((entry) => this.visibleItemFilterFunction(entry, actorIsMerchant, pileData, recipientPileData)); + const itemCurrencies = allItems.filter((entry) => entry.isCurrency && !entry.isSecondaryCurrency); + const secondaryItemCurrencies = allItems.filter((entry) => entry.isSecondaryCurrency); + this.visibleItems.set(visibleItems); + const items = visibleItems.filter((entry) => !get_store_value(entry.filtered)); + this.numItems.set(items.filter((entry) => get_store_value(entry.quantity) > 0).length); + this.items.set(items.sort((a, b) => this.itemSortFunction(a, b))); + const currencies = get_store_value(this.attributes).filter((entry) => !entry.isSecondaryCurrency).concat(itemCurrencies); + const secondaryCurrencies = get_store_value(this.attributes).filter((entry) => entry.isSecondaryCurrency).concat(secondaryItemCurrencies); + this.numCurrencies.set(currencies.concat(secondaryCurrencies).filter((entry) => get_store_value(entry.quantity) > 0).length); + this.currencies.set(currencies.concat(secondaryCurrencies).filter((entry) => !get_store_value(entry.filtered))); + this.allCurrencies.set(currencies.concat(secondaryCurrencies)); + this.itemCategories.set(Object.values(visibleItems.reduce((acc, item) => { + const category = get_store_value(item.category); + if (!acc[category.type]) { + acc[category.type] = { ...category }; + } + return acc; + }, {})).sort((a, b) => a.label < b.label ? -1 : 1)); + const itemsPerCategory = items.reduce((acc, item) => { + const category = get_store_value(item.category); + if (!acc[category.type]) { + acc[category.type] = { + service: category.service, + type: category.type, + label: category.label, + items: [] + }; + } + acc[category.type].items.push(item); + return acc; + }, {}); + Object.values(itemsPerCategory).forEach((category) => category.items.sort((a, b) => { + return a.item.name < b.item.name ? -1 : 1; + })); + this.itemsPerCategory.set(itemsPerCategory); + this.categories.set(Object.values(itemsPerCategory).map((category) => { + return { + service: category.service, + label: category.label, + type: category.type + }; + }).sort((a, b) => a.label < b.label ? -1 : 1)); + } + createItem(item) { + if (isItemInvalid(this.actor, item)) + return; + const items = get_store_value(this.allItems); + const deletedItems = items.filter((item2) => item2.id === null).map((item2) => ({ + pileItem: item2, + ...item2.similarities + })); + const previouslyDeletedItem = findSimilarItem(deletedItems, item); + if (previouslyDeletedItem) { + previouslyDeletedItem.pileItem.setup(item); + } else { + items.push(new this.ItemClass(this, item)); + } + this.allItems.set(items); + } + deleteItem(item) { + if (isItemInvalid(this.actor, item)) + return; + const items = get_store_value(this.allItems); + const pileItem = items.find((pileItem2) => pileItem2.id === item.id); + if (!pileItem) + return; + if (get_store_value(this.editQuantities) || !InterfaceTracker.isOpened(this.application.id)) { + items.splice(items.indexOf(pileItem), 1); + this.allItems.set(items); + } else { + pileItem.id = null; + pileItem.quantity.set(0); + pileItem.quantityLeft.set(0); + } + pileItem.unsubscribe(); + } + hasSimilarItem(item) { + const items = get_store_value(this.allItems).map((item2) => item2.item); + return !!findSimilarItem(items, item, get_store_value(this.pileData)); + } + delete() { + this.deleted.set(true); + } + async update() { + const itemsToUpdate = []; + const itemsToDelete = []; + const attributesToUpdate = {}; + const items = get_store_value(this.allItems).filter((item) => item.id); + for (let item of items) { + const itemQuantity = get_store_value(item.quantity); + if (itemQuantity === 0) { + itemsToDelete.push(item.id); + } else { + if (canItemStack(item.item, this.actor)) { + itemsToUpdate.push(setItemQuantity({ _id: item.id }, itemQuantity)); + } + } + } + const attributes = get_store_value(this.attributes); + for (let attribute of attributes) { + attributesToUpdate[attribute.path] = get_store_value(attribute.quantity); + } + const pileSharingData = getItemPileSharingData(this.actor); + await this.actor.update(attributesToUpdate); + if (pileSharingData?.currencies) { + pileSharingData.currencies = pileSharingData.currencies.map((currency) => { + if (attributesToUpdate[currency.path] !== void 0) { + currency.actors = currency.actors.map((actor) => { + actor.quantity = Math.max(0, Math.min(actor.quantity, attributesToUpdate[currency.path])); + return actor; + }); + } + return currency; + }); + } + await this.actor.updateEmbeddedDocuments("Item", itemsToUpdate); + await this.actor.deleteEmbeddedDocuments("Item", itemsToDelete); + if (pileSharingData?.items) { + pileSharingData.items = pileSharingData.items.map((item) => { + const sharingItem = itemsToUpdate.find((item2) => item2._id === item2.id); + if (sharingItem) { + item.actors = item.actors.map((actor) => { + actor.quantity = Math.max(0, Math.min(actor.quantity, sharingItem.quantity)); + return actor; + }); + } + return item; + }); + } + await updateItemPileSharingData(this.actor, pileSharingData); + this.refreshItems(); + custom_notify(game.i18n.localize("ITEM-PILES.Notifications.UpdateItemPileSuccess")); + } + async depositCurrency() { + const result = await DropCurrencyDialog.show(this.recipient, this.actor, { localization: "DepositCurrencies" }); + return this._addCurrency(result, this.recipient, this.actor); + } + async withdrawCurrency() { + const result = await DropCurrencyDialog.show(this.actor, this.recipient, { localization: "WithdrawCurrencies" }); + return this._addCurrency(result, this.actor, this.recipient); + } + async addCurrency(recipient = false) { + const source = recipient || this.actor; + const target = recipient ? this.actor : false; + const result = await DropCurrencyDialog.show(source, target, { + localization: !target ? "EditCurrencies" : false, + unlimitedCurrencies: !target && game.user.isGM, + existingCurrencies: getActorCurrencies(source, { combine: true }), + getUpdates: !target + }); + return this._addCurrency(result, source, target); + } + async _addCurrency(currencies, source, target = false) { + if (!currencies) + return; + if (!target) { + if (!game.user.isGM) + return; + if (!foundry.utils.isEmpty(currencies.attributes)) { + await game.itempiles.API.setAttributes(source, currencies.attributes, { interactionId: this.interactionId }); + } + if (currencies.items.length) { + const itemsToAdd = currencies.items.filter((currency) => currency.quantity > 0); + const itemsToRemove = currencies.items.filter((currency) => currency.quantity < 0); + await game.itempiles.API.addItems(source, itemsToAdd, { interactionId: this.interactionId }); + await game.itempiles.API.removeItems(source, itemsToRemove, { interactionId: this.interactionId }); + } + } else { + if (!foundry.utils.isEmpty(currencies.attributes)) { + await game.itempiles.API.transferAttributes(source, target, currencies.attributes, { interactionId: this.interactionId }); + } + if (currencies.items.length) { + await game.itempiles.API.transferItems(source, target, currencies.items, { interactionId: this.interactionId }); + } + } + } + takeAll() { + game.itempiles.API.transferEverything( + this.actor, + this.recipient, + { interactionId: this.interactionId } + ); + } + splitAll() { + return game.itempiles.API.splitItemPileContents(this.actor, { instigator: this.recipient }); + } + closeContainer() { + if (!InterfaceTracker.isOpened(this.application.id)) { + return game.itempiles.API.closeItemPile(this.actor, this.recipient); + } + } + subscribeTo(target, callback) { + this.subscriptions.push(target.subscribe(callback)); + } + unsubscribe() { + this.subscriptions.forEach((unsubscribe) => unsubscribe()); + this.subscriptions = []; + } + onDestroy() { + this.unsubscribe(); + __STORES__.delete(this.uuid); + } +} +__name(ItemPileStore, "ItemPileStore"); +const CategorizedItemList_svelte_svelte_type_style_lang = ""; +function get_each_context$u(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[8] = list[i]; + child_ctx[10] = i; + return child_ctx; +} +__name(get_each_context$u, "get_each_context$u"); +function get_each_context_1$e(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[11] = list[i]; + child_ctx[12] = list; + child_ctx[13] = i; + return child_ctx; +} +__name(get_each_context_1$e, "get_each_context_1$e"); +function create_if_block$J(ctx) { + let div; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let div_intro; + let current; + let each_value = ( + /*$categories*/ + ctx[2] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*category*/ + ctx2[8].type + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$u(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$u(key, child_ctx)); + } + return { + c() { + div = element("div"); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + }, + m(target, anchor) { + insert(target, div, anchor); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(div, null); + } + } + current = true; + }, + p(ctx2, dirty) { + if (dirty & /*$itemsPerCategory, $categories, store, localize*/ + 13) { + each_value = /*$categories*/ + ctx2[2]; + group_outros(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, div, outro_and_destroy_block, create_each_block$u, null, get_each_context$u); + check_outros(); + } + }, + i(local) { + if (current) + return; + for (let i = 0; i < each_value.length; i += 1) { + transition_in(each_blocks[i]); + } + if (local) { + if (!div_intro) { + add_render_callback(() => { + div_intro = create_in_transition(div, fade, { duration: 150 }); + div_intro.start(); + }); + } + } + current = true; + }, + o(local) { + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + current = false; + }, + d(detaching) { + if (detaching) + detach(div); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + } + }; +} +__name(create_if_block$J, "create_if_block$J"); +function create_each_block_1$e(key_1, ctx) { + let first; + let listentry; + let updating_entry; + let current; + function listentry_entry_binding(value) { + ctx[7]( + value, + /*item*/ + ctx[11], + /*each_value_1*/ + ctx[12], + /*item_index*/ + ctx[13] + ); + } + __name(listentry_entry_binding, "listentry_entry_binding"); + let listentry_props = { store: ( + /*store*/ + ctx[0] + ) }; + if ( + /*item*/ + ctx[11] !== void 0 + ) { + listentry_props.entry = /*item*/ + ctx[11]; + } + listentry = new ListEntry({ props: listentry_props }); + binding_callbacks.push(() => bind(listentry, "entry", listentry_entry_binding)); + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(listentry.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(listentry, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const listentry_changes = {}; + if (dirty & /*store*/ + 1) + listentry_changes.store = /*store*/ + ctx[0]; + if (!updating_entry && dirty & /*$itemsPerCategory, $categories*/ + 12) { + updating_entry = true; + listentry_changes.entry = /*item*/ + ctx[11]; + add_flush_callback(() => updating_entry = false); + } + listentry.$set(listentry_changes); + }, + i(local) { + if (current) + return; + transition_in(listentry.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(listentry.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(first); + destroy_component(listentry, detaching); + } + }; +} +__name(create_each_block_1$e, "create_each_block_1$e"); +function create_each_block$u(key_1, ctx) { + let div0; + let h3; + let t0_value = localize( + /*category*/ + ctx[8].label + ) + ""; + let t0; + let t1; + let div1; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let t2; + let current; + let each_value_1 = ( + /*$itemsPerCategory*/ + ctx[3][ + /*category*/ + ctx[8].type + ].items + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*item*/ + ctx2[11].id + ), "get_key"); + for (let i = 0; i < each_value_1.length; i += 1) { + let child_ctx = get_each_context_1$e(ctx, each_value_1, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block_1$e(key, child_ctx)); + } + return { + key: key_1, + first: null, + c() { + div0 = element("div"); + h3 = element("h3"); + t0 = text(t0_value); + t1 = space(); + div1 = element("div"); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + t2 = space(); + attr(div0, "class", "item-group-type item-piles-flexrow svelte-bdb8qc"); + attr(div1, "class", "item-piles-items-list"); + this.first = div0; + }, + m(target, anchor) { + insert(target, div0, anchor); + append(div0, h3); + append(h3, t0); + insert(target, t1, anchor); + insert(target, div1, anchor); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(div1, null); + } + } + append(div1, t2); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if ((!current || dirty & /*$categories*/ + 4) && t0_value !== (t0_value = localize( + /*category*/ + ctx[8].label + ) + "")) + set_data(t0, t0_value); + if (dirty & /*store, $itemsPerCategory, $categories*/ + 13) { + each_value_1 = /*$itemsPerCategory*/ + ctx[3][ + /*category*/ + ctx[8].type + ].items; + group_outros(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx, each_value_1, each_1_lookup, div1, outro_and_destroy_block, create_each_block_1$e, t2, get_each_context_1$e); + check_outros(); + } + }, + i(local) { + if (current) + return; + for (let i = 0; i < each_value_1.length; i += 1) { + transition_in(each_blocks[i]); + } + current = true; + }, + o(local) { + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + current = false; + }, + d(detaching) { + if (detaching) + detach(div0); + if (detaching) + detach(t1); + if (detaching) + detach(div1); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + } + }; +} +__name(create_each_block$u, "create_each_block$u"); +function create_fragment$Z(ctx) { + let if_block_anchor; + let current; + let if_block = ( + /*$numItems*/ + ctx[1] > 0 && create_if_block$J(ctx) + ); + return { + c() { + if (if_block) + if_block.c(); + if_block_anchor = empty(); + }, + m(target, anchor) { + if (if_block) + if_block.m(target, anchor); + insert(target, if_block_anchor, anchor); + current = true; + }, + p(ctx2, [dirty]) { + if ( + /*$numItems*/ + ctx2[1] > 0 + ) { + if (if_block) { + if_block.p(ctx2, dirty); + if (dirty & /*$numItems*/ + 2) { + transition_in(if_block, 1); + } + } else { + if_block = create_if_block$J(ctx2); + if_block.c(); + transition_in(if_block, 1); + if_block.m(if_block_anchor.parentNode, if_block_anchor); + } + } else if (if_block) { + group_outros(); + transition_out(if_block, 1, 1, () => { + if_block = null; + }); + check_outros(); + } + }, + i(local) { + if (current) + return; + transition_in(if_block); + current = true; + }, + o(local) { + transition_out(if_block); + current = false; + }, + d(detaching) { + if (if_block) + if_block.d(detaching); + if (detaching) + detach(if_block_anchor); + } + }; +} +__name(create_fragment$Z, "create_fragment$Z"); +function instance$Z($$self, $$props, $$invalidate) { + let $numItems; + let $categories; + let $itemsPerCategory; + let { store } = $$props; + const numItems = store.numItems; + component_subscribe($$self, numItems, (value) => $$invalidate(1, $numItems = value)); + const categories = store.categories; + component_subscribe($$self, categories, (value) => $$invalidate(2, $categories = value)); + const itemsPerCategory = store.itemsPerCategory; + component_subscribe($$self, itemsPerCategory, (value) => $$invalidate(3, $itemsPerCategory = value)); + function listentry_entry_binding(value, item, each_value_1, item_index) { + each_value_1[item_index] = value; + itemsPerCategory.set($itemsPerCategory); + } + __name(listentry_entry_binding, "listentry_entry_binding"); + $$self.$$set = ($$props2) => { + if ("store" in $$props2) + $$invalidate(0, store = $$props2.store); + }; + return [ + store, + $numItems, + $categories, + $itemsPerCategory, + numItems, + categories, + itemsPerCategory, + listentry_entry_binding + ]; +} +__name(instance$Z, "instance$Z"); +class CategorizedItemList extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$Z, create_fragment$Z, safe_not_equal, { store: 0 }); + } +} +__name(CategorizedItemList, "CategorizedItemList"); +const itemPileInventoryShell_svelte_svelte_type_style_lang = ""; +function create_else_block_1$5(ctx) { + let actorpicker; + let t0; + let t1; + let t2; + let div; + let t3; + let current_block_type_index; + let if_block3; + let t4; + let t5; + let currencylist; + let current; + let mounted; + let dispose; + actorpicker = new ActorPicker({ props: { store: ( + /*store*/ + ctx[1] + ) } }); + let if_block0 = ( + /*showSearchBar*/ + ctx[7] && create_if_block_10$2(ctx) + ); + let if_block1 = ( + /*isPileEmpty*/ + ctx[9] && create_if_block_9$2() + ); + let if_block2 = ( + /*scrolled*/ + ctx[5] && create_if_block_8$2() + ); + const if_block_creators = [create_if_block_7$5, create_else_block_2$2]; + const if_blocks = []; + function select_block_type_1(ctx2, dirty) { + if ( + /*$pileData*/ + ctx2[2].displayItemTypes + ) + return 0; + return 1; + } + __name(select_block_type_1, "select_block_type_1"); + current_block_type_index = select_block_type_1(ctx); + if_block3 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx); + let if_block4 = ( + /*hasItems*/ + ctx[8] && create_if_block_6$6() + ); + currencylist = new CurrencyList$1({ props: { store: ( + /*store*/ + ctx[1] + ) } }); + return { + c() { + create_component(actorpicker.$$.fragment); + t0 = space(); + if (if_block0) + if_block0.c(); + t1 = space(); + if (if_block1) + if_block1.c(); + t2 = space(); + div = element("div"); + if (if_block2) + if_block2.c(); + t3 = space(); + if_block3.c(); + t4 = space(); + if (if_block4) + if_block4.c(); + t5 = space(); + create_component(currencylist.$$.fragment); + attr(div, "class", "item-piles-items-list svelte-1543648"); + }, + m(target, anchor) { + mount_component(actorpicker, target, anchor); + insert(target, t0, anchor); + if (if_block0) + if_block0.m(target, anchor); + insert(target, t1, anchor); + if (if_block1) + if_block1.m(target, anchor); + insert(target, t2, anchor); + insert(target, div, anchor); + if (if_block2) + if_block2.m(div, null); + append(div, t3); + if_blocks[current_block_type_index].m(div, null); + append(div, t4); + if (if_block4) + if_block4.m(div, null); + append(div, t5); + mount_component(currencylist, div, null); + ctx[33](div); + current = true; + if (!mounted) { + dispose = listen( + div, + "scroll", + /*evaluateShadow*/ + ctx[24] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + const actorpicker_changes = {}; + if (dirty[0] & /*store*/ + 2) + actorpicker_changes.store = /*store*/ + ctx2[1]; + actorpicker.$set(actorpicker_changes); + if ( + /*showSearchBar*/ + ctx2[7] + ) { + if (if_block0) { + if_block0.p(ctx2, dirty); + if (dirty[0] & /*showSearchBar*/ + 128) { + transition_in(if_block0, 1); + } + } else { + if_block0 = create_if_block_10$2(ctx2); + if_block0.c(); + transition_in(if_block0, 1); + if_block0.m(t1.parentNode, t1); + } + } else if (if_block0) { + group_outros(); + transition_out(if_block0, 1, 1, () => { + if_block0 = null; + }); + check_outros(); + } + if ( + /*isPileEmpty*/ + ctx2[9] + ) { + if (if_block1) { + if_block1.p(ctx2, dirty); + } else { + if_block1 = create_if_block_9$2(); + if_block1.c(); + if_block1.m(t2.parentNode, t2); + } + } else if (if_block1) { + if_block1.d(1); + if_block1 = null; + } + if ( + /*scrolled*/ + ctx2[5] + ) { + if (if_block2) { + if (dirty[0] & /*scrolled*/ + 32) { + transition_in(if_block2, 1); + } + } else { + if_block2 = create_if_block_8$2(); + if_block2.c(); + transition_in(if_block2, 1); + if_block2.m(div, t3); + } + } else if (if_block2) { + group_outros(); + transition_out(if_block2, 1, 1, () => { + if_block2 = null; + }); + check_outros(); + } + let previous_block_index = current_block_type_index; + current_block_type_index = select_block_type_1(ctx2); + if (current_block_type_index === previous_block_index) { + if_blocks[current_block_type_index].p(ctx2, dirty); + } else { + group_outros(); + transition_out(if_blocks[previous_block_index], 1, 1, () => { + if_blocks[previous_block_index] = null; + }); + check_outros(); + if_block3 = if_blocks[current_block_type_index]; + if (!if_block3) { + if_block3 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx2); + if_block3.c(); + } else { + if_block3.p(ctx2, dirty); + } + transition_in(if_block3, 1); + if_block3.m(div, t4); + } + if ( + /*hasItems*/ + ctx2[8] + ) { + if (if_block4) + ; + else { + if_block4 = create_if_block_6$6(); + if_block4.c(); + if_block4.m(div, t5); + } + } else if (if_block4) { + if_block4.d(1); + if_block4 = null; + } + const currencylist_changes = {}; + if (dirty[0] & /*store*/ + 2) + currencylist_changes.store = /*store*/ + ctx2[1]; + currencylist.$set(currencylist_changes); + }, + i(local) { + if (current) + return; + transition_in(actorpicker.$$.fragment, local); + transition_in(if_block0); + transition_in(if_block2); + transition_in(if_block3); + transition_in(currencylist.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(actorpicker.$$.fragment, local); + transition_out(if_block0); + transition_out(if_block2); + transition_out(if_block3); + transition_out(currencylist.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(actorpicker, detaching); + if (detaching) + detach(t0); + if (if_block0) + if_block0.d(detaching); + if (detaching) + detach(t1); + if (if_block1) + if_block1.d(detaching); + if (detaching) + detach(t2); + if (detaching) + detach(div); + if (if_block2) + if_block2.d(); + if_blocks[current_block_type_index].d(); + if (if_block4) + if_block4.d(); + destroy_component(currencylist); + ctx[33](null); + mounted = false; + dispose(); + } + }; +} +__name(create_else_block_1$5, "create_else_block_1$5"); +function create_if_block_5$8(ctx) { + let p; + return { + c() { + p = element("p"); + p.textContent = `${localize("ITEM-PILES.Inspect.Destroyed")}`; + set_style(p, "text-align", "center"); + set_style(p, "flex", "0 1 auto"); + }, + m(target, anchor) { + insert(target, p, anchor); + }, + p: noop, + i: noop, + o: noop, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_if_block_5$8, "create_if_block_5$8"); +function create_if_block_10$2(ctx) { + let div; + let label; + let t1; + let input; + let div_transition; + let current; + let mounted; + let dispose; + return { + c() { + div = element("div"); + label = element("label"); + label.textContent = "Search:"; + t1 = space(); + input = element("input"); + set_style(label, "flex", "0 1 auto"); + set_style(label, "margin-right", "5px"); + attr(input, "type", "text"); + attr(div, "class", "form-group item-piles-flexrow item-piles-top-divider item-piles-bottom-divider"); + set_style(div, "margin-bottom", "0.5rem"); + set_style(div, "align-items", "center"); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, label); + append(div, t1); + append(div, input); + set_input_value( + input, + /*$searchStore*/ + ctx[11] + ); + current = true; + if (!mounted) { + dispose = listen( + input, + "input", + /*input_input_handler*/ + ctx[32] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty[0] & /*$searchStore*/ + 2048 && input.value !== /*$searchStore*/ + ctx2[11]) { + set_input_value( + input, + /*$searchStore*/ + ctx2[11] + ); + } + }, + i(local) { + if (current) + return; + add_render_callback(() => { + if (!current) + return; + if (!div_transition) + div_transition = create_bidirectional_transition(div, fade, { duration: 250 }, true); + div_transition.run(1); + }); + current = true; + }, + o(local) { + if (!div_transition) + div_transition = create_bidirectional_transition(div, fade, { duration: 250 }, false); + div_transition.run(0); + current = false; + }, + d(detaching) { + if (detaching) + detach(div); + if (detaching && div_transition) + div_transition.end(); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_10$2, "create_if_block_10$2"); +function create_if_block_9$2(ctx) { + let p; + return { + c() { + p = element("p"); + p.textContent = `${localize("ITEM-PILES.Inspect.Empty")}`; + attr(p, "class", "item-piles-top-divider"); + set_style(p, "text-align", "center"); + set_style(p, "flex", "0 1 auto"); + }, + m(target, anchor) { + insert(target, p, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_if_block_9$2, "create_if_block_9$2"); +function create_if_block_8$2(ctx) { + let div0; + let div0_transition; + let t; + let div1; + let current; + return { + c() { + div0 = element("div"); + t = space(); + div1 = element("div"); + attr(div0, "class", "item-pile-shadow scroll-shadow-top svelte-1543648"); + }, + m(target, anchor) { + insert(target, div0, anchor); + insert(target, t, anchor); + insert(target, div1, anchor); + current = true; + }, + i(local) { + if (current) + return; + add_render_callback(() => { + if (!current) + return; + if (!div0_transition) + div0_transition = create_bidirectional_transition(div0, fade, { duration: 300 }, true); + div0_transition.run(1); + }); + current = true; + }, + o(local) { + if (!div0_transition) + div0_transition = create_bidirectional_transition(div0, fade, { duration: 300 }, false); + div0_transition.run(0); + current = false; + }, + d(detaching) { + if (detaching) + detach(div0); + if (detaching && div0_transition) + div0_transition.end(); + if (detaching) + detach(t); + if (detaching) + detach(div1); + } + }; +} +__name(create_if_block_8$2, "create_if_block_8$2"); +function create_else_block_2$2(ctx) { + let itemlist; + let current; + itemlist = new ItemList({ props: { store: ( + /*store*/ + ctx[1] + ) } }); + return { + c() { + create_component(itemlist.$$.fragment); + }, + m(target, anchor) { + mount_component(itemlist, target, anchor); + current = true; + }, + p(ctx2, dirty) { + const itemlist_changes = {}; + if (dirty[0] & /*store*/ + 2) + itemlist_changes.store = /*store*/ + ctx2[1]; + itemlist.$set(itemlist_changes); + }, + i(local) { + if (current) + return; + transition_in(itemlist.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(itemlist.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(itemlist, detaching); + } + }; +} +__name(create_else_block_2$2, "create_else_block_2$2"); +function create_if_block_7$5(ctx) { + let categorizeditemlist; + let current; + categorizeditemlist = new CategorizedItemList({ props: { store: ( + /*store*/ + ctx[1] + ) } }); + return { + c() { + create_component(categorizeditemlist.$$.fragment); + }, + m(target, anchor) { + mount_component(categorizeditemlist, target, anchor); + current = true; + }, + p(ctx2, dirty) { + const categorizeditemlist_changes = {}; + if (dirty[0] & /*store*/ + 2) + categorizeditemlist_changes.store = /*store*/ + ctx2[1]; + categorizeditemlist.$set(categorizeditemlist_changes); + }, + i(local) { + if (current) + return; + transition_in(categorizeditemlist.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(categorizeditemlist.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(categorizeditemlist, detaching); + } + }; +} +__name(create_if_block_7$5, "create_if_block_7$5"); +function create_if_block_6$6(ctx) { + let hr; + return { + c() { + hr = element("hr"); + }, + m(target, anchor) { + insert(target, hr, anchor); + }, + d(detaching) { + if (detaching) + detach(hr); + } + }; +} +__name(create_if_block_6$6, "create_if_block_6$6"); +function create_if_block_4$c(ctx) { + let button; + let i; + let t0; + let t1_value = localize("ITEM-PILES.Applications.ItemPileConfig.Update") + ""; + let t1; + let mounted; + let dispose; + return { + c() { + button = element("button"); + i = element("i"); + t0 = space(); + t1 = text(t1_value); + attr(i, "class", "fas fa-save"); + attr(button, "type", "button"); + }, + m(target, anchor) { + insert(target, button, anchor); + append(button, i); + append(button, t0); + append(button, t1); + if (!mounted) { + dispose = listen( + button, + "click", + /*click_handler*/ + ctx[34] + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(button); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_4$c, "create_if_block_4$c"); +function create_if_block_2$n(ctx) { + let button; + let i; + let t; + let button_disabled_value; + let mounted; + let dispose; + function select_block_type_2(ctx2, dirty) { + if ( + /*$pileData*/ + ctx2[2].shareItemsEnabled + ) + return create_if_block_3$i; + return create_else_block$g; + } + __name(select_block_type_2, "select_block_type_2"); + let current_block_type = select_block_type_2(ctx); + let if_block = current_block_type(ctx); + return { + c() { + button = element("button"); + i = element("i"); + t = space(); + if_block.c(); + attr(i, "class", "fas fa-handshake"); + attr(button, "type", "button"); + button.disabled = button_disabled_value = /*isPileEmpty*/ + ctx[9] || !/*canBeSplit*/ + ctx[3]; + }, + m(target, anchor) { + insert(target, button, anchor); + append(button, i); + append(button, t); + if_block.m(button, null); + if (!mounted) { + dispose = listen( + button, + "click", + /*click_handler_1*/ + ctx[35] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (current_block_type === (current_block_type = select_block_type_2(ctx2)) && if_block) { + if_block.p(ctx2, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx2); + if (if_block) { + if_block.c(); + if_block.m(button, null); + } + } + if (dirty[0] & /*isPileEmpty, canBeSplit*/ + 520 && button_disabled_value !== (button_disabled_value = /*isPileEmpty*/ + ctx2[9] || !/*canBeSplit*/ + ctx2[3])) { + button.disabled = button_disabled_value; + } + }, + d(detaching) { + if (detaching) + detach(button); + if_block.d(); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_2$n, "create_if_block_2$n"); +function create_else_block$g(ctx) { + let t_value = localize("ITEM-PILES.Inspect.SplitCurrencies", { num_players: ( + /*num_players*/ + ctx[22] + ) }) + ""; + let t; + return { + c() { + t = text(t_value); + }, + m(target, anchor) { + insert(target, t, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(t); + } + }; +} +__name(create_else_block$g, "create_else_block$g"); +function create_if_block_3$i(ctx) { + let t_value = localize("ITEM-PILES.Inspect.SplitAll", { num_players: ( + /*num_players*/ + ctx[22] + ) }) + ""; + let t; + return { + c() { + t = text(t_value); + }, + m(target, anchor) { + insert(target, t, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(t); + } + }; +} +__name(create_if_block_3$i, "create_if_block_3$i"); +function create_if_block_1$x(ctx) { + let button; + let i; + let t0; + let t1_value = localize("ITEM-PILES.Inspect.TakeAll") + ""; + let t1; + let mounted; + let dispose; + return { + c() { + button = element("button"); + i = element("i"); + t0 = space(); + t1 = text(t1_value); + attr(i, "class", "fas fa-fist-raised"); + attr(button, "type", "submit"); + button.disabled = /*isPileEmpty*/ + ctx[9]; + }, + m(target, anchor) { + insert(target, button, anchor); + append(button, i); + append(button, t0); + append(button, t1); + if (!mounted) { + dispose = listen( + button, + "click", + /*click_handler_2*/ + ctx[36] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty[0] & /*isPileEmpty*/ + 512) { + button.disabled = /*isPileEmpty*/ + ctx2[9]; + } + }, + d(detaching) { + if (detaching) + detach(button); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_1$x, "create_if_block_1$x"); +function create_if_block$I(ctx) { + let button; + let i; + let t0; + let t1_value = localize("ITEM-PILES.Inspect.Close") + ""; + let t1; + let mounted; + let dispose; + return { + c() { + button = element("button"); + i = element("i"); + t0 = space(); + t1 = text(t1_value); + attr(i, "class", "fas fa-box"); + attr(button, "type", "submit"); + }, + m(target, anchor) { + insert(target, button, anchor); + append(button, i); + append(button, t0); + append(button, t1); + if (!mounted) { + dispose = listen( + button, + "click", + /*click_handler_3*/ + ctx[37] + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(button); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block$I, "create_if_block$I"); +function create_default_slot$l(ctx) { + let main; + let div; + let current_block_type_index; + let if_block0; + let t0; + let footer; + let t1; + let t2; + let t3; + let t4; + let button; + let i; + let t5; + let t6_value = localize("ITEM-PILES.Inspect.Leave") + ""; + let t6; + let main_intro; + let current; + let mounted; + let dispose; + const if_block_creators = [create_if_block_5$8, create_else_block_1$5]; + const if_blocks = []; + function select_block_type(ctx2, dirty) { + if ( + /*$deleted*/ + ctx2[10] + ) + return 0; + return 1; + } + __name(select_block_type, "select_block_type"); + current_block_type_index = select_block_type(ctx); + if_block0 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx); + let if_block1 = ( + /*editQuantities*/ + ctx[14] && create_if_block_4$c(ctx) + ); + let if_block2 = ( + /*$pileData*/ + ctx[2].splitAllEnabled && create_if_block_2$n(ctx) + ); + let if_block3 = ( + /*store*/ + ctx[1].recipient && /*$pileData*/ + ctx[2].takeAllEnabled && create_if_block_1$x(ctx) + ); + let if_block4 = ( + /*isContainer*/ + ctx[6] && !/*application*/ + ctx[12].options.remote && create_if_block$I(ctx) + ); + return { + c() { + main = element("main"); + div = element("div"); + if_block0.c(); + t0 = space(); + footer = element("footer"); + if (if_block1) + if_block1.c(); + t1 = space(); + if (if_block2) + if_block2.c(); + t2 = space(); + if (if_block3) + if_block3.c(); + t3 = space(); + if (if_block4) + if_block4.c(); + t4 = space(); + button = element("button"); + i = element("i"); + t5 = space(); + t6 = text(t6_value); + attr(i, "class", "fas fa-sign-out-alt"); + attr(button, "type", "submit"); + attr(footer, "class", "sheet-footer item-piles-flexrow item-piles-top-divider"); + attr(div, "class", "item-piles-item-drop-container"); + }, + m(target, anchor) { + insert(target, main, anchor); + append(main, div); + if_blocks[current_block_type_index].m(div, null); + append(div, t0); + append(div, footer); + if (if_block1) + if_block1.m(footer, null); + append(footer, t1); + if (if_block2) + if_block2.m(footer, null); + append(footer, t2); + if (if_block3) + if_block3.m(footer, null); + append(footer, t3); + if (if_block4) + if_block4.m(footer, null); + append(footer, t4); + append(footer, button); + append(button, i); + append(button, t5); + append(button, t6); + current = true; + if (!mounted) { + dispose = [ + listen( + button, + "click", + /*click_handler_4*/ + ctx[38] + ), + listen(div, "dragover", preventDefault$1), + listen(div, "dragstart", preventDefaultGM), + listen( + div, + "drop", + /*dropData*/ + ctx[23] + ) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + let previous_block_index = current_block_type_index; + current_block_type_index = select_block_type(ctx2); + if (current_block_type_index === previous_block_index) { + if_blocks[current_block_type_index].p(ctx2, dirty); + } else { + group_outros(); + transition_out(if_blocks[previous_block_index], 1, 1, () => { + if_blocks[previous_block_index] = null; + }); + check_outros(); + if_block0 = if_blocks[current_block_type_index]; + if (!if_block0) { + if_block0 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx2); + if_block0.c(); + } else { + if_block0.p(ctx2, dirty); + } + transition_in(if_block0, 1); + if_block0.m(div, t0); + } + if ( + /*editQuantities*/ + ctx2[14] + ) + if_block1.p(ctx2, dirty); + if ( + /*$pileData*/ + ctx2[2].splitAllEnabled + ) { + if (if_block2) { + if_block2.p(ctx2, dirty); + } else { + if_block2 = create_if_block_2$n(ctx2); + if_block2.c(); + if_block2.m(footer, t2); + } + } else if (if_block2) { + if_block2.d(1); + if_block2 = null; + } + if ( + /*store*/ + ctx2[1].recipient && /*$pileData*/ + ctx2[2].takeAllEnabled + ) { + if (if_block3) { + if_block3.p(ctx2, dirty); + } else { + if_block3 = create_if_block_1$x(ctx2); + if_block3.c(); + if_block3.m(footer, t3); + } + } else if (if_block3) { + if_block3.d(1); + if_block3 = null; + } + if ( + /*isContainer*/ + ctx2[6] && !/*application*/ + ctx2[12].options.remote + ) { + if (if_block4) { + if_block4.p(ctx2, dirty); + } else { + if_block4 = create_if_block$I(ctx2); + if_block4.c(); + if_block4.m(footer, t4); + } + } else if (if_block4) { + if_block4.d(1); + if_block4 = null; + } + }, + i(local) { + if (current) + return; + transition_in(if_block0); + if (!main_intro) { + add_render_callback(() => { + main_intro = create_in_transition(main, fade, { duration: 500 }); + main_intro.start(); + }); + } + current = true; + }, + o(local) { + transition_out(if_block0); + current = false; + }, + d(detaching) { + if (detaching) + detach(main); + if_blocks[current_block_type_index].d(); + if (if_block1) + if_block1.d(); + if (if_block2) + if_block2.d(); + if (if_block3) + if_block3.d(); + if (if_block4) + if_block4.d(); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$l, "create_default_slot$l"); +function create_fragment$Y(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[39](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot$l] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, dirty) { + const applicationshell_changes = {}; + if (dirty[0] & /*store, isContainer, isPileEmpty, $pileData, canBeSplit, $deleted, itemListElement, hasItems, scrolled, $searchStore, showSearchBar*/ + 4094 | dirty[1] & /*$$scope*/ + 512) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty[0] & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment$Y, "create_fragment$Y"); +function preventDefaultGM(event) { + if (game.user.isGM) + return; + event.preventDefault(); +} +__name(preventDefaultGM, "preventDefaultGM"); +function preventDefault$1(event) { + event.preventDefault(); +} +__name(preventDefault$1, "preventDefault$1"); +function instance$Y($$self, $$props, $$invalidate) { + let isPileEmpty; + let hasItems; + let showSearchBar; + let isContainer; + let $currencies; + let $items; + let $shareData; + let $pileData; + let $numItems; + let $numCurrencies; + let $deleted; + let $searchStore; + const { application } = getContext("#external"); + let { elementRoot } = $$props; + let { actor } = $$props; + let { recipient } = $$props; + let { store = ItemPileStore.make(application, actor, recipient) } = $$props; + let canBeSplit = false; + let searchStore = store.search; + component_subscribe($$self, searchStore, (value) => $$invalidate(11, $searchStore = value)); + let editQuantities = store.editQuantities; + let pileData = store.pileData; + component_subscribe($$self, pileData, (value) => $$invalidate(2, $pileData = value)); + let deleted = store.deleted; + component_subscribe($$self, deleted, (value) => $$invalidate(10, $deleted = value)); + const items = store.allItems; + component_subscribe($$self, items, (value) => $$invalidate(28, $items = value)); + const currencies = store.currencies; + component_subscribe($$self, currencies, (value) => $$invalidate(27, $currencies = value)); + const numItems = store.numItems; + component_subscribe($$self, numItems, (value) => $$invalidate(30, $numItems = value)); + const shareData = store.shareData; + component_subscribe($$self, shareData, (value) => $$invalidate(29, $shareData = value)); + const numCurrencies = store.numCurrencies; + component_subscribe($$self, numCurrencies, (value) => $$invalidate(31, $numCurrencies = value)); + let num_players = getPlayersForItemPile(actor).length; + async function dropData(event) { + event.preventDefault(); + let data2; + try { + data2 = JSON.parse(event.dataTransfer.getData("text/plain")); + } catch (err) { + return false; + } + if (data2.type === "Actor" && game.user.isGM) { + const newRecipient = data2.uuid ? await fromUuid(data2.uuid) : game.actors.get(data2.id); + return store.updateRecipient(newRecipient); + } + if (data2.type !== "Item") { + custom_warning(`You can't drop documents of type "${data2.type}" into this Item Piles vault!`, true); + return false; + } + const item = await Item.implementation.fromDropData(data2); + const itemData = item.toObject(); + if (!itemData) { + console.error(data2); + throw custom_error("Something went wrong when dropping this item!"); + } + const source = getSourceActorFromDropData(data2); + return PrivateAPI._dropItem({ + source, + target: store.actor, + itemData: { item: itemData, quantity: 1 }, + skipCheck: true + }); + } + __name(dropData, "dropData"); + let itemListElement; + let scrolled = false; + function evaluateShadow() { + $$invalidate(5, scrolled = itemListElement.scrollTop > 20); + } + __name(evaluateShadow, "evaluateShadow"); + onDestroy(() => { + store.onDestroy(); + }); + function input_input_handler() { + $searchStore = this.value; + searchStore.set($searchStore); + } + __name(input_input_handler, "input_input_handler"); + function div_binding($$value) { + binding_callbacks[$$value ? "unshift" : "push"](() => { + itemListElement = $$value; + $$invalidate(4, itemListElement); + }); + } + __name(div_binding, "div_binding"); + const click_handler = /* @__PURE__ */ __name(() => { + store.update(); + }, "click_handler"); + const click_handler_1 = /* @__PURE__ */ __name(() => { + store.splitAll(); + }, "click_handler_1"); + const click_handler_2 = /* @__PURE__ */ __name(() => { + store.takeAll(); + }, "click_handler_2"); + const click_handler_32 = /* @__PURE__ */ __name(() => { + store.closeContainer(); + application.close(); + }, "click_handler_3"); + const click_handler_4 = /* @__PURE__ */ __name(() => { + application.close(); + }, "click_handler_4"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + if ("actor" in $$props2) + $$invalidate(25, actor = $$props2.actor); + if ("recipient" in $$props2) + $$invalidate(26, recipient = $$props2.recipient); + if ("store" in $$props2) + $$invalidate(1, store = $$props2.store); + }; + $$self.$$.update = () => { + if ($$self.$$.dirty[0] & /*$numItems*/ + 1073741824 | $$self.$$.dirty[1] & /*$numCurrencies*/ + 1) { + $$invalidate(9, isPileEmpty = $numItems === 0 && $numCurrencies === 0); + } + if ($$self.$$.dirty[0] & /*$numItems*/ + 1073741824) { + $$invalidate(8, hasItems = $numItems > 0); + } + if ($$self.$$.dirty[0] & /*$numItems*/ + 1073741824) { + $$invalidate(7, showSearchBar = $numItems >= 8); + } + if ($$self.$$.dirty[0] & /*actor, $pileData*/ + 33554436) { + $$invalidate(6, isContainer = isItemPileContainer(actor, $pileData)); + } + if ($$self.$$.dirty[0] & /*$shareData, $items, $currencies, actor*/ + 973078528) { + { + $$invalidate(3, canBeSplit = canItemPileBeSplit(actor)); + } + } + }; + return [ + elementRoot, + store, + $pileData, + canBeSplit, + itemListElement, + scrolled, + isContainer, + showSearchBar, + hasItems, + isPileEmpty, + $deleted, + $searchStore, + application, + searchStore, + editQuantities, + pileData, + deleted, + items, + currencies, + numItems, + shareData, + numCurrencies, + num_players, + dropData, + evaluateShadow, + actor, + recipient, + $currencies, + $items, + $shareData, + $numItems, + $numCurrencies, + input_input_handler, + div_binding, + click_handler, + click_handler_1, + click_handler_2, + click_handler_32, + click_handler_4, + applicationshell_elementRoot_binding + ]; +} +__name(instance$Y, "instance$Y"); +class Item_pile_inventory_shell extends SvelteComponent { + constructor(options) { + super(); + init( + this, + options, + instance$Y, + create_fragment$Y, + safe_not_equal, + { + elementRoot: 0, + actor: 25, + recipient: 26, + store: 1 + }, + null, + [-1, -1] + ); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } + get actor() { + return this.$$.ctx[25]; + } + set actor(actor) { + this.$$set({ actor }); + flush(); + } + get recipient() { + return this.$$.ctx[26]; + } + set recipient(recipient) { + this.$$set({ recipient }); + flush(); + } + get store() { + return this.$$.ctx[1]; + } + set store(store) { + this.$$set({ store }); + flush(); + } +} +__name(Item_pile_inventory_shell, "Item_pile_inventory_shell"); +const Tabs_svelte_svelte_type_style_lang = ""; +function get_each_context$t(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[6] = list[i]; + child_ctx[8] = i; + return child_ctx; +} +__name(get_each_context$t, "get_each_context$t"); +function create_if_block_2$m(ctx) { + let div; + return { + c() { + div = element("div"); + set_style(div, "border-right", "1px solid rgba(0,0,0,0.5)"); + set_style(div, "margin", "0 10px"); + }, + m(target, anchor) { + insert(target, div, anchor); + }, + d(detaching) { + if (detaching) + detach(div); + } + }; +} +__name(create_if_block_2$m, "create_if_block_2$m"); +function create_if_block_1$w(ctx) { + let i; + let i_class_value; + return { + c() { + i = element("i"); + attr(i, "class", i_class_value = "icon " + /*tab*/ + ctx[6].icon + " svelte-14iev2w"); + }, + m(target, anchor) { + insert(target, i, anchor); + }, + p(ctx2, dirty) { + if (dirty & /*tabs*/ + 2 && i_class_value !== (i_class_value = "icon " + /*tab*/ + ctx2[6].icon + " svelte-14iev2w")) { + attr(i, "class", i_class_value); + } + }, + d(detaching) { + if (detaching) + detach(i); + } + }; +} +__name(create_if_block_1$w, "create_if_block_1$w"); +function create_if_block$H(ctx) { + let div; + return { + c() { + div = element("div"); + div.innerHTML = ``; + attr(div, "class", "blob"); + }, + m(target, anchor) { + insert(target, div, anchor); + }, + d(detaching) { + if (detaching) + detach(div); + } + }; +} +__name(create_if_block$H, "create_if_block$H"); +function create_each_block$t(key_1, ctx) { + let first; + let t0; + let div; + let t1; + let t2_value = localize( + /*tab*/ + ctx[6].label + ) + ""; + let t2; + let t3; + let t4; + let mounted; + let dispose; + let if_block0 = ( + /*separateElements*/ + ctx[3] && /*index*/ + ctx[8] > 0 && create_if_block_2$m() + ); + let if_block1 = ( + /*tab*/ + ctx[6].icon && create_if_block_1$w(ctx) + ); + let if_block2 = ( + /*tab*/ + ctx[6].highlight && create_if_block$H() + ); + function click_handler() { + return ( + /*click_handler*/ + ctx[5]( + /*tab*/ + ctx[6] + ) + ); + } + __name(click_handler, "click_handler"); + return { + key: key_1, + first: null, + c() { + first = empty(); + if (if_block0) + if_block0.c(); + t0 = space(); + div = element("div"); + if (if_block1) + if_block1.c(); + t1 = space(); + t2 = text(t2_value); + t3 = space(); + if (if_block2) + if_block2.c(); + t4 = space(); + attr(div, "class", "item item-piles-flexrow item-piles-clickable-link svelte-14iev2w"); + attr(div, "data-tab", "rest"); + toggle_class( + div, + "underscore", + /*underscore*/ + ctx[2] + ); + toggle_class( + div, + "active", + /*activeTab*/ + ctx[0] === /*tab*/ + ctx[6].value + ); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + if (if_block0) + if_block0.m(target, anchor); + insert(target, t0, anchor); + insert(target, div, anchor); + if (if_block1) + if_block1.m(div, null); + append(div, t1); + append(div, t2); + append(div, t3); + if (if_block2) + if_block2.m(div, null); + append(div, t4); + if (!mounted) { + dispose = listen(div, "click", click_handler); + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if ( + /*separateElements*/ + ctx[3] && /*index*/ + ctx[8] > 0 + ) { + if (if_block0) + ; + else { + if_block0 = create_if_block_2$m(); + if_block0.c(); + if_block0.m(t0.parentNode, t0); + } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; + } + if ( + /*tab*/ + ctx[6].icon + ) { + if (if_block1) { + if_block1.p(ctx, dirty); + } else { + if_block1 = create_if_block_1$w(ctx); + if_block1.c(); + if_block1.m(div, t1); + } + } else if (if_block1) { + if_block1.d(1); + if_block1 = null; + } + if (dirty & /*tabs*/ + 2 && t2_value !== (t2_value = localize( + /*tab*/ + ctx[6].label + ) + "")) + set_data(t2, t2_value); + if ( + /*tab*/ + ctx[6].highlight + ) { + if (if_block2) + ; + else { + if_block2 = create_if_block$H(); + if_block2.c(); + if_block2.m(div, t4); + } + } else if (if_block2) { + if_block2.d(1); + if_block2 = null; + } + if (dirty & /*underscore*/ + 4) { + toggle_class( + div, + "underscore", + /*underscore*/ + ctx[2] + ); + } + if (dirty & /*activeTab, tabs*/ + 3) { + toggle_class( + div, + "active", + /*activeTab*/ + ctx[0] === /*tab*/ + ctx[6].value + ); + } + }, + d(detaching) { + if (detaching) + detach(first); + if (if_block0) + if_block0.d(detaching); + if (detaching) + detach(t0); + if (detaching) + detach(div); + if (if_block1) + if_block1.d(); + if (if_block2) + if_block2.d(); + mounted = false; + dispose(); + } + }; +} +__name(create_each_block$t, "create_each_block$t"); +function create_fragment$X(ctx) { + let nav; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let nav_style_value; + let each_value = ( + /*tabs*/ + ctx[1].filter(func$1) + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*tab*/ + ctx2[6].value + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$t(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$t(key, child_ctx)); + } + return { + c() { + nav = element("nav"); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + attr(nav, "class", "tabs svelte-14iev2w"); + attr(nav, "data-group", "primary"); + attr(nav, "style", nav_style_value = /*$$props*/ + ctx[4].style); + }, + m(target, anchor) { + insert(target, nav, anchor); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(nav, null); + } + } + }, + p(ctx2, [dirty]) { + if (dirty & /*underscore, activeTab, tabs, localize, separateElements*/ + 15) { + each_value = /*tabs*/ + ctx2[1].filter(func$1); + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, nav, destroy_block, create_each_block$t, null, get_each_context$t); + } + if (dirty & /*$$props*/ + 16 && nav_style_value !== (nav_style_value = /*$$props*/ + ctx2[4].style)) { + attr(nav, "style", nav_style_value); + } + }, + i: noop, + o: noop, + d(detaching) { + if (detaching) + detach(nav); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + } + }; +} +__name(create_fragment$X, "create_fragment$X"); +const func$1 = /* @__PURE__ */ __name((tab) => !tab.hidden, "func$1"); +function instance$X($$self, $$props, $$invalidate) { + let { activeTab } = $$props; + let { tabs } = $$props; + let { underscore = false } = $$props; + let { separateElements = false } = $$props; + const click_handler = /* @__PURE__ */ __name((tab) => { + $$invalidate(0, activeTab = tab.value); + }, "click_handler"); + $$self.$$set = ($$new_props) => { + $$invalidate(4, $$props = assign(assign({}, $$props), exclude_internal_props($$new_props))); + if ("activeTab" in $$new_props) + $$invalidate(0, activeTab = $$new_props.activeTab); + if ("tabs" in $$new_props) + $$invalidate(1, tabs = $$new_props.tabs); + if ("underscore" in $$new_props) + $$invalidate(2, underscore = $$new_props.underscore); + if ("separateElements" in $$new_props) + $$invalidate(3, separateElements = $$new_props.separateElements); + }; + $$props = exclude_internal_props($$props); + return [activeTab, tabs, underscore, separateElements, $$props, click_handler]; +} +__name(instance$X, "instance$X"); +class Tabs extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$X, create_fragment$X, safe_not_equal, { + activeTab: 0, + tabs: 1, + underscore: 2, + separateElements: 3 + }); + } +} +__name(Tabs, "Tabs"); +class FoundryStyles { + static #sheet = void 0; + static #sheetMap = /* @__PURE__ */ new Map(); + static #initialized = false; + /** + * Called once on initialization / first usage. Parses the core foundry style sheet. + */ + static #initialize() { + this.#initialized = true; + const styleSheets = Array.from(document.styleSheets).filter((entry) => entry.href !== null); + let sheet; + const foundryStyleSheet = globalThis.foundry.utils.getRoute("/css/style.css"); + for (const styleSheet of styleSheets) { + let url; + try { + url = new URL(styleSheet.href); + } catch (err) { + continue; + } + if (typeof url.pathname === "string" && url.pathname === foundryStyleSheet) { + this.#sheet = sheet = styleSheet; + break; + } + } + if (!sheet) { + return; + } + for (const rule of sheet.cssRules) { + if (!(rule instanceof CSSStyleRule)) { + continue; + } + const obj = {}; + for (const entry of rule.style.cssText.split(";")) { + const parts = entry.split(":"); + if (parts.length < 2) { + continue; + } + obj[parts[0].trim()] = parts[1].trim(); + } + this.#sheetMap.set(rule.selectorText, obj); + } + } + /** + * Gets the properties object associated with the selector. Try and use a direct match otherwise all keys + * are iterated to find a selector string that includes the `selector`. + * + * @param {string} selector - Selector to find. + * + * @returns {Object${game.i18n.format(warningContent, { type: newDisallowedType })}
`, + defaultYes: false + }); + if (!force) { + return false; + } + } + } else { + if (SYSTEMS.DATA.ITEM_TRANSFORMER && runTransformer) { + item = await SYSTEMS.DATA.ITEM_TRANSFORMER(item); + } + } + return item; +} +__name(checkItemType, "checkItemType"); +function isItemCurrency(item, { target = false, actorCurrencies = false } = {}) { + const currencies = (actorCurrencies || getActorCurrencies(item.parent || false, { + forActor: target, + getAll: true + })).filter((currency) => currency.type === "item").map((item2) => item2.data.item); + return !!findSimilarItem(currencies, item); +} +__name(isItemCurrency, "isItemCurrency"); +function getItemCurrencyData(item, { target = false, actorCurrencies = false }) { + return (actorCurrencies || getActorCurrencies(item?.parent || false, { + forActor: target, + getAll: true, + combine: true + })).filter((currency) => currency.type === "item").find((currency) => { + return item.name === currency.data.item.name && item.type === currency.data.item.type; + }); +} +__name(getItemCurrencyData, "getItemCurrencyData"); +function getItemPileTokenImage(token, { + data: data2 = false, + items = false, + currencies = false +} = {}, overrideImage = null) { + const pileDocument = getDocument(token); + const itemPileData = getActorFlagData(pileDocument, data2); + const originalImg = overrideImage ?? (pileDocument instanceof TokenDocument ? pileDocument.texture.src : pileDocument.prototypeToken.texture.src); + if (!isValidItemPile(pileDocument, itemPileData) || !isItemPileLootable(pileDocument, itemPileData)) + return originalImg; + items = items || getActorItems(pileDocument); + currencies = currencies || getActorCurrencies(pileDocument); + const numItems = items.length + currencies.length; + let img = originalImg; + if (itemPileData.type === CONSTANTS.PILE_TYPES.CONTAINER) { + img = itemPileData.lockedImage || itemPileData.closedImage || itemPileData.openedImage || itemPileData.emptyImage; + if (itemPileData.locked && itemPileData.lockedImage) { + img = itemPileData.lockedImage; + } else if (itemPileData.closed && itemPileData.closedImage) { + img = itemPileData.closedImage; + } else if (itemPileData.emptyImage && isItemPileEmpty(pileDocument)) { + img = itemPileData.emptyImage; + } else if (itemPileData.openedImage) { + img = itemPileData.openedImage; + } + } else if (itemPileData.displayOne && numItems === 1) { + img = items.length > 0 ? items[0].img : currencies[0].img; + } else if (itemPileData.displayOne && numItems > 1) { + img = originalImg; + } + return img || originalImg; +} +__name(getItemPileTokenImage, "getItemPileTokenImage"); +function getItemPileTokenScale(target, { + data: data2 = false, + items = false, + currencies = false +} = {}, overrideScale = null) { + const pileDocument = getDocument(target); + let itemPileData = getActorFlagData(pileDocument, data2); + const baseScale = overrideScale ?? (pileDocument instanceof TokenDocument ? pileDocument.texture.scaleX : pileDocument.prototypeToken.texture.scaleX); + if (!isValidItemPile(pileDocument, itemPileData) || !isItemPileLootable(pileDocument, itemPileData)) { + return baseScale; + } + items = items || getActorItems(pileDocument); + currencies = currencies || getActorCurrencies(pileDocument); + const numItems = items.length + currencies.length; + if (itemPileData?.type === CONSTANTS.PILE_TYPES.CONTAINER || !itemPileData.displayOne || !itemPileData.overrideSingleItemScale || numItems > 1 || numItems === 0) { + return baseScale; + } + return itemPileData.singleItemScale; +} +__name(getItemPileTokenScale, "getItemPileTokenScale"); +function getItemPileName(target, { data: data2 = false, items = false, currencies = false } = {}, overrideName = null) { + const pileDocument = getDocument(target); + const itemPileData = getActorFlagData(pileDocument, data2); + let name = overrideName ?? (pileDocument instanceof TokenDocument ? pileDocument.name : pileDocument.prototypeToken.name); + if (!isValidItemPile(pileDocument, itemPileData) || !isItemPileLootable(pileDocument, itemPileData)) { + return name; + } + items = items || getActorItems(pileDocument); + currencies = currencies || getActorCurrencies(pileDocument); + const numItems = items.length + currencies.length; + if (itemPileData?.type === CONSTANTS.PILE_TYPES.CONTAINER || !itemPileData.displayOne || !itemPileData.showItemName || numItems > 1 || numItems === 0) { + return name; + } + const item = items.length > 0 ? items[0] : currencies[0]; + const quantity = (items.length > 0 ? getItemQuantity(item) : currencies[0]?.quantity) ?? 1; + return item.name + (quantity > 1 ? " x " + quantity : ""); +} +__name(getItemPileName, "getItemPileName"); +function shouldEvaluateChange(target, changes) { + const flags = getActorFlagData(target, getProperty(changes, CONSTANTS.FLAGS.PILE) ?? {}); + if (!isValidItemPile(target, flags)) + return false; + return flags.type === CONSTANTS.PILE_TYPES.CONTAINER && (flags.closedImage || flags.emptyImage || flags.openedImage || flags.lockedImage) || flags.displayOne || flags.showItemName || flags.overrideSingleItemScale; +} +__name(shouldEvaluateChange, "shouldEvaluateChange"); +function getRelevantTokensAndActor(target) { + const relevantDocument = getDocument(target); + let documentActor; + let documentTokens = []; + if (relevantDocument instanceof Actor) { + documentActor = relevantDocument; + if (relevantDocument.token) { + documentTokens.push(relevantDocument?.token); + } else { + documentTokens = canvas.tokens.placeables.filter((token) => token.document.actor === documentActor).map((token) => token.document); + } + } else { + documentActor = relevantDocument.actor; + if (relevantDocument.isLinked) { + documentTokens = canvas.tokens.placeables.filter((token) => token.document.actor === documentActor).map((token) => token.document); + } else { + documentTokens.push(relevantDocument); + } + } + return [documentActor, documentTokens]; +} +__name(getRelevantTokensAndActor, "getRelevantTokensAndActor"); +async function updateItemPileData(target, flagData, tokenData) { + if (!target) + return; + if (!flagData) + flagData = getActorFlagData(target); + if (!tokenData) + tokenData = {}; + tokenData = foundry.utils.mergeObject(tokenData, {}); + let [documentActor, documentTokens] = getRelevantTokensAndActor(target); + const items = getActorItems(documentActor, { itemFilters: flagData.overrideItemFilters }); + const actorCurrencies = (flagData.overrideCurrencies || []).concat(flagData.overrideSecondaryCurrencies || []); + const currencies = getActorCurrencies(documentActor, { currencyList: actorCurrencies }); + const pileData = { data: flagData, items, currencies }; + flagData = cleanFlagData(flagData); + const updates = documentTokens.map((tokenDocument) => { + const overrideImage = getProperty(tokenData, "texture.src") ?? getProperty(tokenData, "img"); + const overrideScale = getProperty(tokenData, "texture.scaleX") ?? getProperty(tokenData, "texture.scaleY") ?? getProperty(tokenData, "scale"); + const scale = getItemPileTokenScale(tokenDocument, pileData, overrideScale); + const newTokenData = foundry.utils.mergeObject(tokenData, { + "texture.src": getItemPileTokenImage(tokenDocument, pileData, overrideImage), + "texture.scaleX": scale, + "texture.scaleY": scale, + "name": getItemPileName(tokenDocument, pileData, tokenData?.name) + }); + const data2 = { + "_id": tokenDocument.id, + ...newTokenData + }; + if (!tokenDocument.actorLink && (tokenDocument.actor === documentActor || !documentActor)) { + data2[CONSTANTS.FLAGS.PILE] = flagData; + data2[CONSTANTS.FLAGS.VERSION] = getModuleVersion(); + documentActor = false; + } + return data2; + }); + if (canvas.scene && !foundry.utils.isEmpty(updates)) { + await canvas.scene.updateEmbeddedDocuments("Token", updates); + } + if (documentActor) { + await documentActor.update({ + [CONSTANTS.FLAGS.PILE]: flagData, + [CONSTANTS.FLAGS.VERSION]: getModuleVersion() + }); + } + return true; +} +__name(updateItemPileData, "updateItemPileData"); +function cleanFlagData(flagData) { + const defaults = foundry.utils.mergeObject( + { ...CONSTANTS.PILE_DEFAULTS }, + getSetting(SETTINGS$1.PILE_DEFAULTS) ?? {} + ); + const defaultKeys = Object.keys(defaults); + const difference = new Set(Object.keys(foundry.utils.diffObject(flagData, defaults))); + const toRemove = new Set(defaultKeys.filter((key) => !difference.has(key))); + if (flagData.enabled) { + toRemove.delete("type"); + } + if (!CONSTANTS.CUSTOM_PILE_TYPES[flagData.type]) { + const baseKeys = new Set(defaultKeys); + for (const key of Object.keys(flagData)) { + if (!baseKeys.has(key)) { + delete flagData[key]; + flagData["-=" + key] = null; + } + } + } + for (const key of toRemove) { + delete flagData[key]; + flagData["-=" + key] = null; + } + return flagData; +} +__name(cleanFlagData, "cleanFlagData"); +function cleanItemFlagData(flagData, { addRemoveFlag = false } = {}) { + const defaults = Object.keys(CONSTANTS.ITEM_DEFAULTS); + const difference = new Set(Object.keys(foundry.utils.diffObject(flagData, CONSTANTS.ITEM_DEFAULTS))); + const toRemove = new Set(defaults.filter((key) => !difference.has(key))); + for (const key of toRemove) { + delete flagData[key]; + if (!addRemoveFlag) { + flagData["-=" + key] = null; + } + } + return flagData; +} +__name(cleanItemFlagData, "cleanItemFlagData"); +function updateItemData(item, update2, { returnUpdate = false, version = false } = {}) { + const flagData = cleanItemFlagData(foundry.utils.mergeObject(getItemFlagData(item), update2.flags ?? {})); + const updates = foundry.utils.mergeObject(update2?.data ?? {}, {}); + setProperty(updates, CONSTANTS.FLAGS.ITEM, flagData); + setProperty(updates, CONSTANTS.FLAGS.VERSION, version || getModuleVersion()); + if (returnUpdate) { + updates["_id"] = item?.id ?? item?._id; + return updates; + } + return item.update(updates); +} +__name(updateItemData, "updateItemData"); +function getMerchantModifiersForActor(merchant, { + item = false, + actor = false, + pileFlagData = false, + itemFlagData = false, + absolute = false +} = {}) { + let { + buyPriceModifier, + sellPriceModifier, + itemTypePriceModifiers, + actorPriceModifiers + } = getActorFlagData(merchant, pileFlagData); + if (item) { + if (!itemFlagData) { + itemFlagData = getItemFlagData(item); + } + const itemTypePriceModifier = itemTypePriceModifiers.sort((a, b) => a.type === "custom" && b.type !== "custom" ? -1 : 0).find((priceData) => { + return priceData.type === "custom" ? priceData.category.toLowerCase() === itemFlagData.customCategory.toLowerCase() : priceData.type === item.type; + }); + if (itemTypePriceModifier) { + buyPriceModifier = itemTypePriceModifier.override ? itemTypePriceModifier.buyPriceModifier : buyPriceModifier * itemTypePriceModifier.buyPriceModifier; + sellPriceModifier = itemTypePriceModifier.override ? itemTypePriceModifier.sellPriceModifier : sellPriceModifier * itemTypePriceModifier.sellPriceModifier; + } + } + if (actor && actorPriceModifiers) { + const actorSpecificModifiers = actorPriceModifiers?.find((data2) => data2.actorUuid === getUuid(actor) || data2.actor === actor.id); + if (actorSpecificModifiers) { + buyPriceModifier = actorSpecificModifiers.override || absolute ? actorSpecificModifiers.buyPriceModifier ?? buyPriceModifier : buyPriceModifier * actorSpecificModifiers.buyPriceModifier; + sellPriceModifier = actorSpecificModifiers.override || absolute ? actorSpecificModifiers.sellPriceModifier ?? sellPriceModifier : sellPriceModifier * actorSpecificModifiers.sellPriceModifier; + } + } + return { + buyPriceModifier: roundToDecimals(buyPriceModifier, 2), + sellPriceModifier: roundToDecimals(sellPriceModifier, 2) + }; +} +__name(getMerchantModifiersForActor, "getMerchantModifiersForActor"); +function getSmallestExchangeRate(currencies) { + return currencies.length > 1 ? Math.min(...currencies.map((currency) => currency.exchangeRate)) : getSetting(SETTINGS$1.CURRENCY_DECIMAL_DIGITS) ?? 1e-5; +} +__name(getSmallestExchangeRate, "getSmallestExchangeRate"); +function getExchangeRateDecimals(smallestExchangeRate) { + return smallestExchangeRate.toString().includes(".") ? smallestExchangeRate.toString().split(".")[1].length : 0; +} +__name(getExchangeRateDecimals, "getExchangeRateDecimals"); +function getPriceArray(totalCost, currencies) { + const primaryCurrency = currencies.find((currency) => currency.primary); + if (currencies.length === 1) { + return [{ + ...primaryCurrency, + cost: totalCost, + baseCost: totalCost, + maxCurrencyCost: totalCost, + string: primaryCurrency.abbreviation.replace("{#}", totalCost) + }]; + } + const smallestExchangeRate = getSmallestExchangeRate(currencies); + const prices = []; + if (primaryCurrency.exchangeRate === smallestExchangeRate) { + let cost2 = totalCost; + for (const currency of currencies) { + const numCurrency = Math.floor(cost2 / currency.exchangeRate); + cost2 = cost2 - numCurrency * currency.exchangeRate; + prices.push({ + ...currency, + cost: Math.round(numCurrency), + baseCost: Math.round(numCurrency), + maxCurrencyCost: Math.ceil(totalCost / currency.exchangeRate), + string: currency.abbreviation.replace("{#}", numCurrency) + }); + } + return prices; + } + const decimals = getExchangeRateDecimals(smallestExchangeRate); + let fraction = roundToDecimals(totalCost % 1, decimals); + let cost = Math.round(totalCost - fraction); + let skipPrimary = false; + if (cost) { + skipPrimary = true; + prices.push({ + ...primaryCurrency, + cost, + baseCost: cost, + maxCurrencyCost: totalCost, + string: primaryCurrency.abbreviation.replace("{#}", cost) + }); + } + for (const currency of currencies) { + if (currency === primaryCurrency && skipPrimary) + continue; + const numCurrency = Math.floor(roundToDecimals(fraction / currency.exchangeRate, decimals)); + fraction = roundToDecimals(fraction - numCurrency * currency.exchangeRate, decimals); + prices.push({ + ...currency, + cost: Math.round(numCurrency), + baseCost: Math.round(numCurrency), + maxCurrencyCost: Math.ceil(totalCost / currency.exchangeRate), + string: currency.abbreviation.replace("{#}", numCurrency) + }); + } + prices.sort((a, b) => b.exchangeRate - a.exchangeRate); + return prices; +} +__name(getPriceArray, "getPriceArray"); +function getPriceFromString(str, currencyList = false) { + if (!currencyList) { + currencyList = getCurrencyList().filter((currency) => !currency.secondary); + } + const currencies = foundry.utils.duplicate(currencyList).map((currency) => { + currency.quantity = 0; + currency.identifier = currency.abbreviation.toLowerCase().replace("{#}", ""); + return currency; + }); + const splitBy = new RegExp("(.*?) *(" + currencies.map((currency) => currency.identifier).join("|") + ")", "g"); + const parts = [...str.split(",").join("").split(" ").join("").trim().toLowerCase().matchAll(splitBy)]; + let overallCost = 0; + for (const part of parts) { + for (const currency of currencies) { + if (part[2] !== currency.identifier) + continue; + try { + const roll = new Roll(part[1]).evaluate({ async: false }); + currency.quantity = roll.total; + if (roll.total !== Number(part[1])) { + currency.roll = roll; + } + overallCost += roll.total * currency.exchangeRate; + } catch (err) { + } + } + } + if (overallCost === 0) { + try { + const roll = new Roll(str).evaluate({ async: false }); + if (roll.total) { + const primaryCurrency = currencies.find((currency) => currency.primary); + primaryCurrency.quantity = roll.total; + if (roll.total !== Number(str)) { + primaryCurrency.roll = roll; + } + overallCost = roll.total; + } + } catch (err) { + } + } + return { currencies, overallCost }; +} +__name(getPriceFromString, "getPriceFromString"); +function getPriceData({ + cost = false, + item = false, + seller = false, + buyer = false, + sellerFlagData = false, + buyerFlagData = false, + itemFlagData = false, + quantity = 1 +} = {}) { + let priceData = []; + buyerFlagData = getActorFlagData(buyer, buyerFlagData); + if (!isItemPileMerchant(buyer, buyerFlagData)) { + buyerFlagData = false; + } + sellerFlagData = getActorFlagData(seller, sellerFlagData); + if (!isItemPileMerchant(seller, sellerFlagData)) { + sellerFlagData = false; + } + if (cost && !item) { + item = {}; + setProperty(item, game.itempiles.API.ITEM_PRICE_ATTRIBUTE, cost); + setProperty(item, CONSTANTS.FLAGS.ITEM, CONSTANTS.ITEM_DEFAULTS); + } + itemFlagData = itemFlagData || getItemFlagData(item); + let merchant = sellerFlagData ? seller : buyer; + if (merchant === buyer && itemFlagData.cantBeSoldToMerchants) { + priceData.push({ + free: false, + basePrices: [], + basePriceString: "", + prices: [], + priceString: "", + totalCost: 0, + baseCost: 0, + primary: true, + maxQuantity: 0, + quantity + }); + return priceData; + } + let modifier = 1; + if (sellerFlagData) { + modifier = getMerchantModifiersForActor(seller, { + item, + actor: buyer, + pileFlagData: sellerFlagData, + itemFlagData + }).buyPriceModifier; + } else if (buyerFlagData) { + modifier = getMerchantModifiersForActor(buyer, { + item, + actor: seller, + pileFlagData: buyerFlagData, + itemFlagData + }).sellPriceModifier; + } + const disableNormalCost = itemFlagData.disableNormalCost && !sellerFlagData.onlyAcceptBasePrice; + const hasOtherPrices = itemFlagData.prices.filter((priceGroup) => priceGroup.length).length > 0; + const currencyList = getCurrencyList(merchant).filter((currency) => !currency.secondary); + const currencies = getActorCurrencies(merchant, { currencyList, getAll: true, secondary: false }); + const smallestExchangeRate = getSmallestExchangeRate(currencyList); + const decimals = getExchangeRateDecimals(smallestExchangeRate); + let overallCost; + let itemCost = getItemCost(item); + if (SYSTEMS.DATA.ITEM_COST_TRANSFORMER) { + overallCost = SYSTEMS.DATA.ITEM_COST_TRANSFORMER(item, currencyList); + if (overallCost === false) { + debug("failed to find price for item:", item); + } + } else if (typeof itemCost === "string" && isNaN(Number(itemCost))) { + overallCost = getPriceFromString(itemCost, currencyList).overallCost; + } else { + overallCost = Number(itemCost); + } + if (itemFlagData?.free || !disableNormalCost && (overallCost === 0 || overallCost < smallestExchangeRate) && !hasOtherPrices || modifier <= 0) { + priceData.push({ + free: true, + basePrices: [], + basePriceString: "", + prices: [], + priceString: "", + totalCost: 0, + baseCost: 0, + primary: true, + maxQuantity: Infinity, + quantity + }); + return priceData; + } + if (overallCost >= smallestExchangeRate && (!itemFlagData.disableNormalCost || merchant === buyer && buyerFlagData.onlyAcceptBasePrice)) { + const baseCost = roundToDecimals(overallCost * modifier, decimals); + const basePrices = getPriceArray(baseCost, currencies); + let totalCost = roundToDecimals(overallCost * modifier * quantity, decimals); + let prices = getPriceArray(totalCost, currencies); + if (baseCost) { + priceData.push({ + basePrices, + basePriceString: basePrices.filter((price) => price.cost).map((price) => price.string).join(" "), + prices, + priceString: prices.filter((price) => price.cost).map((price) => price.string).join(" "), + totalCost, + baseCost, + primary: true, + maxQuantity: 0, + quantity + }); + } + } + if (itemFlagData.prices.length && !(merchant === buyer && buyerFlagData.onlyAcceptBasePrice)) { + priceData = priceData.concat(itemFlagData.prices.map((priceGroup) => { + const prices = priceGroup.map((price) => { + const itemModifier = price.fixed ? 1 : modifier; + const cost2 = Math.round(price.quantity * itemModifier * quantity); + const baseCost = Math.round(price.quantity * itemModifier); + price.name = game.i18n.localize(price.name); + if (!price.data?.item) { + price.data.item = getItemFromCache(price.data.uuid); + } + return { + ...price, + cost: cost2, + baseCost, + modifier: itemModifier, + priceString: cost2 ? price.abbreviation.replace("{#}", cost2) : "", + basePriceString: baseCost ? price.abbreviation.replace("{#}", baseCost) : "" + }; + }); + return { + prices, + priceString: prices.filter((price) => price.priceString).map((price) => price.priceString).join(" "), + basePriceString: prices.filter((price) => price.basePriceString).map((price) => price.basePriceString).join(" "), + maxQuantity: 0, + quantity + }; + })); + } + if (!buyer) + return priceData; + const buyerInfiniteCurrencies = buyerFlagData?.infiniteCurrencies; + const buyerInfiniteQuantity = buyerFlagData?.infiniteQuantity; + const recipientCurrencies = getActorCurrencies(buyer, { currencyList, secondary: false }); + const totalCurrencies = recipientCurrencies.map((currency) => currency.quantity * currency.exchangeRate).reduce((acc, num) => acc + num, 0); + for (const priceGroup of priceData) { + priceGroup.maxQuantity = Infinity; + if (priceGroup.baseCost !== void 0) { + priceGroup.prices.forEach((price) => { + price.maxQuantity = Infinity; + }); + if (buyerInfiniteCurrencies) + continue; + priceGroup.maxQuantity = Math.floor(totalCurrencies / priceGroup.baseCost); + priceGroup.prices.forEach((price) => { + price.maxQuantity = priceGroup.maxQuantity; + }); + } else { + if (buyerInfiniteQuantity) + continue; + for (const price of priceGroup.prices) { + if (price.type === "attribute") { + const attributeQuantity = Number(getProperty(buyer, price.data.path)); + price.buyerQuantity = attributeQuantity; + if (price.percent) { + const percent = Math.min(1, price.baseCost / 100); + const percentQuantity = Math.max(0, Math.floor(attributeQuantity * percent)); + price.maxQuantity = Math.floor(attributeQuantity / percentQuantity); + price.baseCost = !buyer ? price.baseCost : percentQuantity; + price.cost = !buyer ? price.cost : percentQuantity * quantity; + price.quantity = !buyer ? price.quantity : percentQuantity; + } else { + price.maxQuantity = Math.floor(attributeQuantity / price.baseCost); + } + priceGroup.maxQuantity = Math.min(priceGroup.maxQuantity, price.maxQuantity); + } else { + const priceItem = getItemFromCache(price.data.uuid); + const foundItem = findSimilarItem(buyer.items, priceItem); + const itemQuantity = foundItem ? getItemQuantity(foundItem) : 0; + price.buyerQuantity = itemQuantity; + if (price.percent) { + const percent = Math.min(1, price.baseCost / 100); + const percentQuantity = Math.max(0, Math.floor(itemQuantity * percent)); + price.maxQuantity = Math.floor(itemQuantity / percentQuantity); + price.baseCost = !buyer ? price.baseCost : percentQuantity; + price.cost = !buyer ? price.cost : percentQuantity * quantity; + price.quantity = !buyer ? price.quantity : percentQuantity; + } else { + price.maxQuantity = Math.floor(itemQuantity / price.baseCost); + } + priceGroup.maxQuantity = Math.min(priceGroup.maxQuantity, price.maxQuantity); + } + } + } + } + return priceData; +} +__name(getPriceData, "getPriceData"); +function getPaymentData({ + purchaseData = [], + seller = false, + buyer = false, + sellerFlagData = false, + buyerFlagData = false +} = {}) { + buyerFlagData = getActorFlagData(buyer, buyerFlagData); + if (!isItemPileMerchant(buyer, buyerFlagData)) { + buyerFlagData = false; + } + sellerFlagData = getActorFlagData(seller, sellerFlagData); + if (!isItemPileMerchant(seller, sellerFlagData)) { + sellerFlagData = false; + } + const merchant = sellerFlagData ? seller : buyer; + const currencyList = getCurrencyList(merchant).filter((currency) => !currency.secondary); + const currencies = getActorCurrencies(merchant, { currencyList, getAll: true, secondary: false }); + const smallestExchangeRate = getSmallestExchangeRate(currencies); + const decimals = getExchangeRateDecimals(smallestExchangeRate); + const recipientCurrencies = getActorCurrencies(buyer, { currencyList, getAll: true, secondary: false }); + const buyerInfiniteCurrencies = buyerFlagData?.infiniteCurrencies; + const paymentData = purchaseData.map((data2) => { + const prices = getPriceData({ + cost: data2.cost, + item: data2.item, + seller, + buyer, + sellerFlagData, + buyerFlagData, + itemFlagData: data2.itemFlagData, + quantity: data2.quantity || 1 + })[data2.paymentIndex || 0]; + return { + ...prices, + item: data2.item + }; + }).reduce((priceData, priceGroup) => { + if (!priceGroup.maxQuantity && (buyer || seller)) { + priceData.canBuy = false; + priceData.reason = ["ITEM-PILES.Applications.TradeMerchantItem." + (buyer === merchant ? "TheyCantAfford" : "YouCantAfford")]; + return priceData; + } + if (priceGroup.primary) { + priceData.totalCurrencyCost = roundToDecimals(priceData.totalCurrencyCost + priceGroup.totalCost, decimals); + priceData.primary = true; + } else { + for (const price of priceGroup.prices) { + let existingPrice = priceData.otherPrices.find((otherPrice) => { + return otherPrice.id === price.id || otherPrice.name === price.name && otherPrice.img === price.img && otherPrice.type === price.type; + }); + if (existingPrice) { + existingPrice.cost += price.cost; + } else { + const index2 = priceData.otherPrices.push(price); + existingPrice = priceData.otherPrices[index2 - 1]; + existingPrice.quantity = 0; + } + existingPrice.quantity += price.cost; + existingPrice.buyerQuantity -= price.cost; + if (existingPrice.buyerQuantity < 0) { + priceData.canBuy = false; + priceData.reason = ["ITEM-PILES.Applications.TradeMerchantItem." + (buyer === merchant ? "TheyCantAfford" : "YouCantAfford")]; + } + } + } + if (priceGroup.item) { + const itemQuantity = getItemQuantity(priceGroup.item); + const quantityPerPrice = game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE ? getProperty(priceGroup.item, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE) ?? 1 : 1; + const requiredQuantity = Math.floor(priceGroup.quantity * quantityPerPrice); + if (requiredQuantity > itemQuantity && requiredQuantity > priceGroup.maxQuantity * quantityPerPrice) { + priceData.canBuy = false; + priceData.reason = [`ITEM-PILES.Applications.TradeMerchantItem.${buyer === merchant ? "You" : "They"}LackQuantity`, { + quantity: itemQuantity, + requiredQuantity + }]; + } + priceData.buyerReceive.push({ + type: "item", + name: priceGroup.item.name, + img: priceGroup.item.img, + quantity: requiredQuantity, + item: priceGroup.item + }); + } + return priceData; + }, { + totalCurrencyCost: 0, + canBuy: true, + primary: false, + finalPrices: [], + otherPrices: [], + reason: [], + buyerReceive: [], + buyerChange: [], + sellerReceive: [] + }); + if (paymentData.totalCurrencyCost && !seller && !buyer) { + paymentData.finalPrices = getPriceArray(paymentData.totalCurrencyCost, recipientCurrencies); + } else if (paymentData.totalCurrencyCost) { + const prices = getPriceArray(paymentData.totalCurrencyCost, recipientCurrencies); + let priceLeft = paymentData.totalCurrencyCost; + const inverse = prices[prices.length - 1].primary && prices[prices.length - 1].exchangeRate === 1; + for (let i = prices.length - 1, j = 0; i >= 0; i--, j++) { + const price = prices[inverse ? j : i]; + const buyerPrice = { + ...price, + buyerQuantity: buyerInfiniteCurrencies ? Infinity : price.quantity, + quantity: 0, + isCurrency: true + }; + if (price.type === "item") { + buyerPrice.item = price.data.item ?? getItemFromCache(price.data.uuid); + } + if (priceLeft <= 0 || !price.cost || currencies.length === 1) { + if (currencies.length === 1) { + buyerPrice.quantity = price.cost; + priceLeft = 0; + } + paymentData.finalPrices.push(buyerPrice); + continue; + } + buyerPrice.quantity = buyerPrice.buyerQuantity < price.cost ? buyerPrice.buyerQuantity : price.cost; + if (price.primary) { + const totalCurrencyValue = roundToDecimals(buyerPrice.buyerQuantity * price.exchangeRate, decimals); + if (totalCurrencyValue > priceLeft) { + buyerPrice.quantity = Math.ceil(priceLeft); + } + } + paymentData.finalPrices.push(buyerPrice); + priceLeft = roundToDecimals(priceLeft - buyerPrice.quantity * price.exchangeRate, decimals); + } + if (currencies.length > 1) { + while (priceLeft > 0) { + for (const buyerPrice of paymentData.finalPrices) { + let buyerCurrencyQuantity = buyerPrice.buyerQuantity - buyerPrice.quantity; + if (!buyerCurrencyQuantity) + continue; + const newQuantity = Math.ceil(Math.min(buyerCurrencyQuantity, priceLeft / buyerPrice.exchangeRate)); + buyerPrice.quantity += newQuantity; + priceLeft = roundToDecimals(priceLeft - newQuantity * buyerPrice.exchangeRate, decimals); + if (priceLeft <= 0) + break; + } + if (priceLeft > 0) { + paymentData.finalPrices = paymentData.finalPrices.sort((a, b) => b.exchangeRate - a.exchangeRate); + } else { + break; + } + } + paymentData.finalPrices = paymentData.finalPrices.sort((a, b) => b.exchangeRate - a.exchangeRate); + let change = Math.abs(priceLeft); + for (const currency of currencies) { + if (!change) + break; + let numCurrency = Math.floor(roundToDecimals(change / currency.exchangeRate, decimals)); + change = roundToDecimals(change - numCurrency * currency.exchangeRate, decimals); + if (numCurrency) { + const payment = paymentData.finalPrices.find((payment2) => { + return payment2.id === currency.id || payment2.name === currency.name && payment2.img === currency.img && payment2.type === currency.type; + }); + if (!payment) + continue; + if (payment.quantity - numCurrency >= 0) { + payment.quantity -= numCurrency; + } else { + paymentData.buyerChange.push({ + ...currency, + isCurrency: true, + quantity: numCurrency - payment.quantity + }); + payment.quantity = 0; + } + } + } + } + paymentData.sellerReceive = paymentData.finalPrices.map((price) => { + return { ...price }; + }); + let changeNeeded = paymentData.buyerChange.reduce((acc, change) => { + const currency = currencies.find((currency2) => { + return change.id === currency2.id || change.name === currency2.name && change.img === currency2.img && change.type === currency2.type; + }); + return acc + currency.quantity >= change.quantity ? 0 : (change.quantity - currency.quantity) * change.exchangeRate; + }, 0); + if (changeNeeded) { + const primaryCurrency = paymentData.sellerReceive.find((price) => price.primary && price.quantity * price.exchangeRate > changeNeeded); + if (primaryCurrency) { + primaryCurrency.quantity--; + changeNeeded -= 1 * primaryCurrency.exchangeRate; + } else { + const biggestCurrency = paymentData.sellerReceive.find((price) => price.quantity && price.quantity * price.exchangeRate > changeNeeded); + biggestCurrency.quantity--; + changeNeeded -= 1 * biggestCurrency.exchangeRate; + } + changeNeeded = Math.abs(changeNeeded); + for (const currency of paymentData.sellerReceive) { + if (!changeNeeded) + break; + let numCurrency = Math.floor(roundToDecimals(changeNeeded / currency.exchangeRate, decimals)); + changeNeeded = roundToDecimals(changeNeeded - numCurrency * currency.exchangeRate, decimals); + currency.quantity += numCurrency; + } + } + } + paymentData.finalPrices = paymentData.finalPrices.concat(paymentData.otherPrices); + paymentData.sellerReceive = paymentData.sellerReceive.concat(paymentData.otherPrices); + paymentData.basePriceString = paymentData.finalPrices.filter((price) => price.cost).map((price) => { + let abbreviation = price.abbreviation; + if (price.percent && abbreviation.includes("%")) { + abbreviation = abbreviation.replaceAll("%", ""); + } + return abbreviation.replace("{#}", price.cost); + }).join(" "); + delete paymentData.otherPrices; + return paymentData; +} +__name(getPaymentData, "getPaymentData"); +function getVaultGridData(vaultActor, flagData = false) { + const vaultFlags = getActorFlagData(vaultActor, flagData); + const vaultItems = getActorItems(vaultActor); + const validVaultItems = vaultItems.filter((item) => { + return !getItemFlagData(item).vaultExpander; + }); + let enabledCols = vaultFlags.cols; + let enabledRows = vaultFlags.rows; + if (vaultFlags.vaultExpansion) { + const vaultExpanders = vaultItems.filter((item) => { + return getItemFlagData(item).vaultExpander; + }).map((item) => ({ + itemFlagData: getItemFlagData(item), + quantity: getItemQuantity(item) + })); + const expansions = vaultExpanders.reduce((acc, item) => { + acc.cols += (item.itemFlagData.addsCols ?? 0) * item.quantity; + acc.rows += (item.itemFlagData.addsRows ?? 0) * item.quantity; + return acc; + }, { + cols: vaultFlags.baseExpansionCols ?? 0, + rows: vaultFlags.baseExpansionRows ?? 0 + }); + enabledCols = expansions.cols; + enabledRows = expansions.rows; + } + enabledCols = Math.min(enabledCols, vaultFlags.cols); + enabledRows = Math.min(enabledRows, vaultFlags.rows); + return { + totalSpaces: Math.max(0, vaultFlags.cols * vaultFlags.rows), + enabledSpaces: Math.max(0, enabledCols * enabledRows), + freeSpaces: Math.max(0, enabledCols * enabledRows - validVaultItems.length), + enabledCols, + enabledRows, + cols: vaultFlags.cols, + rows: vaultFlags.rows + }; +} +__name(getVaultGridData, "getVaultGridData"); +function getVaultAccess(vaultActor, { flagData = false, hasRecipient = false } = {}) { + const vaultFlags = getActorFlagData(vaultActor, flagData); + const vaultAccess = vaultFlags.vaultAccess.filter((access) => { + return fromUuidSync(access.uuid)?.isOwner; + }); + return vaultAccess.reduce((acc, access) => { + acc.canView = acc.canView || (access.view ?? true); + acc.canOrganize = acc.canOrganize || access.organize; + acc.canWithdrawItems = (acc.canWithdrawItems || access.items.withdraw) && hasRecipient; + acc.canDepositItems = (acc.canDepositItems || access.items.deposit) && hasRecipient; + acc.canWithdrawCurrencies = (acc.canWithdrawCurrencies || access.currencies.withdraw) && hasRecipient; + acc.canDepositCurrencies = (acc.canDepositCurrencies || access.currencies.deposit) && hasRecipient; + return acc; + }, { + canView: vaultActor.isOwner || !vaultFlags.restrictVaultAccess, + canOrganize: vaultActor.isOwner, + canWithdrawItems: vaultActor.isOwner && hasRecipient, + canDepositItems: vaultActor.isOwner && hasRecipient, + canWithdrawCurrencies: vaultActor.isOwner && hasRecipient, + canDepositCurrencies: vaultActor.isOwner && hasRecipient + }); +} +__name(getVaultAccess, "getVaultAccess"); +async function updateVaultLog(itemPile, { + actor = false, + userId = false, + items = [], + attributes = [], + withdrawal = true, + vaultLogData = {} +} = {}) { + const formattedItems = []; + const formattedCurrencies = []; + const currencies = getActorCurrencies(itemPile, { getAll: true }); + const date = Date.now(); + for (const itemData of items) { + if (currencies.some((currency) => currency.name === itemData.item.name)) { + formattedCurrencies.push({ + actor: actor?.name ?? false, + user: userId, + name: itemData.item.name, + qty: itemData.quantity * (withdrawal ? -1 : 1), + action: vaultLogData?.action ?? (withdrawal ? "withdrew" : "deposited"), + date + }); + } else { + const item = await Item.implementation.create(itemData.item, { temporary: true }); + formattedItems.push({ + actor: actor?.name ?? false, + user: userId, + name: item.name, + qty: itemData.quantity * (withdrawal ? -1 : 1), + action: vaultLogData?.action ?? (withdrawal ? "withdrew" : "deposited"), + date + }); + } + } + for (const [key, quantity] of Object.entries(attributes)) { + const currency = currencies.find((currency2) => currency2.data.path === key); + if (currency) { + formattedCurrencies.push({ + actor: actor?.name ?? false, + user: userId, + name: currency.name, + qty: quantity * (withdrawal ? -1 : 1), + action: vaultLogData?.action ?? (withdrawal ? "withdrew" : "deposited"), + date + }); + } + } + const vaultLog = getActorVaultLog(itemPile); + return itemPile.update({ + [CONSTANTS.FLAGS.LOG]: formattedItems.concat(formattedCurrencies).concat(vaultLog) + }); +} +__name(updateVaultLog, "updateVaultLog"); +function getActorVaultLog(actor) { + return getProperty(getActor(actor), CONSTANTS.FLAGS.LOG) || []; +} +__name(getActorVaultLog, "getActorVaultLog"); +function clearVaultLog(actor) { + return actor.update({ + [CONSTANTS.FLAGS.LOG]: [] + }); +} +__name(clearVaultLog, "clearVaultLog"); +async function rollTable({ + tableUuid, + formula = "1", + resetTable = true, + normalize = false, + displayChat = false, + rollData = {}, + customCategory = false +} = {}) { + const rolledItems = []; + const table = await fromUuid(tableUuid); + if (!tableUuid.startsWith("Compendium")) { + if (resetTable) { + await table.reset(); + } + if (normalize) { + await table.update({ + results: table.results.map((result) => ({ + _id: result.id, + weight: result.range[1] - (result.range[0] - 1) + })) + }); + await table.normalize(); + } + } + const roll = new Roll(formula.toString(), rollData).evaluate({ async: false }); + if (roll.total <= 0) { + return []; + } + let results; + if (game.modules.get("better-rolltables")?.active) { + results = (await game.betterTables.roll(table)).itemsData.map((result) => { + return { + documentCollection: result.compendiumName || result.documentName, + documentId: result.item.id, + text: result.item.text || result.item.name, + img: result.item.img, + quantity: result.quantity + }; + }); + } else { + results = (await table.drawMany(roll.total, { displayChat, recursive: true })).results; + } + for (const rollData2 of results) { + let rolledQuantity = rollData2?.quantity ?? 1; + let item; + if (rollData2.documentCollection === "Item") { + item = game.items.get(rollData2.documentId); + } else { + const compendium = game.packs.get(rollData2.documentCollection); + if (compendium) { + item = await compendium.getDocument(rollData2.documentId); + } + } + if (item instanceof RollTable) { + rolledItems.push(...await rollTable({ tableUuid: item.uuid, resetTable, normalize, displayChat })); + } else if (item instanceof Item) { + const quantity = Math.max(getItemQuantity(item) * rolledQuantity, 1); + rolledItems.push({ + ...rollData2, + item, + quantity + }); + } + } + const items = []; + rolledItems.forEach((newItem) => { + const existingItem = items.find( + (item) => item.documentId === newItem.documentId + ); + if (existingItem) { + existingItem.quantity += Math.max(newItem.quantity, 1); + } else { + setProperty(newItem, "flags", newItem.item.flags); + if (game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE && !getProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE)) { + setProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE, getItemQuantity(newItem.item)); + } + if (customCategory) { + setProperty(newItem, CONSTANTS.FLAGS.CUSTOM_CATEGORY, customCategory); + } + items.push({ + ...newItem + }); + } + }); + return items; +} +__name(rollTable, "rollTable"); +async function rollMerchantTables({ tableData = false, actor = false } = {}) { + if (tableData && !Array.isArray(tableData)) { + tableData = [tableData]; + } else if (!tableData && actor) { + const flagData = getActorFlagData(actor); + tableData = flagData.tablesForPopulate; + } else if (!tableData && !actor) { + return []; + } + let items = []; + for (const table of tableData) { + const rollableTable = await fromUuid(table.uuid); + if (!rollableTable) + continue; + if (!table.uuid.startsWith("Compendium")) { + await rollableTable.reset(); + } + let tableItems = []; + if (table.addAll) { + for (const [itemId, formula] of Object.entries(table.items)) { + const roll = new Roll(formula).evaluate({ async: false }); + if (roll.total <= 0) + continue; + const rollResult = rollableTable.results.get(itemId).toObject(); + const potentialPack = game.packs.get(rollResult.documentCollection); + if (rollResult.documentCollection === "RollTable" || potentialPack?.documentName === "RollTable") { + const subTable = await getTable(rollResult); + items.push(...await rollMerchantTables({ + tableData: [{ + uuid: subTable.uuid, + addAll: false, + timesToRoll: roll.total, + customCategory: table.customCategory + }], + actor + })); + continue; + } + const item = await getItem(rollResult); + if (!item) + continue; + const quantity = roll.total * Math.max(getItemQuantity(item), 1); + tableItems.push({ + ...rollResult, + customCategory: table.customCategory, + item, + quantity + }); + } + } else { + const roll = new Roll((table.timesToRoll ?? "1").toString()).evaluate({ async: false }); + if (roll.total <= 0) { + continue; + } + tableItems = await rollTable({ + tableUuid: table.uuid, + formula: roll.total + }); + tableItems.forEach((item) => { + if (table.customCategory) { + setProperty(item, CONSTANTS.FLAGS.CUSTOM_CATEGORY, table.customCategory); + } + }); + } + tableItems.forEach((newItem) => { + const existingItem = items.find( + (item) => item.documentId === newItem.documentId + ); + if (existingItem) { + existingItem.quantity += Math.max(newItem.quantity, 1); + } else { + setProperty(newItem, "flags", newItem.item.flags); + if (game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE && !getProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE)) { + setProperty(newItem, game.itempiles.API.QUANTITY_FOR_PRICE_ATTRIBUTE, getItemQuantity(newItem.item)); + } + if (newItem.customCategory) { + setProperty(newItem, CONSTANTS.FLAGS.CUSTOM_CATEGORY, newItem.customCategory); + } + items.push({ + ...newItem, + quantity: newItem.quantity + }); + } + }); + } + return items; +} +__name(rollMerchantTables, "rollMerchantTables"); +async function getTable(tableToGet) { + let table; + if (tableToGet.documentCollection === "RollTable") { + table = game.tables.get(tableToGet.documentId); + } else { + const compendium = game.packs.get(tableToGet.documentCollection); + if (compendium) { + table = await compendium.getDocument(tableToGet.documentId); + } + } + return table; +} +__name(getTable, "getTable"); +async function getItem(itemToGet) { + let item; + if (itemToGet.documentCollection === "Item") { + item = game.items.get(itemToGet.documentId); + } else { + const compendium = game.packs.get(itemToGet.documentCollection); + if (compendium) { + item = await compendium.getDocument(itemToGet.documentId); + } + } + return item; +} +__name(getItem, "getItem"); +const PriceList_svelte_svelte_type_style_lang = ""; +function get_each_context$6(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[33] = list[i]; + child_ctx[35] = i; + return child_ctx; +} +__name(get_each_context$6, "get_each_context$6"); +function get_each_context_1$2(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[33] = list[i]; + child_ctx[36] = list; + child_ctx[35] = i; + return child_ctx; +} +__name(get_each_context_1$2, "get_each_context_1$2"); +function create_if_block_3$3(ctx) { + let a; + let mounted; + let dispose; + return { + c() { + a = element("a"); + a.innerHTML = ``; + attr(a, "class", "item-piles-clickable-red"); + }, + m(target, anchor) { + insert(target, a, anchor); + if (!mounted) { + dispose = listen( + a, + "click", + /*click_handler*/ + ctx[17] + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(a); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_3$3, "create_if_block_3$3"); +function create_if_block_2$3(ctx) { + let div; + return { + c() { + div = element("div"); + div.textContent = "Drop to add"; + attr(div, "class", "drop-to-add svelte-1c30usg"); + }, + m(target, anchor) { + insert(target, div, anchor); + }, + d(detaching) { + if (detaching) + detach(div); + } + }; +} +__name(create_if_block_2$3, "create_if_block_2$3"); +function create_else_block$5(ctx) { + let button; + let mounted; + let dispose; + function click_handler_1() { + return ( + /*click_handler_1*/ + ctx[25]( + /*index*/ + ctx[35] + ) + ); + } + __name(click_handler_1, "click_handler_1"); + return { + c() { + button = element("button"); + button.innerHTML = ` View item`; + attr(button, "type", "button"); + }, + m(target, anchor) { + insert(target, button, anchor); + if (!mounted) { + dispose = listen(button, "click", click_handler_1); + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + }, + d(detaching) { + if (detaching) + detach(button); + mounted = false; + dispose(); + } + }; +} +__name(create_else_block$5, "create_else_block$5"); +function create_if_block_1$6(ctx) { + let input; + let mounted; + let dispose; + function input_input_handler() { + ctx[24].call( + input, + /*each_value_1*/ + ctx[36], + /*index*/ + ctx[35] + ); + } + __name(input_input_handler, "input_input_handler"); + return { + c() { + input = element("input"); + attr(input, "type", "text"); + attr(input, "placeholder", "system.attributes.hp.value"); + }, + m(target, anchor) { + insert(target, input, anchor); + set_input_value( + input, + /*price*/ + ctx[33].data.path + ); + if (!mounted) { + dispose = listen(input, "input", input_input_handler); + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty[0] & /*prices*/ + 1 && input.value !== /*price*/ + ctx[33].data.path) { + set_input_value( + input, + /*price*/ + ctx[33].data.path + ); + } + }, + d(detaching) { + if (detaching) + detach(input); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_1$6, "create_if_block_1$6"); +function create_each_block_1$2(key_1, ctx) { + let div9; + let div0; + let i0; + let div0_tabindex_value; + let div0_style_value; + let t0; + let div1; + let input0; + let t1; + let div2; + let input1; + let t2; + let div3; + let input2; + let input2_max_value; + let t3; + let div4; + let input3; + let t4; + let div5; + let input4; + let t5; + let div6; + let filepicker; + let updating_value; + let t6; + let div7; + let t7; + let div8; + let button; + let rect; + let stop_animation = noop; + let current; + let mounted; + let dispose; + function input0_input_handler() { + ctx[18].call( + input0, + /*each_value_1*/ + ctx[36], + /*index*/ + ctx[35] + ); + } + __name(input0_input_handler, "input0_input_handler"); + function input1_input_handler() { + ctx[19].call( + input1, + /*each_value_1*/ + ctx[36], + /*index*/ + ctx[35] + ); + } + __name(input1_input_handler, "input1_input_handler"); + function input2_change_handler() { + ctx[20].call( + input2, + /*each_value_1*/ + ctx[36], + /*index*/ + ctx[35] + ); + } + __name(input2_change_handler, "input2_change_handler"); + function input3_change_handler() { + ctx[21].call( + input3, + /*each_value_1*/ + ctx[36], + /*index*/ + ctx[35] + ); + } + __name(input3_change_handler, "input3_change_handler"); + function input4_input_handler() { + ctx[22].call( + input4, + /*each_value_1*/ + ctx[36], + /*index*/ + ctx[35] + ); + } + __name(input4_input_handler, "input4_input_handler"); + function filepicker_value_binding(value) { + ctx[23]( + value, + /*price*/ + ctx[33] + ); + } + __name(filepicker_value_binding, "filepicker_value_binding"); + let filepicker_props = { + type: "imagevideo", + showImage: true, + showInput: false + }; + if ( + /*price*/ + ctx[33].img !== void 0 + ) { + filepicker_props.value = /*price*/ + ctx[33].img; + } + filepicker = new FilePicker_1({ props: filepicker_props }); + binding_callbacks.push(() => bind(filepicker, "value", filepicker_value_binding)); + function select_block_type(ctx2, dirty) { + if ( + /*price*/ + ctx2[33].type === "attribute" + ) + return create_if_block_1$6; + return create_else_block$5; + } + __name(select_block_type, "select_block_type"); + let current_block_type = select_block_type(ctx); + let if_block = current_block_type(ctx); + function click_handler_2() { + return ( + /*click_handler_2*/ + ctx[26]( + /*index*/ + ctx[35] + ) + ); + } + __name(click_handler_2, "click_handler_2"); + return { + key: key_1, + first: null, + c() { + div9 = element("div"); + div0 = element("div"); + i0 = element("i"); + t0 = space(); + div1 = element("div"); + input0 = element("input"); + t1 = space(); + div2 = element("div"); + input1 = element("input"); + t2 = space(); + div3 = element("div"); + input2 = element("input"); + t3 = space(); + div4 = element("div"); + input3 = element("input"); + t4 = space(); + div5 = element("div"); + input4 = element("input"); + t5 = space(); + div6 = element("div"); + create_component(filepicker.$$.fragment); + t6 = space(); + div7 = element("div"); + if_block.c(); + t7 = space(); + div8 = element("div"); + button = element("button"); + button.innerHTML = ``; + attr(i0, "class", "fas fa-bars"); + attr(div0, "tabindex", div0_tabindex_value = /*dragDisabled*/ + ctx[4] ? 0 : -1); + attr(div0, "aria-label", "drag-handle"); + attr(div0, "style", div0_style_value = /*dragDisabled*/ + ctx[4] ? "cursor: grab" : "cursor: grabbing"); + attr(input0, "type", "text"); + attr(input1, "type", "number"); + attr(input2, "type", "checkbox"); + attr(input2, "min", "0"); + attr(input2, "max", input2_max_value = /*price*/ + ctx[33].percent ? 100 : 1e15); + attr(input3, "type", "checkbox"); + attr(input4, "type", "text"); + attr(button, "type", "button"); + attr(div9, "class", "item-piles-sortable-list-columns item-piles-sortable-list-entry item-piles-even-color svelte-1c30usg"); + this.first = div9; + }, + m(target, anchor) { + insert(target, div9, anchor); + append(div9, div0); + append(div0, i0); + append(div9, t0); + append(div9, div1); + append(div1, input0); + set_input_value( + input0, + /*price*/ + ctx[33].name + ); + append(div9, t1); + append(div9, div2); + append(div2, input1); + set_input_value( + input1, + /*price*/ + ctx[33].quantity + ); + append(div9, t2); + append(div9, div3); + append(div3, input2); + input2.checked = /*price*/ + ctx[33].fixed; + append(div9, t3); + append(div9, div4); + append(div4, input3); + input3.checked = /*price*/ + ctx[33].percent; + append(div9, t4); + append(div9, div5); + append(div5, input4); + set_input_value( + input4, + /*price*/ + ctx[33].abbreviation + ); + append(div9, t5); + append(div9, div6); + mount_component(filepicker, div6, null); + append(div9, t6); + append(div9, div7); + if_block.m(div7, null); + append(div9, t7); + append(div9, div8); + append(div8, button); + current = true; + if (!mounted) { + dispose = [ + listen( + div0, + "mousedown", + /*startDrag*/ + ctx[14] + ), + listen( + div0, + "touchstart", + /*startDrag*/ + ctx[14] + ), + listen( + div0, + "keydown", + /*handleKeyDown*/ + ctx[15] + ), + listen(input0, "input", input0_input_handler), + listen(input1, "input", input1_input_handler), + listen(input2, "change", input2_change_handler), + listen(input3, "change", input3_change_handler), + listen(input4, "input", input4_input_handler), + listen(button, "click", click_handler_2) + ]; + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (!current || dirty[0] & /*dragDisabled*/ + 16 && div0_tabindex_value !== (div0_tabindex_value = /*dragDisabled*/ + ctx[4] ? 0 : -1)) { + attr(div0, "tabindex", div0_tabindex_value); + } + if (!current || dirty[0] & /*dragDisabled*/ + 16 && div0_style_value !== (div0_style_value = /*dragDisabled*/ + ctx[4] ? "cursor: grab" : "cursor: grabbing")) { + attr(div0, "style", div0_style_value); + } + if (dirty[0] & /*prices*/ + 1 && input0.value !== /*price*/ + ctx[33].name) { + set_input_value( + input0, + /*price*/ + ctx[33].name + ); + } + if (dirty[0] & /*prices*/ + 1 && to_number(input1.value) !== /*price*/ + ctx[33].quantity) { + set_input_value( + input1, + /*price*/ + ctx[33].quantity + ); + } + if (!current || dirty[0] & /*prices*/ + 1 && input2_max_value !== (input2_max_value = /*price*/ + ctx[33].percent ? 100 : 1e15)) { + attr(input2, "max", input2_max_value); + } + if (dirty[0] & /*prices*/ + 1) { + input2.checked = /*price*/ + ctx[33].fixed; + } + if (dirty[0] & /*prices*/ + 1) { + input3.checked = /*price*/ + ctx[33].percent; + } + if (dirty[0] & /*prices*/ + 1 && input4.value !== /*price*/ + ctx[33].abbreviation) { + set_input_value( + input4, + /*price*/ + ctx[33].abbreviation + ); + } + const filepicker_changes = {}; + if (!updating_value && dirty[0] & /*prices*/ + 1) { + updating_value = true; + filepicker_changes.value = /*price*/ + ctx[33].img; + add_flush_callback(() => updating_value = false); + } + filepicker.$set(filepicker_changes); + if (current_block_type === (current_block_type = select_block_type(ctx)) && if_block) { + if_block.p(ctx, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx); + if (if_block) { + if_block.c(); + if_block.m(div7, null); + } + } + }, + r() { + rect = div9.getBoundingClientRect(); + }, + f() { + fix_position(div9); + stop_animation(); + }, + a() { + stop_animation(); + stop_animation = create_animation(div9, rect, flip, { duration: flipDurationMs }); + }, + i(local) { + if (current) + return; + transition_in(filepicker.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(filepicker.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(div9); + destroy_component(filepicker); + if_block.d(); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_each_block_1$2, "create_each_block_1$2"); +function create_if_block$9(ctx) { + let div; + let span; + let t1; + let select; + let option; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let mounted; + let dispose; + let each_value = ( + /*presetPrices*/ + ctx[6] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*index*/ + ctx2[35] + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$6(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$6(key, child_ctx)); + } + return { + c() { + div = element("div"); + span = element("span"); + span.textContent = `${localize("ITEM-PILES.Applications.ItemEditor.PricePreset")}`; + t1 = space(); + select = element("select"); + option = element("option"); + option.textContent = `${localize("ITEM-PILES.Applications.ItemEditor.SelectPreset")}`; + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + set_style(span, "margin-right", "0.25rem"); + option.__value = ""; + option.value = option.__value; + attr(select, "class", "price-preset-selector svelte-1c30usg"); + if ( + /*selectedPreset*/ + ctx[5] === void 0 + ) + add_render_callback(() => ( + /*select_change_handler*/ + ctx[28].call(select) + )); + attr(div, "class", "full-span svelte-1c30usg"); + set_style(div, "margin-top", "0.5rem"); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, span); + append(div, t1); + append(div, select); + append(select, option); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(select, null); + } + } + select_option( + select, + /*selectedPreset*/ + ctx[5], + true + ); + if (!mounted) { + dispose = [ + listen( + select, + "change", + /*select_change_handler*/ + ctx[28] + ), + listen( + select, + "change", + /*change_handler*/ + ctx[29] + ) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty[0] & /*presetPrices*/ + 64) { + each_value = /*presetPrices*/ + ctx2[6]; + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, select, destroy_block, create_each_block$6, null, get_each_context$6); + } + if (dirty[0] & /*selectedPreset, presetPrices*/ + 96) { + select_option( + select, + /*selectedPreset*/ + ctx2[5] + ); + } + }, + d(detaching) { + if (detaching) + detach(div); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + mounted = false; + run_all(dispose); + } + }; +} +__name(create_if_block$9, "create_if_block$9"); +function create_each_block$6(key_1, ctx) { + let option; + let t_value = ( + /*price*/ + ctx[33].name + "" + ); + let t; + return { + key: key_1, + first: null, + c() { + option = element("option"); + t = text(t_value); + option.__value = /*index*/ + ctx[35]; + option.value = option.__value; + this.first = option; + }, + m(target, anchor) { + insert(target, option, anchor); + append(option, t); + }, + p(new_ctx, dirty) { + ctx = new_ctx; + }, + d(detaching) { + if (detaching) + detach(option); + } + }; +} +__name(create_each_block$6, "create_each_block$6"); +function create_default_slot$8(ctx) { + let div12; + let div9; + let div0; + let t0; + let div1; + let t2; + let div2; + let t4; + let div3; + let t6; + let div4; + let t8; + let div5; + let t10; + let div6; + let t12; + let div7; + let t14; + let div8; + let t15; + let section; + let t16; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let t17; + let div11; + let div10; + let a; + let t19; + let dndzone_action; + let current; + let mounted; + let dispose; + let if_block0 = ( + /*remove*/ + ctx[1] && create_if_block_3$3(ctx) + ); + let if_block1 = ( + /*isHovering*/ + ctx[3] && create_if_block_2$3() + ); + let each_value_1 = ( + /*prices*/ + ctx[0] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*price*/ + ctx2[33].id + ), "get_key"); + for (let i = 0; i < each_value_1.length; i += 1) { + let child_ctx = get_each_context_1$2(ctx, each_value_1, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block_1$2(key, child_ctx)); + } + let if_block2 = ( + /*presetPrices*/ + ctx[6].length && /*presets*/ + ctx[2] && create_if_block$9(ctx) + ); + return { + c() { + div12 = element("div"); + div9 = element("div"); + div0 = element("div"); + t0 = space(); + div1 = element("div"); + div1.textContent = "Name"; + t2 = space(); + div2 = element("div"); + div2.textContent = "Cost"; + t4 = space(); + div3 = element("div"); + div3.textContent = "Fixed"; + t6 = space(); + div4 = element("div"); + div4.textContent = "%"; + t8 = space(); + div5 = element("div"); + div5.textContent = "Short"; + t10 = space(); + div6 = element("div"); + div6.textContent = "Icon"; + t12 = space(); + div7 = element("div"); + div7.textContent = "Data"; + t14 = space(); + div8 = element("div"); + if (if_block0) + if_block0.c(); + t15 = space(); + section = element("section"); + if (if_block1) + if_block1.c(); + t16 = space(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + t17 = space(); + div11 = element("div"); + div10 = element("div"); + a = element("a"); + a.textContent = `${localize("ITEM-PILES.Applications.ItemEditor.DropMeClickMe")}`; + t19 = space(); + if (if_block2) + if_block2.c(); + attr(div9, "class", "item-piles-sortable-list-columns header svelte-1c30usg"); + attr(a, "class", "svelte-1c30usg"); + toggle_class( + a, + "invisible", + /*isHovering*/ + ctx[3] + ); + attr(div10, "class", "full-span svelte-1c30usg"); + attr(div11, "class", "item-piles-sortable-list-columns svelte-1c30usg"); + set_style(div11, "margin-top", "0.5rem"); + attr(div12, "class", "table-container item-piles-top-divider svelte-1c30usg"); + }, + m(target, anchor) { + insert(target, div12, anchor); + append(div12, div9); + append(div9, div0); + append(div9, t0); + append(div9, div1); + append(div9, t2); + append(div9, div2); + append(div9, t4); + append(div9, div3); + append(div9, t6); + append(div9, div4); + append(div9, t8); + append(div9, div5); + append(div9, t10); + append(div9, div6); + append(div9, t12); + append(div9, div7); + append(div9, t14); + append(div9, div8); + if (if_block0) + if_block0.m(div8, null); + append(div12, t15); + append(div12, section); + if (if_block1) + if_block1.m(section, null); + append(section, t16); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(section, null); + } + } + append(section, t17); + append(section, div11); + append(div11, div10); + append(div10, a); + append(div11, t19); + if (if_block2) + if_block2.m(div11, null); + current = true; + if (!mounted) { + dispose = [ + listen( + a, + "click", + /*click_handler_3*/ + ctx[27] + ), + listen( + section, + "consider", + /*handleConsider*/ + ctx[12] + ), + listen( + section, + "finalize", + /*handleFinalize*/ + ctx[13] + ), + action_destroyer(dndzone_action = dndzone.call(null, section, { + items: ( + /*prices*/ + ctx[0] + ), + dragDisabled: ( + /*dragDisabled*/ + ctx[4] + ), + flipDurationMs + })) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if ( + /*remove*/ + ctx2[1] + ) { + if (if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0 = create_if_block_3$3(ctx2); + if_block0.c(); + if_block0.m(div8, null); + } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; + } + if ( + /*isHovering*/ + ctx2[3] + ) { + if (if_block1) + ; + else { + if_block1 = create_if_block_2$3(); + if_block1.c(); + if_block1.m(section, t16); + } + } else if (if_block1) { + if_block1.d(1); + if_block1 = null; + } + if (dirty[0] & /*removeEntry, prices, editItem, dragDisabled, startDrag, handleKeyDown*/ + 51345) { + each_value_1 = /*prices*/ + ctx2[0]; + group_outros(); + for (let i = 0; i < each_blocks.length; i += 1) + each_blocks[i].r(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value_1, each_1_lookup, section, fix_and_outro_and_destroy_block, create_each_block_1$2, t17, get_each_context_1$2); + for (let i = 0; i < each_blocks.length; i += 1) + each_blocks[i].a(); + check_outros(); + } + if (!current || dirty[0] & /*isHovering*/ + 8) { + toggle_class( + a, + "invisible", + /*isHovering*/ + ctx2[3] + ); + } + if ( + /*presetPrices*/ + ctx2[6].length && /*presets*/ + ctx2[2] + ) { + if (if_block2) { + if_block2.p(ctx2, dirty); + } else { + if_block2 = create_if_block$9(ctx2); + if_block2.c(); + if_block2.m(div11, null); + } + } else if (if_block2) { + if_block2.d(1); + if_block2 = null; + } + if (dndzone_action && is_function(dndzone_action.update) && dirty[0] & /*prices, dragDisabled*/ + 17) + dndzone_action.update.call(null, { + items: ( + /*prices*/ + ctx2[0] + ), + dragDisabled: ( + /*dragDisabled*/ + ctx2[4] + ), + flipDurationMs + }); + }, + i(local) { + if (current) + return; + for (let i = 0; i < each_value_1.length; i += 1) { + transition_in(each_blocks[i]); + } + current = true; + }, + o(local) { + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + current = false; + }, + d(detaching) { + if (detaching) + detach(div12); + if (if_block0) + if_block0.d(); + if (if_block1) + if_block1.d(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + if (if_block2) + if_block2.d(); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$8, "create_default_slot$8"); +function create_fragment$c(ctx) { + let dropzone; + let updating_isHovering; + let current; + function dropzone_isHovering_binding(value) { + ctx[30](value); + } + __name(dropzone_isHovering_binding, "dropzone_isHovering_binding"); + let dropzone_props = { + callback: ( + /*dropData*/ + ctx[10] + ), + $$slots: { default: [create_default_slot$8] }, + $$scope: { ctx } + }; + if ( + /*isHovering*/ + ctx[3] !== void 0 + ) { + dropzone_props.isHovering = /*isHovering*/ + ctx[3]; + } + dropzone = new DropZone({ props: dropzone_props }); + binding_callbacks.push(() => bind(dropzone, "isHovering", dropzone_isHovering_binding)); + return { + c() { + create_component(dropzone.$$.fragment); + }, + m(target, anchor) { + mount_component(dropzone, target, anchor); + current = true; + }, + p(ctx2, dirty) { + const dropzone_changes = {}; + if (dirty[0] & /*prices, dragDisabled, selectedPreset, presets, isHovering, remove*/ + 63 | dirty[1] & /*$$scope*/ + 64) { + dropzone_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_isHovering && dirty[0] & /*isHovering*/ + 8) { + updating_isHovering = true; + dropzone_changes.isHovering = /*isHovering*/ + ctx2[3]; + add_flush_callback(() => updating_isHovering = false); + } + dropzone.$set(dropzone_changes); + }, + i(local) { + if (current) + return; + transition_in(dropzone.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(dropzone.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(dropzone, detaching); + } + }; +} +__name(create_fragment$c, "create_fragment$c"); +let flipDurationMs = 200; +function instance$c($$self, $$props, $$invalidate) { + let { prices } = $$props; + let { item } = $$props; + let { remove = false } = $$props; + let { presets = true } = $$props; + let currencies = getSetting(SETTINGS$1.CURRENCIES); + let secondaryCurrencies = getSetting(SETTINGS$1.SECONDARY_CURRENCIES); + if (item?.parent) { + const flags = getActorFlagData(item?.parent); + if (flags.overrideCurrencies) { + currencies = flags.overrideCurrencies; + } + if (flags.overrideSecondaryCurrencies) { + secondaryCurrencies = flags.overrideSecondaryCurrencies; + } + } + let presetPrices = currencies.concat(secondaryCurrencies).map((currency) => { + return { + id: randomID(), + quantity: 1, + fixed: true, + percent: false, + ...currency + }; + }).concat(getSetting(SETTINGS$1.PRICE_PRESETS)); + let isHovering = false; + let dragDisabled = true; + let selectedPreset = ""; + function removeEntry(index2) { + prices.splice(index2, 1); + $$invalidate(0, prices); + } + __name(removeEntry, "removeEntry"); + function addAttribute() { + $$invalidate(0, prices = [ + ...prices, + { + id: randomID(), + type: "attribute", + name: "New Attribute", + img: "", + abbreviation: "{#}N", + data: { path: "" }, + quantity: 1, + fixed: true, + percent: false + } + ]); + } + __name(addAttribute, "addAttribute"); + function addPreset(index2) { + const preset = foundry.utils.duplicate(presetPrices[index2]); + preset.id = randomID(); + $$invalidate(0, prices = [...prices, preset]); + } + __name(addPreset, "addPreset"); + async function dropData(data2) { + if (!data2.type) { + throw custom_error("Something went wrong when dropping this item!"); + } + if (data2.type !== "Item") { + throw custom_error("You must drop an item, not " + data2.type.toLowerCase() + "!"); + } + let uuid = false; + if (data2.pack) { + uuid = "Compendium" + data2.pack + "." + data2.id; + } + let item2 = await Item.implementation.fromDropData(data2); + let itemData = item2.toObject(); + if (!itemData) { + console.error(data2); + throw custom_error("Something went wrong when dropping this item!"); + } + const itemCurrencies = prices.map((entry) => entry.data?.item ?? {}); + const foundItem = findSimilarItem(itemCurrencies, itemData); + if (!uuid) { + uuid = (await findOrCreateItemInCompendium(itemData)).uuid; + } + if (foundItem) { + const index2 = itemCurrencies.indexOf(foundItem); + $$invalidate(0, prices[index2].data = { uuid }, prices); + custom_notify(`Updated item data for ${localize(prices[index2].name)} (item name ${itemData.name})`); + } else { + $$invalidate(0, prices = [ + ...prices, + { + id: randomID(), + type: "item", + name: itemData.name, + img: itemData.img, + abbreviation: "{#} " + itemData.name, + data: { uuid }, + quantity: 1, + fixed: true, + percent: false + } + ]); + } + } + __name(dropData, "dropData"); + async function editItem(index2) { + const data2 = prices[index2].data; + let item2 = await fromUuid(data2.uuid); + item2.sheet.render(true); + } + __name(editItem, "editItem"); + function handleConsider(e) { + const { items: newItems, info: { source, trigger } } = e.detail; + $$invalidate(0, prices = newItems); + if (source === SOURCES.KEYBOARD && trigger === TRIGGERS.DRAG_STOPPED) { + $$invalidate(4, dragDisabled = true); + } + } + __name(handleConsider, "handleConsider"); + function handleFinalize(e) { + const { items: newItems, info: { source } } = e.detail; + $$invalidate(0, prices = newItems); + if (source === SOURCES.POINTER) { + $$invalidate(4, dragDisabled = true); + } + } + __name(handleFinalize, "handleFinalize"); + function startDrag(e) { + e.preventDefault(); + $$invalidate(4, dragDisabled = false); + } + __name(startDrag, "startDrag"); + function handleKeyDown(e) { + if ((e.key === "Enter" || e.key === " ") && dragDisabled) + $$invalidate(4, dragDisabled = false); + } + __name(handleKeyDown, "handleKeyDown"); + const click_handler = /* @__PURE__ */ __name(() => remove(), "click_handler"); + function input0_input_handler(each_value_1, index2) { + each_value_1[index2].name = this.value; + $$invalidate(0, prices); + } + __name(input0_input_handler, "input0_input_handler"); + function input1_input_handler(each_value_1, index2) { + each_value_1[index2].quantity = to_number(this.value); + $$invalidate(0, prices); + } + __name(input1_input_handler, "input1_input_handler"); + function input2_change_handler(each_value_1, index2) { + each_value_1[index2].fixed = this.checked; + $$invalidate(0, prices); + } + __name(input2_change_handler, "input2_change_handler"); + function input3_change_handler(each_value_1, index2) { + each_value_1[index2].percent = this.checked; + $$invalidate(0, prices); + } + __name(input3_change_handler, "input3_change_handler"); + function input4_input_handler(each_value_1, index2) { + each_value_1[index2].abbreviation = this.value; + $$invalidate(0, prices); + } + __name(input4_input_handler, "input4_input_handler"); + function filepicker_value_binding(value, price) { + if ($$self.$$.not_equal(price.img, value)) { + price.img = value; + $$invalidate(0, prices); + } + } + __name(filepicker_value_binding, "filepicker_value_binding"); + function input_input_handler(each_value_1, index2) { + each_value_1[index2].data.path = this.value; + $$invalidate(0, prices); + } + __name(input_input_handler, "input_input_handler"); + const click_handler_1 = /* @__PURE__ */ __name((index2) => editItem(index2), "click_handler_1"); + const click_handler_2 = /* @__PURE__ */ __name((index2) => removeEntry(index2), "click_handler_2"); + const click_handler_32 = /* @__PURE__ */ __name(() => addAttribute(), "click_handler_3"); + function select_change_handler() { + selectedPreset = select_value(this); + $$invalidate(5, selectedPreset); + $$invalidate(6, presetPrices); + } + __name(select_change_handler, "select_change_handler"); + const change_handler = /* @__PURE__ */ __name(() => { + addPreset(selectedPreset); + $$invalidate(5, selectedPreset = ""); + }, "change_handler"); + function dropzone_isHovering_binding(value) { + isHovering = value; + $$invalidate(3, isHovering); + } + __name(dropzone_isHovering_binding, "dropzone_isHovering_binding"); + $$self.$$set = ($$props2) => { + if ("prices" in $$props2) + $$invalidate(0, prices = $$props2.prices); + if ("item" in $$props2) + $$invalidate(16, item = $$props2.item); + if ("remove" in $$props2) + $$invalidate(1, remove = $$props2.remove); + if ("presets" in $$props2) + $$invalidate(2, presets = $$props2.presets); + }; + return [ + prices, + remove, + presets, + isHovering, + dragDisabled, + selectedPreset, + presetPrices, + removeEntry, + addAttribute, + addPreset, + dropData, + editItem, + handleConsider, + handleFinalize, + startDrag, + handleKeyDown, + item, + click_handler, + input0_input_handler, + input1_input_handler, + input2_change_handler, + input3_change_handler, + input4_input_handler, + filepicker_value_binding, + input_input_handler, + click_handler_1, + click_handler_2, + click_handler_32, + select_change_handler, + change_handler, + dropzone_isHovering_binding + ]; +} +__name(instance$c, "instance$c"); +class PriceList extends SvelteComponent { + constructor(options) { + super(); + init( + this, + options, + instance$c, + create_fragment$c, + safe_not_equal, + { + prices: 0, + item: 16, + remove: 1, + presets: 2 + }, + null, + [-1, -1] + ); + } +} +__name(PriceList, "PriceList"); +const pricePresetEditorShell_svelte_svelte_type_style_lang = ""; +function create_default_slot$7(ctx) { + let form_1; + let p; + let t1; + let pricelist; + let updating_prices; + let t2; + let footer; + let button0; + let i0; + let t3; + let t4_value = localize("ITEM-PILES.Applications.PricePresetEditor.Update") + ""; + let t4; + let t5; + let button1; + let i1; + let t6; + let t7_value = localize("Cancel") + ""; + let t7; + let current; + let mounted; + let dispose; + function pricelist_prices_binding(value) { + ctx[7](value); + } + __name(pricelist_prices_binding, "pricelist_prices_binding"); + let pricelist_props = { presets: false }; + if ( + /*prices*/ + ctx[3] !== void 0 + ) { + pricelist_props.prices = /*prices*/ + ctx[3]; + } + pricelist = new PriceList({ props: pricelist_props }); + binding_callbacks.push(() => bind(pricelist, "prices", pricelist_prices_binding)); + return { + c() { + form_1 = element("form"); + p = element("p"); + p.textContent = `${localize("ITEM-PILES.Applications.PricePresetEditor.Explanation")}`; + t1 = space(); + create_component(pricelist.$$.fragment); + t2 = space(); + footer = element("footer"); + button0 = element("button"); + i0 = element("i"); + t3 = space(); + t4 = text(t4_value); + t5 = space(); + button1 = element("button"); + i1 = element("i"); + t6 = space(); + t7 = text(t7_value); + attr(p, "class", "svelte-1vdoydt"); + attr(i0, "class", "far fa-save"); + attr(button0, "type", "button"); + attr(i1, "class", "far fa-times"); + attr(button1, "type", "button"); + attr(form_1, "autocomplete", "off"); + attr(form_1, "class", "item-piles-config-container"); + }, + m(target, anchor) { + insert(target, form_1, anchor); + append(form_1, p); + append(form_1, t1); + mount_component(pricelist, form_1, null); + append(form_1, t2); + append(form_1, footer); + append(footer, button0); + append(button0, i0); + append(button0, t3); + append(button0, t4); + append(footer, t5); + append(footer, button1); + append(button1, i1); + append(button1, t6); + append(button1, t7); + ctx[9](form_1); + current = true; + if (!mounted) { + dispose = [ + listen( + button0, + "click", + /*requestSubmit*/ + ctx[1], + { once: true } + ), + listen( + button1, + "click", + /*click_handler*/ + ctx[8], + { once: true } + ), + listen(form_1, "submit", prevent_default( + /*updateSettings*/ + ctx[5] + )) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + const pricelist_changes = {}; + if (!updating_prices && dirty & /*prices*/ + 8) { + updating_prices = true; + pricelist_changes.prices = /*prices*/ + ctx2[3]; + add_flush_callback(() => updating_prices = false); + } + pricelist.$set(pricelist_changes); + }, + i(local) { + if (current) + return; + transition_in(pricelist.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(pricelist.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(form_1); + destroy_component(pricelist); + ctx[9](null); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$7, "create_default_slot$7"); +function create_fragment$b(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[10](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot$7] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, [dirty]) { + const applicationshell_changes = {}; + if (dirty & /*$$scope, form, prices*/ + 2060) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment$b, "create_fragment$b"); +function instance$b($$self, $$props, $$invalidate) { + const { application } = getContext("#external"); + let { data: data2 } = $$props; + let { elementRoot } = $$props; + let form; + let prices = foundry.utils.deepClone(data2); + async function updateSettings() { + application.options.resolve(prices); + application.close(); + } + __name(updateSettings, "updateSettings"); + function requestSubmit() { + form.requestSubmit(); + } + __name(requestSubmit, "requestSubmit"); + function pricelist_prices_binding(value) { + prices = value; + $$invalidate(3, prices); + } + __name(pricelist_prices_binding, "pricelist_prices_binding"); + const click_handler = /* @__PURE__ */ __name(() => { + application.close(); + }, "click_handler"); + function form_1_binding($$value) { + binding_callbacks[$$value ? "unshift" : "push"](() => { + form = $$value; + $$invalidate(2, form); + }); + } + __name(form_1_binding, "form_1_binding"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("data" in $$props2) + $$invalidate(6, data2 = $$props2.data); + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + }; + return [ + elementRoot, + requestSubmit, + form, + prices, + application, + updateSettings, + data2, + pricelist_prices_binding, + click_handler, + form_1_binding, + applicationshell_elementRoot_binding + ]; +} +__name(instance$b, "instance$b"); +class Price_preset_editor_shell extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$b, create_fragment$b, safe_not_equal, { + data: 6, + elementRoot: 0, + requestSubmit: 1 + }); + } + get data() { + return this.$$.ctx[6]; + } + set data(data2) { + this.$$set({ data: data2 }); + flush(); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } + get requestSubmit() { + return this.$$.ctx[1]; + } +} +__name(Price_preset_editor_shell, "Price_preset_editor_shell"); +class PricePresetEditor extends Editor { + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + id: `item-pile-price-preset-editor-${randomID()}`, + title: game.i18n.format("ITEM-PILES.Applications.PricePresetEditor.Title"), + width: 500, + svelte: { + class: Price_preset_editor_shell + } + }); + } +} +__name(PricePresetEditor, "PricePresetEditor"); +const unstackableItemTypesEditor_svelte_svelte_type_style_lang = ""; +function get_each_context$5(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[17] = list[i]; + child_ctx[18] = list; + child_ctx[19] = i; + return child_ctx; +} +__name(get_each_context$5, "get_each_context$5"); +function get_each_context_1$1(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[20] = list[i]; + return child_ctx; +} +__name(get_each_context_1$1, "get_each_context_1$1"); +function create_each_block_1$1(ctx) { + let option; + let t0_value = ( + /*systemType*/ + ctx[20] + "" + ); + let t0; + let t1; + let option_disabled_value; + return { + c() { + option = element("option"); + t0 = text(t0_value); + t1 = space(); + option.__value = /*systemType*/ + ctx[20]; + option.value = option.__value; + option.disabled = option_disabled_value = /*systemType*/ + ctx[20] !== /*type*/ + ctx[17] && !/*unusedTypes*/ + ctx[4].includes( + /*systemType*/ + ctx[20] + ); + }, + m(target, anchor) { + insert(target, option, anchor); + append(option, t0); + append(option, t1); + }, + p(ctx2, dirty) { + if (dirty & /*$unstackableItemTypesStore, unusedTypes, systemTypes*/ + 148 && option_disabled_value !== (option_disabled_value = /*systemType*/ + ctx2[20] !== /*type*/ + ctx2[17] && !/*unusedTypes*/ + ctx2[4].includes( + /*systemType*/ + ctx2[20] + ))) { + option.disabled = option_disabled_value; + } + }, + d(detaching) { + if (detaching) + detach(option); + } + }; +} +__name(create_each_block_1$1, "create_each_block_1$1"); +function create_each_block$5(key_1, ctx) { + let tr; + let td0; + let select; + let t0; + let td1; + let button; + let t1; + let mounted; + let dispose; + let each_value_1 = ( + /*systemTypes*/ + ctx[7] + ); + let each_blocks = []; + for (let i = 0; i < each_value_1.length; i += 1) { + each_blocks[i] = create_each_block_1$1(get_each_context_1$1(ctx, each_value_1, i)); + } + function select_change_handler() { + ctx[12].call( + select, + /*each_value*/ + ctx[18], + /*index*/ + ctx[19] + ); + } + __name(select_change_handler, "select_change_handler"); + return { + key: key_1, + first: null, + c() { + tr = element("tr"); + td0 = element("td"); + select = element("select"); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + t0 = space(); + td1 = element("td"); + button = element("button"); + button.innerHTML = ``; + t1 = space(); + attr(select, "class", "svelte-1m1c0js"); + if ( + /*type*/ + ctx[17] === void 0 + ) + add_render_callback(select_change_handler); + attr(button, "type", "button"); + attr(button, "class", "svelte-1m1c0js"); + attr(td1, "class", "small svelte-1m1c0js"); + attr(tr, "class", "svelte-1m1c0js"); + this.first = tr; + }, + m(target, anchor) { + insert(target, tr, anchor); + append(tr, td0); + append(td0, select); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(select, null); + } + } + select_option( + select, + /*type*/ + ctx[17], + true + ); + append(tr, t0); + append(tr, td1); + append(td1, button); + append(tr, t1); + if (!mounted) { + dispose = [ + listen(select, "change", select_change_handler), + listen(button, "click", function() { + if (is_function( + /*remove*/ + ctx[9]( + /*index*/ + ctx[19] + ) + )) + ctx[9]( + /*index*/ + ctx[19] + ).apply(this, arguments); + }) + ]; + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty & /*systemTypes, $unstackableItemTypesStore, unusedTypes*/ + 148) { + each_value_1 = /*systemTypes*/ + ctx[7]; + let i; + for (i = 0; i < each_value_1.length; i += 1) { + const child_ctx = get_each_context_1$1(ctx, each_value_1, i); + if (each_blocks[i]) { + each_blocks[i].p(child_ctx, dirty); + } else { + each_blocks[i] = create_each_block_1$1(child_ctx); + each_blocks[i].c(); + each_blocks[i].m(select, null); + } + } + for (; i < each_blocks.length; i += 1) { + each_blocks[i].d(1); + } + each_blocks.length = each_value_1.length; + } + if (dirty & /*$unstackableItemTypesStore, systemTypes*/ + 132) { + select_option( + select, + /*type*/ + ctx[17] + ); + } + }, + d(detaching) { + if (detaching) + detach(tr); + destroy_each(each_blocks, detaching); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_each_block$5, "create_each_block$5"); +function create_default_slot$6(ctx) { + let form_1; + let p; + let t1; + let table; + let tr; + let th0; + let t3; + let th1; + let a; + let t4; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let t5; + let footer; + let button0; + let i1; + let t6; + let t7_value = localize("Save") + ""; + let t7; + let t8; + let button1; + let i2; + let t9; + let t10_value = localize("Cancel") + ""; + let t10; + let mounted; + let dispose; + let each_value = ( + /*$unstackableItemTypesStore*/ + ctx[2] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*index*/ + ctx2[19] + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$5(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$5(key, child_ctx)); + } + return { + c() { + form_1 = element("form"); + p = element("p"); + p.textContent = `${localize("ITEM-PILES.Applications.UnstackableItemTypesEditor.Explanation")}`; + t1 = space(); + table = element("table"); + tr = element("tr"); + th0 = element("th"); + th0.textContent = `${localize("ITEM-PILES.Applications.UnstackableItemTypesEditor.Type")}`; + t3 = space(); + th1 = element("th"); + a = element("a"); + a.innerHTML = ``; + t4 = space(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + t5 = space(); + footer = element("footer"); + button0 = element("button"); + i1 = element("i"); + t6 = space(); + t7 = text(t7_value); + t8 = space(); + button1 = element("button"); + i2 = element("i"); + t9 = space(); + t10 = text(t10_value); + attr(a, "class", "item-piles-clickable svelte-1m1c0js"); + attr(th1, "class", "small svelte-1m1c0js"); + attr(tr, "class", "svelte-1m1c0js"); + attr(table, "class", "svelte-1m1c0js"); + attr(i1, "class", "far fa-save"); + attr(button0, "type", "button"); + attr(i2, "class", "far fa-times"); + attr(button1, "type", "button"); + attr(form_1, "autocomplete", "off"); + }, + m(target, anchor) { + insert(target, form_1, anchor); + append(form_1, p); + append(form_1, t1); + append(form_1, table); + append(table, tr); + append(tr, th0); + append(tr, t3); + append(tr, th1); + append(th1, a); + append(table, t4); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(table, null); + } + } + append(form_1, t5); + append(form_1, footer); + append(footer, button0); + append(button0, i1); + append(button0, t6); + append(button0, t7); + append(footer, t8); + append(footer, button1); + append(button1, i2); + append(button1, t9); + append(button1, t10); + ctx[14](form_1); + if (!mounted) { + dispose = [ + listen( + a, + "click", + /*add*/ + ctx[8] + ), + listen( + button0, + "click", + /*requestSubmit*/ + ctx[1], + { once: true } + ), + listen( + button1, + "click", + /*click_handler*/ + ctx[13], + { once: true } + ), + listen(form_1, "submit", prevent_default( + /*updateSettings*/ + ctx[10] + )) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*remove, $unstackableItemTypesStore, systemTypes, unusedTypes*/ + 660) { + each_value = /*$unstackableItemTypesStore*/ + ctx2[2]; + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, table, destroy_block, create_each_block$5, null, get_each_context$5); + } + }, + d(detaching) { + if (detaching) + detach(form_1); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + ctx[14](null); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$6, "create_default_slot$6"); +function create_fragment$a(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[15](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot$6] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, [dirty]) { + const applicationshell_changes = {}; + if (dirty & /*$$scope, form, $unstackableItemTypesStore, unusedTypes*/ + 8388636) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment$a, "create_fragment$a"); +function instance$a($$self, $$props, $$invalidate) { + let $unstackableItemTypesStore; + const { application } = getContext("#external"); + let form; + let { elementRoot } = $$props; + let { data: data2 } = $$props; + const itemFilters = (getSetting(SETTINGS$1.ITEM_FILTERS).find((filter) => filter.path === "type")?.filters ?? "").split(","); + const unstackableItemTypesStore = writable$1(data2); + component_subscribe($$self, unstackableItemTypesStore, (value) => $$invalidate(2, $unstackableItemTypesStore = value)); + let systemTypes = game.system.template.Item.types.filter((type) => !itemFilters.includes(type)); + let unusedTypes = []; + function add() { + if (!unusedTypes.length) + return; + unstackableItemTypesStore.update((arr) => { + arr.push(unusedTypes[0]); + return arr; + }); + } + __name(add, "add"); + function remove(index2) { + unstackableItemTypesStore.update((arr) => { + arr.splice(index2, 1); + return arr; + }); + } + __name(remove, "remove"); + async function updateSettings() { + application.options.resolve(get_store_value(unstackableItemTypesStore)); + application.close(); + } + __name(updateSettings, "updateSettings"); + function requestSubmit() { + form.requestSubmit(); + } + __name(requestSubmit, "requestSubmit"); + function select_change_handler(each_value, index2) { + each_value[index2] = select_value(this); + unstackableItemTypesStore.set($unstackableItemTypesStore); + $$invalidate(7, systemTypes); + } + __name(select_change_handler, "select_change_handler"); + const click_handler = /* @__PURE__ */ __name(() => { + application.close(); + }, "click_handler"); + function form_1_binding($$value) { + binding_callbacks[$$value ? "unshift" : "push"](() => { + form = $$value; + $$invalidate(3, form); + }); + } + __name(form_1_binding, "form_1_binding"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + if ("data" in $$props2) + $$invalidate(11, data2 = $$props2.data); + }; + $$self.$$.update = () => { + if ($$self.$$.dirty & /*$unstackableItemTypesStore*/ + 4) { + { + $$invalidate(4, unusedTypes = systemTypes.filter((systemType) => !$unstackableItemTypesStore.some((type) => type === systemType))); + } + } + }; + return [ + elementRoot, + requestSubmit, + $unstackableItemTypesStore, + form, + unusedTypes, + application, + unstackableItemTypesStore, + systemTypes, + add, + remove, + updateSettings, + data2, + select_change_handler, + click_handler, + form_1_binding, + applicationshell_elementRoot_binding + ]; +} +__name(instance$a, "instance$a"); +class Unstackable_item_types_editor extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$a, create_fragment$a, safe_not_equal, { + elementRoot: 0, + data: 11, + requestSubmit: 1 + }); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } + get data() { + return this.$$.ctx[11]; + } + set data(data2) { + this.$$set({ data: data2 }); + flush(); + } + get requestSubmit() { + return this.$$.ctx[1]; + } +} +__name(Unstackable_item_types_editor, "Unstackable_item_types_editor"); +class UnstackableItemTypesEditor extends Editor { + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + title: game.i18n.localize("ITEM-PILES.Applications.UnstackableItemTypesEditor.Title"), + width: 300, + svelte: { + class: Unstackable_item_types_editor + } + }); + } +} +__name(UnstackableItemTypesEditor, "UnstackableItemTypesEditor"); +function get_each_context$4(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[20] = list[i][0]; + child_ctx[21] = list[i][1]; + child_ctx[22] = list; + child_ctx[23] = i; + return child_ctx; +} +__name(get_each_context$4, "get_each_context$4"); +function create_if_block_1$5(ctx) { + let a; + let mounted; + let dispose; + return { + c() { + a = element("a"); + a.innerHTML = ``; + attr(a, "class", "item-piles-flexrow align-center-row item-piles-clickable-green"); + set_style(a, "text-align", "center"); + }, + m(target, anchor) { + insert(target, a, anchor); + if (!mounted) { + dispose = listen( + a, + "click", + /*click_handler*/ + ctx[11] + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(a); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_1$5, "create_if_block_1$5"); +function create_if_block$8(ctx) { + let a; + let mounted; + let dispose; + function click_handler_1() { + return ( + /*click_handler_1*/ + ctx[14]( + /*index*/ + ctx[23] + ) + ); + } + __name(click_handler_1, "click_handler_1"); + return { + c() { + a = element("a"); + a.innerHTML = ` + `; + attr(a, "class", "item-piles-flexrow align-center-row"); + set_style(a, "text-align", "center"); + }, + m(target, anchor) { + insert(target, a, anchor); + if (!mounted) { + dispose = listen(a, "click", click_handler_1); + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + }, + d(detaching) { + if (detaching) + detach(a); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block$8, "create_if_block$8"); +function create_each_block$4(key_1, ctx) { + let input0; + let t0; + let input1; + let t1; + let if_block_anchor; + let mounted; + let dispose; + function input0_input_handler() { + ctx[12].call( + input0, + /*each_value*/ + ctx[22], + /*index*/ + ctx[23] + ); + } + __name(input0_input_handler, "input0_input_handler"); + function input1_input_handler() { + ctx[13].call( + input1, + /*each_value*/ + ctx[22], + /*index*/ + ctx[23] + ); + } + __name(input1_input_handler, "input1_input_handler"); + let if_block = !/*options*/ + ctx[5].readOnly && create_if_block$8(ctx); + return { + key: key_1, + first: null, + c() { + input0 = element("input"); + t0 = space(); + input1 = element("input"); + t1 = space(); + if (if_block) + if_block.c(); + if_block_anchor = empty(); + input0.disabled = /*options*/ + ctx[5].readOnly; + attr(input0, "autocomplete", "false"); + attr(input0, "type", "text"); + attr(input1, "autocomplete", "false"); + attr(input1, "type", "text"); + this.first = input0; + }, + m(target, anchor) { + insert(target, input0, anchor); + set_input_value( + input0, + /*key*/ + ctx[20] + ); + insert(target, t0, anchor); + insert(target, input1, anchor); + set_input_value( + input1, + /*value*/ + ctx[21] + ); + insert(target, t1, anchor); + if (if_block) + if_block.m(target, anchor); + insert(target, if_block_anchor, anchor); + if (!mounted) { + dispose = [ + listen(input0, "input", input0_input_handler), + listen(input1, "input", input1_input_handler) + ]; + mounted = true; + } + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty & /*$values*/ + 4 && input0.value !== /*key*/ + ctx[20]) { + set_input_value( + input0, + /*key*/ + ctx[20] + ); + } + if (dirty & /*$values*/ + 4 && input1.value !== /*value*/ + ctx[21]) { + set_input_value( + input1, + /*value*/ + ctx[21] + ); + } + if (!/*options*/ + ctx[5].readOnly) + if_block.p(ctx, dirty); + }, + d(detaching) { + if (detaching) + detach(input0); + if (detaching) + detach(t0); + if (detaching) + detach(input1); + if (detaching) + detach(t1); + if (if_block) + if_block.d(detaching); + if (detaching) + detach(if_block_anchor); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_each_block$4, "create_each_block$4"); +function create_default_slot$5(ctx) { + let form_1; + let div; + let span0; + let t1; + let span1; + let t3; + let t4; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let t5; + let footer; + let button0; + let i0; + let t6; + let t7_value = localize("Save") + ""; + let t7; + let t8; + let button1; + let i1; + let t9; + let t10_value = localize("Cancel") + ""; + let t10; + let mounted; + let dispose; + let if_block = !/*options*/ + ctx[5].readOnly && create_if_block_1$5(ctx); + let each_value = ( + /*$values*/ + ctx[2] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*index*/ + ctx2[23] + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$4(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$4(key, child_ctx)); + } + return { + c() { + form_1 = element("form"); + div = element("div"); + span0 = element("span"); + span0.textContent = `${localize("ITEM-PILES.Applications.StylesEditor." + /*options*/ + (ctx[5].variables ? "Variable" : "Style"))}`; + t1 = space(); + span1 = element("span"); + span1.textContent = `${localize("ITEM-PILES.Applications.StylesEditor.Value")}`; + t3 = space(); + if (if_block) + if_block.c(); + t4 = space(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + t5 = space(); + footer = element("footer"); + button0 = element("button"); + i0 = element("i"); + t6 = space(); + t7 = text(t7_value); + t8 = space(); + button1 = element("button"); + i1 = element("i"); + t9 = space(); + t10 = text(t10_value); + attr(div, "class", "item-piles-bottom-divider"); + set_style(div, "display", "grid"); + set_style(div, "grid-template-columns", "1.25fr 2fr " + /*options*/ + (ctx[5].readOnly ? "" : "auto")); + set_style(div, "gap", "5px"); + attr(i0, "class", "far fa-save"); + attr(button0, "type", "button"); + attr(i1, "class", "far fa-times"); + attr(button1, "type", "button"); + attr(form_1, "autocomplete", "off"); + }, + m(target, anchor) { + insert(target, form_1, anchor); + append(form_1, div); + append(div, span0); + append(div, t1); + append(div, span1); + append(div, t3); + if (if_block) + if_block.m(div, null); + append(div, t4); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(div, null); + } + } + append(form_1, t5); + append(form_1, footer); + append(footer, button0); + append(button0, i0); + append(button0, t6); + append(button0, t7); + append(footer, t8); + append(footer, button1); + append(button1, i1); + append(button1, t9); + append(button1, t10); + ctx[16](form_1); + if (!mounted) { + dispose = [ + listen( + button0, + "click", + /*requestSubmit*/ + ctx[1], + { once: true } + ), + listen( + button1, + "click", + /*click_handler_2*/ + ctx[15], + { once: true } + ), + listen(form_1, "submit", prevent_default( + /*updateSettings*/ + ctx[9] + )) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (!/*options*/ + ctx2[5].readOnly) + if_block.p(ctx2, dirty); + if (dirty & /*remove, $values, options*/ + 292) { + each_value = /*$values*/ + ctx2[2]; + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, div, destroy_block, create_each_block$4, null, get_each_context$4); + } + }, + d(detaching) { + if (detaching) + detach(form_1); + if (if_block) + if_block.d(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + ctx[16](null); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$5, "create_default_slot$5"); +function create_fragment$9(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[17](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot$5] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, [dirty]) { + const applicationshell_changes = {}; + if (dirty & /*$$scope, form, $values*/ + 16777228) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment$9, "create_fragment$9"); +function instance$9($$self, $$props, $$invalidate) { + let $values; + const { application } = getContext("#external"); + let { data: data2 } = $$props; + let { elementRoot } = $$props; + let form; + const options = application.options; + const styleValues = data2?.subscribe ? data2 : writable$1(data2); + const styleStore = Object.entries(get_store_value(styleValues)); + let values = writable$1(styleStore.length ? styleStore : [["", ""]]); + component_subscribe($$self, values, (value) => $$invalidate(2, $values = value)); + function add() { + values.update((arr) => { + return [...arr, ["", ""]]; + }); + } + __name(add, "add"); + function remove(index2) { + values.update((arr) => { + arr.splice(index2, 1); + return arr; + }); + } + __name(remove, "remove"); + async function updateSettings() { + application.options.resolve(Object.fromEntries(get_store_value(values))); + application.close(); + } + __name(updateSettings, "updateSettings"); + function requestSubmit() { + form.requestSubmit(); + } + __name(requestSubmit, "requestSubmit"); + const click_handler = /* @__PURE__ */ __name(() => add(), "click_handler"); + function input0_input_handler(each_value, index2) { + each_value[index2][0] = this.value; + values.set($values); + } + __name(input0_input_handler, "input0_input_handler"); + function input1_input_handler(each_value, index2) { + each_value[index2][1] = this.value; + values.set($values); + } + __name(input1_input_handler, "input1_input_handler"); + const click_handler_1 = /* @__PURE__ */ __name((index2) => remove(index2), "click_handler_1"); + const click_handler_2 = /* @__PURE__ */ __name(() => { + application.options.resolve(null); + application.close(); + }, "click_handler_2"); + function form_1_binding($$value) { + binding_callbacks[$$value ? "unshift" : "push"](() => { + form = $$value; + $$invalidate(3, form); + }); + } + __name(form_1_binding, "form_1_binding"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("data" in $$props2) + $$invalidate(10, data2 = $$props2.data); + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + }; + $$self.$$.update = () => { + if ($$self.$$.dirty & /*$values*/ + 4) { + { + const data3 = Object.fromEntries($values.map((entry) => [entry[0].trim(), entry[1].trim()]).filter((entry) => entry[0].length && entry[1].length)); + styleValues.set(data3); + if (options.onchange) { + options.onchange(data3); + } + } + } + }; + return [ + elementRoot, + requestSubmit, + $values, + form, + application, + options, + values, + add, + remove, + updateSettings, + data2, + click_handler, + input0_input_handler, + input1_input_handler, + click_handler_1, + click_handler_2, + form_1_binding, + applicationshell_elementRoot_binding + ]; +} +__name(instance$9, "instance$9"); +class Styles_editor extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$9, create_fragment$9, safe_not_equal, { + data: 10, + elementRoot: 0, + requestSubmit: 1 + }); + } + get data() { + return this.$$.ctx[10]; + } + set data(data2) { + this.$$set({ data: data2 }); + flush(); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } + get requestSubmit() { + return this.$$.ctx[1]; + } +} +__name(Styles_editor, "Styles_editor"); +class StylesEditor extends Editor { + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + title: game.i18n.localize("ITEM-PILES.Applications.StylesEditor.Title"), + svelte: { + class: Styles_editor + } + }); + } +} +__name(StylesEditor, "StylesEditor"); +const StyleEntry_svelte_svelte_type_style_lang = ""; +function create_if_block$7(ctx) { + let img; + let img_src_value; + return { + c() { + img = element("img"); + attr(img, "class", "item-piles-item-image-example svelte-5lct34"); + if (!src_url_equal(img.src, img_src_value = /*image*/ + ctx[2])) + attr(img, "src", img_src_value); + }, + m(target, anchor) { + insert(target, img, anchor); + }, + p(ctx2, dirty) { + if (dirty & /*image*/ + 4 && !src_url_equal(img.src, img_src_value = /*image*/ + ctx2[2])) { + attr(img, "src", img_src_value); + } + }, + d(detaching) { + if (detaching) + detach(img); + } + }; +} +__name(create_if_block$7, "create_if_block$7"); +function create_fragment$8(ctx) { + let div0; + let input0; + let t0; + let div1; + let input1; + let t1; + let div3; + let t2; + let div2; + let div2_style_value; + let t3; + let div4; + let a0; + let t4; + let div5; + let a1; + let mounted; + let dispose; + let if_block = ( + /*image*/ + ctx[2] && create_if_block$7(ctx) + ); + return { + c() { + div0 = element("div"); + input0 = element("input"); + t0 = space(); + div1 = element("div"); + input1 = element("input"); + t1 = space(); + div3 = element("div"); + if (if_block) + if_block.c(); + t2 = space(); + div2 = element("div"); + t3 = space(); + div4 = element("div"); + a0 = element("a"); + a0.innerHTML = ``; + t4 = space(); + div5 = element("div"); + a1 = element("a"); + a1.innerHTML = ``; + attr(input0, "placeholder", "system.rarity"); + input0.required = true; + attr(input0, "type", "text"); + attr(div0, "class", "svelte-5lct34"); + attr(input1, "placeholder", "rare"); + input1.required = true; + attr(input1, "type", "text"); + attr(div1, "class", "svelte-5lct34"); + attr(div2, "class", "img-div svelte-5lct34"); + attr(div2, "style", div2_style_value = styleFromObject( + /*$style*/ + ctx[4] + )); + attr(div3, "class", "svelte-5lct34"); + attr(a0, "class", "item-piles-clickable-green svelte-5lct34"); + attr(div4, "class", "svelte-5lct34"); + attr(a1, "class", "item-piles-clickable-red svelte-5lct34"); + attr(div5, "class", "svelte-5lct34"); + }, + m(target, anchor) { + insert(target, div0, anchor); + append(div0, input0); + set_input_value( + input0, + /*entry*/ + ctx[0].path + ); + insert(target, t0, anchor); + insert(target, div1, anchor); + append(div1, input1); + set_input_value( + input1, + /*entry*/ + ctx[0].value + ); + insert(target, t1, anchor); + insert(target, div3, anchor); + if (if_block) + if_block.m(div3, null); + append(div3, t2); + append(div3, div2); + insert(target, t3, anchor); + insert(target, div4, anchor); + append(div4, a0); + insert(target, t4, anchor); + insert(target, div5, anchor); + append(div5, a1); + if (!mounted) { + dispose = [ + listen( + input0, + "input", + /*input0_input_handler*/ + ctx[7] + ), + listen( + input1, + "input", + /*input1_input_handler*/ + ctx[8] + ), + listen( + a0, + "click", + /*click_handler*/ + ctx[9] + ), + listen(a1, "click", function() { + if (is_function( + /*remove*/ + ctx[3]( + /*index*/ + ctx[1] + ) + )) + ctx[3]( + /*index*/ + ctx[1] + ).apply(this, arguments); + }) + ]; + mounted = true; + } + }, + p(new_ctx, [dirty]) { + ctx = new_ctx; + if (dirty & /*entry*/ + 1 && input0.value !== /*entry*/ + ctx[0].path) { + set_input_value( + input0, + /*entry*/ + ctx[0].path + ); + } + if (dirty & /*entry*/ + 1 && input1.value !== /*entry*/ + ctx[0].value) { + set_input_value( + input1, + /*entry*/ + ctx[0].value + ); + } + if ( + /*image*/ + ctx[2] + ) { + if (if_block) { + if_block.p(ctx, dirty); + } else { + if_block = create_if_block$7(ctx); + if_block.c(); + if_block.m(div3, t2); + } + } else if (if_block) { + if_block.d(1); + if_block = null; + } + if (dirty & /*$style*/ + 16 && div2_style_value !== (div2_style_value = styleFromObject( + /*$style*/ + ctx[4] + ))) { + attr(div2, "style", div2_style_value); + } + }, + i: noop, + o: noop, + d(detaching) { + if (detaching) + detach(div0); + if (detaching) + detach(t0); + if (detaching) + detach(div1); + if (detaching) + detach(t1); + if (detaching) + detach(div3); + if (if_block) + if_block.d(); + if (detaching) + detach(t3); + if (detaching) + detach(div4); + if (detaching) + detach(t4); + if (detaching) + detach(div5); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_fragment$8, "create_fragment$8"); +function instance$8($$self, $$props, $$invalidate) { + let $style; + const { application } = getContext("#external"); + let { index: index2 } = $$props; + let { entry } = $$props; + let { image } = $$props; + let { remove } = $$props; + let style = writable$1(entry.styling); + component_subscribe($$self, style, (value) => $$invalidate(4, $style = value)); + async function renderStyleEditor(event) { + const oldStyle = entry.styling; + const newStyles = await StylesEditor.show(style, { + width: 400, + left: application.position.left + 405, + top: event.clientY - 75, + readOnly: true + }); + style.set(newStyles || oldStyle); + $$invalidate(0, entry.styling = newStyles || oldStyle, entry); + } + __name(renderStyleEditor, "renderStyleEditor"); + function input0_input_handler() { + entry.path = this.value; + $$invalidate(0, entry); + } + __name(input0_input_handler, "input0_input_handler"); + function input1_input_handler() { + entry.value = this.value; + $$invalidate(0, entry); + } + __name(input1_input_handler, "input1_input_handler"); + const click_handler = /* @__PURE__ */ __name((evt) => renderStyleEditor(evt), "click_handler"); + $$self.$$set = ($$props2) => { + if ("index" in $$props2) + $$invalidate(1, index2 = $$props2.index); + if ("entry" in $$props2) + $$invalidate(0, entry = $$props2.entry); + if ("image" in $$props2) + $$invalidate(2, image = $$props2.image); + if ("remove" in $$props2) + $$invalidate(3, remove = $$props2.remove); + }; + return [ + entry, + index2, + image, + remove, + $style, + style, + renderStyleEditor, + input0_input_handler, + input1_input_handler, + click_handler + ]; +} +__name(instance$8, "instance$8"); +class StyleEntry extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$8, create_fragment$8, safe_not_equal, { index: 1, entry: 0, image: 2, remove: 3 }); + } +} +__name(StyleEntry, "StyleEntry"); +const vaultStylesEditor_svelte_svelte_type_style_lang = ""; +function get_each_context$3(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[16] = list[i]; + child_ctx[17] = list; + child_ctx[18] = i; + return child_ctx; +} +__name(get_each_context$3, "get_each_context$3"); +function create_each_block$3(key_1, ctx) { + let first; + let styleentry; + let updating_entry; + let current; + function styleentry_entry_binding(value) { + ctx[11]( + value, + /*entry*/ + ctx[16], + /*each_value*/ + ctx[17], + /*index*/ + ctx[18] + ); + } + __name(styleentry_entry_binding, "styleentry_entry_binding"); + let styleentry_props = { + image: ( + /*images*/ + ctx[3][ + /*index*/ + ctx[18] + ] + ), + index: ( + /*index*/ + ctx[18] + ), + remove: ( + /*remove*/ + ctx[8] + ) + }; + if ( + /*entry*/ + ctx[16] !== void 0 + ) { + styleentry_props.entry = /*entry*/ + ctx[16]; + } + styleentry = new StyleEntry({ props: styleentry_props }); + binding_callbacks.push(() => bind(styleentry, "entry", styleentry_entry_binding)); + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(styleentry.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(styleentry, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const styleentry_changes = {}; + if (dirty & /*images, $vaultStyleStore*/ + 24) + styleentry_changes.image = /*images*/ + ctx[3][ + /*index*/ + ctx[18] + ]; + if (dirty & /*$vaultStyleStore*/ + 16) + styleentry_changes.index = /*index*/ + ctx[18]; + if (!updating_entry && dirty & /*$vaultStyleStore*/ + 16) { + updating_entry = true; + styleentry_changes.entry = /*entry*/ + ctx[16]; + add_flush_callback(() => updating_entry = false); + } + styleentry.$set(styleentry_changes); + }, + i(local) { + if (current) + return; + transition_in(styleentry.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(styleentry.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(first); + destroy_component(styleentry, detaching); + } + }; +} +__name(create_each_block$3, "create_each_block$3"); +function create_default_slot$4(ctx) { + let form_1; + let p; + let t1; + let div5; + let div0; + let t3; + let div1; + let t5; + let div2; + let t6; + let div3; + let t7; + let div4; + let a; + let t8; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let t9; + let footer; + let button0; + let i1; + let t10; + let t11_value = localize("Save") + ""; + let t11; + let t12; + let button1; + let i2; + let t13; + let t14_value = localize("Cancel") + ""; + let t14; + let current; + let mounted; + let dispose; + let each_value = ( + /*$vaultStyleStore*/ + ctx[4] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*index*/ + ctx2[18] + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$3(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$3(key, child_ctx)); + } + return { + c() { + form_1 = element("form"); + p = element("p"); + p.textContent = `${localize("ITEM-PILES.Applications.VaultStylesEditor.Explanation")}`; + t1 = space(); + div5 = element("div"); + div0 = element("div"); + div0.textContent = `${localize("ITEM-PILES.Applications.VaultStylesEditor.Path")}`; + t3 = space(); + div1 = element("div"); + div1.textContent = `${localize("ITEM-PILES.Applications.VaultStylesEditor.Value")}`; + t5 = space(); + div2 = element("div"); + t6 = space(); + div3 = element("div"); + t7 = space(); + div4 = element("div"); + a = element("a"); + a.innerHTML = ``; + t8 = space(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + t9 = space(); + footer = element("footer"); + button0 = element("button"); + i1 = element("i"); + t10 = space(); + t11 = text(t11_value); + t12 = space(); + button1 = element("button"); + i2 = element("i"); + t13 = space(); + t14 = text(t14_value); + attr(a, "class", "item-piles-clickable svelte-1jdz898"); + set_style(div4, "text-align", "right"); + attr(div4, "class", "svelte-1jdz898"); + attr(div5, "class", "item-piles-table svelte-1jdz898"); + attr(i1, "class", "far fa-save"); + attr(button0, "type", "button"); + attr(i2, "class", "far fa-times"); + attr(button1, "type", "button"); + attr(form_1, "autocomplete", "off"); + }, + m(target, anchor) { + insert(target, form_1, anchor); + append(form_1, p); + append(form_1, t1); + append(form_1, div5); + append(div5, div0); + append(div5, t3); + append(div5, div1); + append(div5, t5); + append(div5, div2); + append(div5, t6); + append(div5, div3); + append(div5, t7); + append(div5, div4); + append(div4, a); + append(div5, t8); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(div5, null); + } + } + append(form_1, t9); + append(form_1, footer); + append(footer, button0); + append(button0, i1); + append(button0, t10); + append(button0, t11); + append(footer, t12); + append(footer, button1); + append(button1, i2); + append(button1, t13); + append(button1, t14); + ctx[13](form_1); + current = true; + if (!mounted) { + dispose = [ + listen( + a, + "click", + /*add*/ + ctx[7] + ), + listen( + button0, + "click", + /*requestSubmit*/ + ctx[1], + { once: true } + ), + listen( + button1, + "click", + /*click_handler*/ + ctx[12], + { once: true } + ), + listen(form_1, "submit", prevent_default( + /*updateSettings*/ + ctx[9] + )) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*images, $vaultStyleStore, remove*/ + 280) { + each_value = /*$vaultStyleStore*/ + ctx2[4]; + group_outros(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, div5, outro_and_destroy_block, create_each_block$3, null, get_each_context$3); + check_outros(); + } + }, + i(local) { + if (current) + return; + for (let i = 0; i < each_value.length; i += 1) { + transition_in(each_blocks[i]); + } + current = true; + }, + o(local) { + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + current = false; + }, + d(detaching) { + if (detaching) + detach(form_1); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + ctx[13](null); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$4, "create_default_slot$4"); +function create_fragment$7(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[14](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot$4] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, [dirty]) { + const applicationshell_changes = {}; + if (dirty & /*$$scope, form, $vaultStyleStore, images*/ + 524316) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment$7, "create_fragment$7"); +function instance$7($$self, $$props, $$invalidate) { + let $vaultStyleStore; + const { application } = getContext("#external"); + let form; + let { elementRoot } = $$props; + let { data: data2 } = $$props; + const vaultStyleStore = writable$1(data2); + component_subscribe($$self, vaultStyleStore, (value) => $$invalidate(4, $vaultStyleStore = value)); + loadImages(); + function add() { + vaultStyleStore.update((arr) => { + arr.push({ path: "", value: "", styling: {} }); + return arr; + }); + } + __name(add, "add"); + let images = []; + async function loadImages() { + const data3 = await FilePicker.browse("public", "icons/weapons/swords/*.webp", { wildcard: true }); + $$invalidate(3, images = data3.files); + } + __name(loadImages, "loadImages"); + function remove(index2) { + vaultStyleStore.update((arr) => { + arr.splice(index2, 1); + return arr; + }); + } + __name(remove, "remove"); + async function updateSettings() { + application.options.resolve(get_store_value(vaultStyleStore)); + application.close(); + } + __name(updateSettings, "updateSettings"); + function requestSubmit() { + form.requestSubmit(); + } + __name(requestSubmit, "requestSubmit"); + function styleentry_entry_binding(value, entry, each_value, index2) { + each_value[index2] = value; + vaultStyleStore.set($vaultStyleStore); + } + __name(styleentry_entry_binding, "styleentry_entry_binding"); + const click_handler = /* @__PURE__ */ __name(() => { + application.close(); + }, "click_handler"); + function form_1_binding($$value) { + binding_callbacks[$$value ? "unshift" : "push"](() => { + form = $$value; + $$invalidate(2, form); + }); + } + __name(form_1_binding, "form_1_binding"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + if ("data" in $$props2) + $$invalidate(10, data2 = $$props2.data); + }; + return [ + elementRoot, + requestSubmit, + form, + images, + $vaultStyleStore, + application, + vaultStyleStore, + add, + remove, + updateSettings, + data2, + styleentry_entry_binding, + click_handler, + form_1_binding, + applicationshell_elementRoot_binding + ]; +} +__name(instance$7, "instance$7"); +class Vault_styles_editor extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$7, create_fragment$7, safe_not_equal, { + elementRoot: 0, + data: 10, + requestSubmit: 1 + }); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } + get data() { + return this.$$.ctx[10]; + } + set data(data2) { + this.$$set({ data: data2 }); + flush(); + } + get requestSubmit() { + return this.$$.ctx[1]; + } +} +__name(Vault_styles_editor, "Vault_styles_editor"); +class VaultStylesEditor extends Editor { + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + title: game.i18n.localize("ITEM-PILES.Applications.VaultStylesEditor.Title"), + svelte: { + class: Vault_styles_editor + } + }); + } +} +__name(VaultStylesEditor, "VaultStylesEditor"); +const editors = { + "currencies": CurrenciesEditor, + "secondary-currencies": SecondaryCurrenciesEditor, + "item-filters": ItemFiltersEditor, + "item-similarities": StringListEditor, + "item-categories": StringListEditor, + "styles": StylesEditor, + "vault-styles": VaultStylesEditor, + "price-modifiers": PriceModifiersEditor, + "unstackable-item-types": UnstackableItemTypesEditor, + "price-presets": PricePresetEditor +}; +const SettingButton_svelte_svelte_type_style_lang = ""; +function create_if_block$6(ctx) { + let a; + let mounted; + let dispose; + return { + c() { + a = element("a"); + a.innerHTML = ``; + attr(a, "data-fast-tooltip", "Reset setting"); + }, + m(target, anchor) { + insert(target, a, anchor); + if (!mounted) { + dispose = listen( + a, + "click", + /*click_handler*/ + ctx[4] + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(a); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block$6, "create_if_block$6"); +function create_fragment$6(ctx) { + let div3; + let div0; + let label; + let t0_value = localize( + /*data*/ + ctx[0].name + ) + ""; + let t0; + let t1; + let t2; + let p; + let t3_value = localize( + /*data*/ + ctx[0].hint + ) + ""; + let t3; + let t4; + let div2; + let div1; + let button; + let i; + let i_class_value; + let t5; + let t6_value = localize( + /*data*/ + ctx[0].label + ) + ""; + let t6; + let mounted; + let dispose; + let if_block = !/*data*/ + ctx[0].hideResetButton && create_if_block$6(ctx); + return { + c() { + div3 = element("div"); + div0 = element("div"); + label = element("label"); + t0 = text(t0_value); + t1 = space(); + if (if_block) + if_block.c(); + t2 = space(); + p = element("p"); + t3 = text(t3_value); + t4 = space(); + div2 = element("div"); + div1 = element("div"); + button = element("button"); + i = element("i"); + t5 = space(); + t6 = text(t6_value); + attr(label, "class", "svelte-1e4lcsc"); + attr(p, "class", "notes"); + attr(div0, "class", "label-side svelte-1e4lcsc"); + attr(i, "class", i_class_value = null_to_empty( + /*data*/ + ctx[0].icon + ) + " svelte-1e4lcsc"); + attr(button, "type", "button"); + attr(button, "class", "svelte-1e4lcsc"); + attr(div1, "class", "button-container svelte-1e4lcsc"); + attr(div2, "class", "form-fields input-side svelte-1e4lcsc"); + attr(div3, "class", "setting form-scope item-piles-flexrow svelte-1e4lcsc"); + }, + m(target, anchor) { + insert(target, div3, anchor); + append(div3, div0); + append(div0, label); + append(label, t0); + append(label, t1); + if (if_block) + if_block.m(label, null); + append(div0, t2); + append(div0, p); + append(p, t3); + append(div3, t4); + append(div3, div2); + append(div2, div1); + append(div1, button); + append(button, i); + append(button, t5); + append(button, t6); + if (!mounted) { + dispose = listen( + button, + "click", + /*click_handler_1*/ + ctx[5] + ); + mounted = true; + } + }, + p(ctx2, [dirty]) { + if (dirty & /*data*/ + 1 && t0_value !== (t0_value = localize( + /*data*/ + ctx2[0].name + ) + "")) + set_data(t0, t0_value); + if (!/*data*/ + ctx2[0].hideResetButton) { + if (if_block) { + if_block.p(ctx2, dirty); + } else { + if_block = create_if_block$6(ctx2); + if_block.c(); + if_block.m(label, null); + } + } else if (if_block) { + if_block.d(1); + if_block = null; + } + if (dirty & /*data*/ + 1 && t3_value !== (t3_value = localize( + /*data*/ + ctx2[0].hint + ) + "")) + set_data(t3, t3_value); + if (dirty & /*data*/ + 1 && i_class_value !== (i_class_value = null_to_empty( + /*data*/ + ctx2[0].icon + ) + " svelte-1e4lcsc")) { + attr(i, "class", i_class_value); + } + if (dirty & /*data*/ + 1 && t6_value !== (t6_value = localize( + /*data*/ + ctx2[0].label + ) + "")) + set_data(t6, t6_value); + }, + i: noop, + o: noop, + d(detaching) { + if (detaching) + detach(div3); + if (if_block) + if_block.d(); + mounted = false; + dispose(); + } + }; +} +__name(create_fragment$6, "create_fragment$6"); +function instance$6($$self, $$props, $$invalidate) { + const { application } = getContext("#external"); + let { key } = $$props; + let { data: data2 } = $$props; + let { callback = false } = $$props; + let editor = false; + if (!callback) { + editor = editors[data2.application]; + callback = /* @__PURE__ */ __name(() => { + showEditor(); + }, "callback"); + } + function showEditor() { + if (editor) { + const combinedData = data2?.mergedDefaults ? foundry.utils.mergeObject(data2.mergedDefaults, data2.value) : data2.value; + openEditor(key, combinedData).then((result) => { + if (!result) + return; + if (data2?.mergedDefaults) { + result = foundry.utils.diffObject(data2?.mergedDefaults, result); + } + $$invalidate(0, data2.value = result, data2); + }); + application.options.zLevel = 100; + } + } + __name(showEditor, "showEditor"); + function reset() { + $$invalidate(0, data2.value = foundry.utils.deepClone(data2.default), data2); + } + __name(reset, "reset"); + const click_handler = /* @__PURE__ */ __name(() => reset(), "click_handler"); + const click_handler_1 = /* @__PURE__ */ __name(() => { + callback(); + }, "click_handler_1"); + $$self.$$set = ($$props2) => { + if ("key" in $$props2) + $$invalidate(3, key = $$props2.key); + if ("data" in $$props2) + $$invalidate(0, data2 = $$props2.data); + if ("callback" in $$props2) + $$invalidate(1, callback = $$props2.callback); + }; + return [data2, callback, reset, key, click_handler, click_handler_1]; +} +__name(instance$6, "instance$6"); +class SettingButton extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$6, create_fragment$6, safe_not_equal, { key: 3, data: 0, callback: 1 }); + } +} +__name(SettingButton, "SettingButton"); +const settingsShell_svelte_svelte_type_style_lang = ""; +function create_if_block_1$4(ctx) { + let tabs_1; + let updating_activeTab; + let current; + function tabs_1_activeTab_binding(value) { + ctx[11](value); + } + __name(tabs_1_activeTab_binding, "tabs_1_activeTab_binding"); + let tabs_1_props = { tabs: ( + /*tabs*/ + ctx[9] + ) }; + if ( + /*activeTab*/ + ctx[3] !== void 0 + ) { + tabs_1_props.activeTab = /*activeTab*/ + ctx[3]; + } + tabs_1 = new Tabs({ props: tabs_1_props }); + binding_callbacks.push(() => bind(tabs_1, "activeTab", tabs_1_activeTab_binding)); + return { + c() { + create_component(tabs_1.$$.fragment); + }, + m(target, anchor) { + mount_component(tabs_1, target, anchor); + current = true; + }, + p(ctx2, dirty) { + const tabs_1_changes = {}; + if (!updating_activeTab && dirty[0] & /*activeTab*/ + 8) { + updating_activeTab = true; + tabs_1_changes.activeTab = /*activeTab*/ + ctx2[3]; + add_flush_callback(() => updating_activeTab = false); + } + tabs_1.$set(tabs_1_changes); + }, + i(local) { + if (current) + return; + transition_in(tabs_1.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(tabs_1.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(tabs_1, detaching); + } + }; +} +__name(create_if_block_1$4, "create_if_block_1$4"); +function create_if_block$5(ctx) { + let div0; + let setting0; + let updating_data; + let t0; + let setting1; + let updating_data_1; + let t1; + let setting2; + let updating_data_2; + let t2; + let setting3; + let updating_data_3; + let t3; + let setting4; + let updating_data_4; + let t4; + let setting5; + let updating_data_5; + let t5; + let setting6; + let updating_data_6; + let t6; + let setting7; + let updating_data_7; + let t7; + let setting8; + let updating_data_8; + let t8; + let settingbutton0; + let updating_data_9; + let t9; + let settingbutton1; + let updating_data_10; + let t10; + let div1; + let settingbutton2; + let updating_data_11; + let t11; + let settingbutton3; + let updating_data_12; + let t12; + let div2; + let settingbutton4; + let t13; + let setting9; + let updating_data_13; + let t14; + let setting10; + let updating_data_14; + let t15; + let setting11; + let updating_data_15; + let t16; + let settingbutton5; + let updating_data_16; + let t17; + let settingbutton6; + let updating_data_17; + let t18; + let setting12; + let updating_data_18; + let t19; + let settingbutton7; + let updating_data_19; + let t20; + let settingbutton8; + let updating_data_20; + let t21; + let settingbutton9; + let updating_data_21; + let current; + function setting0_data_binding_1(value) { + ctx[18](value); + } + __name(setting0_data_binding_1, "setting0_data_binding_1"); + let setting0_props = { key: SETTINGS$1.ENABLE_DROPPING_ITEMS }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.ENABLE_DROPPING_ITEMS] !== void 0 + ) { + setting0_props.data = /*settings*/ + ctx[1][SETTINGS$1.ENABLE_DROPPING_ITEMS]; + } + setting0 = new Setting({ props: setting0_props }); + binding_callbacks.push(() => bind(setting0, "data", setting0_data_binding_1)); + function setting1_data_binding_1(value) { + ctx[19](value); + } + __name(setting1_data_binding_1, "setting1_data_binding_1"); + let setting1_props = { key: SETTINGS$1.ENABLE_GIVING_ITEMS }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.ENABLE_GIVING_ITEMS] !== void 0 + ) { + setting1_props.data = /*settings*/ + ctx[1][SETTINGS$1.ENABLE_GIVING_ITEMS]; + } + setting1 = new Setting({ props: setting1_props }); + binding_callbacks.push(() => bind(setting1, "data", setting1_data_binding_1)); + function setting2_data_binding_1(value) { + ctx[20](value); + } + __name(setting2_data_binding_1, "setting2_data_binding_1"); + let setting2_props = { key: SETTINGS$1.ENABLE_TRADING }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.ENABLE_TRADING] !== void 0 + ) { + setting2_props.data = /*settings*/ + ctx[1][SETTINGS$1.ENABLE_TRADING]; + } + setting2 = new Setting({ props: setting2_props }); + binding_callbacks.push(() => bind(setting2, "data", setting2_data_binding_1)); + function setting3_data_binding_1(value) { + ctx[21](value); + } + __name(setting3_data_binding_1, "setting3_data_binding_1"); + let setting3_props = { key: SETTINGS$1.SHOW_TRADE_BUTTON }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.SHOW_TRADE_BUTTON] !== void 0 + ) { + setting3_props.data = /*settings*/ + ctx[1][SETTINGS$1.SHOW_TRADE_BUTTON]; + } + setting3 = new Setting({ props: setting3_props }); + binding_callbacks.push(() => bind(setting3, "data", setting3_data_binding_1)); + function setting4_data_binding_1(value) { + ctx[22](value); + } + __name(setting4_data_binding_1, "setting4_data_binding_1"); + let setting4_props = { key: SETTINGS$1.INSPECT_ITEMS_IN_TRADE }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.INSPECT_ITEMS_IN_TRADE] !== void 0 + ) { + setting4_props.data = /*settings*/ + ctx[1][SETTINGS$1.INSPECT_ITEMS_IN_TRADE]; + } + setting4 = new Setting({ props: setting4_props }); + binding_callbacks.push(() => bind(setting4, "data", setting4_data_binding_1)); + function setting5_data_binding_1(value) { + ctx[23](value); + } + __name(setting5_data_binding_1, "setting5_data_binding_1"); + let setting5_props = { key: SETTINGS$1.OUTPUT_TO_CHAT }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.OUTPUT_TO_CHAT] !== void 0 + ) { + setting5_props.data = /*settings*/ + ctx[1][SETTINGS$1.OUTPUT_TO_CHAT]; + } + setting5 = new Setting({ props: setting5_props }); + binding_callbacks.push(() => bind(setting5, "data", setting5_data_binding_1)); + function setting6_data_binding(value) { + ctx[24](value); + } + __name(setting6_data_binding, "setting6_data_binding"); + let setting6_props = { key: SETTINGS$1.DELETE_EMPTY_PILES }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.DELETE_EMPTY_PILES] !== void 0 + ) { + setting6_props.data = /*settings*/ + ctx[1][SETTINGS$1.DELETE_EMPTY_PILES]; + } + setting6 = new Setting({ props: setting6_props }); + binding_callbacks.push(() => bind(setting6, "data", setting6_data_binding)); + function setting7_data_binding(value) { + ctx[25](value); + } + __name(setting7_data_binding, "setting7_data_binding"); + let setting7_props = { key: SETTINGS$1.POPULATION_TABLES_FOLDER }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.POPULATION_TABLES_FOLDER] !== void 0 + ) { + setting7_props.data = /*settings*/ + ctx[1][SETTINGS$1.POPULATION_TABLES_FOLDER]; + } + setting7 = new Setting({ props: setting7_props }); + binding_callbacks.push(() => bind(setting7, "data", setting7_data_binding)); + function setting8_data_binding(value) { + ctx[26](value); + } + __name(setting8_data_binding, "setting8_data_binding"); + let setting8_props = { key: SETTINGS$1.HIDE_TOKEN_BORDER }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.HIDE_TOKEN_BORDER] !== void 0 + ) { + setting8_props.data = /*settings*/ + ctx[1][SETTINGS$1.HIDE_TOKEN_BORDER]; + } + setting8 = new Setting({ props: setting8_props }); + binding_callbacks.push(() => bind(setting8, "data", setting8_data_binding)); + function settingbutton0_data_binding(value) { + ctx[27](value); + } + __name(settingbutton0_data_binding, "settingbutton0_data_binding"); + let settingbutton0_props = { key: SETTINGS$1.PRICE_PRESETS }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.PRICE_PRESETS] !== void 0 + ) { + settingbutton0_props.data = /*settings*/ + ctx[1][SETTINGS$1.PRICE_PRESETS]; + } + settingbutton0 = new SettingButton({ props: settingbutton0_props }); + binding_callbacks.push(() => bind(settingbutton0, "data", settingbutton0_data_binding)); + function settingbutton1_data_binding(value) { + ctx[28](value); + } + __name(settingbutton1_data_binding, "settingbutton1_data_binding"); + let settingbutton1_props = { key: SETTINGS$1.CUSTOM_ITEM_CATEGORIES }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.CUSTOM_ITEM_CATEGORIES] !== void 0 + ) { + settingbutton1_props.data = /*settings*/ + ctx[1][SETTINGS$1.CUSTOM_ITEM_CATEGORIES]; + } + settingbutton1 = new SettingButton({ props: settingbutton1_props }); + binding_callbacks.push(() => bind(settingbutton1, "data", settingbutton1_data_binding)); + function settingbutton2_data_binding(value) { + ctx[29](value); + } + __name(settingbutton2_data_binding, "settingbutton2_data_binding"); + let settingbutton2_props = { key: SETTINGS$1.CSS_VARIABLES }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.CSS_VARIABLES] !== void 0 + ) { + settingbutton2_props.data = /*settings*/ + ctx[1][SETTINGS$1.CSS_VARIABLES]; + } + settingbutton2 = new SettingButton({ props: settingbutton2_props }); + binding_callbacks.push(() => bind(settingbutton2, "data", settingbutton2_data_binding)); + function settingbutton3_data_binding(value) { + ctx[30](value); + } + __name(settingbutton3_data_binding, "settingbutton3_data_binding"); + let settingbutton3_props = { key: SETTINGS$1.VAULT_STYLES }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.VAULT_STYLES] !== void 0 + ) { + settingbutton3_props.data = /*settings*/ + ctx[1][SETTINGS$1.VAULT_STYLES]; + } + settingbutton3 = new SettingButton({ props: settingbutton3_props }); + binding_callbacks.push(() => bind(settingbutton3, "data", settingbutton3_data_binding)); + settingbutton4 = new SettingButton({ + props: { + data: { + name: "ITEM-PILES.Settings.Reset.Title", + hint: "ITEM-PILES.Settings.Reset.Hint", + label: "ITEM-PILES.Settings.Reset.Label", + icon: "fas fa-undo", + hideResetButton: true + }, + callback: ( + /*func*/ + ctx[31] + ) + } + }); + function setting9_data_binding(value) { + ctx[32](value); + } + __name(setting9_data_binding, "setting9_data_binding"); + let setting9_props = { + key: SETTINGS$1.ACTOR_CLASS_TYPE, + options: game.system.template.Actor.types + }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.ACTOR_CLASS_TYPE] !== void 0 + ) { + setting9_props.data = /*settings*/ + ctx[1][SETTINGS$1.ACTOR_CLASS_TYPE]; + } + setting9 = new Setting({ props: setting9_props }); + binding_callbacks.push(() => bind(setting9, "data", setting9_data_binding)); + function setting10_data_binding(value) { + ctx[33](value); + } + __name(setting10_data_binding, "setting10_data_binding"); + let setting10_props = { key: SETTINGS$1.ITEM_QUANTITY_ATTRIBUTE }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.ITEM_QUANTITY_ATTRIBUTE] !== void 0 + ) { + setting10_props.data = /*settings*/ + ctx[1][SETTINGS$1.ITEM_QUANTITY_ATTRIBUTE]; + } + setting10 = new Setting({ props: setting10_props }); + binding_callbacks.push(() => bind(setting10, "data", setting10_data_binding)); + function setting11_data_binding(value) { + ctx[34](value); + } + __name(setting11_data_binding, "setting11_data_binding"); + let setting11_props = { key: SETTINGS$1.ITEM_PRICE_ATTRIBUTE }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.ITEM_PRICE_ATTRIBUTE] !== void 0 + ) { + setting11_props.data = /*settings*/ + ctx[1][SETTINGS$1.ITEM_PRICE_ATTRIBUTE]; + } + setting11 = new Setting({ props: setting11_props }); + binding_callbacks.push(() => bind(setting11, "data", setting11_data_binding)); + function settingbutton5_data_binding(value) { + ctx[35](value); + } + __name(settingbutton5_data_binding, "settingbutton5_data_binding"); + let settingbutton5_props = { key: SETTINGS$1.CURRENCIES }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.CURRENCIES] !== void 0 + ) { + settingbutton5_props.data = /*settings*/ + ctx[1][SETTINGS$1.CURRENCIES]; + } + settingbutton5 = new SettingButton({ props: settingbutton5_props }); + binding_callbacks.push(() => bind(settingbutton5, "data", settingbutton5_data_binding)); + function settingbutton6_data_binding(value) { + ctx[36](value); + } + __name(settingbutton6_data_binding, "settingbutton6_data_binding"); + let settingbutton6_props = { key: SETTINGS$1.SECONDARY_CURRENCIES }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.SECONDARY_CURRENCIES] !== void 0 + ) { + settingbutton6_props.data = /*settings*/ + ctx[1][SETTINGS$1.SECONDARY_CURRENCIES]; + } + settingbutton6 = new SettingButton({ props: settingbutton6_props }); + binding_callbacks.push(() => bind(settingbutton6, "data", settingbutton6_data_binding)); + function setting12_data_binding(value) { + ctx[37](value); + } + __name(setting12_data_binding, "setting12_data_binding"); + let setting12_props = { + key: SETTINGS$1.CURRENCY_DECIMAL_DIGITS, + disabled: ( + /*settings*/ + ctx[1][SETTINGS$1.CURRENCIES].value.length !== 1 + ) + }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.CURRENCY_DECIMAL_DIGITS] !== void 0 + ) { + setting12_props.data = /*settings*/ + ctx[1][SETTINGS$1.CURRENCY_DECIMAL_DIGITS]; + } + setting12 = new Setting({ props: setting12_props }); + binding_callbacks.push(() => bind(setting12, "data", setting12_data_binding)); + function settingbutton7_data_binding(value) { + ctx[38](value); + } + __name(settingbutton7_data_binding, "settingbutton7_data_binding"); + let settingbutton7_props = { key: SETTINGS$1.ITEM_FILTERS }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.ITEM_FILTERS] !== void 0 + ) { + settingbutton7_props.data = /*settings*/ + ctx[1][SETTINGS$1.ITEM_FILTERS]; + } + settingbutton7 = new SettingButton({ props: settingbutton7_props }); + binding_callbacks.push(() => bind(settingbutton7, "data", settingbutton7_data_binding)); + function settingbutton8_data_binding(value) { + ctx[39](value); + } + __name(settingbutton8_data_binding, "settingbutton8_data_binding"); + let settingbutton8_props = { key: SETTINGS$1.ITEM_SIMILARITIES }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.ITEM_SIMILARITIES] !== void 0 + ) { + settingbutton8_props.data = /*settings*/ + ctx[1][SETTINGS$1.ITEM_SIMILARITIES]; + } + settingbutton8 = new SettingButton({ props: settingbutton8_props }); + binding_callbacks.push(() => bind(settingbutton8, "data", settingbutton8_data_binding)); + function settingbutton9_data_binding(value) { + ctx[40](value); + } + __name(settingbutton9_data_binding, "settingbutton9_data_binding"); + let settingbutton9_props = { key: SETTINGS$1.UNSTACKABLE_ITEM_TYPES }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.UNSTACKABLE_ITEM_TYPES] !== void 0 + ) { + settingbutton9_props.data = /*settings*/ + ctx[1][SETTINGS$1.UNSTACKABLE_ITEM_TYPES]; + } + settingbutton9 = new SettingButton({ props: settingbutton9_props }); + binding_callbacks.push(() => bind(settingbutton9, "data", settingbutton9_data_binding)); + return { + c() { + div0 = element("div"); + create_component(setting0.$$.fragment); + t0 = space(); + create_component(setting1.$$.fragment); + t1 = space(); + create_component(setting2.$$.fragment); + t2 = space(); + create_component(setting3.$$.fragment); + t3 = space(); + create_component(setting4.$$.fragment); + t4 = space(); + create_component(setting5.$$.fragment); + t5 = space(); + create_component(setting6.$$.fragment); + t6 = space(); + create_component(setting7.$$.fragment); + t7 = space(); + create_component(setting8.$$.fragment); + t8 = space(); + create_component(settingbutton0.$$.fragment); + t9 = space(); + create_component(settingbutton1.$$.fragment); + t10 = space(); + div1 = element("div"); + create_component(settingbutton2.$$.fragment); + t11 = space(); + create_component(settingbutton3.$$.fragment); + t12 = space(); + div2 = element("div"); + create_component(settingbutton4.$$.fragment); + t13 = space(); + create_component(setting9.$$.fragment); + t14 = space(); + create_component(setting10.$$.fragment); + t15 = space(); + create_component(setting11.$$.fragment); + t16 = space(); + create_component(settingbutton5.$$.fragment); + t17 = space(); + create_component(settingbutton6.$$.fragment); + t18 = space(); + create_component(setting12.$$.fragment); + t19 = space(); + create_component(settingbutton7.$$.fragment); + t20 = space(); + create_component(settingbutton8.$$.fragment); + t21 = space(); + create_component(settingbutton9.$$.fragment); + attr(div0, "class", "tab flex"); + attr(div0, "data-scope", "primary"); + attr(div0, "data-tab", "module"); + toggle_class( + div0, + "active", + /*activeTab*/ + ctx[3] === "module" + ); + attr(div1, "class", "tab flex"); + attr(div1, "data-scope", "primary"); + attr(div1, "data-tab", "styles"); + toggle_class( + div1, + "active", + /*activeTab*/ + ctx[3] === "styles" + ); + attr(div2, "class", "tab flex"); + attr(div2, "data-scope", "primary"); + attr(div2, "data-tab", "system"); + toggle_class( + div2, + "active", + /*activeTab*/ + ctx[3] === "system" + ); + }, + m(target, anchor) { + insert(target, div0, anchor); + mount_component(setting0, div0, null); + append(div0, t0); + mount_component(setting1, div0, null); + append(div0, t1); + mount_component(setting2, div0, null); + append(div0, t2); + mount_component(setting3, div0, null); + append(div0, t3); + mount_component(setting4, div0, null); + append(div0, t4); + mount_component(setting5, div0, null); + append(div0, t5); + mount_component(setting6, div0, null); + append(div0, t6); + mount_component(setting7, div0, null); + append(div0, t7); + mount_component(setting8, div0, null); + append(div0, t8); + mount_component(settingbutton0, div0, null); + append(div0, t9); + mount_component(settingbutton1, div0, null); + insert(target, t10, anchor); + insert(target, div1, anchor); + mount_component(settingbutton2, div1, null); + append(div1, t11); + mount_component(settingbutton3, div1, null); + insert(target, t12, anchor); + insert(target, div2, anchor); + mount_component(settingbutton4, div2, null); + append(div2, t13); + mount_component(setting9, div2, null); + append(div2, t14); + mount_component(setting10, div2, null); + append(div2, t15); + mount_component(setting11, div2, null); + append(div2, t16); + mount_component(settingbutton5, div2, null); + append(div2, t17); + mount_component(settingbutton6, div2, null); + append(div2, t18); + mount_component(setting12, div2, null); + append(div2, t19); + mount_component(settingbutton7, div2, null); + append(div2, t20); + mount_component(settingbutton8, div2, null); + append(div2, t21); + mount_component(settingbutton9, div2, null); + current = true; + }, + p(ctx2, dirty) { + const setting0_changes = {}; + if (!updating_data && dirty[0] & /*settings*/ + 2) { + updating_data = true; + setting0_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.ENABLE_DROPPING_ITEMS]; + add_flush_callback(() => updating_data = false); + } + setting0.$set(setting0_changes); + const setting1_changes = {}; + if (!updating_data_1 && dirty[0] & /*settings*/ + 2) { + updating_data_1 = true; + setting1_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.ENABLE_GIVING_ITEMS]; + add_flush_callback(() => updating_data_1 = false); + } + setting1.$set(setting1_changes); + const setting2_changes = {}; + if (!updating_data_2 && dirty[0] & /*settings*/ + 2) { + updating_data_2 = true; + setting2_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.ENABLE_TRADING]; + add_flush_callback(() => updating_data_2 = false); + } + setting2.$set(setting2_changes); + const setting3_changes = {}; + if (!updating_data_3 && dirty[0] & /*settings*/ + 2) { + updating_data_3 = true; + setting3_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.SHOW_TRADE_BUTTON]; + add_flush_callback(() => updating_data_3 = false); + } + setting3.$set(setting3_changes); + const setting4_changes = {}; + if (!updating_data_4 && dirty[0] & /*settings*/ + 2) { + updating_data_4 = true; + setting4_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.INSPECT_ITEMS_IN_TRADE]; + add_flush_callback(() => updating_data_4 = false); + } + setting4.$set(setting4_changes); + const setting5_changes = {}; + if (!updating_data_5 && dirty[0] & /*settings*/ + 2) { + updating_data_5 = true; + setting5_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.OUTPUT_TO_CHAT]; + add_flush_callback(() => updating_data_5 = false); + } + setting5.$set(setting5_changes); + const setting6_changes = {}; + if (!updating_data_6 && dirty[0] & /*settings*/ + 2) { + updating_data_6 = true; + setting6_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.DELETE_EMPTY_PILES]; + add_flush_callback(() => updating_data_6 = false); + } + setting6.$set(setting6_changes); + const setting7_changes = {}; + if (!updating_data_7 && dirty[0] & /*settings*/ + 2) { + updating_data_7 = true; + setting7_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.POPULATION_TABLES_FOLDER]; + add_flush_callback(() => updating_data_7 = false); + } + setting7.$set(setting7_changes); + const setting8_changes = {}; + if (!updating_data_8 && dirty[0] & /*settings*/ + 2) { + updating_data_8 = true; + setting8_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.HIDE_TOKEN_BORDER]; + add_flush_callback(() => updating_data_8 = false); + } + setting8.$set(setting8_changes); + const settingbutton0_changes = {}; + if (!updating_data_9 && dirty[0] & /*settings*/ + 2) { + updating_data_9 = true; + settingbutton0_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.PRICE_PRESETS]; + add_flush_callback(() => updating_data_9 = false); + } + settingbutton0.$set(settingbutton0_changes); + const settingbutton1_changes = {}; + if (!updating_data_10 && dirty[0] & /*settings*/ + 2) { + updating_data_10 = true; + settingbutton1_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.CUSTOM_ITEM_CATEGORIES]; + add_flush_callback(() => updating_data_10 = false); + } + settingbutton1.$set(settingbutton1_changes); + if (!current || dirty[0] & /*activeTab*/ + 8) { + toggle_class( + div0, + "active", + /*activeTab*/ + ctx2[3] === "module" + ); + } + const settingbutton2_changes = {}; + if (!updating_data_11 && dirty[0] & /*settings*/ + 2) { + updating_data_11 = true; + settingbutton2_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.CSS_VARIABLES]; + add_flush_callback(() => updating_data_11 = false); + } + settingbutton2.$set(settingbutton2_changes); + const settingbutton3_changes = {}; + if (!updating_data_12 && dirty[0] & /*settings*/ + 2) { + updating_data_12 = true; + settingbutton3_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.VAULT_STYLES]; + add_flush_callback(() => updating_data_12 = false); + } + settingbutton3.$set(settingbutton3_changes); + if (!current || dirty[0] & /*activeTab*/ + 8) { + toggle_class( + div1, + "active", + /*activeTab*/ + ctx2[3] === "styles" + ); + } + const setting9_changes = {}; + if (!updating_data_13 && dirty[0] & /*settings*/ + 2) { + updating_data_13 = true; + setting9_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.ACTOR_CLASS_TYPE]; + add_flush_callback(() => updating_data_13 = false); + } + setting9.$set(setting9_changes); + const setting10_changes = {}; + if (!updating_data_14 && dirty[0] & /*settings*/ + 2) { + updating_data_14 = true; + setting10_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.ITEM_QUANTITY_ATTRIBUTE]; + add_flush_callback(() => updating_data_14 = false); + } + setting10.$set(setting10_changes); + const setting11_changes = {}; + if (!updating_data_15 && dirty[0] & /*settings*/ + 2) { + updating_data_15 = true; + setting11_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.ITEM_PRICE_ATTRIBUTE]; + add_flush_callback(() => updating_data_15 = false); + } + setting11.$set(setting11_changes); + const settingbutton5_changes = {}; + if (!updating_data_16 && dirty[0] & /*settings*/ + 2) { + updating_data_16 = true; + settingbutton5_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.CURRENCIES]; + add_flush_callback(() => updating_data_16 = false); + } + settingbutton5.$set(settingbutton5_changes); + const settingbutton6_changes = {}; + if (!updating_data_17 && dirty[0] & /*settings*/ + 2) { + updating_data_17 = true; + settingbutton6_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.SECONDARY_CURRENCIES]; + add_flush_callback(() => updating_data_17 = false); + } + settingbutton6.$set(settingbutton6_changes); + const setting12_changes = {}; + if (dirty[0] & /*settings*/ + 2) + setting12_changes.disabled = /*settings*/ + ctx2[1][SETTINGS$1.CURRENCIES].value.length !== 1; + if (!updating_data_18 && dirty[0] & /*settings*/ + 2) { + updating_data_18 = true; + setting12_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.CURRENCY_DECIMAL_DIGITS]; + add_flush_callback(() => updating_data_18 = false); + } + setting12.$set(setting12_changes); + const settingbutton7_changes = {}; + if (!updating_data_19 && dirty[0] & /*settings*/ + 2) { + updating_data_19 = true; + settingbutton7_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.ITEM_FILTERS]; + add_flush_callback(() => updating_data_19 = false); + } + settingbutton7.$set(settingbutton7_changes); + const settingbutton8_changes = {}; + if (!updating_data_20 && dirty[0] & /*settings*/ + 2) { + updating_data_20 = true; + settingbutton8_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.ITEM_SIMILARITIES]; + add_flush_callback(() => updating_data_20 = false); + } + settingbutton8.$set(settingbutton8_changes); + const settingbutton9_changes = {}; + if (!updating_data_21 && dirty[0] & /*settings*/ + 2) { + updating_data_21 = true; + settingbutton9_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.UNSTACKABLE_ITEM_TYPES]; + add_flush_callback(() => updating_data_21 = false); + } + settingbutton9.$set(settingbutton9_changes); + if (!current || dirty[0] & /*activeTab*/ + 8) { + toggle_class( + div2, + "active", + /*activeTab*/ + ctx2[3] === "system" + ); + } + }, + i(local) { + if (current) + return; + transition_in(setting0.$$.fragment, local); + transition_in(setting1.$$.fragment, local); + transition_in(setting2.$$.fragment, local); + transition_in(setting3.$$.fragment, local); + transition_in(setting4.$$.fragment, local); + transition_in(setting5.$$.fragment, local); + transition_in(setting6.$$.fragment, local); + transition_in(setting7.$$.fragment, local); + transition_in(setting8.$$.fragment, local); + transition_in(settingbutton0.$$.fragment, local); + transition_in(settingbutton1.$$.fragment, local); + transition_in(settingbutton2.$$.fragment, local); + transition_in(settingbutton3.$$.fragment, local); + transition_in(settingbutton4.$$.fragment, local); + transition_in(setting9.$$.fragment, local); + transition_in(setting10.$$.fragment, local); + transition_in(setting11.$$.fragment, local); + transition_in(settingbutton5.$$.fragment, local); + transition_in(settingbutton6.$$.fragment, local); + transition_in(setting12.$$.fragment, local); + transition_in(settingbutton7.$$.fragment, local); + transition_in(settingbutton8.$$.fragment, local); + transition_in(settingbutton9.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(setting0.$$.fragment, local); + transition_out(setting1.$$.fragment, local); + transition_out(setting2.$$.fragment, local); + transition_out(setting3.$$.fragment, local); + transition_out(setting4.$$.fragment, local); + transition_out(setting5.$$.fragment, local); + transition_out(setting6.$$.fragment, local); + transition_out(setting7.$$.fragment, local); + transition_out(setting8.$$.fragment, local); + transition_out(settingbutton0.$$.fragment, local); + transition_out(settingbutton1.$$.fragment, local); + transition_out(settingbutton2.$$.fragment, local); + transition_out(settingbutton3.$$.fragment, local); + transition_out(settingbutton4.$$.fragment, local); + transition_out(setting9.$$.fragment, local); + transition_out(setting10.$$.fragment, local); + transition_out(setting11.$$.fragment, local); + transition_out(settingbutton5.$$.fragment, local); + transition_out(settingbutton6.$$.fragment, local); + transition_out(setting12.$$.fragment, local); + transition_out(settingbutton7.$$.fragment, local); + transition_out(settingbutton8.$$.fragment, local); + transition_out(settingbutton9.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(div0); + destroy_component(setting0); + destroy_component(setting1); + destroy_component(setting2); + destroy_component(setting3); + destroy_component(setting4); + destroy_component(setting5); + destroy_component(setting6); + destroy_component(setting7); + destroy_component(setting8); + destroy_component(settingbutton0); + destroy_component(settingbutton1); + if (detaching) + detach(t10); + if (detaching) + detach(div1); + destroy_component(settingbutton2); + destroy_component(settingbutton3); + if (detaching) + detach(t12); + if (detaching) + detach(div2); + destroy_component(settingbutton4); + destroy_component(setting9); + destroy_component(setting10); + destroy_component(setting11); + destroy_component(settingbutton5); + destroy_component(settingbutton6); + destroy_component(setting12); + destroy_component(settingbutton7); + destroy_component(settingbutton8); + destroy_component(settingbutton9); + } + }; +} +__name(create_if_block$5, "create_if_block$5"); +function create_default_slot$3(ctx) { + let form_1; + let h2; + let t1; + let t2; + let section; + let div1; + let setting0; + let updating_data; + let t3; + let setting1; + let updating_data_1; + let t4; + let setting2; + let updating_data_2; + let t5; + let setting3; + let updating_data_3; + let t6; + let setting4; + let updating_data_4; + let t7; + let setting5; + let updating_data_5; + let t8; + let div0; + let p0; + let p1; + let p2; + let a0; + let t12; + let p3; + let t14; + let p4; + let t17; + let t18; + let footer; + let button1; + let i; + let t19; + let t20_value = localize("ITEM-PILES.Applications.Settings.Submit") + ""; + let t20; + let current; + let mounted; + let dispose; + let if_block0 = ( + /*userCanChangeSettings*/ + ctx[4] && create_if_block_1$4(ctx) + ); + function setting0_data_binding(value) { + ctx[12](value); + } + __name(setting0_data_binding, "setting0_data_binding"); + let setting0_props = { key: SETTINGS$1.INVERT_SHEET_OPEN }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.INVERT_SHEET_OPEN] !== void 0 + ) { + setting0_props.data = /*settings*/ + ctx[1][SETTINGS$1.INVERT_SHEET_OPEN]; + } + setting0 = new Setting({ props: setting0_props }); + binding_callbacks.push(() => bind(setting0, "data", setting0_data_binding)); + function setting1_data_binding(value) { + ctx[13](value); + } + __name(setting1_data_binding, "setting1_data_binding"); + let setting1_props = { key: SETTINGS$1.HIDE_ACTOR_HEADER_TEXT }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.HIDE_ACTOR_HEADER_TEXT] !== void 0 + ) { + setting1_props.data = /*settings*/ + ctx[1][SETTINGS$1.HIDE_ACTOR_HEADER_TEXT]; + } + setting1 = new Setting({ props: setting1_props }); + binding_callbacks.push(() => bind(setting1, "data", setting1_data_binding)); + function setting2_data_binding(value) { + ctx[14](value); + } + __name(setting2_data_binding, "setting2_data_binding"); + let setting2_props = { key: SETTINGS$1.HIDE_ACTOR_HEADER_BUTTON }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.HIDE_ACTOR_HEADER_BUTTON] !== void 0 + ) { + setting2_props.data = /*settings*/ + ctx[1][SETTINGS$1.HIDE_ACTOR_HEADER_BUTTON]; + } + setting2 = new Setting({ props: setting2_props }); + binding_callbacks.push(() => bind(setting2, "data", setting2_data_binding)); + function setting3_data_binding(value) { + ctx[15](value); + } + __name(setting3_data_binding, "setting3_data_binding"); + let setting3_props = { key: SETTINGS$1.PRELOAD_FILES }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.PRELOAD_FILES] !== void 0 + ) { + setting3_props.data = /*settings*/ + ctx[1][SETTINGS$1.PRELOAD_FILES]; + } + setting3 = new Setting({ props: setting3_props }); + binding_callbacks.push(() => bind(setting3, "data", setting3_data_binding)); + function setting4_data_binding(value) { + ctx[16](value); + } + __name(setting4_data_binding, "setting4_data_binding"); + let setting4_props = { key: SETTINGS$1.DEBUG }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.DEBUG] !== void 0 + ) { + setting4_props.data = /*settings*/ + ctx[1][SETTINGS$1.DEBUG]; + } + setting4 = new Setting({ props: setting4_props }); + binding_callbacks.push(() => bind(setting4, "data", setting4_data_binding)); + function setting5_data_binding(value) { + ctx[17](value); + } + __name(setting5_data_binding, "setting5_data_binding"); + let setting5_props = { key: SETTINGS$1.DEBUG_HOOKS }; + if ( + /*settings*/ + ctx[1][SETTINGS$1.DEBUG_HOOKS] !== void 0 + ) { + setting5_props.data = /*settings*/ + ctx[1][SETTINGS$1.DEBUG_HOOKS]; + } + setting5 = new Setting({ props: setting5_props }); + binding_callbacks.push(() => bind(setting5, "data", setting5_data_binding)); + let if_block1 = ( + /*userCanChangeSettings*/ + ctx[4] && create_if_block$5(ctx) + ); + return { + c() { + form_1 = element("form"); + h2 = element("h2"); + h2.textContent = `${localize("ITEM-PILES.Applications.Settings.Title")}`; + t1 = space(); + if (if_block0) + if_block0.c(); + t2 = space(); + section = element("section"); + div1 = element("div"); + create_component(setting0.$$.fragment); + t3 = space(); + create_component(setting1.$$.fragment); + t4 = space(); + create_component(setting2.$$.fragment); + t5 = space(); + create_component(setting3.$$.fragment); + t6 = space(); + create_component(setting4.$$.fragment); + t7 = space(); + create_component(setting5.$$.fragment); + t8 = space(); + div0 = element("div"); + p0 = element("p"); + p0.textContent = `${localize("ITEM-PILES.Applications.Settings.MoreToCome")} + `; + p1 = element("p"); + p2 = element("p"); + a0 = element("a"); + a0.textContent = `${localize("ITEM-PILES.Applications.Settings.Request")}`; + t12 = space(); + p3 = element("p"); + p3.textContent = `${localize("ITEM-PILES.Applications.Settings.Donate")}`; + t14 = space(); + p4 = element("p"); + p4.innerHTML = ``; + t17 = space(); + if (if_block1) + if_block1.c(); + t18 = space(); + footer = element("footer"); + button1 = element("button"); + i = element("i"); + t19 = space(); + t20 = text(t20_value); + set_style(h2, "text-align", "center"); + set_style(h2, "margin-bottom", "1rem"); + attr(a0, "class", "link-text svelte-ui4yo1"); + attr(a0, "href", "https://github.com/fantasycalendar/FoundryVTT-ItemPiles/issues/new?assignees=&labels=&template=feature_request.md&title="); + attr(a0, "target", "_blank"); + set_style(p2, "margin-bottom", "1rem"); + set_style(div0, "text-align", "center"); + set_style(div0, "font-size", "1rem"); + set_style(div0, "margin-top", "3rem"); + attr(div1, "class", "tab flex"); + attr(div1, "data-scope", "primary"); + attr(div1, "data-tab", "local"); + toggle_class( + div1, + "active", + /*activeTab*/ + ctx[3] === "local" + ); + attr(section, "class", "tab-body svelte-ui4yo1"); + attr(i, "class", "far fa-save"); + attr(button1, "type", "button"); + attr(footer, "class", "svelte-ui4yo1"); + attr(form_1, "autocomplete", "off"); + }, + m(target, anchor) { + insert(target, form_1, anchor); + append(form_1, h2); + append(form_1, t1); + if (if_block0) + if_block0.m(form_1, null); + append(form_1, t2); + append(form_1, section); + append(section, div1); + mount_component(setting0, div1, null); + append(div1, t3); + mount_component(setting1, div1, null); + append(div1, t4); + mount_component(setting2, div1, null); + append(div1, t5); + mount_component(setting3, div1, null); + append(div1, t6); + mount_component(setting4, div1, null); + append(div1, t7); + mount_component(setting5, div1, null); + append(div1, t8); + append(div1, div0); + append(div0, p0); + append(div0, p1); + append(div0, p2); + append(p2, a0); + append(div0, t12); + append(div0, p3); + append(div0, t14); + append(div0, p4); + append(section, t17); + if (if_block1) + if_block1.m(section, null); + append(form_1, t18); + append(form_1, footer); + append(footer, button1); + append(button1, i); + append(button1, t19); + append(button1, t20); + ctx[41](form_1); + current = true; + if (!mounted) { + dispose = [ + listen( + button1, + "click", + /*requestSubmit*/ + ctx[6], + { once: true } + ), + listen(form_1, "submit", prevent_default( + /*updateSettings*/ + ctx[7] + ), { once: true }) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if ( + /*userCanChangeSettings*/ + ctx2[4] + ) + if_block0.p(ctx2, dirty); + const setting0_changes = {}; + if (!updating_data && dirty[0] & /*settings*/ + 2) { + updating_data = true; + setting0_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.INVERT_SHEET_OPEN]; + add_flush_callback(() => updating_data = false); + } + setting0.$set(setting0_changes); + const setting1_changes = {}; + if (!updating_data_1 && dirty[0] & /*settings*/ + 2) { + updating_data_1 = true; + setting1_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.HIDE_ACTOR_HEADER_TEXT]; + add_flush_callback(() => updating_data_1 = false); + } + setting1.$set(setting1_changes); + const setting2_changes = {}; + if (!updating_data_2 && dirty[0] & /*settings*/ + 2) { + updating_data_2 = true; + setting2_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.HIDE_ACTOR_HEADER_BUTTON]; + add_flush_callback(() => updating_data_2 = false); + } + setting2.$set(setting2_changes); + const setting3_changes = {}; + if (!updating_data_3 && dirty[0] & /*settings*/ + 2) { + updating_data_3 = true; + setting3_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.PRELOAD_FILES]; + add_flush_callback(() => updating_data_3 = false); + } + setting3.$set(setting3_changes); + const setting4_changes = {}; + if (!updating_data_4 && dirty[0] & /*settings*/ + 2) { + updating_data_4 = true; + setting4_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.DEBUG]; + add_flush_callback(() => updating_data_4 = false); + } + setting4.$set(setting4_changes); + const setting5_changes = {}; + if (!updating_data_5 && dirty[0] & /*settings*/ + 2) { + updating_data_5 = true; + setting5_changes.data = /*settings*/ + ctx2[1][SETTINGS$1.DEBUG_HOOKS]; + add_flush_callback(() => updating_data_5 = false); + } + setting5.$set(setting5_changes); + if (!current || dirty[0] & /*activeTab*/ + 8) { + toggle_class( + div1, + "active", + /*activeTab*/ + ctx2[3] === "local" + ); + } + if ( + /*userCanChangeSettings*/ + ctx2[4] + ) + if_block1.p(ctx2, dirty); + }, + i(local) { + if (current) + return; + transition_in(if_block0); + transition_in(setting0.$$.fragment, local); + transition_in(setting1.$$.fragment, local); + transition_in(setting2.$$.fragment, local); + transition_in(setting3.$$.fragment, local); + transition_in(setting4.$$.fragment, local); + transition_in(setting5.$$.fragment, local); + transition_in(if_block1); + current = true; + }, + o(local) { + transition_out(if_block0); + transition_out(setting0.$$.fragment, local); + transition_out(setting1.$$.fragment, local); + transition_out(setting2.$$.fragment, local); + transition_out(setting3.$$.fragment, local); + transition_out(setting4.$$.fragment, local); + transition_out(setting5.$$.fragment, local); + transition_out(if_block1); + current = false; + }, + d(detaching) { + if (detaching) + detach(form_1); + if (if_block0) + if_block0.d(); + destroy_component(setting0); + destroy_component(setting1); + destroy_component(setting2); + destroy_component(setting3); + destroy_component(setting4); + destroy_component(setting5); + if (if_block1) + if_block1.d(); + ctx[41](null); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$3, "create_default_slot$3"); +function create_fragment$5(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[42](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot$3] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, dirty) { + const applicationshell_changes = {}; + if (dirty[0] & /*form, activeTab, settings*/ + 14 | dirty[1] & /*$$scope*/ + 8192) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty[0] & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment$5, "create_fragment$5"); +function instance$5($$self, $$props, $$invalidate) { + const { application } = getContext("#external"); + let { elementRoot } = $$props; + let form; + let { settings = {} } = $$props; + let userCanChangeSettings = game.user.hasPermission("SETTINGS_MODIFY"); + getSettings(); + function getSettings() { + $$invalidate(1, settings = Object.fromEntries(Object.entries(SETTINGS$1.GET_DEFAULT()).map((entry) => { + entry[1].value = getSetting(entry[0]); + return entry; + }))); + $$invalidate( + 1, + settings[SETTINGS$1.POPULATION_TABLES_FOLDER].choices = { + "root": "ITEM-PILES.Settings.PopulationTablesFolder.AllTables", + ...Object.fromEntries(game.folders.filter((f) => f.type === "RollTable").map((f) => [f.id, f.name])) + }, + settings + ); + } + __name(getSettings, "getSettings"); + function importSettings(incomingSettings) { + for (const [key, value] of Object.entries(incomingSettings)) { + if (settings[SETTINGS$1[key]] === void 0) + continue; + $$invalidate(1, settings[SETTINGS$1[key]].value = value, settings); + } + $$invalidate(1, settings); + } + __name(importSettings, "importSettings"); + function requestSubmit() { + form.requestSubmit(); + } + __name(requestSubmit, "requestSubmit"); + async function updateSettings() { + let settingsToUpdate = Object.entries(settings).filter((entry) => userCanChangeSettings || entry[1].scope === "client"); + for (let [key, setting] of settingsToUpdate) { + await setSetting(key, setting.value); + } + application.close(); + } + __name(updateSettings, "updateSettings"); + async function resetSettings() { + const doThing = await TJSDialog.confirm({ + title: "Item Piles - " + game.i18n.localize("ITEM-PILES.Dialogs.ResetSettings.Title"), + content: { + class: CustomDialog, + props: { + content: game.i18n.localize("ITEM-PILES.Dialogs.ResetSettings.Content") + } + }, + buttons: { + yes: { + icon: '', + label: game.i18n.localize("ITEM-PILES.Dialogs.ResetSettings.Confirm") + }, + no: { + icon: '', + label: game.i18n.localize("No") + } + }, + modal: true, + draggable: false, + rejectClose: false, + defaultYes: true, + options: { height: "auto" } + }); + if (!doThing) + return; + return applyDefaultSettings(); + } + __name(resetSettings, "resetSettings"); + let tabs = [ + { + value: "local", + label: localize("ITEM-PILES.Applications.Settings.Local") + }, + { + value: "module", + label: localize("ITEM-PILES.Applications.Settings.Module"), + hidden: !userCanChangeSettings + }, + { + value: "styles", + label: localize("ITEM-PILES.Applications.Settings.Styles"), + hidden: !userCanChangeSettings + }, + { + value: "system", + label: localize("ITEM-PILES.Applications.Settings.System"), + hidden: !userCanChangeSettings + } + ]; + let activeTab = tabs[0].value; + function tabs_1_activeTab_binding(value) { + activeTab = value; + $$invalidate(3, activeTab); + } + __name(tabs_1_activeTab_binding, "tabs_1_activeTab_binding"); + function setting0_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.INVERT_SHEET_OPEN], value)) { + settings[SETTINGS$1.INVERT_SHEET_OPEN] = value; + $$invalidate(1, settings); + } + } + __name(setting0_data_binding, "setting0_data_binding"); + function setting1_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.HIDE_ACTOR_HEADER_TEXT], value)) { + settings[SETTINGS$1.HIDE_ACTOR_HEADER_TEXT] = value; + $$invalidate(1, settings); + } + } + __name(setting1_data_binding, "setting1_data_binding"); + function setting2_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.HIDE_ACTOR_HEADER_BUTTON], value)) { + settings[SETTINGS$1.HIDE_ACTOR_HEADER_BUTTON] = value; + $$invalidate(1, settings); + } + } + __name(setting2_data_binding, "setting2_data_binding"); + function setting3_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.PRELOAD_FILES], value)) { + settings[SETTINGS$1.PRELOAD_FILES] = value; + $$invalidate(1, settings); + } + } + __name(setting3_data_binding, "setting3_data_binding"); + function setting4_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.DEBUG], value)) { + settings[SETTINGS$1.DEBUG] = value; + $$invalidate(1, settings); + } + } + __name(setting4_data_binding, "setting4_data_binding"); + function setting5_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.DEBUG_HOOKS], value)) { + settings[SETTINGS$1.DEBUG_HOOKS] = value; + $$invalidate(1, settings); + } + } + __name(setting5_data_binding, "setting5_data_binding"); + function setting0_data_binding_1(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.ENABLE_DROPPING_ITEMS], value)) { + settings[SETTINGS$1.ENABLE_DROPPING_ITEMS] = value; + $$invalidate(1, settings); + } + } + __name(setting0_data_binding_1, "setting0_data_binding_1"); + function setting1_data_binding_1(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.ENABLE_GIVING_ITEMS], value)) { + settings[SETTINGS$1.ENABLE_GIVING_ITEMS] = value; + $$invalidate(1, settings); + } + } + __name(setting1_data_binding_1, "setting1_data_binding_1"); + function setting2_data_binding_1(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.ENABLE_TRADING], value)) { + settings[SETTINGS$1.ENABLE_TRADING] = value; + $$invalidate(1, settings); + } + } + __name(setting2_data_binding_1, "setting2_data_binding_1"); + function setting3_data_binding_1(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.SHOW_TRADE_BUTTON], value)) { + settings[SETTINGS$1.SHOW_TRADE_BUTTON] = value; + $$invalidate(1, settings); + } + } + __name(setting3_data_binding_1, "setting3_data_binding_1"); + function setting4_data_binding_1(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.INSPECT_ITEMS_IN_TRADE], value)) { + settings[SETTINGS$1.INSPECT_ITEMS_IN_TRADE] = value; + $$invalidate(1, settings); + } + } + __name(setting4_data_binding_1, "setting4_data_binding_1"); + function setting5_data_binding_1(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.OUTPUT_TO_CHAT], value)) { + settings[SETTINGS$1.OUTPUT_TO_CHAT] = value; + $$invalidate(1, settings); + } + } + __name(setting5_data_binding_1, "setting5_data_binding_1"); + function setting6_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.DELETE_EMPTY_PILES], value)) { + settings[SETTINGS$1.DELETE_EMPTY_PILES] = value; + $$invalidate(1, settings); + } + } + __name(setting6_data_binding, "setting6_data_binding"); + function setting7_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.POPULATION_TABLES_FOLDER], value)) { + settings[SETTINGS$1.POPULATION_TABLES_FOLDER] = value; + $$invalidate(1, settings); + } + } + __name(setting7_data_binding, "setting7_data_binding"); + function setting8_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.HIDE_TOKEN_BORDER], value)) { + settings[SETTINGS$1.HIDE_TOKEN_BORDER] = value; + $$invalidate(1, settings); + } + } + __name(setting8_data_binding, "setting8_data_binding"); + function settingbutton0_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.PRICE_PRESETS], value)) { + settings[SETTINGS$1.PRICE_PRESETS] = value; + $$invalidate(1, settings); + } + } + __name(settingbutton0_data_binding, "settingbutton0_data_binding"); + function settingbutton1_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.CUSTOM_ITEM_CATEGORIES], value)) { + settings[SETTINGS$1.CUSTOM_ITEM_CATEGORIES] = value; + $$invalidate(1, settings); + } + } + __name(settingbutton1_data_binding, "settingbutton1_data_binding"); + function settingbutton2_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.CSS_VARIABLES], value)) { + settings[SETTINGS$1.CSS_VARIABLES] = value; + $$invalidate(1, settings); + } + } + __name(settingbutton2_data_binding, "settingbutton2_data_binding"); + function settingbutton3_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.VAULT_STYLES], value)) { + settings[SETTINGS$1.VAULT_STYLES] = value; + $$invalidate(1, settings); + } + } + __name(settingbutton3_data_binding, "settingbutton3_data_binding"); + const func2 = /* @__PURE__ */ __name(async () => { + await resetSettings(); + getSettings(); + }, "func"); + function setting9_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.ACTOR_CLASS_TYPE], value)) { + settings[SETTINGS$1.ACTOR_CLASS_TYPE] = value; + $$invalidate(1, settings); + } + } + __name(setting9_data_binding, "setting9_data_binding"); + function setting10_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.ITEM_QUANTITY_ATTRIBUTE], value)) { + settings[SETTINGS$1.ITEM_QUANTITY_ATTRIBUTE] = value; + $$invalidate(1, settings); + } + } + __name(setting10_data_binding, "setting10_data_binding"); + function setting11_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.ITEM_PRICE_ATTRIBUTE], value)) { + settings[SETTINGS$1.ITEM_PRICE_ATTRIBUTE] = value; + $$invalidate(1, settings); + } + } + __name(setting11_data_binding, "setting11_data_binding"); + function settingbutton5_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.CURRENCIES], value)) { + settings[SETTINGS$1.CURRENCIES] = value; + $$invalidate(1, settings); + } + } + __name(settingbutton5_data_binding, "settingbutton5_data_binding"); + function settingbutton6_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.SECONDARY_CURRENCIES], value)) { + settings[SETTINGS$1.SECONDARY_CURRENCIES] = value; + $$invalidate(1, settings); + } + } + __name(settingbutton6_data_binding, "settingbutton6_data_binding"); + function setting12_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.CURRENCY_DECIMAL_DIGITS], value)) { + settings[SETTINGS$1.CURRENCY_DECIMAL_DIGITS] = value; + $$invalidate(1, settings); + } + } + __name(setting12_data_binding, "setting12_data_binding"); + function settingbutton7_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.ITEM_FILTERS], value)) { + settings[SETTINGS$1.ITEM_FILTERS] = value; + $$invalidate(1, settings); + } + } + __name(settingbutton7_data_binding, "settingbutton7_data_binding"); + function settingbutton8_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.ITEM_SIMILARITIES], value)) { + settings[SETTINGS$1.ITEM_SIMILARITIES] = value; + $$invalidate(1, settings); + } + } + __name(settingbutton8_data_binding, "settingbutton8_data_binding"); + function settingbutton9_data_binding(value) { + if ($$self.$$.not_equal(settings[SETTINGS$1.UNSTACKABLE_ITEM_TYPES], value)) { + settings[SETTINGS$1.UNSTACKABLE_ITEM_TYPES] = value; + $$invalidate(1, settings); + } + } + __name(settingbutton9_data_binding, "settingbutton9_data_binding"); + function form_1_binding($$value) { + binding_callbacks[$$value ? "unshift" : "push"](() => { + form = $$value; + $$invalidate(2, form); + }); + } + __name(form_1_binding, "form_1_binding"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + if ("settings" in $$props2) + $$invalidate(1, settings = $$props2.settings); + }; + return [ + elementRoot, + settings, + form, + activeTab, + userCanChangeSettings, + getSettings, + requestSubmit, + updateSettings, + resetSettings, + tabs, + importSettings, + tabs_1_activeTab_binding, + setting0_data_binding, + setting1_data_binding, + setting2_data_binding, + setting3_data_binding, + setting4_data_binding, + setting5_data_binding, + setting0_data_binding_1, + setting1_data_binding_1, + setting2_data_binding_1, + setting3_data_binding_1, + setting4_data_binding_1, + setting5_data_binding_1, + setting6_data_binding, + setting7_data_binding, + setting8_data_binding, + settingbutton0_data_binding, + settingbutton1_data_binding, + settingbutton2_data_binding, + settingbutton3_data_binding, + func2, + setting9_data_binding, + setting10_data_binding, + setting11_data_binding, + settingbutton5_data_binding, + settingbutton6_data_binding, + setting12_data_binding, + settingbutton7_data_binding, + settingbutton8_data_binding, + settingbutton9_data_binding, + form_1_binding, + applicationshell_elementRoot_binding + ]; +} +__name(instance$5, "instance$5"); +class Settings_shell extends SvelteComponent { + constructor(options) { + super(); + init( + this, + options, + instance$5, + create_fragment$5, + safe_not_equal, + { + elementRoot: 0, + settings: 1, + importSettings: 10 + }, + null, + [-1, -1] + ); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } + get settings() { + return this.$$.ctx[1]; + } + set settings(settings) { + this.$$set({ settings }); + flush(); + } + get importSettings() { + return this.$$.ctx[10]; + } +} +__name(Settings_shell, "Settings_shell"); +class SettingsApp extends SvelteApplication { + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + id: `item-piles-application-system-settings-${randomID()}`, + title: "Item Piles Module Configuration", + width: 600, + svelte: { + class: Settings_shell, + target: document.body + }, + zIndex: 100, + classes: ["item-piles-app"] + }); + } + static getActiveApp() { + return getActiveApps("item-piles-application-system-settings", true); + } + static async show(options = {}, dialogData = {}) { + const app = this.getActiveApp(); + if (app) + return app.render(false, { focus: true }); + return new Promise((resolve) => { + options.resolve = resolve; + new this(options, dialogData).render(true, { focus: true }); + }); + } + /** @override */ + _getHeaderButtons() { + let buttons = super._getHeaderButtons(); + if (game.user.isGM) { + buttons = [ + { + label: "ITEM-PILES.Applications.Settings.Export", + class: "item-piles-export-settings", + icon: "fas fa-file-export", + onclick: () => { + const settingKeys = Object.fromEntries(Object.entries(SETTINGS$1).filter(([_, value]) => typeof value === "string").map(([key, value]) => [value, key])); + const settings = Object.entries(this.svelte.applicationShell.settings).filter(([_, setting]) => { + return setting.system && setting.name; + }).map(([key, setting]) => { + return [settingKeys[key], setting.value]; + }); + const a = document.createElement("a"); + const file = new Blob([JSON.stringify(Object.fromEntries(settings), null, 4)], { type: "text/json" }); + a.href = URL.createObjectURL(file); + a.download = `item-piles-${game.system.id}.json`; + a.click(); + a.remove(); + } + }, + { + label: "ITEM-PILES.Applications.Settings.Import", + class: "item-piles-import-settings", + icon: "fas fa-file-import", + onclick: () => { + const input = document.createElement("input"); + input.type = "file"; + input.onchange = (e) => { + input.remove(); + const file = e.target.files[0]; + const reader = new FileReader(); + reader.addEventListener("load", async () => { + try { + const incomingSettings = JSON.parse(reader.result); + this.svelte.applicationShell.importSettings(incomingSettings); + } catch (err) { + console.error(err); + } + }); + reader.readAsText(file); + }; + input.click(); + } + } + ].concat(buttons); + } + return buttons; + } +} +__name(SettingsApp, "SettingsApp"); +class SettingsShim extends FormApplication { + /** + * @inheritDoc + */ + constructor() { + super({}); + SettingsApp.show(); + } + async _updateObject(event, formData) { + } + render() { + this.close(); + } +} +__name(SettingsShim, "SettingsShim"); +function registerSettings() { + game.settings.registerMenu(CONSTANTS.MODULE_NAME, "configure-settings", { + name: "ITEM-PILES.Settings.Configure.Title", + label: "ITEM-PILES.Settings.Configure.Label", + hint: "ITEM-PILES.Settings.Configure.Hint", + icon: "fas fa-cog", + type: SettingsShim, + restricted: false + }); + for (let [name, data2] of Object.entries(SETTINGS$1.GET_DEFAULT())) { + game.settings.register(CONSTANTS.MODULE_NAME, name, data2); + } +} +__name(registerSettings, "registerSettings"); +async function applyDefaultSettings() { + const settings = SETTINGS$1.GET_SYSTEM_DEFAULTS(); + for (const [name, data2] of Object.entries(settings)) { + await setSetting(name, data2.default); + } + await setSetting(SETTINGS$1.SYSTEM_VERSION, SYSTEMS.DATA.VERSION); + await patchCurrencySettings(); +} +__name(applyDefaultSettings, "applyDefaultSettings"); +async function patchCurrencySettings() { + const currencies = getSetting(SETTINGS$1.CURRENCIES); + for (let currency of currencies) { + if (currency.type !== "item" || !currency.data.uuid || currency.data.item) + continue; + const item = await fromUuid(currency.data.uuid); + if (!item) + continue; + currency.data.item = item.toObject(); + } + return setSetting(SETTINGS$1.CURRENCIES, currencies); +} +__name(patchCurrencySettings, "patchCurrencySettings"); +function applySystemSpecificStyles(data2 = false) { + const defaultCssVariables = foundry.utils.deepClone(SETTINGS$1.DEFAULT_CSS_VARIABLES); + const cssVariables2 = data2 || getSetting(SETTINGS$1.CSS_VARIABLES); + const mergedCssVariables = foundry.utils.mergeObject(defaultCssVariables, cssVariables2); + const root = document.documentElement; + for (const [style, val] of Object.entries(mergedCssVariables)) { + if (!val) { + root.style.removeProperty(`--item-piles-${style}`); + } else { + root.style.setProperty(`--item-piles-${style}`, val); + } + } +} +__name(applySystemSpecificStyles, "applySystemSpecificStyles"); +async function checkSystem() { + if (!SYSTEMS.HAS_SYSTEM_SUPPORT) { + if (getSetting(SETTINGS$1.SYSTEM_NOT_FOUND_WARNING_SHOWN)) + return; + let settingsValid = true; + for (const [name, data2] of Object.entries(SETTINGS$1.GET_DEFAULT())) { + settingsValid = settingsValid && getSetting(name).length !== new data2.type().length; + } + if (settingsValid) + return; + TJSDialog.prompt({ + title: game.i18n.localize("ITEM-PILES.Dialogs.NoSystemFound.Title"), + content: { + class: CustomDialog, + props: { + content: game.i18n.localize("ITEM-PILES.Dialogs.NoSystemFound.Content") + } + } + }); + return setSetting(SETTINGS$1.SYSTEM_NOT_FOUND_WARNING_SHOWN, true); + } + if (getSetting(SETTINGS$1.SYSTEM_FOUND) || SYSTEMS.DATA.INTEGRATION) { + const currentVersion = getSetting(SETTINGS$1.SYSTEM_VERSION); + const newVersion = SYSTEMS.DATA.VERSION; + debug(`Comparing system version - Current: ${currentVersion} - New: ${newVersion}`); + if (isNewerVersion(newVersion, currentVersion)) { + debug(`Applying system settings for ${game.system.title}`); + await applyDefaultSettings(); + } + return; + } + await setSetting(SETTINGS$1.SYSTEM_FOUND, true); + if (getSetting(SETTINGS$1.SYSTEM_NOT_FOUND_WARNING_SHOWN)) { + custom_notify(game.i18n.localize("ITEM-PILES.Notifications.SystemSupportFound")); + } + return applyDefaultSettings(); +} +__name(checkSystem, "checkSystem"); +function applyShims() { + if (game.release.generation !== 11) + return; + CONSTANTS.ACTOR_DELTA_PROPERTY = "delta"; + Object.freeze(CONSTANTS); +} +__name(applyShims, "applyShims"); +const SETTINGS = { + // Client settings + OUTPUT_TO_CHAT: "outputToChat", + INVERT_SHEET_OPEN: "invertSheetOpen", + HIDE_ACTOR_HEADER_TEXT: "hideActorHeaderText", + HIDE_ACTOR_HEADER_BUTTON: "hideActorHeaderButton", + PRELOAD_FILES: "preloadFiles", + DEBUG: "debug", + DEBUG_HOOKS: "debugHooks", + // Module Settings + ENABLE_DROPPING_ITEMS: "enableDroppingItems", + ENABLE_TRADING: "enableTrading", + ENABLE_GIVING_ITEMS: "enableGivingItems", + SHOW_TRADE_BUTTON: "showTradeButton", + DELETE_EMPTY_PILES: "deleteEmptyPiles", + INSPECT_ITEMS_IN_TRADE: "inspectItemsInTrade", + POPULATION_TABLES_FOLDER: "populationTablesFolder", + PRICE_PRESETS: "pricePresets", + HIDE_TOKEN_BORDER: "hideTokenBorder", + // Style settings + CSS_VARIABLES: "cssVariables", + VAULT_STYLES: "vaultStyles", + // System Settings + CURRENCIES: "currencies", + SECONDARY_CURRENCIES: "secondaryCurrencies", + CURRENCY_DECIMAL_DIGITS: "currencyDecimalDigits", + ITEM_FILTERS: "itemFilters", + ACTOR_CLASS_TYPE: "actorClassType", + ITEM_QUANTITY_ATTRIBUTE: "itemQuantityAttribute", + ITEM_PRICE_ATTRIBUTE: "itemPriceAttribute", + QUANTITY_FOR_PRICE_ATTRIBUTE: "quantityForPriceAttribute", + ITEM_SIMILARITIES: "itemSimilarities", + UNSTACKABLE_ITEM_TYPES: "unstackableItemTypes", + PILE_DEFAULTS: "pileDefaults", + TOKEN_FLAG_DEFAULTS: "tokenFlagDefaults", + // Hidden settings + DEFAULT_ITEM_PILE_JOURNAL_ID: "defaultItemPileJournalID", + DEFAULT_ITEM_PILE_ACTOR_ID: "defaultItemPileActorID", + SYSTEM_FOUND: "systemFound", + SYSTEM_NOT_FOUND_WARNING_SHOWN: "systemNotFoundWarningShown", + SYSTEM_VERSION: "systemVersion", + CUSTOM_ITEM_CATEGORIES: "customItemCategories", + HIDE_TOKEN_BORDER_OPTIONS: { + EVERYONE: "everyone", + PLAYERS: "players", + SHOW: "show" + }, + DEFAULT_CSS_VARIABLES: { + "inactive": "rgba(31,143,255,1)", + "minor-inactive": "rgba(201,200,185,1)", + "shadow-primary": "rgba(255,0,0,1)", + "even-color": "rgba(240,240,223,1)", + "odd-color": "rgba(0,0,0,0)", + "border-dark-primary": "rgba(25,24,19,1)", + "border-light-primary": "rgba(181,179,164,1)", + "text-light-highlight": "rgba(240,240,224,1)", + "text-important": "rgba(255,100,0,1)" + }, + GET_DEFAULT() { + return foundry.utils.deepClone(SETTINGS.DEFAULTS()); + }, + GET_SYSTEM_DEFAULTS() { + return Object.fromEntries(Object.entries(SETTINGS.GET_DEFAULT()).filter((entry) => { + return entry[1].system; + })); + }, + DEFAULTS: () => ({ + [SETTINGS.CURRENCIES]: { + name: "ITEM-PILES.Settings.Currencies.Title", + label: "ITEM-PILES.Settings.Currencies.Label", + hint: "ITEM-PILES.Settings.Currencies.Hint", + icon: "fa fa-money-bill-alt", + application: "currencies", + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.CURRENCIES, + type: Array + }, + [SETTINGS.SECONDARY_CURRENCIES]: { + name: "ITEM-PILES.Settings.SecondaryCurrencies.Title", + label: "ITEM-PILES.Settings.SecondaryCurrencies.Label", + hint: "ITEM-PILES.Settings.SecondaryCurrencies.Hint", + icon: "fa fa-money-bill-alt", + application: "secondary-currencies", + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.SECONDARY_CURRENCIES, + type: Array + }, + [SETTINGS.CURRENCY_DECIMAL_DIGITS]: { + name: "ITEM-PILES.Settings.CurrencyDecimalDigits.Title", + hint: "ITEM-PILES.Settings.CurrencyDecimalDigits.Hint", + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.CURRENCY_DECIMAL_DIGITS, + step: 1e-5, + min: 0, + max: 1, + type: Number + }, + [SETTINGS.ITEM_FILTERS]: { + name: "ITEM-PILES.Settings.ItemFilters.Title", + label: "ITEM-PILES.Settings.ItemFilters.Label", + hint: "ITEM-PILES.Settings.ItemFilters.Hint", + icon: "fa fa-filter", + application: "item-filters", + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.ITEM_FILTERS, + type: Array + }, + [SETTINGS.ITEM_SIMILARITIES]: { + name: "ITEM-PILES.Settings.ItemSimilarities.Title", + label: "ITEM-PILES.Settings.ItemSimilarities.Label", + hint: "ITEM-PILES.Settings.ItemSimilarities.Hint", + icon: "fa fa-equals", + application: "item-similarities", + applicationOptions: { + title: "ITEM-PILES.Applications.SimilaritiesEditor.Title", + content: "ITEM-PILES.Applications.SimilaritiesEditor.Explanation", + column: "ITEM-PILES.Applications.SimilaritiesEditor.Path" + }, + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.ITEM_SIMILARITIES, + onChange: () => { + refreshItemTypesThatCanStack(); + }, + type: Array + }, + [SETTINGS.UNSTACKABLE_ITEM_TYPES]: { + name: "ITEM-PILES.Settings.UnstackableItemTypes.Title", + label: "ITEM-PILES.Settings.UnstackableItemTypes.Label", + hint: "ITEM-PILES.Settings.UnstackableItemTypes.Hint", + icon: "fa fa-equals", + application: "unstackable-item-types", + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.UNSTACKABLE_ITEM_TYPES, + onChange: () => { + refreshItemTypesThatCanStack(); + }, + type: Array + }, + [SETTINGS.CSS_VARIABLES]: { + name: "ITEM-PILES.Settings.CssVariables.Title", + label: "ITEM-PILES.Settings.CssVariables.Label", + hint: "ITEM-PILES.Settings.CssVariables.Hint", + icon: "fa-solid fa-wand-magic-sparkles", + application: "styles", + applicationOptions: { + readOnly: true, + variables: true + }, + scope: "world", + config: false, + default: SYSTEMS.DATA.CSS_VARIABLES, + mergedDefaults: SETTINGS.DEFAULT_CSS_VARIABLES, + onchange: (data2) => { + applySystemSpecificStyles(data2); + }, + type: Object + }, + [SETTINGS.VAULT_STYLES]: { + name: "ITEM-PILES.Settings.VaultStyles.Title", + label: "ITEM-PILES.Settings.VaultStyles.Label", + hint: "ITEM-PILES.Settings.VaultStyles.Hint", + icon: "fa-solid fa-wand-magic-sparkles", + application: "vault-styles", + scope: "world", + config: false, + default: SYSTEMS.DATA.VAULT_STYLES, + type: Array + }, + [SETTINGS.ACTOR_CLASS_TYPE]: { + name: "ITEM-PILES.Settings.ActorClass.Title", + hint: "ITEM-PILES.Settings.ActorClass.Hint", + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.ACTOR_CLASS_TYPE, + type: String + }, + [SETTINGS.ITEM_QUANTITY_ATTRIBUTE]: { + name: "ITEM-PILES.Settings.Quantity.Title", + hint: "ITEM-PILES.Settings.Quantity.Hint", + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.ITEM_QUANTITY_ATTRIBUTE, + type: String + }, + [SETTINGS.ITEM_PRICE_ATTRIBUTE]: { + name: "ITEM-PILES.Settings.Price.Title", + hint: "ITEM-PILES.Settings.Price.Hint", + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.ITEM_PRICE_ATTRIBUTE, + type: String + }, + [SETTINGS.QUANTITY_FOR_PRICE_ATTRIBUTE]: { + name: "ITEM-PILES.Settings.QuantityForPrice.Title", + hint: "ITEM-PILES.Settings.QuantityForPrice.Hint", + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.QUANTITY_FOR_PRICE_ATTRIBUTE, + type: String + }, + [SETTINGS.PILE_DEFAULTS]: { + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.PILE_DEFAULTS, + type: Object + }, + [SETTINGS.TOKEN_FLAG_DEFAULTS]: { + scope: "world", + config: false, + system: true, + default: SYSTEMS.DATA.TOKEN_FLAG_DEFAULTS, + type: Object + }, + [SETTINGS.CUSTOM_ITEM_CATEGORIES]: { + name: "ITEM-PILES.Settings.CustomItemCategories.Title", + label: "ITEM-PILES.Settings.CustomItemCategories.Label", + hint: "ITEM-PILES.Settings.CustomItemCategories.Hint", + application: "item-categories", + applicationOptions: { + title: "ITEM-PILES.Applications.CustomItemCategoriesEditor.Title", + content: "ITEM-PILES.Applications.CustomItemCategoriesEditor.Explanation", + column: "ITEM-PILES.Applications.CustomItemCategoriesEditor.Category" + }, + scope: "world", + config: false, + default: [], + type: Array + }, + [SETTINGS.SYSTEM_VERSION]: { + scope: "world", + config: false, + default: "0.0.0", + type: String + }, + [SETTINGS.DEFAULT_ITEM_PILE_ACTOR_ID]: { + scope: "world", + config: false, + default: "", + type: String + }, + [SETTINGS.DEFAULT_ITEM_PILE_JOURNAL_ID]: { + scope: "world", + config: false, + default: "", + type: String + }, + [SETTINGS.SYSTEM_FOUND]: { + scope: "world", + config: false, + default: false, + type: Boolean + }, + [SETTINGS.SYSTEM_NOT_FOUND_WARNING_SHOWN]: { + scope: "world", + config: false, + default: false, + type: Boolean + }, + [SETTINGS.OUTPUT_TO_CHAT]: { + name: "ITEM-PILES.Settings.OutputToChat.Title", + hint: "ITEM-PILES.Settings.OutputToChat.Hint", + scope: "world", + config: false, + default: 1, + choices: [ + "ITEM-PILES.Settings.OutputToChat.Off", + "ITEM-PILES.Settings.OutputToChat.Public", + "ITEM-PILES.Settings.OutputToChat.SelfGM", + "ITEM-PILES.Settings.OutputToChat.Blind" + ], + type: Number + }, + [SETTINGS.INSPECT_ITEMS_IN_TRADE]: { + name: "ITEM-PILES.Settings.InspectItemsTrade.Title", + hint: "ITEM-PILES.Settings.InspectItemsTrade.Hint", + scope: "world", + config: false, + default: true, + type: Boolean + }, + [SETTINGS.POPULATION_TABLES_FOLDER]: { + name: "ITEM-PILES.Settings.PopulationTablesFolder.Title", + hint: "ITEM-PILES.Settings.PopulationTablesFolder.Hint", + scope: "world", + config: false, + default: "root", + type: String + }, + [SETTINGS.DELETE_EMPTY_PILES]: { + name: "ITEM-PILES.Settings.DeleteEmptyPiles.Title", + hint: "ITEM-PILES.Settings.DeleteEmptyPiles.Hint", + scope: "world", + config: false, + default: false, + type: Boolean + }, + [SETTINGS.ENABLE_DROPPING_ITEMS]: { + name: "ITEM-PILES.Settings.EnableDroppingItems.Title", + hint: "ITEM-PILES.Settings.EnableDroppingItems.Hint", + scope: "world", + config: false, + default: true, + type: Boolean + }, + [SETTINGS.ENABLE_TRADING]: { + name: "ITEM-PILES.Settings.EnableTrading.Title", + hint: "ITEM-PILES.Settings.EnableTrading.Hint", + scope: "world", + config: false, + default: true, + type: Boolean + }, + [SETTINGS.ENABLE_GIVING_ITEMS]: { + name: "ITEM-PILES.Settings.EnableGivingItems.Title", + hint: "ITEM-PILES.Settings.EnableGivingItems.Hint", + scope: "world", + config: false, + default: true, + type: Boolean + }, + [SETTINGS.SHOW_TRADE_BUTTON]: { + name: "ITEM-PILES.Settings.ShowTradeButton.Title", + hint: "ITEM-PILES.Settings.ShowTradeButton.Hint", + scope: "world", + config: false, + default: true, + type: Boolean + }, + [SETTINGS.PRICE_PRESETS]: { + name: "ITEM-PILES.Settings.PricePresets.Title", + label: "ITEM-PILES.Settings.PricePresets.Label", + hint: "ITEM-PILES.Settings.PricePresets.Hint", + scope: "world", + icon: "fa fa-tags", + application: "price-presets", + config: false, + default: [], + type: Array + }, + [SETTINGS.HIDE_TOKEN_BORDER]: { + name: "ITEM-PILES.Settings.HideTokenBorder.Title", + label: "ITEM-PILES.Settings.HideTokenBorder.Label", + hint: "ITEM-PILES.Settings.HideTokenBorder.Hint", + scope: "world", + config: false, + default: SETTINGS.HIDE_TOKEN_BORDER_OPTIONS.EVERYONE, + choices: { + [SETTINGS.HIDE_TOKEN_BORDER_OPTIONS.EVERYONE]: "ITEM-PILES.Settings.HideTokenBorder.HideEveryone", + [SETTINGS.HIDE_TOKEN_BORDER_OPTIONS.PLAYERS]: "ITEM-PILES.Settings.HideTokenBorder.HidePlayers", + [SETTINGS.HIDE_TOKEN_BORDER_OPTIONS.SHOW]: "ITEM-PILES.Settings.HideTokenBorder.Show" + }, + type: String + }, + [SETTINGS.INVERT_SHEET_OPEN]: { + name: "ITEM-PILES.Settings.InvertSheetOpen.Title", + hint: "ITEM-PILES.Settings.InvertSheetOpen.Hint", + scope: "client", + config: false, + default: false, + type: Boolean + }, + [SETTINGS.HIDE_ACTOR_HEADER_TEXT]: { + name: "ITEM-PILES.Settings.HideHeaderButtonText.Title", + hint: "ITEM-PILES.Settings.HideHeaderButtonText.Hint", + scope: "client", + config: false, + default: false, + type: Boolean + }, + [SETTINGS.HIDE_ACTOR_HEADER_BUTTON]: { + name: "ITEM-PILES.Settings.HideHeaderButton.Title", + hint: "ITEM-PILES.Settings.HideHeaderButton.Hint", + scope: "client", + config: false, + default: false, + type: Boolean + }, + [SETTINGS.PRELOAD_FILES]: { + name: "ITEM-PILES.Settings.PreloadFiles.Title", + hint: "ITEM-PILES.Settings.PreloadFiles.Hint", + scope: "client", + config: false, + default: true, + type: Boolean + }, + [SETTINGS.DEBUG]: { + name: "ITEM-PILES.Settings.Debug.Title", + hint: "ITEM-PILES.Settings.Debug.Hint", + scope: "client", + config: false, + default: false, + type: Boolean + }, + [SETTINGS.DEBUG_HOOKS]: { + name: "ITEM-PILES.Settings.DebugHooks.Title", + hint: "ITEM-PILES.Settings.DebugHooks.Hint", + scope: "client", + config: false, + default: false, + type: Boolean + } + }) +}; +const SETTINGS$1 = SETTINGS; +function getActor(target) { + if (target instanceof Actor) + return target; + let targetDoc = target; + if (stringIsUuid(target)) { + targetDoc = fromUuidSync(target); + if (!targetDoc && deletedActorCache.has(target)) { + return deletedActorCache.get(target); + } + } + targetDoc = getDocument(targetDoc); + return targetDoc?.character ?? targetDoc?.actor ?? targetDoc; +} +__name(getActor, "getActor"); +function getToken(documentUuid) { + let doc = fromUuidSync(documentUuid); + doc = doc?.token ?? doc; + return doc instanceof TokenDocument ? doc?.object ?? doc : doc; +} +__name(getToken, "getToken"); +function getDocument(target) { + if (stringIsUuid(target)) { + target = fromUuidSync(target); + } + return target?.document ?? target; +} +__name(getDocument, "getDocument"); +function stringIsUuid(inId) { + return typeof inId === "string" && (inId.match(/\./g) || []).length && !inId.endsWith("."); +} +__name(stringIsUuid, "stringIsUuid"); +function getUuid(target) { + if (stringIsUuid(target)) + return target; + const document2 = getDocument(target); + return document2?.uuid ?? false; +} +__name(getUuid, "getUuid"); +function findSimilarItem(items, findItem, actorFlagData = false, ignoreVault = false) { + const itemSimilarities = game.itempiles.API.ITEM_SIMILARITIES; + let findItemData = findItem instanceof Item ? findItem.toObject() : findItem; + findItemData = findItemData?.item ?? findItemData; + const findItemId = findItemData?._id; + let hasUniqueKey = false; + for (let prop of CONSTANTS.ITEM_FORCED_UNIQUE_KEYS) { + if (getProperty(findItemData, prop)) { + hasUniqueKey = true; + break; + } + } + const actorIsVault = actorFlagData ? actorFlagData?.enabled && actorFlagData?.type === CONSTANTS.PILE_TYPES.VAULT : false; + const filteredItems = items.filter((item) => { + for (let prop of CONSTANTS.ITEM_FORCED_UNIQUE_KEYS) { + if (getProperty(item?.item ?? item, prop)) { + return false; + } + } + return true; + }).filter((item) => { + const itemId = item instanceof Item ? item.id : item?.item?._id ?? item?._id ?? item?.id; + if (itemId && findItemId && itemId === findItemId) { + return true; + } + if (!itemSimilarities.some((path) => hasProperty(findItem, path))) { + return false; + } + if (hasUniqueKey) { + return false; + } + let itemData = item instanceof Item ? item.toObject() : item; + itemData = itemData?.item ?? itemData; + if (areItemsDifferent(itemData, findItemData)) { + return false; + } + return itemSimilarities.length > 0; + }); + let sortedItems = filteredItems; + if (actorIsVault && !ignoreVault) { + let distanceItems = filteredItems.map((item) => { + const itemX = getProperty(item, CONSTANTS.FLAGS.ITEM + ".x") ?? Infinity; + const itemY = getProperty(item, CONSTANTS.FLAGS.ITEM + ".y") ?? Infinity; + const findX = getProperty(findItem, CONSTANTS.FLAGS.ITEM + ".x") ?? Infinity; + const findY = getProperty(findItem, CONSTANTS.FLAGS.ITEM + ".y") ?? Infinity; + const distance = new Ray({ x: itemX, y: itemY }, { x: findX, y: findY }).distance; + return { distance, item }; + }); + distanceItems.sort((a, b) => a.distance - b.distance); + distanceItems = distanceItems.filter((item) => { + return item.distance === 0 && { + "default": actorFlagData?.canStackItems ?? true, + "yes": true, + "no": false + }[getItemFlagData(item)?.canStack ?? "default"]; + }).map((item) => item.item); + sortedItems = distanceItems; + } + return sortedItems?.[0] ?? false; +} +__name(findSimilarItem, "findSimilarItem"); +function areItemsDifferent(itemA, itemB) { + const itemSimilarities = game.itempiles.API.ITEM_SIMILARITIES; + for (const path of itemSimilarities) { + if (getProperty(itemA, path) !== getProperty(itemB, path) || !hasProperty(itemA, path) ^ !hasProperty(itemB, path)) { + return true; + } + } + return false; +} +__name(areItemsDifferent, "areItemsDifferent"); +function setSimilarityProperties(obj, item) { + const itemData = item instanceof Item ? item.toObject() : item; + setProperty(obj, "_id", itemData._id); + game.itempiles.API.ITEM_SIMILARITIES.forEach((prop) => { + setProperty(obj, prop, getProperty(itemData, prop)); + }); + return obj; +} +__name(setSimilarityProperties, "setSimilarityProperties"); +let itemTypesWithQuantities = false; +function refreshItemTypesThatCanStack() { + itemTypesWithQuantities = false; + getItemTypesThatCanStack(); +} +__name(refreshItemTypesThatCanStack, "refreshItemTypesThatCanStack"); +function getItemTypesThatCanStack() { + if (!itemTypesWithQuantities) { + const unstackableItemTypes = getSetting(SETTINGS$1.UNSTACKABLE_ITEM_TYPES); + const types = new Set(Object.keys(CONFIG?.Item?.dataModels ?? {}).concat(game.system.template.Item.types)); + itemTypesWithQuantities = new Set(types.filter((type) => { + let itemTemplate = {}; + if (CONFIG?.Item?.dataModels?.[type]?.defineSchema !== void 0) { + itemTemplate.system = Object.entries(CONFIG.Item.dataModels[type].defineSchema()).map(([key, schema]) => { + return [key, schema.fields ?? true]; + }); + itemTemplate.system = Object.fromEntries(itemTemplate.system); + } else if (game.system?.template?.Item?.[type]) { + itemTemplate.system = foundry.utils.deepClone(game.system.template.Item[type]); + if (itemTemplate.system?.templates?.length) { + const templates = foundry.utils.duplicate(itemTemplate.system.templates); + for (let template of templates) { + itemTemplate.system = foundry.utils.mergeObject( + itemTemplate.system, + foundry.utils.duplicate(game.system.template.Item.templates[template]) + ); + } + } + } + return hasItemQuantity(itemTemplate); + })).filter((type) => !unstackableItemTypes.includes(type)); + } + return itemTypesWithQuantities; +} +__name(getItemTypesThatCanStack, "getItemTypesThatCanStack"); +function getItemQuantity(item) { + const itemData = item instanceof Item ? item.toObject() : item; + return Number(getProperty(itemData, game.itempiles.API.ITEM_QUANTITY_ATTRIBUTE) ?? 0); +} +__name(getItemQuantity, "getItemQuantity"); +function hasItemQuantity(item) { + const itemData = item instanceof Item ? item.toObject() : item; + return hasProperty(itemData, game.itempiles.API.ITEM_QUANTITY_ATTRIBUTE); +} +__name(hasItemQuantity, "hasItemQuantity"); +function setItemQuantity(itemData, quantity, requiresExistingQuantity = false) { + if (!requiresExistingQuantity || getItemTypesThatCanStack().has(itemData.type)) { + setProperty(itemData, game.itempiles.API.ITEM_QUANTITY_ATTRIBUTE, quantity); + } + return itemData; +} +__name(setItemQuantity, "setItemQuantity"); +function getItemCost(item) { + const itemData = item instanceof Item ? item.toObject() : item; + return getProperty(itemData, game.itempiles.API.ITEM_PRICE_ATTRIBUTE) ?? 0; +} +__name(getItemCost, "getItemCost"); +function getTokensAtLocation(position) { + const tokens = [...canvas.tokens.placeables].filter((token) => token?.mesh?.visible); + return tokens.filter((token) => { + return position.x >= token.x && position.x < token.x + token.document.width * canvas.grid.size && position.y >= token.y && position.y < token.y + token.document.height * canvas.grid.size; + }); +} +__name(getTokensAtLocation, "getTokensAtLocation"); +function distance_between_rect(p1, p2) { + const x1 = p1.x; + const y1 = p1.y; + const x1b = p1.x + p1.w; + const y1b = p1.y + p1.h; + const x2 = p2.x; + const y2 = p2.y; + const x2b = p2.x + p2.w; + const y2b = p2.y + p2.h; + const left = x2b < x1; + const right = x1b < x2; + const bottom = y2b < y1; + const top = y1b < y2; + if (top && left) { + return distance_between({ x: x1, y: y1b }, { x: x2b, y: y2 }); + } else if (left && bottom) { + return distance_between({ x: x1, y: y1 }, { x: x2b, y: y2b }); + } else if (bottom && right) { + return distance_between({ x: x1b, y: y1 }, { x: x2, y: y2b }); + } else if (right && top) { + return distance_between({ x: x1b, y: y1b }, { x: x2, y: y2 }); + } else if (left) { + return x1 - x2b; + } else if (right) { + return x2 - x1b; + } else if (bottom) { + return y1 - y2b; + } else if (top) { + return y2 - y1b; + } + return 0; +} +__name(distance_between_rect, "distance_between_rect"); +function distance_between(a, b) { + return new Ray(a, b).distance; +} +__name(distance_between, "distance_between"); +function grids_between_tokens(a, b) { + return Math.floor(distance_between_rect(a, b) / canvas.grid.size) + 1; +} +__name(grids_between_tokens, "grids_between_tokens"); +function tokens_close_enough(a, b, maxDistance) { + const distance = grids_between_tokens(a, b); + return maxDistance >= distance; +} +__name(tokens_close_enough, "tokens_close_enough"); +async function runMacro(macroId, macroData) { + let macro; + if (macroId.startsWith("Compendium")) { + let packArray = macroId.split("."); + let compendium = game.packs.get(`${packArray[1]}.${packArray[2]}`); + if (!compendium) { + throw custom_error(`Compendium ${packArray[1]}.${packArray[2]} was not found`); + } + let findMacro = (await compendium.getDocuments()).find((m) => m.name === packArray[3] || m.id === packArray[3]); + if (!findMacro) { + throw custom_error(`The "${packArray[3]}" macro was not found in Compendium ${packArray[1]}.${packArray[2]}`); + } + macro = new Macro(findMacro?.toObject()); + macro.ownership.default = CONST.DOCUMENT_PERMISSION_LEVELS.OWNER; + } else { + macro = game.macros.getName(macroId); + if (!macro) { + throw custom_error(`Could not find macro with name "${macroId}"`); + } + } + let result = false; + try { + result = await macro.execute(macroData); + } catch (err) { + custom_warning(`Error when executing macro ${macroId}! +${err}`, true); + } + return result; +} +__name(runMacro, "runMacro"); +function getOwnedCharacters(user = false) { + user = user || game.user; + return game.actors.filter((actor) => { + return actor.ownership?.[user.id] === CONST.DOCUMENT_PERMISSION_LEVELS.OWNER && actor.prototypeToken.actorLink; + }).sort((a, b) => { + return b._stats.modifiedTime - a._stats.modifiedTime; + }); +} +__name(getOwnedCharacters, "getOwnedCharacters"); +function getUserCharacter(user = false) { + user = user || game.user; + return user.character || (user.isGM ? false : getOwnedCharacters(user)?.[0] ?? false); +} +__name(getUserCharacter, "getUserCharacter"); +async function createFoldersFromNames(folders, type = "Actor") { + let lastFolder = false; + for (const folder of folders) { + let actualFolder = game.folders.getName(folder); + if (!actualFolder) { + const folderData = { name: folder, type, sorting: "a" }; + if (lastFolder) { + folderData.parent = lastFolder.id; + } + actualFolder = await Folder.create(folderData); + } + lastFolder = actualFolder; + } + if (lastFolder) { + return lastFolder; + } +} +__name(createFoldersFromNames, "createFoldersFromNames"); +function getSourceActorFromDropData(dropData) { + if (dropData.uuid) { + const doc = fromUuidSync(dropData.uuid); + return doc instanceof Actor ? doc : doc.parent; + } else if (dropData.tokenId) { + if (dropData.sceneId) { + const uuid = `Scene.${dropData.sceneId}.Token.${dropData.tokenId}`; + return fromUuidSync(uuid)?.actor; + } + return canvas.tokens.get(dropData.tokenId).actor; + } else if (dropData.actorId) { + return game.actors.get(dropData.actorId); + } + return false; +} +__name(getSourceActorFromDropData, "getSourceActorFromDropData"); +const ActorDropSelect_svelte_svelte_type_style_lang = ""; +function get_each_context$2(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[13] = list[i]; + return child_ctx; +} +__name(get_each_context$2, "get_each_context$2"); +function create_else_block_2(ctx) { + let p; + return { + c() { + p = element("p"); + p.textContent = `${localize("ITEM-PILES.Trade.Prompt.DropActor")}`; + }, + m(target, anchor) { + insert(target, p, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_else_block_2, "create_else_block_2"); +function create_if_block_1$3(ctx) { + let div; + let t; + let if_block0 = ( + /*actor*/ + ctx[0].img && create_if_block_4$2(ctx) + ); + function select_block_type_1(ctx2, dirty) { + if ( + /*multipleActors*/ + ctx2[4] + ) + return create_if_block_2$2; + return create_else_block_1$2; + } + __name(select_block_type_1, "select_block_type_1"); + let current_block_type = select_block_type_1(ctx); + let if_block1 = current_block_type(ctx); + return { + c() { + div = element("div"); + if (if_block0) + if_block0.c(); + t = space(); + if_block1.c(); + attr(div, "class", "align-center-col"); + }, + m(target, anchor) { + insert(target, div, anchor); + if (if_block0) + if_block0.m(div, null); + append(div, t); + if_block1.m(div, null); + }, + p(ctx2, dirty) { + if ( + /*actor*/ + ctx2[0].img + ) { + if (if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0 = create_if_block_4$2(ctx2); + if_block0.c(); + if_block0.m(div, t); + } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; + } + if_block1.p(ctx2, dirty); + }, + d(detaching) { + if (detaching) + detach(div); + if (if_block0) + if_block0.d(); + if_block1.d(); + } + }; +} +__name(create_if_block_1$3, "create_if_block_1$3"); +function create_if_block_4$2(ctx) { + let img; + let img_src_value; + return { + c() { + img = element("img"); + if (!src_url_equal(img.src, img_src_value = /*actor*/ + ctx[0].img)) + attr(img, "src", img_src_value); + attr(img, "class", "svelte-1fiqefb"); + }, + m(target, anchor) { + insert(target, img, anchor); + }, + p(ctx2, dirty) { + if (dirty & /*actor, actors*/ + 3 && !src_url_equal(img.src, img_src_value = /*actor*/ + ctx2[0].img)) { + attr(img, "src", img_src_value); + } + }, + d(detaching) { + if (detaching) + detach(img); + } + }; +} +__name(create_if_block_4$2, "create_if_block_4$2"); +function create_else_block_1$2(ctx) { + let span; + let t_value = ( + /*actor*/ + ctx[0].name + "" + ); + let t; + return { + c() { + span = element("span"); + t = text(t_value); + attr(span, "class", "svelte-1fiqefb"); + }, + m(target, anchor) { + insert(target, span, anchor); + append(span, t); + }, + p(ctx2, dirty) { + if (dirty & /*actor*/ + 1 && t_value !== (t_value = /*actor*/ + ctx2[0].name + "")) + set_data(t, t_value); + }, + d(detaching) { + if (detaching) + detach(span); + } + }; +} +__name(create_else_block_1$2, "create_else_block_1$2"); +function create_if_block_2$2(ctx) { + let span; + function select_block_type_2(ctx2, dirty) { + if ( + /*changingActor*/ + ctx2[2] + ) + return create_if_block_3$2; + return create_else_block$4; + } + __name(select_block_type_2, "select_block_type_2"); + let current_block_type = select_block_type_2(ctx); + let if_block = current_block_type(ctx); + return { + c() { + span = element("span"); + if_block.c(); + attr(span, "class", "svelte-1fiqefb"); + }, + m(target, anchor) { + insert(target, span, anchor); + if_block.m(span, null); + }, + p(ctx2, dirty) { + if (current_block_type === (current_block_type = select_block_type_2(ctx2)) && if_block) { + if_block.p(ctx2, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx2); + if (if_block) { + if_block.c(); + if_block.m(span, null); + } + } + }, + d(detaching) { + if (detaching) + detach(span); + if_block.d(); + } + }; +} +__name(create_if_block_2$2, "create_if_block_2$2"); +function create_else_block$4(ctx) { + let a; + let t_value = ( + /*actor*/ + ctx[0].name + "" + ); + let t; + let mounted; + let dispose; + return { + c() { + a = element("a"); + t = text(t_value); + attr(a, "class", "item-piles-change-actor item-piles-highlight"); + }, + m(target, anchor) { + insert(target, a, anchor); + append(a, t); + if (!mounted) { + dispose = listen( + a, + "click", + /*click_handler*/ + ctx[12] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*actor*/ + 1 && t_value !== (t_value = /*actor*/ + ctx2[0].name + "")) + set_data(t, t_value); + }, + d(detaching) { + if (detaching) + detach(a); + mounted = false; + dispose(); + } + }; +} +__name(create_else_block$4, "create_else_block$4"); +function create_if_block_3$2(ctx) { + let select; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let mounted; + let dispose; + let each_value = ( + /*actors*/ + ctx[1] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*potentialActor*/ + ctx2[13].id + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$2(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$2(key, child_ctx)); + } + return { + c() { + select = element("select"); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + attr(select, "class", "item-piles-change-actor-select svelte-1fiqefb"); + if ( + /*actor*/ + ctx[0] === void 0 + ) + add_render_callback(() => ( + /*select_change_handler*/ + ctx[10].call(select) + )); + }, + m(target, anchor) { + insert(target, select, anchor); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(select, null); + } + } + select_option( + select, + /*actor*/ + ctx[0], + true + ); + if (!mounted) { + dispose = [ + listen( + select, + "change", + /*select_change_handler*/ + ctx[10] + ), + listen( + select, + "change", + /*change_handler*/ + ctx[11] + ) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*actors*/ + 2) { + each_value = /*actors*/ + ctx2[1]; + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, select, destroy_block, create_each_block$2, null, get_each_context$2); + } + if (dirty & /*actor, actors*/ + 3) { + select_option( + select, + /*actor*/ + ctx2[0] + ); + } + }, + d(detaching) { + if (detaching) + detach(select); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + mounted = false; + run_all(dispose); + } + }; +} +__name(create_if_block_3$2, "create_if_block_3$2"); +function create_each_block$2(key_1, ctx) { + let option; + let t_value = ( + /*potentialActor*/ + ctx[13].name + "" + ); + let t; + let option_value_value; + return { + key: key_1, + first: null, + c() { + option = element("option"); + t = text(t_value); + option.__value = option_value_value = /*potentialActor*/ + ctx[13]; + option.value = option.__value; + this.first = option; + }, + m(target, anchor) { + insert(target, option, anchor); + append(option, t); + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty & /*actors*/ + 2 && t_value !== (t_value = /*potentialActor*/ + ctx[13].name + "")) + set_data(t, t_value); + if (dirty & /*actors*/ + 2 && option_value_value !== (option_value_value = /*potentialActor*/ + ctx[13])) { + option.__value = option_value_value; + option.value = option.__value; + } + }, + d(detaching) { + if (detaching) + detach(option); + } + }; +} +__name(create_each_block$2, "create_each_block$2"); +function create_if_block$4(ctx) { + let div; + let button; + let i; + let t0; + let t1_value = localize("ITEM-PILES.Trade.Prompt.PickToken") + ""; + let t1; + let mounted; + let dispose; + return { + c() { + div = element("div"); + button = element("button"); + i = element("i"); + t0 = space(); + t1 = text(t1_value); + attr(i, "class", "fas fa-expand"); + attr(button, "type", "button"); + attr(div, "class", "item-piles-flexrow"); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, button); + append(button, i); + append(button, t0); + append(button, t1); + if (!mounted) { + dispose = listen( + button, + "click", + /*setActorFromSelectedToken*/ + ctx[6] + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(div); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block$4, "create_if_block$4"); +function create_fragment$4(ctx) { + let div1; + let div0; + let t; + let mounted; + let dispose; + function select_block_type(ctx2, dirty) { + if ( + /*actor*/ + ctx2[0] + ) + return create_if_block_1$3; + return create_else_block_2; + } + __name(select_block_type, "select_block_type"); + let current_block_type = select_block_type(ctx); + let if_block0 = current_block_type(ctx); + let if_block1 = ( + /*hasUnlinkedTokenOwnership*/ + ctx[5] && create_if_block$4(ctx) + ); + return { + c() { + div1 = element("div"); + div0 = element("div"); + if_block0.c(); + t = space(); + if (if_block1) + if_block1.c(); + attr(div0, "class", "form-group item-piles-actor-container align-center-row svelte-1fiqefb"); + toggle_class( + div0, + "item-piles-box-highlight", + /*counter*/ + ctx[3] > 0 + ); + attr(div1, "class", "item-piles-bottom-divider"); + }, + m(target, anchor) { + insert(target, div1, anchor); + append(div1, div0); + if_block0.m(div0, null); + append(div1, t); + if (if_block1) + if_block1.m(div1, null); + if (!mounted) { + dispose = [ + listen( + div0, + "dragenter", + /*dragEnter*/ + ctx[8] + ), + listen( + div0, + "dragleave", + /*dragLeave*/ + ctx[9] + ), + listen(div0, "dragover", preventDefault), + listen(div0, "dragstart", preventDefault), + listen( + div0, + "drop", + /*dropData*/ + ctx[7] + ) + ]; + mounted = true; + } + }, + p(ctx2, [dirty]) { + if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0.d(1); + if_block0 = current_block_type(ctx2); + if (if_block0) { + if_block0.c(); + if_block0.m(div0, null); + } + } + if (dirty & /*counter*/ + 8) { + toggle_class( + div0, + "item-piles-box-highlight", + /*counter*/ + ctx2[3] > 0 + ); + } + if ( + /*hasUnlinkedTokenOwnership*/ + ctx2[5] + ) + if_block1.p(ctx2, dirty); + }, + i: noop, + o: noop, + d(detaching) { + if (detaching) + detach(div1); + if_block0.d(); + if (if_block1) + if_block1.d(); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_fragment$4, "create_fragment$4"); +function preventDefault(event) { + event.preventDefault(); +} +__name(preventDefault, "preventDefault"); +function instance$4($$self, $$props, $$invalidate) { + let { actor } = $$props; + let { actors } = $$props; + let changingActor = false; + let multipleActors = actors.length > 1 && !game.user.isGM; + let hasUnlinkedTokenOwnership = actors.filter((a) => !a.prototypeToken.actorLink).length > 0; + function setActorFromSelectedToken() { + if (canvas.tokens.controlled.length === 0) + return; + $$invalidate(0, actor = canvas.tokens.controlled[0].actor); + } + __name(setActorFromSelectedToken, "setActorFromSelectedToken"); + async function dropData(event) { + $$invalidate(3, counter = 0); + let data2; + try { + data2 = JSON.parse(event.dataTransfer.getData("text/plain")); + } catch (err) { + return false; + } + if (data2.type !== "Actor") + return; + $$invalidate(0, actor = getSourceActorFromDropData(data2)); + } + __name(dropData, "dropData"); + let counter = 0; + function dragEnter() { + $$invalidate(3, counter++, counter); + } + __name(dragEnter, "dragEnter"); + function dragLeave() { + $$invalidate(3, counter--, counter); + } + __name(dragLeave, "dragLeave"); + function select_change_handler() { + actor = select_value(this); + $$invalidate(0, actor); + $$invalidate(1, actors); + } + __name(select_change_handler, "select_change_handler"); + const change_handler = /* @__PURE__ */ __name(() => { + $$invalidate(2, changingActor = false); + }, "change_handler"); + const click_handler = /* @__PURE__ */ __name(() => { + $$invalidate(2, changingActor = true); + }, "click_handler"); + $$self.$$set = ($$props2) => { + if ("actor" in $$props2) + $$invalidate(0, actor = $$props2.actor); + if ("actors" in $$props2) + $$invalidate(1, actors = $$props2.actors); + }; + return [ + actor, + actors, + changingActor, + counter, + multipleActors, + hasUnlinkedTokenOwnership, + setActorFromSelectedToken, + dropData, + dragEnter, + dragLeave, + select_change_handler, + change_handler, + click_handler + ]; +} +__name(instance$4, "instance$4"); +class ActorDropSelect extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$4, create_fragment$4, safe_not_equal, { actor: 0, actors: 1 }); + } +} +__name(ActorDropSelect, "ActorDropSelect"); +const tradeDialogPrompt_svelte_svelte_type_style_lang = ""; +function get_each_context$1(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[13] = list[i]; + return child_ctx; +} +__name(get_each_context$1, "get_each_context$1"); +function create_each_block$1(key_1, ctx) { + let option; + let t_value = ( + /*potentialUser*/ + ctx[13].name + "" + ); + let t; + let option_value_value; + return { + key: key_1, + first: null, + c() { + option = element("option"); + t = text(t_value); + option.__value = option_value_value = /*potentialUser*/ + ctx[13]; + option.value = option.__value; + this.first = option; + }, + m(target, anchor) { + insert(target, option, anchor); + append(option, t); + }, + p(new_ctx, dirty) { + ctx = new_ctx; + if (dirty & /*users*/ + 4 && t_value !== (t_value = /*potentialUser*/ + ctx[13].name + "")) + set_data(t, t_value); + if (dirty & /*users*/ + 4 && option_value_value !== (option_value_value = /*potentialUser*/ + ctx[13])) { + option.__value = option_value_value; + option.value = option.__value; + } + }, + d(detaching) { + if (detaching) + detach(option); + } + }; +} +__name(create_each_block$1, "create_each_block$1"); +function create_else_block$3(ctx) { + let p; + return { + c() { + p = element("p"); + p.textContent = `${localize("ITEM-PILES.Trade.Prompt.PickActor")}`; + }, + m(target, anchor) { + insert(target, p, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_else_block$3, "create_else_block$3"); +function create_if_block$3(ctx) { + let p; + return { + c() { + p = element("p"); + p.textContent = `${localize("ITEM-PILES.Trade.Prompt.PickedActor")}`; + }, + m(target, anchor) { + insert(target, p, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_if_block$3, "create_if_block$3"); +function create_default_slot$2(ctx) { + let div4; + let p0; + let t0; + let p1; + let strong; + let t2; + let p2; + let t4; + let div1; + let div0; + let select; + let each_blocks = []; + let each_1_lookup = /* @__PURE__ */ new Map(); + let t5; + let div3; + let div2; + let label; + let input; + let t6; + let span; + let t8; + let small; + let t10; + let t11; + let actordropselect; + let updating_actor; + let t12; + let footer; + let button; + let i1; + let t13; + let t14_value = localize("ITEM-PILES.Trade.Prompt.Label") + ""; + let t14; + let button_disabled_value; + let current; + let mounted; + let dispose; + let each_value = ( + /*users*/ + ctx[2] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*potentialUser*/ + ctx2[13].id + ), "get_key"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context$1(ctx, each_value, i); + let key = get_key(child_ctx); + each_1_lookup.set(key, each_blocks[i] = create_each_block$1(key, child_ctx)); + } + function select_block_type(ctx2, dirty) { + if ( + /*actor*/ + ctx2[5] + ) + return create_if_block$3; + return create_else_block$3; + } + __name(select_block_type, "select_block_type"); + let current_block_type = select_block_type(ctx); + let if_block = current_block_type(ctx); + function actordropselect_actor_binding(value) { + ctx[9](value); + } + __name(actordropselect_actor_binding, "actordropselect_actor_binding"); + let actordropselect_props = { actors: ( + /*actors*/ + ctx[4] + ) }; + if ( + /*actor*/ + ctx[5] !== void 0 + ) { + actordropselect_props.actor = /*actor*/ + ctx[5]; + } + actordropselect = new ActorDropSelect({ props: actordropselect_props }); + binding_callbacks.push(() => bind(actordropselect, "actor", actordropselect_actor_binding)); + return { + c() { + div4 = element("div"); + p0 = element("p"); + p0.innerHTML = ``; + t0 = space(); + p1 = element("p"); + strong = element("strong"); + strong.textContent = `${localize("ITEM-PILES.Trade.Prompt.Title")}`; + t2 = space(); + p2 = element("p"); + p2.textContent = `${localize("ITEM-PILES.Trade.Prompt.User")}`; + t4 = space(); + div1 = element("div"); + div0 = element("div"); + select = element("select"); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + t5 = space(); + div3 = element("div"); + div2 = element("div"); + label = element("label"); + input = element("input"); + t6 = space(); + span = element("span"); + span.textContent = `${localize("ITEM-PILES.Trade.Private")}`; + t8 = space(); + small = element("small"); + small.textContent = `${localize("ITEM-PILES.Trade.PrivateExplanation")}`; + t10 = space(); + if_block.c(); + t11 = space(); + create_component(actordropselect.$$.fragment); + t12 = space(); + footer = element("footer"); + button = element("button"); + i1 = element("i"); + t13 = space(); + t14 = text(t14_value); + set_style(strong, "font-size", "1.2rem"); + set_style(p1, "margin-bottom", "1rem"); + attr(select, "name", "user"); + set_style(select, "width", "66%"); + if ( + /*user*/ + ctx[3] === void 0 + ) + add_render_callback(() => ( + /*select_change_handler*/ + ctx[7].call(select) + )); + attr(div0, "class", "form-group align-center-row"); + attr(div1, "class", "item-piles-bottom-divider"); + attr(input, "name", "private"); + attr(input, "type", "checkbox"); + attr(label, "class", "align-center-row"); + attr(div2, "class", "form-group align-center-col"); + attr(div3, "class", "item-piles-bottom-divider"); + attr(i1, "class", "fas fa-check"); + button.disabled = button_disabled_value = !/*actor*/ + ctx[5]; + attr(button, "type", "button"); + attr(button, "class", "svelte-r6pfu5"); + attr(footer, "class", "sheet-footer item-piles-flexrow"); + attr(div4, "class", "item-piles-flexcol trade-dialog svelte-r6pfu5"); + }, + m(target, anchor) { + insert(target, div4, anchor); + append(div4, p0); + append(div4, t0); + append(div4, p1); + append(p1, strong); + append(div4, t2); + append(div4, p2); + append(div4, t4); + append(div4, div1); + append(div1, div0); + append(div0, select); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(select, null); + } + } + select_option( + select, + /*user*/ + ctx[3], + true + ); + append(div4, t5); + append(div4, div3); + append(div3, div2); + append(div2, label); + append(label, input); + input.checked = /*isPrivate*/ + ctx[1]; + append(label, t6); + append(label, span); + append(div2, t8); + append(div2, small); + append(div4, t10); + if_block.m(div4, null); + append(div4, t11); + mount_component(actordropselect, div4, null); + append(div4, t12); + append(div4, footer); + append(footer, button); + append(button, i1); + append(button, t13); + append(button, t14); + current = true; + if (!mounted) { + dispose = [ + listen( + select, + "change", + /*select_change_handler*/ + ctx[7] + ), + listen( + input, + "change", + /*input_change_handler*/ + ctx[8] + ), + listen( + button, + "click", + /*requestTrade*/ + ctx[6], + { once: true } + ) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*users*/ + 4) { + each_value = /*users*/ + ctx2[2]; + each_blocks = update_keyed_each(each_blocks, dirty, get_key, 1, ctx2, each_value, each_1_lookup, select, destroy_block, create_each_block$1, null, get_each_context$1); + } + if (dirty & /*user, users*/ + 12) { + select_option( + select, + /*user*/ + ctx2[3] + ); + } + if (dirty & /*isPrivate*/ + 2) { + input.checked = /*isPrivate*/ + ctx2[1]; + } + if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block) { + if_block.p(ctx2, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx2); + if (if_block) { + if_block.c(); + if_block.m(div4, t11); + } + } + const actordropselect_changes = {}; + if (dirty & /*actors*/ + 16) + actordropselect_changes.actors = /*actors*/ + ctx2[4]; + if (!updating_actor && dirty & /*actor*/ + 32) { + updating_actor = true; + actordropselect_changes.actor = /*actor*/ + ctx2[5]; + add_flush_callback(() => updating_actor = false); + } + actordropselect.$set(actordropselect_changes); + if (!current || dirty & /*actor*/ + 32 && button_disabled_value !== (button_disabled_value = !/*actor*/ + ctx2[5])) { + button.disabled = button_disabled_value; + } + }, + i(local) { + if (current) + return; + transition_in(actordropselect.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(actordropselect.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(div4); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + if_block.d(); + destroy_component(actordropselect); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$2, "create_default_slot$2"); +function create_fragment$3(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[10](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot$2] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, [dirty]) { + const applicationshell_changes = {}; + if (dirty & /*$$scope, actor, actors, isPrivate, user, users*/ + 65598) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment$3, "create_fragment$3"); +function instance$3($$self, $$props, $$invalidate) { + const { application } = getContext("#external"); + let { elementRoot } = $$props; + let { isPrivate } = $$props; + let { users } = $$props; + let { user } = $$props; + let { actors } = $$props; + let { actor } = $$props; + let isGM = game.user.isGM; + users = game.users.filter((user2) => user2.active && user2 !== game.user); + user = user || users?.[0] || false; + actors = actors || game.actors.filter((actor2) => actor2.isOwner); + actor = actor || game.user.character || (!isGM ? actors?.[0] : false); + function requestTrade() { + application.options.resolve({ user, actor, isPrivate }); + application.close(); + } + __name(requestTrade, "requestTrade"); + function select_change_handler() { + user = select_value(this); + $$invalidate(3, user); + $$invalidate(2, users); + } + __name(select_change_handler, "select_change_handler"); + function input_change_handler() { + isPrivate = this.checked; + $$invalidate(1, isPrivate); + } + __name(input_change_handler, "input_change_handler"); + function actordropselect_actor_binding(value) { + actor = value; + $$invalidate(5, actor); + } + __name(actordropselect_actor_binding, "actordropselect_actor_binding"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + if ("isPrivate" in $$props2) + $$invalidate(1, isPrivate = $$props2.isPrivate); + if ("users" in $$props2) + $$invalidate(2, users = $$props2.users); + if ("user" in $$props2) + $$invalidate(3, user = $$props2.user); + if ("actors" in $$props2) + $$invalidate(4, actors = $$props2.actors); + if ("actor" in $$props2) + $$invalidate(5, actor = $$props2.actor); + }; + return [ + elementRoot, + isPrivate, + users, + user, + actors, + actor, + requestTrade, + select_change_handler, + input_change_handler, + actordropselect_actor_binding, + applicationshell_elementRoot_binding + ]; +} +__name(instance$3, "instance$3"); +class Trade_dialog_prompt extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$3, create_fragment$3, safe_not_equal, { + elementRoot: 0, + isPrivate: 1, + users: 2, + user: 3, + actors: 4, + actor: 5 + }); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } + get isPrivate() { + return this.$$.ctx[1]; + } + set isPrivate(isPrivate) { + this.$$set({ isPrivate }); + flush(); + } + get users() { + return this.$$.ctx[2]; + } + set users(users) { + this.$$set({ users }); + flush(); + } + get user() { + return this.$$.ctx[3]; + } + set user(user) { + this.$$set({ user }); + flush(); + } + get actors() { + return this.$$.ctx[4]; + } + set actors(actors) { + this.$$set({ actors }); + flush(); + } + get actor() { + return this.$$.ctx[5]; + } + set actor(actor) { + this.$$set({ actor }); + flush(); + } +} +__name(Trade_dialog_prompt, "Trade_dialog_prompt"); +function is_date(obj) { + return Object.prototype.toString.call(obj) === "[object Date]"; +} +__name(is_date, "is_date"); +function get_interpolator(a, b) { + if (a === b || a !== a) + return () => a; + const type = typeof a; + if (type !== typeof b || Array.isArray(a) !== Array.isArray(b)) { + throw new Error("Cannot interpolate values of different type"); + } + if (Array.isArray(a)) { + const arr = b.map((bi, i) => { + return get_interpolator(a[i], bi); + }); + return (t) => arr.map((fn) => fn(t)); + } + if (type === "object") { + if (!a || !b) + throw new Error("Object cannot be null"); + if (is_date(a) && is_date(b)) { + a = a.getTime(); + b = b.getTime(); + const delta = b - a; + return (t) => new Date(a + t * delta); + } + const keys = Object.keys(b); + const interpolators = {}; + keys.forEach((key) => { + interpolators[key] = get_interpolator(a[key], b[key]); + }); + return (t) => { + const result = {}; + keys.forEach((key) => { + result[key] = interpolators[key](t); + }); + return result; + }; + } + if (type === "number") { + const delta = b - a; + return (t) => a + t * delta; + } + throw new Error(`Cannot interpolate ${type} values`); +} +__name(get_interpolator, "get_interpolator"); +function tweened(value, defaults = {}) { + const store = writable$1(value); + let task; + let target_value = value; + function set(new_value, opts) { + if (value == null) { + store.set(value = new_value); + return Promise.resolve(); + } + target_value = new_value; + let previous_task = task; + let started = false; + let { delay = 0, duration = 400, easing = identity, interpolate = get_interpolator } = assign(assign({}, defaults), opts); + if (duration === 0) { + if (previous_task) { + previous_task.abort(); + previous_task = null; + } + store.set(value = target_value); + return Promise.resolve(); + } + const start = now() + delay; + let fn; + task = loop$1((now2) => { + if (now2 < start) + return true; + if (!started) { + fn = interpolate(value, new_value); + if (typeof duration === "function") + duration = duration(value, new_value); + started = true; + } + if (previous_task) { + previous_task.abort(); + previous_task = null; + } + const elapsed = now2 - start; + if (elapsed > duration) { + store.set(value = new_value); + return false; + } + store.set(value = fn(easing(elapsed / duration))); + return true; + }); + return task.promise; + } + __name(set, "set"); + return { + set, + update: (fn, opts) => set(fn(target_value, value), opts), + subscribe: store.subscribe + }; +} +__name(tweened, "tweened"); +const tradeDialogRequest_svelte_svelte_type_style_lang = ""; +function create_else_block_1$1(ctx) { + let p; + let t_value = localize("ITEM-PILES.Trade.Request.Content", { + trading_user_name: ( + /*tradingUser*/ + ctx[5].name + ), + trading_actor_name: ( + /*tradingActor*/ + ctx[4].name + ) + }) + ""; + let t; + return { + c() { + p = element("p"); + t = text(t_value); + }, + m(target, anchor) { + insert(target, p, anchor); + append(p, t); + }, + p(ctx2, dirty) { + if (dirty & /*tradingUser, tradingActor*/ + 48 && t_value !== (t_value = localize("ITEM-PILES.Trade.Request.Content", { + trading_user_name: ( + /*tradingUser*/ + ctx2[5].name + ), + trading_actor_name: ( + /*tradingActor*/ + ctx2[4].name + ) + }) + "")) + set_data(t, t_value); + }, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_else_block_1$1, "create_else_block_1$1"); +function create_if_block_1$2(ctx) { + let p; + let raw_value = localize("ITEM-PILES.Trade.Request.PrivateContent", { + trading_user_name: ( + /*tradingUser*/ + ctx[5].name + ), + trading_actor_name: ( + /*tradingActor*/ + ctx[4].name + ) + }) + ""; + return { + c() { + p = element("p"); + }, + m(target, anchor) { + insert(target, p, anchor); + p.innerHTML = raw_value; + }, + p(ctx2, dirty) { + if (dirty & /*tradingUser, tradingActor*/ + 48 && raw_value !== (raw_value = localize("ITEM-PILES.Trade.Request.PrivateContent", { + trading_user_name: ( + /*tradingUser*/ + ctx2[5].name + ), + trading_actor_name: ( + /*tradingActor*/ + ctx2[4].name + ) + }) + "")) + p.innerHTML = raw_value; + }, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_if_block_1$2, "create_if_block_1$2"); +function create_else_block$2(ctx) { + let p; + return { + c() { + p = element("p"); + p.textContent = `${localize("ITEM-PILES.Trade.Prompt.PickActor")}`; + }, + m(target, anchor) { + insert(target, p, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_else_block$2, "create_else_block$2"); +function create_if_block$2(ctx) { + let p; + return { + c() { + p = element("p"); + p.textContent = `${localize("ITEM-PILES.Trade.Prompt.PickedActor")}`; + }, + m(target, anchor) { + insert(target, p, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(p); + } + }; +} +__name(create_if_block$2, "create_if_block$2"); +function create_default_slot$1(ctx) { + let div2; + let p0; + let t0; + let p1; + let strong; + let t2; + let div0; + let t3; + let p2; + let t5; + let t6; + let actordropselect; + let updating_actor; + let t7; + let footer; + let button0; + let i1; + let t8; + let t9_value = localize("ITEM-PILES.Trade.Accept") + ""; + let t9; + let button0_disabled_value; + let t10; + let button1; + let i2; + let t11; + let t12_value = localize("ITEM-PILES.Trade.Decline") + ""; + let t12; + let t13; + let button2; + let i3; + let t14; + let t15_value = localize("ITEM-PILES.Trade.Mute") + ""; + let t15; + let t16; + let div1; + let span; + let current; + let mounted; + let dispose; + function select_block_type(ctx2, dirty) { + if ( + /*isPrivate*/ + ctx2[3] + ) + return create_if_block_1$2; + return create_else_block_1$1; + } + __name(select_block_type, "select_block_type"); + let current_block_type = select_block_type(ctx); + let if_block0 = current_block_type(ctx); + function select_block_type_1(ctx2, dirty) { + if ( + /*actor*/ + ctx2[2] + ) + return create_if_block$2; + return create_else_block$2; + } + __name(select_block_type_1, "select_block_type_1"); + let current_block_type_1 = select_block_type_1(ctx); + let if_block1 = current_block_type_1(ctx); + function actordropselect_actor_binding(value) { + ctx[14](value); + } + __name(actordropselect_actor_binding, "actordropselect_actor_binding"); + let actordropselect_props = { actors: ( + /*actors*/ + ctx[1] + ) }; + if ( + /*actor*/ + ctx[2] !== void 0 + ) { + actordropselect_props.actor = /*actor*/ + ctx[2]; + } + actordropselect = new ActorDropSelect({ props: actordropselect_props }); + binding_callbacks.push(() => bind(actordropselect, "actor", actordropselect_actor_binding)); + return { + c() { + div2 = element("div"); + p0 = element("p"); + p0.innerHTML = ``; + t0 = space(); + p1 = element("p"); + strong = element("strong"); + strong.textContent = `${localize("ITEM-PILES.Trade.Request.Title")}`; + t2 = space(); + div0 = element("div"); + if_block0.c(); + t3 = space(); + p2 = element("p"); + p2.textContent = `${localize("ITEM-PILES.Trade.Request.AcceptQuery")}`; + t5 = space(); + if_block1.c(); + t6 = space(); + create_component(actordropselect.$$.fragment); + t7 = space(); + footer = element("footer"); + button0 = element("button"); + i1 = element("i"); + t8 = space(); + t9 = text(t9_value); + t10 = space(); + button1 = element("button"); + i2 = element("i"); + t11 = space(); + t12 = text(t12_value); + t13 = space(); + button2 = element("button"); + i3 = element("i"); + t14 = space(); + t15 = text(t15_value); + t16 = space(); + div1 = element("div"); + span = element("span"); + set_style(strong, "font-size", "1.2rem"); + set_style(p1, "margin-bottom", "1rem"); + attr(div0, "class", "item-piles-bottom-divider"); + attr(i1, "class", "fas fa-check"); + button0.disabled = button0_disabled_value = !/*actor*/ + ctx[2]; + attr(button0, "type", "button"); + attr(button0, "class", "svelte-bu4abp"); + attr(i2, "class", "fas fa-times"); + attr(button1, "type", "button"); + attr(button1, "class", "svelte-bu4abp"); + attr(i3, "class", "fas fa-comment-slash"); + attr(button2, "type", "button"); + attr(button2, "class", "svelte-bu4abp"); + attr(footer, "class", "sheet-footer item-piles-flexrow"); + attr(span, "class", "progress-bar svelte-bu4abp"); + set_style( + span, + "width", + /*actualProgress*/ + ctx[6] + "%" + ); + attr(div1, "class", "item-piles-progress svelte-bu4abp"); + set_style(div1, "flex", "1 0 auto"); + toggle_class( + div1, + "active", + /*actualProgress*/ + ctx[6] > 0 + ); + attr(div2, "class", "item-piles-flexcol trade-dialog svelte-bu4abp"); + }, + m(target, anchor) { + insert(target, div2, anchor); + append(div2, p0); + append(div2, t0); + append(div2, p1); + append(p1, strong); + append(div2, t2); + append(div2, div0); + if_block0.m(div0, null); + append(div0, t3); + append(div0, p2); + append(div2, t5); + if_block1.m(div2, null); + append(div2, t6); + mount_component(actordropselect, div2, null); + append(div2, t7); + append(div2, footer); + append(footer, button0); + append(button0, i1); + append(button0, t8); + append(button0, t9); + append(footer, t10); + append(footer, button1); + append(button1, i2); + append(button1, t11); + append(button1, t12); + append(footer, t13); + append(footer, button2); + append(button2, i3); + append(button2, t14); + append(button2, t15); + append(div2, t16); + append(div2, div1); + append(div1, span); + current = true; + if (!mounted) { + dispose = [ + listen( + button0, + "click", + /*accept*/ + ctx[7], + { once: true } + ), + listen( + button1, + "click", + /*decline*/ + ctx[8], + { once: true } + ), + listen( + button2, + "click", + /*mute*/ + ctx[9], + { once: true } + ) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0.d(1); + if_block0 = current_block_type(ctx2); + if (if_block0) { + if_block0.c(); + if_block0.m(div0, t3); + } + } + if (current_block_type_1 === (current_block_type_1 = select_block_type_1(ctx2)) && if_block1) { + if_block1.p(ctx2, dirty); + } else { + if_block1.d(1); + if_block1 = current_block_type_1(ctx2); + if (if_block1) { + if_block1.c(); + if_block1.m(div2, t6); + } + } + const actordropselect_changes = {}; + if (dirty & /*actors*/ + 2) + actordropselect_changes.actors = /*actors*/ + ctx2[1]; + if (!updating_actor && dirty & /*actor*/ + 4) { + updating_actor = true; + actordropselect_changes.actor = /*actor*/ + ctx2[2]; + add_flush_callback(() => updating_actor = false); + } + actordropselect.$set(actordropselect_changes); + if (!current || dirty & /*actor*/ + 4 && button0_disabled_value !== (button0_disabled_value = !/*actor*/ + ctx2[2])) { + button0.disabled = button0_disabled_value; + } + if (!current || dirty & /*actualProgress*/ + 64) { + set_style( + span, + "width", + /*actualProgress*/ + ctx2[6] + "%" + ); + } + if (!current || dirty & /*actualProgress*/ + 64) { + toggle_class( + div1, + "active", + /*actualProgress*/ + ctx2[6] > 0 + ); + } + }, + i(local) { + if (current) + return; + transition_in(actordropselect.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(actordropselect.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(div2); + if_block0.d(); + if_block1.d(); + destroy_component(actordropselect); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_default_slot$1, "create_default_slot$1"); +function create_fragment$2(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[15](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot$1] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, [dirty]) { + const applicationshell_changes = {}; + if (dirty & /*$$scope, actualProgress, actor, actors, tradingUser, tradingActor, isPrivate*/ + 8388734) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment$2, "create_fragment$2"); +function instance$2($$self, $$props, $$invalidate) { + let actualProgress; + let $progress; + const { application } = getContext("#external"); + let { elementRoot } = $$props; + let { isPrivate } = $$props; + let { tradingActor } = $$props; + let { tradingUser } = $$props; + let { users } = $$props; + let { user } = $$props; + let { actors } = $$props; + let { actor } = $$props; + let isGM = game.user.isGM; + users = game.users.filter((user2) => user2.active && user2 !== game.user); + user = user || users?.[0] || false; + actors = actors || game.actors.filter((actor2) => actor2.isOwner); + actor = actor || game.user.character || (!isGM ? actors?.[0] : false); + let done = false; + async function accept() { + application.options.resolve(actor); + close(); + } + __name(accept, "accept"); + async function decline() { + application.options.resolve(false); + close(); + } + __name(decline, "decline"); + async function mute() { + application.options.resolve("mute"); + close(); + } + __name(mute, "mute"); + async function disconnected() { + custom_warning(game.i18n.localize("ITEM-PILES.Trade.Disconnected"), true); + close(); + } + __name(disconnected, "disconnected"); + const progress = tweened(0, { duration: 2e4, easing: identity }); + component_subscribe($$self, progress, (value) => $$invalidate(13, $progress = value)); + let timeout = setTimeout( + () => { + if (done) + return; + progress.set(1); + timeout = setTimeout( + () => { + if (done) + return; + custom_warning(localize("ITEM-PILES.Trade.AutoDecline"), true); + decline(); + }, + 21e3 + ); + }, + 14e3 + ); + const connection = setInterval( + () => { + const user2 = game.users.get(tradingUser.id); + if (!user2.active) { + disconnected(); + } + }, + 100 + ); + function close() { + clearInterval(connection); + clearTimeout(timeout); + done = true; + application.close(); + } + __name(close, "close"); + function actordropselect_actor_binding(value) { + actor = value; + $$invalidate(2, actor); + } + __name(actordropselect_actor_binding, "actordropselect_actor_binding"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + if ("isPrivate" in $$props2) + $$invalidate(3, isPrivate = $$props2.isPrivate); + if ("tradingActor" in $$props2) + $$invalidate(4, tradingActor = $$props2.tradingActor); + if ("tradingUser" in $$props2) + $$invalidate(5, tradingUser = $$props2.tradingUser); + if ("users" in $$props2) + $$invalidate(11, users = $$props2.users); + if ("user" in $$props2) + $$invalidate(12, user = $$props2.user); + if ("actors" in $$props2) + $$invalidate(1, actors = $$props2.actors); + if ("actor" in $$props2) + $$invalidate(2, actor = $$props2.actor); + }; + $$self.$$.update = () => { + if ($$self.$$.dirty & /*$progress*/ + 8192) { + $$invalidate(6, actualProgress = $progress * 100); + } + }; + return [ + elementRoot, + actors, + actor, + isPrivate, + tradingActor, + tradingUser, + actualProgress, + accept, + decline, + mute, + progress, + users, + user, + $progress, + actordropselect_actor_binding, + applicationshell_elementRoot_binding + ]; +} +__name(instance$2, "instance$2"); +class Trade_dialog_request extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$2, create_fragment$2, safe_not_equal, { + elementRoot: 0, + isPrivate: 3, + tradingActor: 4, + tradingUser: 5, + users: 11, + user: 12, + actors: 1, + actor: 2 + }); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } + get isPrivate() { + return this.$$.ctx[3]; + } + set isPrivate(isPrivate) { + this.$$set({ isPrivate }); + flush(); + } + get tradingActor() { + return this.$$.ctx[4]; + } + set tradingActor(tradingActor) { + this.$$set({ tradingActor }); + flush(); + } + get tradingUser() { + return this.$$.ctx[5]; + } + set tradingUser(tradingUser) { + this.$$set({ tradingUser }); + flush(); + } + get users() { + return this.$$.ctx[11]; + } + set users(users) { + this.$$set({ users }); + flush(); + } + get user() { + return this.$$.ctx[12]; + } + set user(user) { + this.$$set({ user }); + flush(); + } + get actors() { + return this.$$.ctx[1]; + } + set actors(actors) { + this.$$set({ actors }); + flush(); + } + get actor() { + return this.$$.ctx[2]; + } + set actor(actor) { + this.$$set({ actor }); + flush(); + } +} +__name(Trade_dialog_request, "Trade_dialog_request"); +class TradePromptDialog extends SvelteApplication { + constructor(tradeOptions, options = {}) { + super({ + svelte: { + class: Trade_dialog_prompt, + target: document.body, + props: { + ...tradeOptions + } + }, + close: () => this.options.resolve?.(null), + ...options + }); + } + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + title: game.i18n.localize("ITEM-PILES.Trade.Title"), + width: 400, + height: "auto", + classes: ["dialog", "item-piles-app"] + }); + } + static show(tradeOptions, options = {}, dialogData = {}) { + return new Promise((resolve) => { + options.resolve = resolve; + new this(tradeOptions, options, dialogData).render(true); + }); + } +} +__name(TradePromptDialog, "TradePromptDialog"); +class TradeRequestDialog extends SvelteApplication { + constructor(tradeOptions, options = {}) { + super({ + svelte: { + class: Trade_dialog_request, + target: document.body, + props: { + ...tradeOptions + } + }, + close: () => this.options.resolve?.(null), + ...options + }); + this.tradeId = tradeOptions.tradeId; + } + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + title: game.i18n.localize("ITEM-PILES.Trade.Title"), + width: 400, + height: "auto", + classes: ["dialog"] + }); + } + static show(tradeOptions, options = {}) { + return new Promise((resolve) => { + options.resolve = resolve; + new this(tradeOptions, options).render(true); + }); + } + static cancel(tradeId) { + for (const app of Object.values(ui.windows)) { + if (app instanceof this && app.tradeId === tradeId) { + app.options.resolve({ type: "cancelled" }); + return app.close(); + } + } + return false; + } +} +__name(TradeRequestDialog, "TradeRequestDialog"); +class TradeStore { + constructor(instigator, leftTrader, rightTrader, publicTradeId, privateTradeId = false, isPrivate = false) { + this.instigator = instigator; + this.publicTradeId = publicTradeId; + this.privateTradeId = privateTradeId; + this.isPrivate = isPrivate; + this.leftTraderUser = leftTrader.user; + this.leftTraderActor = leftTrader.actor; + this.leftTraderItems = writable$1(leftTrader.items ?? []); + this.leftTraderCurrencies = writable$1(leftTrader.currencies ?? []); + this.leftTraderItemCurrencies = writable$1(leftTrader.itemCurrencies ?? []); + this.leftTraderAccepted = writable$1(leftTrader.accepted ?? false); + this.rightTraderUser = rightTrader.user; + this.rightTraderActor = rightTrader.actor; + this.rightTraderItems = writable$1(rightTrader.items ?? []); + this.rightTraderCurrencies = writable$1(rightTrader.currencies ?? []); + this.rightTraderItemCurrencies = writable$1(rightTrader.itemCurrencies ?? []); + this.rightTraderAccepted = writable$1(rightTrader?.accepted ?? false); + } + get isUserParticipant() { + return game.user === this.leftTraderUser || game.user === this.rightTraderUser; + } + get tradeIsAccepted() { + return get_store_value(this.leftTraderAccepted) && get_store_value(this.rightTraderAccepted); + } + static import(tradeData) { + const leftTrader = { + user: game.users.get(tradeData.leftTraderData.user), + actor: fromUuidSync(tradeData.leftTraderData.actor), + items: tradeData.leftTraderData.items, + currencies: tradeData.leftTraderData.currencies, + itemCurrencies: tradeData.leftTraderData.itemCurrencies, + accepted: tradeData.leftTraderData.accepted + }; + const rightTrader = { + user: game.users.get(tradeData.rightTraderData.user), + actor: fromUuidSync(tradeData.rightTraderData.actor), + items: tradeData.rightTraderData.items, + currencies: tradeData.rightTraderData.currencies, + itemCurrencies: tradeData.rightTraderData.itemCurrencies, + accepted: tradeData.rightTraderData.accepted + }; + return new this(tradeData.instigator, leftTrader, rightTrader, tradeData.publicTradeId); + } + export() { + return { + instigator: this.instigator, + publicTradeId: this.publicTradeId, + leftTraderData: { + user: this.leftTraderUser.id, + actor: getUuid(this.leftTraderActor), + items: get_store_value(this.leftTraderItems), + currencies: get_store_value(this.leftTraderCurrencies), + itemCurrencies: get_store_value(this.leftTraderItemCurrencies), + accepted: get_store_value(this.leftTraderAccepted) + }, + rightTraderData: { + user: this.rightTraderUser.id, + actor: getUuid(this.rightTraderActor), + items: get_store_value(this.rightTraderItems), + currencies: get_store_value(this.rightTraderCurrencies), + itemCurrencies: get_store_value(this.rightTraderItemCurrencies), + accepted: get_store_value(this.rightTraderAccepted) + } + }; + } + getTradeData() { + return { + sourceActor: this.leftTraderActor, + targetActor: this.rightTraderActor, + remove: { + items: get_store_value(this.leftTraderItems).concat(get_store_value(this.leftTraderItemCurrencies)), + attributes: get_store_value(this.leftTraderCurrencies) + }, + add: { + items: get_store_value(this.rightTraderItems).concat(get_store_value(this.rightTraderItemCurrencies)), + attributes: get_store_value(this.rightTraderCurrencies) + } + }; + } + getExistingCurrencies() { + return [...get_store_value(this.leftTraderCurrencies), ...get_store_value(this.leftTraderItemCurrencies)]; + } + async toggleAccepted() { + this.leftTraderAccepted.set(!get_store_value(this.leftTraderAccepted)); + } + updateItems(userId, inItems) { + if (userId === game.user.id) + return; + this.leftTraderAccepted.set(false); + this.rightTraderAccepted.set(false); + if (userId === this.leftTraderUser.id) { + this.leftTraderItems.set(inItems); + } + if (userId === this.rightTraderUser.id) { + this.rightTraderItems.set(inItems); + } + } + updateItemCurrencies(userId, itemCurrencies) { + if (userId === game.user.id) + return; + this.leftTraderAccepted.set(false); + this.rightTraderAccepted.set(false); + if (userId === this.leftTraderUser.id) { + this.leftTraderItemCurrencies.set(itemCurrencies); + } + if (userId === this.rightTraderUser.id) { + this.rightTraderItemCurrencies.set(itemCurrencies); + } + } + updateCurrencies(userId, inCurrencies) { + if (userId === game.user.id) + return; + this.leftTraderAccepted.set(false); + this.rightTraderAccepted.set(false); + if (userId === this.leftTraderUser.id) { + this.leftTraderCurrencies.set(inCurrencies); + } + if (userId === this.rightTraderUser.id) { + this.rightTraderCurrencies.set(inCurrencies); + } + } + updateAcceptedState(userId, state) { + if (userId === game.user.id) + return; + if (userId === this.leftTraderUser.id) { + this.leftTraderAccepted.set(state); + } + if (userId === this.rightTraderUser.id) { + this.rightTraderAccepted.set(state); + } + } + addItem(newItem, { uuid = false, quantity = false, currency = false } = {}) { + const items = !currency ? get_store_value(this.leftTraderItems) : get_store_value(this.leftTraderItemCurrencies); + const item = findSimilarItem(items, newItem); + const maxQuantity = game.user.isGM ? Infinity : getItemQuantity(newItem); + if (item && canItemStack(item)) { + if (item.quantity >= maxQuantity) + return; + if (quantity) { + item.quantity = Math.min(quantity ? quantity : item.quantity + 1, maxQuantity); + item.newQuantity = item.quantity; + item.maxQuantity = maxQuantity; + } else { + items.splice(items.indexOf(item)); + } + } else if (!item && quantity) { + items.push({ + id: newItem._id ?? newItem.id, + uuid, + name: newItem.name, + img: newItem?.img ?? "", + type: newItem?.type, + currency, + quantity: quantity ? quantity : 1, + newQuantity: quantity ? quantity : 1, + maxQuantity, + data: newItem instanceof Item ? newItem.toObject() : newItem + }); + } + if (!currency) { + this.leftTraderItems.set(items); + } else { + this.leftTraderItemCurrencies.set(items); + } + } + addAttribute(newCurrency) { + const currencies = get_store_value(this.leftTraderCurrencies); + const existingCurrency = currencies.find((currency) => currency.path === newCurrency.path); + if (existingCurrency) { + existingCurrency.quantity = newCurrency.quantity; + existingCurrency.newQuantity = newCurrency.quantity; + } else { + currencies.push(newCurrency); + } + currencies.sort((a, b) => a.index - b.index); + this.leftTraderCurrencies.set(currencies); + } + removeEntry(entry) { + if (entry.id) { + if (!entry.currency) { + const items = get_store_value(this.leftTraderItems).filter((item) => item.id !== entry.id); + this.leftTraderItems.set(items); + } else { + const items = get_store_value(this.leftTraderItemCurrencies).filter((item) => item.id !== entry.id); + this.leftTraderItemCurrencies.set(items); + } + } else { + const items = get_store_value(this.leftTraderCurrencies).filter((currency) => currency.path !== entry.path); + this.leftTraderCurrencies.set(items); + } + } +} +__name(TradeStore, "TradeStore"); +function create_if_block_4$1(ctx) { + let div; + let a; + let mounted; + let dispose; + return { + c() { + div = element("div"); + a = element("a"); + a.innerHTML = ``; + attr(a, "class", "item-piles-clickable-red"); + set_style(div, "flex", "0 1 auto"); + set_style(div, "margin", "0 6px"); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, a); + if (!mounted) { + dispose = listen( + a, + "click", + /*click_handler_1*/ + ctx[8] + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(div); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_4$1, "create_if_block_4$1"); +function create_if_block_2$1(ctx) { + let div; + let if_block = ( + /*data*/ + ctx[0].editing && create_if_block_3$1(ctx) + ); + return { + c() { + div = element("div"); + if (if_block) + if_block.c(); + set_style(div, "flex", "0 1 17px"); + set_style(div, "margin", "0 5px"); + }, + m(target, anchor) { + insert(target, div, anchor); + if (if_block) + if_block.m(div, null); + }, + p(ctx2, dirty) { + if ( + /*data*/ + ctx2[0].editing + ) { + if (if_block) { + if_block.p(ctx2, dirty); + } else { + if_block = create_if_block_3$1(ctx2); + if_block.c(); + if_block.m(div, null); + } + } else if (if_block) { + if_block.d(1); + if_block = null; + } + }, + d(detaching) { + if (detaching) + detach(div); + if (if_block) + if_block.d(); + } + }; +} +__name(create_if_block_2$1, "create_if_block_2$1"); +function create_if_block_3$1(ctx) { + let a; + let mounted; + let dispose; + return { + c() { + a = element("a"); + a.innerHTML = ``; + attr(a, "class", "item-piles-clickable-green item-piles-confirm-quantity"); + }, + m(target, anchor) { + insert(target, a, anchor); + if (!mounted) { + dispose = listen( + a, + "click", + /*updateQuantity*/ + ctx[6] + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(a); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_3$1, "create_if_block_3$1"); +function create_else_block_1(ctx) { + let span; + let t_value = ( + /*data*/ + ctx[0].quantity + "" + ); + let t; + return { + c() { + span = element("span"); + t = text(t_value); + attr(span, "class", "item-piles-text"); + set_style(span, "padding-right", "0.5rem"); + }, + m(target, anchor) { + insert(target, span, anchor); + append(span, t); + }, + p(ctx2, dirty) { + if (dirty & /*data*/ + 1 && t_value !== (t_value = /*data*/ + ctx2[0].quantity + "")) + set_data(t, t_value); + }, + d(detaching) { + if (detaching) + detach(span); + } + }; +} +__name(create_else_block_1, "create_else_block_1"); +function create_if_block$1(ctx) { + let div; + function select_block_type_1(ctx2, dirty) { + if ( + /*data*/ + ctx2[0].editing + ) + return create_if_block_1$1; + return create_else_block$1; + } + __name(select_block_type_1, "select_block_type_1"); + let current_block_type = select_block_type_1(ctx); + let if_block = current_block_type(ctx); + return { + c() { + div = element("div"); + if_block.c(); + attr(div, "class", "item-piles-quantity-container"); + }, + m(target, anchor) { + insert(target, div, anchor); + if_block.m(div, null); + }, + p(ctx2, dirty) { + if (current_block_type === (current_block_type = select_block_type_1(ctx2)) && if_block) { + if_block.p(ctx2, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx2); + if (if_block) { + if_block.c(); + if_block.m(div, null); + } + } + }, + d(detaching) { + if (detaching) + detach(div); + if_block.d(); + } + }; +} +__name(create_if_block$1, "create_if_block$1"); +function create_else_block$1(ctx) { + let span; + let t_value = ( + /*data*/ + ctx[0].quantity + "" + ); + let t; + let mounted; + let dispose; + return { + c() { + span = element("span"); + t = text(t_value); + attr(span, "class", "item-piles-quantity-text"); + }, + m(target, anchor) { + insert(target, span, anchor); + append(span, t); + if (!mounted) { + dispose = listen( + span, + "click", + /*click_handler_2*/ + ctx[10] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*data*/ + 1 && t_value !== (t_value = /*data*/ + ctx2[0].quantity + "")) + set_data(t, t_value); + }, + d(detaching) { + if (detaching) + detach(span); + mounted = false; + dispose(); + } + }; +} +__name(create_else_block$1, "create_else_block$1"); +function create_if_block_1$1(ctx) { + let div; + let input; + let mounted; + let dispose; + return { + c() { + div = element("div"); + input = element("input"); + attr(input, "class", "item-piles-quantity"); + attr(input, "type", "number"); + attr(div, "class", "item-piles-quantity-input-container"); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, input); + set_input_value( + input, + /*data*/ + ctx[0].newQuantity + ); + if (!mounted) { + dispose = [ + listen( + input, + "input", + /*input_input_handler*/ + ctx[9] + ), + listen( + input, + "keydown", + /*onKeyDown*/ + ctx[5] + ) + ]; + mounted = true; + } + }, + p(ctx2, dirty) { + if (dirty & /*data*/ + 1 && to_number(input.value) !== /*data*/ + ctx2[0].newQuantity) { + set_input_value( + input, + /*data*/ + ctx2[0].newQuantity + ); + } + }, + d(detaching) { + if (detaching) + detach(div); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_if_block_1$1, "create_if_block_1$1"); +function create_fragment$1(ctx) { + let div4; + let t0; + let div0; + let img; + let img_src_value; + let t1; + let div2; + let div1; + let p; + let t2_value = ( + /*data*/ + ctx[0].name + "" + ); + let t2; + let t3; + let t4; + let div3; + let mounted; + let dispose; + let if_block0 = ( + /*editable*/ + ctx[2] && create_if_block_4$1(ctx) + ); + let if_block1 = ( + /*editable*/ + ctx[2] && create_if_block_2$1(ctx) + ); + function select_block_type(ctx2, dirty) { + if ( + /*editable*/ + ctx2[2] + ) + return create_if_block$1; + return create_else_block_1; + } + __name(select_block_type, "select_block_type"); + let current_block_type = select_block_type(ctx); + let if_block2 = current_block_type(ctx); + return { + c() { + div4 = element("div"); + if (if_block0) + if_block0.c(); + t0 = space(); + div0 = element("div"); + img = element("img"); + t1 = space(); + div2 = element("div"); + div1 = element("div"); + p = element("p"); + t2 = text(t2_value); + t3 = space(); + if (if_block1) + if_block1.c(); + t4 = space(); + div3 = element("div"); + if_block2.c(); + attr(img, "class", "item-piles-img"); + if (!src_url_equal(img.src, img_src_value = /*data*/ + ctx[0].img)) + attr(img, "src", img_src_value); + attr(div0, "class", "item-piles-img-container"); + toggle_class( + p, + "item-piles-clickable-link", + /*canPreview*/ + ctx[3] + ); + attr(div1, "class", "item-piles-name-container"); + attr(div2, "class", "item-piles-name item-piles-text"); + attr(div3, "class", "item-piles-text-right"); + toggle_class( + div3, + "item-piles-quantity-container", + /*editable*/ + ctx[2] + ); + attr(div4, "class", "item-piles-flexrow item-piles-item-row item-piles-even-color"); + }, + m(target, anchor) { + insert(target, div4, anchor); + if (if_block0) + if_block0.m(div4, null); + append(div4, t0); + append(div4, div0); + append(div0, img); + append(div4, t1); + append(div4, div2); + append(div2, div1); + append(div1, p); + append(p, t2); + append(div4, t3); + if (if_block1) + if_block1.m(div4, null); + append(div4, t4); + append(div4, div3); + if_block2.m(div3, null); + if (!mounted) { + dispose = [ + listen( + window, + "click", + /*click_handler*/ + ctx[7] + ), + listen( + p, + "click", + /*previewItem*/ + ctx[4] + ), + listen(div3, "click", click_handler_3) + ]; + mounted = true; + } + }, + p(ctx2, [dirty]) { + if ( + /*editable*/ + ctx2[2] + ) { + if (if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0 = create_if_block_4$1(ctx2); + if_block0.c(); + if_block0.m(div4, t0); + } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; + } + if (dirty & /*data*/ + 1 && !src_url_equal(img.src, img_src_value = /*data*/ + ctx2[0].img)) { + attr(img, "src", img_src_value); + } + if (dirty & /*data*/ + 1 && t2_value !== (t2_value = /*data*/ + ctx2[0].name + "")) + set_data(t2, t2_value); + if ( + /*editable*/ + ctx2[2] + ) { + if (if_block1) { + if_block1.p(ctx2, dirty); + } else { + if_block1 = create_if_block_2$1(ctx2); + if_block1.c(); + if_block1.m(div4, t4); + } + } else if (if_block1) { + if_block1.d(1); + if_block1 = null; + } + if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block2) { + if_block2.p(ctx2, dirty); + } else { + if_block2.d(1); + if_block2 = current_block_type(ctx2); + if (if_block2) { + if_block2.c(); + if_block2.m(div3, null); + } + } + if (dirty & /*editable*/ + 4) { + toggle_class( + div3, + "item-piles-quantity-container", + /*editable*/ + ctx2[2] + ); + } + }, + i: noop, + o: noop, + d(detaching) { + if (detaching) + detach(div4); + if (if_block0) + if_block0.d(); + if (if_block1) + if_block1.d(); + if_block2.d(); + mounted = false; + run_all(dispose); + } + }; +} +__name(create_fragment$1, "create_fragment$1"); +const click_handler_3 = /* @__PURE__ */ __name((evt) => evt.stopPropagation(), "click_handler_3"); +function instance$1($$self, $$props, $$invalidate) { + let { store } = $$props; + let { data: data2 } = $$props; + let { editable = true } = $$props; + const canPreview = data2.id && (getSetting(SETTINGS$1.INSPECT_ITEMS_IN_TRADE) || editable); + function previewItem2() { + if (!canPreview || !data2.id) + return; + const item = store.leftTraderActor.items.get(data2.id) ?? store.rightTraderActor.items.get(data2.id); + if (!item) + return; + if (game.user.isGM || item.ownership[game.user.id] === CONST.DOCUMENT_PERMISSION_LEVELS.OWNER) { + return item.sheet.render(true); + } + const cls = item._getSheetClass(); + const sheet = new cls(item, { editable: false }); + return sheet._render(true); + } + __name(previewItem2, "previewItem"); + function onKeyDown(e) { + if (e.keyCode === 13) { + updateQuantity(); + } + } + __name(onKeyDown, "onKeyDown"); + function updateQuantity() { + $$invalidate(0, data2.quantity = Math.max(0, Math.min(data2.maxQuantity, data2.newQuantity)), data2); + if (data2.quantity === 0) { + return store.removeEntry(data2); + } + $$invalidate(0, data2.newQuantity = data2.quantity, data2); + $$invalidate(0, data2.editing = false, data2); + } + __name(updateQuantity, "updateQuantity"); + const click_handler = /* @__PURE__ */ __name(() => { + if (data2.editing && editable) + updateQuantity(); + }, "click_handler"); + const click_handler_1 = /* @__PURE__ */ __name(() => { + store.removeEntry(data2); + }, "click_handler_1"); + function input_input_handler() { + data2.newQuantity = to_number(this.value); + $$invalidate(0, data2); + } + __name(input_input_handler, "input_input_handler"); + const click_handler_2 = /* @__PURE__ */ __name(() => { + $$invalidate(0, data2.editing = true, data2); + }, "click_handler_2"); + $$self.$$set = ($$props2) => { + if ("store" in $$props2) + $$invalidate(1, store = $$props2.store); + if ("data" in $$props2) + $$invalidate(0, data2 = $$props2.data); + if ("editable" in $$props2) + $$invalidate(2, editable = $$props2.editable); + }; + return [ + data2, + store, + editable, + canPreview, + previewItem2, + onKeyDown, + updateQuantity, + click_handler, + click_handler_1, + input_input_handler, + click_handler_2 + ]; +} +__name(instance$1, "instance$1"); +class TradeEntry extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance$1, create_fragment$1, safe_not_equal, { store: 1, data: 0, editable: 2 }); + } +} +__name(TradeEntry, "TradeEntry"); +const tradingAppShell_svelte_svelte_type_style_lang = ""; +function get_each_context(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[33] = list[i]; + child_ctx[34] = list; + child_ctx[35] = i; + return child_ctx; +} +__name(get_each_context, "get_each_context"); +function get_each_context_1(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[36] = list[i]; + child_ctx[37] = list; + child_ctx[38] = i; + return child_ctx; +} +__name(get_each_context_1, "get_each_context_1"); +function get_each_context_2(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[33] = list[i]; + child_ctx[39] = list; + child_ctx[40] = i; + return child_ctx; +} +__name(get_each_context_2, "get_each_context_2"); +function get_each_context_3(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[33] = list[i]; + child_ctx[41] = list; + child_ctx[42] = i; + return child_ctx; +} +__name(get_each_context_3, "get_each_context_3"); +function get_each_context_4(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[36] = list[i]; + child_ctx[43] = list; + child_ctx[44] = i; + return child_ctx; +} +__name(get_each_context_4, "get_each_context_4"); +function get_each_context_5(ctx, list, i) { + const child_ctx = ctx.slice(); + child_ctx[33] = list[i]; + child_ctx[45] = list; + child_ctx[46] = i; + return child_ctx; +} +__name(get_each_context_5, "get_each_context_5"); +function create_if_block_7(ctx) { + let div4; + let div4_transition; + let current; + return { + c() { + div4 = element("div"); + div4.innerHTML = ` + + + `; + attr(div4, "class", "lds-ellipsis svelte-3zgsgo"); + }, + m(target, anchor) { + insert(target, div4, anchor); + current = true; + }, + i(local) { + if (current) + return; + add_render_callback(() => { + if (!current) + return; + if (!div4_transition) + div4_transition = create_bidirectional_transition(div4, fade, {}, true); + div4_transition.run(1); + }); + current = true; + }, + o(local) { + if (!div4_transition) + div4_transition = create_bidirectional_transition(div4, fade, {}, false); + div4_transition.run(0); + current = false; + }, + d(detaching) { + if (detaching) + detach(div4); + if (detaching && div4_transition) + div4_transition.end(); + } + }; +} +__name(create_if_block_7, "create_if_block_7"); +function create_if_block_6(ctx) { + let div; + let h3; + return { + c() { + div = element("div"); + h3 = element("h3"); + h3.textContent = `${localize("ITEM-PILES.Trade.DragDrop")}`; + attr(h3, "class", "item-piles-text-center"); + attr(div, "class", "item-piles-flexcol"); + }, + m(target, anchor) { + insert(target, div, anchor); + append(div, h3); + }, + p: noop, + d(detaching) { + if (detaching) + detach(div); + } + }; +} +__name(create_if_block_6, "create_if_block_6"); +function create_each_block_5(key_1, ctx) { + let first; + let tradeentry; + let updating_data; + let current; + function tradeentry_data_binding(value) { + ctx[22]( + value, + /*item*/ + ctx[33], + /*each_value_5*/ + ctx[45], + /*item_index_3*/ + ctx[46] + ); + } + __name(tradeentry_data_binding, "tradeentry_data_binding"); + let tradeentry_props = { + store: ( + /*store*/ + ctx[1] + ), + editable: ( + /*store*/ + ctx[1].isUserParticipant + ) + }; + if ( + /*item*/ + ctx[33] !== void 0 + ) { + tradeentry_props.data = /*item*/ + ctx[33]; + } + tradeentry = new TradeEntry({ props: tradeentry_props }); + binding_callbacks.push(() => bind(tradeentry, "data", tradeentry_data_binding)); + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(tradeentry.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(tradeentry, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const tradeentry_changes = {}; + if (dirty[0] & /*store*/ + 2) + tradeentry_changes.store = /*store*/ + ctx[1]; + if (dirty[0] & /*store*/ + 2) + tradeentry_changes.editable = /*store*/ + ctx[1].isUserParticipant; + if (!updating_data && dirty[0] & /*$leftItems*/ + 16) { + updating_data = true; + tradeentry_changes.data = /*item*/ + ctx[33]; + add_flush_callback(() => updating_data = false); + } + tradeentry.$set(tradeentry_changes); + }, + i(local) { + if (current) + return; + transition_in(tradeentry.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(tradeentry.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(first); + destroy_component(tradeentry, detaching); + } + }; +} +__name(create_each_block_5, "create_each_block_5"); +function create_if_block_3(ctx) { + let div; + let t0; + let each_blocks_1 = []; + let each0_lookup = /* @__PURE__ */ new Map(); + let t1; + let each_blocks = []; + let each1_lookup = /* @__PURE__ */ new Map(); + let current; + let if_block = ( + /*store*/ + ctx[1].isUserParticipant && create_if_block_4(ctx) + ); + let each_value_4 = ( + /*$leftCurrencies*/ + ctx[5] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*currency*/ + ctx2[36].path + ), "get_key"); + for (let i = 0; i < each_value_4.length; i += 1) { + let child_ctx = get_each_context_4(ctx, each_value_4, i); + let key = get_key(child_ctx); + each0_lookup.set(key, each_blocks_1[i] = create_each_block_4(key, child_ctx)); + } + let each_value_3 = ( + /*$leftItemCurrencies*/ + ctx[6] + ); + const get_key_1 = /* @__PURE__ */ __name((ctx2) => ( + /*item*/ + ctx2[33].id + ), "get_key_1"); + for (let i = 0; i < each_value_3.length; i += 1) { + let child_ctx = get_each_context_3(ctx, each_value_3, i); + let key = get_key_1(child_ctx); + each1_lookup.set(key, each_blocks[i] = create_each_block_3(key, child_ctx)); + } + return { + c() { + div = element("div"); + if (if_block) + if_block.c(); + t0 = space(); + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].c(); + } + t1 = space(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + attr(div, "class", "row item-piles-items-list item-piles-currency-list svelte-3zgsgo"); + toggle_class( + div, + "item-piles-top-divider", + /*$leftCurrencies*/ + ctx[5].length || /*$leftItemCurrencies*/ + ctx[6].length + ); + }, + m(target, anchor) { + insert(target, div, anchor); + if (if_block) + if_block.m(div, null); + append(div, t0); + for (let i = 0; i < each_blocks_1.length; i += 1) { + if (each_blocks_1[i]) { + each_blocks_1[i].m(div, null); + } + } + append(div, t1); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(div, null); + } + } + current = true; + }, + p(ctx2, dirty) { + if ( + /*store*/ + ctx2[1].isUserParticipant + ) { + if (if_block) { + if_block.p(ctx2, dirty); + } else { + if_block = create_if_block_4(ctx2); + if_block.c(); + if_block.m(div, t0); + } + } else if (if_block) { + if_block.d(1); + if_block = null; + } + if (dirty[0] & /*store, $leftCurrencies*/ + 34) { + each_value_4 = /*$leftCurrencies*/ + ctx2[5]; + group_outros(); + each_blocks_1 = update_keyed_each(each_blocks_1, dirty, get_key, 1, ctx2, each_value_4, each0_lookup, div, outro_and_destroy_block, create_each_block_4, t1, get_each_context_4); + check_outros(); + } + if (dirty[0] & /*store, $leftItemCurrencies*/ + 66) { + each_value_3 = /*$leftItemCurrencies*/ + ctx2[6]; + group_outros(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key_1, 1, ctx2, each_value_3, each1_lookup, div, outro_and_destroy_block, create_each_block_3, null, get_each_context_3); + check_outros(); + } + if (!current || dirty[0] & /*$leftCurrencies, $leftItemCurrencies*/ + 96) { + toggle_class( + div, + "item-piles-top-divider", + /*$leftCurrencies*/ + ctx2[5].length || /*$leftItemCurrencies*/ + ctx2[6].length + ); + } + }, + i(local) { + if (current) + return; + for (let i = 0; i < each_value_4.length; i += 1) { + transition_in(each_blocks_1[i]); + } + for (let i = 0; i < each_value_3.length; i += 1) { + transition_in(each_blocks[i]); + } + current = true; + }, + o(local) { + for (let i = 0; i < each_blocks_1.length; i += 1) { + transition_out(each_blocks_1[i]); + } + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + current = false; + }, + d(detaching) { + if (detaching) + detach(div); + if (if_block) + if_block.d(); + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].d(); + } + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + } + }; +} +__name(create_if_block_3, "create_if_block_3"); +function create_if_block_4(ctx) { + let div; + let t0; + let a; + let i; + let t1; + let t2_value = localize("ITEM-PILES.Inspect.AddCurrency") + ""; + let t2; + let mounted; + let dispose; + let if_block = ( + /*isGM*/ + ctx[18] && create_if_block_5(ctx) + ); + return { + c() { + div = element("div"); + if (if_block) + if_block.c(); + t0 = space(); + a = element("a"); + i = element("i"); + t1 = space(); + t2 = text(t2_value); + attr(i, "class", "fas fa-plus"); + attr(a, "class", "item-piles-text-right item-piles-small-text item-piles-middle item-piles-add-currency"); + attr(div, "class", "item-piles-flexrow"); + }, + m(target, anchor) { + insert(target, div, anchor); + if (if_block) + if_block.m(div, null); + append(div, t0); + append(div, a); + append(a, i); + append(a, t1); + append(a, t2); + if (!mounted) { + dispose = listen( + a, + "click", + /*click_handler_1*/ + ctx[24] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if ( + /*isGM*/ + ctx2[18] + ) + if_block.p(ctx2, dirty); + }, + d(detaching) { + if (detaching) + detach(div); + if (if_block) + if_block.d(); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_4, "create_if_block_4"); +function create_if_block_5(ctx) { + let a; + let i; + let t0; + let t1_value = localize("ITEM-PILES.Trade.GMAddCurrency") + ""; + let t1; + let mounted; + let dispose; + return { + c() { + a = element("a"); + i = element("i"); + t0 = space(); + t1 = text(t1_value); + attr(i, "class", "fas fa-plus"); + attr(a, "class", "item-piles-text-right item-piles-small-text item-piles-middle item-piles-gm-add-currency"); + }, + m(target, anchor) { + insert(target, a, anchor); + append(a, i); + append(a, t0); + append(a, t1); + if (!mounted) { + dispose = listen( + a, + "click", + /*click_handler*/ + ctx[23] + ); + mounted = true; + } + }, + p: noop, + d(detaching) { + if (detaching) + detach(a); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_5, "create_if_block_5"); +function create_each_block_4(key_1, ctx) { + let first; + let tradeentry; + let updating_data; + let current; + function tradeentry_data_binding_1(value) { + ctx[25]( + value, + /*currency*/ + ctx[36], + /*each_value_4*/ + ctx[43], + /*currency_index_1*/ + ctx[44] + ); + } + __name(tradeentry_data_binding_1, "tradeentry_data_binding_1"); + let tradeentry_props = { + store: ( + /*store*/ + ctx[1] + ), + editable: ( + /*store*/ + ctx[1].isUserParticipant + ) + }; + if ( + /*currency*/ + ctx[36] !== void 0 + ) { + tradeentry_props.data = /*currency*/ + ctx[36]; + } + tradeentry = new TradeEntry({ props: tradeentry_props }); + binding_callbacks.push(() => bind(tradeentry, "data", tradeentry_data_binding_1)); + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(tradeentry.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(tradeentry, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const tradeentry_changes = {}; + if (dirty[0] & /*store*/ + 2) + tradeentry_changes.store = /*store*/ + ctx[1]; + if (dirty[0] & /*store*/ + 2) + tradeentry_changes.editable = /*store*/ + ctx[1].isUserParticipant; + if (!updating_data && dirty[0] & /*$leftCurrencies*/ + 32) { + updating_data = true; + tradeentry_changes.data = /*currency*/ + ctx[36]; + add_flush_callback(() => updating_data = false); + } + tradeentry.$set(tradeentry_changes); + }, + i(local) { + if (current) + return; + transition_in(tradeentry.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(tradeentry.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(first); + destroy_component(tradeentry, detaching); + } + }; +} +__name(create_each_block_4, "create_each_block_4"); +function create_each_block_3(key_1, ctx) { + let first; + let tradeentry; + let updating_data; + let current; + function tradeentry_data_binding_2(value) { + ctx[26]( + value, + /*item*/ + ctx[33], + /*each_value_3*/ + ctx[41], + /*item_index_2*/ + ctx[42] + ); + } + __name(tradeentry_data_binding_2, "tradeentry_data_binding_2"); + let tradeentry_props = { + store: ( + /*store*/ + ctx[1] + ), + editable: ( + /*store*/ + ctx[1].isUserParticipant + ) + }; + if ( + /*item*/ + ctx[33] !== void 0 + ) { + tradeentry_props.data = /*item*/ + ctx[33]; + } + tradeentry = new TradeEntry({ props: tradeentry_props }); + binding_callbacks.push(() => bind(tradeentry, "data", tradeentry_data_binding_2)); + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(tradeentry.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(tradeentry, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const tradeentry_changes = {}; + if (dirty[0] & /*store*/ + 2) + tradeentry_changes.store = /*store*/ + ctx[1]; + if (dirty[0] & /*store*/ + 2) + tradeentry_changes.editable = /*store*/ + ctx[1].isUserParticipant; + if (!updating_data && dirty[0] & /*$leftItemCurrencies*/ + 64) { + updating_data = true; + tradeentry_changes.data = /*item*/ + ctx[33]; + add_flush_callback(() => updating_data = false); + } + tradeentry.$set(tradeentry_changes); + }, + i(local) { + if (current) + return; + transition_in(tradeentry.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(tradeentry.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(first); + destroy_component(tradeentry, detaching); + } + }; +} +__name(create_each_block_3, "create_each_block_3"); +function create_if_block_1(ctx) { + let button; + let mounted; + let dispose; + function select_block_type(ctx2, dirty) { + if ( + /*$leftTraderAccepted*/ + ctx2[2] + ) + return create_if_block_2; + return create_else_block; + } + __name(select_block_type, "select_block_type"); + let current_block_type = select_block_type(ctx); + let if_block = current_block_type(ctx); + return { + c() { + button = element("button"); + if_block.c(); + attr(button, "type", "button"); + set_style(button, "flex", "0 1 auto"); + set_style(button, "margin-top", "0.25rem"); + }, + m(target, anchor) { + insert(target, button, anchor); + if_block.m(button, null); + if (!mounted) { + dispose = listen( + button, + "click", + /*click_handler_2*/ + ctx[27] + ); + mounted = true; + } + }, + p(ctx2, dirty) { + if (current_block_type === (current_block_type = select_block_type(ctx2)) && if_block) { + if_block.p(ctx2, dirty); + } else { + if_block.d(1); + if_block = current_block_type(ctx2); + if (if_block) { + if_block.c(); + if_block.m(button, null); + } + } + }, + d(detaching) { + if (detaching) + detach(button); + if_block.d(); + mounted = false; + dispose(); + } + }; +} +__name(create_if_block_1, "create_if_block_1"); +function create_else_block(ctx) { + let i; + let t0; + let t1_value = localize("ITEM-PILES.Trade.Accept") + ""; + let t1; + return { + c() { + i = element("i"); + t0 = space(); + t1 = text(t1_value); + attr(i, "class", "fas fa-check"); + }, + m(target, anchor) { + insert(target, i, anchor); + insert(target, t0, anchor); + insert(target, t1, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(i); + if (detaching) + detach(t0); + if (detaching) + detach(t1); + } + }; +} +__name(create_else_block, "create_else_block"); +function create_if_block_2(ctx) { + let i; + let t0; + let t1_value = localize("Cancel") + ""; + let t1; + return { + c() { + i = element("i"); + t0 = space(); + t1 = text(t1_value); + attr(i, "class", "fas fa-times"); + }, + m(target, anchor) { + insert(target, i, anchor); + insert(target, t0, anchor); + insert(target, t1, anchor); + }, + p: noop, + d(detaching) { + if (detaching) + detach(i); + if (detaching) + detach(t0); + if (detaching) + detach(t1); + } + }; +} +__name(create_if_block_2, "create_if_block_2"); +function create_each_block_2(key_1, ctx) { + let first; + let tradeentry; + let updating_data; + let current; + function tradeentry_data_binding_3(value) { + ctx[28]( + value, + /*item*/ + ctx[33], + /*each_value_2*/ + ctx[39], + /*item_index_1*/ + ctx[40] + ); + } + __name(tradeentry_data_binding_3, "tradeentry_data_binding_3"); + let tradeentry_props = { store: ( + /*store*/ + ctx[1] + ), editable: false }; + if ( + /*item*/ + ctx[33] !== void 0 + ) { + tradeentry_props.data = /*item*/ + ctx[33]; + } + tradeentry = new TradeEntry({ props: tradeentry_props }); + binding_callbacks.push(() => bind(tradeentry, "data", tradeentry_data_binding_3)); + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(tradeentry.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(tradeentry, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const tradeentry_changes = {}; + if (dirty[0] & /*store*/ + 2) + tradeentry_changes.store = /*store*/ + ctx[1]; + if (!updating_data && dirty[0] & /*$rightItems*/ + 128) { + updating_data = true; + tradeentry_changes.data = /*item*/ + ctx[33]; + add_flush_callback(() => updating_data = false); + } + tradeentry.$set(tradeentry_changes); + }, + i(local) { + if (current) + return; + transition_in(tradeentry.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(tradeentry.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(first); + destroy_component(tradeentry, detaching); + } + }; +} +__name(create_each_block_2, "create_each_block_2"); +function create_if_block(ctx) { + let div; + let each_blocks_1 = []; + let each0_lookup = /* @__PURE__ */ new Map(); + let t; + let each_blocks = []; + let each1_lookup = /* @__PURE__ */ new Map(); + let current; + let each_value_1 = ( + /*$rightCurrencies*/ + ctx[8] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*currency*/ + ctx2[36].path + ), "get_key"); + for (let i = 0; i < each_value_1.length; i += 1) { + let child_ctx = get_each_context_1(ctx, each_value_1, i); + let key = get_key(child_ctx); + each0_lookup.set(key, each_blocks_1[i] = create_each_block_1(key, child_ctx)); + } + let each_value = ( + /*$rightItemCurrencies*/ + ctx[9] + ); + const get_key_1 = /* @__PURE__ */ __name((ctx2) => ( + /*item*/ + ctx2[33].id + ), "get_key_1"); + for (let i = 0; i < each_value.length; i += 1) { + let child_ctx = get_each_context(ctx, each_value, i); + let key = get_key_1(child_ctx); + each1_lookup.set(key, each_blocks[i] = create_each_block(key, child_ctx)); + } + return { + c() { + div = element("div"); + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].c(); + } + t = space(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + attr(div, "class", "row item-piles-items-list item-piles-currency-list svelte-3zgsgo"); + toggle_class( + div, + "item-piles-top-divider", + /*$rightCurrencies*/ + ctx[8].length || /*$rightItemCurrencies*/ + ctx[9].length + ); + }, + m(target, anchor) { + insert(target, div, anchor); + for (let i = 0; i < each_blocks_1.length; i += 1) { + if (each_blocks_1[i]) { + each_blocks_1[i].m(div, null); + } + } + append(div, t); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(div, null); + } + } + current = true; + }, + p(ctx2, dirty) { + if (dirty[0] & /*store, $rightCurrencies*/ + 258) { + each_value_1 = /*$rightCurrencies*/ + ctx2[8]; + group_outros(); + each_blocks_1 = update_keyed_each(each_blocks_1, dirty, get_key, 1, ctx2, each_value_1, each0_lookup, div, outro_and_destroy_block, create_each_block_1, t, get_each_context_1); + check_outros(); + } + if (dirty[0] & /*store, $rightItemCurrencies*/ + 514) { + each_value = /*$rightItemCurrencies*/ + ctx2[9]; + group_outros(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key_1, 1, ctx2, each_value, each1_lookup, div, outro_and_destroy_block, create_each_block, null, get_each_context); + check_outros(); + } + if (!current || dirty[0] & /*$rightCurrencies, $rightItemCurrencies*/ + 768) { + toggle_class( + div, + "item-piles-top-divider", + /*$rightCurrencies*/ + ctx2[8].length || /*$rightItemCurrencies*/ + ctx2[9].length + ); + } + }, + i(local) { + if (current) + return; + for (let i = 0; i < each_value_1.length; i += 1) { + transition_in(each_blocks_1[i]); + } + for (let i = 0; i < each_value.length; i += 1) { + transition_in(each_blocks[i]); + } + current = true; + }, + o(local) { + for (let i = 0; i < each_blocks_1.length; i += 1) { + transition_out(each_blocks_1[i]); + } + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + current = false; + }, + d(detaching) { + if (detaching) + detach(div); + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].d(); + } + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + } + }; +} +__name(create_if_block, "create_if_block"); +function create_each_block_1(key_1, ctx) { + let first; + let tradeentry; + let updating_data; + let current; + function tradeentry_data_binding_4(value) { + ctx[29]( + value, + /*currency*/ + ctx[36], + /*each_value_1*/ + ctx[37], + /*currency_index*/ + ctx[38] + ); + } + __name(tradeentry_data_binding_4, "tradeentry_data_binding_4"); + let tradeentry_props = { store: ( + /*store*/ + ctx[1] + ), editable: false }; + if ( + /*currency*/ + ctx[36] !== void 0 + ) { + tradeentry_props.data = /*currency*/ + ctx[36]; + } + tradeentry = new TradeEntry({ props: tradeentry_props }); + binding_callbacks.push(() => bind(tradeentry, "data", tradeentry_data_binding_4)); + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(tradeentry.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(tradeentry, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const tradeentry_changes = {}; + if (dirty[0] & /*store*/ + 2) + tradeentry_changes.store = /*store*/ + ctx[1]; + if (!updating_data && dirty[0] & /*$rightCurrencies*/ + 256) { + updating_data = true; + tradeentry_changes.data = /*currency*/ + ctx[36]; + add_flush_callback(() => updating_data = false); + } + tradeentry.$set(tradeentry_changes); + }, + i(local) { + if (current) + return; + transition_in(tradeentry.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(tradeentry.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(first); + destroy_component(tradeentry, detaching); + } + }; +} +__name(create_each_block_1, "create_each_block_1"); +function create_each_block(key_1, ctx) { + let first; + let tradeentry; + let updating_data; + let current; + function tradeentry_data_binding_5(value) { + ctx[30]( + value, + /*item*/ + ctx[33], + /*each_value*/ + ctx[34], + /*item_index*/ + ctx[35] + ); + } + __name(tradeentry_data_binding_5, "tradeentry_data_binding_5"); + let tradeentry_props = { store: ( + /*store*/ + ctx[1] + ), editable: false }; + if ( + /*item*/ + ctx[33] !== void 0 + ) { + tradeentry_props.data = /*item*/ + ctx[33]; + } + tradeentry = new TradeEntry({ props: tradeentry_props }); + binding_callbacks.push(() => bind(tradeentry, "data", tradeentry_data_binding_5)); + return { + key: key_1, + first: null, + c() { + first = empty(); + create_component(tradeentry.$$.fragment); + this.first = first; + }, + m(target, anchor) { + insert(target, first, anchor); + mount_component(tradeentry, target, anchor); + current = true; + }, + p(new_ctx, dirty) { + ctx = new_ctx; + const tradeentry_changes = {}; + if (dirty[0] & /*store*/ + 2) + tradeentry_changes.store = /*store*/ + ctx[1]; + if (!updating_data && dirty[0] & /*$rightItemCurrencies*/ + 512) { + updating_data = true; + tradeentry_changes.data = /*item*/ + ctx[33]; + add_flush_callback(() => updating_data = false); + } + tradeentry.$set(tradeentry_changes); + }, + i(local) { + if (current) + return; + transition_in(tradeentry.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(tradeentry.$$.fragment, local); + current = false; + }, + d(detaching) { + if (detaching) + detach(first); + destroy_component(tradeentry, detaching); + } + }; +} +__name(create_each_block, "create_each_block"); +function create_default_slot_1(ctx) { + let div12; + let div11; + let div5; + let div2; + let img0; + let img0_src_value; + let t0; + let h20; + let div0; + let t1_value = ( + /*store*/ + ctx[1].leftTraderActor.name + "" + ); + let t1; + let t2; + let div1; + let i0; + let t3; + let div4; + let div3; + let t4; + let each_blocks_1 = []; + let each0_lookup = /* @__PURE__ */ new Map(); + let t5; + let t6; + let t7; + let div10; + let div7; + let div6; + let i1; + let t8; + let h21; + let t9_value = ( + /*store*/ + ctx[1].rightTraderActor.name + "" + ); + let t9; + let t10; + let img1; + let img1_src_value; + let t11; + let div9; + let div8; + let each_blocks = []; + let each1_lookup = /* @__PURE__ */ new Map(); + let t12; + let current; + let if_block0 = !/*$leftItems*/ + ctx[4].length && /*store*/ + ctx[1].isUserParticipant && create_if_block_6(); + let each_value_5 = ( + /*$leftItems*/ + ctx[4] + ); + const get_key = /* @__PURE__ */ __name((ctx2) => ( + /*item*/ + ctx2[33].id + ), "get_key"); + for (let i = 0; i < each_value_5.length; i += 1) { + let child_ctx = get_each_context_5(ctx, each_value_5, i); + let key = get_key(child_ctx); + each0_lookup.set(key, each_blocks_1[i] = create_each_block_5(key, child_ctx)); + } + let if_block1 = ( + /*systemHasCurrencies*/ + ctx[19] && create_if_block_3(ctx) + ); + let if_block2 = ( + /*store*/ + ctx[1].isUserParticipant && create_if_block_1(ctx) + ); + let each_value_2 = ( + /*$rightItems*/ + ctx[7] + ); + const get_key_1 = /* @__PURE__ */ __name((ctx2) => ( + /*item*/ + ctx2[33].id + ), "get_key_1"); + for (let i = 0; i < each_value_2.length; i += 1) { + let child_ctx = get_each_context_2(ctx, each_value_2, i); + let key = get_key_1(child_ctx); + each1_lookup.set(key, each_blocks[i] = create_each_block_2(key, child_ctx)); + } + let if_block3 = ( + /*systemHasCurrencies*/ + ctx[19] && create_if_block(ctx) + ); + return { + c() { + div12 = element("div"); + div11 = element("div"); + div5 = element("div"); + div2 = element("div"); + img0 = element("img"); + t0 = space(); + h20 = element("h2"); + div0 = element("div"); + t1 = text(t1_value); + t2 = space(); + div1 = element("div"); + i0 = element("i"); + t3 = space(); + div4 = element("div"); + div3 = element("div"); + if (if_block0) + if_block0.c(); + t4 = space(); + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].c(); + } + t5 = space(); + if (if_block1) + if_block1.c(); + t6 = space(); + if (if_block2) + if_block2.c(); + t7 = space(); + div10 = element("div"); + div7 = element("div"); + div6 = element("div"); + i1 = element("i"); + t8 = space(); + h21 = element("h2"); + t9 = text(t9_value); + t10 = space(); + img1 = element("img"); + t11 = space(); + div9 = element("div"); + div8 = element("div"); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].c(); + } + t12 = space(); + if (if_block3) + if_block3.c(); + if (!src_url_equal(img0.src, img0_src_value = /*store*/ + ctx[1].leftTraderActor.img)) + attr(img0, "src", img0_src_value); + attr(h20, "class", "character-name"); + attr(i0, "class", "fas accepted-icon"); + toggle_class( + i0, + "accepted", + /*$leftTraderAccepted*/ + ctx[2] + ); + toggle_class( + i0, + "fa-user-check", + /*$leftTraderAccepted*/ + ctx[2] + ); + toggle_class(i0, "fa-user-times", !/*$leftTraderAccepted*/ + ctx[2]); + attr(div2, "class", "character-header item-piles-bottom-divider"); + attr(div3, "class", "row item-piles-items-list svelte-3zgsgo"); + attr(div4, "class", "item-piles-flexcol"); + attr(div5, "class", "col item-piles-flexcol svelte-3zgsgo"); + attr(i1, "class", "fas accepted-icon"); + toggle_class( + i1, + "accepted", + /*$rightTraderAccepted*/ + ctx[3] + ); + toggle_class( + i1, + "fa-user-check", + /*$rightTraderAccepted*/ + ctx[3] + ); + toggle_class(i1, "fa-user-times", !/*$rightTraderAccepted*/ + ctx[3]); + attr(h21, "class", "character-name"); + if (!src_url_equal(img1.src, img1_src_value = /*store*/ + ctx[1].rightTraderActor.img)) + attr(img1, "src", img1_src_value); + attr(div7, "class", "character-header trader item-piles-bottom-divider"); + attr(div8, "class", "row item-piles-items-list svelte-3zgsgo"); + attr(div9, "class", "item-piles-flexcol"); + attr(div10, "class", "col item-piles-flexcol svelte-3zgsgo"); + attr(div11, "class", "item-piles-flexrow"); + attr(div12, "class", "item-piles-flexcol"); + }, + m(target, anchor) { + insert(target, div12, anchor); + append(div12, div11); + append(div11, div5); + append(div5, div2); + append(div2, img0); + append(div2, t0); + append(div2, h20); + append(h20, div0); + append(div0, t1); + append(div2, t2); + append(div2, div1); + append(div1, i0); + append(div5, t3); + append(div5, div4); + append(div4, div3); + if (if_block0) + if_block0.m(div3, null); + append(div3, t4); + for (let i = 0; i < each_blocks_1.length; i += 1) { + if (each_blocks_1[i]) { + each_blocks_1[i].m(div3, null); + } + } + append(div4, t5); + if (if_block1) + if_block1.m(div4, null); + append(div5, t6); + if (if_block2) + if_block2.m(div5, null); + append(div11, t7); + append(div11, div10); + append(div10, div7); + append(div7, div6); + append(div6, i1); + append(div7, t8); + append(div7, h21); + append(h21, t9); + append(div7, t10); + append(div7, img1); + append(div10, t11); + append(div10, div9); + append(div9, div8); + for (let i = 0; i < each_blocks.length; i += 1) { + if (each_blocks[i]) { + each_blocks[i].m(div8, null); + } + } + append(div9, t12); + if (if_block3) + if_block3.m(div9, null); + current = true; + }, + p(ctx2, dirty) { + if (!current || dirty[0] & /*store*/ + 2 && !src_url_equal(img0.src, img0_src_value = /*store*/ + ctx2[1].leftTraderActor.img)) { + attr(img0, "src", img0_src_value); + } + if ((!current || dirty[0] & /*store*/ + 2) && t1_value !== (t1_value = /*store*/ + ctx2[1].leftTraderActor.name + "")) + set_data(t1, t1_value); + if (!current || dirty[0] & /*$leftTraderAccepted*/ + 4) { + toggle_class( + i0, + "accepted", + /*$leftTraderAccepted*/ + ctx2[2] + ); + } + if (!current || dirty[0] & /*$leftTraderAccepted*/ + 4) { + toggle_class( + i0, + "fa-user-check", + /*$leftTraderAccepted*/ + ctx2[2] + ); + } + if (!current || dirty[0] & /*$leftTraderAccepted*/ + 4) { + toggle_class(i0, "fa-user-times", !/*$leftTraderAccepted*/ + ctx2[2]); + } + if (!/*$leftItems*/ + ctx2[4].length && /*store*/ + ctx2[1].isUserParticipant) { + if (if_block0) { + if_block0.p(ctx2, dirty); + } else { + if_block0 = create_if_block_6(); + if_block0.c(); + if_block0.m(div3, t4); + } + } else if (if_block0) { + if_block0.d(1); + if_block0 = null; + } + if (dirty[0] & /*store, $leftItems*/ + 18) { + each_value_5 = /*$leftItems*/ + ctx2[4]; + group_outros(); + each_blocks_1 = update_keyed_each(each_blocks_1, dirty, get_key, 1, ctx2, each_value_5, each0_lookup, div3, outro_and_destroy_block, create_each_block_5, null, get_each_context_5); + check_outros(); + } + if ( + /*systemHasCurrencies*/ + ctx2[19] + ) + if_block1.p(ctx2, dirty); + if ( + /*store*/ + ctx2[1].isUserParticipant + ) { + if (if_block2) { + if_block2.p(ctx2, dirty); + } else { + if_block2 = create_if_block_1(ctx2); + if_block2.c(); + if_block2.m(div5, null); + } + } else if (if_block2) { + if_block2.d(1); + if_block2 = null; + } + if (!current || dirty[0] & /*$rightTraderAccepted*/ + 8) { + toggle_class( + i1, + "accepted", + /*$rightTraderAccepted*/ + ctx2[3] + ); + } + if (!current || dirty[0] & /*$rightTraderAccepted*/ + 8) { + toggle_class( + i1, + "fa-user-check", + /*$rightTraderAccepted*/ + ctx2[3] + ); + } + if (!current || dirty[0] & /*$rightTraderAccepted*/ + 8) { + toggle_class(i1, "fa-user-times", !/*$rightTraderAccepted*/ + ctx2[3]); + } + if ((!current || dirty[0] & /*store*/ + 2) && t9_value !== (t9_value = /*store*/ + ctx2[1].rightTraderActor.name + "")) + set_data(t9, t9_value); + if (!current || dirty[0] & /*store*/ + 2 && !src_url_equal(img1.src, img1_src_value = /*store*/ + ctx2[1].rightTraderActor.img)) { + attr(img1, "src", img1_src_value); + } + if (dirty[0] & /*store, $rightItems*/ + 130) { + each_value_2 = /*$rightItems*/ + ctx2[7]; + group_outros(); + each_blocks = update_keyed_each(each_blocks, dirty, get_key_1, 1, ctx2, each_value_2, each1_lookup, div8, outro_and_destroy_block, create_each_block_2, null, get_each_context_2); + check_outros(); + } + if ( + /*systemHasCurrencies*/ + ctx2[19] + ) + if_block3.p(ctx2, dirty); + }, + i(local) { + if (current) + return; + for (let i = 0; i < each_value_5.length; i += 1) { + transition_in(each_blocks_1[i]); + } + transition_in(if_block1); + for (let i = 0; i < each_value_2.length; i += 1) { + transition_in(each_blocks[i]); + } + transition_in(if_block3); + current = true; + }, + o(local) { + for (let i = 0; i < each_blocks_1.length; i += 1) { + transition_out(each_blocks_1[i]); + } + transition_out(if_block1); + for (let i = 0; i < each_blocks.length; i += 1) { + transition_out(each_blocks[i]); + } + transition_out(if_block3); + current = false; + }, + d(detaching) { + if (detaching) + detach(div12); + if (if_block0) + if_block0.d(); + for (let i = 0; i < each_blocks_1.length; i += 1) { + each_blocks_1[i].d(); + } + if (if_block1) + if_block1.d(); + if (if_block2) + if_block2.d(); + for (let i = 0; i < each_blocks.length; i += 1) { + each_blocks[i].d(); + } + if (if_block3) + if_block3.d(); + } + }; +} +__name(create_default_slot_1, "create_default_slot_1"); +function create_default_slot(ctx) { + let t; + let dropzone; + let current; + let if_block = ( + /*$leftTraderAccepted*/ + ctx[2] && /*$rightTraderAccepted*/ + ctx[3] && create_if_block_7() + ); + dropzone = new DropZone({ + props: { + callback: ( + /*dropItem*/ + ctx[20] + ), + $$slots: { default: [create_default_slot_1] }, + $$scope: { ctx } + } + }); + return { + c() { + if (if_block) + if_block.c(); + t = space(); + create_component(dropzone.$$.fragment); + }, + m(target, anchor) { + if (if_block) + if_block.m(target, anchor); + insert(target, t, anchor); + mount_component(dropzone, target, anchor); + current = true; + }, + p(ctx2, dirty) { + if ( + /*$leftTraderAccepted*/ + ctx2[2] && /*$rightTraderAccepted*/ + ctx2[3] + ) { + if (if_block) { + if (dirty[0] & /*$leftTraderAccepted, $rightTraderAccepted*/ + 12) { + transition_in(if_block, 1); + } + } else { + if_block = create_if_block_7(); + if_block.c(); + transition_in(if_block, 1); + if_block.m(t.parentNode, t); + } + } else if (if_block) { + group_outros(); + transition_out(if_block, 1, 1, () => { + if_block = null; + }); + check_outros(); + } + const dropzone_changes = {}; + if (dirty[0] & /*$rightCurrencies, $rightItemCurrencies, store, $rightItems, $rightTraderAccepted, $leftTraderAccepted, $leftCurrencies, $leftItemCurrencies, $leftItems*/ + 1022 | dirty[1] & /*$$scope*/ + 65536) { + dropzone_changes.$$scope = { dirty, ctx: ctx2 }; + } + dropzone.$set(dropzone_changes); + }, + i(local) { + if (current) + return; + transition_in(if_block); + transition_in(dropzone.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(if_block); + transition_out(dropzone.$$.fragment, local); + current = false; + }, + d(detaching) { + if (if_block) + if_block.d(detaching); + if (detaching) + detach(t); + destroy_component(dropzone, detaching); + } + }; +} +__name(create_default_slot, "create_default_slot"); +function create_fragment(ctx) { + let applicationshell; + let updating_elementRoot; + let current; + function applicationshell_elementRoot_binding(value) { + ctx[31](value); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + let applicationshell_props = { + $$slots: { default: [create_default_slot] }, + $$scope: { ctx } + }; + if ( + /*elementRoot*/ + ctx[0] !== void 0 + ) { + applicationshell_props.elementRoot = /*elementRoot*/ + ctx[0]; + } + applicationshell = new ApplicationShell({ props: applicationshell_props }); + binding_callbacks.push(() => bind(applicationshell, "elementRoot", applicationshell_elementRoot_binding)); + return { + c() { + create_component(applicationshell.$$.fragment); + }, + m(target, anchor) { + mount_component(applicationshell, target, anchor); + current = true; + }, + p(ctx2, dirty) { + const applicationshell_changes = {}; + if (dirty[0] & /*$rightCurrencies, $rightItemCurrencies, store, $rightItems, $rightTraderAccepted, $leftTraderAccepted, $leftCurrencies, $leftItemCurrencies, $leftItems*/ + 1022 | dirty[1] & /*$$scope*/ + 65536) { + applicationshell_changes.$$scope = { dirty, ctx: ctx2 }; + } + if (!updating_elementRoot && dirty[0] & /*elementRoot*/ + 1) { + updating_elementRoot = true; + applicationshell_changes.elementRoot = /*elementRoot*/ + ctx2[0]; + add_flush_callback(() => updating_elementRoot = false); + } + applicationshell.$set(applicationshell_changes); + }, + i(local) { + if (current) + return; + transition_in(applicationshell.$$.fragment, local); + current = true; + }, + o(local) { + transition_out(applicationshell.$$.fragment, local); + current = false; + }, + d(detaching) { + destroy_component(applicationshell, detaching); + } + }; +} +__name(create_fragment, "create_fragment"); +function instance($$self, $$props, $$invalidate) { + let $leftTraderAccepted; + let $rightTraderAccepted; + let $leftItems; + let $leftCurrencies; + let $leftItemCurrencies; + let $rightItems; + let $rightCurrencies; + let $rightItemCurrencies; + let { elementRoot } = $$props; + let { store } = $$props; + const leftItems = store.leftTraderItems; + component_subscribe($$self, leftItems, (value) => $$invalidate(4, $leftItems = value)); + const leftCurrencies = store.leftTraderCurrencies; + component_subscribe($$self, leftCurrencies, (value) => $$invalidate(5, $leftCurrencies = value)); + const leftItemCurrencies = store.leftTraderItemCurrencies; + component_subscribe($$self, leftItemCurrencies, (value) => $$invalidate(6, $leftItemCurrencies = value)); + const leftTraderAccepted = store.leftTraderAccepted; + component_subscribe($$self, leftTraderAccepted, (value) => $$invalidate(2, $leftTraderAccepted = value)); + const rightItems = store.rightTraderItems; + component_subscribe($$self, rightItems, (value) => $$invalidate(7, $rightItems = value)); + const rightCurrencies = store.rightTraderCurrencies; + component_subscribe($$self, rightCurrencies, (value) => $$invalidate(8, $rightCurrencies = value)); + const rightItemCurrencies = store.rightTraderItemCurrencies; + component_subscribe($$self, rightItemCurrencies, (value) => $$invalidate(9, $rightItemCurrencies = value)); + const rightTraderAccepted = store.rightTraderAccepted; + component_subscribe($$self, rightTraderAccepted, (value) => $$invalidate(3, $rightTraderAccepted = value)); + let isGM = game.user.isGM; + let systemHasCurrencies = game.itempiles.API.CURRENCIES.length > 0; + async function dropItem(data2) { + if (data2.type !== "Item") + return; + let item = (await Item.implementation.fromDropData(data2)).toObject(); + data2.actorId = getSourceActorFromDropData(data2)?.id; + if (!data2.actorId && !game.user.isGM) { + return custom_warning(game.i18n.localize("ITEM-PILES.Errors.NoSourceDrop"), true); + } + if (!game.user.isGM && data2.actorId && data2.actorId !== store.leftTraderActor.id) { + throw custom_error(`You cannot drop items into the trade UI from a different actor than ${store.leftTraderActor.name}!`); + } + const validItem = await checkItemType(store.rightTraderActor, item, { + errorText: "ITEM-PILES.Errors.DisallowedItemTrade", + warningTitle: "ITEM-PILES.Dialogs.TypeWarning.Title", + warningContent: "ITEM-PILES.Dialogs.TypeWarning.TradeContent" + }); + if (!validItem) + return; + const actorItemCurrencyList = getCurrencyList(store.leftTraderActor).filter((entry) => entry.type !== "attribute"); + const isCurrency = !!findSimilarItem(actorItemCurrencyList.map((item2) => item2.data), validItem); + if (!validItem._id) { + validItem._id = item._id; + } + const itemToSend = await Item.implementation.create(validItem, { temporary: true }); + return store.addItem(itemToSend, { + uuid: data2.uuid, + quantity: 1, + currency: isCurrency + }); + } + __name(dropItem, "dropItem"); + if (store.isUserParticipant) { + const itemsUpdatedDebounce = debounce( + async (items) => { + await ItemPileSocket.executeForUsers(ItemPileSocket.HANDLERS.PRIVATE_TRADE_UPDATE_ITEMS, [store.leftTraderUser.id, store.rightTraderUser.id], store.privateTradeId, game.user.id, items); + return executeSocketAction(ItemPileSocket.HANDLERS.PUBLIC_TRADE_UPDATE_ITEMS, store.publicTradeId, game.user.id, items); + }, + 20 + ); + leftItems.subscribe(itemsUpdatedDebounce); + const itemCurrenciesUpdatedDebounce = debounce( + async (items) => { + await ItemPileSocket.executeForUsers(ItemPileSocket.HANDLERS.PRIVATE_TRADE_UPDATE_ITEM_CURRENCIES, [store.leftTraderUser.id, store.rightTraderUser.id], store.privateTradeId, game.user.id, items); + return executeSocketAction(ItemPileSocket.HANDLERS.PUBLIC_TRADE_UPDATE_ITEM_CURRENCIES, store.publicTradeId, game.user.id, items); + }, + 20 + ); + leftItemCurrencies.subscribe(itemCurrenciesUpdatedDebounce); + const attributesUpdatedDebounce = debounce( + async (attributes) => { + await ItemPileSocket.executeForUsers(ItemPileSocket.HANDLERS.PRIVATE_TRADE_UPDATE_CURRENCIES, [store.leftTraderUser.id, store.rightTraderUser.id], store.privateTradeId, game.user.id, attributes); + return executeSocketAction(ItemPileSocket.HANDLERS.PUBLIC_TRADE_UPDATE_CURRENCIES, store.publicTradeId, game.user.id, attributes); + }, + 40 + ); + leftCurrencies.subscribe(attributesUpdatedDebounce); + const acceptedDebounce = debounce( + async (acceptedState) => { + await ItemPileSocket.executeForUsers(ItemPileSocket.HANDLERS.PRIVATE_TRADE_STATE, [store.leftTraderUser.id, store.rightTraderUser.id], store.privateTradeId, game.user.id, acceptedState); + return executeSocketAction(ItemPileSocket.HANDLERS.PUBLIC_TRADE_STATE, store.publicTradeId, game.user.id, acceptedState); + }, + 10 + ); + leftTraderAccepted.subscribe(acceptedDebounce); + } + async function executeSocketAction(socketHandler, ...args) { + if (store.isPrivate) { + return ItemPileSocket.executeForUsers(socketHandler, [store.leftTraderUser.id, store.rightTraderUser.id], ...args); + } + return ItemPileSocket.executeForEveryone(socketHandler, ...args); + } + __name(executeSocketAction, "executeSocketAction"); + async function addCurrency(asGM = false) { + const currenciesToAdd = await DropCurrencyDialog.show(store.leftTraderActor, store.rightTraderActor, { + existingCurrencies: store.getExistingCurrencies(), + title: game.i18n.localize("ITEM-PILES.Trade.AddCurrency.Title"), + content: game.i18n.format("ITEM-PILES.Trade.AddCurrency.Content", { + trader_actor_name: store.rightTraderActor.name + }), + button: game.i18n.localize("ITEM-PILES.Trade.AddCurrency.Label"), + unlimitedCurrencies: asGM + }); + if (!currenciesToAdd || foundry.utils.isEmpty(currenciesToAdd.attributes) && !currenciesToAdd.items.length) + return; + currenciesToAdd.items.forEach((item) => { + const itemData = store.leftTraderActor.items.get(item._id).toObject(); + store.addItem(itemData, { quantity: item.quantity, currency: true }); + }); + const currencies = getActorCurrencies(store.leftTraderActor, { getAll: asGM }).filter((currency) => currency.type === "attribute"); + Object.entries(currenciesToAdd.attributes).forEach(([path, quantity]) => { + const currency = currencies.find((currency2) => currency2.path === path); + store.addAttribute({ + path, + quantity, + newQuantity: quantity, + name: currency.name, + img: currency.img, + maxQuantity: !game.user.isGM ? currency.quantity : Infinity, + index: currency.index + }); + }); + } + __name(addCurrency, "addCurrency"); + function tradeentry_data_binding(value, item, each_value_5, item_index_3) { + each_value_5[item_index_3] = value; + leftItems.set($leftItems); + } + __name(tradeentry_data_binding, "tradeentry_data_binding"); + const click_handler = /* @__PURE__ */ __name(() => { + addCurrency(true); + }, "click_handler"); + const click_handler_1 = /* @__PURE__ */ __name(() => { + addCurrency(); + }, "click_handler_1"); + function tradeentry_data_binding_1(value, currency, each_value_4, currency_index_1) { + each_value_4[currency_index_1] = value; + leftCurrencies.set($leftCurrencies); + } + __name(tradeentry_data_binding_1, "tradeentry_data_binding_1"); + function tradeentry_data_binding_2(value, item, each_value_3, item_index_2) { + each_value_3[item_index_2] = value; + leftItemCurrencies.set($leftItemCurrencies); + } + __name(tradeentry_data_binding_2, "tradeentry_data_binding_2"); + const click_handler_2 = /* @__PURE__ */ __name(() => { + store.toggleAccepted(store.leftTraderUser.id); + }, "click_handler_2"); + function tradeentry_data_binding_3(value, item, each_value_2, item_index_1) { + each_value_2[item_index_1] = value; + rightItems.set($rightItems); + } + __name(tradeentry_data_binding_3, "tradeentry_data_binding_3"); + function tradeentry_data_binding_4(value, currency, each_value_1, currency_index) { + each_value_1[currency_index] = value; + rightCurrencies.set($rightCurrencies); + } + __name(tradeentry_data_binding_4, "tradeentry_data_binding_4"); + function tradeentry_data_binding_5(value, item, each_value, item_index) { + each_value[item_index] = value; + rightItemCurrencies.set($rightItemCurrencies); + } + __name(tradeentry_data_binding_5, "tradeentry_data_binding_5"); + function applicationshell_elementRoot_binding(value) { + elementRoot = value; + $$invalidate(0, elementRoot); + } + __name(applicationshell_elementRoot_binding, "applicationshell_elementRoot_binding"); + $$self.$$set = ($$props2) => { + if ("elementRoot" in $$props2) + $$invalidate(0, elementRoot = $$props2.elementRoot); + if ("store" in $$props2) + $$invalidate(1, store = $$props2.store); + }; + return [ + elementRoot, + store, + $leftTraderAccepted, + $rightTraderAccepted, + $leftItems, + $leftCurrencies, + $leftItemCurrencies, + $rightItems, + $rightCurrencies, + $rightItemCurrencies, + leftItems, + leftCurrencies, + leftItemCurrencies, + leftTraderAccepted, + rightItems, + rightCurrencies, + rightItemCurrencies, + rightTraderAccepted, + isGM, + systemHasCurrencies, + dropItem, + addCurrency, + tradeentry_data_binding, + click_handler, + click_handler_1, + tradeentry_data_binding_1, + tradeentry_data_binding_2, + click_handler_2, + tradeentry_data_binding_3, + tradeentry_data_binding_4, + tradeentry_data_binding_5, + applicationshell_elementRoot_binding + ]; +} +__name(instance, "instance"); +class Trading_app_shell extends SvelteComponent { + constructor(options) { + super(); + init(this, options, instance, create_fragment, safe_not_equal, { elementRoot: 0, store: 1 }, null, [-1, -1]); + } + get elementRoot() { + return this.$$.ctx[0]; + } + set elementRoot(elementRoot) { + this.$$set({ elementRoot }); + flush(); + } + get store() { + return this.$$.ctx[1]; + } + set store(store) { + this.$$set({ store }); + flush(); + } +} +__name(Trading_app_shell, "Trading_app_shell"); +class TradingApp extends SvelteApplication { + constructor(store, options = {}, dialogData = {}) { + super({ + title: game.i18n.format("ITEM-PILES.Trade.Between", { + actor_1: store.leftTraderActor.name, + actor_2: store.rightTraderActor.name + }), + svelte: { + class: Trading_app_shell, + target: document.body, + props: { + store + } + }, + ...options + }, dialogData); + this.store = store; + this.publicTradeId = store.publicTradeId; + } + static get defaultOptions() { + return foundry.utils.mergeObject(super.defaultOptions, { + zIndex: 100, + classes: ["dialog", "item-piles-trading-sheet", "item-piles", "item-piles-app"], + width: 800, + height: "auto", + closeOnSubmit: false + }); + } + static getActiveApp(publicTradeId) { + for (const app of Object.values(ui.windows)) { + if (app instanceof this && app?.publicTradeId === publicTradeId) { + return app; + } + } + return false; + } + async close(options = {}) { + if (!options?.callback && this.store.isUserParticipant) { + await ItemPileSocket.executeForEveryone(ItemPileSocket.HANDLERS.TRADE_CLOSED, this.publicTradeId, game.user.id); + } + return super.close(options); + } +} +__name(TradingApp, "TradingApp"); +const mutedUsers = /* @__PURE__ */ new Set(); +const ongoingTrades = /* @__PURE__ */ new Map(); +class TradeAPI { + static initialize() { + Hooks.on("renderPlayerList", this._userDisconnected.bind(this)); + } + static async _requestTrade(user = false) { + const users = game.users.filter((user2) => user2.active && user2 !== game.user); + if (!users.length) { + return TJSDialog.prompt({ + title: game.i18n.localize("ITEM-PILES.Trade.Title"), + content: { + class: CustomDialog, + props: { + header: game.i18n.localize("ITEM-PILES.Trade.NoActiveUsers.Title"), + content: game.i18n.localize("ITEM-PILES.Trade.NoActiveUsers.Content"), + icon: "fas fa-heart-broken" + } + }, + modal: true, + draggable: false, + options: { + height: "auto" + } + }); + } + let userId; + let actor; + let isPrivate; + const actors = game.actors.filter((actor2) => actor2.isOwner); + if (actors.length === 1 && user) { + userId = user.id; + actor = actors[0]; + isPrivate = false; + } else { + const result = await TradePromptDialog.show({ actors, users, user }); + if (!result) + return; + userId = result.user.id; + actor = result.actor; + isPrivate = result.private; + } + if (!actor) + return false; + actor = getActor(actor); + const actorOwner = game.users.find((user2) => user2.character === actor && user2 !== game.user); + if (actorOwner) { + const doContinue = TJSDialog.confirm({ + title: game.i18n.localize("ITEM-PILES.Trade.Title"), + content: { + class: CustomDialog, + props: { + header: game.i18n.localize("ITEM-PILES.Trade.Title"), + content: actorOwner.active ? game.i18n.format("ITEM-PILES.Trade.UserActiveCharacterWarning", { + actor_name: actor.name, + player_name: actorOwner.name + }) : game.i18n.format("ITEM-PILES.Trade.UserCharacterWarning", { + actor_name: actor.name, + player_name: actorOwner.name + }), + icon: "fas fa-exclamation-triangle" + } + }, + modal: true, + draggable: false, + rejectClose: false, + defaultYes: true, + options: { + height: "auto" + } + }); + if (!doContinue) { + return; + } + } + const privateTradeId = randomID(); + const publicTradeId = randomID(); + const cancelDialog = new Dialog({ + title: game.i18n.localize("ITEM-PILES.Trade.Title"), + content: `${game.i18n.format("ITEM-PILES.Trade.OngoingRequest.Content", { user_name: game.users.get(userId).name })}
`, + buttons: { + confirm: { + icon: '', + label: game.i18n.localize("ITEM-PILES.Trade.OngoingRequest.Label"), + callback: () => { + ItemPileSocket.executeAsUser(ItemPileSocket.HANDLERS.TRADE_REQUEST_CANCELLED, userId, game.user.id, privateTradeId); + } + } + } + }, { + top: 50, + width: 300 + }).render(true); + return ItemPileSocket.executeAsUser(ItemPileSocket.HANDLERS.TRADE_REQUEST_PROMPT, userId, game.user.id, actor.uuid, privateTradeId, publicTradeId, isPrivate).then(async (data2) => { + if (data2 === "cancelled") + return; + cancelDialog.close(); + if (data2 === "same-actor") { + return custom_warning(game.i18n.localize("ITEM-PILES.Trade.SameActor"), true); + } + if (!data2 || !data2.fullPrivateTradeId.includes(privateTradeId)) { + return custom_warning(game.i18n.localize("ITEM-PILES.Trade.Declined"), true); + } + const traderActor = getActor(data2.actorUuid); + if (traderActor === actor) { + return custom_warning(game.i18n.localize("ITEM-PILES.Trade.SameActor"), true); + } + const store = new TradeStore(game.user.id, { + user: game.user, + actor + }, { + user: game.users.get(userId), + actor: traderActor + }, data2.fullPublicTradeId, data2.fullPrivateTradeId, isPrivate); + const [actorSheet, tradeApp] = getApplicationPositions(actor.sheet); + const app = new TradingApp(store, tradeApp).render(true); + ongoingTrades.set(data2.fullPublicTradeId, { app, store }); + actorSheet.byassItemPiles = true; + actor.sheet.render(true, actorSheet); + if (isPrivate) { + return ItemPileSocket.callHookForUsers(CONSTANTS.HOOKS.TRADE.STARTED, [game.user.id, userId], { + user: game.user.id, + actor: actor.uuid + }, { user: userId, actor: data2.actorUuid }, data2.fullPublicTradeId, isPrivate); + } + return ItemPileSocket.callHook(CONSTANTS.HOOKS.TRADE.STARTED, { + user: game.user.id, + actor: actor.uuid + }, { user: userId, actor: data2.actorUuid }, data2.fullPublicTradeId, isPrivate); + }).catch((err) => { + console.error(err); + custom_warning(game.i18n.localize("ITEM-PILES.Trade.Disconnected"), true); + cancelDialog.close(); + }); + } + static async _respondPrompt(tradingUserId, tradingActorUuid, privateTradeId, publicTradeId, isPrivate) { + if (mutedUsers.has(tradingUserId)) { + await wait(Math.random() * 15e3); + return false; + } + const fullPrivateTradeId = privateTradeId + randomID(); + const fullPublicTradeId = publicTradeId + randomID(); + const tradingUser = game.users.get(tradingUserId); + const tradingActor = getActor(tradingActorUuid); + const result = await TradeRequestDialog.show({ tradeId: privateTradeId, tradingUser, tradingActor, isPrivate }); + if (!result) + return false; + if (result === "cancelled") { + return "cancelled"; + } + if (result === "mute") { + mutedUsers.push(tradingUserId); + return false; + } + const actor = result.actor ?? result; + if (actor === tradingActor) { + custom_warning(game.i18n.localize("ITEM-PILES.Trade.SameActor"), true); + return "same-actor"; + } + const store = new TradeStore(tradingUserId, { + user: game.user, + actor + }, { + user: tradingUser, + actor: tradingActor + }, fullPublicTradeId, fullPrivateTradeId, isPrivate); + const [actorSheet, tradeApp] = getApplicationPositions(actor.sheet); + const app = new TradingApp(store, tradeApp).render(true); + ongoingTrades.set(fullPublicTradeId, { app, store }); + actorSheet.byassItemPiles = true; + actor.sheet.render(true, actorSheet); + return { + fullPrivateTradeId, + fullPublicTradeId, + actorUuid: result.uuid + }; + } + static getAppOptions(actor) { + const midPoint = window.innerWidth / 2 - 200; + return { + actorSheet: { left: midPoint - actor.sheet.position.width - 25 }, + tradeApp: { left: midPoint + 25 } + }; + } + static async _tradeCancelled(userId, privateTradeId) { + TJSDialog.prompt({ + title: game.i18n.localize("ITEM-PILES.Trade.Title"), + content: { + class: CustomDialog, + props: { + header: game.i18n.localize("ITEM-PILES.Trade.Title"), + content: game.i18n.format("ITEM-PILES.Trade.CancelledRequest.Content", { user_name: game.users.get(userId).name }), + icon: "fas fa-exclamation-triangle" + } + }, + modal: true, + draggable: false, + options: { + height: "auto" + } + }); + return TradeRequestDialog.cancel(privateTradeId); + } + static async _requestTradeData({ tradeId, tradeUser } = {}) { + const ongoingTrade = this._getOngoingTrade(tradeId); + if (ongoingTrade) { + return ongoingTrade.store.export(); + } + const user = game.users.get(tradeUser); + if (!user?.active) { + return false; + } + const ongoingTradeData = await ItemPileSocket.executeAsUser(ItemPileSocket.HANDLERS.REQUEST_TRADE_DATA, tradeUser, tradeId, game.user.id); + if (!ongoingTradeData) { + return false; + } + return ongoingTradeData; + } + static async _spectateTrade({ tradeId, tradeUser } = {}) { + const existingApp = TradingApp.getActiveApp(tradeId); + if (existingApp) { + return existingApp.render(false, { focus: true }); + } + const ongoingTradeData = await this._requestTradeData({ tradeId, tradeUser }); + if (!ongoingTradeData) { + if (isGMConnected()) { + ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.DISABLE_CHAT_TRADE_BUTTON, tradeId); + } + return custom_warning(game.i18n.localize("ITEM-PILES.Trade.Over"), true); + } + const store = TradeStore.import(ongoingTradeData); + const app = new TradingApp(store).render(true); + ongoingTrades.set(store.publicTradeId, { app, store }); + } + static async _respondActiveTradeData(tradeId, requesterId) { + const trade = this._getOngoingTrade(tradeId, requesterId); + if (!trade) + return; + return trade.store.export(); + } + static _getOngoingTrade(tradeId, requesterId = game.user.id) { + if (!ongoingTrades.has(tradeId)) + return false; + const trade = ongoingTrades.get(tradeId); + if (!trade.store.isPrivate) { + return trade; + } + if (trade.store.leftTraderUser.id !== requesterId && trade.store.rightTraderUser.id !== requesterId) + return false; + return trade; + } + static async _updateItems(tradeId, userId, items) { + const trade = this._getOngoingTrade(tradeId); + if (!trade) + return; + trade.store.updateItems(userId, items); + } + static async _updateItemCurrencies(tradeId, userId, items) { + const trade = this._getOngoingTrade(tradeId); + if (!trade) + return; + trade.store.updateItemCurrencies(userId, items); + } + static async _updateCurrencies(tradeId, userId, currencies) { + const trade = this._getOngoingTrade(tradeId); + if (!trade) + return; + trade.store.updateCurrencies(userId, currencies); + } + static async _updateAcceptedState(tradeId, userId, status) { + const trade = this._getOngoingTrade(tradeId); + if (!trade) + return; + trade.store.updateAcceptedState(userId, status); + if (userId === game.user.id && (trade.store.leftTraderUser.id === game.user.id || trade.store.rightTraderUser.id === game.user.id)) { + if (trade.store.tradeIsAccepted) { + setTimeout(async () => { + if (trade.store.tradeIsAccepted) { + ItemPileSocket.executeForUsers( + ItemPileSocket.HANDLERS.EXECUTE_TRADE, + [trade.store.leftTraderUser.id, trade.store.rightTraderUser.id], + trade.store.publicTradeId, + trade.store.privateTradeId, + userId + ); + } + }, 2e3); + } + } + } + static async _userDisconnected() { + const tradesToDelete = []; + const activeUsers = game.users.filter((user) => user.active); + for (let [tradeId, trade] of ongoingTrades) { + const foundLeft = activeUsers.find((u) => u === trade.store.leftTraderUser); + const foundRight = activeUsers.find((u) => u === trade.store.rightTraderUser); + if (foundLeft && foundRight) + continue; + tradesToDelete.push(tradeId); + custom_warning(game.i18n.localize("ITEM-PILES.Trade.Disconnected"), true); + await trade.app.close({ callback: true }); + if (foundLeft === game.user || foundRight === game.user) { + if (isGMConnected()) { + await ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.DISABLE_CHAT_TRADE_BUTTON, tradeId); + } + } + } + tradesToDelete.forEach((tradeId) => ongoingTrades.delete(tradeId)); + } + static async _tradeClosed(tradeId, closeUserId) { + const trade = this._getOngoingTrade(tradeId); + if (!trade) + return; + if (trade.store.leftTraderUser.id === game.user.id || trade.store.rightTraderUser.id === game.user.id) { + if (closeUserId === trade.store.rightTraderUser.id) { + TJSDialog.prompt({ + title: game.i18n.localize("ITEM-PILES.Trade.Closed.Title"), + content: { + class: CustomDialog, + props: { + header: game.i18n.localize("ITEM-PILES.Trade.Closed.Title"), + content: game.i18n.format("ITEM-PILES.Trade.Closed.Them", { + user_name: trade.store.rightTraderUser.name + }), + icon: "fas fa-exclamation-triangle" + } + }, + modal: false, + draggable: true, + options: { + height: "auto" + } + }); + } else { + if (trade.store.isPrivate) { + const otherUserId = trade.store.leftTraderUser.id === game.user.id ? trade.store.rightTraderUser.id : trade.store.leftTraderUser.id; + ItemPileSocket.executeAsUser(ItemPileSocket.HANDLERS.TRADE_CLOSED, otherUserId, tradeId, game.user.id); + } else { + ItemPileSocket.executeForOthers(ItemPileSocket.HANDLERS.TRADE_CLOSED, tradeId, game.user.id); + } + TJSDialog.prompt({ + title: game.i18n.localize("ITEM-PILES.Trade.Closed.Title"), + content: { + class: CustomDialog, + props: { + header: game.i18n.localize("ITEM-PILES.Trade.Closed.Title"), + content: game.i18n.format("ITEM-PILES.Trade.Closed.You"), + icon: "fas fa-exclamation-triangle" + } + }, + modal: false, + draggable: true, + options: { + height: "auto" + } + }); + if (isGMConnected()) { + await ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.DISABLE_CHAT_TRADE_BUTTON, tradeId); + } + } + } else { + custom_warning(game.i18n.localize("ITEM-PILES.Trade.Closed.Someone"), true); + } + trade.app.close({ callback: true }); + ongoingTrades.delete(tradeId); + } + static async _executeTrade(tradeId, privateId, userId) { + const trade = this._getOngoingTrade(tradeId); + if (!trade) + return; + if (trade.store.privateTradeId !== privateId) + return; + const updates = trade.store.getTradeData(); + const itemsToAdd = []; + for (const entry of updates.add.items) { + let item = updates.targetActor.items.get(entry.id); + if (!item) { + item = await fromUuid(entry.uuid); + if (!item) + continue; + } + const itemData = item.toObject(); + itemsToAdd.push(setItemQuantity(itemData, entry.quantity, true)); + } + const itemsToRemove = []; + for (const entry of updates.remove.items) { + const item = updates.sourceActor.items.get(entry.id); + if (!item) + continue; + const itemData = item.toObject(); + itemsToRemove.push(setItemQuantity(itemData, entry.quantity, true)); + } + const transaction = new Transaction(updates.sourceActor); + await transaction.appendItemChanges(itemsToAdd); + await transaction.appendItemChanges(itemsToRemove, { remove: true }); + await transaction.appendActorChanges(updates.add.attributes); + await transaction.appendActorChanges(updates.remove.attributes, { remove: true }); + await transaction.commit(); + if (trade.store.isPrivate) { + Hooks.callAll(CONSTANTS.HOOKS.TRADE.COMPLETE, trade.store.instigator, data[0], data[1], tradeId); + trade.app.close({ callback: true }); + ongoingTrades.delete(tradeId); + } else if (userId === game.user.id) { + if (isGMConnected()) { + await ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.DISABLE_CHAT_TRADE_BUTTON, tradeId); + } + return ItemPileSocket.executeForEveryone(ItemPileSocket.HANDLERS.TRADE_COMPLETED, tradeId, updates); + } + } + static async _tradeCompleted(tradeId) { + const trade = this._getOngoingTrade(tradeId); + if (!trade) + return; + const data2 = trade.store.export(); + if (data2.instigator === game.user.id) { + if (trade.store.isPrivate) { + Hooks.callAll(CONSTANTS.HOOKS.TRADE.COMPLETE, data2.instigator, data2.leftTraderData, data2.rightTraderData, tradeId); + } else { + ItemPileSocket.executeForEveryone( + ItemPileSocket.HANDLERS.CALL_HOOK, + CONSTANTS.HOOKS.TRADE.COMPLETE, + trade.store.instigator, + data2.leftTraderData, + data2.rightTraderData, + tradeId, + trade.store.isPrivate + ); + } + } + trade.app.close({ callback: true }); + ongoingTrades.delete(tradeId); + } +} +__name(TradeAPI, "TradeAPI"); +class ChatAPI { + static initialize() { + hooks.on("preCreateChatMessage", this._preCreateChatMessage.bind(this)); + hooks.on("renderChatMessage", this._renderChatMessage.bind(this)); + hooks.on(CONSTANTS.HOOKS.ITEM.TRANSFER, this._outputTransferItem.bind(this)); + hooks.on(CONSTANTS.HOOKS.ATTRIBUTE.TRANSFER, this._outputTransferCurrency.bind(this)); + hooks.on(CONSTANTS.HOOKS.TRANSFER_EVERYTHING, this._outputTransferEverything.bind(this)); + hooks.on(CONSTANTS.HOOKS.PILE.SPLIT_INVENTORY, this._outputSplitItemPileInventory.bind(this)); + hooks.on(CONSTANTS.HOOKS.TRADE.STARTED, this._outputTradeStarted.bind(this)); + hooks.on(CONSTANTS.HOOKS.TRADE.COMPLETE, this._outputTradeComplete.bind(this)); + hooks.on(CONSTANTS.HOOKS.ITEM.TRADE, this._outputMerchantTradeComplete.bind(this)); + hooks.on(CONSTANTS.HOOKS.ITEM.GIVE, this._outputGiveItem.bind(this)); + $(document).on("click", ".item-piles-chat-card .item-piles-collapsible", async function() { + if ($(this).attr("open")) + return; + await wait(25); + $(this).parent()[0].scrollIntoView({ behavior: "smooth", block: "nearest", inline: "start" }); + }); + } + static _preCreateChatMessage(chatMessage) { + if (!getSetting(SETTINGS$1.ENABLE_TRADING)) + return; + const content = chatMessage.content.toLowerCase(); + if (!(content.startsWith("!itempiles") || content.startsWith("!ip"))) + return; + const args = content.split(" ").slice(1); + if (args[0] === "trade") { + setTimeout(() => { + game.itempiles.API.requestTrade(); + }); + } + return false; + } + static _renderChatMessage(app, html) { + html.find(".item-piles-specate-trade").click(function() { + game.itempiles.API.spectateTrade($(this).data()); + }); + } + static _disableTradingButton(publicTradeId) { + const message = Array.from(game.messages).find((message2) => { + return getProperty(message2, CONSTANTS.FLAGS.PUBLIC_TRADE_ID) === publicTradeId; + }); + if (!message) + return; + const update2 = this._replaceChatContent(message); + return message.update(update2); + } + static async disablePastTradingButtons() { + if (!game.user.isGM) + return; + const messages = Array.from(game.messages).filter((message) => { + return getProperty(message, CONSTANTS.FLAGS.PUBLIC_TRADE_ID); + }); + if (!messages.length) + return; + const updates = []; + for (let message of messages) { + const update2 = this._replaceChatContent(message); + const tradeId = getProperty(message, CONSTANTS.FLAGS.PUBLIC_TRADE_ID); + const tradeUsers = getProperty(message, CONSTANTS.FLAGS.TRADE_USERS); + const bothUsersActive = tradeUsers.filter((userId) => game.users.get(userId).active).length === tradeUsers.length; + if (!bothUsersActive) { + updates.push(update2); + } else { + const otherUsers = tradeUsers.filter((userId) => userId !== game.user.id); + const tradeData = await TradeAPI._requestTradeData({ tradeId, tradeUser: otherUsers[0] }); + if (!tradeData) { + updates.push(update2); + } + } + } + if (!updates.length) + return; + return ChatMessage.updateDocuments(updates); + } + static _replaceChatContent(message) { + const tradeId = getProperty(message, CONSTANTS.FLAGS.PUBLIC_TRADE_ID); + const stringToFind = `data-trade-id="${tradeId}"`; + let content = message.content; + content = content.replace(stringToFind, ""); + content = content.replace(stringToFind, "disabled"); + content = content.replace(game.i18n.localize("ITEM-PILES.Chat.TradeSpectate"), game.i18n.localize("ITEM-PILES.Chat.SpectateDisabled")); + return { + _id: message.id, + content, + [`flags.-=${CONSTANTS.MODULE_NAME}`]: null + }; + } + /** + * Outputs to chat based on transferring an item from or to an item pile + * + * @param source + * @param target + * @param items + * @param userId + * @param interactionId + * @returns {Promise} + */ + static async _outputTransferItem(source, target, items, userId, interactionId) { + if (!isItemPileLootable(source)) + return; + if (!interactionId || game.user.id !== userId || !getSetting(SETTINGS$1.OUTPUT_TO_CHAT)) + return; + const [itemData, itemCurrencies] = await this._formatItemData(source, items); + return ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.PICKUP_CHAT_MESSAGE, source.uuid, target.uuid, itemData, itemCurrencies, userId, interactionId); + } + /** + * Outputs to chat based on transferring a currency from or to an item pile + * + * @param source + * @param target + * @param currencies + * @param userId + * @param interactionId + * @returns {Promise} + */ + static async _outputTransferCurrency(source, target, currencies, userId, interactionId) { + if (!isItemPileLootable(source)) + return; + if (!interactionId || game.user.id !== userId || !getSetting(SETTINGS$1.OUTPUT_TO_CHAT)) + return; + const currencyData = this._formatCurrencyData(source, currencies); + return ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.PICKUP_CHAT_MESSAGE, source.uuid, target.uuid, [], currencyData, userId, interactionId); + } + /** + * Outputs to chat based on giving an item from one actor to another + * + * @param source + * @param target + * @param item + * @param userId + * @returns {Promise} + */ + static async _outputGiveItem(source, target, item, userId) { + if (game.user.id !== userId || !getSetting(SETTINGS$1.OUTPUT_TO_CHAT)) + return; + const [itemData, itemCurrencies] = await this._formatItemData(source, [item]); + return this._giveChatMessage(source, target, itemData.concat(itemCurrencies), userId); + } + /** + * Outputs to chat based on transferring everything from or to an item pile + * + * @param source + * @param target + * @param items + * @param currencies + * @param userId + * @param interactionId + * @returns {Promise} + */ + static async _outputTransferEverything(source, target, items, currencies, userId, interactionId) { + if (!isItemPileLootable(source)) + return; + if (!interactionId || game.user.id !== userId || !getSetting(SETTINGS$1.OUTPUT_TO_CHAT)) + return; + const [itemData, itemCurrencies] = await this._formatItemData(source, items); + const currencyData = this._formatCurrencyData(source, currencies).concat(itemCurrencies); + return ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.PICKUP_CHAT_MESSAGE, source.uuid, target.uuid, itemData, currencyData, userId, interactionId); + } + static _outputSplitItemPileInventory(source, pileDeltas, actorDeltas, userId) { + if (!isItemPileLootable(source)) + return; + if (game.user.id !== userId || !getSetting(SETTINGS$1.OUTPUT_TO_CHAT)) + return; + return ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.SPLIT_CHAT_MESSAGE, source.uuid, pileDeltas, actorDeltas, userId); + } + static async _outputTradeStarted(party_1, party_2, publicTradeId, isPrivate) { + if (party_1.user !== game.user.id || !getSetting(SETTINGS$1.OUTPUT_TO_CHAT) || isPrivate) + return; + return this._outputTradeStartedToChat(party_1, party_2, publicTradeId); + } + static async _outputTradeComplete(instigator, party_1, party_2, publicTradeId, isPrivate) { + if (!getSetting(SETTINGS$1.OUTPUT_TO_CHAT)) + return; + return this._outputTradeCompleteToChat(instigator, party_1, party_2, publicTradeId, isPrivate); + } + static async _outputMerchantTradeComplete(source, target, priceInformation, userId, interactionId) { + if (!getSetting(SETTINGS$1.OUTPUT_TO_CHAT)) + return; + if (!isItemPileMerchant(source)) + return; + if (!interactionId || game.user.id !== userId || !getSetting(SETTINGS$1.OUTPUT_TO_CHAT)) + return; + return ItemPileSocket.executeAsGM(ItemPileSocket.HANDLERS.MERCHANT_TRADE_CHAT_MESSAGE, source.uuid, target.uuid, priceInformation, userId, interactionId); + } + /** + * Formats item data to a chat friendly structure + * + * @param itemPile + * @param items + * @param divideBy + * @returns {Promise