// ClinicScene.ts: 诊所. 芙医生 (dr_fu - never corrupts), table chart (C8 from D5).
import Phaser from 'phaser';
import { MapScene } from '../MapScene';
import { director } from '../../systems/CorruptionDirector';
import { story } from '../../systems/StoryDirector';
import { NPCS } from '../../data/gamedata';
import { DialogueLine } from '../UIScene';

export class ClinicScene extends MapScene {
  fuSprite!: Phaser.GameObjects.Sprite;
  constructor() { super('ClinicScene', 'map:clinic', 'clinic'); }

  onBuild(map: Phaser.Tilemaps.Tilemap, ts: Phaser.Tilemaps.Tileset) {
    this.fuSprite = this.add.sprite(5*16+8, 5*16+8, 'npc', NPCS.dr_fu.fieldSprite).setOrigin(0.5,0.9);
    (this.fuSprite as any).npcKey = 'dr_fu';
    this.npcSprites.push(this.fuSprite);

    this.addInteract(5, 5, () => {
      if (director.noteNpcTalk('dr_fu')) director.sadness('对同一 NPC 一天内对话 ≥5 次（纠缠）', 'dr_fu');
      story.recordGreet('dr_fu');
      // letter deliver (T4 day2)
      if (director.day === 2 && story.lettersTaken[2]) {
        story.deliverLetter('dr_fu', (l) => this.say(l));
        return;
      }
      this.say(story.npcTalk('dr_fu'));
    }, { promptText: '按 E 和芙医生说话' });

    // C8 chart (from D5)
    this.addInteract(9, 3, () => {
      if (director.day >= 5) {
        const got = director.discoverClue('C8');
        this.say([{ speaker:'', text: got ? '桌上的表格抬头被手肘挡住，只露出：「……谷情绪疗……」' : '表格的抬头还是被挡着。' }]);
      } else {
        this.say([{ speaker:'芙医生', npcKey:'dr_fu', portrait: NPCS.dr_fu.portrait.smile, text:'这里没什么好看的哦。你不需要来这里的。' }]);
      }
    }, { promptText: '按 E 看表格' });
  }
}
