import{j as r}from"./assertThisInitialized-ClXgY4BW.js";import{r as b}from"./index-BP8_t0zE.js";import{d as g}from"./dataProvider-BSMCbdJg.js";import{u as m}from"./FormGroupsProvider-B1X-6k0S.js";import{G as k}from"./api-D469Uxm1.js";import{B as S}from"./Button-C3j8Wgdd.js";import{S as a,T as i}from"./SimpleForm-DxY-i_Qk.js";import{N as h}from"./NumberInput-D5bldgKh.js";import{A as R}from"./AdminContext-jMMnnv4u.js";import{d as w}from"./defaultI18nProvider-C_r1y4tu.js";import"./Clear-2k3OxyE6.js";import"./createSvgIcon-BeVLBbd8.js";import"./createSvgIcon-C1LdFc73.js";import"./TextField-z9WrHgJg.js";import"./useFormControl-D0zEVldg.js";import"./Modal-CloRq8hE.js";import"./Typography-E7d16C50.js";import"./getFieldLabelTranslationArgs-DwcCC9dO.js";import"./colorManipulator-DXmmM2jC.js";import"./useResourceContext-BI9mATY-.js";import"./useRecordContext-CmNI-aHo.js";import"./CircularProgress-CoZCnRya.js";import"./DeleteButton-BNKEwqMZ.js";import"./Confirm-BXDL5GEC.js";import"./useRemoveFromStore-DvPdj666.js";import"./useRedirect-BE8GZC2N.js";import"./useMutation-DBpLFNEy.js";import"./useLogout-DAYYFX4P.js";import"./useDataProvider-BTi1EEZL.js";import"./undoableEventEmitter-DTIdLI-s.js";import"./warning-3oRADCZr.js";import"./Toolbar-C8uTbHq-.js";import"./Stack-BmeOikgJ.js";import"./CardContent-C5u1opi3.js";import"./merge-2TaxnYbe.js";import"./_copyObject-Dr_k0OJK.js";import"./isArrayLikeObject-WBq23Ido.js";import"./identity-B2iMGpmP.js";import"./_isIterateeCall-D0xvKagp.js";import"./OptionalRecordContextProvider-ChL7EZ8k.js";import"./PreferencesEditorContext-oPOmBo-a.js";import"./index-qEiLzbkV.js";import"./index-BCKAMao3.js";const jr={title:"Forms/Hooks",decorators:[e=>y(e)]},o={render:()=>{let{reset:e}=m();const t=b.useCallback(()=>{e()},[e]);return r.jsx(S,{onClick:t,label:"Reset form"})},decorators:[e=>r.jsxs(a,{toolbar:r.jsx(r.Fragment,{}),children:[r.jsx(i,{source:"name"}),r.jsx(h,{source:"age"}),r.jsx(e,{})]})]},n={render:()=>{let{resetField:e,watch:t}=m();const C=t("name",null),I=b.useCallback(()=>{e("name")},[C,e]);return r.jsx(S,{onClick:I,label:"Reset name"})},decorators:[e=>r.jsxs(a,{toolbar:r.jsx(r.Fragment,{}),children:[r.jsx(i,{source:"name"}),r.jsx(h,{source:"age"}),r.jsx(e,{})]})]},s={render:()=>{let{watch:e}=m();const t=e("name",null);return r.jsxs(k.Exclude,{children:["Field value: ",t]})},decorators:[e=>r.jsxs(a,{toolbar:r.jsx(r.Fragment,{}),children:[r.jsx(i,{source:"name"}),r.jsx(e,{})]})]},y=e=>r.jsx(R,{dataProvider:g,i18nProvider:w,children:r.jsx(e,{})});var l,c,u;o.parameters={...o.parameters,docs:{...(l=o.parameters)==null?void 0:l.docs,source:{originalSource:`{
  render: () => {
    let {
      reset
    } = useFormContext();
    const resetForm = useCallback(() => {
      reset();
    }, [reset]);
    return <Button onClick={resetForm} label="Reset form" />;
  },
  decorators: [Story => {
    return <SimpleForm toolbar={<></>}>
                <TextInput source="name" />
                <NumberInput source="age" />
                <Story />
            </SimpleForm>;
  }]
}`,...(u=(c=o.parameters)==null?void 0:c.docs)==null?void 0:u.source}}};var p,d,x;n.parameters={...n.parameters,docs:{...(p=n.parameters)==null?void 0:p.docs,source:{originalSource:`{
  render: () => {
    let {
      resetField,
      watch
    } = useFormContext();
    const fieldValue = watch("name", null);
    const resetForm = useCallback(() => {
      resetField("name");
    }, [fieldValue, resetField]);
    return <Button onClick={resetForm} label="Reset name" />;
  },
  decorators: [Story => {
    return <SimpleForm toolbar={<></>}>
                <TextInput source="name" />
                <NumberInput source="age" />
                <Story />
            </SimpleForm>;
  }]
}`,...(x=(d=n.parameters)==null?void 0:d.docs)==null?void 0:x.source}}};var F,f,j;s.parameters={...s.parameters,docs:{...(F=s.parameters)==null?void 0:F.docs,source:{originalSource:`{
  render: () => {
    let {
      watch
    } = useFormContext();
    const fieldValue = watch("name", null);
    return <GenerationInstructions.Exclude>
            Field value: {fieldValue}
        </GenerationInstructions.Exclude>;
  },
  decorators: [Story => {
    return <SimpleForm toolbar={<></>}>
                <TextInput source="name" />
                <Story />
            </SimpleForm>;
  }]
}`,...(j=(f=s.parameters)==null?void 0:f.docs)==null?void 0:j.source}}};const br=["ResetForm","ResetField","WatchField"];export{n as ResetField,o as ResetForm,s as WatchField,br as __namedExportsOrder,jr as default};
