import $ from 'jquery';

var MekariForm = function MekariForm() {

checkAll();

};

var checkAll = function checkAll() {

// find all class name checkallbox
var $checkallWrapper = $('.checkallbox-wrapper');
$checkallWrapper.each(function () {
  var $datacheckall = $(this).attr('data-checkall');
  var $parentCheckbox = $(this).find(".checkallbox-parent[data-checkall = '" + $datacheckall + "']");
  var $arrayListCheckbox = $(this).find("input[type='checkbox'][data-checkall = '" + $datacheckall + "']").not('.checkallbox-parent'); // update check all status (init)

  updateCheckAll($parentCheckbox, $arrayListCheckbox); // call function for trigered when parent is change

  activateParentCheckAll($parentCheckbox, $arrayListCheckbox); // call function for trigered when child is change

  activateChildCheckAll($parentCheckbox, $arrayListCheckbox);
});

};

var updateCheckAll = function updateCheckAll($parentCb, $childCb) {

var $totalChildCb = $childCb.length;
var $totalChildChecked = $childCb.filter(function () {
  return $(this).is(':checked') === true;
}).length;

if ($totalChildChecked === $totalChildCb && $totalChildCb > 0) {
  $parentCb.prop('checked', true);
} else {
  $parentCb.prop('checked', false);
}

};

var activateParentCheckAll = function activateParentCheckAll($parentCb, $childCb) {

$parentCb.change(function () {
  if ($(this).is(':checked')) {
    $childCb.prop('checked', true);
  } else {
    $childCb.prop('checked', false);
  }
});

};

var activateChildCheckAll = function activateChildCheckAll($parentCb, $childCb) {

$childCb.change(function () {
  updateCheckAll($parentCb, $childCb);
});

};

$(document).ready(function () {

MekariForm();

}); export default MekariForm;

//# sourceMappingURL=mekari-ui-form.js.map