/**
 * Skipped minification because the original files appears to be already minified.
 * Original file: /npm/stories-react-bd@1.1.2/dist/index.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
"use strict";var e=require("react/jsx-runtime"),n=require("react"),t=function(){return t=Object.assign||function(e){for(var n,t=1,r=arguments.length;t<r;t++)for(var o in n=arguments[t])Object.prototype.hasOwnProperty.call(n,o)&&(e[o]=n[o]);return e},t.apply(this,arguments)};"function"==typeof SuppressedError&&SuppressedError;var r=n.createContext({stories:[],width:"100%",height:"100%",defaultDuration:1e4,isPaused:!1}),o=Object.freeze({LEFT:"left",RIGHT:"right"}),s={left:"Actions-styles_left__eky50",right:"Actions-styles_right__zguoH"};function u(r){var u=r.onNextClick,i=r.onPrevClick,c=r.onPause,a=r.onResume,l=n.useState(!1),d=l[0],f=l[1],v=n.useRef(null);function p(e){e.preventDefault(),clearTimeout(v.current),v.current=setTimeout((function(){c(),f(!0)}),200)}function m(e,n){if(n.preventDefault(),clearTimeout(v.current),d)return a(),void f(!1);a(),e!=o.LEFT?u():i()}function y(e){return{onMouseUp:function(n){return m(e,n)},onTouchEnd:function(n){return m(e,n)},onTouchStart:function(e){return p(e)},onMouseDown:function(e){return p(e)}}}return e.jsxs(n.Fragment,{children:[e.jsx("div",t({className:s.left},y(o.LEFT))),e.jsx("div",t({className:s.right},y(o.RIGHT)))]})}function i(){return n.useContext(r)}var c={wrapper:"ProgressBar-styles_wrapper__oqUCo",bar:"ProgressBar-styles_bar__x0O50"},a=0,l=.1;function d(r){var o,s,u,d,f,v=i(),p=v.defaultDuration,m=v.classNames,y=n.useRef(null),h=n.useRef(null),x=n.useState(!1),_=x[0],w=x[1];return n.useEffect((function(){!r.isPaused&&r.isActive&&r.isActive?w(!0):w(!1)}),[r.isActive,r.isPaused]),n.useEffect((function(){var e;y.current&&(r.hasStoryPassed?y.current.style.width="".concat(null===(e=null==h?void 0:h.current)||void 0===e?void 0:e.offsetWidth,"px"):y.current.style.width="0px")}),[r.hasStoryPassed,r.isActive]),o=function(e){var n;y.current&&h.current&&((a=Number((y.current.style.width||"1px").slice(0,y.current.style.width.length-2))||0)>h.current.offsetWidth?w(!1):(l=(null===(n=null==h?void 0:h.current)||void 0===n?void 0:n.offsetWidth)/((r.story.duration||p)/e),y.current.style.width="".concat(a+l,"px")))},s=_,u=n.useRef(),d=n.useRef(),f=n.useRef(o),n.useEffect((function(){f.current=o}),[o]),n.useEffect((function(){return!1!==s?(u.current=requestAnimationFrame((function e(n){if(null!=d.current){var t=n-d.current;f.current(t)}d.current=n,u.current=requestAnimationFrame(e)})),function(){cancelAnimationFrame(u.current),u.current=null,d.current=null}):function(){u.current&&(u.current=null),cancelAnimationFrame(u.current),d.current=null}}),[s]),e.jsx("div",t({className:"".concat(c.wrapper," ").concat((null==m?void 0:m.progressBarContainer)||""),ref:h},{children:e.jsx("div",{className:"".concat(c.bar," ").concat((null==m?void 0:m.progressBar)||""),ref:y})}))}var f={wrapper:"progress-styles_wrapper__qQPyW"};function v(n){var r=i(),o=r.stories,s=r.classNames;return e.jsx("div",t({className:"".concat(f.wrapper," ").concat((null==s?void 0:s.progressContainer)||""),style:{gridTemplateColumns:"repeat(".concat(o.length,",1fr)")}},{children:o.map((function(t){return e.jsx(d,{hasStoryPassed:t.index<n.activeStoryIndex,isActive:t.index===n.activeStoryIndex,story:t,isPaused:t.index===n.activeStoryIndex&&n.isPaused},t.index)}))}))}var p=Object.freeze({IMAGE:"image",VIDEO:"video",COMPONENT:"component"}),m={wrapper:"Story-styles_wrapper__oJP7j",header:"Story-styles_header__-rnWL"},y={image:"Image-styles_image__gnfW1"};function h(t){return n.useEffect((function(){t.onPause()}),[]),e.jsx("img",{className:y.image,src:t.story.url,alt:"story",onLoad:function(){setTimeout((function(){t.onResume()}),4)}})}var x,_={video:"Video-styles_video__BykuO",loaderWrapper:"Video-styles_loaderWrapper__TqVWk",loader:"Video-styles_loader__FxxSV",spin:"Video-styles_spin__ilbIB",soundIcon:"Video-styles_soundIcon__ZvYXE"};function w(n){return"off"===n.type?e.jsx("svg",t({xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"white"},{children:e.jsx("path",{d:"M3 9v6h-1v-6h1zm13-7l-9 5v2.288l7-3.889v13.202l-7-3.889v2.288l9 5v-20zm-11 5h-5v10h5v-10zm17.324 4.993l1.646-1.659-1.324-1.324-1.651 1.67-1.665-1.648-1.316 1.318 1.67 1.657-1.65 1.669 1.318 1.317 1.658-1.672 1.666 1.653 1.324-1.325-1.676-1.656z"})})):e.jsx("svg",t({xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"white"},{children:e.jsx("path",{d:"M22 0v24l-11-6v-2.278l9 4.909v-17.262l-9 4.91v-2.279l11-6zm-13 6v12h-7v-12h7zm-2 2h-3v8h3v-8z"})}))}var j="RSIsMute",g="undefined"==typeof window?{}:window;function S(r){var o,s=i().isPaused,u=n.useState("true"===(null===(o=null==g?void 0:g.localStorage)||void 0===o?void 0:o.getItem(j))),c=u[0],a=u[1],l=n.useState(!1),d=l[0],f=l[1],v=n.useRef(null);function p(e){var n;null===(n=null==g?void 0:g.localStorage)||void 0===n||n.setItem(j,String(e)),a(e)}return n.useEffect((function(){r.onPause(),f(!0)}),[]),n.useEffect((function(){v.current&&(!s||v.current.paused?v.current.play().catch((function(){var e;p(!0),null===(e=v.current)||void 0===e||e.play()})):v.current.pause())}),[s]),e.jsxs(n.Fragment,{children:[e.jsxs("video",t({className:_.video,ref:v,playsInline:!0,"webkit-playsinline":"",controls:!1,src:r.story.url,onLoadedData:function(){setTimeout((function(){r.onResume(),f(!1)}),4)},muted:c},{children:[e.jsx("source",{src:r.story.url,type:"video/mp4"}),e.jsx("source",{src:r.story.url,type:"video/webm"}),e.jsx("source",{src:r.story.url,type:"video/ogg"}),e.jsx("p",{children:"Video not supported"})]})),e.jsx("div",t({className:_.soundIcon,onClick:function(){return p(!c)}},{children:e.jsx(w,{type:c?"off":"on"})})),d&&e.jsx("div",t({className:_.loaderWrapper},{children:e.jsx("div",{className:_.loader})}))]})}null===(x=null==g?void 0:g.localStorage)||void 0===x||x.setItem(j,"true");var M={component:"CustomComponents-styles_component__w87Wx"};function E(n){return e.jsx("div",t({className:M.component},{children:e.jsx(n.story.component,{pause:n.onPause,resume:n.onResume,story:n.story,isPaused:n.isPaused})}))}var C={seeMoreWrapper:"SeeMore-styles_seeMoreWrapper__kwjif",defaultSeeMore:"SeeMore-styles_defaultSeeMore__-B1QW"};function N(n){return n.story.seeMore?e.jsx("button",t({type:"button",onClick:function(){n.onSeeMoreClick()},className:C.seeMoreWrapper},{children:function(){var r=n.story.seeMore,o=typeof r;if(["string","boolean"].includes(o)){var s="string"===o?r:"See More";return e.jsxs("div",t({className:C.defaultSeeMore},{children:[e.jsx("span",{children:"^"}),e.jsx("p",{children:s})]}))}return"function"===o?e.jsx(n.story.seeMore,{}):n.story.seeMore}()})):null}var P={seeMoreComponentWrapper:"SeeMoreComponent-styles_seeMoreComponentWrapper__0T6Ap",up:"SeeMoreComponent-styles_up__sRaEA",closeIcon:"SeeMoreComponent-styles_closeIcon__LMm3b"};function I(n){return n.story.seeMore&&n.story.seeMoreComponent?e.jsxs("div",t({className:P.seeMoreComponentWrapper},{children:[e.jsx("button",t({className:P.closeIcon,onClick:n.onClose},{children:"✕"})),"function"==typeof n.story.seeMoreComponent?e.jsx(n.story.seeMoreComponent,{}):n.story.seeMoreComponent]})):null}function R(r){var o=n.useState(!1),s=o[0],u=o[1],c=i().classNames;return n.useEffect((function(){u(!1)}),[r.story]),e.jsxs("div",t({className:"".concat(m.wrapper," ").concat((null==c?void 0:c.storyContainer)||"")},{children:[r.story.type===p.IMAGE?e.jsx(h,t({},r)):r.story.type===p.VIDEO?e.jsx(S,t({},r)):r.story.type===p.COMPONENT?e.jsx(E,t({},r)):null,r.story.header&&e.jsx("div",t({className:m.header},{children:"function"==typeof r.story.header?e.jsx(r.story.header,{}):r.story.header})),e.jsx(N,{onSeeMoreClick:function(){var e,n;r.onPause(),u(!0),null===(n=(e=r.story).onSeeMoreClick)||void 0===n||n.call(e,r.story.index)},story:r.story}),s&&e.jsx(I,{story:r.story,onClose:function(){r.onResume(),u(!1)}})]}))}var W="styles_main__-0FEu";function b(e){return void 0===e&&(e=4),Number(Math.random().toFixed(e))}module.exports=function(o){var s,i,c,a,l,d,f,p=o.stories,m=void 0===p?[]:p,y=o.width,h=void 0===y?"100%":y,x=o.height,_=void 0===x?"100%":x,w=o.onStoryChange,j=void 0===w?function(){}:w,g=o.currentIndex,S=void 0===g?0:g,M=o.defaultDuration,E=void 0===M?1e4:M,C=o.onAllStoriesEnd,N=void 0===C?function(){}:C,P=o.onStoriesStart,I=void 0===P?function(){}:P,T=o.classNames,A=void 0===T?{}:T,k=o.pauseStoryWhenInActiveWindow,D=void 0===k||k,O=n.useMemo((function(){return function(e,n){var r=0;return e.map((function(e,o){var s=e.duration||n,u=s+b();return u===r&&(u=s+b(6)),r=u,t(t({},e),{index:o,calculatedDuration:u})}))}(m,E)}),[m,E]),F=n.useState(),L=F[0],z=F[1],V=m.length-1,B=n.useState(!1),q=B[0],G=B[1],H=n.useRef(!1),Q=n.useRef(!1);function U(){H.current||(null==L?void 0:L.index)!==V||(N(),H.current=!0),(null==L?void 0:L.index)!==V&&z((function(e){if(!e)return O[0];var n=(null==e?void 0:e.index)+1;return O[n]}))}function J(){G(!0)}function X(){G(!1)}n.useEffect((function(){Q.current||(Q.current=!0,I())}),[I]),n.useEffect((function(){var e=O[S];e&&z(e)}),[S,m]),n.useEffect((function(){L&&j(L.index)}),[L]),i=function(){U()},c=null!==(s=null==L?void 0:L.calculatedDuration)&&void 0!==s?s:null,a=q,l=n.useRef(),d=n.useRef(c),f=n.useRef(Date.now()),n.useEffect((function(){l.current=i}),[i]),n.useEffect((function(){d.current=c}),[c]),n.useEffect((function(){if(null!==c&&!1===a){f.current=Date.now();var e=setTimeout((function(){l.current()}),d.current);return function(){clearTimeout(e)}}return function(){}}),[c,a]),n.useEffect((function(){a&&(d.current=d.current-(Date.now()-f.current))}),[a]),function(e){var t=n.useRef(e);n.useEffect((function(){t.current=e}),[e]),n.useEffect((function(){function e(){t.current(!0)}function n(){t.current(!1)}return window.addEventListener("focus",e),window.addEventListener("blur",n),function(){window.removeEventListener("focus",e),window.removeEventListener("blur",n)}}),[])}((function(e){D&&G(!e)}));var Y={stories:O,width:h,height:_,defaultDuration:E,isPaused:q,classNames:A};return L?e.jsx(r.Provider,t({value:Y},{children:e.jsxs("div",t({className:"".concat(W," ").concat(A.main||""),style:{width:h,height:_}},{children:[e.jsx(v,{activeStoryIndex:L.index,isPaused:q}),e.jsx(R,{onPause:J,onResume:X,story:L,isPaused:q},L.index),e.jsx(u,{onNextClick:U,onPrevClick:function(){0!==(null==L?void 0:L.index)&&z((function(e){if(!e)return O[0];var n=(null==e?void 0:e.index)-1;return O[n]}))},onPause:J,onResume:X})]}))})):null};
//# sourceMappingURL=index.js.map
