import{j as t}from"./app-BMysVXg2.js";import{c as r}from"./utils-BpqJBFla.js";import{G as K}from"./iconBase-BRa7Gs07.js";import{C as M}from"./circle-alert-YqkuI-V9.js";function q(d){return K({attr:{fill:"currentColor",viewBox:"0 0 16 16"},child:[{tag:"path",attr:{d:"M3.612 15.443c-.386.198-.824-.149-.746-.592l.83-4.73L.173 6.765c-.329-.314-.158-.888.283-.95l4.898-.696L7.538.792c.197-.39.73-.39.927 0l2.184 4.327 4.898.696c.441.062.612.636.282.95l-3.522 3.356.83 4.73c.078.443-.36.79-.746.592L8 13.187l-4.389 2.256z"},child:[]}]})(d)}function A({className:d,type:s,...e}){return t.jsx("input",{type:s,"data-slot":"input",className:r("border-input file:text-foreground placeholder:text-muted-foreground selection:bg-primary selection:text-primary-foreground flex h-9 w-full min-w-0 rounded-md border bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm","focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px]","aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",d),...e})}const Y=({id:d,label:s,name:e,type:l="text",value:c,onChange:a,onBlur:f,touched:k,checked:b=!1,errors:i,placeholder:u,className:N="",classNameInput:o="",required:y=!1,disabled:x=!1,prefix:p="",subfix:h="",rows:$=4,tsize:g,min:L,minLength:z,max:C,maxLength:S})=>{const w=`
    [type='number']::-webkit-outer-spin-button,
  [type='number']::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
  }
  [type='number'] {
    -moz-appearance: textfield;
  }
    mt-1 block w-full outline-none
    ${l==="toggle"?"rounded-full":"rounded-md"} 
    border border-gray-300 bg-muted/20 px-3 py-2 shadow-sm transition-all duration-200 text-md
    ${x?"cursor-not-allowed bg-gray-100":""} 
    ${p?"pl-12":"pr-10"}`,m=n=>{const j=n.target.value;a(j)},G=n=>{a(n)},R=()=>{if(l==="textarea")return t.jsx("textarea",{id:d??e,name:e,rows:$,value:c,onChange:m,onBlur:f,placeholder:u||`Masukan ${String(s).toLowerCase()}`,className:r(w,(i==null?void 0:i[e])&&"border-red-500",o),disabled:x,"aria-invalid":!!(i!=null&&i[e]),"aria-describedby":i!=null&&i[e]?`${e}-error`:void 0});if(l==="rating")return t.jsxs("div",{className:"flex items-center gap-1",children:[[1,2,3,4,5].map(n=>t.jsx("button",{type:"button",onClick:()=>G(n),className:"text-2xl focus:outline-none","aria-label":`Rate ${n} star`,children:t.jsx(q,{className:n<=Number(c)?"text-yellow-400":"text-secondary-foreground"})},n)),t.jsx("input",{type:"hidden",name:e,value:c,onChange:m})]});if(l==="toggle"){const n={xs:"text-xs",sm:"text-sm",md:"text-md",lg:"text-lg",xl:"text-xl"},F={xs:"h-4 w-12",sm:"h-5 w-14",md:"h-5 w-16",lg:"h-6 w-18",xl:"h-7 w-20"}[g??"md"],v=n[g??"md"];return t.jsxs("label",{className:`relative inline-flex items-center ${F}`,children:[t.jsx("input",{type:"checkbox",className:r("peer sr-only",o),checked:b,onChange:I=>a==null?void 0:a(I.target.checked),name:e}),t.jsx("div",{className:"h-full w-full rounded-full bg-gray-300 transition-colors duration-300 peer-checked:bg-green-500"}),t.jsx("div",{className:"absolute top-0.5 left-0.5 aspect-square h-[calc(100%-4px)] rounded-full bg-white shadow transition-transform duration-300 peer-checked:right-0.5 peer-checked:left-auto"}),t.jsx("span",{className:`absolute right-2 ${v} font-medium text-gray-600 peer-checked:hidden`,children:"No"}),t.jsx("span",{className:`absolute left-2 hidden ${v} font-medium text-white peer-checked:inline`,children:"Yes"})]})}return l==="checkbox"?t.jsx("input",{type:"checkbox",id:e,name:e,checked:b,onChange:n=>a==null?void 0:a(n.target.checked),className:o}):t.jsx(A,{id:d??e,name:e,type:l==="currency"?"number":l,value:c,onChange:m,onBlur:f,placeholder:u||(s?`Ketik ${s==null?void 0:s.toLowerCase()}`:`Ketik ${e==null?void 0:e.toLowerCase()}`),className:r(o,w,(i==null?void 0:i[e])&&"border-red-500","appearance-none [&::-webkit-inner-spin-button]:appearance-none [&::-webkit-outer-spin-button]:appearance-none"),disabled:x,"aria-invalid":!!(i!=null&&i[e]),"aria-describedby":i!=null&&i[e]?`${e}-error`:void 0,step:l==="currency"?"0.01":void 0,min:L,max:C,maxLength:S,minLength:z})};return t.jsxs("div",{className:N,children:[s&&t.jsxs("label",{htmlFor:e,className:"block text-sm font-medium text-secondary-foreground",children:[s,y&&t.jsx("span",{className:"text-red-500",children:" *"})]}),t.jsxs("div",{className:"relative mt-1",children:[p&&t.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-0 flex items-center bg-muted px-3",children:t.jsx("span",{className:"text-sm font-bold text-muted-foreground",children:p})}),R(),h&&t.jsx("div",{className:"pointer-events-none absolute inset-y-0 right-0 flex items-center pr-3",children:t.jsx("span",{className:"text-sm font-bold text-muted-foreground",children:h})})]}),k||(i==null?void 0:i[e])&&t.jsxs("p",{className:"flex items-center gap-2 text-xs text-destructive mt-1",children:[t.jsx(M,{className:"w-4 h-4"}),i[e]]})]})};export{Y as I};
