@kompasid/lit-web-components 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/.editorconfig +29 -0
  2. package/.github/workflows/npm-publish.yml +35 -0
  3. package/LICENSE +21 -0
  4. package/README.md +62 -0
  5. package/assets/font-awesome.ts +21 -0
  6. package/components.d.ts +4 -0
  7. package/demo/index.html +137 -0
  8. package/dist/assets/font-awesome.d.ts +2 -0
  9. package/dist/assets/font-awesome.js +20 -0
  10. package/dist/assets/font-awesome.js.map +1 -0
  11. package/dist/src/components/kompas-footer/KompasFooter.d.ts +13 -0
  12. package/dist/src/components/kompas-footer/KompasFooter.js +304 -0
  13. package/dist/src/components/kompas-footer/KompasFooter.js.map +1 -0
  14. package/dist/src/components/kompas-footer/types.d.ts +47 -0
  15. package/dist/src/components/kompas-footer/types.js +2 -0
  16. package/dist/src/components/kompas-footer/types.js.map +1 -0
  17. package/dist/src/components/kompas-metered-paywall/KompasMeteredPaywall.d.ts +50 -0
  18. package/dist/src/components/kompas-metered-paywall/KompasMeteredPaywall.js +225 -0
  19. package/dist/src/components/kompas-metered-paywall/KompasMeteredPaywall.js.map +1 -0
  20. package/dist/src/components/kompas-paywall/KompasPaywall.d.ts +73 -0
  21. package/dist/src/components/kompas-paywall/KompasPaywall.js +470 -0
  22. package/dist/src/components/kompas-paywall/KompasPaywall.js.map +1 -0
  23. package/dist/src/components/kompas-paywall/types.d.ts +53 -0
  24. package/dist/src/components/kompas-paywall/types.js +2 -0
  25. package/dist/src/components/kompas-paywall/types.js.map +1 -0
  26. package/dist/src/components/kompas-paywall-banner-registration/KompasPaywallBannerRegistration.d.ts +11 -0
  27. package/dist/src/components/kompas-paywall-banner-registration/KompasPaywallBannerRegistration.js +100 -0
  28. package/dist/src/components/kompas-paywall-banner-registration/KompasPaywallBannerRegistration.js.map +1 -0
  29. package/dist/src/components/kompas-paywall-body/KompasPaywallBody.d.ts +107 -0
  30. package/dist/src/components/kompas-paywall-body/KompasPaywallBody.js +843 -0
  31. package/dist/src/components/kompas-paywall-body/KompasPaywallBody.js.map +1 -0
  32. package/dist/src/components/kompas-paywall-information-header/KompasPaywallInformationHeader.d.ts +8 -0
  33. package/dist/src/components/kompas-paywall-information-header/KompasPaywallInformationHeader.js +39 -0
  34. package/dist/src/components/kompas-paywall-information-header/KompasPaywallInformationHeader.js.map +1 -0
  35. package/dist/src/components/kompas-paywall-video/KompasPaywallVideo.d.ts +53 -0
  36. package/dist/src/components/kompas-paywall-video/KompasPaywallVideo.js +245 -0
  37. package/dist/src/components/kompas-paywall-video/KompasPaywallVideo.js.map +1 -0
  38. package/dist/src/index.d.ts +10 -0
  39. package/dist/src/index.js +5 -0
  40. package/dist/src/index.js.map +1 -0
  41. package/dist/src/utils/deviceType.d.ts +2 -0
  42. package/dist/src/utils/deviceType.js +11 -0
  43. package/dist/src/utils/deviceType.js.map +1 -0
  44. package/dist/src/utils/fontawesome-setup.d.ts +1 -0
  45. package/dist/src/utils/fontawesome-setup.js +25 -0
  46. package/dist/src/utils/fontawesome-setup.js.map +1 -0
  47. package/dist/tailwind/tailwind.d.ts +1 -0
  48. package/dist/tailwind/tailwind.js +1654 -0
  49. package/dist/tailwind/tailwind.js.map +1 -0
  50. package/dist/tsconfig.tsbuildinfo +1 -0
  51. package/package.json +94 -0
  52. package/src/components/kompas-footer/KompasFooter.ts +331 -0
  53. package/src/components/kompas-footer/types.ts +54 -0
  54. package/src/components/kompas-metered-paywall/KompasMeteredPaywall.ts +174 -0
  55. package/src/components/kompas-metered-paywall/readme.md +32 -0
  56. package/src/components/kompas-paywall/KompasPaywall.ts +398 -0
  57. package/src/components/kompas-paywall/readme.md +166 -0
  58. package/src/components/kompas-paywall/types.ts +53 -0
  59. package/src/components/kompas-paywall-banner-registration/KompasPaywallBannerRegistration.ts +92 -0
  60. package/src/components/kompas-paywall-banner-registration/readme.md +31 -0
  61. package/src/components/kompas-paywall-body/KompasPaywallBody.ts +844 -0
  62. package/src/components/kompas-paywall-body/readme.md +54 -0
  63. package/src/components/kompas-paywall-information-header/KompasPaywallInformationHeader.ts +29 -0
  64. package/src/components/kompas-paywall-information-header/readme.md +30 -0
  65. package/src/components/kompas-paywall-video/KompasPaywallVideo.ts +194 -0
  66. package/src/components/kompas-paywall-video/readme.md +46 -0
  67. package/src/index.ts +11 -0
  68. package/src/utils/deviceType.ts +11 -0
  69. package/src/utils/fontawesome-setup.ts +40 -0
  70. package/tailwind/tailwind.css +1635 -0
  71. package/tailwind/tailwind.ts +1654 -0
  72. package/tailwind/tailwindlib.css +3 -0
  73. package/tailwind.config.js +96 -0
  74. package/tsconfig.json +21 -0
  75. package/web-dev-server.config.mjs +27 -0
  76. package/web-test-runner.config.mjs +41 -0
@@ -0,0 +1,844 @@
1
+ /* eslint-disable no-return-assign */
2
+
3
+ import { html, css, LitElement } from 'lit'
4
+ import { property, state, customElement } from 'lit/decorators.js'
5
+ import { unsafeSVG } from 'lit/directives/unsafe-svg.js'
6
+ import { TWStyles } from '../../../tailwind/tailwind.js'
7
+ import {
8
+ PaywallProduct,
9
+ Product,
10
+ Packages,
11
+ PaymentImage,
12
+ } from '../kompas-paywall/types.js'
13
+ import { getFontAwesomeIcon } from '../../utils/fontawesome-setup.js'
14
+ import { deviceType } from '../../utils/deviceType.js'
15
+
16
+ @customElement('kompas-paywall-body')
17
+ export class KompasPaywallBody extends LitElement {
18
+ static styles = [css``, TWStyles]
19
+
20
+ /**
21
+ * Props
22
+ */
23
+ /**
24
+ * prop slug untuk menghandle slug
25
+ * prop isLogin untuk menghandle apakah user sudah login atau belum
26
+ * prop type untuk menghandle tipe epaper
27
+ * prop paywallData untuk menghandle data paywall
28
+ * prop userGuid untuk menghandle user Guid
29
+ * prop subscriptionStatus untuk menghandle status subscription user
30
+ * prop countdownArticle untuk menghandle count artikel
31
+ * prop swgEnable untuk menghandle swg apakah di aktifkan atau tidak
32
+ * prop paywall_location = The location where user encounter the paywall
33
+ * prop paywall_subscription_package = The name of the subscription package viewed by user
34
+ * prop paywall_subscription_id = The ID of the subscription package viewed by user
35
+ * prop paywall_subscription_price = The price of the subscriprtion package viewed by user
36
+ * prop paywall_position = The position of the subscription package viewed by user
37
+ * prop tracker_page_type = Type of the page
38
+ * prop tracker_content_id = ID of article (slug)
39
+ * prop tracker_content_type = Whether it's free article or paid article
40
+ * prop tracker_content_title = The title of article
41
+ * prop tracker_content_categories = The category of the content
42
+ * prop tracker_user_type = Type of user based on their subscription
43
+ * prop tracker_subscription_status = Status of their subscription
44
+ * prop tracker_page_domain = Page Domain
45
+ * prop tracker_metered_wall_type = The type of Metered Wall
46
+ * prop tracker_metered_wall_balance = The balance of their metered wall
47
+ * prop tracker_metered_wall_balance = The edition of epaper viewed by user
48
+ * prop theme = The theme of the paywall component
49
+ */
50
+
51
+ @property({ type: String }) slug = ''
52
+ @property({ type: Number }) udin = 0
53
+ @property({ type: Boolean }) isLogin = false
54
+ @property({ type: String }) type: 'epaper' | 'reguler' = 'reguler'
55
+ @property({ type: Object }) paywallData: PaywallProduct | undefined =
56
+ undefined
57
+ @property({ type: String }) userGuid = ''
58
+ @property({ type: String }) subscriptionStatus = ''
59
+ @property({ type: Number }) countdownArticle = 0
60
+ @property({ type: Boolean }) swgEnable = false
61
+ @property({ type: String }) paywall_location = ''
62
+ @property({ type: String }) paywall_subscription_package = ''
63
+ @property({ type: Number }) paywall_subscription_id = 0
64
+ @property({ type: Number }) paywall_subscription_price = 0
65
+ @property({ type: Number }) paywall_position = 0
66
+ @property({ type: String }) tracker_page_type = ''
67
+ @property({ type: String }) tracker_content_id = ''
68
+ @property({ type: String }) tracker_content_title = ''
69
+ @property({ type: String }) tracker_content_categories = ''
70
+ @property({ type: String }) tracker_content_type = ''
71
+ @property({ type: String }) tracker_user_type = ''
72
+ @property({ type: String }) tracker_subscription_status = ''
73
+ @property({ type: String }) tracker_page_domain = ''
74
+ @property({ type: String }) tracker_metered_wall_type = ''
75
+ @property({ type: Number }) tracker_metered_wall_balance = 0
76
+ @property({ type: String }) tracker_epaper_edition = ''
77
+ @property({ type: String }) theme = ''
78
+
79
+ @state() private isExtensionsOpened = false
80
+ @state() private kompasAkunHost = 'https://akun.kompas.id'
81
+ @state() private kompasApigenHost = 'https://apigen.kompas.id'
82
+ @state() private kompasApiWcmHost = 'https://apiwcm.kompas.id'
83
+ @state() private kompasLoginHost = 'https://account.kompas.id/login'
84
+ @state() private selfHost = 'https://epaper.kompas.id'
85
+ @state() private swgPublisherName = 'Harian Kompas'
86
+ @state() private swgPublisherId = 'kompas.id'
87
+ @state() private swgProductId = 'kompas.id:kompas_digital_premium'
88
+ @state() private errorFlag = 0
89
+
90
+ buttonElement!: HTMLButtonElement
91
+
92
+ private getRupiahFormat(value: number) {
93
+ const roundedValue = Math.round(value)
94
+ return `Rp ${roundedValue
95
+ .toString()
96
+ .replace(/(\d)(?=(\d{3})+(?!\d))/g, '$1.')}`
97
+ }
98
+
99
+ private redirectToCheckout(
100
+ url: string,
101
+ name: string,
102
+ id: string,
103
+ price: number,
104
+ position: number
105
+ ): void {
106
+ this.sendDataLayeronButtonBuyPackage(name, id, price, position)
107
+ const originHost: string = encodeURIComponent(window.location.href)
108
+ const directUrlCheckout: string = url + originHost
109
+ window.open(directUrlCheckout)
110
+ }
111
+
112
+ private redirectToPrevUrl(): void {
113
+ window.history.back()
114
+ }
115
+
116
+ private redirectToSubscriber(): void {
117
+ this.sendDataLayer()
118
+ window.open('https://www.kompas.id/berlangganan')
119
+ }
120
+
121
+ private redirectToRegister(): void {
122
+ const loginHost: string = 'https://account.kompas.id/login'
123
+ const nextParams: string = encodeURIComponent(window.location.href)
124
+ const directUrlRegister: string = `${loginHost}?next=${nextParams}?status=sukses_login&status_login=login`
125
+ window.location.href = directUrlRegister
126
+ }
127
+
128
+ private redirectToHelpdesk(): void {
129
+ this.sendDataLayeronHelpDesk()
130
+ window.open(
131
+ 'https://api.whatsapp.com/send/?phone=6281290050800&text=Halo,%20saya%20perlu%20informasi%20mengenai%20kompas.id'
132
+ )
133
+ }
134
+
135
+ private paymentExtensionHandler(): void {
136
+ this.isExtensionsOpened = !this.isExtensionsOpened
137
+ }
138
+
139
+ get isDark() {
140
+ return this.theme === 'dark'
141
+ }
142
+
143
+ get redirectToLogin() {
144
+ return `${this.kompasLoginHost}?next=${encodeURIComponent(
145
+ this.selfHost + window.location.pathname
146
+ )}`
147
+ }
148
+
149
+ private async getRegisterToken(path: string, payload: any): Promise<string> {
150
+ return fetch(`${this.kompasApigenHost}/v1/user/register/token/${path}`, {
151
+ method: 'POST',
152
+ body: JSON.stringify(payload),
153
+ headers: {
154
+ 'content-type': 'application/json',
155
+ },
156
+ })
157
+ .then(response => response.json())
158
+ .then((data: any) => data.result.token)
159
+ .catch(error => {
160
+ throw error
161
+ })
162
+ }
163
+
164
+ private async getUserToken(path: string, payload: any): Promise<string> {
165
+ return fetch(`${this.kompasApigenHost}/v1/user/token/${path}`, {
166
+ method: 'POST',
167
+ body: JSON.stringify(payload),
168
+ headers: {
169
+ 'content-type': 'application/json',
170
+ },
171
+ })
172
+ .then(response => response.json())
173
+ .then((data: any) => data.result.token)
174
+ .catch(error => {
175
+ throw error
176
+ })
177
+ }
178
+
179
+ private async getSubscriptionToken(
180
+ path: string,
181
+ payload: any
182
+ ): Promise<string> {
183
+ return fetch(`${this.kompasAkunHost}/api/subscription/login/${path}`, {
184
+ method: 'POST',
185
+ body: JSON.stringify(payload),
186
+ headers: {
187
+ 'content-type': 'application/json',
188
+ },
189
+ })
190
+ .then(response => response.json())
191
+ .then((data: any) => {
192
+ this.errorFlag = 0
193
+ return data.access_token
194
+ })
195
+ .catch(async error => {
196
+ const errorCode = error.response.status
197
+ if (errorCode === 500 && this.errorFlag < 5) {
198
+ // eslint-disable-next-line no-plusplus
199
+ this.errorFlag++
200
+ setTimeout(async () => {
201
+ await this.getSubscriptionToken(path, payload)
202
+ }, 2000)
203
+ } else {
204
+ this.errorFlag = 0
205
+ throw error
206
+ }
207
+ })
208
+ }
209
+
210
+ private async createSwG(payload: any, token: string) {
211
+ await fetch(`${this.kompasApiWcmHost}/v2/membership/swg/create`, {
212
+ method: 'POST',
213
+ body: JSON.stringify(payload),
214
+ headers: {
215
+ 'content-type': 'application/json',
216
+ Authorization: `Bearer ${token}`,
217
+ },
218
+ })
219
+ .then(response => response.json())
220
+ .catch(error => {
221
+ throw error
222
+ })
223
+ }
224
+
225
+ private subscribeWithGoogleButton = (): any => {
226
+ // @ts-ignore
227
+ // eslint-disable-next-line no-restricted-globals
228
+ ;(self.SWG = self.SWG || []).push((subscriptions: any) => {
229
+ // set entitlement
230
+ subscriptions.setOnEntitlementsResponse(() => {
231
+ // subscriptions attach button
232
+ subscriptions.attachButton(
233
+ this.buttonElement,
234
+ { theme: 'light', lang: 'en' },
235
+ () => {
236
+ subscriptions.showOffers({ isClosable: true })
237
+ subscriptions.setOnLoginRequest(() => {
238
+ window.location.href = this.redirectToLogin
239
+ })
240
+ subscriptions.setOnPaymentResponse(async (paymentResponse: any) => {
241
+ const response = await paymentResponse
242
+ const raw = JSON.parse(response.purchaseData.raw)
243
+ const { productId, purchaseToken, packageName } = raw
244
+ const { email } = response.userData.data
245
+
246
+ const payload = {
247
+ subscription_token: purchaseToken,
248
+ products: productId,
249
+ detail: 'test',
250
+ }
251
+ const userToken = await this.getUserToken('google', payload)
252
+ if (userToken) {
253
+ // login and update membership
254
+ const accessToken = await this.getSubscriptionToken('google', {
255
+ token: userToken,
256
+ })
257
+ if (accessToken) {
258
+ const payloadSWG = {
259
+ email,
260
+ package_name: packageName,
261
+ product_id: productId,
262
+ purchase_token: purchaseToken,
263
+ }
264
+ await this.createSwG(payloadSWG, accessToken)
265
+ }
266
+ } else {
267
+ // register and login the unknown user
268
+ const payloadRegisterToken = {
269
+ subscription_token: purchaseToken,
270
+ products: productId,
271
+ detail: 'test',
272
+ }
273
+ const token = await this.getRegisterToken(
274
+ 'google',
275
+ payloadRegisterToken
276
+ )
277
+ if (token) {
278
+ const accessToken = await this.getSubscriptionToken(
279
+ 'google',
280
+ { token }
281
+ )
282
+ const payloadSWRUknown = {
283
+ email,
284
+ package_name: packageName,
285
+ product_id: productId,
286
+ purchase_token: purchaseToken,
287
+ }
288
+ await this.createSwG(payloadSWRUknown, accessToken)
289
+ }
290
+ }
291
+ response.complete().then(() => {
292
+ window.location.href = this.redirectToLogin
293
+ })
294
+ })
295
+ }
296
+ )
297
+ })
298
+ })
299
+ }
300
+
301
+ private jsonScript() {
302
+ const jsonData = {
303
+ '@context': 'https://schema.org',
304
+ '@type': ['WebSite', 'WebPage'],
305
+ isAccessibleForFree: false,
306
+ url: this.selfHost + window.location.pathname,
307
+ name: this.swgPublisherName,
308
+ hasPart: {
309
+ '@type': 'WebPageElement',
310
+ },
311
+ isPartOf: {
312
+ '@type': ['CreativeWork', 'Product'],
313
+ name: this.swgPublisherId,
314
+ productID: this.swgProductId,
315
+ },
316
+ }
317
+ const str = JSON.stringify(jsonData)
318
+ const jsonScript = document.createElement('script')
319
+ jsonScript.type = 'application/ld+json'
320
+ jsonScript.text = str
321
+ jsonScript.defer = true
322
+ const jsonHead = document.querySelector('head')
323
+ if (jsonHead) {
324
+ jsonHead.appendChild(jsonScript)
325
+ }
326
+ }
327
+
328
+ override connectedCallback() {
329
+ // eslint-disable-next-line wc/guard-super-call
330
+ super.connectedCallback()
331
+ if (this.swgEnable) {
332
+ this.jsonScript()
333
+ if (this.buttonElement) {
334
+ const head = document.querySelector('head')
335
+ const script = document.createElement('script')
336
+ script.src = 'https://news.google.com/swg/js/v1/swg.js'
337
+ script.defer = true
338
+ script.onload = this.subscribeWithGoogleButton()
339
+ if (head) {
340
+ head.appendChild(script)
341
+ }
342
+ }
343
+ }
344
+ }
345
+
346
+ private sendDataLayer(): void {
347
+ window.dataLayer.push({
348
+ event: 'halamanBerlanggananClick',
349
+ subscriptionStatus: '',
350
+ GUID: '',
351
+ interface: deviceType(),
352
+ })
353
+ }
354
+
355
+ private sendDataLayeronHelpDesk(): void {
356
+ window.dataLayer.push({
357
+ event: 'helpOfferClick',
358
+ userType: this.subscriptionStatus,
359
+ GUID: this.userGuid,
360
+ interface: deviceType(),
361
+ })
362
+ }
363
+
364
+ private sendDataLayeronButtonBuyPackage(
365
+ name: string,
366
+ id: string,
367
+ price: number,
368
+ position: number
369
+ ): void {
370
+ const gtmParams: Record<string, any> = {
371
+ event: 'subscribe_button_clicked',
372
+ paywall_location: this.paywall_location,
373
+ paywall_subscription_package: name,
374
+ paywall_subscription_id: id,
375
+ paywall_subscription_price: price,
376
+ paywall_position: position,
377
+ user_type: this.tracker_user_type,
378
+ subscription_status: this.tracker_subscription_status,
379
+ page_domain: this.tracker_page_domain || 'Kompas.id',
380
+ metered_wall_type: this.tracker_metered_wall_type || 'HP',
381
+ metered_wall_balance: this.tracker_metered_wall_balance,
382
+ }
383
+
384
+ if (this.type !== 'epaper') {
385
+ gtmParams.content_title = this.tracker_content_title
386
+ gtmParams.content_id = this.tracker_content_id
387
+ gtmParams.content_categories = this.tracker_content_categories
388
+ gtmParams.content_type = this.tracker_content_type
389
+ gtmParams.page_type = this.tracker_page_type
390
+ } else {
391
+ gtmParams.epaper_edition = this.tracker_epaper_edition
392
+ }
393
+
394
+ window.dataLayer.push(gtmParams)
395
+ }
396
+
397
+ private sendDataLayeronPaywallBody = (): void => {
398
+ const gtmParams: Record<string, any> = {
399
+ event: 'paywall_viewed',
400
+ impressions: [
401
+ {
402
+ paywall_location: this.paywall_location || '',
403
+ paywall_subscription_package:
404
+ 'Cash-B2C-Halaman Berlangganan-Reguler_Digital-KDP 12',
405
+ paywall_subscription_id: '9802032',
406
+ paywall_subscription_price: 360000,
407
+ paywall_position: 1,
408
+ user_type: this.tracker_user_type,
409
+ subscription_status: this.tracker_subscription_status,
410
+ page_domain: this.tracker_page_domain || 'Kompas.id',
411
+ metered_wall_type: this.tracker_metered_wall_type || 'HP',
412
+ metered_wall_balance: this.tracker_metered_wall_balance,
413
+ },
414
+ {
415
+ paywall_location: this.paywall_location || '',
416
+ paywall_subscription_package:
417
+ 'Cash-B2C-Halaman Berlangganan-Reguler_Digital-KDP 1',
418
+ paywall_subscription_id: '9802035',
419
+ paywall_subscription_price: 50000,
420
+ paywall_position: 2,
421
+ user_type: this.tracker_user_type,
422
+ subscription_status: this.tracker_subscription_status,
423
+ page_domain: this.tracker_page_domain || 'Kompas.id',
424
+ metered_wall_type: this.tracker_metered_wall_type || 'HP',
425
+ metered_wall_balance: this.tracker_metered_wall_balance,
426
+ },
427
+ ],
428
+ }
429
+
430
+ if (this.type === 'epaper') {
431
+ gtmParams.impressions[0].epaper_edition = this.tracker_epaper_edition
432
+ gtmParams.impressions[1].epaper_edition = this.tracker_epaper_edition
433
+ } else {
434
+ gtmParams.impressions[0].page_type = this.tracker_page_type
435
+ gtmParams.impressions[0].content_id = this.tracker_content_id
436
+ gtmParams.impressions[0].content_title = this.tracker_content_title
437
+ gtmParams.impressions[0].content_categories =
438
+ this.tracker_content_categories
439
+ gtmParams.impressions[0].content_type = this.tracker_content_type
440
+
441
+ gtmParams.impressions[1].page_type = this.tracker_page_type
442
+ gtmParams.impressions[1].content_id = this.tracker_content_id
443
+ gtmParams.impressions[1].content_title = this.tracker_content_title
444
+ gtmParams.impressions[1].content_categories =
445
+ this.tracker_content_categories
446
+ gtmParams.impressions[1].content_type = this.tracker_content_type
447
+ }
448
+
449
+ window.dataLayer.push(gtmParams)
450
+ }
451
+
452
+ private headerSection(type: 'epaper' | 'reguler') {
453
+ return html`
454
+ <div class="flex w-full items-center">
455
+ ${type === 'epaper'
456
+ ? html`<button
457
+ @click=${() => this.redirectToPrevUrl()}
458
+ class="hidden lg:block w-8 h-8 text-blue-600 pl-4"
459
+ >
460
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'arrow-left'))}
461
+ </button>`
462
+ : ''}
463
+ <h4
464
+ class="text-base md:text-xl ${this.isDark &&
465
+ 'text-white'} text-center font-bold font-serif tracking-wide md:tracking-normal w-full"
466
+ >
467
+ Langganan untuk Lanjut Membaca
468
+ </h4>
469
+ </div>
470
+ `
471
+ }
472
+
473
+ private descriptionSection(data: Array<string>) {
474
+ return html`<div class=" flex flex-col items-center">
475
+ <div class="flex flex-col space-y-2 mt-2.5 md:mt-3">
476
+ ${data.map(
477
+ item =>
478
+ html`
479
+ <div class="flex items-center">
480
+ <div class="text-green-500">
481
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'check', 12, 12))}
482
+ </div>
483
+ <h6
484
+ class="text-xs md:text-base ${this.isDark &&
485
+ 'text-white'} ml-0.5 md:ml-1"
486
+ >
487
+ ${item}
488
+ </h6>
489
+ </div>
490
+ `
491
+ )}
492
+ </div>
493
+ </div>`
494
+ }
495
+
496
+ private informationPackages() {
497
+ return html` <div class="mt-4 flex justify-center">
498
+ <button
499
+ @click=${() => this.redirectToSubscriber()}
500
+ class="text-sm md:text-base font-bold ${this.isDark
501
+ ? 'text-blue-300'
502
+ : 'text-blue-600'} underline"
503
+ >
504
+ Lihat Paket Lainnya
505
+ </button>
506
+ </div>`
507
+ }
508
+
509
+ private separatorLine() {
510
+ return html`
511
+ <div class="flex flex-row w-full justify-center">
512
+ <div
513
+ class="border-b-2 ${this.isDark
514
+ ? 'border-dark-2'
515
+ : 'border-blue-200'} w-1/4 my-4 flex justify-center"
516
+ ></div>
517
+ <p class="px-4 pt-1 ${this.isDark && 'text-dark-1'}">atau</p>
518
+ <div
519
+ class="border-b-2 ${this.isDark
520
+ ? 'border-dark-2'
521
+ : 'border-blue-200'} w-1/4 my-4 flex justify-center"
522
+ ></div>
523
+ </div>
524
+ `
525
+ }
526
+
527
+ private paymentDesktopSection(data: Array<PaymentImage>) {
528
+ return html`
529
+ <div
530
+ class="hidden md:flex w-full md:max-w-sm items-center justify-center flex-wrap"
531
+ >
532
+ ${data.map(
533
+ item =>
534
+ html`<img
535
+ class="object-cover ${this.isDark ? 'h-9' : 'h-10'}"
536
+ src=${item.link}
537
+ alt="${item.name}-logo-payment"
538
+ />`
539
+ )}
540
+ </div>
541
+ `
542
+ }
543
+
544
+ private paymentMobileSection(data: Array<PaymentImage>) {
545
+ return html`
546
+ <div
547
+ class="grid md:hidden items-center grid-flow-col grid-cols-auto grid-rows-1 mt-4 mx-4"
548
+ >
549
+ ${data.map(
550
+ item =>
551
+ html`<img
552
+ class="w-16"
553
+ src=${item.link}
554
+ alt="${item.name}-logo-payment"
555
+ />`
556
+ )}
557
+ <button
558
+ @click=${() => this.paymentExtensionHandler()}
559
+ class="text-xs md:text-sm ${this.isDark
560
+ ? 'text-blue-300'
561
+ : 'text-blue-600'} font-bold"
562
+ >
563
+ +9 lainnya
564
+ </button>
565
+ </div>
566
+ `
567
+ }
568
+
569
+ private paymentMobileExtension(data: Array<PaymentImage>) {
570
+ return html`
571
+ <div
572
+ class="w-full ${this.isDark
573
+ ? '-bottom-6'
574
+ : 'bottom-0'} max-w-xs mb-1 ml-8 md:hidden absolute px-4"
575
+ >
576
+ <div
577
+ class="w-full ${this.isDark
578
+ ? 'bg-dark-6 border-dark-6'
579
+ : 'bg-white border-white'} rounded p-3 max-w-xs"
580
+ >
581
+ <svg
582
+ class="right-0 ${this.isDark
583
+ ? 'text-dark-6 border-dark-6'
584
+ : 'text-white border-white '} h-4 mr-10 -mt-7 z-0 transform rotate-180 absolute"
585
+ x="0px"
586
+ y="0px"
587
+ viewBox="0 0 255 255"
588
+ >
589
+ <polygon class="fill-current" points="0,0 127.5,127.5 255,0" />
590
+ </svg>
591
+ <div
592
+ class="grid place-items-center items-center grid-flow-row grid-cols-5 grid-rows-2 gap-y-4"
593
+ >
594
+ ${data.map(
595
+ item =>
596
+ html`<img
597
+ class="object-cover"
598
+ src=${item.link}
599
+ alt="${item.name}-logo-payment"
600
+ />`
601
+ )}
602
+ </div>
603
+ </div>
604
+ </div>
605
+ `
606
+ }
607
+
608
+ private primaryPackages(product: Product) {
609
+ return html`
610
+ <div
611
+ class="flex flex-wrap justify-between items-center ${this.isDark
612
+ ? 'bg-grey-600'
613
+ : 'bg-white'} rounded md:mx-0 w-full max-w-xs md:max-w-sm md:w-3/5 mt-2.5 md:mt-4 border border-yellow-400 relative"
614
+ >
615
+ <div class="flex flex-col py-3 px-4">
616
+ <div class="flex flex-none items-center">
617
+ <h5 class="text-base md:text-lg font-bold text-orange-400">
618
+ ${this.getRupiahFormat(product.price)}
619
+ </h5>
620
+ <h6
621
+ class="text-xs md:text-base ${this.isDark &&
622
+ 'text-white'} font-bold pl-1"
623
+ >
624
+ / ${product.periode}
625
+ </h6>
626
+ </div>
627
+ <div class="flex items-center">
628
+ <p class="text-xs ${this.isDark && 'text-white'}">
629
+ hanya <span class="text-orange-400">Rp 30.000</span> / bulan
630
+ </p>
631
+ </div>
632
+ </div>
633
+ <button
634
+ class="h-auto ${this.isDark
635
+ ? 'bg-green-300 border border-green-400'
636
+ : 'bg-green-500'} rounded mr-4"
637
+ @click=${() =>
638
+ this.redirectToCheckout(
639
+ product.url,
640
+ 'Cash-B2C-Halaman Berlangganan-Reguler_Digital-KDP 12',
641
+ '9802032',
642
+ 360000,
643
+ 1
644
+ )}
645
+ >
646
+ <h6
647
+ class="text-xs md:text-base ${this.isDark
648
+ ? 'text-black'
649
+ : 'text-white'} font-bold py-2 px-4"
650
+ >
651
+ Langganan
652
+ </h6>
653
+ </button>
654
+ <div class="absolute -top-2 left-4">
655
+ <div class="rounded bg-yellow-300 px-2 py-0.5 text-xs">
656
+ <b>Harga Terbaik</b>
657
+ </div>
658
+ </div>
659
+ </div>
660
+ `
661
+ }
662
+
663
+ private secondaryPackages(product: Product) {
664
+ return html`
665
+ <div
666
+ class="flex flex-wrap justify-between ${this.isDark
667
+ ? 'bg-grey-600'
668
+ : 'bg-white'} py-3 px-4 rounded md:mx-0 w-full max-w-xs md:max-w-sm md:w-3/5 mt-3 md:mt-4"
669
+ >
670
+ <div class="flex items-center">
671
+ <h5 class="text-base md:text-lg font-bold text-orange-400">
672
+ ${this.getRupiahFormat(product.price)}
673
+ </h5>
674
+ <h6
675
+ class="text-xs md:text-base ${this.isDark &&
676
+ 'text-white'} font-bold pl-1"
677
+ >
678
+ / ${product.periode}
679
+ </h6>
680
+ </div>
681
+ <button
682
+ @click=${() =>
683
+ this.redirectToCheckout(
684
+ product.url,
685
+ 'Cash-B2C-Halaman Berlangganan-Reguler_Digital-KDP 1',
686
+ '9802035',
687
+ 50000,
688
+ 2
689
+ )}
690
+ class="h-auto ${!this.isDark &&
691
+ 'bg-white'} border border-green-500 rounded"
692
+ >
693
+ <h6
694
+ class="text-xs md:text-base ${this.isDark
695
+ ? 'text-green-300'
696
+ : 'text-green-500'} font-bold py-2 px-4"
697
+ >
698
+ Langganan
699
+ </h6>
700
+ </button>
701
+ </div>
702
+ `
703
+ }
704
+
705
+ private packagesSection(data: Packages) {
706
+ return html`
707
+ <div class="flex flex-col w-full items-center mt-8 lg:mt-2 px-2 ">
708
+ <h6
709
+ class="text-sm md:text-base ${this.isDark && 'text-white'} font-bold"
710
+ >
711
+ ${data.title}
712
+ </h6>
713
+ ${data.memberships.map(item =>
714
+ item.isHighlight
715
+ ? this.primaryPackages(item)
716
+ : this.secondaryPackages(item)
717
+ )}
718
+ </div>
719
+ `
720
+ }
721
+
722
+ private topNavigator() {
723
+ return html`
724
+ <div class="flex lg:hidden items-center w-full pb-4 ">
725
+ <button
726
+ @click=${() => this.redirectToPrevUrl()}
727
+ class="text-xs md:text-lg text-white flex flex-row"
728
+ >
729
+ <div class="icon-lg icon-white w-4 h-4 mr-3.5 md:mr-5 pt-0.5">
730
+ ${unsafeSVG(getFontAwesomeIcon('fas', 'arrow-left'))}
731
+ </div>
732
+ Kembali
733
+ </button>
734
+ </div>
735
+ `
736
+ }
737
+
738
+ private helpDesk() {
739
+ return html`
740
+ <div class="py-2.5 text-white self-center text-xs md:text-sm">
741
+ Mengalami masalah? Hubungi
742
+ <button
743
+ @click=${() => this.redirectToHelpdesk()}
744
+ class="font-bold ${this.isDark && 'text-blue-300'} underline"
745
+ >
746
+ Layanan Pelanggan.
747
+ </button>
748
+ </div>
749
+ `
750
+ }
751
+
752
+ private authRegister() {
753
+ return html`
754
+ <div
755
+ class="flex flex-row text-white px-2 py-2.5 space-x-4 md:space-x-8 self-center"
756
+ >
757
+ <div class="flex flex-col text-left text-xs md:text-sm text-white">
758
+ <b>Sudah berlangganan Kompas.id?</b>
759
+ <p>Masuk untuk lanjut membaca.</p>
760
+ </div>
761
+ <button
762
+ @click=${() => this.redirectToRegister()}
763
+ class="h-auto ${this.isDark
764
+ ? 'bg-blue-300'
765
+ : 'bg-grey-100'} rounded mr-3"
766
+ >
767
+ <p
768
+ class="text-xs md:text-sm ${this.isDark
769
+ ? 'text-black'
770
+ : 'text-blue-600'} font-bold py-2 px-4"
771
+ >
772
+ Masuk / Daftar
773
+ </p>
774
+ </button>
775
+ </div>
776
+ `
777
+ }
778
+
779
+ private userAction(isLogin: boolean, type: 'epaper' | 'reguler') {
780
+ return html`
781
+ <div
782
+ class="flex h-20 ${this.isDark
783
+ ? 'bg-dark-4'
784
+ : 'bg-blue-600'} w-full justify-evenly rounded-b mt-6 md:mt-8 relative"
785
+ >
786
+ ${isLogin || type !== 'epaper' ? this.helpDesk() : this.authRegister()}
787
+ </div>
788
+ `
789
+ }
790
+
791
+ render() {
792
+ return html`
793
+ <div
794
+ class="${this.type === 'epaper'
795
+ ? 'bg-transparent wrapper-body'
796
+ : 'wrapper-body'}"
797
+ >
798
+ <div
799
+ class="flex flex-col justify-center items-center w-full max-w-screen-sm px-4 md:px-0 my-5 relative"
800
+ >
801
+ ${this.type === 'epaper' ? this.topNavigator() : ''}
802
+ <div
803
+ class="flex w-full flex-col items-center justify-center ${this
804
+ .isDark
805
+ ? 'bg-dark-3'
806
+ : 'bg-blue-100'} rounded pt-6 md:pt-8 relative"
807
+ >
808
+ ${this.headerSection(this.type)}
809
+ ${this.descriptionSection(
810
+ this.paywallData?.informations?.description ?? []
811
+ )}
812
+ ${this.packagesSection(
813
+ this.paywallData?.packages ?? ({} as Packages)
814
+ )}
815
+ ${this.informationPackages()}
816
+ ${this.swgEnable ? this.separatorLine() : null}
817
+ ${this.swgEnable
818
+ ? html`<button
819
+ class="border-2 bg-grey-100 border-grey-100 rounded-lg px-6 shadow-sm flex flex-row py-2 mt-1 mb-4"
820
+ ref=${(el: any) => (this.buttonElement = el as HTMLButtonElement)}
821
+ >
822
+ <p>Subscribe with</p>
823
+ <img class="pl-2 object-scale-down w-20 pt-0.5" src="https://kompasid-production-www.s3.ap-southeast-1.amazonaws.com/paywall-asset/google.png" alt="subscribe with google"></img>
824
+ </button>`
825
+ : null}
826
+ ${this.paymentDesktopSection(
827
+ this.paywallData?.payment?.desktop ?? []
828
+ )}
829
+ ${this.paymentMobileSection(
830
+ this.paywallData?.payment?.mobile ?? []
831
+ )}
832
+ ${this.userAction(this.isLogin, this.type)}
833
+ ${this.sendDataLayeronPaywallBody()}
834
+ </div>
835
+ ${this.isExtensionsOpened
836
+ ? this.paymentMobileExtension(
837
+ this.paywallData?.payment?.ekstension ?? []
838
+ )
839
+ : ''}
840
+ </div>
841
+ </div>
842
+ `
843
+ }
844
+ }