"use strict";var e=require("react"),t=require("axios"),i=require("sharetribe-flex-sdk"),o=require("prop-types"),n=require("react-video-recorder"),a=require("react-dom"),r=require("react-final-form"),l=require("react-intl");function s(e,t){var i={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(i[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var n=0;for(o=Object.getOwnPropertySymbols(e);n=arguments.length)?l=t[r]:(l=arguments[n],n+=1),o[r]=l,c(l)||(a-=1),r+=1}return a<=0?i.apply(this,o):p(a,b(e,o,i))}}"function"==typeof SuppressedError&&SuppressedError;var g=m((function(e,t){return 1===e?u(t):p(e,b(e,[],t))})),x=u((function(e){return g(e.length,(function(){var t=0,i=arguments[0],o=arguments[arguments.length-1],n=Array.prototype.slice.call(arguments,0);return n[0]=function(){var e=i.apply(this,function(e,t){var i;t=t||[];var o=(e=e||[]).length,n=t.length,a=[];for(i=0;i=0&&"[object Array]"===Object.prototype.toString.call(e)};function Q(e,t,i){return function(){if(0===arguments.length)return i();var o=Array.prototype.slice.call(arguments,0),n=o.pop();if(!I(n)){for(var a=0;a0&&(e.hasOwnProperty(0)&&e.hasOwnProperty(e.length-1)))))})),w=function(){function e(e){this.f=e}return e.prototype["@@transducer/init"]=function(){throw new Error("init not implemented on XWrap")},e.prototype["@@transducer/result"]=function(e){return e},e.prototype["@@transducer/step"]=function(e,t){return this.f(e,t)},e}();var R=m((function(e,t){return p(e.length,(function(){return e.apply(t,arguments)}))}));function F(e,t,i){for(var o=i.next();!o.done;){if((t=e["@@transducer/step"](t,o.value))&&t["@@transducer/reduced"]){t=t["@@transducer/value"];break}o=i.next()}return e["@@transducer/result"](t)}function C(e,t,i,o){return e["@@transducer/result"](i[o](R(e["@@transducer/step"],e),t))}var y="undefined"!=typeof Symbol?Symbol.iterator:"@@iterator";function N(e,t,i){if("function"==typeof e&&(e=function(e){return new w(e)}(e)),G(i))return function(e,t,i){for(var o=0,n=i.length;o=0;)Z(t=X[i],e)&&!D(o,t)&&(o[o.length]=t),i-=1;return o})):u((function(e){return Object(e)!==e?[]:Object.keys(e)})),S=m(Q(["fantasy-land/map","map"],f,(function(e,t){switch(Object.prototype.toString.call(t)){case"[object Function]":return g(t.length,(function(){return e.call(this,t.apply(this,arguments))}));case"[object Object]":return N((function(i,o){return i[o]=e(t[o]),i}),{},L(t));default:return function(e,t){for(var i=0,o=t.length,n=Array(o);i=0;){if(i[l]===e)return o[l]===t;l-=1}switch(r){case"Map":return e.size===t.size&&P(e.entries(),t.entries(),i.concat([e]),o.concat([t]));case"Set":return e.size===t.size&&P(e.values(),t.values(),i.concat([e]),o.concat([t]));case"Arguments":case"Array":case"Object":case"Boolean":case"Number":case"String":case"Date":case"Error":case"RegExp":case"Int8Array":case"Uint8Array":case"Uint8ClampedArray":case"Int16Array":case"Uint16Array":case"Int32Array":case"Uint32Array":case"Float32Array":case"Float64Array":case"ArrayBuffer":break;default:return!1}var s=L(e);if(s.length!==L(t).length)return!1;var d=i.concat([e]),c=o.concat([t]);for(l=s.length-1;l>=0;){var u=s[l];if(!Z(u,t)||!z(t[u],e[u],d,c))return!1;l-=1}return!0}var K=m((function(e,t){return z(e,t,[],[])}));var q=u((function(e){return null!=e&&"function"==typeof e["fantasy-land/empty"]?e["fantasy-land/empty"]():null!=e&&null!=e.constructor&&"function"==typeof e.constructor["fantasy-land/empty"]?e.constructor["fantasy-land/empty"]():null!=e&&"function"==typeof e.empty?e.empty():null!=e&&null!=e.constructor&&"function"==typeof e.constructor.empty?e.constructor.empty():I(e)?[]:v(e)?"":function(e){return"[object Object]"===Object.prototype.toString.call(e)}(e)?{}:W(e)?function(){return arguments}():void 0})),$=u((function(e){return null!=e&&K(e,q(e))})),ee="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function te(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var ie={exports:{}},oe=ie.exports=function(e){e||(e={}),"string"==typeof e&&(e={cookie:e}),void 0===e.cookie&&(e.cookie="");var t={get:function(t){for(var i=e.cookie.split(/;\s*/),o=0;o0?2===s.length?typeof s[1]==n?this[s[0]]=s[1].call(this,c):this[s[0]]=s[1]:3===s.length?typeof s[1]!==n||s[1].exec&&s[1].test?this[s[0]]=c?c.replace(s[1],s[2]):o:this[s[0]]=c?s[1].call(this,c,s[2]):o:4===s.length&&(this[s[0]]=c?s[3].call(this,c.replace(s[1],s[2])):o):this[s]=c||o;u+=2}},j=function(e,t){for(var i in t)if(typeof t[i]===r&&t[i].length>0){for(var n=0;n2&&(e[d]="iPad",e[u]=I),e},this.getEngine=function(){var e={};return e[c]=o,e[p]=o,H.call(e,Q,B.engine),e},this.getOS=function(){var e={};return e[c]=o,e[p]=o,H.call(e,Q,B.os),v&&!e[c]&&h&&"Unknown"!=h.platform&&(e[c]=h.platform.replace(/chrome os/i,k).replace(/macos/i,J)),e},this.getResult=function(){return{ua:this.getUA(),browser:this.getBrowser(),engine:this.getEngine(),os:this.getOS(),device:this.getDevice(),cpu:this.getCPU()}},this.getUA=function(){return Q},this.setUA=function(e){return Q=typeof e===l&&e.length>350?M(e,350):e,this},this.setUA(Q),this};z.VERSION="0.7.35",z.BROWSER=O([c,p,s]),z.CPU=O([b]),z.DEVICE=O([d,m,u,g,x,Q,I,h,B]),z.ENGINE=z.OS=O([c,p]),e.exports&&(t=e.exports=z),t.UAParser=z;var K=typeof i!==a&&(i.jQuery||i.Zepto);if(K&&!K.ua){var q=new z;K.ua=q.getResult(),K.ua.get=function(){return q.getUA()},K.ua.set=function(e){q.setUA(e);var t=q.getResult();for(var i in t)K.ua[i]=t[i]}}}("object"==typeof window?window:ee)}(le,le.exports);var se=le.exports;Object.defineProperty(re,"__esModule",{value:!0});var de,ce=e,ue=(de=ce)&&"object"==typeof de&&"default"in de?de.default:de,me=new se,pe=me.getBrowser();me.getCPU();var be=me.getDevice(),ge=me.getEngine(),xe=me.getOS(),Ie=me.getUA(),Qe=function(e){return e||(arguments.length>1&&void 0!==arguments[1]?arguments[1]:"none")},he=function(){return!("undefined"==typeof window||!window.navigator&&!navigator)&&(window.navigator||navigator)},Be=function(e){var t=he();return t&&t.platform&&(-1!==t.platform.indexOf(e)||"MacIntel"===t.platform&&t.maxTouchPoints>1&&!window.MSStream)};function ve(e){return ve="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},ve(e)}function Ge(e,t){for(var i=0;i=0||(n[i]=e[i]);return n}(e,t);if(Object.getOwnPropertySymbols){var a=Object.getOwnPropertySymbols(e);for(o=0;o=0||Object.prototype.propertyIsEnumerable.call(e,i)&&(n[i]=e[i])}return n}function Ae(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}var fe="mobile",Ze="tablet",Ue="smarttv",We="console",Ee="wearable",Xe=void 0,Ve={Chrome:"Chrome",Firefox:"Firefox",Opera:"Opera",Yandex:"Yandex",Safari:"Safari",InternetExplorer:"Internet Explorer",Edge:"Edge",Chromium:"Chromium",Ie:"IE",MobileSafari:"Mobile Safari",EdgeChromium:"Edge Chromium",MIUI:"MIUI Browser",SamsungBrowser:"Samsung Browser"},De={IOS:"iOS",Android:"Android",WindowsPhone:"Windows Phone",Windows:"Windows",MAC_OS:"Mac OS"},Le={isMobile:!1,isTablet:!1,isBrowser:!1,isSmartTV:!1,isConsole:!1,isWearable:!1},Se=function(e,t,i,o){return function(e){for(var t=1;t1)&&!window.MSStream,Rt=Me(),Ft=Be("iPhone"),Ct=Be("iPod"),yt=function(){var e=he(),t=e&&e.userAgent&&e.userAgent.toLowerCase();return"string"==typeof t&&/electron/.test(t)}(),Nt=Oe(),At=_e()&&!Oe(),ft=xe.name===De.Windows,Zt=xe.name===De.MAC_OS,Ut=pe.name===Ve.MIUI,Wt=pe.name===Ve.SamsungBrowser;re.AndroidView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return it?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.BrowserTypes=Ve,re.BrowserView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return et?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.ConsoleView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return je?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.CustomView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=e.condition,r=Ne(e,["renderWithFragment","children","viewClassName","style","condition"]);return a?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},r),i):null},re.IEView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return dt?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.IOSView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return nt?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.MobileOnlyView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return qe?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.MobileView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return Ke?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.OsTypes=De,re.SmartTVView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return He?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.TabletView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return $e?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.WearableView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return Te?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.WinPhoneView=function(e){var t=e.renderWithFragment,i=e.children,o=e.viewClassName,n=e.style,a=Ne(e,["renderWithFragment","children","viewClassName","style"]);return ot?t?ue.createElement(ce.Fragment,null,i):ue.createElement("div",Re({className:o,style:n},a),i):null},re.browserName=bt,re.browserVersion=pt,re.deviceDetect=function(){var e=ke.isBrowser,t=ke.isMobile,i=ke.isTablet,o=ke.isSmartTV,n=ke.isConsole,a=ke.isWearable;return e?function(e,t,i,o,n){return{isBrowser:e,browserMajorVersion:Qe(t.major),browserFullVersion:Qe(t.version),browserName:Qe(t.name),engineName:Qe(i.name),engineVersion:Qe(i.version),osName:Qe(o.name),osVersion:Qe(o.version),userAgent:Qe(n)}}(e,pe,ge,xe,Ie):o?function(e,t,i,o){return{isSmartTV:e,engineName:Qe(t.name),engineVersion:Qe(t.version),osName:Qe(i.name),osVersion:Qe(i.version),userAgent:Qe(o)}}(o,ge,xe,Ie):n?function(e,t,i,o){return{isConsole:e,engineName:Qe(t.name),engineVersion:Qe(t.version),osName:Qe(i.name),osVersion:Qe(i.version),userAgent:Qe(o)}}(n,ge,xe,Ie):t||i?Se(ke,be,xe,Ie):a?function(e,t,i,o){return{isWearable:e,engineName:Qe(t.name),engineVersion:Qe(t.version),osName:Qe(i.name),osVersion:Qe(i.version),userAgent:Qe(o)}}(a,ge,xe,Ie):void 0},re.deviceType=Gt,re.engineName=It,re.engineVersion=Qt,re.fullBrowserVersion=mt,re.getUA=ht,re.isAndroid=it,re.isBrowser=et,re.isChrome=at,re.isChromium=ze,re.isConsole=je,re.isDesktop=tt,re.isEdge=Bt,re.isEdgeChromium=Nt,re.isElectron=yt,re.isFirefox=rt,re.isIE=dt,re.isIOS=nt,re.isIOS13=wt,re.isIPad13=Rt,re.isIPhone13=Ft,re.isIPod13=Ct,re.isLegacyEdge=At,re.isMIUI=Ut,re.isMacOs=Zt;var Et=re.isMobile=Ke;re.isMobileOnly=qe,re.isMobileSafari=Pe,re.isOpera=st,re.isSafari=lt,re.isSamsungBrowser=Wt,re.isSmartTV=He,re.isTablet=$e,re.isWearable=Te,re.isWinPhone=ot,re.isWindows=ft,re.isYandex=vt,re.mobileModel=xt,re.mobileVendor=gt,re.osName=ut,re.osVersion=ct,re.withOrientationChange=function(e){return function(t){function i(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,i),(t=function(e,t){return!t||"object"!=typeof t&&"function"!=typeof t?Ae(e):t}(this,Ce(i).call(this,e))).isEventListenerAdded=!1,t.handleOrientationChange=t.handleOrientationChange.bind(Ae(t)),t.onOrientationChange=t.onOrientationChange.bind(Ae(t)),t.onPageLoad=t.onPageLoad.bind(Ae(t)),t.state={isLandscape:!1,isPortrait:!1},t}var o,n,a;return function(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),t&&ye(e,t)}(i,ue.Component),o=i,(n=[{key:"handleOrientationChange",value:function(){this.isEventListenerAdded||(this.isEventListenerAdded=!0);var e=window.innerWidth>window.innerHeight?90:0;this.setState({isPortrait:0===e,isLandscape:90===e})}},{key:"onOrientationChange",value:function(){this.handleOrientationChange()}},{key:"onPageLoad",value:function(){this.handleOrientationChange()}},{key:"componentDidMount",value:function(){void 0!==("undefined"==typeof window?"undefined":ve(window))&&Ke&&(this.isEventListenerAdded?window.removeEventListener("load",this.onPageLoad,!1):(this.handleOrientationChange(),window.addEventListener("load",this.onPageLoad,!1)),window.addEventListener("resize",this.onOrientationChange,!1))}},{key:"componentWillUnmount",value:function(){window.removeEventListener("resize",this.onOrientationChange,!1)}},{key:"render",value:function(){return ue.createElement(e,Re({},this.props,{isLandscape:this.state.isLandscape,isPortrait:this.state.isPortrait}))}}])&&Ge(o.prototype,n),a&&Ge(o,a),i}()};const Xt=Et?"video/mp4":"video/webm",Vt=(o,n,a,r,l)=>{const[s,c]=e.useState(!1),[u,m]=e.useState(null),[p,b]=e.useState(null),[g,x]=e.useState(null),[I,Q]=e.useState(null),[h,B]=e.useState(null),[v,G]=e.useState(null),[w,R]=e.useState(null),[F,C]=e.useState(!1),[y,N]=e.useState(!0),[A,f]=e.useState(!0),[Z,U]=e.useState(!1),W=Y(["reviewProPhotoUrl"],l),E=Y(["reviewProVideoUrl"],l);e.useEffect((()=>{r&&!I&&Q(r)}),[r]),e.useEffect((()=>{(W||E)&&(N(!W),f(!E))}),[W,E]);const X=e=>d(void 0,void 0,void 0,(function*(){const i=`${atob("aHR0cHM6Ly91cy1jZW50cmFsMS1yZXZpZXdwcm8tYnktY2FsaXNjYWxlLWFnZW5jeS5jbG91ZGZ1bmN0aW9ucy5uZXQvdjE=")}/booking/${a}/file`;try{const o=yield t({method:"GET",url:i,headers:{authorization:`Bearer ${I}`,"content-type":"application/x-www-form-urlencoded","file-content-type":e}}),n=Y(["data","urlToUpload"],o),a=Y(["data","urlToRead"],o),r=Y(["data","metadata"],o);return a||n?(console.log("response",null==g?void 0:g.type,a,n,o,null==o?void 0:o.data),{urlToUpload:n,urlToRead:a,metadata:r}):null}catch(e){return console.error(e),null}})),V=e=>d(void 0,void 0,void 0,(function*(){const t=y?yield S(e):k(e,W,"photo");n(t)})),D=()=>d(void 0,void 0,void 0,(function*(){try{const t=i.createInstance({clientId:process.env.REACT_APP_SHARETRIBE_SDK_CLIENT_ID,secure:"true"===process.env.REACT_APP_SHARETRIBE_USING_SSL});yield t.marketplace.show(),yield(e=800,new Promise((t=>setTimeout(t,e))));const o=Y(["access_token"],Jt());Q(o)}catch(e){}var e})),L=e=>d(void 0,void 0,void 0,(function*(){c(!0),m(e),yield D(),d(void 0,void 0,void 0,(function*(){try{const e=yield X(Xt);if(!e)return;const{urlToUpload:t,urlToRead:i,metadata:o}=e;B(t),G(i),R(o)}catch(e){console.error(e)}}))})),S=e=>d(void 0,void 0,void 0,(function*(){if(!g)return e;try{U(!0);const i=yield X(g.type);if(U(!1),!i)return e;const{urlToUpload:o,urlToRead:n,metadata:a={}}=i;return U(!0),yield t({method:"PUT",url:o,headers:Object.assign({"Access-Control-Allow-Origin":"*","Content-Type":g.type},a),data:g}),U(!1),k(e,n,"photo")}catch(t){return e}})),k=(e,t,i)=>{if(!e)return e;const{reviewContent:o}=e;return(p||g)&&t?o?Object.assign(Object.assign({},e),{reviewContent:o+"\n\n\n"+`<${i}>${t}`}):Object.assign(Object.assign({},e),{reviewContent:t}):e},J=()=>d(void 0,void 0,void 0,(function*(){if(console.log("handleSubmitVideo",p,u,v,"video"),!p)return V(u);C(!0);const e=new FormData,i="video.webm",o=new File([p],i);e.append("file",o,i);const n=yield t({method:"PUT",url:h,headers:Object.assign({"Access-Control-Allow-Origin":"*","Content-Type":Xt},null!=w?w:{}),data:p});console.log("response",w,n,null==n?void 0:n.data),C(!1),V(k(u,v,"video"))}));return{handleResetReviewView:()=>{c(!1)},handleSubmit:e=>d(void 0,void 0,void 0,(function*(){try{if(o)return V(e);if(!s&&A)return L(e);if(yield D(),!A)return V(k(e,E,"video"));J()}catch(e){U(!1),C(!1)}})),handleSetVideo:e=>d(void 0,void 0,void 0,(function*(){b(e)})),handleSetImage:e=>d(void 0,void 0,void 0,(function*(){x(e)})),image:g,isUploadingVideo:F,isUploadingPhoto:Z,hasSetVideo:!!p,isMakingVideo:s,values:u,canShowPhotoField:y,canShowVideoField:A}},Dt=e.createContext({handleSubmit:Function.prototype,handleSetVideo:Function.prototype,handleSetImage:Function.prototype,image:null,isUploadingVideo:!1,isUploadingPhoto:!1,hasSetVideo:!1,isMakingVideo:!1,values:null,canShowPhotoField:!0,canShowVideoField:!0}),Lt=e=>{const t=`https://${(e=>{if(!e)return"";const t=e.match(/https:\/\/storage.googleapis.com\/reviewpro.(.*?)\//);return t?`reviewpro-${t[1]}`:""})(e)}.b-cdn.net/`;return null==e?void 0:e.replace(/https:\/\/storage.googleapis.com\/reviewpro-.*?\//g,t)},St=e=>{if(!e)return e;const t=e.match(/