import{r as t,h as i,F as e,H as s}from"./p-0f50db55.js";var n,h,a,o,r,l,c,d,g,u,f=function(t,i,e,s){if("a"===e&&!s)throw new TypeError("Private accessor was defined without a getter");if("function"==typeof i?t!==i||!s:!i.has(t))throw new TypeError("Cannot read private member from an object whose class did not declare it");return"m"===e?s:"a"===e?s.call(t):s?s.value:i.get(t)};const m=class{constructor(i){t(this,i),n.add(this),this.json=void 0,this.field_name=void 0,this.cols=40,this.rows=10,this.delete_svg_src="/static/admin/img/icon-deletelink.svg",this.add_svg_src="/static/admin/img/icon-addlink.svg",this.edit_svg_src="/static/admin/img/icon-changelink.svg",this.output_render_type="rows",this.__json=new Array}jsonWatcher(t){f(this,n,"m",o).call(this,t)}connectedCallback(){f(this,n,"m",o).call(this,this.json)}render(){return i(s,{key:"913f5e65c4e4c29a4d6fe630b76657be2c8295ad"},this.__json&&this.__json.length>0&&Array.isArray(this.__json)?i(e,null,i("textarea",{class:("textarea"===this.output_render_type?"":"hidden invisible")+" vLargeTextField",cols:this.cols,name:this.field_name,rows:this.rows,onInput:f(this,n,"m",d).bind(this)},f(this,n,"a",a)),"rows"===this.output_render_type&&this.__json&&i(e,null,this.__json.map((t=>i("div",{class:"form-row field-data",key:t.index},i("div",{class:"flex gap-2.5"},i("input",{value:t.key,onInput:i=>f(this,n,"m",g).call(this,i,t),placeholder:"key",class:"min-width-[150px]"}),i("strong",null,":"),i("input",{value:t.value,onInput:i=>f(this,n,"m",u).call(this,i,t),placeholder:"value",class:"min-width-[300px]"}),i("div",{class:"items-center justify-center flex",onClick:()=>f(this,n,"m",r).call(this,t.index)},i("img",{src:this.delete_svg_src,alt:"❌"}))))))),i("div",{class:"form-row justify-between items-center flex"},i("div",{class:"items-center justify-center flex gap-1 "+("textarea"===this.output_render_type?"invisible":""),onClick:f(this,n,"m",l).bind(this)},i("img",{src:this.add_svg_src,alt:"➕"}),"Add row"),i("div",{class:"items-center justify-center flex gap-1",onClick:f(this,n,"m",c).bind(this)},"textarea"===this.output_render_type?i(e,null,i("img",{src:this.delete_svg_src,alt:"❌"}),"Close TextArea"):"rows"===this.output_render_type?i(e,null,i("img",{src:this.edit_svg_src,alt:"✏️"}),"Open TextArea"):i("div",null,"Output render type is ",this.output_render_type," which doesn't fall in `rows` or `textarea`")))):i("div",{class:"flex items-center justify-center gap-1"},i("p",null,"The provided json is ",i("code",null,this.json)," which is not valid."),i("p",null,"Please check the the json or ",i("a",{href:f(this,n,"a",h)},"file an issue at Github"))))}static get watchers(){return{json:["jsonWatcher"]}}};n=new WeakSet,h=function(){return"https://github.com/baseplate-admin/django-hstore-widget/issues"},a=function(){const t=this.__json.reduce(((t,i)=>(t[i.key]=i.value,t)),{});let i=0;return Object.keys(t).length>1&&(i=4),globalThis.JSON.stringify(t,null,i)},o=function(t){try{let i=globalThis.JSON.parse(t);this.__json=Object.keys(i).map(((t,e)=>({key:t,value:i[t],index:e})))}catch(t){console.error(t),this.__json=[]}finally{this.__json=globalThis.structuredClone(this.__json)}},r=function(t){this.__json=this.__json.filter((i=>i.index!==t)),this.__json=globalThis.structuredClone(this.__json)},l=function(){const t=this.__json.at(-1);this.__json.push({index:t?t.index+1:0,key:"",value:""}),this.__json=globalThis.structuredClone(this.__json)},c=function(){"rows"===this.output_render_type?this.output_render_type="textarea":"textarea"===this.output_render_type?this.output_render_type="rows":console.error(`Something is wrong with \`output_render_type\`. It is ${this.output_render_type}`)},d=function(t){this.json=t.currentTarget.value},g=function(t,i){i.key=t.currentTarget.value,this.__json=globalThis.structuredClone(this.__json)},u=function(t,i){i.value=t.currentTarget.value,this.__json=globalThis.structuredClone(this.__json)},m.style="django-hstore-widget .min-width-\\[150px\\]{min-width:150px}django-hstore-widget .min-width-\\[300px\\]{min-width:300px}django-hstore-widget .flex{display:flex}django-hstore-widget .justify-center{justify-content:center}django-hstore-widget .justify-between{justify-content:space-between}django-hstore-widget .items-center{align-items:center}django-hstore-widget .flex-col{flex-direction:column}django-hstore-widget .invisible{visibility:hidden}django-hstore-widget .hidden{display:none}django-hstore-widget .gap-1{gap:0.25rem;}django-hstore-widget .gap-2\\.5{gap:0.625rem;}";export{m as django_hstore_widget}