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