import{r as V,w as N,a as r,_ as T,i as x}from"./createElementId-DhjFt1I9-Cdw8hg_s.chunk.mjs";import{l as g}from"./logger-D3RVzcfQ-v2acROFG.chunk.mjs";import{N as u,a as O}from"./NcSelect-B1uITk_3-Sy-Mfeg1.chunk.mjs";import{c as S}from"./index-DaEUtA7I.chunk.mjs";import{f as m,c as v,o as w,y as F,C as P,w as n,m as _,a9 as $,aa as A,e as h,z as D}from"./runtime-dom.esm-bundler-CnPoR0UW.chunk.mjs";V(N);function d(e){let t={};if(e.nodeType===1){if(e.attributes.length>0){t["@attributes"]={};for(let s=0;s<e.attributes.length;s++){const o=e.attributes.item(s);t["@attributes"][o.nodeName]=o.nodeValue}}}else e.nodeType===3&&(t=e.nodeValue);if(e.hasChildNodes())for(let s=0;s<e.childNodes.length;s++){const o=e.childNodes.item(s),a=o.nodeName;if(typeof t[a]>"u")t[a]=d(o);else{if(typeof t[a].push>"u"){const l=t[a];t[a]=[],t[a].push(l)}t[a].push(d(o))}}return t}function I(e){let t=null;try{t=new DOMParser().parseFromString(e,"text/xml")}catch(s){g.error("[NcSelectTags] Failed to parse xml document",{error:s})}return t}function f(e){const t=d(I(e))["d:multistatus"]["d:response"],s=[];for(const o in t){const a=t[o]["d:propstat"];a["d:status"]["#text"]==="HTTP/1.1 200 OK"&&s.push({id:parseInt(a["d:prop"]["oc:id"]["#text"]),displayName:a["d:prop"]["oc:display-name"]["#text"],canAssign:a["d:prop"]["oc:can-assign"]["#text"]==="true",userAssignable:a["d:prop"]["oc:user-assignable"]["#text"]==="true",userVisible:a["d:prop"]["oc:user-visible"]["#text"]==="true"})}return s}async function L(){if(window.NextcloudVueDocs)return Promise.resolve(f(window.NextcloudVueDocs.tags));const e=await S({method:"PROPFIND",url:x("dav")+"/systemtags/",data:`<?xml version="1.0"?>
					<d:propfind  xmlns:d="DAV:" xmlns:oc="http://owncloud.org/ns">
					  <d:prop>
						<oc:id />
						<oc:display-name />
						<oc:user-visible />
						<oc:user-assignable />
						<oc:can-assign />
					  </d:prop>
					</d:propfind>`});return f(e.data)}const j={name:"NcSelectTags",components:{NcEllipsisedOption:O,NcSelect:u},props:{...u.props,fetchTags:{type:Boolean,default:!0},getOptionLabel:{type:Function,default:e=>{const{displayName:t,userVisible:s,userAssignable:o}=e;return s===!1?r("{tag} (invisible)",{tag:t}):o===!1?r("{tag} (restricted)",{tag:t}):t}},limit:{type:Number,default:5},multiple:{type:Boolean,default:!0},optionsFilter:{type:Function,default:null},passthru:{type:Boolean,default:!1},placeholder:{type:String,default:r("Select a tag")},modelValue:{type:[Number,Array,Object],default:null}," ":{}},emits:["update:modelValue"," "],data(){return{search:"",availableTags:[]}},computed:{availableOptions(){return this.optionsFilter?this.tags.filter(this.optionsFilter):this.tags},localValue(){return this.passthru?this.modelValue:this.tags.length===0?[]:this.multiple?this.modelValue.filter(e=>e!=="").map(e=>this.tags.find(t=>t.id===e)):this.tags.find(e=>e.id===this.modelValue)},propsToForward(){const e={...this.$props};return delete e.fetchTags,delete e.optionsFilter,delete e.passthru,e},tags(){return this.fetchTags?this.availableTags:this.options}},async created(){if(this.fetchTags)try{const e=await L();this.availableTags=e}catch(e){g.error("[NcSelectTags] Loading systemtags failed",e)}},methods:{handleInput(e){if(this.passthru){this.$emit("update:modelValue",e);return}this.multiple?this.$emit("update:modelValue",e.map(t=>t.id)):e===null?this.$emit("update:modelValue",null):this.$emit("update:modelValue",e.id)}}};function B(e,t,s,o,a,l){const p=m("NcEllipsisedOption"),b=m("NcSelect");return w(),v(b,D(l.propsToForward,{options:l.availableOptions,closeOnSelect:!s.multiple,modelValue:l.localValue,onSearch:t[0]||(t[0]=i=>a.search=i),"onUpdate:modelValue":l.handleInput}),F({option:n(i=>[h(p,{name:s.getOptionLabel(i),search:a.search},null,8,["name","search"])]),"selected-option":n(i=>[h(p,{name:s.getOptionLabel(i),search:a.search},null,8,["name","search"])]),_:2},[P(e.$slots,(i,c)=>({name:c,fn:n(y=>[_(e.$slots,c,$(A(y)))])}))]),1040,["options","closeOnSelect","modelValue","onUpdate:modelValue"])}const R=T(j,[["render",B]]),H=Object.freeze(Object.defineProperty({__proto__:null,default:u},Symbol.toStringTag,{value:"Module"}));export{R as N,H as i};
//# sourceMappingURL=index-DfkIdINN.chunk.mjs.map
