import n from "../utils/index.js";
import a from "./type.js";
import { TYPE as s } from "../constants.js";
class l {
  /* CONSTRUCTOR */
  constructor(t, e) {
    this.color = e, this.changed = !1, this.data = t, this.type = new a();
  }
  /* API */
  set(t, e) {
    return this.color = e, this.changed = !1, this.data = t, this.type.type = s.ALL, this;
  }
  /* HELPERS */
  _ensureHSL() {
    const t = this.data, { h: e, s: h, l: i } = t;
    e === void 0 && (t.h = n.channel.rgb2hsl(t, "h")), h === void 0 && (t.s = n.channel.rgb2hsl(t, "s")), i === void 0 && (t.l = n.channel.rgb2hsl(t, "l"));
  }
  _ensureRGB() {
    const t = this.data, { r: e, g: h, b: i } = t;
    e === void 0 && (t.r = n.channel.hsl2rgb(t, "r")), h === void 0 && (t.g = n.channel.hsl2rgb(t, "g")), i === void 0 && (t.b = n.channel.hsl2rgb(t, "b"));
  }
  /* GETTERS */
  get r() {
    const t = this.data, e = t.r;
    return !this.type.is(s.HSL) && e !== void 0 ? e : (this._ensureHSL(), n.channel.hsl2rgb(t, "r"));
  }
  get g() {
    const t = this.data, e = t.g;
    return !this.type.is(s.HSL) && e !== void 0 ? e : (this._ensureHSL(), n.channel.hsl2rgb(t, "g"));
  }
  get b() {
    const t = this.data, e = t.b;
    return !this.type.is(s.HSL) && e !== void 0 ? e : (this._ensureHSL(), n.channel.hsl2rgb(t, "b"));
  }
  get h() {
    const t = this.data, e = t.h;
    return !this.type.is(s.RGB) && e !== void 0 ? e : (this._ensureRGB(), n.channel.rgb2hsl(t, "h"));
  }
  get s() {
    const t = this.data, e = t.s;
    return !this.type.is(s.RGB) && e !== void 0 ? e : (this._ensureRGB(), n.channel.rgb2hsl(t, "s"));
  }
  get l() {
    const t = this.data, e = t.l;
    return !this.type.is(s.RGB) && e !== void 0 ? e : (this._ensureRGB(), n.channel.rgb2hsl(t, "l"));
  }
  get a() {
    return this.data.a;
  }
  /* SETTERS */
  set r(t) {
    this.type.set(s.RGB), this.changed = !0, this.data.r = t;
  }
  set g(t) {
    this.type.set(s.RGB), this.changed = !0, this.data.g = t;
  }
  set b(t) {
    this.type.set(s.RGB), this.changed = !0, this.data.b = t;
  }
  set h(t) {
    this.type.set(s.HSL), this.changed = !0, this.data.h = t;
  }
  set s(t) {
    this.type.set(s.HSL), this.changed = !0, this.data.s = t;
  }
  set l(t) {
    this.type.set(s.HSL), this.changed = !0, this.data.l = t;
  }
  set a(t) {
    this.changed = !0, this.data.a = t;
  }
}
export {
  l as default
};
