33
44import Modal from '../design-system/components/modal/modal.js' ;
55
6- const status = document . getElementById ( 'status' ) ;
7-
86// App state
97let counterValue = 0 ;
108let incrementAmount = 1 ;
119let counterLabel = 'Counter' ;
1210let dropdownInstance = null ;
1311let helpModal = null ;
1412
15- function setStatus ( msg ) {
16- if ( status ) {
17- status . textContent = msg ;
18- }
19- }
20-
21- // Update counter display
22- function updateCounterDisplay ( ) {
13+ // Update counter display
14+ function updateCounterDisplay ( ) {
2315 const counterDisplay = document . getElementById ( 'counter-value' ) ;
2416 const labelDisplay = document . getElementById ( 'display-label' ) ;
2517 const labelValueDisplay = document . getElementById ( 'display-label-value' ) ;
@@ -43,10 +35,10 @@ let helpModal = null;
4335
4436 // Update status tags
4537 updateStatusTags ( ) ;
46- }
38+ }
4739
48- // Update status tags based on counter value
49- function updateStatusTags ( ) {
40+ // Update status tags based on counter value
41+ function updateStatusTags ( ) {
5042 const primaryTag = document . getElementById ( 'status-tag-primary' ) ;
5143 const positiveTag = document . getElementById ( 'status-tag-positive' ) ;
5244 const negativeTag = document . getElementById ( 'status-tag-negative' ) ;
@@ -64,31 +56,28 @@ let helpModal = null;
6456 if ( positiveTag ) positiveTag . style . display = 'none' ;
6557 if ( negativeTag ) negativeTag . style . display = 'none' ;
6658 }
67- }
59+ }
6860
69- // Increment counter
70- function incrementCounter ( ) {
61+ // Increment counter
62+ function incrementCounter ( ) {
7163 counterValue += incrementAmount ;
7264 updateCounterDisplay ( ) ;
73- setStatus ( 'Counter incremented' ) ;
74- }
65+ }
7566
76- // Decrement counter
77- function decrementCounter ( ) {
67+ // Decrement counter
68+ function decrementCounter ( ) {
7869 counterValue -= incrementAmount ;
7970 updateCounterDisplay ( ) ;
80- setStatus ( 'Counter decremented' ) ;
81- }
71+ }
8272
83- // Reset counter
84- function resetCounter ( ) {
73+ // Reset counter
74+ function resetCounter ( ) {
8575 counterValue = 0 ;
8676 updateCounterDisplay ( ) ;
87- setStatus ( 'Counter reset' ) ;
88- }
77+ }
8978
90- // Initialize dropdown component
91- function initializeDropdown ( ) {
79+ // Initialize dropdown component
80+ function initializeDropdown ( ) {
9281 if ( typeof window . Dropdown === 'undefined' ) {
9382 console . error ( 'Dropdown class not found. Make sure dropdown.js is loaded.' ) ;
9483 return ;
@@ -109,16 +98,15 @@ let helpModal = null;
10998 onSelect : ( value ) => {
11099 incrementAmount = parseInt ( value , 10 ) ;
111100 updateCounterDisplay ( ) ;
112- setStatus ( `Increment amount set to ${ incrementAmount } ` ) ;
113101 }
114102 } ) ;
115103 } catch ( error ) {
116104 console . error ( 'Error initializing dropdown:' , error ) ;
117105 }
118- }
106+ }
119107
120- // Initialize event listeners
121- function initializeEventListeners ( ) {
108+ // Initialize event listeners
109+ function initializeEventListeners ( ) {
122110 // Sidebar controls
123111 const btnIncrement = document . getElementById ( 'btn-increment' ) ;
124112 const btnDecrement = document . getElementById ( 'btn-decrement' ) ;
@@ -145,13 +133,12 @@ let helpModal = null;
145133 counterLabelInput . addEventListener ( 'input' , ( e ) => {
146134 counterLabel = e . target . value || 'Counter' ;
147135 updateCounterDisplay ( ) ;
148- setStatus ( 'Label updated' ) ;
149136 } ) ;
150137 }
151- }
138+ }
152139
153- // Initialize help modal
154- async function initializeHelpModal ( ) {
140+ // Initialize help modal
141+ async function initializeHelpModal ( ) {
155142 try {
156143 const response = await fetch ( './help-content.html' ) ;
157144 const helpContent = await response . text ( ) ;
@@ -185,28 +172,20 @@ let helpModal = null;
185172 } ) ;
186173 }
187174 }
188- }
189-
190- // Initialize everything when DOM is ready
191- async function initialize ( ) {
192- setStatus ( 'Loading...' ) ;
193-
194- // Initialize event listeners
195- initializeEventListeners ( ) ;
196-
197- // Initialize help modal
198- await initializeHelpModal ( ) ;
199-
200- // Initialize dropdown after a short delay to ensure Dropdown class is loaded
201- setTimeout ( ( ) => {
202- initializeDropdown ( ) ;
203- updateCounterDisplay ( ) ;
204- setStatus ( 'Ready' ) ;
205- } , 100 ) ;
206- }
207-
208- if ( document . readyState === 'loading' ) {
209- document . addEventListener ( 'DOMContentLoaded' , initialize ) ;
210- } else {
211- initialize ( ) ;
212- }
175+ }
176+
177+ // Initialize everything when DOM is ready
178+ async function initialize ( ) {
179+ initializeEventListeners ( ) ;
180+ await initializeHelpModal ( ) ;
181+ setTimeout ( ( ) => {
182+ initializeDropdown ( ) ;
183+ updateCounterDisplay ( ) ;
184+ } , 100 ) ;
185+ }
186+
187+ if ( document . readyState === 'loading' ) {
188+ document . addEventListener ( 'DOMContentLoaded' , initialize ) ;
189+ } else {
190+ initialize ( ) ;
191+ }
0 commit comments