import{j as r}from"./assertThisInitialized-ClXgY4BW.js";import{d as l,b as x}from"./dataProvider-BSMCbdJg.js";import{G as a,t as f}from"./api-D469Uxm1.js";import{r as h,a as b}from"./ideExtension-Duoj5XVI.js";import{A as j}from"./utils-CkyKHvS2.js";import{T as m}from"./Typography-E7d16C50.js";import{S as R,L as p}from"./SimpleShowLayout-Bj8OsoZA.js";import{S}from"./Show-CQpDTbX7.js";import{T as i}from"./TextField-n0Myx-gm.js";import{A as y}from"./AdminContext-jMMnnv4u.js";import{d as L}from"./defaultI18nProvider-C_r1y4tu.js";import{R as T}from"./ResourceContextProvider-_t2ysSg2.js";import{R as C,u as g}from"./useRecordContext-CmNI-aHo.js";import{L as v}from"./List-D8wQapDP.js";import{C as I}from"./CreateButton-BoKnyQsN.js";import{D}from"./Datagrid-BK2vyqjN.js";import"./index-BP8_t0zE.js";import"./useResourceDefinitionContext-mEDLreK0.js";import"./useAuthenticated-CxLvTTH7.js";import"./_isIterateeCall-D0xvKagp.js";import"./identity-B2iMGpmP.js";import"./useAuthState-Chcbfem2.js";import"./colorManipulator-DXmmM2jC.js";import"./Button-C3j8Wgdd.js";import"./useQuery-DJhJ3Hj4.js";import"./useLogout-DAYYFX4P.js";import"./useResourceContext-BI9mATY-.js";import"./useGetRecordRepresentation-DwGaoA_n.js";import"./useRedirect-BE8GZC2N.js";import"./useRefresh-BVYjI9Ho.js";import"./useGetOne-Ddk2GsYy.js";import"./useDataProvider-BTi1EEZL.js";import"./TopToolbar-BqW7kXvQ.js";import"./Toolbar-C8uTbHq-.js";import"./EditButton-DudJBc_J.js";import"./createSvgIcon-BeVLBbd8.js";import"./createSvgIcon-C1LdFc73.js";import"./index-qEiLzbkV.js";import"./index-BCKAMao3.js";import"./Card-Cv9uZOGS.js";import"./Modal-CloRq8hE.js";import"./Title-Db_cbkJo.js";import"./PreferencesEditorContext-oPOmBo-a.js";import"./TextField-z9WrHgJg.js";import"./useFormControl-D0zEVldg.js";import"./warning-3oRADCZr.js";import"./Stack-BmeOikgJ.js";import"./getFieldLabelTranslationArgs-DwcCC9dO.js";import"./OptionalRecordContextProvider-ChL7EZ8k.js";import"./ListView-BNoLT4yC.js";import"./FormGroupsProvider-B1X-6k0S.js";import"./cloneDeep-BX3t29rH.js";import"./_copyObject-Dr_k0OJK.js";import"./ListNoResults-BHi6V5m8.js";import"./pick-BQz50zYv.js";import"./hasIn-BUTlUeuZ.js";import"./useGetList-Dit6Yzrj.js";import"./useRemoveFromStore-DvPdj666.js";import"./debounce-0x2xWYwC.js";import"./hooks-kyAPvxe4.js";import"./CardContent-C5u1opi3.js";import"./Clear-2k3OxyE6.js";import"./MenuItem-CP3dxiK8.js";import"./listItemTextClasses-C7xWMLDP.js";import"./ListItemText-Cc_vo_cp.js";import"./Confirm-BXDL5GEC.js";import"./ListBase-CEqRUlEo.js";import"./merge-2TaxnYbe.js";import"./isArrayLikeObject-WBq23Ido.js";import"./SwitchBase-GsdOADyY.js";import"./_baseUniq-BtunyI9N.js";import"./ExpandMore-Bu7ZqolT.js";import"./useMutation-DBpLFNEy.js";import"./undoableEventEmitter-DTIdLI-s.js";const Yr={title:"Relations/SubTable",component:j,decorators:[e=>w(e)]},t={render:({subresourceName:e,subresourceBackReference:s,...N})=>{const d=f(()=>{const o=g();return o?r.jsxs(v,{disableSyncWithLocation:!0,resource:e,filter:{[s]:o.id},sx:{width:"100%"},actions:r.jsx(I,{state:{record:{[s]:o.id}}}),title:r.jsx("span",{}),children:[r.jsx(a.Exclude,{children:r.jsx(m,{variant:"h6",children:"Department users"})}),r.jsx(D,{children:r.jsx(i,{source:"id"})})]}):r.jsx(r.Fragment,{})});return r.jsxs(S,{resource:"departments",id:2,children:[r.jsxs(R,{children:[r.jsx(m,{variant:"h5",children:"Department"}),r.jsx(p,{children:r.jsx(i,{source:"id"})}),r.jsx(p,{children:r.jsx(i,{source:"name"})})]}),r.jsx(a.InsertOnly,{children:r.jsx(d,{})})]})},args:{subresourceName:h("users",{title:"Child Resource",resourceId:"subresource",allowContext:!1}),subresourceBackReference:b("department_id",{resourceId:"subresource",attributeSelectTitle:"Reference Attribute from Child Resource to Main Resource"})}},w=e=>r.jsx(y,{dataProvider:l,i18nProvider:L,children:r.jsx(T,{value:"departments",children:r.jsx(C,{value:x[2],children:r.jsx(e,{})})})});var n,c,u;t.parameters={...t.parameters,docs:{...(n=t.parameters)==null?void 0:n.docs,source:{originalSource:`{
  render: ({
    subresourceName,
    subresourceBackReference,
    ...props
  }) => {
    const SubTable = topLevel(() => {
      const record = useRecordContext();
      if (!record) {
        return <></>;
      }
      return <List disableSyncWithLocation resource={subresourceName} filter={{
        [subresourceBackReference]: record.id
      }} sx={{
        width: "100%"
      }} actions={<CreateButton state={{
        record: {
          [subresourceBackReference]: record.id
        }
      }} />} title={<span />}>
                        <GenerationInstructions.Exclude>
                            <Typography variant="h6">Department users</Typography>
                        </GenerationInstructions.Exclude>
                        <Datagrid>
                            <TextField source="id" />
                            {/*  use 'field' completion to generate other fields  */}
                        </Datagrid>
                    </List>;
    });
    return <Show resource='departments' id={2}>
                <SimpleShowLayout>
                    <Typography variant="h5">Department</Typography>

                    <Labeled>
                        <TextField source="id" />
                    </Labeled>

                    <Labeled>
                        <TextField source="name" />
                    </Labeled>
                </SimpleShowLayout>

                <GenerationInstructions.InsertOnly>
                    <SubTable />
                </GenerationInstructions.InsertOnly>
            </Show>;
  },
  args: {
    subresourceName: resourceName("users", {
      title: 'Child Resource',
      resourceId: 'subresource',
      allowContext: false
    }),
    subresourceBackReference: attributeName("department_id", {
      resourceId: 'subresource',
      attributeSelectTitle: 'Reference Attribute from Child Resource to Main Resource'
    })
  }
}`,...(u=(c=t.parameters)==null?void 0:c.docs)==null?void 0:u.source}}};const Zr=["Default"];export{t as Default,Zr as __namedExportsOrder,Yr as default};
