import { CommonModule } from "@angular/common";
import { Component, Input, OnInit } from "@angular/core";
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
import { IconDefinition } from "@fortawesome/fontawesome-svg-core";

import { Employment } from "../config/Employment";
import { JobTypeDescriptions, JobTypes } from "../config/Icons";

/**
 *
 */
@Component({
  selector: "app-job",
  standalone: true,
  imports: [CommonModule, FontAwesomeModule],
  templateUrl: "./job.component.html",
  styleUrl: "./job.component.css"
})
export class JobComponent implements OnInit {
  @Input() job: (typeof Employment)[number] = {} as never;
  @Input() align: "left" | "right" = "left";
  public type!: "current" | "former" | (typeof Employment)[number]["type"];
  public icon!: IconDefinition;
  public iconDescription = "";
  public expanded = false;
  public description: string[] = [];
  public date = "";

  /**
   *
   */
  ngOnInit() {
    this.description = this.job.description.split(/\n+/);
    this.icon = JobTypes[this.job.type];
    this.iconDescription = JobTypeDescriptions[this.job.type];
    if (this.job.end) {
      this.type = "former";
      this.date = `${this.job.start.toLocaleDateString("en-GB", {
        month: "long",
        year: "numeric"
      })} - ${this.job.end.toLocaleDateString("en-GB", {
        month: "long",
        year: "numeric"
      })}`;
      return;
    }
    this.type = this.job.type === "hypothetical" ? "hypothetical" : "current";
    this.date = this.job.start.toLocaleDateString("en-GB", {
      month: "long",
      year: "numeric"
    });
  }

  /** */
  expand() {
    this.expanded = !this.expanded;
  }
}
