import { ColumnItem } from "@queenjs/components/FormUI";
import { colorToHex, hexToColor } from "@queenjs/utils";

export function createColorOpts(): Pick<
  ColumnItem,
  "getValue" | "changeExtra" | "component"
> {
  return {
    component: "ColorPicker",
    getValue(v) {
      try {
        return hexToColor(v);
      } catch (error) {
        return [0, 0, 0];
      }
    },
    changeExtra(data) {
      data.value = colorToHex(data.value);
      return data;
    },
  };
}
