1/*
2 * Copyright (c) 2024 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
16const pip = requireNapi('pip');
17const NodeController = requireNapi('arkui.node').NodeController;
18const FrameNode = requireNapi('arkui.node').FrameNode;
19
20const TAG = 'PiPContent';
21const ABOUT_TO_STOP = 3;
22
23class XCNodeController extends NodeController {
24    constructor(k2) {
25        super();
26        this.node = null;
27        this.mXComponent = k2;
28    }
29
30    makeNode(i2) {
31        let j2;
32        this.node = new FrameNode(i2);
33        this.node.appendChild(this.mXComponent);
34        return this.node;
35    }
36
37    removeNode() {
38        let h2;
39        (h2 = this.node) === null || h2 === void 0 ? void 0 : h2.removeChild(this.mXComponent);
40    }
41}
42
43export class PiPContent extends ViewPU {
44    constructor(b2, c2, d2, e2 = -1, f2 = undefined, g2) {
45        super(b2, d2, e2, g2);
46        if (typeof f2 === 'function') {
47            this.paramsGenerator_ = f2;
48        }
49        this.xComponentController = new XComponentController;
50        this.nodeController = null;
51        this.mXCNodeController = null;
52        this.useNode = false;
53        this.xComponentId = 'pipContent';
54        this.xComponentType = 'surface';
55        this.xComponent = null;
56        this.setInitiallyProvidedValue(c2);
57    }
58
59    setInitiallyProvidedValue(a2) {
60        if (a2.xComponentController !== undefined) {
61            this.xComponentController = a2.xComponentController;
62        }
63        if (a2.nodeController !== undefined) {
64            this.nodeController = a2.nodeController;
65        }
66        if (a2.mXCNodeController !== undefined) {
67            this.mXCNodeController = a2.mXCNodeController;
68        }
69        if (a2.useNode !== undefined) {
70            this.useNode = a2.useNode;
71        }
72        if (a2.xComponentId !== undefined) {
73            this.xComponentId = a2.xComponentId;
74        }
75        if (a2.xComponentType !== undefined) {
76            this.xComponentType = a2.xComponentType;
77        }
78        if (a2.xComponent !== undefined) {
79            this.xComponent = a2.xComponent;
80        }
81    }
82
83    updateStateVars(z1) {
84    }
85
86    purgeVariableDependenciesOnElmtId(y1) {
87    }
88
89    aboutToAppear() {
90        this.nodeController = pip.getCustomUIController();
91        this.xComponent = pip.getTypeNode();
92        if (this.xComponent === null || this.xComponent === undefined) {
93            console.error(TAG, `xComponent node is null`);
94            return;
95        }
96        let u1 = this.xComponent.getNodeType();
97        if (u1 !== 'XComponent') {
98            console.error(`xComponent type mismatch: ${u1}`);
99            return;
100        }
101        this.useNode = true;
102        let parent = this.xComponent.getParent();
103        if (parent === null || parent === undefined) {
104            pip.setPipNodeType(this.xComponent, false);
105        } else {
106            pip.setPipNodeType(this.xComponent, true);
107            parent.removeChild(this.xComponent);
108        }
109        pip.setTypeNodeEnabled();
110        this.mXCNodeController = new XCNodeController(this.xComponent);
111        console.info(TAG, 'use Node Controller');
112        pip.on('stateChange', (w1) => {
113            let x1;
114            console.info(TAG, `stateChange state: ${w1}`);
115            if (w1 === ABOUT_TO_STOP) {
116                (x1 = this.mXCNodeController) === null || x1 === void 0 ? void 0 : x1.removeNode();
117            }
118        });
119    }
120
121    aboutToBeDeleted() {
122        SubscriberManager.Get().delete(this.id__());
123        this.aboutToBeDeletedInternal();
124    }
125
126    aboutToDisappear() {
127        pip.off('stateChange');
128    }
129
130    initialRender() {
131        this.observeComponentCreation2((s1, t1) => {
132            Stack.create();
133            Stack.size({ width: '100%', height: '100%' });
134        }, Stack);
135        this.observeComponentCreation2((h1, i1) => {
136            If.create();
137            if (this.useNode) {
138                this.ifElseBranchUpdateFunction(0, () => {
139                    this.buildNode.bind(this)();
140                });
141            } else {
142                this.ifElseBranchUpdateFunction(1, () => {
143                    this.buildXComponent.bind(this)();
144                });
145            }
146        }, If);
147        If.pop();
148        this.observeComponentCreation2((a1, b1) => {
149            If.create();
150            if (this.nodeController !== null) {
151                this.ifElseBranchUpdateFunction(0, () => {
152                    this.buildCustomUI.bind(this)();
153                });
154            } else {
155                this.ifElseBranchUpdateFunction(1, () => {
156                });
157            }
158        }, If);
159        If.pop();
160        Stack.pop();
161    }
162
163    buildCustomUI(g1 = null) {
164        this.observeComponentCreation2((i1, j1) => {
165            NodeContainer.create(this.nodeController);
166            NodeContainer.size({ width: '100%', height: '100%'});
167        }, NodeContainer);
168    }
169
170    buildXComponent(b1 = null) {
171        this.observeComponentCreation2((d1, e1) => {
172            XComponent.create({
173                id: this.xComponentId,
174                type: this.xComponentType,
175                controller: this.xComponentController
176            }, 'pipContent_XComponent');
177            XComponent.onLoad((() => {
178                pip.initXComponentController(this.xComponentController);
179                console.info(TAG, 'XComponent onLoad done');
180            }));
181            XComponent.size({ width: '100%', height: '100%' });
182            XComponent.backgroundColor(Color.Transparent);
183        }, XComponent);
184    }
185
186    buildNode(x = null) {
187        this.observeComponentCreation2((z, a1) => {
188            NodeContainer.create(this.mXCNodeController);
189            NodeContainer.size({ width: '100%', height: '100%' });
190        }, NodeContainer);
191    }
192
193    rerender() {
194        this.updateDirtyElements();
195    }
196
197    static getEntryName() {
198        return 'PiPContent';
199    }
200}
201
202ViewStackProcessor.StartGetAccessRecordingFor(ViewStackProcessor.AllocateNewElmetIdForNextComponent());
203loadDocument(new PiPContent(void 0, {}));
204ViewStackProcessor.StopGetAccessRecording();