"use strict";

exports.__esModule = true;
exports.default = void 0;

var _dom = _interopRequireDefault(require("../../../shared/dom7"));

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

/* eslint indent: ["off"] */
var _default = {
  render: function render(self) {
    // prettier-ignore
    return "\n      <div class=\"color-picker-module color-picker-module-palette\">\n        <div class=\"color-picker-palette\">\n          " + self.params.palette.map(function (p) {
      if (Array.isArray(p)) {
        var row = '<div class="color-picker-palette-row">';
        row += p.map(function (c) {
          return "\n                <div class=\"color-picker-palette-value\" data-palette-color=\"" + c + "\" style=\"background-color: " + c + "\"></div>\n              ";
        }).join('');
        row += '</div>';
        return row;
      }

      return "\n              <div class=\"color-picker-palette-value\" data-palette-color=\"" + p + "\" style=\"background-color: " + p + "\"></div>\n            ";
    }).join('') + "\n        </div>\n      </div>\n    ";
  },
  init: function init(self) {
    function handlePaletteClick(e) {
      var hex = (0, _dom.default)(e.target).attr('data-palette-color');
      self.setValue({
        hex: hex
      });
    }

    self.$el.on('click', '.color-picker-module-palette .color-picker-palette-value', handlePaletteClick);

    self.destroyPaletteEvents = function destroyPaletteEvents() {
      self.$el.off('click', '.color-picker-module-hex input', handlePaletteClick);
    };
  },
  destroy: function destroy(self) {
    if (self.destroyPaletteEvents) {
      self.destroyPaletteEvents();
    }

    delete self.destroyPaletteEvents;
  }
};
exports.default = _default;