/*
 * ATTENTION: The "eval" devtool has been used (maybe by default in mode: "development").
 * This devtool is neither made for production nor for readable output files.
 * It uses "eval()" calls to create a separate source file in the browser devtools.
 * If you are trying to read the output file, select a different devtool (https://webpack.js.org/configuration/devtool/)
 * or disable the default devtool with "devtool: false".
 * If you are looking for production-ready output files, see mode: "production" (https://webpack.js.org/configuration/mode/).
 */
/******/ (() => { // webpackBootstrap
/******/ 	"use strict";
/******/ 	var __webpack_modules__ = ({

/***/ "./assets/src/js/admin/settings.js":
/*!*****************************************!*\
  !*** ./assets/src/js/admin/settings.js ***!
  \*****************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

eval("__webpack_require__.r(__webpack_exports__);\n/* harmony import */ var _scss_admin_settings_scss__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! @/scss/admin/settings.scss */ \"./assets/src/scss/admin/settings.scss\");\nfunction _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }\nfunction _nonIterableSpread() { throw new TypeError(\"Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); }\nfunction _iterableToArray(iter) { if (typeof Symbol !== \"undefined\" && iter[Symbol.iterator] != null || iter[\"@@iterator\"] != null) return Array.from(iter); }\nfunction _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }\nfunction _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== \"undefined\" && o[Symbol.iterator] || o[\"@@iterator\"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === \"number\") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError(\"Invalid attempt to iterate non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.\"); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it[\"return\"] != null) it[\"return\"](); } finally { if (didErr) throw err; } } }; }\nfunction _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === \"string\") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === \"Object\" && o.constructor) n = o.constructor.name; if (n === \"Map\" || n === \"Set\") return Array.from(o); if (n === \"Arguments\" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }\nfunction _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }\n\n\n//Stored updated metafields\n\nvar postTypeMetaFields = {};\n\n// Store reference to dual select components\n\nvar leftSelect = document.getElementById('left-select');\nvar rightSelect = document.getElementById('right-select');\nvar moveToRightBtn = document.getElementById('move-to-right');\nvar moveToLeftBtn = document.getElementById('move-to-left');\n\n/** Select post type **/\n\nvar postTypeSelect = document.getElementById('post-type-select');\nfunction handlePostTypeChange() {\n  var postType = postTypeSelect.value;\n  if (postType) {\n    rightSelect.innerHTML = '';\n    fetchPostTypeMetaFields(postType);\n    fetchPostTypeExcludedMetaFields(postType);\n  } else {\n    leftSelect.innerHTML = '';\n  }\n}\n\n// Attach the event listener to 'change' event\npostTypeSelect.addEventListener('change', handlePostTypeChange);\n// Trigger the event on page load\nwindow.addEventListener('load', handlePostTypeChange);\n\n/** Dual select boxes **/\n\nfunction fetchPostTypeMetaFields(postType) {\n  var url = WP_REST.url + 'postsync/fetchMetaFieldsForPostType' + '?post_type=' + encodeURIComponent(postType);\n  fetch(url, {\n    method: 'GET',\n    headers: {\n      'X-WP-Nonce': WP_REST.nonce\n    }\n  }).then(function (response) {\n    if (response.ok) {\n      return response.json();\n    } else {\n      throw new Error('Error fetching post type meta fields');\n    }\n  }).then(function (data) {\n    // Clear and populate the left select box with the received data\n    leftSelect.innerHTML = '';\n    data.forEach(function (metaField) {\n      var option = document.createElement('option');\n      option.value = metaField;\n      option.text = metaField;\n      leftSelect.add(option);\n    });\n  })[\"catch\"](function (error) {\n    console.error('AJAX error:', error);\n  });\n}\nfunction fetchPostTypeExcludedMetaFields(postType) {\n  var url = WP_REST.url + 'postsync/fetchExcludedMetaFieldsForPostType' + '?post_type=' + encodeURIComponent(postType);\n  fetch(url, {\n    method: 'GET',\n    headers: {\n      'X-WP-Nonce': WP_REST.nonce\n    }\n  }).then(function (response) {\n    if (response.ok) {\n      return response.json();\n    } else {\n      throw new Error('Error fetching post type meta fields');\n    }\n  }).then(function (data) {\n    // Clear and populate the left select box with the received data\n    rightSelect.innerHTML = '';\n    data.forEach(function (metaField) {\n      var option = document.createElement('option');\n      option.value = metaField;\n      option.text = metaField;\n      rightSelect.add(option);\n    });\n  })[\"catch\"](function (error) {\n    console.error('AJAX error:', error);\n  });\n}\nmoveToRightBtn.addEventListener('click', function () {\n  moveSelectedOptions(leftSelect, rightSelect);\n});\nmoveToLeftBtn.addEventListener('click', function () {\n  moveSelectedOptions(rightSelect, leftSelect);\n});\nfunction moveSelectedOptions(sourceSelect, targetSelect) {\n  var postType = document.getElementById('post-type-select').value;\n  var _iterator = _createForOfIteratorHelper(sourceSelect.selectedOptions),\n    _step;\n  try {\n    for (_iterator.s(); !(_step = _iterator.n()).done;) {\n      var option = _step.value;\n      // Add the moved option to the target select\n      targetSelect.add(new Option(option.text, option.value, false, false));\n    }\n\n    // Remove the moved options from the source select\n  } catch (err) {\n    _iterator.e(err);\n  } finally {\n    _iterator.f();\n  }\n  _toConsumableArray(sourceSelect.selectedOptions).forEach(function (option) {\n    return sourceSelect.remove(option.index);\n  });\n\n  // Update the postTypeMetaFields object with the complete contents of the right list\n  postTypeMetaFields[postType] = _toConsumableArray(rightSelect.options).map(function (option) {\n    return option.value;\n  });\n}\n\n//Save settings button and modal\nvar saveBtn = document.getElementById('save-settings-btn');\nsaveBtn.addEventListener('click', function (event) {\n  var modal = document.getElementById('modal');\n  modal.classList.remove('hidden');\n});\nmodal.addEventListener('click', function (event) {\n  modal.classList.add('hidden');\n});\nfunction saveSettings(resync) {\n  var syncMetadata = document.querySelector('#sync-metadata-checkbox').checked;\n  var syncTaxonomies = document.querySelector('#sync-taxonomies-checkbox').checked;\n  var copyMedia = document.querySelector('#copy-media-checkbox').checked;\n\n  // Get all the checkboxes for post types\n  var postTypeCheckboxes = document.querySelectorAll(\".post-type-checkbox\");\n\n  // Filter the checkboxes to get only the ones that are checked\n  var checkedPostTypes = Array.from(postTypeCheckboxes).filter(function (checkbox) {\n    return checkbox.checked;\n  });\n\n  // Get an array of the id of the checked checkboxes (assuming the id is the post type name)\n  var enabledPostTypes = checkedPostTypes.map(function (checkbox) {\n    return checkbox.id;\n  });\n  fetch(WP_REST.url + 'postsync/settings', {\n    method: 'PATCH',\n    headers: {\n      'Content-Type': 'application/json',\n      'X-WP-Nonce': WP_REST.nonce\n    },\n    body: JSON.stringify({\n      sync_metadata: syncMetadata,\n      sync_taxonomies: syncTaxonomies,\n      copy_media: copyMedia,\n      resync: resync,\n      excluded_meta_fields: postTypeMetaFields,\n      enabled_post_types: enabledPostTypes // Send the enabled post types\n    })\n  }).then(function (response) {\n    return response.json();\n  }).then(function (response) {\n    if (response.success) {\n      // Show the success notification\n      document.getElementById('success-notification').classList.remove('hidden');\n\n      // Hide the notification after 3 seconds\n      setTimeout(function () {\n        document.getElementById('success-notification').classList.add('hidden');\n      }, 3000);\n      console.log('Setting saved successfully');\n    } else {\n      console.error('Error saving settings');\n    }\n  })[\"catch\"](function (error) {\n    console.error('AJAX error:', error);\n  });\n}\ndocument.addEventListener('DOMContentLoaded', function () {\n  var noReSyncBtn = document.querySelector('#no-re-sync-btn');\n  var reSyncBtn = document.querySelector('#re-sync-btn');\n  noReSyncBtn.addEventListener('click', function () {\n    saveSettings(false);\n  });\n  reSyncBtn.addEventListener('click', function () {\n    saveSettings(true);\n  });\n});\n\n//# sourceURL=webpack://post-sync/./assets/src/js/admin/settings.js?");

/***/ }),

/***/ "./assets/src/scss/admin/settings.scss":
/*!*********************************************!*\
  !*** ./assets/src/scss/admin/settings.scss ***!
  \*********************************************/
/***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {

eval("__webpack_require__.r(__webpack_exports__);\n// extracted by mini-css-extract-plugin\n\n\n//# sourceURL=webpack://post-sync/./assets/src/scss/admin/settings.scss?");

/***/ })

/******/ 	});
/************************************************************************/
/******/ 	// The module cache
/******/ 	var __webpack_module_cache__ = {};
/******/ 	
/******/ 	// The require function
/******/ 	function __webpack_require__(moduleId) {
/******/ 		// Check if module is in cache
/******/ 		var cachedModule = __webpack_module_cache__[moduleId];
/******/ 		if (cachedModule !== undefined) {
/******/ 			return cachedModule.exports;
/******/ 		}
/******/ 		// Create a new module (and put it into the cache)
/******/ 		var module = __webpack_module_cache__[moduleId] = {
/******/ 			// no module.id needed
/******/ 			// no module.loaded needed
/******/ 			exports: {}
/******/ 		};
/******/ 	
/******/ 		// Execute the module function
/******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
/******/ 	
/******/ 		// Return the exports of the module
/******/ 		return module.exports;
/******/ 	}
/******/ 	
/************************************************************************/
/******/ 	/* webpack/runtime/make namespace object */
/******/ 	(() => {
/******/ 		// define __esModule on exports
/******/ 		__webpack_require__.r = (exports) => {
/******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
/******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
/******/ 			}
/******/ 			Object.defineProperty(exports, '__esModule', { value: true });
/******/ 		};
/******/ 	})();
/******/ 	
/************************************************************************/
/******/ 	
/******/ 	// startup
/******/ 	// Load entry module and return exports
/******/ 	// This entry module can't be inlined because the eval devtool is used.
/******/ 	var __webpack_exports__ = __webpack_require__("./assets/src/js/admin/settings.js");
/******/ 	
/******/ })()
;