"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.ADDON_ID = void 0;
exports.registerCreeveyPanels = registerCreeveyPanels;
var _managerApi = require("@storybook/manager-api");
var _react = _interopRequireDefault(require("react"));
var _Addon = require("./components/Addon");
var _Tools = require("./components/Tools");
var _Manager = require("./Manager");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
const ADDON_ID = exports.ADDON_ID = 'creevey';
_managerApi.addons.register(ADDON_ID, api => {
  void registerCreeveyPanels(api);
});
async function registerCreeveyPanels(storybookApi) {
  const manager = new _Manager.CreeveyManager(storybookApi);
  _managerApi.addons.add(`${ADDON_ID}/panel/run`, {
    title: `Creevey/Run`,
    match: _ref => {
      let {
        viewMode
      } = _ref;
      return !!(viewMode && /^story$/.exec(viewMode));
    },
    type: _managerApi.types.TOOL,
    // eslint-disable-next-line react/display-name
    render: () => /*#__PURE__*/_react.default.createElement(_Tools.Tools, {
      manager
    })
  });
  await manager.initAll();
  const browsers = manager.getBrowsers();
  browsers.forEach(browser => {
    const panelId = `${ADDON_ID}/panel/${browser}`;
    const title = manager.getTabTitle(browser);
    _managerApi.addons.add(panelId, {
      title,
      type: _managerApi.types.PANEL,
      paramKey: browser,
      // NOTE key = PANEL_ID needs to correct render button in addons panel
      // eslint-disable-next-line react/display-name
      render: _ref2 => {
        let {
          active
        } = _ref2;
        return /*#__PURE__*/_react.default.createElement(_Addon.Addon, {
          active,
          manager,
          browser
        });
      }
    });
  });
}