import{d as O,m as I,g as V,r as E,az as F,s as T,aA as N,h as P,i as m,o as u,f as a,e as M,j as R,aB as A,aw as f,n as c,c as _,F as K,z,w as C,t as g,u as o,au as W}from"./Dih1Xbo1.js";import{_ as q}from"./Bh0_f5g3.js";import{u as j}from"./DSufQG8x.js";import{u as G}from"./X83roiBl.js";const H=W(q),J={class:"flex items-center gap2"},Q={class:"flex-1 text-left"},X={class:"text-sm"},Y={class:"op50 font-mono text-xs"},Z={class:"flex-1 text-left"},ee={class:"text-sm"},te={class:"flex-1 text-left"},se={class:"text-sm"},ue=O({__name:"UiEditorLinkInput",props:I({hasDeleteButton:{type:Boolean,default:!1},dropdownClasses:{default:"DROPDOWN_MENU absolute mt2 w-xs"},toggleOnFocus:{type:Boolean,default:!0},focus:{type:Boolean},limitResults:{default:10}},{modelValue:{required:!1},modelModifiers:{}}),emits:I(["change","submit"],["update:modelValue"]),setup(h,{emit:$}){const y=h,k=$,i=V(h,"modelValue"),v=E(!1),r=F("input"),t=E(i.value),n=E([]),L=T(()=>{const s=[];return n.value.forEach(e=>{s.push({type:"result",value:e._path})}),t.value?.includes("://")||t.value?.startsWith("http")?/^https?:\/\/[^\s.]+\.\S+$/.test(t.value)&&s.push({type:"external",value:t.value}):!n.value?.length&&t.value?.length&&s.push({type:"newPage",value:N(t.value)}),s}),{selectedIndex:b,resetSelection:d,setSelection:x}=G({isFocused:v,items:L,onSelect:s=>{i.value=s.value||"",t.value=s.value||"",r.value?.blur(),d(),k("submit",s.value)},onSubmit:()=>{i.value=t.value||"",r.value?.blur(),d(),k("submit",t.value)},onEscape:()=>{d(),r.value?.blur(),t.value=i.value}});function p(s){i.value=s||"",t.value=s||"",r.value?.blur(),d(),k("submit",s)}const{onSearchPage:U}=j();async function S(s){if(!(s.key==="Enter"||s.key==="Escape"||s.key==="ArrowUp"||s.key==="ArrowDown"))try{n.value=(await U(t.value)).slice(0,y.limitResults),d()}catch(e){console.warn(e)}}return P(()=>y.focus,()=>{y.focus&&r.value?.focus()},{immediate:!0}),(s,e)=>{const w=H;return u(),m("div",null,[a("div",J,[R(a("input",{ref_key:"input",ref:r,"onUpdate:modelValue":e[0]||(e[0]=l=>t.value=l),placeholder:"Paste a link or search pages...",class:"INLINE_MENU_LINK_INPUT",onKeyup:e[1]||(e[1]=l=>S(l)),onFocus:e[2]||(e[2]=l=>v.value=!0),onBlur:e[3]||(e[3]=l=>v.value=!1)},null,544),[[A,t.value]]),s.hasDeleteButton&&i.value?.length?(u(),m("button",{key:0,class:"flex INLINE_MENU_LINK_REMOVE_BUTTON op80 hover:op100 transition",onClick:e[4]||(e[4]=l=>p()),onMousedown:e[5]||(e[5]=f(()=>{},["prevent"]))},e[10]||(e[10]=[a("div",{class:"ICON_DELETE"},null,-1)]),32)):M("",!0)]),(!s.toggleOnFocus||v.value)&&t.value?.length?(u(),m("div",{key:0,class:c(s.dropdownClasses)},[(u(!0),m(K,null,z(n.value,(l,B)=>(u(),_(w,{key:l._id,class:c(["items-start",{"bg-gray-100 dark:bg-gray-800":o(b)===B}]),onClick:f(D=>p(l._path),["prevent"]),onMouseenter:D=>o(x)(B)},{default:C(()=>[e[11]||(e[11]=a("div",{class:"i-lucide-file op50 mt0.5"},null,-1)),a("div",Q,[a("div",X,g(l._path),1),a("div",Y,g(l._id.replaceAll(":","/")),1)])]),_:2},1032,["class","onClick","onMouseenter"]))),128)),t.value?.includes("://")||t.value?.startsWith("http")?(u(),_(w,{key:0,class:c(["items-start disabled:op80",{"bg-gray-100 dark:bg-gray-800":o(b)===n.value.length}]),disabled:!/^https?:\/\/.*\..+$/.test(t.value),onClick:e[6]||(e[6]=f(l=>p(t.value),["prevent"])),onMouseenter:e[7]||(e[7]=l=>o(x)(n.value.length))},{default:C(()=>[e[13]||(e[13]=a("div",{class:"op50 mt0.5 i-lucide-globe"},null,-1)),a("div",Z,[a("div",ee,g(t.value),1),e[12]||(e[12]=a("div",{class:"font-mono op50 text-xs"}," Lien externe ",-1))])]),_:1},8,["class","disabled"])):n.value?.length?M("",!0):(u(),_(w,{key:1,class:c(["items-start",{"bg-gray-100 dark:bg-gray-800":o(b)===0}]),onClick:e[8]||(e[8]=f(l=>p(o(N)(t.value)),["prevent"])),onMouseenter:e[9]||(e[9]=l=>o(x)(0))},{default:C(()=>[e[15]||(e[15]=a("div",{class:"op50 mt0.5 i-lucide-file-plus"},null,-1)),a("div",te,[a("div",se,g(o(N)(t.value)),1),e[14]||(e[14]=a("div",{class:"font-mono op50 text-xs"}," Nouvelle page ",-1))])]),_:1},8,["class"]))],2)):M("",!0)])}}});export{ue as _};
