{"version":3,"file":"use-dev-warnings.cjs","names":[],"sources":["../../../src/components/DataTable/use-dev-warnings.ts"],"sourcesContent":["import { useEffect } from \"react\";\n\nimport { isDevBuild } from \"../../utils/dev-mode\";\n\n/** What {@link useDevWarnings} needs to judge the prop combination. */\nexport interface DataTableDevWarningsInput {\n    /** Whether `totalItems` was passed. */\n    serverMode: boolean;\n    /** The controlled `page`, if any. */\n    controlledPage: number | undefined;\n    /** The page callback, if any. */\n    onPageChange: ((page: number) => void) | undefined;\n    /** Whether sorting is delegated. */\n    sortIsManual: boolean;\n    /** Whether any column renders a header the user can click to sort. */\n    hasSortableColumn: boolean;\n    /** The sort callback, if any. */\n    onSortChange: ((sort: never) => void) | undefined;\n    /** Whether a search box is rendered at all. */\n    searchable: boolean;\n    /** The search callback, if any. */\n    onSearchChange: ((term: string) => void) | undefined;\n}\n\n/**\n * Warn, in development only, about prop combinations that render a table which\n * silently lies.\n *\n * Each of these produces a screen that looks like it works: the header sorts and\n * nothing moves, the pager renders and clicking it does nothing.\n *\n * Three of them **are** type errors now — `DataTablePagingProps`,\n * `DataTableSortProps` and `DataTableSearchProps` reject them at the call site —\n * so those warnings only reach a caller the types cannot: plain JavaScript, or\n * props arriving through an `any`-typed spread.\n *\n * Each one also has to be reachable. `totalItems` implies `manualSort`, so the\n * sort warning fired on every server-mode table — including one whose columns are\n * all plain, where no header is clickable and the sentence it prints (\"clicking a\n * sortable header changes the arrow and nothing else\") describes a state the user\n * cannot reach. A warning nobody can act on is not a warning: it teaches the\n * reader to skim past the two next to it, which *are* real, and the way out it\n * suggests is `onSortChange={() => {}}` — a callback that does nothing, that the\n * type-checker accepts, and that would hide the warning on the day a `sortable`\n * column does appear. So the sort warning asks for a sortable column first, the\n * way the search one already asks for `searchable`.\n *\n * The fourth is the one the types genuinely cannot afford. `totalItems` *implies*\n * `manualSearch`, so `searchable` with no `onSearchChange` is an inert search box\n * in server mode without anybody writing `manualSearch`. Expressing that means\n * the search axis has to read the paging axis, crossing two three-member unions\n * into nine — so it stays here, which is what \"runtime is the cheaper check\"\n * actually looks like when it is true.\n *\n * @param input - The resolved prop combination.\n */\nexport function useDevWarnings({\n    serverMode,\n    controlledPage,\n    onPageChange,\n    sortIsManual,\n    hasSortableColumn,\n    onSortChange,\n    searchable,\n    onSearchChange,\n}: DataTableDevWarningsInput): void {\n    useEffect(() => {\n        if (!isDevBuild()) return;\n\n        if (serverMode && controlledPage === undefined) {\n            console.warn(\n                \"[tempest] <DataTable totalItems> is server mode, which needs a controlled `page`. \" +\n                    \"Without it the pager moves the internal page while `data` keeps showing page 1.\",\n            );\n        }\n        if (controlledPage !== undefined && !onPageChange) {\n            console.warn(\n                \"[tempest] <DataTable page> is controlled but `onPageChange` is missing, so the pager cannot do anything.\",\n            );\n        }\n        if (serverMode && searchable && !onSearchChange) {\n            console.warn(\n                \"[tempest] <DataTable totalItems searchable> delegates searching, so the box needs \" +\n                    \"`onSearchChange`. Without it the user types and nothing filters and nothing is reported.\",\n            );\n        }\n        if (sortIsManual && hasSortableColumn && !onSortChange) {\n            console.warn(\n                \"[tempest] <DataTable> is sorting manually but `onSortChange` is missing: clicking a sortable header changes the arrow and nothing else.\",\n            );\n        }\n    }, [\n        serverMode,\n        controlledPage,\n        onPageChange,\n        sortIsManual,\n        hasSortableColumn,\n        onSortChange,\n        searchable,\n        onSearchChange,\n    ]);\n}\n"],"mappings":"mEAwDA,SAAgB,EAAe,CAC3B,aACA,iBACA,eACA,eACA,oBACA,eACA,aACA,kBACgC,EAChC,EAAA,EAAA,UAAA,KAAgB,CACP,EAAA,WAAW,IAEZ,GAAc,IAAmB,IAAA,IACjC,QAAQ,KACJ,mKAEJ,EAEA,IAAmB,IAAA,IAAa,CAAC,GACjC,QAAQ,KACJ,0GACJ,EAEA,GAAc,GAAc,CAAC,GAC7B,QAAQ,KACJ,4KAEJ,EAEA,GAAgB,GAAqB,CAAC,GACtC,QAAQ,KACJ,yIACJ,EAER,EAAG,CACC,EACA,EACA,EACA,EACA,EACA,EACA,EACA,CACJ,CAAC,CACL"}