import{d as _,an as C,ap as j,r as A,o as i,f as u,D as I,x as p,z as h,J,a3 as P,g as B,A as W,t as y,S as d,b as w,y as S,W as x,_ as R,Y as G,b2 as L,c as v,Z as U}from"./index-hX9gYZGS.js";const X={class:"WdsFieldWrapper colorTransformer"},Y={class:"temporaryMissingBar"},Z={key:0,class:"WdsFieldWrapper__title"},H={key:0,class:"WdsFieldWrapper__title__label"},Q={key:0,class:"WdsFieldWrapper__title__label__unit"},ee={class:"WdsFieldWrapper__slot"},te={key:1,class:"WdsFieldWrapper__error"},ae={key:2,class:"WdsFieldWrapper__hint"},se=_({__name:"WdsFieldWrapper",props:C({label:{type:String,required:!1,default:void 0},unit:{type:String,required:!1,default:void 0},hint:{type:String,required:!1,default:void 0},error:{type:String,required:!1,default:void 0},isExpansible:{type:Boolean,required:!1,default:!1},isBindingButtonShown:{type:Boolean,required:!1,default:!1},helpButton:{type:[String,Boolean],required:!1,default:void 0}},{isBindingEnabled:{type:Boolean,required:!1,default:!1},isBindingEnabledModifiers:{}}),emits:C({helpClick:()=>!0,expand:()=>!0,shrink:()=>!0},["update:isBindingEnabled"]),setup(e,{emit:o}){const r=j(e,"isBindingEnabled"),c=o,a=A(!1);function k(){c("expand"),a.value=!0}const m={desc:"OK",fn:()=>{a.value=!1,c("shrink")}};return(f,l)=>(i(),u("div",X,[a.value?(i(),u(I,{key:0},[p(P,{actions:[m],description:e.hint,title:e.label},{default:h(()=>[J(f.$slots,"default",{},void 0,!0)]),_:3},8,["actions","description","title"]),B("div",Y,[l[2]||(l[2]=W(" Field ")),B("strong",null,y(e.label),1),l[3]||(l[3]=W(" is open in a new window. "))])],64)):(i(),u(I,{key:1},[!a.value&&(e.label||e.helpButton)?(i(),u("div",Z,[e.label?(i(),u("label",H,[W(y(e.label),1),e.unit?(i(),u("span",Q," : "+y(e.unit),1)):d("",!0)])):d("",!0),e.isExpansible?(i(),w(x,{key:1,variant:"neutral",size:"smallIcon","data-writer-tooltip":"Expand",onClick:k},{default:h(()=>[p(S,{name:"expand"})]),_:1})):d("",!0),e.helpButton?(i(),w(x,{key:2,variant:"neutral",size:"smallIcon","data-writer-tooltip":typeof e.helpButton=="string"?e.helpButton:void 0,onClick:l[0]||(l[0]=b=>f.$emit("helpClick"))},{default:h(()=>[p(S,{name:"circle-question-mark"})]),_:1},8,["data-writer-tooltip"])):d("",!0),e.isBindingButtonShown?(i(),w(x,{key:3,variant:"neutral",size:"smallIcon","data-writer-tooltip-placement":"left","data-writer-tooltip":r.value?"Unbind from variable":"Bind to a variable",onClick:l[1]||(l[1]=b=>r.value=!r.value)},{default:h(()=>[p(S,{name:r.value?"wds-at-sign-slash":"at-sign"},null,8,["name"])]),_:1},8,["data-writer-tooltip"])):d("",!0)])):d("",!0),B("div",ee,[J(f.$slots,"default",{},void 0,!0)]),e.error?(i(),u("p",te,y(e.error),1)):d("",!0),e.hint?(i(),u("p",ae,y(e.hint),1)):d("",!0)],64))]))}}),le=R(se,[["__scopeId","data-v-15f0885c"]]);function ne(e){try{return JSON.parse(e),!0}catch{return!1}}function F(e){try{return JSON.parse(e)}catch{return{}}}function V(e){return Object.values(e).every(o=>typeof o=="string")}function ue(e){const o=ie(),r=A(T(e)),c=A(typeof e=="string"?e:JSON.stringify(e)),a=G({});N(e);function k(t){if(r.value!==t){switch(t){case"assisted":N(E.value);break;case"freehand":c.value=JSON.stringify(q.value,void 0,2);break}r.value=t}}function m(t){a.value=Object.entries(t).reduce((s,[n,g])=>(s[o()]={key:n,value:String(g)},s),{})}function f(){a.value={...a.value,[o()]:{value:"",key:""}}}function l(t,s){const n=a.value[t];n&&(a.value={...a.value,[t]:{...n,key:s}})}function b(t,s){const n=a.value[t];n&&(a.value={...a.value,[t]:{...n,value:s}})}function z(t){if(!a.value[t])return;const s={...a.value};delete s[t],a.value=s}function M(t){const s=a.value[t];if(s&&O.value.has(s.key))return"This key is already in use. Please remove duplicate keys."}function T(t){return typeof t!="string"?V(t)?"assisted":"freehand":L.exec(t)||!ne(t)?"freehand":V(F(t))?"assisted":"freehand"}function N(t){const s=typeof t=="string"?F(t):t;a.value=Object.entries(s).reduce((n,[g,K])=>(n[o()]={key:g,value:String(K)},n),{}),Object.keys(a.value).length===0&&f()}const $=v(()=>Object.values(a.value).some(t=>t.key==="")),O=v(()=>{const t=new Set,s=new Set;for(const{key:n}of Object.values(a.value))t.has(n)?s.add(n):t.add(n);return s}),D=v(()=>{switch(r.value){case"assisted":return O.value.size===0;case"freehand":return!0;default:return!1}}),E=v(()=>{switch(r.value){case"assisted":{const t=Object.values(a.value).filter(s=>!(s.key===""&&s.value==="")).reduce((s,n)=>(s[n.key]=n.value,s),{});return JSON.stringify(t)}case"freehand":return c.value;default:return""}}),q=v(()=>F(E.value));return{mode:v({get:()=>r.value,set:k}),assistedEntries:U(a),addEntryDisabled:$,addAssistedEntry:f,updateAssistedEntryKey:l,updateAssistedEntryValue:b,removeAssistedEntry:z,getAssistedEntryError:M,updateAssistedEntries:m,freehandValue:c,isValid:D,currentValue:E,currentValueObject:q}}function ie(){let e=0;return()=>String(++e)}export{le as W,ue as u};
