import { html, LitElement, PropertyValues, TemplateResult } from "lit";
import { customElement, query } from "lit/decorators";
import { getEntity } from "../../../src/fake_data/entity";
import { provideHass } from "../../../src/fake_data/provide_hass";
import "../components/demo-cards";

const ENTITIES = [
  getEntity("light", "bed_light", "on", {
    friendly_name: "Bed Light",
  }),
  getEntity("switch", "bed_ac", "on", {
    friendly_name: "Ecobee",
  }),
  getEntity("sensor", "bed_temp", "72", {
    friendly_name: "Bedroom Temp",
    device_class: "temperature",
    unit_of_measurement: "°F",
  }),
  getEntity("light", "living_room_light", "off", {
    friendly_name: "Living Room Light",
  }),
  getEntity("fan", "living_room", "on", {
    friendly_name: "Living Room Fan",
  }),
  getEntity("sensor", "office_humidity", "73", {
    friendly_name: "Office Humidity",
    device_class: "humidity",
    unit_of_measurement: "%",
  }),
  getEntity("light", "office", "on", {
    friendly_name: "Office Light",
  }),
  getEntity("fan", "kitchen", "on", {
    friendly_name: "Second Office Fan",
  }),
  getEntity("binary_sensor", "kitchen_door", "on", {
    friendly_name: "Office Door",
    device_class: "door",
  }),
];

// TODO: Update image here
const CONFIGS = [
  {
    heading: "Bedroom",
    config: `
- type: area
  area: bedroom
  image: "/images/bed.png"
    `,
  },
  {
    heading: "Living Room",
    config: `
- type: area
  area: living_room
  image: "/images/living_room.png"
    `,
  },
  {
    heading: "Office",
    config: `
- type: area
  area: office
  image: "/images/office.jpg"
    `,
  },
  {
    heading: "Kitchen",
    config: `
- type: area
  area: kitchen
  image: "/images/kitchen.png"
    `,
  },
];

@customElement("demo-hui-area-card")
class DemoArea extends LitElement {
  @query("#demos") private _demoRoot!: HTMLElement;

  protected render(): TemplateResult {
    return html`<demo-cards id="demos" .configs=${CONFIGS}></demo-cards>`;
  }

  protected firstUpdated(changedProperties: PropertyValues) {
    super.firstUpdated(changedProperties);
    const hass = provideHass(this._demoRoot);
    hass.updateTranslations(null, "en");
    hass.updateTranslations("lovelace", "en");
    hass.addEntities(ENTITIES);
    hass.mockWS("config/area_registry/list", () => [
      {
        name: "Bedroom",
        area_id: "bedroom",
      },
      {
        name: "Living Room",
        area_id: "living_room",
      },
      {
        name: "Office",
        area_id: "office",
      },
      {
        name: "Second Office",
        area_id: "kitchen",
      },
    ]);
    hass.mockWS("config/device_registry/list", () => []);
    hass.mockWS("config/entity_registry/list", () => [
      {
        area_id: "bedroom",
        entity_id: "light.bed_light",
      },
      {
        area_id: "bedroom",
        entity_id: "switch.bed_ac",
      },
      {
        area_id: "bedroom",
        entity_id: "sensor.bed_temp",
      },
      {
        area_id: "living_room",
        entity_id: "light.living_room_light",
      },
      {
        area_id: "living_room",
        entity_id: "fan.living_room",
      },
      {
        area_id: "office",
        entity_id: "light.office",
      },
      {
        area_id: "office",
        entity_id: "sensor.office_humidity",
      },
      {
        area_id: "kitchen",
        entity_id: "fan.kitchen",
      },
      {
        area_id: "kitchen",
        entity_id: "binary_sensor.kitchen_door",
      },
    ]);
  }
}

declare global {
  interface HTMLElementTagNameMap {
    "demo-hui-area-card": DemoArea;
  }
}
