!function(t){var e={};function o(a){if(e[a])return e[a].exports;var s=e[a]={i:a,l:!1,exports:{}};return t[a].call(s.exports,s,s.exports,o),s.l=!0,s.exports}o.m=t,o.c=e,o.d=function(t,e,a){o.o(t,e)||Object.defineProperty(t,e,{enumerable:!0,get:a})},o.r=function(t){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})},o.t=function(t,e){if(1&e&&(t=o(t)),8&e)return t;if(4&e&&"object"==typeof t&&t&&t.__esModule)return t;var a=Object.create(null);if(o.r(a),Object.defineProperty(a,"default",{enumerable:!0,value:t}),2&e&&"string"!=typeof t)for(var s in t)o.d(a,s,function(e){return t[e]}.bind(null,s));return a},o.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return o.d(e,"a",e),e},o.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},o.p="",o(o.s=0)}([function(t,e,o){"use strict";o.r(e);const{createElement:a,render:s,useState:n,useEffect:d,Fragment:r}=wp.element;var i=t=>{d(()=>{});const e=e=>{var o;t.status=e.target.value,"remove"==t.status?(o=t.index,t.removeItem(o)):((e,o)=>{t.changeStatus(e,o)})(t.index,t.status)};return a("li",{className:"todo"},a("select",{id:"todo_select",index:t.index,className:"todo_status "+t.status,onChange:t=>{e(t)}},a("option",{className:"normal todo_option",value:"normal"},"Normal"),a("option",{className:"low todo_option",value:"low"},"Low"),a("option",{className:"high todo_option",value:"high"},"High"),a("option",{className:"done todo_option",value:"done"},"Done"),a("option",{className:"remove todo_option",value:"remove"},"Remove")),a("div",{className:"todo__text"},t.content),a("span",{className:"todo_date",status:t.status},t.date))};const{createElement:l,render:u,useState:c,useEffect:m,Fragment:p}=wp.element;var _=t=>{m(()=>{});var e=t.items.map(e=>l(i,{index:e.index,status:e.status,content:e.content,date:e.date,removeItem:t.removeItem,changeStatus:t.changeStatus}));return l("ul",null,e)};const{createElement:v,render:w,useState:g,useEffect:f,Fragment:h}=wp.element;var b=t=>{const[e,o]=g("");f(()=>{},[e]);return v("div",{className:"add_todo_task"},v("ul",null,v("li",{className:"add-task"},v("a",null,v("i",{className:"vicon vicon-plus",onClick:()=>{""!=e.trim()&&(t.addItem(e),o(""))}})),v("input",{type:"text",id:"task_input",className:"add_new_task",value:e,onChange:t=>{o(t.target.value)},placeholder:window.todo_task.translations.add_new}),v("span",{className:"todo_date"},t.date))))};const{createElement:k,render:y,useState:N,useEffect:x,Fragment:S}=wp.element,{select:E,dispatch:j}=wp.data,O=t=>{const[e,o]=N(!0),[a,s]=N([]);x(()=>{},[a]),x(()=>{e&&fetch(window.todo_task.api+"/todo_task?post",{method:"post",body:JSON.stringify({type:"get_todo",token:E("vibebp").getToken(),user_id:window.todo_task.user_id})}).then(t=>t.ok?t.json():{status:0,message:window.wplms_course_data.translations.error_loading_data}).then(e=>{if(e.status){o(!1);var a=e.result,n=0;a&&Array.isArray(a)&&a.map(t=>{s(e=>[...e,{index:n,content:t.text,status:t.status,date:t.date}]),n++})}document.dispatchEvent(new CustomEvent("vibebp_widget_loaded",{detail:{props:t}}))}).catch(t=>{o(!1),j("vibebp").addNotification({text:window.wplms_course_data.translations.error_loading_data})})},[]);return k("div",{className:"wplms_todo_task"},k("h3",{className:"dash_widget_title"},t.settings.title,k("button",{className:"small button",onClick:()=>{fetch(window.todo_task.api+"/todo_task?post",{method:"post",body:JSON.stringify({type:"update_todo",token:E("vibebp").getToken(),user_id:window.todo_task.user_id,todo_data:a})}).then(t=>t.ok?t.json():{status:0,message:window.wplms_course_data.translations.error_loading_data}).then(t=>{t.status&&console.log("Api data",t),o(!1)}).catch(t=>{o(!1),console.error("Uh oh, an error!",t),j("vibebp").addNotification({text:window.wplms_course_data.translations.error_loading_data})})}},window.todo_task.translations.save)),k("div",{className:"todo-list"},k(_,{items:a,removeItem:t=>{var e=[...a];e.splice(t,1),s(e)},changeStatus:(t,e)=>{var o=[...a];o[t].status=e,s(o)}}),k(b,{addItem:e=>{var o=a.length,n=e,d=t.settings.today,r=t.settings.status;s(t=>[...t,{index:o,status:r,content:n,date:d}])},date:window.todo_task.settings.today})))};document.addEventListener("wplms_dash_tasks",t=>{document.querySelector(".wplms_todo_task")&&y(k(O,{settings:t.detail.widget.options}),document.querySelector(".wplms_todo_task"))})}]);