import{u as p,a as r,T as n,j as t,Q as m,A as y,d as g,b as v}from"./dataProvider-3f13e24d.js";import{u as f}from"./useMutation-5bff67ad.js";import{u as D,B as h}from"./Button-a22a3ea5.js";const b={title:"Blocks/DataFetching/UseMutation",parameters:{layout:"centered"},decorators:[e=>P(e)],args:{record:p[0]}},a={render:({record:e,name:i,...T})=>{const u=D(),{mutate:l,isLoading:c}=f(()=>u.update("users",{id:e.id,data:{name:i},previousData:e}));return r("div",{children:[r(n,{children:["ID: ",e.id]}),r(n,{children:["Name: ",e.name]}),t(h,{label:"Update user",onClick:()=>l(),disabled:c})]})},args:{name:"Burr"}},P=e=>(new m({defaultOptions:{queries:{retry:!1,structuralSharing:!1},mutations:{retryDelay:1e4}}}),t(y,{dataProvider:g,i18nProvider:v,children:t(e,{})}));var o,s,d;a.parameters={...a.parameters,docs:{...(o=a.parameters)==null?void 0:o.docs,source:{originalSource:`{
  // decorators: [(Story) => {
  //   return (
  //     <div>
  //       <Button label="Update user" onClick={() => mutate()} disabled={isLoading} />
  //     </div>
  //   )
  // }],
  render: ({
    record,
    name,
    ...props
  }: any) => {
    const dataProvider = useDataProvider();
    const {
      mutate,
      isLoading
    } = useMutation(() => dataProvider.update("users", {
      id: record.id,
      data: {
        name
      },
      previousData: record
    }));
    return <div>
        <Typography>ID: {record.id}</Typography>
        <Typography>Name: {record.name}</Typography>
        {/** illustrate update like notification */}
        <Button label="Update user" onClick={() => mutate()} disabled={isLoading} />
      </div>;
  },
  args: {
    name: 'Burr'
  }
}`,...(d=(s=a.parameters)==null?void 0:s.docs)==null?void 0:d.source}}};const B=["Default"],j=Object.freeze(Object.defineProperty({__proto__:null,Default:a,__namedExportsOrder:B,default:b},Symbol.toStringTag,{value:"Module"}));export{a as D,j as U};
