1 /*
<lambda>null2  * Copyright (C) 2023 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.car.customization.tool.domain.panel
18 
19 /**
20  * The model of a Panel.
21  *
22  * @property items the list of [PanelItem] that are shown in a panel.
23  */
24 internal data class Panel(
25     val headerItems: List<PanelHeaderItem> = listOf(PanelHeaderItem.CloseButton),
26     val items: List<PanelItem>
27 )
28 
29 internal sealed class PanelHeaderItem {
30 
31     data class SearchBox(
32         val searchHint: String,
33         val searchAction: (String) -> PanelAction,
34     ) : PanelHeaderItem()
35 
36     object CloseButton : PanelHeaderItem() {
37         val action: PanelAction = ClosePanelAction
38     }
39 
40     data class DropDown(
41         val text: String,
42         val items: List<Item>
43     ) : PanelHeaderItem() {
44         data class Item(
45             val text: String,
46             val action: PanelAction,
47             val isActive: Boolean
48         )
49 
50         fun selectDropDownItem(action: PanelAction): DropDown = copy(
51             items = items.map { item -> item.copy(isActive = item.action == action) }
52         )
53     }
54 }
55 
56 /**
57  * The base for all items that can be shown in a Panel.
58  *
59  * @property isEnabled defines if an item is enabled, users can't interact with disabled items.
60  */
61 internal sealed class PanelItem(open val isEnabled: Boolean) {
62 
63     data class SectionTitle(
64         val text: String,
65     ) : PanelItem(isEnabled = true)
66 
67     data class Switch(
68         val text: String,
69         val errorText: String?,
70         val isChecked: Boolean,
71         override val isEnabled: Boolean,
72         val action: PanelAction,
73     ) : PanelItem(isEnabled)
74 }
75