/*
    Elfsight Instagram Feed
    Version: 3.6.2
    Release date: Fri Nov 09 2018

    https://elfsight.com

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

!function(wp,$){let IconBlock=function(e){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.58 0a4.103 4.103 0 0 1 4.092 4.092v8.488a4.103 4.103 0 0 1-4.092 4.092H4.092A4.103 4.103 0 0 1 0 12.58V4.092A4.103 4.103 0 0 1 4.092 0h8.488zm2.37 12.387h-.009V4.286a2.564 2.564 0 0 0-2.554-2.555H4.286A2.564 2.564 0 0 0 1.73 4.286v8.1a2.564 2.564 0 0 0 2.555 2.555h8.109a2.564 2.564 0 0 0 2.555-2.554zm3.319-8.303A4.09 4.09 0 0 1 20 7.42v8.488A4.103 4.103 0 0 1 15.908 20H7.42c-1.37 0-2.596-.69-3.336-1.731h11.63a2.564 2.564 0 0 0 2.555-2.555V4.084zM8.244 4.067a4.266 4.266 0 0 1 4.26 4.26 4.271 4.271 0 0 1-4.26 4.261 4.271 4.271 0 0 1-4.26-4.26 4.266 4.266 0 0 1 4.26-4.26zm0 6.698a2.435 2.435 0 0 0 2.428-2.429 2.435 2.435 0 0 0-2.428-2.428 2.435 2.435 0 0 0-2.429 2.428 2.435 2.435 0 0 0 2.429 2.429zM12.513 5a.941.941 0 1 1 0-1.882.941.941 0 0 1 0 1.882z"})])};if(void 0===wp.components)return!1;const{__:__}=wp.i18n,el=wp.element.createElement,registerBlockType=wp.blocks.registerBlockType,ServerSideRender=wp.components.ServerSideRender;function initWidget(){setTimeout(function(){$("[data-elfsight-instagram-feed-options]").each(function(){var options=$(this).attr("data-elfsight-instagram-feed-options"),data=JSON.parse(decodeURIComponent(options)),jsInitFunc="$(this).eappsInstagramFeed(data)";eval(jsInitFunc).removeAttr("data-elfsight-instagram-feed-options").data("elfsight-options",options),$(this).parents(".elfsight-block-widget-container").toggleClass("elfsight-block-widget-initialized",!0)})},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-feed/block",attributes:{id:this.props.id}}),el("div",{className:"elfsight-block-widget-placeholder"},el(IconBlock,{}),el("span",{},"Elfsight Instagram Feed"))):[]}}class Button extends React.Component{render(){var e=document.location.origin+document.location.pathname.replace("post.php","admin.php")+"?page=elfsight-instagram-feed#";return el("a",{href:e+this.props.href,target:"_blank",className:this.props.className},this.props.text)}}class WidgetSelect extends React.Component{constructor(){super(),this.state={widgets:[]}}setWidget(e){e.preventDefault();var t=e.target.querySelector("option:checked");this.props.setAttributes({id:t.value})}componentDidMount(){$.get(ajaxurl,{action:"elfsight-instagram-feed".replace(/-/g,"_")+"_widgets_api",endpoint:"list"}).then(e=>{if(e.status){this.setState({widgets:e.data});var t=e.data.reduce(function(e,t){return e[t.id]=t,e},{}),s=!(!t[this.props.id]||"1"!==t[this.props.id].active);!s&&e.data[0]?(this.props.setAttributes({id:parseInt(e.data[0].id)}),this.props.setAttributes({exist:!0})):this.props.setAttributes({exist:s})}})}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-feed-block-control-id",value:this.props.id,onChange:this.setWidget.bind(this)},this.state.widgets.map(e=>wp.element.createElement("option",{value:e.id},[e.name]))))):[]}}registerBlockType("elfsight-instagram-feed/block",{title:"Elfsight Instagram Feed",description:"Add Instagram images to your website to engage your visitors",icon:{src:IconBlock},category:"widgets",keywords:["Elfsight Instagram Feed","Elfsight"],supports:{html:!1},attributes:{id:{type:"integer",default:1},exist:{type:"bool",default:!1}},edit:function(e){const{attributes:{id:t,exist:s},setAttributes:i}=e;return el(wp.element.Fragment,{},el(wp.editor.InspectorControls,{},el(wp.components.PanelBody,{className:"elfsight-block-panel",title:"Select widget"},el(WidgetSelect,{id:t,setAttributes:function(t){e.setAttributes(t)}}),s?el("div",{className:"elfsight-block-panel-group"},el(Button,{href:"/edit-widget/"+t,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")})))),s?el(Widget,{id:t,exist:s}):null,s?null:el("div",{className:"elfsight-block-form"},el("div",{className:"elfsight-block-form-header"},el(IconBlock,{}),el("span",{},"Elfsight Instagram Feed")),el("div",{className:"elfsight-block-form-text"},__("Add Instagram images to your website to engage your visitors"),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);