import{r as s,P as X,D as P,O as F,c as A,I as Y,j as z,k as m}from"./iframe-B4rglaWu.js";import{C as G,u as Q,U as Z}from"./Form-a1c8JcgO.js";import{u as ee,C as oe,a as te,d as re,c as ne}from"./componentbase.esm-O764U3c0.js";import{C as ae}from"./index.esm-WSOT0cb2.js";import{T as ie}from"./tooltip.esm-C17X5ypA.js";import"./preload-helper-PPVm8Dsz.js";import"./iconbase.esm-CeJUwaxq.js";import"./portal.esm-9O3HNf5A.js";function k(){return k=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var r=arguments[e];for(var n in r)({}).hasOwnProperty.call(r,n)&&(t[n]=r[n])}return t},k.apply(null,arguments)}function C(t){"@babel/helpers - typeof";return C=typeof Symbol=="function"&&typeof Symbol.iterator=="symbol"?function(e){return typeof e}:function(e){return e&&typeof Symbol=="function"&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},C(t)}function se(t,e){if(C(t)!="object"||!t)return t;var r=t[Symbol.toPrimitive];if(r!==void 0){var n=r.call(t,e);if(C(n)!="object")return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return(e==="string"?String:Number)(t)}function ce(t){var e=se(t,"string");return C(e)=="symbol"?e:e+""}function le(t,e,r){return(e=ce(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function ue(t){if(Array.isArray(t))return t}function de(t,e){var r=t==null?null:typeof Symbol<"u"&&t[Symbol.iterator]||t["@@iterator"];if(r!=null){var n,o,f,u,c=[],l=!0,b=!1;try{if(f=(r=r.call(t)).next,e!==0)for(;!(l=(n=f.call(r)).done)&&(c.push(n.value),c.length!==e);l=!0);}catch(d){b=!0,o=d}finally{try{if(!l&&r.return!=null&&(u=r.return(),Object(u)!==u))return}finally{if(b)throw o}}return c}}function w(t,e){(e==null||e>t.length)&&(e=t.length);for(var r=0,n=Array(e);r<e;r++)n[r]=t[r];return n}function pe(t,e){if(t){if(typeof t=="string")return w(t,e);var r={}.toString.call(t).slice(8,-1);return r==="Object"&&t.constructor&&(r=t.constructor.name),r==="Map"||r==="Set"?Array.from(t):r==="Arguments"||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?w(t,e):void 0}}function me(){throw new TypeError(`Invalid attempt to destructure non-iterable instance.
In order to be iterable, non-array objects must have a [Symbol.iterator]() method.`)}function fe(t,e){return ue(t)||de(t,e)||pe(t,e)||me()}var be={box:"p-checkbox-box",input:"p-checkbox-input",icon:"p-checkbox-icon",root:function(e){var r=e.props,n=e.checked,o=e.context;return A("p-checkbox p-component",{"p-highlight":n,"p-disabled":r.disabled,"p-invalid":r.invalid,"p-variant-filled":r.variant?r.variant==="filled":o&&o.inputStyle==="filled"})}},O=oe.extend({defaultProps:{__TYPE:"Checkbox",autoFocus:!1,checked:!1,className:null,disabled:!1,falseValue:!1,icon:null,id:null,inputId:null,inputRef:null,invalid:!1,variant:null,name:null,onChange:null,onContextMenu:null,onMouseDown:null,readOnly:!1,required:!1,style:null,tabIndex:null,tooltip:null,tooltipOptions:null,trueValue:!0,value:null,children:void 0},css:{classes:be}});function q(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(t);e&&(n=n.filter(function(o){return Object.getOwnPropertyDescriptor(t,o).enumerable})),r.push.apply(r,n)}return r}function T(t){for(var e=1;e<arguments.length;e++){var r=arguments[e]!=null?arguments[e]:{};e%2?q(Object(r),!0).forEach(function(n){le(t,n,r[n])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):q(Object(r)).forEach(function(n){Object.defineProperty(t,n,Object.getOwnPropertyDescriptor(r,n))})}return t}var D=s.memo(s.forwardRef(function(t,e){var r=ee(),n=s.useContext(X),o=O.getProps(t,n),f=s.useState(!1),u=fe(f,2),c=u[0],l=u[1],b=O.setMetaData({props:o,state:{focused:c},context:{checked:o.checked===o.trueValue,disabled:o.disabled}}),d=b.ptm,y=b.cx,U=b.isUnstyled;te(O.css.styles,U,{name:"checkbox"});var I=s.useRef(null),h=s.useRef(o.inputRef),R=function(){return o.checked===o.trueValue},B=function(a){if(!(o.disabled||o.readOnly)&&o.onChange){var i,x=R(),p=x?o.falseValue:o.trueValue,J={originalEvent:a,value:o.value,checked:p,stopPropagation:function(){a?.stopPropagation()},preventDefault:function(){a?.preventDefault()},target:{type:"checkbox",name:o.name,id:o.id,value:o.value,checked:p}};if(o==null||(i=o.onChange)===null||i===void 0||i.call(o,J),a.defaultPrevented)return;P.focus(h.current)}},M=function(a){var i;l(!0),o==null||(i=o.onFocus)===null||i===void 0||i.call(o,a)},L=function(a){var i;l(!1),o==null||(i=o.onBlur)===null||i===void 0||i.call(o,a)};s.useImperativeHandle(e,function(){return{props:o,focus:function(){return P.focus(h.current)},getElement:function(){return I.current},getInput:function(){return h.current}}}),s.useEffect(function(){F.combinedRefs(h,o.inputRef)},[h,o.inputRef]),re(function(){h.current.checked=R()},[o.checked,o.trueValue]),ne(function(){o.autoFocus&&P.focus(h.current,o.autoFocus)});var g=R(),V=F.isNotEmpty(o.tooltip),_=O.getOtherProps(o),$=r({id:o.id,className:A(o.className,y("root",{checked:g,context:n})),style:o.style,"data-p-highlight":g,"data-p-disabled":o.disabled,onContextMenu:o.onContextMenu,onMouseDown:o.onMouseDown},_,d("root")),H=function(){var a=F.reduceKeys(_,P.ARIA_PROPS),i=r(T({id:o.inputId,type:"checkbox",className:y("input"),name:o.name,tabIndex:o.tabIndex,onFocus:function(p){return M(p)},onBlur:function(p){return L(p)},onChange:function(p){return B(p)},disabled:o.disabled,readOnly:o.readOnly,required:o.required,"aria-invalid":o.invalid,checked:g},a),d("input"));return s.createElement("input",k({ref:h},i))},K=function(){var a=r({className:y("icon")},d("icon")),i=r({className:y("box",{checked:g}),"data-p-highlight":g,"data-p-disabled":o.disabled},d("box")),x=g?o.icon||s.createElement(ae,a):null,p=Y.getJSXIcon(x,T({},a),{props:o,checked:g});return s.createElement("div",i,p)};return s.createElement(s.Fragment,null,s.createElement("div",k({ref:I},$),H(),K()),V&&s.createElement(ie,k({target:I,content:o.tooltip,pt:d("tooltip")},o.tooltipOptions)))}));D.displayName="Checkbox";const N=t=>{const e=z.c(9),{id:r,name:n,label:o,required:f,className:u}=t;let c;e[0]!==u||e[1]!==r||e[2]!==o||e[3]!==n||e[4]!==f?(c=b=>{const{field:d}=b;return m.jsxs("div",{className:`flex align-items-center gap-2 ${u}`,children:[m.jsx(D,{inputId:r,name:n,checked:d.value,onChange:y=>d.onChange(y)}),m.jsxs("label",{htmlFor:r,children:[o," ",f?"*":""]})]})},e[0]=u,e[1]=r,e[2]=o,e[3]=n,e[4]=f,e[5]=c):c=e[5];let l;return e[6]!==n||e[7]!==c?(l=m.jsx(m.Fragment,{children:m.jsx(G,{name:n,render:c})}),e[6]=n,e[7]=c,e[8]=l):l=e[8],l};N.__docgenInfo={description:`Componente de checkbox controlado por react-hook-form.

Componente de checkbox que se integra automaticamente com o
FormProvider do react-hook-form. O label é exibido ao lado do checkbox,
diferente dos outros componentes que usam FloatLabel.

@remarks
Este componente deve ser usado dentro de um FormProvider do react-hook-form.
Não possui versão não-controlada pois checkboxes geralmente são usados em formulários.

@example
\`\`\`tsx
// Dentro de um FormProvider
<UiCheckboxControlled
  id="aceite-termos"
  name="aceiteTermos"
  label="Aceito os termos de uso"
  required
/>
\`\`\`

@see {@link https://primereact.org/checkbox/ | PrimeReact Checkbox}
@see {@link https://react-hook-form.com/docs/usecontroller/controller | React Hook Form Controller}`,methods:[],displayName:"UiCheckboxControlled",props:{id:{required:!0,tsType:{name:"string"},description:"Identificador único do campo, usado para associar o label ao input"},name:{required:!0,tsType:{name:"string"},description:"Nome do campo no formulário, usado pelo react-hook-form para registro"},label:{required:!0,tsType:{name:"string"},description:"Texto do label exibido ao lado do checkbox"},required:{required:!1,tsType:{name:"boolean"},description:"Indica se o campo é obrigatório (adiciona asterisco ao label)"},className:{required:!1,tsType:{name:"string"},description:"Classes CSS adicionais para o container do componente"}}};const Oe={title:"Components/Form/UiCheckboxControlled",component:N,parameters:{layout:"centered"},tags:["autodocs"],decorators:[t=>{const e=Q({defaultValues:{aceite:!1}});return m.jsx(Z,{methods:e,onSubmit:r=>console.log(r),children:m.jsx("div",{style:{width:"300px"},children:m.jsx(t,{})})})}],argTypes:{required:{control:"boolean",description:"Indica se o campo é obrigatório"}}},j={args:{id:"aceite",name:"aceite",label:"Aceito os termos"}},S={args:{id:"aceite-obrigatorio",name:"aceite",label:"Aceito os termos de uso",required:!0}},E={args:{id:"aceite-longo",name:"aceite",label:"Li e concordo com os termos de uso e política de privacidade da plataforma"}};j.parameters={...j.parameters,docs:{...j.parameters?.docs,source:{originalSource:`{
  args: {
    id: 'aceite',
    name: 'aceite',
    label: 'Aceito os termos'
  }
}`,...j.parameters?.docs?.source}}};S.parameters={...S.parameters,docs:{...S.parameters?.docs,source:{originalSource:`{
  args: {
    id: 'aceite-obrigatorio',
    name: 'aceite',
    label: 'Aceito os termos de uso',
    required: true
  }
}`,...S.parameters?.docs?.source}}};E.parameters={...E.parameters,docs:{...E.parameters?.docs,source:{originalSource:`{
  args: {
    id: 'aceite-longo',
    name: 'aceite',
    label: 'Li e concordo com os termos de uso e política de privacidade da plataforma'
  }
}`,...E.parameters?.docs?.source}}};const je=["Default","Required","LongLabel"];export{j as Default,E as LongLabel,S as Required,je as __namedExportsOrder,Oe as default};
