"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = exports.SiteHubMobile = void 0;
var _clsx = _interopRequireDefault(require("clsx"));
var _data = require("@wordpress/data");
var _components = require("@wordpress/components");
var _i18n = require("@wordpress/i18n");
var _coreData = require("@wordpress/core-data");
var _htmlEntities = require("@wordpress/html-entities");
var _element = require("@wordpress/element");
var _icons = require("@wordpress/icons");
var _commands = require("@wordpress/commands");
var _keycodes = require("@wordpress/keycodes");
var _url = require("@wordpress/url");
var _router = require("@wordpress/router");
var _store = require("../../store");
var _siteIcon = _interopRequireDefault(require("../site-icon"));
var _lockUnlock = require("../../lock-unlock");
var _sidebar = require("../sidebar");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * External dependencies
 */

/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const {
  useHistory
} = (0, _lockUnlock.unlock)(_router.privateApis);
const SiteHub = (0, _element.memo)((0, _element.forwardRef)(({
  isTransparent
}, ref) => {
  const {
    dashboardLink,
    homeUrl,
    siteTitle
  } = (0, _data.useSelect)(select => {
    const {
      getSettings
    } = (0, _lockUnlock.unlock)(select(_store.store));
    const {
      getEntityRecord
    } = select(_coreData.store);
    const _site = getEntityRecord('root', 'site');
    return {
      dashboardLink: getSettings().__experimentalDashboardLink || 'index.php',
      homeUrl: getEntityRecord('root', '__unstableBase')?.home,
      siteTitle: !_site?.title && !!_site?.url ? (0, _url.filterURLForDisplay)(_site?.url) : _site?.title
    };
  }, []);
  const {
    open: openCommandCenter
  } = (0, _data.useDispatch)(_commands.store);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: "edit-site-site-hub",
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
      justify: "flex-start",
      spacing: "0",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: (0, _clsx.default)('edit-site-site-hub__view-mode-toggle-container', {
          'has-transparent-background': isTransparent
        }),
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
          __next40pxDefaultSize: true,
          ref: ref,
          href: dashboardLink,
          label: (0, _i18n.__)('Go to the Dashboard'),
          className: "edit-site-layout__view-mode-toggle",
          style: {
            transform: 'scale(0.5)',
            borderRadius: 4
          },
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_siteIcon.default, {
            className: "edit-site-layout__view-mode-toggle-icon"
          })
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: "edit-site-site-hub__title",
          children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.Button, {
            __next40pxDefaultSize: true,
            variant: "link",
            href: homeUrl,
            target: "_blank",
            children: [(0, _htmlEntities.decodeEntities)(siteTitle), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.VisuallyHidden, {
              as: "span",
              children: /* translators: accessibility text */
              (0, _i18n.__)('(opens in a new tab)')
            })]
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalHStack, {
          spacing: 0,
          expanded: false,
          className: "edit-site-site-hub__actions",
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
            __next40pxDefaultSize: true,
            className: "edit-site-site-hub_toggle-command-center",
            icon: _icons.search,
            onClick: () => openCommandCenter(),
            label: (0, _i18n.__)('Open command palette'),
            shortcut: _keycodes.displayShortcut.primary('k')
          })
        })]
      })]
    })
  });
}));
var _default = exports.default = SiteHub;
const SiteHubMobile = exports.SiteHubMobile = (0, _element.memo)((0, _element.forwardRef)(({
  isTransparent
}, ref) => {
  const history = useHistory();
  const {
    navigate
  } = (0, _element.useContext)(_sidebar.SidebarNavigationContext);
  const {
    homeUrl,
    siteTitle
  } = (0, _data.useSelect)(select => {
    const {
      getEntityRecord
    } = select(_coreData.store);
    const _site = getEntityRecord('root', 'site');
    return {
      homeUrl: getEntityRecord('root', '__unstableBase')?.home,
      siteTitle: !_site?.title && !!_site?.url ? (0, _url.filterURLForDisplay)(_site?.url) : _site?.title
    };
  }, []);
  const {
    open: openCommandCenter
  } = (0, _data.useDispatch)(_commands.store);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
    className: "edit-site-site-hub",
    children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
      justify: "flex-start",
      spacing: "0",
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: (0, _clsx.default)('edit-site-site-hub__view-mode-toggle-container', {
          'has-transparent-background': isTransparent
        }),
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
          __next40pxDefaultSize: true,
          ref: ref,
          label: (0, _i18n.__)('Go to Site Editor'),
          className: "edit-site-layout__view-mode-toggle",
          style: {
            transform: 'scale(0.5)',
            borderRadius: 4
          },
          onClick: () => {
            history.push({});
            navigate('back');
          },
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_siteIcon.default, {
            className: "edit-site-layout__view-mode-toggle-icon"
          })
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(_components.__experimentalHStack, {
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
          className: "edit-site-site-hub__title",
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
            __next40pxDefaultSize: true,
            variant: "link",
            href: homeUrl,
            target: "_blank",
            label: (0, _i18n.__)('View site (opens in a new tab)'),
            children: (0, _htmlEntities.decodeEntities)(siteTitle)
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.__experimentalHStack, {
          spacing: 0,
          expanded: false,
          className: "edit-site-site-hub__actions",
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_components.Button, {
            __next40pxDefaultSize: true,
            className: "edit-site-site-hub_toggle-command-center",
            icon: _icons.search,
            onClick: () => openCommandCenter(),
            label: (0, _i18n.__)('Open command palette'),
            shortcut: _keycodes.displayShortcut.primary('k')
          })
        })]
      })]
    })
  });
}));
//# sourceMappingURL=index.js.map