'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

var _elementLayoutsManager = require('../managers/elementLayoutsManager');

var _elementLayoutsManager2 = _interopRequireDefault(_elementLayoutsManager);

var _appUtils = require('../utils/appUtils');

var _appUtils2 = _interopRequireDefault(_appUtils);

var _underscore = require('underscore');

var _underscore2 = _interopRequireDefault(_underscore);

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

var findElementLayoutsByElementKey = function findElementLayoutsByElementKey(props, params, callback) {
  var elementKey = _appUtils2.default.getProperty(params, props.elementKey);

  _elementLayoutsManager2.default.findByElementKey(elementKey).then(_appUtils2.default.onFindOptional.bind(null, params, props.setProperty, callback));
}; /*
    * *******************************************************************************
    *  * Copyright (c) 2018 Edgeworx, Inc.
    *  *
    *  * This program and the accompanying materials are made available under the
    *  * terms of the Eclipse Public License v. 2.0 which is available at
    *  * http://www.eclipse.org/legal/epl-2.0
    *  *
    *  * SPDX-License-Identifier: EPL-2.0
    *  *******************************************************************************
    *
    */

var createElementLayout = function createElementLayout(props, params, callback) {
  _elementLayoutsManager2.default.create(props.data).then(_appUtils2.default.onCreate.bind(null, params, props.setProperty, 'Unable to create Element Layout object.', callback));
};

var updateLayout = function updateLayout(props, params, callback) {
  var elementKey = _appUtils2.default.getProperty(params, props.elementKey);

  _elementLayoutsManager2.default.updateLayoutByElementKey(elementKey, props.updatedData).then(_appUtils2.default.onUpdate.bind(null, params, 'Unable to update Element Layout', callback));
};

var findElementLayoutsByElementKeys = function findElementLayoutsByElementKeys(props, params, callback) {
  var elementData = _appUtils2.default.getProperty(params, props.elementData);

  _elementLayoutsManager2.default.findByElementKey(_underscore2.default.pluck(elementData, props.field)).then(_appUtils2.default.onFindOptional.bind(null, params, props.setProperty, callback));
};

var deleteElementLayoutsByElementKeys = function deleteElementLayoutsByElementKeys(props, params, callback) {
  var elementKey = _appUtils2.default.getProperty(params, props.elementKey);

  _elementLayoutsManager2.default.deleteLayoutsByElementKey(elementKey).then(_appUtils2.default.onDeleteOptional.bind(null, params, callback));
};

exports.default = {
  createElementLayout: createElementLayout,
  deleteElementLayoutsByElementKeys: deleteElementLayoutsByElementKeys,
  findElementLayoutsByElementKey: findElementLayoutsByElementKey,
  findElementLayoutsByElementKeys: findElementLayoutsByElementKeys,
  updateLayout: updateLayout
};