1 | "use strict";
|
2 | var __importStar = (this && this.__importStar) || function (mod) {
|
3 | if (mod && mod.__esModule) return mod;
|
4 | var result = {};
|
5 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
6 | result["default"] = mod;
|
7 | return result;
|
8 | };
|
9 | Object.defineProperty(exports, "__esModule", { value: true });
|
10 | var React = __importStar(require("react"));
|
11 | var utils_1 = require("../../_helpers/utils");
|
12 | function useViews(views, openTo, onChange) {
|
13 | var _a = React.useState(openTo && utils_1.arrayIncludes(views, openTo) ? openTo : views[0]), openView = _a[0], setOpenView = _a[1];
|
14 | var handleChangeAndOpenNext = React.useCallback(function (date, isFinish) {
|
15 | var nextViewToOpen = views[views.indexOf(openView) + 1];
|
16 | if (isFinish && nextViewToOpen) {
|
17 |
|
18 | onChange(date, false);
|
19 | setOpenView(nextViewToOpen);
|
20 | return;
|
21 | }
|
22 | onChange(date, Boolean(isFinish));
|
23 | }, [onChange, openView, views]);
|
24 | return { handleChangeAndOpenNext: handleChangeAndOpenNext, openView: openView, setOpenView: setOpenView };
|
25 | }
|
26 | exports.useViews = useViews;
|