import { c as _c } from "react/compiler-runtime";
import * as React from 'react';
import { useEffect, useState } from 'react';
import { getIsRemoteMode } from '../../bootstrap/state.js';
import { useNotifications } from '../../context/notifications.js';
import { Text } from '../../ink.js';
import { logForDebugging } from '../../utils/debug.js';
import { onPluginsAutoUpdated } from '../../utils/plugins/pluginAutoupdate.js';

/**
 * Hook that displays a notification when plugins have been auto-updated.
 * The notification tells the user to run /reload-plugins to apply the updates.
 */
export function usePluginAutoupdateNotification() {
  const $ = _c(7);
  const {
    addNotification
  } = useNotifications();
  let t0;
  if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
    t0 = [];
    $[0] = t0;
  } else {
    t0 = $[0];
  }
  const [updatedPlugins, setUpdatedPlugins] = useState(t0);
  let t1;
  let t2;
  if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
    t1 = () => {
      if (getIsRemoteMode()) {
        return;
      }
      const unsubscribe = onPluginsAutoUpdated(plugins => {
        logForDebugging(`Plugin autoupdate notification: ${plugins.length} plugin(s) updated`);
        setUpdatedPlugins(plugins);
      });
      return unsubscribe;
    };
    t2 = [];
    $[1] = t1;
    $[2] = t2;
  } else {
    t1 = $[1];
    t2 = $[2];
  }
  useEffect(t1, t2);
  let t3;
  let t4;
  if ($[3] !== addNotification || $[4] !== updatedPlugins) {
    t3 = () => {
      if (getIsRemoteMode()) {
        return;
      }
      if (updatedPlugins.length === 0) {
        return;
      }
      const pluginNames = updatedPlugins.map(_temp);
      const displayNames = pluginNames.length <= 2 ? pluginNames.join(" and ") : `${pluginNames.length} plugins`;
      addNotification({
        key: "plugin-autoupdate-restart",
        jsx: <><Text color="success">{pluginNames.length === 1 ? "Plugin" : "Plugins"} updated:{" "}{displayNames}</Text><Text dimColor={true}> · Run /reload-plugins to apply</Text></>,
        priority: "low",
        timeoutMs: 10000
      });
      logForDebugging(`Showing plugin autoupdate notification for: ${pluginNames.join(", ")}`);
    };
    t4 = [updatedPlugins, addNotification];
    $[3] = addNotification;
    $[4] = updatedPlugins;
    $[5] = t3;
    $[6] = t4;
  } else {
    t3 = $[5];
    t4 = $[6];
  }
  useEffect(t3, t4);
}
function _temp(id) {
  const atIndex = id.indexOf("@");
  return atIndex > 0 ? id.substring(0, atIndex) : id;
}
//# sourceMappingURL=data:application/json;charset=utf-8;base64,eyJ2ZXJzaW9uIjozLCJuYW1lcyI6WyJSZWFjdCIsInVzZUVmZmVjdCIsInVzZVN0YXRlIiwiZ2V0SXNSZW1vdGVNb2RlIiwidXNlTm90aWZpY2F0aW9ucyIsIlRleHQiLCJsb2dGb3JEZWJ1Z2dpbmciLCJvblBsdWdpbnNBdXRvVXBkYXRlZCIsInVzZVBsdWdpbkF1dG91cGRhdGVOb3RpZmljYXRpb24iLCIkIiwiX2MiLCJhZGROb3RpZmljYXRpb24iLCJ0MCIsIlN5bWJvbCIsImZvciIsInVwZGF0ZWRQbHVnaW5zIiwic2V0VXBkYXRlZFBsdWdpbnMiLCJ0MSIsInQyIiwidW5zdWJzY3JpYmUiLCJwbHVnaW5zIiwibGVuZ3RoIiwidDMiLCJ0NCIsInBsdWdpbk5hbWVzIiwibWFwIiwiX3RlbXAiLCJkaXNwbGF5TmFtZXMiLCJqb2luIiwia2V5IiwianN4IiwicHJpb3JpdHkiLCJ0aW1lb3V0TXMiLCJpZCIsImF0SW5kZXgiLCJpbmRleE9mIiwic3Vic3RyaW5nIl0sInNvdXJjZXMiOlsidXNlUGx1Z2luQXV0b3VwZGF0ZU5vdGlmaWNhdGlvbi50c3giXSwic291cmNlc0NvbnRlbnQiOlsiaW1wb3J0ICogYXMgUmVhY3QgZnJvbSAncmVhY3QnXG5pbXBvcnQgeyB1c2VFZmZlY3QsIHVzZVN0YXRlIH0gZnJvbSAncmVhY3QnXG5pbXBvcnQgeyBnZXRJc1JlbW90ZU1vZGUgfSBmcm9tICcuLi8uLi9ib290c3RyYXAvc3RhdGUuanMnXG5pbXBvcnQgeyB1c2VOb3RpZmljYXRpb25zIH0gZnJvbSAnLi4vLi4vY29udGV4dC9ub3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