import { RadioChecked, RadioUnchecked } from "@app/assets/images/icons";
import { RadioProps } from "@app/models/components";
import React from "react";
import "./radio-styles.scss";

const Radio: React.FC<RadioProps> = ({
  name,
  id = "",
  onChange,
  value,
  checked,
  label,
  size = "md",
  icons,
}) => {
  const sizeMapping = {
    sm: "radio-sm",
    md: "radio-md",
    lg: "radio-lg",
  };

  const checkedIcon = icons?.checkedIcon || RadioChecked;
  const uncheckedIcon = icons?.uncheckedIcon || RadioUnchecked;

  return (
    <div id={id} className={`radio-wrapper ${label ? "has-label" : ""}`}>
      <span
        className={`radio-root ${
          checked ? "radio-checked" : "radio-unchecked"
        }`}
      >
        <input
          className="radio"
          type="radio"
          name={name}
          value={value}
          checked={checked ?? false}
          onChange={onChange}
        />
        <span className={`radio-icon ${sizeMapping[size]}`}>
          {checked ? checkedIcon : uncheckedIcon}
        </span>
      </span>
      {label && <label htmlFor={id}>{label}</label>}
    </div>
  );
};

export default Radio;
