import * as R from "ramda";
import { toNumber } from "@applicaster/zapp-react-native-utils/numberUtils";

const Image = "Image";

type Props = {
  prefix: string;
  value: Function;
  pluginIdentifier: string;
};

export const Asset = ({ prefix, value, pluginIdentifier }: Props) => {
  if (!value(`${prefix}_asset_enabled`)) return null;

  return {
    type: Image,
    style: {
      marginTop: value(`${prefix}_asset_margin_top`),
      marginRight: value(`${prefix}_asset_margin_right`),
      marginBottom: value(`${prefix}_asset_margin_bottom`),
      marginLeft: value(`${prefix}_asset_margin_left`),

      width: toNumber(value(`${prefix}_asset_width`)) || 40,
      height: toNumber(value(`${prefix}_asset_height`)) || 40,
    },
    data: [
      {
        func: R.identity,
        args: [],
        propName: "entry",
      },
    ],
    additionalProps: {
      resizeMode: "cover",
      source: {
        context: pluginIdentifier,
      },
    },
  };
};
