import type * as React from 'react';
import { useCallback, useEffect } from 'react';
import { useAppStateStore, useSetAppState } from 'src/state/AppState.js';
import type { Theme } from '../utils/theme.js';
type Priority = 'low' | 'medium' | 'high' | 'immediate';
type BaseNotification = {
  key: string;
  /**
   * Keys of notifications that this notification invalidates.
   * If a notification is invalidated, it will be removed from the queue
   * and, if currently displayed, cleared immediately.
   */
  invalidates?: string[];
  priority: Priority;
  timeoutMs?: number;
  /**
   * Combine notifications with the same key, like Array.reduce().
   * Called as fold(accumulator, incoming) when a notification with a matching
   * key already exists in the queue or is currently displayed.
   * Returns the merged notification (should carry fold forward for future merges).
   */
  fold?: (accumulator: Notification, incoming: Notification) => Notification;
};
type TextNotification = BaseNotification & {
  text: string;
  color?: keyof Theme;
};
type JSXNotification = BaseNotification & {
  jsx: React.ReactNode;
};
type AddNotificationFn = (content: Notification) => void;
type RemoveNotificationFn = (key: string) => void;
export type Notification = TextNotification | JSXNotification;
const DEFAULT_TIMEOUT_MS = 8000;

// Track current timeout to clear it when immediate notifications arrive
let currentTimeoutId: NodeJS.Timeout | null = null;
export function useNotifications(): {
  addNotification: AddNotificationFn;
  removeNotification: RemoveNotificationFn;
} {
  const store = useAppStateStore();
  const setAppState = useSetAppState();

  // Process queue when current notification finishes or queue changes
  const processQueue = useCallback(() => {
    setAppState(prev => {
      const next = getNext(prev.notifications.queue);
      if (prev.notifications.current !== null || !next) {
        return prev;
      }
      currentTimeoutId = setTimeout((setAppState, nextKey, processQueue) => {
        currentTimeoutId = null;
        setAppState(prev => {
          // Compare by key instead of reference to handle re-created notifications
          if (prev.notifications.current?.key !== nextKey) {
            return prev;
          }
          return {
            ...prev,
            notifications: {
              queue: prev.notifications.queue,
              current: null
            }
          };
        });
        processQueue();
      }, next.timeoutMs ?? DEFAULT_TIMEOUT_MS, setAppState, next.key, processQueue);
      return {
        ...prev,
        notifications: {
          queue: prev.notifications.queue.filter(_ => _ !== next),
          current: next
        }
      };
    });
  }, [setAppState]);
  const addNotification = useCallback<AddNotificationFn>((notif: Notification) => {
    // Handle immediate priority notifications
    if (notif.priority === 'immediate') {
      // Clear any existing timeout since we're showing a new immediate notification
      if (currentTimeoutId) {
        clearTimeout(currentTimeoutId);
        currentTimeoutId = null;
      }

      // Set up timeout for the immediate notification
      currentTimeoutId = setTimeout((setAppState, notif, processQueue) => {
        currentTimeoutId = null;
        setAppState(prev => {
          // Compare by key instead of reference to handle re-created notifications
          if (prev.notifications.current?.key !== notif.key) {
            return prev;
          }
          return {
            ...prev,
            notifications: {
              queue: prev.notifications.queue.filter(_ => !notif.invalidates?.includes(_.key)),
              current: null
            }
          };
        });
        processQueue();
      }, notif.timeoutMs ?? DEFAULT_TIMEOUT_MS, setAppState, notif, processQueue);

      // Show the immediate notification right away
      setAppState(prev => ({
        ...prev,
        notifications: {
          current: notif,
          queue:
          // Only re-queue the current notification if it's not immediate
          [...(prev.notifications.current ? [prev.notifications.current] : []), ...prev.notifications.queue].filter(_ => _.priority !== 'immediate' && !notif.invalidates?.includes(_.key))
        }
      }));
      return; // IMPORTANT: Exit addNotification for immediate notifications
    }

    // Handle non-immediate notifications
    setAppState(prev => {
      // Check if we can fold into an existing notification with the same key
      if (notif.fold) {
        // Fold into current notification if keys match
        if (prev.notifications.current?.key === notif.key) {
          const folded = notif.fold(prev.notifications.current, notif);
          // Reset timeout for the folded notification
          if (currentTimeoutId) {
            clearTimeout(currentTimeoutId);
            currentTimeoutId = null;
          }
          currentTimeoutId = setTimeout((setAppState, foldedKey, processQueue) => {
            currentTimeoutId = null;
            setAppState(p => {
              if (p.notifications.current?.key !== foldedKey) {
                return p;
              }
              return {
                ...p,
                notifications: {
                  queue: p.notifications.queue,
                  current: null
                }
              };
            });
            processQueue();
          }, folded.timeoutMs ?? DEFAULT_TIMEOUT_MS, setAppState, folded.key, processQueue);
          return {
            ...prev,
            notifications: {
              current: folded,
              queue: prev.notifications.queue
            }
          };
        }

        // Fold into queued notification if keys match
        const queueIdx = prev.notifications.queue.findIndex(_ => _.key === notif.key);
        if (queueIdx !== -1) {
          const folded = notif.fold(prev.notifications.queue[queueIdx]!, notif);
          const newQueue = [...prev.notifications.queue];
          newQueue[queueIdx] = folded;
          return {
            ...prev,
            notifications: {
              current: prev.notifications.current,
              queue: newQueue
            }
          };
        }
      }

      // Only add to queue if not already present (prevent duplicates)
      const queuedKeys = new Set(prev.notifications.queue.map(_ => _.key));
      const shouldAdd = !queuedKeys.has(notif.key) && prev.notifications.current?.key !== notif.key;
      if (!shouldAdd) return prev;
      const invalidatesCurrent = prev.notifications.current !== null && notif.invalidates?.includes(prev.notifications.current.key);
      if (invalidatesCurrent && currentTimeoutId) {
        clearTimeout(currentTimeoutId);
        currentTimeoutId = null;
      }
      return {
        ...prev,
        notifications: {
          current: invalidatesCurrent ? null : prev.notifications.current,
          queue: [...prev.notifications.queue.filter(_ => _.priority !== 'immediate' && !notif.invalidates?.includes(_.key)), notif]
        }
      };
    });

    // Process queue after adding the notification
    processQueue();
  }, [setAppState, processQueue]);
  const removeNotification = useCallback<RemoveNotificationFn>((key: string) => {
    setAppState(prev => {
      const isCurrent = prev.notifications.current?.key === key;
      const inQueue = prev.notifications.queue.some(n => n.key === key);
      if (!isCurrent && !inQueue) {
        return prev;
      }
      if (isCurrent && currentTimeoutId) {
        clearTimeout(currentTimeoutId);
        currentTimeoutId = null;
      }
      return {
        ...prev,
        notifications: {
          current: isCurrent ? null : prev.notifications.current,
          queue: prev.notifications.queue.filter(n => n.key !== key)
        }
      };
    });
    processQueue();
  }, [setAppState, processQueue]);

  // Process queue on mount if there are notifications in the initial state.
  // Imperative read (not useAppState) — a subscription in a mount-only
  // effect would be vestigial and make every caller re-render on queue changes.
  // eslint-disable-next-line react-hooks/exhaustive-deps
  // biome-ignore lint/correctness/useExhaustiveDependencies: mount-only effect, store is a stable context ref
  useEffect(() => {
    if (store.getState().notifications.queue.length > 0) {
      processQueue();
    }
  }, []);
  return {
    addNotification,
    removeNotification
  };
}
const PRIORITIES: Record<Priority, number> = {
  immediate: 0,
  high: 1,
  medium: 2,
  low: 3
};
export function getNext(queue: Notification[]): Notification | undefined {
  if (queue.length === 0) return undefined;
  return queue.reduce((min, n) => PRIORITIES[n.priority] < PRIORITIES[min.priority] ? n : min);
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJSZWFjdCIsInVzZUNhbGxiYWNrIiwidXNlRWZmZWN0IiwidXNlQXBwU3RhdGVTdG9yZSIsInVzZVNldEFwcFN0YXRlIiwiVGhlbWUiLCJQcmlvcml0eSIsIkJhc2VOb3RpZmljYXRpb24iLCJrZXkiLCJpbnZhbGlkYXRlcyIsInByaW9yaXR5IiwidGltZW91dE1zIiwiZm9sZCIsImFjY3VtdWxhdG9yIiwiTm90aWZpY2F0aW9uIiwiaW5jb21pbmciLCJUZXh0Tm90aWZpY2F0aW9uIiwidGV4dCIsImNvbG9yIiwiSlNYTm90aWZpY2F0aW9uIiwianN4IiwiUmVhY3ROb2RlIiwiQWRkTm90aWZpY2F0aW9uRm4iLCJjb250ZW50IiwiUmVtb3ZlTm90aWZpY2F0aW9uRm4iLCJERUZBVUxUX1RJTUVPVVRfTVMiLCJjdXJyZW50VGltZW91dElkIiwiTm9kZUpTIiwiVGltZW91dCIsInVzZU5vdGlmaWNhdGlvbnMiLCJhZGROb3RpZmljYXRpb24iLCJyZW1vdmVOb3RpZmljYXRpb24iLCJzdG9yZSIsInNldEFwcFN0YXRlIiwicHJvY2Vzc1F1ZXVlIiwicHJldiIsIm5leHQiLCJnZXROZXh0Iiwibm90aWZpY2F0aW9ucyIsInF1ZXVlIiwiY3VycmVudCIsInNldFRpbWVvdXQiLCJuZXh0S2V5IiwiZmlsdGVyIiwiXyIsIm5vdGlmIiwiY2xlYXJUaW1lb3V0IiwiaW5jbHVkZXMiLCJmb2xkZWQiLCJmb2xkZWRLZXkiLCJwIiwicXVldWVJZHgiLCJmaW5kSW5kZXgiLCJuZXdRdWV1ZSIsInF1ZXVlZEtleXMiLCJTZ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ZmljYXRpb25zXG4gICAgICAgICAgICBpZiAocHJldi5ub3RpZmljYXRpb25zLmN1cnJlbnQ/LmtleSAhPT0gbmV4dEtleSkge1xuICAgICAgICAgICAgICByZXR1cm4gcHJldlxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgICAgLi4ucHJldixcbiAgICAgICAgICAgICAgbm90aWZpY2F0aW9uczoge1xuICAgICAgICAgICAgICAgIHF1ZXVlOiBwcmV2Lm5vdGlmaWNhdGlvbnMucXVldWUsXG4gICAgICAgICAgICAgICAgY3VycmVudDogbnVsbCxcbiAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgIH1cbiAgICAgICAgICB9KVxuICAgICAgICAgIHByb2Nlc3NRdWV1ZSgpXG4gICAgICAgIH0sXG4gICAgICAgIG5leHQudGltZW91dE1zID8/IERFRkFVTFRfVElNRU9VVF9NUyxcbiAgICAgICAgc2V0QXBwU3RhdGUsXG4gICAgICAgIG5leHQua2V5LFxuICAgICAgICBwcm9jZXNzUXVldWUsXG4gICAgICApXG5cbiAgICAgIHJldHVybiB7XG4gICAgICAgIC4uLnByZXYsXG4gICAgICAgIG5vdGlmaWNhdGlvbnM6IHtcbiAgICAgICAgICBxdWV1ZTogcHJldi5ub3RpZmljYXRpb25zLnF1ZXVlLmZpbHRlcihfID0+IF8gIT09IG5leHQpLFxuICAgICAgICAgIGN1cnJlbnQ6IG5leHQsXG4gICAgICAgIH0sXG4gICAgICB9XG4gICAgfSlcbiAgfSwgW3NldEFwcFN0YXRlXSlcblxuICBjb25zdCBhZGROb3RpZmljYXRpb24gPSB1c2VDYWxsYmFjazxBZGROb3RpZmljYXRpb25Gbj4oXG4gICAgKG5vdGlmOiBOb3RpZmljYXRpb24pID0+IHtcbiAgICAgIC8vIEhhbmRsZSBpbW1lZGlhdGUgcHJpb3JpdHkgbm90aWZpY2F0aW9uc1xuICAgICAgaWYgKG5vdGlmLnByaW9yaXR5ID09PSAnaW1tZWRpYXRlJykge1xuICAgICAgICAvLyBDbGVhciBhbnkgZXhpc3RpbmcgdGltZW91dCBzaW5jZSB3ZSdyZSBzaG93aW5nIGEgbmV3IGltbWVkaWF0ZSBub3RpZmljYXRpb25cbiAgICAgICAgaWYgKGN1cnJlbnRUaW1lb3V0SWQpIHtcbiAgICAgICAgICBjbGVhclRpbWVvdXQoY3VycmVudFRpbWVvdXRJZClcbiAgICAgICAgICBjdXJyZW50VGltZW91dElkID0gbnVsbFxuICAgICAgICB9XG5cbiAgICAgICAgLy8gU2V0IHVwIHRpbWVvdXQgZm9yIHRoZSBpbW1lZGlhdGUgbm90aWZpY2F0aW9uXG4gICAgICAgIGN1cnJlbnRUaW1lb3V0SWQgPSBzZXRUaW1lb3V0KFxuICAgICAgICAgIChzZXRBcHBTdGF0ZSwgbm90aWYsIHByb2Nlc3NRdWV1ZSkgPT4ge1xuICAgICAgICAgICAgY3VycmVudFRpbWVvdXRJZCA9IG51bGxcbiAgICAgICAgICAgIHNldEFwcFN0YXRlKHByZXYgPT4ge1xuICAgICAgICAgICAgICAvLyBDb21wYXJlIGJ5IGtleSBpbnN0ZWFkIG9mIHJlZmVyZW5jZSB0byBoYW5kbGUgcmUtY3JlYXRlZCBub3RpZmljYXRpb25zXG4gICAgICAgICAgICAgIGlmIChwcmV2Lm5vdGlmaWNhdGlvbnMuY3VycmVudD8ua2V5ICE9PSBub3RpZi5rZXkpIHtcbiAgICAgICAgICAgICAgICByZXR1cm4gcHJldlxuICAgICAgICAgICAgICB9XG4gICAgICAgICAgICAgIHJldHVybiB7XG4gICAgICAgICAgICAgICAgLi4ucHJldixcbiAgICAgICAgICAgICAgICBub3RpZmljYXRpb25zOiB7XG4gICAgICAgICAgICAgICAgICBxdWV1ZTogcHJldi5ub3RpZmljYXRpb25zLnF1ZXVlLmZpbHRlcihcbiAgICAgICAgICAgICAgICAgICAgXyA9PiAhbm90aWYuaW52YWxpZGF0ZXM/LmluY2x1ZGVzKF8ua2V5KSxcbiAgICAgICAgICAgICAgICAgICksXG4gICAgICAgICAgICAgICAgICBjdXJyZW50OiBudWxsLFxuICAgICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgIH1cbiAgICAgICAgICAgIH0pXG4gICAgICAgICAgICBwcm9jZXNzUXVldWUoKVxuICAgICAgICAgIH0sXG4gICAgICAgICAgbm90aWYudGltZW91dE1zID8/IERFRkFVTFRfVElNRU9VVF9NUyxcbiAgICAgICAgICBzZXRBcHBTdGF0ZSxcbiAgICAgICAgICBub3RpZixcbiAgICAgICAgICBwcm9jZXNzUXVldWUsXG4gICAgICAgIClcblxuICAgICAgICAvLyBTaG93IHRoZSBpbW1lZGlhdGUgbm90aWZpY2F0aW9uIHJpZ2h0IGF3YXlcbiAgICAgICAgc2V0QXBwU3RhdGUocHJldiA9PiAoe1xuICAgICAgICAgIC4uLnByZXYsXG4gICAgICAgICAgbm90aWZpY2F0aW9uczoge1xuICAgICAgICAgICAgY3VycmVudDogbm90aWYsXG4gICAgICAgICAgICBxdWV1ZTpcbiAgICAgICAgICAgICAgLy8gT25seSByZS1xdWV1ZSB0aGUgY3VycmVudCBub3RpZmljYXRpb24gaWYgaXQncyBub3QgaW1tZWRpYXRlXG4gICAgICAgICAgICAgIFtcbiAgICAgICAgICAgICAgICAuLi4ocHJldi5ub3RpZmljYXRpb25zLmN1cnJlbnRcbiAgICAgICAgICAgICAgICAgID8gW3ByZXYubm90aWZpY2F0aW9ucy5jdXJyZW50XVxuICAgICAgICAgICAgICAgICAgOiBbXSksXG4gICAgICAgICAgICAgICAgLi4ucHJldi5ub3RpZmljYXRpb25zLnF1ZXVlLFxuICAgICAgICAgICAgICBdLmZpbHRlcihcbiAgICAgICAgICAgICAgICBfID0+XG4gICAgICAgICAgICAgICAgICBfLnByaW9yaXR5ICE9PSAnaW1tZWRpYXRlJyAmJlxuICAgICAgICAgICAgICAgICAgIW5vdGlmLmludmFsaWRhdGVzPy5pbmNsdWRlcyhfLmtleSksXG4gICAgICAgICAgICAgICksXG4gICAgICAgICAgfSxcbiAgICAgICAgfSkpXG4gICAgICAgIHJldHVybiAvLyBJTVBPUlRBTlQ6IEV4aXQgYWRkTm90aWZpY2F0aW9uIGZvciBpbW1lZGlhdGUgbm90aWZpY2F0aW9uc1xuICAgICAgfVxuXG4gICAgICAvLyBIYW5kbGUgbm9uLWltbWVkaWF0ZSBub3RpZmljYXRpb25zXG4gICAgICBzZXRBcHBTdGF0ZShwcmV2ID0+IHtcbiAgICAgICAgLy8gQ2hlY2sgaWYgd2UgY2FuIGZvbGQgaW50byBhbiBleGlzdGluZyBub3RpZmljYXRpb24gd2l0aCB0aGUgc2FtZSBrZXlcbiAgICAgICAgaWYgKG5vdGlmLmZvbGQpIHtcbiAgICAgICAgICAvLyBGb2xkIGludG8gY3VycmVudCBub3RpZmljYXRpb24gaWYga2V5cyBtYXRjaFxuICAgICAgICAgIGlmIChwcmV2Lm5vdGlmaWNhdGlvbnMuY3VycmVudD8ua2V5ID09PSBub3RpZi5rZXkpIHtcbiAgICAgICAgICAgIGNvbnN0IGZvbGRlZCA9IG5vdGlmLmZvbGQocHJldi5ub3RpZmljYXRpb25zLmN1cnJlbnQsIG5vdGlmKVxuICAgICAgICAgICAgLy8gUmVzZXQgdGltZW91dCBmb3IgdGhlIGZvbGRlZCBub3RpZmljYXRpb25cbiAgICAgICAgICAgIGlmIChjdXJyZW50VGltZW91dElkKSB7XG4gICAgICAgICAgICAgIGNsZWFyVGltZW91dChjdXJyZW50VGltZW91dElkKVxuICAgICAgICAgICAgICBjdXJyZW50VGltZW91dElkID0gbnVsbFxuICAgICAgICAgICAgfVxuICAgICAgICAgICAgY3VycmVudFRpbWVvdXRJZCA9IHNldFRpbWVvdXQoXG4gICAgICAgICAgICAgIChzZXRBcHBTdGF0ZSwgZm9sZGVkS2V5LCBwcm9jZXNzUXVldWUpID0+IHtcbiAgICAgICAgICAgICAgICBjdXJyZW50VGltZW91dElkID0gbnVsbFxuICAgICAgICAgICAgICAgIHNldEFwcFN0YXRlKHAgPT4ge1xuICAgICAgICAgICAgICAgICAgaWYgKHAubm90aWZpY2F0aW9ucy5jdXJyZW50Py5rZXkgIT09IGZvbGRlZEtleSkge1xuICAgICAgICAgICAgICAgICAgICByZXR1cm4gcFxuICAgICAgICAgICAgICAgICAgfVxuICAgICAgICAgICAgICAgICAgcmV0dXJuIHtcbiAgICAgICAgICAgICAgICAgICAgLi4ucCxcbiAgICAgICAgICAgICAgICAgICAgbm90aWZpY2F0aW9uczoge1xuICAgICAgICAgICAgICAgICAgICAgIHF1ZXVlOiBwLm5vdGlmaWNhdGlvbnMucXVldWUsXG4gICAgICAgICAgICAgICAgICAgICAgY3VycmVudDogbnVsbCxcbiAgICAgICAgICAgICAgICAgICAgfSxcbiAgICAgICAgICAgICAgICAgIH1cbiAgICAgICAgICAgICAgICB9KVxuICAgICAgICAgICAgICAgIHByb2Nlc3NRdWV1ZSgpXG4gICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICAgIGZvbGRlZC50aW1lb3V0TXMgPz8gREVGQVVMVF9USU1FT1VUX01TLFxuICAgICAgICAgICAgICBzZXRBcHBTdGF0ZSxcbiAgICAgICAgICAgICAgZm9sZGVkLmtleSxcbiAgICAgICAgICAgICAgcHJvY2Vzc1F1ZXVlLFxuICAgICAgICAgICAgKVxuXG4gICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAuLi5wcmV2LFxuICAgICAgICAgICAgICBub3RpZmljYXRpb25zOiB7XG4gICAgICAgICAgICAgICAgY3VycmVudDogZm9sZGVkLFxuICAgICAgICAgICAgICAgIHF1ZXVlOiBwcmV2Lm5vdGlmaWNhdGlvbnMucXVldWUsXG4gICAgICAgICAgICAgIH0sXG4gICAgICAgICAgICB9XG4gICAgICAgICAgfVxuXG4gICAgICAgICAgLy8gRm9sZCBpbnRvIHF1ZXVlZCBub3RpZmljYXRpb24gaWYga2V5cyBtYXRjaFxuICAgICAgICAgIGNvbnN0IHF1ZXVlSWR4ID0gcHJldi5ub3RpZmljYXRpb25zLnF1ZXVlLmZpbmRJbmRleChcbiAgICAgICAgICAgIF8gPT4gXy5rZXkgPT09IG5vdGlmLmtleSxcbiAgICAgICAgICApXG4gICAgICAgICAgaWYgKHF1ZXVlSWR4ICE9PSAtMSkge1xuICAgICAgICAgICAgY29uc3QgZm9sZGVkID0gbm90aWYuZm9sZChcbiAgICAgICAgICAgICAgcHJldi5ub3RpZmljYXRpb25zLnF1ZXVlW3F1ZXVlSWR4XSEsXG4gICAgICAgICAgICAgIG5vdGlmLFxuICAgICAgICAgICAgKVxuICAgICAgICAgICAgY29uc3QgbmV3UXVldWUgPSBbLi4ucHJldi5ub3RpZmljYXRpb25zLnF1ZXVlXVxuICAgICAgICAgICAgbmV3UXVldWVbcXVldWVJZHhdID0gZm9sZGVkXG4gICAgICAgICAgICByZXR1cm4ge1xuICAgICAgICAgICAgICAuLi5wcmV2LFxuICAgICAgICAgICAgICBub3RpZmljYXRpb25zOiB7XG4gICAgICAgICAgICAgICAgY3VycmVudDogcHJldi5ub3RpZmljYXRpb25zLmN1cnJlbnQsXG4gICAgICAgICAgICAgICAgcXVldWU6IG5ld1F1ZXVlLFxuICAgICAgICAgICAgICB9LFxuICAgICAgICAgICAgfVxuICAgICAgICAgIH1cbiAgICAgICAgfVxuXG4gICAgICAgIC8vIE9ubHkgYWRkIHRvIHF1ZXVlIGlmIG5vdCBhbHJlYWR5IHByZXNlbnQgKHByZXZlbnQgZHVwbGljYXRlcylcbiAgICAgICAgY29uc3QgcXVldWVkS2V5cyA9IG5ldyBTZXQocHJldi5ub3RpZmljYXRpb25zLnF1ZXVlLm1hcChfID0+IF8ua2V5KSlcbiAgICAgICAgY29uc3Qgc2hvdWxkQWRkID1cbiAgICAgICAgICAhcXVldWVkS2V5cy5oYXMobm90aWYua2V5KSAmJlxuICAgICAgICAgIHByZXYubm90aWZpY2F0aW9ucy5jdXJyZW50Py5rZXkgIT09IG5vdGlmLmtleVxuXG4gICAgICAgIGlmICghc2hvdWxkQWRkKSByZXR1cm4gcHJldlxuXG4gICAgICAgIGNvbnN0IGludmFsaWRhdGVzQ3VycmVudCA9XG4gICAgICAgICAgcHJldi5ub3RpZmljYXRpb25zLmN1cnJlbnQgIT09IG51bGwgJiZcbiAgICAgICAgICBub3RpZi5pbnZhbGlkYXRlcz8uaW5jbHVkZXMocHJldi5ub3RpZmljYXRpb25zLmN1cnJlbnQua2V5KVxuXG4gICAgICAgIGlmIChpbnZhbGlkYXRlc0N1cnJlbnQgJiYgY3VycmVudFRpbWVvdXRJZCkge1xuICAgICAgICAgIGNsZWFyVGltZW91dChjdXJyZW50VGltZW91dElkKVxuICAgICAgICAgIGN1cnJlbnRUaW1lb3V0SWQgPSBudWxsXG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgIC4uLnByZXYsXG4gICAgICAgICAgbm90aWZpY2F0aW9uczoge1xuICAgICAgICAgICAgY3VycmVudDogaW52YWxpZGF0ZXNDdXJyZW50ID8gbnVsbCA6IHByZXYubm90aWZpY2F0aW9ucy5jdXJyZW50LFxuICAgICAgICAgICAgcXVldWU6IFtcbiAgICAgICAgICAgICAgLi4ucHJldi5ub3RpZmljYXRpb25zLnF1ZXVlLmZpbHRlcihcbiAgICAgICAgICAgICAgICBfID0+XG4gICAgICAgICAgICAgICAgICBfLnByaW9yaXR5ICE9PSAnaW1tZWRpYXRlJyAmJlxuICAgICAgICAgICAgICAgICAgIW5vdGlmLmludmFsaWRhdGVzPy5pbmNsdWRlcyhfLmtleSksXG4gICAgICAgICAgICAgICksXG4gICAgICAgICAgICAgIG5vdGlmLFxuICAgICAgICAgICAgXSxcbiAgICAgICAgICB9LFxuICAgICAgICB9XG4gICAgICB9KVxuXG4gICAgICAvLyBQcm9jZXNzIHF1ZXVlIGFmdGVyIGFkZGluZyB0aGUgbm90aWZpY2F0aW9uXG4gICAgICBwcm9jZXNzUXVldWUoKVxuICAgIH0sXG4gICAgW3NldEFwcFN0YXRlLCBwcm9jZXNzUXVldWVdLFxuICApXG5cbiAgY29uc3QgcmVtb3ZlTm90aWZpY2F0aW9uID0gdXNlQ2FsbGJhY2s8UmVtb3ZlTm90aWZpY2F0aW9uRm4+KFxuICAgIChrZXk6IHN0cmluZykgPT4ge1xuICAgICAgc2V0QXBwU3RhdGUocHJldiA9PiB7XG4gICAgICAgIGNvbnN0IGlzQ3VycmVudCA9IHByZXYubm90aWZpY2F0aW9ucy5jdXJyZW50Py5rZXkgPT09IGtleVxuICAgICAgICBjb25zdCBpblF1ZXVlID0gcHJldi5ub3RpZmljYXRpb25zLnF1ZXVlLnNvbWUobiA9PiBuLmtleSA9PT0ga2V5KVxuXG4gICAgICAgIGlmICghaXNDdXJyZW50ICYmICFpblF1ZXVlKSB7XG4gICAgICAgICAgcmV0dXJuIHByZXZcbiAgICAgICAgfVxuXG4gICAgICAgIGlmIChpc0N1cnJlbnQgJiYgY3VycmVudFRpbWVvdXRJZCkge1xuICAgICAgICAgIGNsZWFyVGltZW91dChjdXJyZW50VGltZW91dElkKVxuICAgICAgICAgIGN1cnJlbnRUaW1lb3V0SWQgPSBudWxsXG4gICAgICAgIH1cblxuICAgICAgICByZXR1cm4ge1xuICAgICAgICAgIC4uLnByZXYsXG4gICAgICAgICAgbm90aWZpY2F0aW9uczoge1xuICAgICAgICAgICAgY3VycmVudDogaXNDdXJyZW50ID8gbnVsbCA6IHByZXYubm90aWZpY2F0aW9ucy5jdXJyZW50LFxuICAgICAgICAgICAgcXVldWU6IHByZXYubm90aWZpY2F0aW9ucy5xdWV1ZS5maWx0ZXIobiA9PiBuLmtleSAhPT0ga2V5KSxcbiAgICAgICAgICB9LFxuICAgICAgICB9XG4gICAgICB9KVxuXG4gICAgICBwcm9jZXNzUXVldWUoKVxuICAgIH0sXG4gICAgW3NldEFwcFN0YXRlLCBwcm9jZXNzUXVldWVdLFxuICApXG5cbiAgLy8gUHJvY2VzcyBxdWV1ZSBvbiBtb3VudCBpZiB0aGVyZSBhcmUgbm90aWZpY2F0aW9ucyBpbiB0aGUg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