import{r as e,h as t,F as s,H as i}from"./p-f350f2d0.js";const a="django-hstore-widget .wrapper{display:flex;gap:10px}django-hstore-widget .left{min-width:150px}django-hstore-widget .right{min-width:300px}django-hstore-widget .centered{display:flex;align-items:center;justify-content:center}django-hstore-widget .end-items{display:flex;justify-content:space-between;align-items:center}django-hstore-widget .hidden{display:none;visibility:hidden}django-hstore-widget .gap-1{gap:0.25rem;}";const d=a;const n=class{constructor(t){e(this,t);this.json=undefined;this.field_name=undefined;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;this._json_string=""}connectedCallback(){let e=JSON.parse(this.json);let t=Object.keys(e).map(((t,s)=>({key:t,value:e[t],index:s})));this._json=t;this.updateJSONString()}handleDelete(e){const t=this._json.filter((t=>t.index!==e));this._json=structuredClone(t)}handleRowAdd(){let e=this._json;const t=e.at(-1);const s={index:t.index+1,key:"",value:""};e.push(s);this._json=structuredClone(e)}handleToggleClick(){switch(this.output_render_type){case"rows":this.output_render_type="textarea";break;case"textarea":this.output_render_type="rows";break;default:console.error("Something is wrong with `output_render_type`");break}}getJSONWithoutIndex(){return this._json.reduce(((e,t)=>{e[t.key]=t.value;return e}),{})}updateJSONString(){this._json_string=JSON.stringify(this.getJSONWithoutIndex(),null,Object.keys(this._json).length===1?0:4)}handleTextAreaInput(e){this.json=e;this.connectedCallback()}render(){return t(i,{key:"77b16da3b3a2263e68c44d7f8eecd08b76f14c14"},t("textarea",{key:"7ae9b7fbed6963475af888e58db07540dab3debc",class:`${this.output_render_type==="textarea"?"":"hidden"} vLargeTextField`,cols:40,name:`${this.field_name}`,rows:10,onInput:e=>{const t=e.currentTarget;const s=t.value;this.handleTextAreaInput(s)}},this._json_string),this.output_render_type==="rows"&&this._json&&t(s,{key:"d09edc9df2c628f3b5b0a2ebda5ac0af84073b69"},this._json.map(((e,s)=>t("div",{class:"form-row field-data"},t("div",{class:"wrapper"},t("input",{value:e.key,onInput:t=>{const s=t.currentTarget;const i=s.value;e.key=i;this.updateJSONString()},placeholder:"key",class:"left"}),t("strong",null,":"),t("input",{value:e.value,onInput:()=>{const t=event.currentTarget;const s=t.value;e.value=s;this.updateJSONString()},placeholder:"value",class:"right"}),t("div",{class:"centered",onClick:()=>{this.handleDelete(s)}},t("img",{src:this.delete_svg_src,alt:"❌"}))))))),t("div",{key:"d0d6aa78a655a4774fb74d8c1c63d19216252af6",class:"form-row end-items"},this.output_render_type==="rows"?t(s,null,t("div",{class:"centered gap-1",onClick:()=>{this.handleRowAdd()}},t("img",{src:this.add_svg_src,alt:"➕"}),"Add row")):t(s,null,t("div",null)),t("div",{key:"f2f39d2d17e65de1560ded22f818a8881664ce13",class:"centered gap-1",onClick:()=>{this.handleToggleClick()}},this.output_render_type==="textarea"&&t(s,{key:"ee7550127ffdbaa70121168e500f7dfdfe6926b4"},t("img",{key:"94d3d944fa366ed1b8884805bf2d91773b105d22",src:this.delete_svg_src,alt:"❌"}),"Close TextArea"),this.output_render_type==="rows"&&t(s,{key:"440cbcf942064d69042cc7c2c26bc35fecba3a49"},t("img",{key:"ed9a735556ce0c8074bafa4c0aa9293ef23720ee",src:this.edit_svg_src,alt:"✏️"}),"Open TextArea"))))}};n.style=d;export{n as django_hstore_widget};
//# sourceMappingURL=p-d858b589.entry.js.map