100aff185Sopenharmony_ci/*
200aff185Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd.
300aff185Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
400aff185Sopenharmony_ci * you may not use this file except in compliance with the License.
500aff185Sopenharmony_ci * You may obtain a copy of the License at
600aff185Sopenharmony_ci *
700aff185Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
800aff185Sopenharmony_ci *
900aff185Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
1000aff185Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
1100aff185Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1200aff185Sopenharmony_ci * See the License for the specific language governing permissions and
1300aff185Sopenharmony_ci * limitations under the License.
1400aff185Sopenharmony_ci */
1500aff185Sopenharmony_ci
1600aff185Sopenharmony_ciimport { Action, Log } from '@ohos/common';
1700aff185Sopenharmony_ciimport { ToolBar } from '@ohos/common/CommonComponents';
1800aff185Sopenharmony_ci
1900aff185Sopenharmony_ciconst TAG: string = 'timeline_TimelinePageToolBar';
2000aff185Sopenharmony_ci
2100aff185Sopenharmony_ci@Component
2200aff185Sopenharmony_ciexport struct TimelinePageToolBar {
2300aff185Sopenharmony_ci  @Consume @Watch('updateToolbar') isSelectedMode: boolean;
2400aff185Sopenharmony_ci  @Consume @Watch('updateToolbar') isAllSelected: boolean;
2500aff185Sopenharmony_ci  @Link @Watch('updateToolbar') totalSelectedCount: number;
2600aff185Sopenharmony_ci  @Provide selectedCount: number = 0;
2700aff185Sopenharmony_ci  onMenuClicked: Function = (): void => {};
2800aff185Sopenharmony_ci  @Provide toolMenuList: Action[] = [];
2900aff185Sopenharmony_ci  @Consume moreMenuList: Action[];
3000aff185Sopenharmony_ci  @Consume hidePopup: boolean;
3100aff185Sopenharmony_ci
3200aff185Sopenharmony_ci  aboutToAppear(): void {
3300aff185Sopenharmony_ci    this.updateToolbar();
3400aff185Sopenharmony_ci  }
3500aff185Sopenharmony_ci
3600aff185Sopenharmony_ci  build() {
3700aff185Sopenharmony_ci    ToolBar({
3800aff185Sopenharmony_ci      onMenuClicked: this.onMenuClicked
3900aff185Sopenharmony_ci    })
4000aff185Sopenharmony_ci  }
4100aff185Sopenharmony_ci
4200aff185Sopenharmony_ci  private updateToolbar(): void {
4300aff185Sopenharmony_ci    Log.info(TAG, 'updateToolbar');
4400aff185Sopenharmony_ci    this.selectedCount = this.totalSelectedCount;
4500aff185Sopenharmony_ci    if (this.isSelectedMode) {
4600aff185Sopenharmony_ci      Log.info(TAG, 'pushActionToolbar');
4700aff185Sopenharmony_ci      this.toolMenuList = [];
4800aff185Sopenharmony_ci      this.toolMenuList.push(
4900aff185Sopenharmony_ci        this.isAllSelected ? Action.DESELECT_ALL : Action.SELECT_ALL,
5000aff185Sopenharmony_ci        Boolean(this.selectedCount) ? Action.DELETE : Action.DELETE_INVALID, Action.MORE);
5100aff185Sopenharmony_ci    }
5200aff185Sopenharmony_ci  }
5300aff185Sopenharmony_ci}