import{d as D,ak as q,am as K,r as A,o as i,f as d,D as C,x as p,z as h,J as I,U as _,g as B,A as W,t as y,S as u,b as w,y as S,W as x,_ as P,Z as R,b2 as U,c as f,$ as G}from"./index-DKV98_mQ.js";const L={class:"WdsFieldWrapper colorTransformer"},X={class:"temporaryMissingBar"},Z={key:0,class:"WdsFieldWrapper__title"},H={key:0,class:"WdsFieldWrapper__title__label"},Q={key:0,class:"WdsFieldWrapper__title__label__unit"},Y={class:"WdsFieldWrapper__slot"},ee={key:1,class:"WdsFieldWrapper__error"},te={key:2,class:"WdsFieldWrapper__hint"},ae=D({__name:"WdsFieldWrapper",props:q({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:q({helpClick:()=>!0,expand:()=>!0,shrink:()=>!0},["update:isBindingEnabled"]),setup(e,{emit:v}){const r=K(e,"isBindingEnabled"),o=v,a=A(!1);function m(){o("expand"),a.value=!0}const k={desc:"OK",fn:()=>{a.value=!1,o("shrink")}};return(c,l)=>(i(),d("div",L,[a.value?(i(),d(C,{key:0},[p(_,{actions:[k],description:e.hint,title:e.label},{default:h(()=>[I(c.$slots,"default",{},void 0,!0)]),_:3},8,["actions","description","title"]),B("div",X,[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(),d(C,{key:1},[!a.value&&(e.label||e.helpButton)?(i(),d("div",Z,[e.label?(i(),d("label",H,[W(y(e.label),1),e.unit?(i(),d("span",Q," : "+y(e.unit),1)):u("",!0)])):u("",!0),e.isExpansible?(i(),w(x,{key:1,variant:"neutral",size:"smallIcon","data-writer-tooltip":"Expand",onClick:m},{default:h(()=>[p(S,{name:"expand"})]),_:1})):u("",!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=>c.$emit("helpClick"))},{default:h(()=>[p(S,{name:"circle-question-mark"})]),_:1},8,["data-writer-tooltip"])):u("",!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"])):u("",!0)])):u("",!0),B("div",Y,[I(c.$slots,"default",{},void 0,!0)]),e.error?(i(),d("p",ee,y(e.error),1)):u("",!0),e.hint?(i(),d("p",te,y(e.hint),1)):u("",!0)],64))]))}}),re=P(ae,[["__scopeId","data-v-15f0885c"]]);function se(e){try{return JSON.parse(e),!0}catch{return!1}}function J(e){try{return JSON.parse(e)}catch{return{}}}function le(e){const v=ne(),r=A(z(e)),o=A(typeof e=="string"?e:JSON.stringify(e)),a=R({});F(e);function m(t){if(r.value!==t){switch(t){case"assisted":F(E.value);break;case"freehand":o.value=JSON.stringify(N.value,void 0,2);break}r.value=t}}function k(t){a.value=Object.entries(t).reduce((s,[n,g])=>(s[v()]={key:n,value:String(g)},s),{})}function c(){a.value={...a.value,[v()]:{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 V(t){if(!a.value[t])return;const s={...a.value};delete s[t],a.value=s}function $(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 z(t){return typeof t=="string"&&(U.exec(t)||!se(t))?"freehand":"assisted"}function F(t){const s=typeof t=="string"?J(t):t;a.value=Object.entries(s).reduce((n,[g,j])=>(n[v()]={key:g,value:String(j)},n),{}),Object.keys(a.value).length===0&&c()}const M=f(()=>Object.values(a.value).some(t=>t.key==="")),O=f(()=>{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}),T=f(()=>{switch(r.value){case"assisted":return O.value.size===0;case"freehand":return!0;default:return!1}}),E=f(()=>{switch(r.value){case"assisted":{const t=Object.values(a.value).reduce((s,n)=>(s[n.key]=n.value,s),{});return JSON.stringify(t)}case"freehand":return o.value;default:return""}}),N=f(()=>J(E.value));return{mode:f({get:()=>r.value,set:m}),assistedEntries:G(a),addEntryDisabled:M,addAssistedEntry:c,updateAssistedEntryKey:l,updateAssistedEntryValue:b,removeAssistedEntry:V,getAssistedEntryError:$,updateAssistedEntries:k,freehandValue:o,isValid:T,currentValue:E,currentValueObject:N}}function ne(){let e=0;return()=>String(++e)}export{re as W,le as u};
