/*
    Elfsight Instagram Testimonials
    Version: 1.3.1
    Release date: Thu May 23 2019

    https://elfsight.com

    Copyright (c) 2019 Elfsight, LLC. ALL RIGHTS RESERVED
*/

!function(wp,$){let IconBlock=function(t){return wp.element.createElement("svg",{xmlns:"http://www.w3.org/2000/svg","xmlns:xlink":"http://www.w3.org/1999/xlink",width:"20",height:"20",viewBox:"0 0 20 20",class:"dashicon"},[wp.element.createElement("path",{id:"a",d:"M12.01 5.538a.893.893 0 1 1 0-1.786.893.893 0 0 1 0 1.786zm-4.06-.885a4.057 4.057 0 0 1 4.051 4.05 4.057 4.057 0 0 1-4.05 4.051 4.057 4.057 0 0 1-4.052-4.05A4.057 4.057 0 0 1 7.95 4.653zm0 6.363a2.306 2.306 0 0 0 2.305-2.305A2.31 2.31 0 0 0 7.95 6.407a2.31 2.31 0 0 0-2.304 2.304 2.306 2.306 0 0 0 2.304 2.305zM4.075 2.412A2.425 2.425 0 0 0 1.65 4.844v7.695a2.437 2.437 0 0 0 2.432 2.432h5.502l1.754 1.643H3.891A3.902 3.902 0 0 1 0 12.722V4.661A3.902 3.902 0 0 1 3.891.769h8.062a3.902 3.902 0 0 1 3.892 3.892v4.05s-.383-.015-.925.288c-.47.27-.718.677-.718.677V4.844a2.437 2.437 0 0 0-2.432-2.432H4.075zm11.172 8.23a.336.336 0 0 1 .31-.192c.136 0 .248.072.312.191l1.108 2.241a.333.333 0 0 0 .255.191l2.472.36c.128.015.24.11.28.23a.335.335 0 0 1-.089.351l-1.786 1.747a.33.33 0 0 0-.095.303l.422 2.464a.339.339 0 0 1-.135.335.327.327 0 0 1-.36.023l-2.208-1.164a.325.325 0 0 0-.319 0l-2.209 1.164a.342.342 0 0 1-.359-.023.345.345 0 0 1-.135-.335l.422-2.464a.353.353 0 0 0-.095-.303l-1.818-1.747a.34.34 0 0 1 .191-.582l2.472-.359a.333.333 0 0 0 .255-.191l1.109-2.24z"})])};if(void 0===wp.components||void 0===wp.blocks||void 0===wp.element||void 0===wp.i18n)return!1;const{__:__}=wp.i18n,el=wp.element.createElement,registerBlockType=wp.blocks.registerBlockType,ServerSideRender=wp.components.ServerSideRender;let initTimeout;function initWidget(){clearTimeout(initTimeout),initTimeout=setTimeout(function(){let widgets=document.querySelectorAll("[data-elfsight-instagram-testimonials-options]");Array.prototype.slice.call(widgets).forEach(function(widget){let options=widget.getAttribute("data-elfsight-instagram-testimonials-options"),data=JSON.parse(decodeURIComponent(options));eval("eappsInstagramTestimonials(widget, data)"),widget.removeAttribute("data-elfsight-instagram-testimonials-options"),widget.removeAttribute("data-elfsight-instagram-testimonials-version"),widget.closest(".elfsight-block-widget-container").classList.add("elfsight-block-widget-initialized")})},1500)}class Widget extends React.Component{componentDidMount(){initWidget()}componentDidUpdate(){initWidget()}render(){return this.props.id?el("div",{className:"elfsight-block-widget-container"},el(ServerSideRender,{block:"elfsight-instagram-testimonials/block",attributes:{id:this.props.id||"1"}}),el("div",{className:"elfsight-block-widget-placeholder"},el(IconBlock,{}),el("span",{},"Elfsight Instagram Testimonials"))):[]}}class Button extends React.Component{render(){let t=document.location.origin+document.location.pathname.replace("post.php","admin.php")+"?page=elfsight-instagram-testimonials#";return el("a",{href:t+this.props.href,target:"_blank",className:this.props.className},this.props.text)}}class WidgetSelect extends React.Component{constructor(){super(),this.state={widgets:[]}}setWidget(t){t.preventDefault();let e=t.target.querySelector("option:checked");this.props.setAttributes({id:e.value.toString()})}componentDidMount(){$.get(ajaxurl,{action:"elfsight-instagram-testimonials".replace(/-/g,"_")+"_widgets_api",endpoint:"list"}).then(t=>{if(t.status){this.setState({widgets:t.data});let e=t.data.reduce(function(t,e){return t[e.id]=e,t},{}),i=!(!e[this.props.id]||"1"!==e[this.props.id].active);!i&&t.data[0]?this.props.setAttributes({id:parseInt(t.data[0].id),exist:!0}):this.props.setAttributes({id:this.props.id,exist:i})}})}render(){return this.state.widgets.length>0?el("div",{className:"components-base-control"},el("div",{className:"components-base-control__field"},el("select",{className:"components-select-control__input",id:"elfsight-instagram-testimonials-block-control-id",value:this.props.id,onChange:this.setWidget.bind(this)},this.state.widgets.map(t=>wp.element.createElement("option",{value:t.id},[t.name]))))):[]}}registerBlockType("elfsight-instagram-testimonials/block",{title:"Elfsight Instagram Testimonials",description:"Let real Instagram testimonials increase trust in your brand",icon:{src:IconBlock},category:"widgets",keywords:["Elfsight Instagram Testimonials","Elfsight"],supports:{html:!1},attributes:{id:{type:"string"},exist:{type:"bool",default:!1}},edit:function(t){const{attributes:{id:e,exist:i},setAttributes:s}=t;return el(wp.element.Fragment,{},el(wp.editor.InspectorControls,{},el(wp.components.PanelBody,{className:"elfsight-block-panel",title:"Select widget"},el(WidgetSelect,{id:e,setAttributes:function(e){t.setAttributes(e)}}),i?el("div",{className:"elfsight-block-panel-group"},el(Button,{href:"/edit-widget/"+e,className:"components-button is-button is-default is-large elfsight-block-panel-button",text:__("Edit Widget")}),el(Button,{href:"/add-widget/",className:"elfsight-block-panel-link",text:__("Create new widget")})):el("div",{className:"elfsight-block-panel-group"},el("span",{},__("No widgets yet")),el(Button,{href:"/add-widget/",className:"components-button is-button is-default is-primary is-large elfsight-block-panel-button",text:__("Create Widget")})))),i?el(Widget,{id:e,exist:i}):null,i?null:el("div",{className:"elfsight-block-form"},el("div",{className:"elfsight-block-form-header"},el(IconBlock,{}),el("span",{},"Elfsight Instagram Testimonials")),el("div",{className:"elfsight-block-form-text"},__("Let real Instagram testimonials increase trust in your brand"),el("br"),el("strong",{},__("Let's create your first widget!"))),el(Button,{href:"/add-widget/",className:"components-button is-button is-default is-primary is-large elfsight-block-form-button",text:__("Create Widget")})))},save:function(){return null}})}(wp,jQuery);