PluginProbe
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler / 1.6.5
FluentCart A New Era of eCommerce – Faster, Lighter, and Simpler v1.6.5
1.6.5 1.6.4 1.6.3 1.6.2 1.6.1 1.6.0 1.5.4 1.5.5 1.5.3 1.5.2 1.5.1 1.5.0 1.4.2 1.4.1 1.4.0 1.3.28 1.3.27 1.3.26 1.3.25 1.3.23 1.3.22 1.3.21 1.3.20 1.3.19 trunk All 48 releases
← All changes | assets/chunks/FluentPlayerVideoTab.js +1 -1 1.6.4 → 1.6.5 View file →
@@ -1 +1 @@
1 -import{l as b,h as V,v as ae,K as Se,r as A,e as f,o as n,d as u,c as I,t as r,u as i,w as g,f as F,F as x,b as N,a as h,g as fe,n as Ae}from"./vue.esm-bundler.js?ver=1.6.4";import{R as K}from"./Rest.js?ver=1.6.4";import{n as T}from"./Notify.js?ver=1.6.4";import{t}from"./Translator.js?ver=1.6.4";import{_ as W}from"./DynamicIcon.js?ver=1.6.4";import{n as Ie,c as le,p as pe,l as xe,a as Me,r as Ee,d as Re,M as me}from"../fluent-player-gallery.js";import{E as Ue}from"./index.js?ver=1.6.4";import"./Str.js?ver=1.6.4";import"./Arr.js?ver=1.6.4";import"./preload-helper.js?ver=1.6.4";import"./galleryTabs.js?ver=1.6.4";function Ne(d){const R=Number((d==null?void 0:d.status_code)??(d==null?void 0:d.status));return Number.isFinite(R)?R:0}function H(d,R=""){var k,D,M;const y=(d==null?void 0:d.message)||((k=d==null?void 0:d.data)==null?void 0:k.message)||((D=d==null?void 0:d.errors)==null?void 0:D.message);if(typeof y=="string"&&y.trim())return y;const _=((M=d==null?void 0:d.data)==null?void 0:M.errors)||(d==null?void 0:d.errors);if(_&&typeof _=="object")for(const C of Object.keys(_)){const L=Array.isArray(_[C])?_[C][0]:typeof _[C]=="object"&&_[C]?Object.values(_[C])[0]:_[C];if(typeof L=="string"&&L.trim())return L}return R}const Le={class:"fct-fp-video","data-fct-fp-video-tab":""},Oe={key:0,class:"fct-fp-video__block","data-fct-fp-video-inactive":""},Be={class:"fct-fp-video__notice"},De={key:0,class:"fct-fp-video__notice","data-fct-fp-video-no-install-permission":""},$e={key:0,class:"fct-fp-video__notice","data-fct-fp-video-no-permission":""},je={class:"fct-fp-video__section"},ze={class:"fct-fp-video__block","data-fct-fp-video-create":""},qe={class:"fct-fp-video__section-title",for:"fct-fp-video-src"},Ye={class:"fct-fp-video__source"},Ke={key:0,class:"fct-fp-video__hint"},We={key:1,class:"fct-fp-video__hint","data-fct-fp-video-detected":""},He={key:2,class:"fct-fp-video__hint"},Je={key:3,class:"fct-fp-video__hint"},Xe={class:"fct-fp-video__divider",role:"separator"},Ge={class:"fct-fp-video__block","data-fct-fp-video-existing":""},Qe={class:"fct-fp-video__section-title"},Ze={class:"fct-fp-video__source"},et={key:0,class:"fct-fp-video__list","data-fct-fp-video-list":""},tt={class:"fct-fp-video__section-title"},at=["data-fct-fp-video-id","aria-busy","aria-label"],lt={class:"fct-fp-video__card-thumb"},it=["src","alt"],ot={class:"fct-fp-video__card-play","aria-hidden":"true"},st={class:"fct-fp-video__card-body"},nt={class:"fct-fp-video__card-lines"},dt={class:"fct-fp-video__card-title","data-fct-fp-video-title":""},ct={class:"fct-fp-video__card-meta"},rt={class:"fct-fp-video__id"},ut={key:0,class:"fct-fp-video__provider"},vt={class:"fct-fp-video__card-actions"},ft=["href","aria-label"],pt=["aria-label","onClick"],St={__name:"FluentPlayerVideoTab",props:{modelValue:{type:Object,default:()=>({media_ids:[]})},config:{type:Object,default:()=>({})}},emits:["update:modelValue","busy"],setup(d,{emit:R}){const y=d,_=R,k=b(()=>{var e;return((e=y.config)==null?void 0:e.restUrl)||""}),D=b(()=>{var e;return!!((e=y.config)!=null&&e.active)}),M=b(()=>{var e;return!!((e=y.config)!=null&&e.installed)}),C=b(()=>{var e;return!!((e=y.config)!=null&&e.canInstall)}),L=b(()=>{var e;return!!((e=y.config)!=null&&e.canAuthor)}),$=V(!1),j=V(!1),_e=()=>Ue.confirm(t("Save the product first if you have unsaved changes — reloading discards them."),t("Reload this page?"),{confirmButtonText:t("Reload Page"),cancelButtonText:t("Cancel"),type:"warning"}).then(()=>{window.location.reload()}).catch(()=>{}),he=()=>{$.value=!0,K.post("integration/feed/install-plugin",{addon:"fluent-player"}).then(e=>{const a=M.value?t("FluentPlayer activated successfully."):t("FluentPlayer installed successfully.");T.success((e==null?void 0:e.message)||a),j.value=!0}).catch(e=>{const a=M.value?t("Could not activate FluentPlayer."):t("Could not install FluentPlayer.");T.error(H(e,a))}).finally(()=>{$.value=!1})},z=b(()=>Ie(y.modelValue)),O=b(()=>z.value.media_ids),ie=e=>{const a=Number(e)||0;if(a){if(O.value.includes(a)){T.info(t("That video is already attached to this product."));return}if(O.value.length>=me){T.info(t("A product can have at most %1$s videos.",me));return}_("update:modelValue",{media_ids:[...z.value.media_ids,a],positions:[...z.value.positions,null]})}},ye=e=>{_("update:modelValue",Ee(z.value,e))},ge=e=>Me(e,t("Untitled video")),oe=e=>({id:e,title:t("Video #%1$s (unavailable)",e),poster:"",provider:"",missing:!0}),S=V({});ae(O,e=>{const a=e.filter(v=>!S.value[v]);if(!a.length||!k.value)return;const p={};a.forEach(v=>{p[v]={id:v,title:t("Loading..."),poster:"",provider:"",loading:!0}}),S.value={...S.value,...p},xe(k.value,a,t("Untitled video")).then(v=>{const m={...S.value};a.forEach(o=>{m[o]=v[o]&&!v[o].missing?v[o]:oe(o)}),S.value=m}).catch(v=>{const m={...S.value};a.forEach(o=>{m[o]=oe(o)}),S.value=m,T.error(H(v,t("Could not load the FluentPlayer videos.")))})},{immediate:!0});const J=b(()=>O.value.map(e=>S.value[e]||{id:e,title:t("Video #%1$s",e),poster:"",provider:""})),se=e=>{var a;return(a=y.config)!=null&&a.editUrlBase?y.config.editUrlBase+e:""},X=V([]),G=V(!1),U=V(null);let Q=null;const ne=e=>{k.value&&(clearTimeout(Q),Q=setTimeout(()=>{G.value=!0,K.get("media/search",{q:e||"",limit:20,status:"publish,private"},k.value).then(a=>{const p=Array.isArray(a)?a:(a==null?void 0:a.data)||(a==null?void 0:a.medias)||[];X.value=p.map(ge).filter(v=>v.id>0)}).catch(a=>{T.error(H(a,t("Could not search FluentPlayer videos.")))}).finally(()=>{G.value=!1})},250))},be=b(()=>X.value.filter(e=>!O.value.includes(e.id))),ke=()=>{U.value&&(ie(U.value),U.value=null)},de=()=>({src:"",attachment_id:0,attachmentTitle:"",provider:"",viewType:"video",metaTitle:"",metaPoster:"",metaProvider:"",metaViewType:"",metaFailed:!1}),we=["youtube","vimeo","external","wordpress"],Te=e=>{const a=String((e==null?void 0:e.provider)||(e==null?void 0:e.provider_name)||"").toLowerCase();return we.includes(a)?a:""},l=V(de()),E=V(!1);ae(E,e=>_("busy",e));const Z=V(!1);let ee=null,te=0,q=null;const Pe=e=>{if(!le(e)||!k.value)return;const p=e.trim(),v=++te,m=()=>v===te&&l.value.src.trim()===p;Z.value=!0,q=K.get("media/metadata",{url:p},k.value).then(o=>{var P;if(!m())return;const c=(o==null?void 0:o.metaData)||((P=o==null?void 0:o.data)==null?void 0:P.metaData)||null;l.value.metaTitle=(c==null?void 0:c.title)||"",l.value.metaPoster=(c==null?void 0:c.thumbnail_url)||"",l.value.metaProvider=Te(c),l.value.metaViewType=["video","audio"].includes(c==null?void 0:c.media_type)?c.media_type:""}).catch(()=>{m()&&(l.value.metaFailed=!0)}).finally(()=>{v===te&&(Z.value=!1,q=null)})};ae(()=>l.value.src,e=>{clearTimeout(ee),l.value.metaTitle="",l.value.metaPoster="",l.value.metaProvider="",l.value.metaViewType="",l.value.metaFailed=!1,l.value.provider!=="wordpress"&&le(e)&&(ee=setTimeout(()=>Pe(e),400))});const Y=b(()=>l.value.provider==="wordpress"?{provider:"wordpress",viewType:l.value.viewType}:le(l.value.src)),ce=b(()=>Y.value?pe(Y.value.provider):""),re=b(()=>!!Y.value&&!E.value),Ve=()=>{l.value.provider==="wordpress"&&(l.value.provider="",l.value.attachment_id=0,l.value.attachmentTitle="")};let w=null;const Fe=()=>{var e;if(typeof((e=window.wp)==null?void 0:e.media)!="function"){T.error(t("The WordPress media library is not available on this screen."));return}w||(w=window.wp.media({title:t("Select or upload a video"),button:{text:t("Use this video")},library:{type:"video"},multiple:!1}),w.on("open",()=>{try{w.content.mode("browse")}catch{}}),w.on("select",()=>{var p;const a=(p=w.state().get("selection").first())==null?void 0:p.toJSON();a!=null&&a.url&&(l.value.src=a.url,l.value.attachment_id=Number(a.id)||0,l.value.attachmentTitle=a.title||"",l.value.provider="wordpress",l.value.viewType="video")})),w.open()};Se(()=>{clearTimeout(Q),clearTimeout(ee),E.value&&_("busy",!1),w&&typeof w.detach=="function"&&w.detach(),w=null});const ue=()=>{var m;const e=Y.value;if(!e){E.value=!1;return}const a=e.provider==="wordpress"?"wordpress":l.value.metaProvider||e.provider,p=e.provider==="wordpress"?e.viewType:l.value.metaViewType||e.viewType,v={title:Re({metaTitle:l.value.metaTitle,attachmentTitle:l.value.attachmentTitle,url:l.value.src},t("Untitled Media")),post_status:"publish",src:l.value.src.trim(),provider:a,viewType:p,posterSrc:l.value.metaPoster||"",preset_slug:((m=y.config)==null?void 0:m.defaultPresetSlug)||"course",playsInline:!0,mutedAutoplay:!1,autoplay:!1,loadStrategy:"visible",preload:"metadata",aspectRatio:"default"};a==="wordpress"&&l.value.attachment_id&&(v.attachment_id=l.value.attachment_id),K.post("media",{settings:v,tags:[]},k.value).then(o=>{var B;const c=(o==null?void 0:o.media)||((B=o==null?void 0:o.data)==null?void 0:B.media)||null,P=Number((c==null?void 0:c.ID)||(c==null?void 0:c.id))||0;if(!P){T.error(t("FluentPlayer did not return the new video id."));return}T.success((o==null?void 0:o.message)||t("Video created in FluentPlayer.")),l.value=de(),ie(P)}).catch(o=>{const c=Ne(o);if(c===403||c===401){T.error(t("Your account is not allowed to create FluentPlayer videos."));return}T.error(H(o,t("Could not create the video in FluentPlayer.")))}).finally(()=>{E.value=!1})},Ce=()=>{!re.value||!k.value||(E.value=!0,q?q.finally(ue):ue())};return(e,a)=>{const p=A("el-button"),v=A("el-input"),m=A("el-tooltip"),o=A("el-option"),c=A("el-select"),P=A("el-skeleton-item"),B=A("el-skeleton"),ve=A("el-tag");return n(),f("div",Le,[D.value?(n(),f(x,{key:1},[L.value?(n(),f(x,{key:1},[u("div",je,[u("div",ze,[u("label",qe,r(J.value.length?i(t)("Add another video"):i(t)("Add a video")),1),u("div",Ye,[h(v,{id:"fct-fp-video-src",modelValue:l.value.src,"onUpdate:modelValue":a[0]||(a[0]=s=>l.value.src=s),placeholder:i(t)("Paste a YouTube, Vimeo or direct video URL"),onInput:Ve},null,8,["modelValue","placeholder"]),h(m,{content:i(t)("Choose from the Media Library"),placement:"top"},{default:g(()=>[h(p,{class:"fct-fp-video__icon-only","data-fct-fp-video-library":"","aria-label":i(t)("Choose from the Media Library"),onClick:Fe},{default:g(()=>[h(W,{name:"VideoAdd"})]),_:1},8,["aria-label"])]),_:1},8,["content"]),h(p,{type:"primary",loading:E.value,disabled:!re.value,"data-fct-fp-video-create-btn":"",onClick:Ce},{default:g(()=>[F(r(i(t)("Add Video")),1)]),_:1},8,["loading","disabled"])]),Z.value?(n(),f("span",Ke,r(i(t)("Reading the video details...")),1)):ce.value?(n(),f("span",We,[F(r(i(t)("Detected: %1$s",ce.value))+" ",1),l.value.metaTitle?(n(),f(x,{key:0},[F(" — "+r(l.value.metaTitle),1)],64)):l.value.metaFailed?(n(),f(x,{key:1},[F(" — "+r(i(t)("details could not be read; the file name will be used as the title")),1)],64)):N("",!0)])):l.value.src?(n(),f("span",He,r(i(t)("Enter a full URL starting with http:// or https://")),1)):(n(),f("span",Je,r(i(t)("Title and poster are sourced from YouTube, Vimeo, audio or HLS file or direct video")),1))]),u("div",Xe,[u("span",null,r(i(t)("OR")),1)]),u("div",Ge,[u("span",Qe,r(i(t)("Pick an existing FluentPlayer video")),1),u("div",Ze,[h(c,{modelValue:U.value,"onUpdate:modelValue":a[1]||(a[1]=s=>U.value=s),filterable:"",remote:"",clearable:"","remote-method":ne,loading:G.value,placeholder:i(t)("Search videos by title or ID..."),class:"fct-fp-video__select",onVisibleChange:a[2]||(a[2]=s=>s&&!X.value.length&&ne(""))},{default:g(()=>[(n(!0),f(x,null,fe(be.value,s=>(n(),I(o,{key:s.id,label:`#${s.id} — ${s.title}`,value:s.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue","loading","placeholder"]),h(p,{type:"primary",disabled:!U.value,"data-fct-fp-video-use-existing":"",onClick:ke},{default:g(()=>[F(r(i(t)("Use Video")),1)]),_:1},8,["disabled"])])])]),J.value.length?(n(),f("div",et,[u("h4",tt,r(i(t)("Videos")),1),(n(!0),f(x,null,fe(J.value,s=>(n(),f("div",{key:s.id,class:Ae(["fct-fp-video__card",{"is-loading":s.loading}]),"data-fct-fp-video-selected":"","data-fct-fp-video-id":s.id,"aria-busy":s.loading?"true":null,"aria-label":s.loading?i(t)("Loading..."):null},[u("div",lt,[s.loading?(n(),I(B,{key:0,animated:""},{template:g(()=>[h(P,{variant:"image",class:"fct-fp-video__card-thumb-skeleton"})]),_:1})):(n(),f(x,{key:1},[s.poster?(n(),f("img",{key:0,src:s.poster,alt:s.title||""},null,8,it)):N("",!0),u("div",ot,[h(W,{name:"PlayCircle"})])],64))]),u("div",st,[s.loading?(n(),I(B,{key:0,animated:"",rows:0,"data-fct-fp-video-loading":""},{template:g(()=>[u("div",nt,[h(P,{variant:"h3",class:"fct-fp-video__card-title-skeleton"}),h(P,{variant:"text",class:"fct-fp-video__card-meta-skeleton"})])]),_:1})):(n(),f(x,{key:1},[u("span",dt,r(s.title),1),u("span",ct,[u("span",rt,"#"+r(s.id),1),s.provider?(n(),f("span",ut,r(i(pe)(s.provider)),1)):N("",!0),s.missing?(n(),I(ve,{key:1,type:"danger",size:"small","data-fct-fp-video-missing":""},{default:g(()=>[F(r(i(t)("Not found")),1)]),_:1})):s.trashed?(n(),I(ve,{key:2,type:"warning",size:"small","data-fct-fp-video-trashed":""},{default:g(()=>[F(r(i(t)("In trash")),1)]),_:1})):N("",!0)])],64))]),u("div",vt,[se(s.id)?(n(),I(m,{key:0,content:i(t)("Edit in FluentPlayer"),placement:"top"},{default:g(()=>[u("a",{href:se(s.id),target:"_blank",rel:"noopener",class:"fct-fp-video__icon-btn","data-fct-fp-video-edit":"","aria-label":i(t)("Edit in FluentPlayer")},[h(W,{name:"Edit"})],8,ft)]),_:2},1032,["content"])):N("",!0),h(m,{content:i(t)("Remove video"),placement:"top"},{default:g(()=>[u("button",{type:"button",class:"fct-fp-video__icon-btn fct-fp-video__icon-btn--danger","data-fct-fp-video-remove":"","aria-label":i(t)("Remove video"),onClick:_t=>ye(s.id)},[h(W,{name:"Delete"})],8,pt)]),_:2},1032,["content"])])],10,at))),128))])):N("",!0)],64)):(n(),f("p",$e,r(i(t)("Your account cannot manage FluentPlayer videos. Ask an administrator to grant the FluentPlayer authoring capability.")),1))],64)):(n(),f("div",Oe,[u("p",Be,r(j.value?i(t)("FluentPlayer is ready. Save any changes to this product, then reload the page to add videos."):i(t)("FluentPlayer is required to add videos to this product.")),1),!j.value&&!C.value?(n(),f("p",De,r(M.value?i(t)("Ask an administrator to activate it for you."):i(t)("Ask an administrator to install it for you.")),1)):j.value?(n(),I(p,{key:1,type:"primary","data-fct-fp-video-reload":"",onClick:_e},{default:g(()=>[F(r(i(t)("Reload Page")),1)]),_:1})):(n(),I(p,{key:2,type:"primary",loading:$.value,disabled:$.value,"data-fct-fp-video-install":"",onClick:he},{default:g(()=>[F(r(M.value?i(t)("Activate FluentPlayer"):i(t)("Install & Activate FluentPlayer")),1)]),_:1},8,["loading","disabled"]))]))])}}};export{St as default};
1 +import{l as b,h as V,v as ae,M as Se,r as A,e as f,o as n,d as u,c as I,t as r,u as i,w as g,f as F,F as M,b as N,a as h,g as fe,n as Ae}from"./vue.esm-bundler.js?ver=1.6.5";import{R as W}from"./Rest.js?ver=1.6.5";import{n as T}from"./Notify.js?ver=1.6.5";import{t}from"./Translator.js?ver=1.6.5";import{_ as H}from"./DynamicIcon.js?ver=1.6.5";import{n as Ie,c as le,p as pe,l as Me,a as xe,r as Ee,d as Re,M as me}from"../fluent-player-gallery.js";import{E as Ue}from"./index.js?ver=1.6.5";import"./Str.js?ver=1.6.5";import"./Arr.js?ver=1.6.5";import"./preload-helper.js?ver=1.6.5";import"./galleryTabs.js?ver=1.6.5";function Ne(d){const R=Number((d==null?void 0:d.status_code)??(d==null?void 0:d.status));return Number.isFinite(R)?R:0}function J(d,R=""){var k,D,x;const y=(d==null?void 0:d.message)||((k=d==null?void 0:d.data)==null?void 0:k.message)||((D=d==null?void 0:d.errors)==null?void 0:D.message);if(typeof y=="string"&&y.trim())return y;const _=((x=d==null?void 0:d.data)==null?void 0:x.errors)||(d==null?void 0:d.errors);if(_&&typeof _=="object")for(const C of Object.keys(_)){const L=Array.isArray(_[C])?_[C][0]:typeof _[C]=="object"&&_[C]?Object.values(_[C])[0]:_[C];if(typeof L=="string"&&L.trim())return L}return R}const Le={class:"fct-fp-video","data-fct-fp-video-tab":""},Oe={key:0,class:"fct-fp-video__block","data-fct-fp-video-inactive":""},Be={class:"fct-fp-video__notice"},De={key:0,class:"fct-fp-video__notice","data-fct-fp-video-no-install-permission":""},$e={key:0,class:"fct-fp-video__notice","data-fct-fp-video-no-permission":""},je={class:"fct-fp-video__section"},ze={class:"fct-fp-video__block","data-fct-fp-video-create":""},qe={class:"fct-fp-video__section-title",for:"fct-fp-video-src"},Ye={class:"fct-fp-video__source"},We={key:0,class:"fct-fp-video__hint"},He={key:1,class:"fct-fp-video__hint","data-fct-fp-video-detected":""},Je={key:2,class:"fct-fp-video__hint"},Ke={key:3,class:"fct-fp-video__hint"},Xe={class:"fct-fp-video__divider",role:"separator"},Ge={class:"fct-fp-video__block","data-fct-fp-video-existing":""},Qe={class:"fct-fp-video__section-title"},Ze={class:"fct-fp-video__source"},et={key:0,class:"fct-fp-video__list","data-fct-fp-video-list":""},tt={class:"fct-fp-video__section-title"},at=["data-fct-fp-video-id","aria-busy","aria-label"],lt={class:"fct-fp-video__card-thumb"},it=["src","alt"],ot={class:"fct-fp-video__card-play","aria-hidden":"true"},st={class:"fct-fp-video__card-body"},nt={class:"fct-fp-video__card-lines"},dt={class:"fct-fp-video__card-title","data-fct-fp-video-title":""},ct={class:"fct-fp-video__card-meta"},rt={class:"fct-fp-video__id"},ut={key:0,class:"fct-fp-video__provider"},vt={class:"fct-fp-video__card-actions"},ft=["href","aria-label"],pt=["aria-label","onClick"],St={__name:"FluentPlayerVideoTab",props:{modelValue:{type:Object,default:()=>({media_ids:[]})},config:{type:Object,default:()=>({})}},emits:["update:modelValue","busy"],setup(d,{emit:R}){const y=d,_=R,k=b(()=>{var e;return((e=y.config)==null?void 0:e.restUrl)||""}),D=b(()=>{var e;return!!((e=y.config)!=null&&e.active)}),x=b(()=>{var e;return!!((e=y.config)!=null&&e.installed)}),C=b(()=>{var e;return!!((e=y.config)!=null&&e.canInstall)}),L=b(()=>{var e;return!!((e=y.config)!=null&&e.canAuthor)}),$=V(!1),j=V(!1),_e=()=>Ue.confirm(t("Save the product first if you have unsaved changes — reloading discards them."),t("Reload this page?"),{confirmButtonText:t("Reload Page"),cancelButtonText:t("Cancel"),type:"warning"}).then(()=>{window.location.reload()}).catch(()=>{}),he=()=>{$.value=!0,W.post("integration/feed/install-plugin",{addon:"fluent-player"}).then(e=>{const a=x.value?t("FluentPlayer activated successfully."):t("FluentPlayer installed successfully.");T.success((e==null?void 0:e.message)||a),j.value=!0}).catch(e=>{const a=x.value?t("Could not activate FluentPlayer."):t("Could not install FluentPlayer.");T.error(J(e,a))}).finally(()=>{$.value=!1})},z=b(()=>Ie(y.modelValue)),O=b(()=>z.value.media_ids),ie=e=>{const a=Number(e)||0;if(a){if(O.value.includes(a)){T.info(t("That video is already attached to this product."));return}if(O.value.length>=me){T.info(t("A product can have at most %1$s videos.",me));return}_("update:modelValue",{media_ids:[...z.value.media_ids,a],positions:[...z.value.positions,null]})}},ye=e=>{_("update:modelValue",Ee(z.value,e))},ge=e=>xe(e,t("Untitled video")),oe=e=>({id:e,title:t("Video #%1$s (unavailable)",e),poster:"",provider:"",missing:!0}),S=V({});ae(O,e=>{const a=e.filter(v=>!S.value[v]);if(!a.length||!k.value)return;const p={};a.forEach(v=>{p[v]={id:v,title:t("Loading..."),poster:"",provider:"",loading:!0}}),S.value={...S.value,...p},Me(k.value,a,t("Untitled video")).then(v=>{const m={...S.value};a.forEach(o=>{m[o]=v[o]&&!v[o].missing?v[o]:oe(o)}),S.value=m}).catch(v=>{const m={...S.value};a.forEach(o=>{m[o]=oe(o)}),S.value=m,T.error(J(v,t("Could not load the FluentPlayer videos.")))})},{immediate:!0});const K=b(()=>O.value.map(e=>S.value[e]||{id:e,title:t("Video #%1$s",e),poster:"",provider:""})),se=e=>{var a;return(a=y.config)!=null&&a.editUrlBase?y.config.editUrlBase+e:""},X=V([]),G=V(!1),U=V(null);let Q=null;const ne=e=>{k.value&&(clearTimeout(Q),Q=setTimeout(()=>{G.value=!0,W.get("media/search",{q:e||"",limit:20,status:"publish,private"},k.value).then(a=>{const p=Array.isArray(a)?a:(a==null?void 0:a.data)||(a==null?void 0:a.medias)||[];X.value=p.map(ge).filter(v=>v.id>0)}).catch(a=>{T.error(J(a,t("Could not search FluentPlayer videos.")))}).finally(()=>{G.value=!1})},250))},be=b(()=>X.value.filter(e=>!O.value.includes(e.id))),ke=()=>{U.value&&(ie(U.value),U.value=null)},de=()=>({src:"",attachment_id:0,attachmentTitle:"",provider:"",viewType:"video",metaTitle:"",metaPoster:"",metaProvider:"",metaViewType:"",metaFailed:!1}),we=["youtube","vimeo","external","wordpress"],Te=e=>{const a=String((e==null?void 0:e.provider)||(e==null?void 0:e.provider_name)||"").toLowerCase();return we.includes(a)?a:""},l=V(de()),E=V(!1);ae(E,e=>_("busy",e));const Z=V(!1);let ee=null,te=0,q=null;const Pe=e=>{if(!le(e)||!k.value)return;const p=e.trim(),v=++te,m=()=>v===te&&l.value.src.trim()===p;Z.value=!0,q=W.get("media/metadata",{url:p},k.value).then(o=>{var P;if(!m())return;const c=(o==null?void 0:o.metaData)||((P=o==null?void 0:o.data)==null?void 0:P.metaData)||null;l.value.metaTitle=(c==null?void 0:c.title)||"",l.value.metaPoster=(c==null?void 0:c.thumbnail_url)||"",l.value.metaProvider=Te(c),l.value.metaViewType=["video","audio"].includes(c==null?void 0:c.media_type)?c.media_type:""}).catch(()=>{m()&&(l.value.metaFailed=!0)}).finally(()=>{v===te&&(Z.value=!1,q=null)})};ae(()=>l.value.src,e=>{clearTimeout(ee),l.value.metaTitle="",l.value.metaPoster="",l.value.metaProvider="",l.value.metaViewType="",l.value.metaFailed=!1,l.value.provider!=="wordpress"&&le(e)&&(ee=setTimeout(()=>Pe(e),400))});const Y=b(()=>l.value.provider==="wordpress"?{provider:"wordpress",viewType:l.value.viewType}:le(l.value.src)),ce=b(()=>Y.value?pe(Y.value.provider):""),re=b(()=>!!Y.value&&!E.value),Ve=()=>{l.value.provider==="wordpress"&&(l.value.provider="",l.value.attachment_id=0,l.value.attachmentTitle="")};let w=null;const Fe=()=>{var e;if(typeof((e=window.wp)==null?void 0:e.media)!="function"){T.error(t("The WordPress media library is not available on this screen."));return}w||(w=window.wp.media({title:t("Select or upload a video"),button:{text:t("Use this video")},library:{type:"video"},multiple:!1}),w.on("open",()=>{try{w.content.mode("browse")}catch{}}),w.on("select",()=>{var p;const a=(p=w.state().get("selection").first())==null?void 0:p.toJSON();a!=null&&a.url&&(l.value.src=a.url,l.value.attachment_id=Number(a.id)||0,l.value.attachmentTitle=a.title||"",l.value.provider="wordpress",l.value.viewType="video")})),w.open()};Se(()=>{clearTimeout(Q),clearTimeout(ee),E.value&&_("busy",!1),w&&typeof w.detach=="function"&&w.detach(),w=null});const ue=()=>{var m;const e=Y.value;if(!e){E.value=!1;return}const a=e.provider==="wordpress"?"wordpress":l.value.metaProvider||e.provider,p=e.provider==="wordpress"?e.viewType:l.value.metaViewType||e.viewType,v={title:Re({metaTitle:l.value.metaTitle,attachmentTitle:l.value.attachmentTitle,url:l.value.src},t("Untitled Media")),post_status:"publish",src:l.value.src.trim(),provider:a,viewType:p,posterSrc:l.value.metaPoster||"",preset_slug:((m=y.config)==null?void 0:m.defaultPresetSlug)||"course",playsInline:!0,mutedAutoplay:!1,autoplay:!1,loadStrategy:"visible",preload:"metadata",aspectRatio:"default"};a==="wordpress"&&l.value.attachment_id&&(v.attachment_id=l.value.attachment_id),W.post("media",{settings:v,tags:[]},k.value).then(o=>{var B;const c=(o==null?void 0:o.media)||((B=o==null?void 0:o.data)==null?void 0:B.media)||null,P=Number((c==null?void 0:c.ID)||(c==null?void 0:c.id))||0;if(!P){T.error(t("FluentPlayer did not return the new video id."));return}T.success((o==null?void 0:o.message)||t("Video created in FluentPlayer.")),l.value=de(),ie(P)}).catch(o=>{const c=Ne(o);if(c===403||c===401){T.error(t("Your account is not allowed to create FluentPlayer videos."));return}T.error(J(o,t("Could not create the video in FluentPlayer.")))}).finally(()=>{E.value=!1})},Ce=()=>{!re.value||!k.value||(E.value=!0,q?q.finally(ue):ue())};return(e,a)=>{const p=A("el-button"),v=A("el-input"),m=A("el-tooltip"),o=A("el-option"),c=A("el-select"),P=A("el-skeleton-item"),B=A("el-skeleton"),ve=A("el-tag");return n(),f("div",Le,[D.value?(n(),f(M,{key:1},[L.value?(n(),f(M,{key:1},[u("div",je,[u("div",ze,[u("label",qe,r(K.value.length?i(t)("Add another video"):i(t)("Add a video")),1),u("div",Ye,[h(v,{id:"fct-fp-video-src",modelValue:l.value.src,"onUpdate:modelValue":a[0]||(a[0]=s=>l.value.src=s),placeholder:i(t)("Paste a YouTube, Vimeo or direct video URL"),onInput:Ve},null,8,["modelValue","placeholder"]),h(m,{content:i(t)("Choose from the Media Library"),placement:"top"},{default:g(()=>[h(p,{class:"fct-fp-video__icon-only","data-fct-fp-video-library":"","aria-label":i(t)("Choose from the Media Library"),onClick:Fe},{default:g(()=>[h(H,{name:"VideoAdd"})]),_:1},8,["aria-label"])]),_:1},8,["content"]),h(p,{type:"primary",loading:E.value,disabled:!re.value,"data-fct-fp-video-create-btn":"",onClick:Ce},{default:g(()=>[F(r(i(t)("Add Video")),1)]),_:1},8,["loading","disabled"])]),Z.value?(n(),f("span",We,r(i(t)("Reading the video details...")),1)):ce.value?(n(),f("span",He,[F(r(i(t)("Detected: %1$s",ce.value))+" ",1),l.value.metaTitle?(n(),f(M,{key:0},[F(" — "+r(l.value.metaTitle),1)],64)):l.value.metaFailed?(n(),f(M,{key:1},[F(" — "+r(i(t)("details could not be read; the file name will be used as the title")),1)],64)):N("",!0)])):l.value.src?(n(),f("span",Je,r(i(t)("Enter a full URL starting with http:// or https://")),1)):(n(),f("span",Ke,r(i(t)("Title and poster are sourced from YouTube, Vimeo, audio or HLS file or direct video")),1))]),u("div",Xe,[u("span",null,r(i(t)("OR")),1)]),u("div",Ge,[u("span",Qe,r(i(t)("Pick an existing FluentPlayer video")),1),u("div",Ze,[h(c,{modelValue:U.value,"onUpdate:modelValue":a[1]||(a[1]=s=>U.value=s),filterable:"",remote:"",clearable:"","remote-method":ne,loading:G.value,placeholder:i(t)("Search videos by title or ID..."),class:"fct-fp-video__select",onVisibleChange:a[2]||(a[2]=s=>s&&!X.value.length&&ne(""))},{default:g(()=>[(n(!0),f(M,null,fe(be.value,s=>(n(),I(o,{key:s.id,label:`#${s.id} — ${s.title}`,value:s.id},null,8,["label","value"]))),128))]),_:1},8,["modelValue","loading","placeholder"]),h(p,{type:"primary",disabled:!U.value,"data-fct-fp-video-use-existing":"",onClick:ke},{default:g(()=>[F(r(i(t)("Use Video")),1)]),_:1},8,["disabled"])])])]),K.value.length?(n(),f("div",et,[u("h4",tt,r(i(t)("Videos")),1),(n(!0),f(M,null,fe(K.value,s=>(n(),f("div",{key:s.id,class:Ae(["fct-fp-video__card",{"is-loading":s.loading}]),"data-fct-fp-video-selected":"","data-fct-fp-video-id":s.id,"aria-busy":s.loading?"true":null,"aria-label":s.loading?i(t)("Loading..."):null},[u("div",lt,[s.loading?(n(),I(B,{key:0,animated:""},{template:g(()=>[h(P,{variant:"image",class:"fct-fp-video__card-thumb-skeleton"})]),_:1})):(n(),f(M,{key:1},[s.poster?(n(),f("img",{key:0,src:s.poster,alt:s.title||""},null,8,it)):N("",!0),u("div",ot,[h(H,{name:"PlayCircle"})])],64))]),u("div",st,[s.loading?(n(),I(B,{key:0,animated:"",rows:0,"data-fct-fp-video-loading":""},{template:g(()=>[u("div",nt,[h(P,{variant:"h3",class:"fct-fp-video__card-title-skeleton"}),h(P,{variant:"text",class:"fct-fp-video__card-meta-skeleton"})])]),_:1})):(n(),f(M,{key:1},[u("span",dt,r(s.title),1),u("span",ct,[u("span",rt,"#"+r(s.id),1),s.provider?(n(),f("span",ut,r(i(pe)(s.provider)),1)):N("",!0),s.missing?(n(),I(ve,{key:1,type:"danger",size:"small","data-fct-fp-video-missing":""},{default:g(()=>[F(r(i(t)("Not found")),1)]),_:1})):s.trashed?(n(),I(ve,{key:2,type:"warning",size:"small","data-fct-fp-video-trashed":""},{default:g(()=>[F(r(i(t)("In trash")),1)]),_:1})):N("",!0)])],64))]),u("div",vt,[se(s.id)?(n(),I(m,{key:0,content:i(t)("Edit in FluentPlayer"),placement:"top"},{default:g(()=>[u("a",{href:se(s.id),target:"_blank",rel:"noopener",class:"fct-fp-video__icon-btn","data-fct-fp-video-edit":"","aria-label":i(t)("Edit in FluentPlayer")},[h(H,{name:"Edit"})],8,ft)]),_:2},1032,["content"])):N("",!0),h(m,{content:i(t)("Remove video"),placement:"top"},{default:g(()=>[u("button",{type:"button",class:"fct-fp-video__icon-btn fct-fp-video__icon-btn--danger","data-fct-fp-video-remove":"","aria-label":i(t)("Remove video"),onClick:_t=>ye(s.id)},[h(H,{name:"Delete"})],8,pt)]),_:2},1032,["content"])])],10,at))),128))])):N("",!0)],64)):(n(),f("p",$e,r(i(t)("Your account cannot manage FluentPlayer videos. Ask an administrator to grant the FluentPlayer authoring capability.")),1))],64)):(n(),f("div",Oe,[u("p",Be,r(j.value?i(t)("FluentPlayer is ready. Save any changes to this product, then reload the page to add videos."):i(t)("FluentPlayer is required to add videos to this product.")),1),!j.value&&!C.value?(n(),f("p",De,r(x.value?i(t)("Ask an administrator to activate it for you."):i(t)("Ask an administrator to install it for you.")),1)):j.value?(n(),I(p,{key:1,type:"primary","data-fct-fp-video-reload":"",onClick:_e},{default:g(()=>[F(r(i(t)("Reload Page")),1)]),_:1})):(n(),I(p,{key:2,type:"primary",loading:$.value,disabled:$.value,"data-fct-fp-video-install":"",onClick:he},{default:g(()=>[F(r(x.value?i(t)("Activate FluentPlayer"):i(t)("Install & Activate FluentPlayer")),1)]),_:1},8,["loading","disabled"]))]))])}}};export{St as default};