'use strict';

Liferay.Loader.define("frontend-taglib-clay$clay-dropdown@2.24.1/lib/ClayDropdown", ['module', 'exports', 'require', 'frontend-taglib-clay$clay-icon', './ClayDropdownBase', 'frontend-taglib-clay$clay-component', 'frontend-js-metal-web$metal-web-component', 'frontend-js-metal-web$metal-soy', 'frontend-js-metal-web$metal-state', './validators', './ClayDropdown.soy'], function (module, exports, require) {
  var define = undefined;
  var global = window;
  {
    Object.defineProperty(exports, "__esModule", {
      value: true
    });
    exports.ClayDropdown = undefined;

    var _createClass = function () {
      function defineProperties(target, props) {
        for (var i = 0; i < props.length; i++) {
          var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
        }
      }return function (Constructor, protoProps, staticProps) {
        if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
      };
    }();

    require("frontend-taglib-clay$clay-icon");

    require('./ClayDropdownBase');

    var _clayComponent = require("frontend-taglib-clay$clay-component");

    var _clayComponent2 = _interopRequireDefault(_clayComponent);

    var _metalWebComponent = require("frontend-js-metal-web$metal-web-component");

    var _metalWebComponent2 = _interopRequireDefault(_metalWebComponent);

    var _metalSoy = require("frontend-js-metal-web$metal-soy");

    var _metalSoy2 = _interopRequireDefault(_metalSoy);

    var _metalState = require("frontend-js-metal-web$metal-state");

    var _validators = require('./validators');

    var _ClayDropdownSoy = require("./ClayDropdown.soy");

    var _ClayDropdownSoy2 = _interopRequireDefault(_ClayDropdownSoy);

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

    function _classCallCheck(instance, Constructor) {
      if (!(instance instanceof Constructor)) {
        throw new TypeError("Cannot call a class as a function");
      }
    }

    function _possibleConstructorReturn(self, call) {
      if (!self) {
        throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
      }return call && (typeof call === "object" || typeof call === "function") ? call : self;
    }

    function _inherits(subClass, superClass) {
      if (typeof superClass !== "function" && superClass !== null) {
        throw new TypeError("Super expression must either be null or a function, not " + typeof superClass);
      }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
    }

    /**
     * Implementation for Metal Clay Dropdown.
     * @extends ClayComponent
     */
    var ClayDropdown = function (_ClayComponent) {
      _inherits(ClayDropdown, _ClayComponent);

      function ClayDropdown() {
        _classCallCheck(this, ClayDropdown);

        return _possibleConstructorReturn(this, (ClayDropdown.__proto__ || Object.getPrototypeOf(ClayDropdown)).apply(this, arguments));
      }

      _createClass(ClayDropdown, [{
        key: 'attached',

        /**
         * @inheritDoc
         */
        value: function attached() {
          this.addListener('toggle', this._defaultToggle, true);
        }

        /**
         * Toggles the dropdown, closing it when open or opening it when closed.
         * @param {!Event} event
         * @protected
         */

      }, {
        key: '_defaultToggle',
        value: function _defaultToggle(event) {
          event.preventDefault();

          this.expanded = !this.expanded;
        }

        /**
         * Handles footer button click.
         * @param {!Event} event
         * @protected
         */

      }, {
        key: '_handleButtonClick',
        value: function _handleButtonClick(event) {
          this.emit('buttonClicked', event);
        }

        /**
         * Continues the propagation of the item clicked event
         * @param {!Event} event
         * @protected
         * @return {Boolean} If the event has been prevented or not.
         */

      }, {
        key: '_handleItemClick',
        value: function _handleItemClick(event) {
          return !this.emit({
            data: event.data,
            name: 'itemClicked',
            originalEvent: event
          });
        }

        /**
         * Continues the propagation of the toggle event.
         * @param {!Event} event
         * @return {Boolean} If the event has been prevented or not.
         */

      }, {
        key: 'toggle',
        value: function toggle(event) {
          return !this.emit({
            name: 'toggle',
            originalEvent: event
          });
        }
      }]);

      return ClayDropdown;
    }(_clayComponent2.default);

    /**
     * State definition.
     * @static
     * @type {!Object}
     */

    ClayDropdown.STATE = {
      /**
       * Button configuration to place a button at dropdown footer.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      button: _metalState.Config.shapeOf({
        label: _metalState.Config.string().required(),
        style: _metalState.Config.oneOf(['primary', 'secondary']),
        type: _metalState.Config.oneOf(['button', 'reset', 'submit'])
      }),

      /**
       * Content Renderer name of items.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      contentRenderer: _metalState.Config.string(),

      /**
       * Data to add to the element.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?object}
       */
      data: _metalState.Config.object(),

      /**
       * Object that wires events with default listeners
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @review
       * @type {?(object|undefined)}
       */
      defaultEventHandler: _metalState.Config.object(),

      /**
       * Flag to indicate if menu is disabled
       * @default false
       * @instance
       * @memberof ClayDropdown
       * @type {?bool}
       */
      disabled: _metalState.Config.bool().value(false),

      /**
       * CSS classes to be applied to the element.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      elementClasses: _metalState.Config.string(),

      /**
       * Flag to indicate if menu is expanded.
       * @default false
       * @instance
       * @memberof ClayDropdown
       * @type {?bool}
       */
      expanded: _metalState.Config.bool().value(false),

      /**
       * Id to be applied to the element.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      id: _metalState.Config.string(),

      /**
       * Icon to use in the trigger.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      icon: _metalState.Config.string(),

      /**
       * List of menu items.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {!Array}
       */
      items: _validators.itemsValidator.required(),

      /**
       * Position in which item icon will be placed. Needed if any item has icons.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      itemsIconAlignment: _metalState.Config.oneOf(['left', 'right', 'left-right']),

      /**
       * Label of the trigger button.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(html|string|undefined)}
       */
      label: _metalState.Config.any(),

      /**
       * The preferred alignment for the dropdown content.
       * @default BottomLeft
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      preferredAlign: _validators.preferredAlign.value('BottomLeft'),

      /**
       * Flag to indicate if menu has a search field and search through elements
       * is possible.
       * @default false
       * @instance
       * @memberof ClayDropdown
       * @type {?bool}
       */
      searchable: _metalState.Config.bool().value(false),

      /**
       * Flag to indicate if toggle icon should appear or not.
       * @default true
       * @instance
       * @memberof ClayDropdown
       * @type {?bool}
       */
      showToggleIcon: _metalState.Config.bool().value(true),

      /**
       * The path to the SVG spritemap file containing the icons.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {!string}
       */
      spritemap: _metalState.Config.string().required(),

      /**
       * Style of the trigger button.
       * @default unstyled
       * @instance
       * @memberof ClayDropdown
       * @type {?string}
       */
      style: _metalState.Config.oneOf(['link', 'primary', 'secondary', 'unstyled']).value('unstyled'),

      /**
       * Aria label attribute for the trigger element.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      triggerAriaLabel: _metalState.Config.string(),

      /**
       * CSS classes to be applied to the trigger element.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      triggerClasses: _metalState.Config.string(),

      /**
       * The title attribute of the trigger element.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      triggerTitle: _metalState.Config.string(),

      /**
       * Size of the trigger button.
       * @default undefined
       * @instance
       * @memberof ClayDropdown
       * @type {?(string|undefined)}
       */
      triggerSize: _metalState.Config.oneOf(['sm']),

      /**
       * Flag to indicate whether the search element will be wrapped
       * with `<form />` tag.
       * @default true
       * @instance
       * @memberof ClayDropdown
       * @type {?bool}
       */
      useSearchableWithForm: _metalState.Config.bool().value(true)
    };

    (0, _metalWebComponent2.default)('clay-dropdown', ClayDropdown);

    _metalSoy2.default.register(ClayDropdown, _ClayDropdownSoy2.default);

    exports.ClayDropdown = ClayDropdown;
    exports.default = ClayDropdown;
    //# sourceMappingURL=ClayDropdown.js.map
  }
});
//# sourceMappingURL=ClayDropdown.js.map