import { ChangeDetectionStrategy, Component, computed, input } from '@angular/core'; import { LucideAngularModule, MapPin, Video } from 'lucide-angular'; @Component({ selector: 'app-lesson-delivery-badge', imports: [LucideAngularModule], changeDetection: ChangeDetectionStrategy.OnPush, host: { '[hidden]': '!delivery()' }, template: ` @if (delivery(); as value) { } `, styles: ` :host { display: inline-flex; align-self: flex-start; max-width: 100%; } :host([hidden]) { display: none; } .delivery-badge { display: inline-flex; align-items: center; gap: 0.25em; padding: 0.15em 0.45em; border-radius: 0.35em; background: #e2eefb; color: #214f7a; font-size: 0.75em; font-weight: 650; line-height: 1.35; white-space: nowrap; } .delivery-badge.offline { background: #e4f2e9; color: #246245; } lucide-icon { display: inline-flex; flex: none; } `, }) export class LessonDeliveryBadgeComponent { readonly mode = input(); readonly legacyLabel = input(); protected readonly pinIcon = MapPin; protected readonly videoIcon = Video; protected readonly delivery = computed(() => { const mode = String(this.mode() ?? '').trim().toLowerCase(); if (mode === 'online' || mode === 'offline') return mode; const label = String(this.legacyLabel() ?? '').trim().toLowerCase(); const online = /线上|在线|远程/.test(label) || label === 'online'; const offline = /线下|到店|面授/.test(label) || /^(offline|机构|上门)$/.test(label); return online === offline ? null : offline ? 'offline' : 'online'; }); }