import{j as n,u as l}from"./fields-wnm5Jtc6.js";import{a as d,R as v}from"./vendor-D21mNUGX.js";import{P as i}from"./index-pmrLY__j.js";import"./Select-DRmfXoMp.js";import{I as h}from"./InputHidden-B-jHubUl.js";const g=({id:u,register:j,setValue:x,defaultValue:o,description:c})=>{const a=d.useRef(null),m=d.useRef(null),p=()=>{const s=a.current.value,t=m.current.value;if(s&&t){const e=s==="after"?parseInt(t)+1:parseInt(t)-1;x(u,e)}},b=()=>{const s=e=>{const r=e.replace(/(<([^>]+)>)/gi,"");return e.length!==r.length?e.split(" ")[0]:e};let t=[];for(const[e,r]of Object.entries(document.globals.menu))t.push({label:r[0]!==""?s(r[0]):"----",value:e});return t},f=()=>{if(!o)return{position:null,menu:null};for(const[e,r]of Object.entries(document.globals.menu)){if(parseInt(e)+1===o)return{position:"after",menu:e};if(parseInt(e)-1===o)return{position:"before",menu:e}}const t=Object.keys(document.globals.menu).findIndex(e=>parseInt(e)===parseInt(o));return Object.entries(document.globals.menu)[t+1]?{position:"before",menu:Object.entries(document.globals.menu)[t+1][0]}:Object.entries(document.globals.menu)[t-1]?{position:"after",menu:Object.entries(document.globals.menu)[t-1][0]}:{position:null,menu:null}};return n.jsxs(v.Fragment,{children:[n.jsx(h,{register:j,id:u,value:o}),n.jsxs("div",{className:"i-flex-center s-8 w-100",children:[n.jsx("div",{className:"acpt-select w-50",children:n.jsxs("select",{ref:a,"data-cy":`position-${u}`,className:"form-control",onChangeCapture:p,defaultValue:f().position,children:[n.jsx("option",{value:"",children:l("Select")}),n.jsx("option",{value:"after",children:l("After")}),n.jsx("option",{value:"before",children:l("Before")})]})}),n.jsx("div",{className:"acpt-select w-50",children:n.jsxs("select",{ref:m,"data-cy":`menu-${u}`,className:"form-control",onChangeCapture:p,defaultValue:f().menu,children:[n.jsx("option",{value:"",children:l("Select")}),b().map(s=>n.jsx("option",{value:s.value,children:s.label},s.value))]})})]}),c&&n.jsx("div",{className:"form-description",children:c})]})};g.propTypes={id:i.string.isRequired,defaultValue:i.number,description:i.string,setValue:i.func.isRequired,register:i.func.isRequired};export{g as M};
