1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #ifndef FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_CALENDAR_PICKER_H
17 #define FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_CALENDAR_PICKER_H
18 
19 #include "frameworks/bridge/declarative_frontend/jsview/dialog/js_alert_dialog.h"
20 
21 namespace OHOS::Ace::Framework {
22 class JSCalendarPicker : public JSViewAbstract, public JSInteractableView {
23 public:
24     static void Create(const JSCallbackInfo& info);
25     static void JSBind(BindingTarget globalObj);
26 
27     static void SetEdgeAlign(const JSCallbackInfo& info);
28     static void SetTextStyle(const JSCallbackInfo& info);
29     static void SetOnChange(const JSCallbackInfo& info);
30     static void SetBorder(const JSCallbackInfo& info);
31     static void JsPadding(const JSCallbackInfo& info);
32     static void JsHeight(const JSCallbackInfo& info);
33     static void JsBorderColor(const JSCallbackInfo& info);
34     static void JsBorderRadius(const JSCallbackInfo& info);
35 
36 private:
37     static void ParseTextStyle(const JSRef<JSObject>& paramObj, NG::PickerTextStyle& textStyle);
38     static void ParseSelectedDateObject(const JSCallbackInfo& info, const JSRef<JSObject>& selectedObject);
39     static PickerDate ParseDate(const JSRef<JSVal>& dateVal);
40     static void ParseCalendarPickerBorderColor(const JSRef<JSVal>& args);
41     static NG::PaddingProperty SetPaddings(const std::optional<CalcDimension>& top,
42         const std::optional<CalcDimension>& bottom, const std::optional<CalcDimension>& left,
43         const std::optional<CalcDimension>& right);
44     static bool ParseJsDimensionVpWithCheck(const JSRef<JSVal>& jsValue, CalcDimension& result);
45 };
46 
47 class JSCalendarPickerDialog : JSAlertDialog {
48 public:
49     static void JSBind(BindingTarget globalObj);
50     static void Show(const JSCallbackInfo& info);
51     static void CalendarPickerDialogShow(const JSRef<JSObject>& paramObj,
52         const std::map<std::string, NG::DialogEvent>& dialogEvent,
53         const std::map<std::string, NG::DialogGestureEvent>& dialogCancelEvent,
54         const std::map<std::string, NG::DialogCancelEvent>& dialogLifeCycleEvent,
55         const std::vector<ButtonInfo>& buttonInfos);
56 
57 private:
58     static std::map<std::string, NG::DialogEvent> ChangeDialogEvent(const JSCallbackInfo& info);
59     static std::map<std::string, NG::DialogGestureEvent> DialogCancelEvent(const JSCallbackInfo& info);
60     static std::map<std::string, NG::DialogCancelEvent> LifeCycleDialogEvent(const JSCallbackInfo& info);
61 
62     static PickerDate ParseDate(const JSRef<JSVal>& dateVal);
63 };
64 } // namespace OHOS::Ace::Framework
65 #endif // FRAMEWORKS_BRIDGE_DECLARATIVE_FRONTEND_JS_VIEW_JS_CALENDAR_PICKER_H
66