/*
    Elfsight Instagram Feed
    Version: 3.8.4
    Release date: Fri Aug 23 2019

    https://elfsight.com

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

!function(wp,$){"use strict";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||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-feed-options]");Array.prototype.slice.call(widgets).forEach(function(widget){let options=widget.getAttribute("data-elfsight-instagram-feed-options"),data=JSON.parse(decodeURIComponent(options));eval("eappsInstagramFeed(widget, data)"),widget.removeAttribute("data-elfsight-instagram-feed-options"),widget.removeAttribute("data-elfsight-instagram-feed-version"),widget.closest(".elfsight-block-widget-container").classList.add("elfsight-block-widget-initialized")})},1500)}async function getWidgets(){const e=await $.get(ajaxurl,{action:"elfsight-instagram-feed".replace(/-/g,"_")+"_widgets_api",endpoint:"list"});return e.status?[e.data,e.data.reduce(function(e,t){return e[t.id]=t,e},{})]:[]}function getWidgetId(e){let t;return e.some(function(e){if("1"===e.active)return t=e.id}),t}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||"1"}}),el("div",{className:"elfsight-block-widget-placeholder"},el(IconBlock,{}),el("span",{},"Elfsight Instagram Feed"))):[]}}class Button extends React.Component{render(){let 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();let t=e.target.querySelector("option:checked");this.props.setAttributes({id:t.value.toString()})}componentDidMount(){getWidgets().then(e=>{const[t,i]=e;this.setState({widgets:t});const s=this.props.id,n=!(!i[s]||"1"!==i[s].active);!n&&i?this.props.setAttributes({id:getWidgetId(t),exist:!0}):this.props.setAttributes({id:s,exist:n})})}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:"number"},exist:{type:"bool",default:!1}},edit:function(e){const{attributes:{id:t,exist:i},setAttributes:s}=e;return getWidgets().then(e=>{const[n,o]=e;s(!i&&n?{id:getWidgetId(n),exist:!0}:{id:t,exist:i})}),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)}}),i?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")})))),i?el(Widget,{id:t,exist:i}):null,i?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);