const firstName = 'Viktor',
  lastName = 'Kraastav',
  species = 'Ankylosaurus',
  dateOfBirth = new Date('1987-12-08'),
  gender = 'male',
  pronouns = 'he/him',
  orientation = 'gay',
  role = 'bottom',
  height = 227, // cm
  weight = 175, // kg
  color = {
    front: '#e7c7b1',
    limbs: '#493428',
    back: '#422322',
    spine: '#341c1c',
    tissue: '#6bb9db',
    spikes: '#f8ebdd',
    eyesPrimary: '#a7eef1',
    eyesSecondary: '#6dabd1'
  },
  description = '',
  jobs = [
    {
      title: 'Bartender',
      icon: 'whiskey',
      desc: "Viktor's professional career began as a bartender at a pub in his hometown. There he often doubled as a bouncer when a few guests got too drunk and started making a fuss. A defining moment of that job was when someone climbed over the counter and threatened him with a broken bottle. Wrestled to the ground and with a broken bottle in front of his face, he had to make a split-second decision. With a powerful swing of his tail bone, he knocked the attacker down. This experience taught him the importance of effectively defending himself against unpleasant fellows and to eliminate threats before they get close to him ever again."
    },
    {
      title: 'Lumberjack',
      icon: 'tree',
      desc: 'After leaving his hometown, Viktor started working as a lumberjack. The club at the end of his tail came very much in handy as a counterweight for each swing of his axe, allowing him to strike efficiently and powerfully, felling even the largest trees with relative ease. His naturally tough scales protected him from splinters from the felled wood. The long-lasting hard physical work toughened his body over the years. Before taking the cut logs to the sawmill, Viktor always took a break to rest in the peace and quiet of the forest. Although he enjoyed the seclusion of the country life for a while, he was longing for the sociability of city life again.'
    },
    {
      title: 'Car Mechanic',
      icon: 'car',
      desc: 'Moving into a suburban town, Viktor applied at an auto repair shop, where he learned the ins and outs of fixing cars. He became really good at it and enjoyed breathing new mechanical life into broken down vehicles. However, as time went on, the repair shop faced financial troubles, as it became increasingly difficult to come by spare parts as auto makers would only deal them to certified repair partners and certifications were prohibitively expensive. Viktor had to watch business slowly deteriorate, as skilled coworkers kept getting laid off, until the repair shop closed down for good.'
    },
    {
      title: 'Construction Worker',
      icon: 'helmet-safety',
      desc: 'Having taken a liking in physically demanding work, Viktor took on a job as a construction worker. Hard hat perched atop his head and belt tool slung around his waist, he was always ready to lend a hand (or tail if walls or boulders needed a good teardown). Since he had more than enough strength training from his previous jobs, he was often assigned carrying jobs to clear the site and haul building materials. After work was done, Viktor enjoyed the company of his colleagues over an after-work beer until late in the evenings. On one of these evenings, he got a little reckless with a colleague under the veil of the night and both were caught in the act of fooling around with each other on the construction site. In the following weeks, the colleagues kept their distance from Viktor and the evenings together also dissolved very quickly when he joined them. The continued ostracization ultimately prompted him to look for something new.'
    },
    {
      title: 'Welder',
      icon: 'industry',
      desc: 'In his job as a welder, Viktor spent his days working shifts in a workshop. In addition to special tools and plasma welders, he also used his powerful tail club to hammer metal parts into shape. He acquired a wide variety of welding techniques to join or repair metal structures. He worked with a wide variety of alloys such as steel, aluminum and titanium. Viktor showed extreme skill in his work with great precision and attention to detail. However, this dedication was a thorn in the side of a jealous colleague who saw Viktor as a rival and schemed against him, sabotaging his work, which ultimately ended in his termination after a customer sued the welding shop for botching the job. Viktor never found out who the culprit was, and the loss of that job still hangs over him.'
    },
    {
      title: 'Delivery Driver',
      icon: 'truck',
      desc: "When Viktor was strapped for cash, he took on a job in the gig economy as a driver delivering packages for a large online delivery service. His previous physically demanding jobs allowed him to haul even bulky deliveries to their destination with relative ease. If the shipping center managers hadn't been breathing down his neck constantly, he might have held this job even longer. But after one of the managers tried to show him up in front of the whole team, he snapped and broke their leg with his tail club. Of course, he didn't have to report for duty the next day."
    },
    {
      title: 'Docks Werehouse Worker',
      icon: 'boxes-stacked',
      desc: "Currently Viktor works at the docks in the port town he moved to. His main responsibilities include loading and unloading cargo from ships and transporting it to and from warehousing. The hustle and bustle of the port sometimes gets on his nerves. Especially when the crew of docking ships come ashore again after a long time and make it clear that they don't have much contact with \"landlubbers\". Viktor doesn't get particularly impressed by this and foul mouths them right back if he gets the impression they're looking for trouble."
    }
  ];

const getClientLocale = () => {
  return navigator.languages.length > 0 ? navigator.languages[0] : 'en-US';
};

const getAge = (dateOfBirth) => {
  const today = new Date();

  const thisYear = today.getFullYear();
  const thisMonth = today.getMonth();
  const thisDay = today.getDate();

  const dobYear = dateOfBirth.getFullYear();
  const dobMonth = dateOfBirth.getMonth();
  const dobDay = dateOfBirth.getDate();

  let age = thisYear - dobYear;

  if (thisMonth < dobMonth) age--;
  if (thisMonth === dobMonth && thisDay < dobDay) age--;

  return age;
};

const toImperial = (cm) => {
  const realFeet = (cm * 0.3937) / 12;
  const feet = Math.floor(realFeet);
  const inches = Math.round((realFeet - feet) * 12);

  return `${feet}'${inches}"`;
};

const toInch = (cm) => {
  return `${Math.round(cm / 2.45)} in`;
};

const toLbs = (kg) => {
  const nearExact = kg / 0.45359237;
  const lbs = Math.floor(nearExact);

  return lbs;
};

const toFahrenheit = (celsius) => {
  return celsius * 1.8 + 32;
};

const dateFormat = new Intl.DateTimeFormat(getClientLocale(), {
  year: 'numeric',
  month: 'long',
  day: '2-digit'
});

const getFullName = () => `${firstName} ${lastName}`;
const getDateOfBirth = () => `${dateFormat.format(dateOfBirth)} (${getAge(dateOfBirth)})`;
const getHeight = () => `${height} cm (${toImperial(height)})`;
const getWeight = () => `${weight} kg (${toLbs(weight)} lbs)`;

const getTraits = () => [
  { icon: 'cake-candles', type: 'Date of Birth', text: getDateOfBirth() },
  { icon: 'mars', type: 'Sex/Gender', text: gender },
  { icon: 'ruler', type: 'Height', text: getHeight() },
  { icon: 'weight-hanging', type: 'Weight', text: getWeight() }
];

const getSexTraits = () => [
  { icon: 'heart', type: 'Orientation', text: orientation },
  { icon: 'arrows-up-down', type: 'Role', text: role }
];

const getColors = () => [
  { name: 'Front', value: color.front },
  { name: 'Arms, legs', value: color.limbs },
  { name: 'Back Main', value: color.back },
  { name: 'Back Spine', value: color.spine },
  { name: 'Highlight scales, tissue', value: color.tissue },
  { name: 'Spikes, tail club', value: color.spikes },
  { name: 'Eyes primary', value: color.eyesPrimary },
  { name: 'Eyes secondary', value: color.eyesSecondary }
];

export default {
  firstName,
  species,
  gender,
  pronouns,
  orientation,
  role,
  jobs,
  getFullName,
  getTraits,
  getSexTraits,
  getColors
};
