"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.BreadcrumbBase = exports.Breadcrumb = exports["default"] = exports.breadcrumbWidth = void 0;

var _jsxRuntime = require("react/jsx-runtime");

var _handle = require("@enact/core/handle");

var _kind = _interopRequireDefault(require("@enact/core/kind"));

var _Spottable = _interopRequireDefault(require("@enact/spotlight/Spottable"));

var _propTypes = _interopRequireDefault(require("prop-types"));

var _$L = _interopRequireDefault(require("../internal/$L"));

var _PanelsModule = _interopRequireDefault(require("./Panels.module.css"));

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }

function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }

// Since we expose `onSelect` to handle breadcrumb selection, we need that handler to be set on a
// component that proxies mouse events for key events so we create a spottable div that will
// get the right classes as well as handle events correctly.
var SpottableDiv = (0, _Spottable["default"])('div');
/**
 * The width of a breadcrumb which may be used to allocate space for it in a panels layout.
 *
 * @type {Number}
 * @default 105;
 * @memberof agate/Panels
 * @private
 */

var breadcrumbWidth = 105;
/**
 * Vertical, transparent bar used to navigate to a prior Panel.
 *
 * [`BreadcrumbPanels`]{@link agate/Panels.BreadcrumbPanels} has one breadcrumb.
 *
 * @class Breadcrumb
 * @memberof agate/Panels
 * @ui
 * @public
 */

exports.breadcrumbWidth = breadcrumbWidth;
var BreadcrumbBase = (0, _kind["default"])({
  name: 'Breadcrumb',
  propTypes:
  /** @lends agate/Panels.Breadcrumb.prototype */
  {
    /**
     * Index of the associated panel.
     *
     * @type {Number}
     * @required
     */
    index: _propTypes["default"].number.isRequired,

    /**
     * Called when the breadcrumb is clicked.
     *
     * @type {Function}
     * @private
     */
    onClick: _propTypes["default"].func,

    /**
     * Called when the breadcrumb is clicked.
     *
     * The index of the clicked breadcrumb is passed in the event data.
     *
     * @type {Function}
     */
    onSelect: _propTypes["default"].func
  },
  styles: {
    css: _PanelsModule["default"],
    className: 'breadcrumb'
  },
  handlers: {
    onSelect: (0, _handle.handle)((0, _handle.forward)('onClick'), (0, _handle.adaptEvent)(function (ev, _ref) {
      var index = _ref.index;
      return {
        type: 'onSelect',
        index: index
      };
    }, (0, _handle.forward)('onSelect')))
  },
  render: function render(_ref2) {
    var children = _ref2.children,
        index = _ref2.index,
        onSelect = _ref2.onSelect,
        rest = _objectWithoutProperties(_ref2, ["children", "index", "onSelect"]);

    return /*#__PURE__*/(0, _jsxRuntime.jsx)(SpottableDiv, _objectSpread(_objectSpread({}, rest), {}, {
      "aria-label": (0, _$L["default"])('GO TO PREVIOUS'),
      "data-index": index,
      onClick: onSelect,
      children: /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
        className: _PanelsModule["default"].breadcrumbContent,
        children: children
      })
    }));
  }
});
exports.BreadcrumbBase = exports.Breadcrumb = BreadcrumbBase;
var _default = BreadcrumbBase;
exports["default"] = _default;