import{a as e}from"./rolldown-runtime-CNC7AqOf.js";import{t}from"./react-Augu_vA3.js";import{K as n,Si as r,V as i,_t as a,dt as o,ot as s,t as c}from"./forms-CL2ODv4X.js";import{t as l}from"./useTranslation-B_YCgyrR.js";import{t as u}from"./enterprise-plan-7ejkapqa.js";import{t as d}from"./jsx-runtime-CTknu7_t.js";import{n as f,s as p}from"./cards-CR_9H_Xm.js";import{t as m}from"./useHasPermission-CRA8mdHC.js";import{t as h}from"./pro-plan-WDhyng0X.js";import{t as g}from"./ArrowRight-DsSPsdeY.js";var _=e(t(),1);function v(){let{isAdmin:e}=m();return!((h()||u())&&e)}var y=e(d());function b({size:e=`1.2rem`,color:t=`#000`,strokeWidth:n=`2`}){return(0,y.jsxs)(`svg`,{xmlns:`http://www.w3.org/2000/svg`,xmlnsXlink:`http://www.w3.org/1999/xlink`,x:`0px`,y:`0px`,style:{width:e,height:e},viewBox:`0 0 20 20`,children:[(0,y.jsx)(`line`,{x1:`10`,y1:`3`,x2:`10`,y2:`17`,fill:`none`,stroke:t,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:n,"data-color":`color-2`}),(0,y.jsx)(`polyline`,{points:`5 12 10 17 15 12`,fill:`none`,stroke:t,strokeLinecap:`round`,strokeLinejoin:`round`,strokeWidth:n})]})}var x=function(e){return e.SingleLineText=`single_line_text`,e.MultiLineText=`multi_line_text`,e.Switch=`switch`,e.Dropdown=`dropdown`,e.Date=`date`,e}({});function S(e){let[t]=l(),r=a(),[o,s]=(0,_.useState)(``),[c,u]=(0,_.useState)(``),d=v(),[m,h]=(0,_.useState)(`single_line_text`),x=[`single_line_text`,`multi_line_text`,`switch`,`dropdown`,`date`],S=(0,_.useRef)(),C=(0,_.useRef)();(0,_.useEffect)(()=>{if(e.initialValue){let t=e.initialValue.split(`|`);e.initialValue.includes(`|`)?x.includes(t[1])?h(t[1]):(h(`dropdown`),u(t[1])):h(`multi_line_text`),s(t[0])}},[]);let w=t=>{t&&h(t);let n=t||m,r=n===`dropdown`?C.current?.value.split(`,`).map(e=>e.trim()).join(`,`):n,i=r===`multi_line_text`?`${S.current?.value||``}`:`${S.current?.value||``}|${r}`;e.onChange&&e.onChange(i,e.field,n)};return e.withArrowAsSeparator?(0,y.jsxs)(y.Fragment,{children:[(0,y.jsxs)(`div`,{className:`flex flex-col sm:flex-row w-full space-y-3 sm:space-y-0 sm:space-x-3 items-center justify-between py-3 text-sm`,children:[(0,y.jsx)(`div`,{className:`w-full sm:w-2/6`,children:(0,y.jsx)(i,{id:e.field,innerRef:S,placeholder:e.placeholder,onValueChange:()=>w(),value:o,disabled:d})}),(0,y.jsx)(`div`,{className:`hidden sm:inline-block`,children:(0,y.jsx)(g,{size:`1.2rem`,color:r.$17,strokeWidth:`1.5`})}),(0,y.jsx)(`div`,{className:`inline-block sm:hidden`,children:(0,y.jsx)(b,{size:`1.2rem`,color:r.$17,strokeWidth:`1.5`})}),(0,y.jsx)(`div`,{className:`w-full sm:w-4/6`,children:(0,y.jsxs)(n,{value:m,onValueChange:e=>w(e),dismissable:!1,customSelector:!0,children:[(0,y.jsx)(`option`,{value:`single_line_text`,children:t(`single_line_text`)}),(0,y.jsx)(`option`,{value:`multi_line_text`,children:t(`multi_line_text`)}),(0,y.jsx)(`option`,{value:`switch`,children:t(`switch`)}),(0,y.jsx)(`option`,{value:`dropdown`,children:t(`dropdown`)}),(0,y.jsx)(`option`,{value:`date`,children:t(`date`)})]})})]}),m===`dropdown`&&(0,y.jsx)(i,{id:`multi_line_text`,innerRef:C,placeholder:t(`comma_sparated_list`),value:c,onValueChange:()=>w()})]}):(0,y.jsxs)(y.Fragment,{children:[(0,y.jsx)(p,{noExternalPadding:e.noExternalPadding,leftSide:(0,y.jsx)(i,{id:e.field,innerRef:S,placeholder:e.placeholder,onValueChange:()=>w(),value:o,disabled:d}),children:(0,y.jsxs)(n,{value:m,onValueChange:e=>w(e),dismissable:!1,customSelector:!0,children:[(0,y.jsx)(`option`,{value:`single_line_text`,children:t(`single_line_text`)}),(0,y.jsx)(`option`,{value:`multi_line_text`,children:t(`multi_line_text`)}),(0,y.jsx)(`option`,{value:`switch`,children:t(`switch`)}),(0,y.jsx)(`option`,{value:`dropdown`,children:t(`dropdown`)}),(0,y.jsx)(`option`,{value:`date`,children:t(`date`)})]})}),m===`dropdown`&&(0,y.jsx)(f,{children:(0,y.jsx)(i,{id:`multi_line_text`,innerRef:C,placeholder:t(`comma_sparated_list`),value:c,onValueChange:()=>w()})})]})}function C(e){let[t,r]=(0,_.useState)(`single_line_text`),o=a();return(0,_.useEffect)(()=>{let[,t]=e.value.includes(`|`)?e.value.split(`|`):[e.value,`multi_line_text`];r(t)},[e.field]),(0,y.jsxs)(y.Fragment,{children:[t===x.SingleLineText&&(0,y.jsx)(i,{style:{color:o.$3,colorScheme:o.$0},type:`text`,id:e.field,onValueChange:e.onValueChange,value:e.defaultValue||``}),t===x.MultiLineText&&(0,y.jsx)(i,{style:{color:o.$3,colorScheme:o.$0},element:`textarea`,id:e.field,onValueChange:e.onValueChange,value:e.defaultValue||``}),t===x.Switch&&(0,y.jsx)(c,{style:{color:o.$3,colorScheme:o.$0},onChange:t=>{let n=t?`yes`:`no`;e.onValueChange(n)},checked:typeof e.defaultValue==`string`?e.defaultValue===`true`||e.defaultValue===`1`||e.defaultValue===`yes`:e.defaultValue}),t===x.Date&&(0,y.jsx)(i,{style:{color:o.$3,colorScheme:o.$0},type:`date`,id:e.field,onValueChange:e.onValueChange,value:e.defaultValue||``}),!Object.values(x).includes(t)&&(0,y.jsx)(n,{value:e.defaultValue||``,onValueChange:t=>e.onValueChange(t),customSelector:!0,withBlank:!0,menuPosition:e.selectMenuPosition,children:t.split(`,`).map((e,t)=>(0,y.jsx)(`option`,{value:e,children:e},t))})]})}var w=e(o());function T(e){let[t,n]=e.includes(`|`)?e.split(`|`):[e,``];return{label:()=>t,type:()=>n}}function E(){let e=r();return t=>e&&e.custom_fields[t]?T(e.custom_fields[t]):T(``)}function D(e){let[t,n]=(0,_.useState)(``);return(0,_.useEffect)(()=>{let[t]=e.value.includes(`|`)?e.value.split(`|`):[e.value,``];n(t||``)},[]),e.fieldOnly?(0,y.jsx)(C,{...e}):e.labelOnTop?(0,y.jsxs)(`div`,{className:(0,w.default)(`flex flex-col gap-y-1`,e.labelWrapperClassName),children:[t?(0,y.jsx)(s,{children:t}):null,(0,y.jsx)(C,{...e})]}):(0,y.jsx)(p,{leftSide:t,noExternalPadding:e.noExternalPadding,children:(0,y.jsx)(C,{...e})})}export{S as a,x as i,T as n,b as o,E as r,v as s,D as t};