import {
  Component, h, useEffect, useProp,
} from "atomico";
import {Option}  from "funfix";
import style from "./kun-icon.scss";


import { getComponentOrDefine } from "../../hooks/aync-hook/redirect";

const KunIcon = () => {
  const [type] = useProp<string>("iconType");
  const [iconType, setIconType] = useProp<string>("title");
  const iconTypes = type ?? iconType;
  const [height] = useProp<number>("iconHeight");
  const [width] = useProp<number>("iconWidth");
  const clsName = `icon icon-${Option.of(iconTypes).getOrElse("zan")}`;

  useEffect(() => {
    setIconType(type);
  }, [iconType, type]);

  return (
    <host>
      <style>{style}</style>
      {
        type != null && (
        <div className={clsName} style={{ width: `${width}px`, height: `${height}px` }} />
        )
      }
    </host>
  );
};

KunIcon.props = {
  iconType: {
    type: String,
  },
  title: {
    type: String,
  },
  iconWidth: {
    type: Number,
    value: 40,
    reflect: true,
  },
  iconHeight: {
    type: Number,
    value: 40,
    reflect: true,
  },
  height: {
    type: Number,
    value: 40,
    reflect: true,
  },
  width: {
    type: Number,
    value: 40,
    reflect: true,
  },
};

export default getComponentOrDefine("kun-icon", KunIcon);
