import{j as _,z as b,k as l}from"./iframe-B4rglaWu.js";import{g as x,s as y,u as C,C as V,U as N}from"./Form-a1c8JcgO.js";import{B as k}from"./button.esm-BWX-wzE5.js";import{U as E}from"./UiInputText.stories-DdUnsdKr.js";import{U as z}from"./UiPassword.stories-EKQuoQER.js";import"./preload-helper-PPVm8Dsz.js";import"./componentbase.esm-O764U3c0.js";import"./index.esm-Bp9biEJw.js";import"./iconbase.esm-CeJUwaxq.js";import"./ripple.esm-Bd7Vm0vw.js";import"./tooltip.esm-C17X5ypA.js";import"./portal.esm-9O3HNf5A.js";import"./ErrorMessage-DFhVHOBn.js";import"./inputtext.esm-PyaMa37F.js";import"./keyfilter.esm-Bl_Obi_0.js";import"./overlayservice.esm-C5VFRSbT.js";const F=(e,o,t)=>{if(e&&"reportValidity"in e){const r=x(t,o);e.setCustomValidity(r&&r.message||""),e.reportValidity()}},P=(e,o)=>{for(const t in o.fields){const r=o.fields[t];r&&r.ref&&"reportValidity"in r.ref?F(r.ref,t,e):r&&r.refs&&r.refs.forEach(c=>F(c,t,e))}},T=(e,o)=>{o.shouldUseNativeValidation&&P(e,o);const t={};for(const r in e){const c=x(o.fields,r),s=Object.assign(e[r]||{},{ref:c&&c.ref});if($(o.names||Object.keys(e),r)){const m=Object.assign({},x(t,r));y(m,"root",s),y(t,r,m)}else y(t,r,s)}return t},$=(e,o)=>{const t=w(o);return e.some(r=>w(r).match(`^${t}\\.\\d+`))};function w(e){return e.replace(/\]|\[/g,"")}function D(e){if(e.path?.length){let o="";for(const t of e.path){const r=typeof t=="object"?t.key:t;if(typeof r=="string"||typeof r=="number")o?o+=`.${r}`:o+=r;else return null}return o}return null}function S(){return S=Object.assign?Object.assign.bind():function(e){for(var o=1;o<arguments.length;o++){var t=arguments[o];for(var r in t)({}).hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},S.apply(null,arguments)}function I(e,o,t){return t===void 0&&(t={}),function(r,c,s){try{var m=function(){if(n.issues){var i=(function(u,d){for(var f={},p=0;p<u.length;p++){var v=u[p],g=D(v);if(g&&(f[g]||(f[g]={message:v.message,type:""}),d)){var j,U=f[g].types||{};f[g].types=S({},U,((j={})[Object.keys(U).length]=v.message,j))}}return f})(n.issues,!s.shouldUseNativeValidation&&s.criteriaMode==="all");return{values:{},errors:T(i,s)}}return s.shouldUseNativeValidation&&P({},s),{values:t.raw?Object.assign({},r):n.value,errors:{}}},n=e["~standard"].validate(r),a=(function(){if(n instanceof Promise)return Promise.resolve(n).then(function(i){n=i})})();return Promise.resolve(a&&a.then?a.then(m):m())}catch(i){return Promise.reject(i)}}}const O=()=>{const e=_.c(16);let o;e[0]===Symbol.for("react.memo_cache_sentinel")?(o={defaultValues:{username:"",password:""},resolver:I(b.object({username:b.string().min(1),password:b.string().min(1)}))},e[0]=o):o=e[0];const t=C(o);let r;e[1]===Symbol.for("react.memo_cache_sentinel")?(r=function(p){alert(JSON.stringify(p))},e[1]=r):r=e[1];const c=r;let s;e[2]!==t?(s=t.register("username"),e[2]=t,e[3]=s):s=e[3];const m=t.formState.errors.username?.message;let n;e[4]!==s||e[5]!==m?(n=l.jsx(E,{id:"text",label:"Texto",...s,error:m}),e[4]=s,e[5]=m,e[6]=n):n=e[6];let a;e[7]!==t.control?(a=l.jsx(V,{control:t.control,name:"password",render:B}),e[7]=t.control,e[8]=a):a=e[8];let i;e[9]!==n||e[10]!==a?(i=l.jsxs("div",{className:"grid grid-cols-2 items-start gap-10 [&>div]:space-y-1 mb-2",children:[n,a]}),e[9]=n,e[10]=a,e[11]=i):i=e[11];let u;e[12]===Symbol.for("react.memo_cache_sentinel")?(u=l.jsx(k,{type:"submit",label:"Enviar"}),e[12]=u):u=e[12];let d;return e[13]!==t||e[14]!==i?(d=l.jsx(l.Fragment,{children:l.jsxs(N,{methods:t,onSubmit:c,children:[i,u]})}),e[13]=t,e[14]=i,e[15]=d):d=e[15],d};O.__docgenInfo={description:"",methods:[],displayName:"DocsFormulario"};function B(e){const{field:o,fieldState:t}=e;return l.jsx(z,{id:"password",label:"Senha",required:!0,value:o.value,onChange:r=>o.onChange(r.target.value),invalid:!!t.error})}const M=`import { standardSchemaResolver } from '@hookform/resolvers/standard-schema'
import { Button } from 'primereact/button'
import { Controller, useForm } from 'react-hook-form'
import z from 'zod'
import UiForm from '@/components/ui/form/Form'
import UiInputText from '@/components/ui/form/UiInputText'
import UiPassword from '@/components/ui/form/UiPassword'

const DocsFormulario = () => {
  type MyForm = { username: string; password: string }

  const methods = useForm<MyForm>({
    defaultValues: {
      username: '',
      password: '',
    },
    resolver: standardSchemaResolver(
      z.object({
        username: z.string().min(1),
        password: z.string().min(1),
      }),
    ),
  })

  function onSubmit(values: MyForm) {
    alert(JSON.stringify(values))
  }

  return (
    <>
      <UiForm methods={methods} onSubmit={onSubmit}>
        <div className="grid grid-cols-2 items-start gap-10 [&>div]:space-y-1 mb-2">
          <UiInputText
            id="text"
            label="Texto"
            {...methods.register('username')}
            error={methods.formState.errors.username?.message}
          />

          <Controller
            control={methods.control}
            name="password"
            render={({ field, fieldState }) => {
              return (
                <UiPassword
                  id="password"
                  label="Senha"
                  required
                  value={field.value}
                  onChange={e => field.onChange(e.target.value)}
                  invalid={!!fieldState.error}
                />
              )
            }}
          />
        </div>

        <Button type="submit" label="Enviar" />
      </UiForm>
    </>
  )
}

export default DocsFormulario
`,oe={title:"Examples/Form",component:O,parameters:{docs:{source:{codePanel:!0,code:M,language:"tsx"}}}},h={};h.parameters={...h.parameters,docs:{...h.parameters?.docs,source:{originalSource:"{}",...h.parameters?.docs?.source}}};const se=["Login"];export{h as Login,se as __namedExportsOrder,oe as default};
