/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});require('./MediaUploadModal.css');const e=require("vue"),a=require("../../../../Form/index.js"),l=require("../../../../Button/index.js");;/* empty css                       */const t=require("../../../../_virtual/_plugin-vue_export-helper.js"),i=require("../../../../Overlay/src/Modal.vue.js"),o={class:"gap-6 grid-cols-1"},d={class:"gsc-form-item gsc-form-item--vertical gap-1 mb-4"},u={class:"flex gap-4"},r={class:"inline-flex items-center gap-2"},v=["name"],n={class:"inline-flex items-center gap-2"},c=["name"],s={key:0,class:"gsc-form-item gsc-form-item--vertical gap-1"},m={class:"gsc-form-label mb-0.5"},p=["accept"],h={key:0,class:"mt-2 border rounded p-2"},g=["src"],f=["src"],w={key:1,class:"gsc-form-item gsc-form-item--vertical gap-1"},y={class:"gsc-form-label mb-0.5"},k=["placeholder"],V={key:0,class:"mt-2 border rounded p-2"},N=["src"],x=["src"],b={class:"gsc-form-item gsc-form-item--vertical gap-1 mt-4"},E={class:"gsc-form-label mb-0.5"},M={class:"flex items-center gap-2"},T=["title","aria-pressed"],U={class:"flex justify-end gap-2"},B=Object.assign({name:"MediaUploadModal"},{__name:"MediaUploadModal",props:{visible:{type:Boolean,default:!1},title:{type:String,required:!0},mediaType:{type:String,validator:e=>["image","video"].includes(e),default:"image"},editor:{type:Object,required:!0}},emits:["update:visible","cancel","ok"],setup(t,{emit:B}){const C=t,_=B,D=e.ref(C.visible),R=e.ref(null),j=e.ref(null),L=e.ref(""),P=e.ref(""),S=e.ref(!0),q=e.ref(null);e.watch(()=>C.visible,e=>{D.value=e}),e.watch(D,e=>{_("update:visible",e)});const H=e.ref({uploadMethod:"local",mediaUrl:"",width:void 0,height:void 0}),W=e.computed(()=>"local"===H.value.uploadMethod),I=e.computed(()=>"network"===H.value.uploadMethod),F=e.computed(()=>"image"===C.mediaType?"Local Image":"Local Video"),G=e.computed(()=>`Select ${C.mediaType.charAt(0).toUpperCase()+C.mediaType.slice(1)}`),O=e.computed(()=>"image"===C.mediaType?"image/*":"video/*"),$=e.ref(!1),A=()=>{H.value={uploadMethod:"local",mediaUrl:"",width:void 0,height:void 0},L.value="",P.value="",S.value=!0,q.value=null},z=()=>{R.value?.click()},K=e=>{const[a]=e.target.files||[];a&&((e,a)=>{const l=new FileReader;l.onload=e=>{a(e.target?.result||"")},l.readAsDataURL(e)})(a,e=>{L.value=e,H.value.width=void 0,H.value.height=void 0,q.value=null}),e.target.value=""},J=()=>{if("image"===C.mediaType){const e=j.value;if(!e||!e.naturalWidth||!e.naturalHeight)return;q.value=e.naturalWidth/e.naturalHeight,H.value.width=e.naturalWidth,H.value.height=e.naturalHeight}else{const e=j.value;if(!e||!e.videoWidth||!e.videoHeight)return;q.value=e.videoWidth/e.videoHeight,H.value.width=e.videoWidth,H.value.height=e.videoHeight}},Q=e=>{if(null==e||""===e)return;const a=Number(e);return Number.isNaN(a)?void 0:Math.max(1,Math.round(a))},X=e=>{const a={src:e};H.value.width&&(a.width=H.value.width),H.value.height&&(a.height=H.value.height),C.editor?.chain().focus()["image"===C.mediaType?"setImage":"setVideo"](a).run()},Y=()=>{_("update:visible",!1),_("cancel"),A()},Z=()=>{W.value&&L.value?(X(L.value),_("update:visible",!1),_("ok",{mediaType:C.mediaType,url:L.value,...H.value}),A()):I.value&&H.value.mediaUrl&&(X(H.value.mediaUrl),_("update:visible",!1),_("ok",{mediaType:C.mediaType,url:H.value.mediaUrl,...H.value}),A())};e.watch(()=>C.visible,e=>{e||A()}),e.watch(()=>H.value.uploadMethod,e=>{H.value.mediaUrl="",H.value.width=void 0,H.value.height=void 0,q.value=null,"local"===e?P.value="":L.value=""}),e.watch(()=>H.value.mediaUrl,e=>{I.value&&(P.value=e||"",P.value||(q.value=null,H.value.width=void 0,H.value.height=void 0))}),e.watch(()=>H.value.width,e=>{if($.value)return;const a=Q(e);if(void 0!==a)return a!==e?($.value=!0,H.value.width=a,void($.value=!1)):void(S.value&&q.value&&($.value=!0,H.value.height=Math.round(a/q.value),$.value=!1));S.value&&($.value=!0,H.value.height=void 0,$.value=!1)}),e.watch(()=>H.value.height,e=>{if($.value)return;const a=Q(e);if(void 0!==a)return a!==e?($.value=!0,H.value.height=a,void($.value=!1)):void(S.value&&q.value&&($.value=!0,H.value.width=Math.round(a*q.value),$.value=!1));S.value&&($.value=!0,H.value.width=void 0,$.value=!1)}),e.watch(S,e=>{if(!e||!q.value)return;const a=Q(H.value.width);void 0!==a&&($.value=!0,H.value.height=Math.round(a/q.value),$.value=!1)});const ee=()=>{if(S.value=!S.value,S.value&&q.value){const e=Q(H.value.width);void 0!==e&&($.value=!0,H.value.height=Math.round(e/q.value),$.value=!1)}};return(B,C)=>(e.openBlock(),e.createBlock(e.unref(i.default),{modelValue:D.value,"onUpdate:modelValue":C[5]||(C[5]=e=>D.value=e),title:t.title},{footer:e.withCtx(()=>[e.createElementVNode("div",U,[e.createVNode(e.unref(l.GscButton),{variant:"default",onClick:Y},{default:e.withCtx(()=>[...C[10]||(C[10]=[e.createTextVNode(" Cancel ",-1)])]),_:1}),e.createVNode(e.unref(l.GscButton),{variant:"primary",onClick:Z},{default:e.withCtx(()=>[...C[11]||(C[11]=[e.createTextVNode(" Insert ",-1)])]),_:1})])]),default:e.withCtx(()=>[e.createVNode(e.unref(a.GscForm),{"show-actions":!1},{default:e.withCtx(()=>[e.createElementVNode("div",o,[e.createElementVNode("div",d,[C[7]||(C[7]=e.createElementVNode("div",{class:"gsc-form-label mb-0.5"}," Upload Method ",-1)),e.createElementVNode("div",u,[e.createElementVNode("label",r,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":C[0]||(C[0]=e=>H.value.uploadMethod=e),type:"radio",name:`${t.mediaType}-upload-method`,value:"local"},null,8,v),[[e.vModelRadio,H.value.uploadMethod]]),e.createElementVNode("span",null,e.toDisplayString(F.value),1)]),e.createElementVNode("label",n,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":C[1]||(C[1]=e=>H.value.uploadMethod=e),type:"radio",name:`${t.mediaType}-upload-method`,value:"network"},null,8,c),[[e.vModelRadio,H.value.uploadMethod]]),C[6]||(C[6]=e.createElementVNode("span",null,"Network Address",-1))])])]),W.value?(e.openBlock(),e.createElementBlock("div",s,[e.createElementVNode("div",m,e.toDisplayString(G.value),1),e.createElementVNode("div",null,[e.createVNode(e.unref(l.GscButton),{variant:"primary",onClick:z},{default:e.withCtx(()=>[...C[8]||(C[8]=[e.createTextVNode(" Click to Upload ",-1)])]),_:1}),e.createElementVNode("input",{ref_key:"modalFileInputRef",ref:R,type:"file",accept:O.value,class:"hidden",onChange:K},null,40,p)]),L.value?(e.openBlock(),e.createElementBlock("div",h,["image"===t.mediaType?(e.openBlock(),e.createElementBlock("img",{key:0,ref_key:"mediaPreviewRef",ref:j,src:L.value,alt:"Preview",style:{"max-width":"100%","max-height":"200px"},onLoad:J},null,40,g)):(e.openBlock(),e.createElementBlock("video",{key:1,ref_key:"mediaPreviewRef",ref:j,src:L.value,alt:"Preview",style:{"max-width":"100%","max-height":"200px"},onLoadedmetadata:J},null,40,f))])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),I.value?(e.openBlock(),e.createElementBlock("div",w,[e.createElementVNode("div",y,e.toDisplayString(t.mediaType)+" URL ",1),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":C[2]||(C[2]=e=>H.value.mediaUrl=e),type:"text",class:"gsc-control",placeholder:`Enter ${t.mediaType} URL`},null,8,k),[[e.vModelText,H.value.mediaUrl,void 0,{trim:!0}]]),P.value?(e.openBlock(),e.createElementBlock("div",V,["image"===t.mediaType?(e.openBlock(),e.createElementBlock("img",{key:0,ref_key:"mediaPreviewRef",ref:j,src:P.value,alt:"Preview",style:{"max-width":"100%","max-height":"200px"},onLoad:J},null,40,N)):(e.openBlock(),e.createElementBlock("video",{key:1,ref_key:"mediaPreviewRef",ref:j,src:P.value,alt:"Preview",style:{"max-width":"100%","max-height":"200px"},controls:"",onLoadedmetadata:J},null,40,x))])):e.createCommentVNode("",!0)])):e.createCommentVNode("",!0),e.createElementVNode("div",b,[e.createElementVNode("div",E,e.toDisplayString(t.mediaType)+" Dimensions ",1),e.createElementVNode("div",M,[e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":C[3]||(C[3]=e=>H.value.width=e),type:"number",min:"1",placeholder:"Width",class:"gsc-control w-32"},null,512),[[e.vModelText,H.value.width,void 0,{number:!0}]]),C[9]||(C[9]=e.createElementVNode("span",{class:"text-gray-500"},"×",-1)),e.withDirectives(e.createElementVNode("input",{"onUpdate:modelValue":C[4]||(C[4]=e=>H.value.height=e),type:"number",min:"1",placeholder:"Height",class:"gsc-control w-32"},null,512),[[e.vModelText,H.value.height,void 0,{number:!0}]]),e.createElementVNode("button",{type:"button",class:e.normalizeClass(["border-none bg-transparent",{"text-blue-500":S.value}]),title:S.value?"Keep aspect ratio":"Do not keep aspect ratio","aria-pressed":S.value,onClick:ee},[e.createElementVNode("span",{class:e.normalizeClass(S.value?"i-simple-line-icons:lock":"i-simple-line-icons:lock-open")},null,2)],10,T)])])])]),_:1})]),_:1},8,["modelValue","title"]))}}),C=t.default(B,[["__scopeId","data-v-319fae53"]]);exports.default=C;