define(["jquery","core/custom_interaction_events","core/notification","core/pubsub","core/paged_content_paging_bar","core/templates","core_course/events","core_course/repository","theme_remui/slick"],function(o,n,t,e,i,s,r,c){function d(n){return c.getLastAccessedCourses(n,10).then(function(n){return function(n){var i=n.map(function(n){return s.render("block_recentlyaccessedcourses/course-card",n)});return o.when.apply(null,i).then(function(){var e=[];return i.forEach(function(n){n.then(function(n){e.push(o(n))}).catch(t.exception)}),e})}(n)})}function a(n){var e=n.find(l.CONTENT).find(l.CARD_CONTAINER);!function(n){var e=n.find(l.PAGING_BAR);e.css("opacity",0),e.css("visibility","hidden"),e.attr("aria-hidden","true")}(n),e.is(".slick-initialized")&&e.slick("unslick"),e.html(h),e.slick({dots:!1,arrows:!0,infinite:!1,rtl:"rtl"==o("html").attr("dir"),opacity:0,speed:500,slidesToShow:4,slidesToScroll:4,responsive:[{breakpoint:1024,settings:{slidesToShow:3,slidesToScroll:3}},{breakpoint:800,settings:{slidesToShow:2,slidesToScroll:2}},{breakpoint:480,settings:{slidesToShow:1,slidesToScroll:1}}]})}function u(i){var n=null,t=!1;e.subscribe(r.favourited,function(n){!function(n,e){h.forEach(function(n){n.attr("data-course-id")==e&&n.find(l.COURSE_IS_FAVOURITE).removeClass("hidden")})}(0,n)}),e.subscribe(r.unfavorited,function(n){!function(n,e){h.forEach(function(n){n.attr("data-course-id")==e&&n.find(l.COURSE_IS_FAVOURITE).addClass("hidden")})}(0,n)}),e.subscribe("nav-drawer-toggle-start",function(){if(f&&h.length&&!t){t=!0;var n=0,e=function(){setTimeout(function(){a(i),++n<5&&t&&e()},100)};e(i)}}),e.subscribe("nav-drawer-toggle-end",function(){t=!1}),o(window).on("resize",function(){f&&h.length&&(n=n||setTimeout(function(){n=null,a(i)},66))})}var l={CARD_CONTAINER:'[data-region="card-deck"]',COURSE_IS_FAVOURITE:'[data-region="is-favourite"]',CONTENT:'[data-region="view-content"]',EMPTY_MESSAGE:'[data-region="empty-message"]',LOADING_PLACEHOLDER:'[data-region="loading-placeholder"]'},f=!1,h=[];return{init:function(n,e){e=o(e),u(e),d(n).then(function(n){f=!0,(h=n).length?(function(n){n.find(l.CONTENT).removeClass("hidden"),n.find(l.EMPTY_MESSAGE).addClass("hidden"),n.find(l.LOADING_PLACEHOLDER).addClass("hidden")}(e),a(e)):function(n){n.find(l.EMPTY_MESSAGE).removeClass("hidden"),n.find(l.LOADING_PLACEHOLDER).addClass("hidden"),n.find(l.CONTENT).addClass("hidden")}(e)}).catch(t.exception)}}});