!function(e){var t={};function n(o){if(t[o])return t[o].exports;var r=t[o]={i:o,l:!1,exports:{}};return e[o].call(r.exports,r,r.exports,n),r.l=!0,r.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var r in e)n.d(o,r,function(t){return e[t]}.bind(null,r));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=23)}({2:function(e,t,n){var o;
/*!
  Copyright (c) 2017 Jed Watson.
  Licensed under the MIT License (MIT), see
  http://jedwatson.github.io/classnames
*/
/*!
  Copyright (c) 2017 Jed Watson.
  Licensed under the MIT License (MIT), see
  http://jedwatson.github.io/classnames
*/
!function(){"use strict";var n={}.hasOwnProperty;function r(){for(var e=[],t=0;t<arguments.length;t++){var o=arguments[t];if(o){var a=typeof o;if("string"===a||"number"===a)e.push(o);else if(Array.isArray(o)&&o.length){var l=r.apply(null,o);l&&e.push(l)}else if("object"===a)for(var c in o)n.call(o,c)&&o[c]&&e.push(c)}}return e.join(" ")}e.exports?(r.default=r,e.exports=r):void 0===(o=function(){return r}.apply(t,[]))||(e.exports=o)}()},21:function(e,t,n){},23:function(e,t,n){"use strict";n.r(t);var o=n(2),r=n.n(o),a={blockIcon:wp.element.createElement("span",null,wp.element.createElement("span",{className:r()("toolset-gutenberg-block-image","toolset-ct-gutenberg-block","dashicon")})),blockPlaceholder:wp.element.createElement("span",{className:r()("toolset-gutenberg-block-placeholder","toolset-ct-gutenberg-block","dashicon")})};function l(e){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function c(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function i(e,t){return!t||"object"!==l(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function s(e){return(s=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function p(e,t){return(p=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var u=wp.i18n.__,f=wp.element.Component,m=wp.components.BaseControl,b=window.toolset_ct_block_strings,w=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),i(this,s(t).apply(this,arguments))}var n,o,r;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&p(e,t)}(t,f),n=t,(o=[{key:"render",value:function(){var e=this.props,t=e.attributes,n=e.className,o=e.onChangeCT,r=t.ct,a=Object.values(b.publishedCTs);return void 0!==a&&a.length>0?wp.element.createElement(m,null," ",wp.element.createElement("select",{onChange:o,value:r,className:n},wp.element.createElement("option",{disabled:"disabled",value:""},u("Select a Content Template","wpv-views")),a.map(function(e){return wp.element.createElement("option",{key:e.post_name,value:e.post_name},e.post_title)}))):wp.element.createElement(m,null,wp.element.createElement("select",{disabled:"disabled",className:n},wp.element.createElement("option",null,u("Create a Content Template first","wpv-views"))))}}])&&c(n.prototype,o),r&&c(n,r),t}();function y(e){return(y="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function v(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function d(e,t){return!t||"object"!==y(t)&&"function"!=typeof t?function(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}(e):t}function h(e){return(h=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function g(e,t){return(g=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}var _=wp.i18n.__,k=wp.element.Component,C=wp.editor.InspectorControls,O=wp.components.PanelBody,E=function(e){function t(){return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),d(this,h(t).apply(this,arguments))}var n,o,r;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&g(e,t)}(t,k),n=t,(o=[{key:"render",value:function(){var e=this.props,t=e.attributes,n=e.onChangeCT,o=t.ct;return wp.element.createElement(C,null,wp.element.createElement(O,{title:_("Content Template","wpv-views")},wp.element.createElement(w,{attributes:{ct:o},className:"components-select-control__input",onChangeCT:n})))}}])&&v(n.prototype,o),r&&v(n,r),t}();function T(e){return(T="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function j(e,t){for(var n=0;n<t.length;n++){var o=t[n];o.enumerable=o.enumerable||!1,o.configurable=!0,"value"in o&&(o.writable=!0),Object.defineProperty(e,o.key,o)}}function S(e){return(S=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}function P(e,t){return(P=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function N(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var x=wp.i18n.__,M=wp.element.Component,I=wp.components.Spinner,A=window.toolset_ct_block_strings,D=function(e){function t(){var e,n,o;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,t),n=this,(e=!(o=S(t).apply(this,arguments))||"object"!==T(o)&&"function"!=typeof o?N(n):o).getCTInfo=e.getCTInfo.bind(N(N(e))),e.state={fetching:!1,error:!1,errorMessage:""},e}var n,o,a;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&P(e,t)}(t,M),n=t,a=[{key:"getDerivedStateFromProps",value:function(e,t){return e.attributes.ct&&void 0===t.ctPostContent&&!1===t.fetching&&(t.fetching=!0),t}}],(o=[{key:"render",value:function(){var e=this.state,t=e.fetching,n=e.error,o=e.errorMessage,a=e.ctPostContent;return t?wp.element.createElement("div",{key:"fetching",className:r()(this.props.className)},wp.element.createElement("div",{key:"loading",className:r()("wp-block-embed is-loading")},wp.element.createElement(I,null),wp.element.createElement("p",null,x("Loading the Content Template preview…","wpv-views")))):n?wp.element.createElement("div",{key:"error",className:r()(this.props.className)},wp.element.createElement("div",{className:r()("wpv-ct-info-warning")},o)):wp.element.createElement("div",{className:r()(this.props.className)},wp.element.createElement("div",{dangerouslySetInnerHTML:{__html:a}}))}},{key:"componentDidMount",value:function(){this.getCTInfo()}},{key:"componentDidUpdate",value:function(e){e.attributes.ct.post_name!==this.props.attributes.ct.post_name&&(this.setState({fetching:!0,error:!1,errorMessage:""}),this.getCTInfo(this.props.attributes.ct.post_name))}},{key:"getCTInfo",value:function(e){var t=this,n=new window.FormData;n.append("action",A.actionName),n.append("wpnonce",A.wpnonce),n.append("ct_post_name",void 0===e?this.props.attributes.ct.post_name:e),window.fetch(window.ajaxurl,{method:"POST",body:n,credentials:"same-origin"}).then(function(e){return e.json()}).then(function(e){var n={};if(0!==e&&e.success&&void 0!==e.data)""===e.data?(n.error=!0,n.errorMessage=x('The selected Content Template has an empty "Template" section.',"wpv-views")):n.ctPostContent=e.data;else{var o="";o=void 0!==e.data&&void 0!==e.data.message?e.data.message:x("An error occurred while trying to get the Content Template information.","wpv-views"),n.error=!0,n.errorMessage=o}n.fetching=!1,t.setState(n)})}}])&&j(n.prototype,o),a&&j(n,a),t}(),L=(n(21),wp.i18n),R=L.__,B=L.setLocaleData,F=wp.blocks.registerBlockType,H=wp.components.Placeholder,U=wp.element.RawHTML,q=window.toolset_ct_block_strings;q.locale&&B(q.locale,"wpv-views"),F(q.blockName,{title:R("Content Template","wpv-views"),description:R("Add a Content Template to the editor.","wpv-views"),category:q.blockCategory,icon:a.blockIcon,keywords:[R("Toolset","wpv-views"),R("Content Template","wpv-views"),R("Shortcode","wpv-views")],supports:{align:["wide","full"]},edit:function(e){var t=function(t){e.setAttributes({ct:t.target.value})};return[!(!e.focus&&!e.isSelected)&&wp.element.createElement(E,{key:"wpv-gutenberg-ct-block-render-inspector",attributes:{ct:e.attributes.ct},onChangeCT:t}),""===e.attributes.ct?wp.element.createElement(H,{key:"ct-block-placeholder",className:r()("wp-block-toolset-ct")},wp.element.createElement("div",{className:"wp-block-toolset-ct-placeholder"},a.blockPlaceholder,wp.element.createElement("h2",null,R("Toolset Content Template","wpv-views")),wp.element.createElement(w,{attributes:{ct:e.attributes.ct},className:r()("components-select-control__input"),onChangeCT:t}))):wp.element.createElement(D,{key:"toolset-ct-gutenberg-block-preview",className:r()(e.className,"wp-block-toolset-ct-preview"),attributes:{ct:{post_name:e.attributes.ct}}})]},save:function(e){var t=e.attributes.ct||"";return t.length?(t=' view_template="'+t+'"',wp.element.createElement(U,null,"[wpv-post-body"+t+"]")):null}})}});