/* wp:polyfill */
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.default = EditorPreferencesModal;
var _i18n = require("@wordpress/i18n");
var _compose = require("@wordpress/compose");
var _data = require("@wordpress/data");
var _element = require("@wordpress/element");
var _preferences = require("@wordpress/preferences");
var _interface = require("@wordpress/interface");
var _enablePanel = _interopRequireDefault(require("./enable-panel"));
var _enablePluginDocumentSettingPanel = _interopRequireDefault(require("./enable-plugin-document-setting-panel"));
var _enablePublishSidebar = _interopRequireDefault(require("./enable-publish-sidebar"));
var _blockVisibility = _interopRequireDefault(require("./block-visibility"));
var _postTaxonomies = _interopRequireDefault(require("../post-taxonomies"));
var _check = _interopRequireDefault(require("../post-featured-image/check"));
var _check2 = _interopRequireDefault(require("../post-excerpt/check"));
var _check3 = _interopRequireDefault(require("../page-attributes/check"));
var _postTypeSupportCheck = _interopRequireDefault(require("../post-type-support-check"));
var _store = require("../../store");
var _lockUnlock = require("../../lock-unlock");
var _jsxRuntime = require("react/jsx-runtime");
/**
 * WordPress dependencies
 */

/**
 * Internal dependencies
 */

const {
  PreferencesModal,
  PreferencesModalTabs,
  PreferencesModalSection,
  PreferenceToggleControl
} = (0, _lockUnlock.unlock)(_preferences.privateApis);
function EditorPreferencesModal({
  extraSections = {}
}) {
  const isActive = (0, _data.useSelect)(select => {
    return select(_interface.store).isModalActive('editor/preferences');
  }, []);
  const {
    closeModal
  } = (0, _data.useDispatch)(_interface.store);
  if (!isActive) {
    return null;
  }

  // Please wrap all contents inside PreferencesModalContents to prevent all
  // hooks from executing when the modal is not open.
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferencesModal, {
    closeModal: closeModal,
    children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferencesModalContents, {
      extraSections: extraSections
    })
  });
}
function PreferencesModalContents({
  extraSections = {}
}) {
  const isLargeViewport = (0, _compose.useViewportMatch)('medium');
  const showBlockBreadcrumbsOption = (0, _data.useSelect)(select => {
    const {
      getEditorSettings
    } = select(_store.store);
    const {
      get
    } = select(_preferences.store);
    const isRichEditingEnabled = getEditorSettings().richEditingEnabled;
    const isDistractionFreeEnabled = get('core', 'distractionFree');
    return !isDistractionFreeEnabled && isLargeViewport && isRichEditingEnabled;
  }, [isLargeViewport]);
  const {
    setIsListViewOpened,
    setIsInserterOpened
  } = (0, _data.useDispatch)(_store.store);
  const {
    set: setPreference
  } = (0, _data.useDispatch)(_preferences.store);
  const sections = (0, _element.useMemo)(() => [{
    name: 'general',
    tabLabel: (0, _i18n.__)('General'),
    content: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(PreferencesModalSection, {
        title: (0, _i18n.__)('Interface'),
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
          scope: "core",
          featureName: "showListViewByDefault",
          help: (0, _i18n.__)('Opens the List View sidebar by default.'),
          label: (0, _i18n.__)('Always open List View')
        }), showBlockBreadcrumbsOption && /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
          scope: "core",
          featureName: "showBlockBreadcrumbs",
          help: (0, _i18n.__)('Display the block hierarchy trail at the bottom of the editor.'),
          label: (0, _i18n.__)('Show block breadcrumbs')
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
          scope: "core",
          featureName: "allowRightClickOverrides",
          help: (0, _i18n.__)('Allows contextual List View menus via right-click, overriding browser defaults.'),
          label: (0, _i18n.__)('Allow right-click contextual menus')
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
          scope: "core",
          featureName: "enableChoosePatternModal",
          help: (0, _i18n.__)('Shows starter patterns when creating a new page.'),
          label: (0, _i18n.__)('Show starter patterns')
        })]
      }), /*#__PURE__*/(0, _jsxRuntime.jsxs)(PreferencesModalSection, {
        title: (0, _i18n.__)('Document settings'),
        description: (0, _i18n.__)('Select what settings are shown in the document panel.'),
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_enablePluginDocumentSettingPanel.default.Slot, {}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_postTaxonomies.default, {
          taxonomyWrapper: (content, taxonomy) => /*#__PURE__*/(0, _jsxRuntime.jsx)(_enablePanel.default, {
            label: taxonomy.labels.menu_name,
            panelName: `taxonomy-panel-${taxonomy.slug}`
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_check.default, {
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_enablePanel.default, {
            label: (0, _i18n.__)('Featured image'),
            panelName: "featured-image"
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_check2.default, {
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_enablePanel.default, {
            label: (0, _i18n.__)('Excerpt'),
            panelName: "post-excerpt"
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_postTypeSupportCheck.default, {
          supportKeys: ['comments', 'trackbacks'],
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_enablePanel.default, {
            label: (0, _i18n.__)('Discussion'),
            panelName: "discussion-panel"
          })
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(_check3.default, {
          children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_enablePanel.default, {
            label: (0, _i18n.__)('Page attributes'),
            panelName: "page-attributes"
          })
        })]
      }), isLargeViewport && /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferencesModalSection, {
        title: (0, _i18n.__)('Publishing'),
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_enablePublishSidebar.default, {
          help: (0, _i18n.__)('Review settings, such as visibility and tags.'),
          label: (0, _i18n.__)('Enable pre-publish checks')
        })
      }), extraSections?.general]
    })
  }, {
    name: 'appearance',
    tabLabel: (0, _i18n.__)('Appearance'),
    content: /*#__PURE__*/(0, _jsxRuntime.jsxs)(PreferencesModalSection, {
      title: (0, _i18n.__)('Appearance'),
      description: (0, _i18n.__)('Customize the editor interface to suit your needs.'),
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
        scope: "core",
        featureName: "fixedToolbar",
        onToggle: () => setPreference('core', 'distractionFree', false),
        help: (0, _i18n.__)('Access all block and document tools in a single place.'),
        label: (0, _i18n.__)('Top toolbar')
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
        scope: "core",
        featureName: "distractionFree",
        onToggle: () => {
          setPreference('core', 'fixedToolbar', true);
          setIsInserterOpened(false);
          setIsListViewOpened(false);
        },
        help: (0, _i18n.__)('Reduce visual distractions by hiding the toolbar and other elements to focus on writing.'),
        label: (0, _i18n.__)('Distraction free')
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
        scope: "core",
        featureName: "focusMode",
        help: (0, _i18n.__)('Highlights the current block and fades other content.'),
        label: (0, _i18n.__)('Spotlight mode')
      }), extraSections?.appearance]
    })
  }, {
    name: 'accessibility',
    tabLabel: (0, _i18n.__)('Accessibility'),
    content: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(PreferencesModalSection, {
        title: (0, _i18n.__)('Navigation'),
        description: (0, _i18n.__)('Optimize the editing experience for enhanced control.'),
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
          scope: "core",
          featureName: "keepCaretInsideBlock",
          help: (0, _i18n.__)('Keeps the text cursor within blocks while navigating with arrow keys, preventing it from moving to other blocks and enhancing accessibility for keyboard users.'),
          label: (0, _i18n.__)('Contain text cursor inside block')
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferencesModalSection, {
        title: (0, _i18n.__)('Interface'),
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
          scope: "core",
          featureName: "showIconLabels",
          label: (0, _i18n.__)('Show button text labels'),
          help: (0, _i18n.__)('Show text instead of icons on buttons across the interface.')
        })
      })]
    })
  }, {
    name: 'blocks',
    tabLabel: (0, _i18n.__)('Blocks'),
    content: /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
      children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(PreferencesModalSection, {
        title: (0, _i18n.__)('Inserter'),
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
          scope: "core",
          featureName: "mostUsedBlocks",
          help: (0, _i18n.__)('Adds a category with the most frequently used blocks in the inserter.'),
          label: (0, _i18n.__)('Show most used blocks')
        })
      }), /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferencesModalSection, {
        title: (0, _i18n.__)('Manage block visibility'),
        description: (0, _i18n.__)("Disable blocks that you don't want to appear in the inserter. They can always be toggled back on later."),
        children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_blockVisibility.default, {})
      })]
    })
  }, window.__experimentalMediaProcessing && {
    name: 'media',
    tabLabel: (0, _i18n.__)('Media'),
    content: /*#__PURE__*/(0, _jsxRuntime.jsx)(_jsxRuntime.Fragment, {
      children: /*#__PURE__*/(0, _jsxRuntime.jsxs)(PreferencesModalSection, {
        title: (0, _i18n.__)('General'),
        description: (0, _i18n.__)('Customize options related to the media upload flow.'),
        children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
          scope: "core/media",
          featureName: "optimizeOnUpload",
          help: (0, _i18n.__)('Compress media items before uploading to the server.'),
          label: (0, _i18n.__)('Pre-upload compression')
        }), /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferenceToggleControl, {
          scope: "core/media",
          featureName: "requireApproval",
          help: (0, _i18n.__)('Require approval step when optimizing existing media.'),
          label: (0, _i18n.__)('Approval step')
        })]
      })
    })
  }].filter(Boolean), [showBlockBreadcrumbsOption, extraSections, setIsInserterOpened, setIsListViewOpened, setPreference, isLargeViewport]);
  return /*#__PURE__*/(0, _jsxRuntime.jsx)(PreferencesModalTabs, {
    sections: sections
  });
}
//# sourceMappingURL=index.js.map