import { Label } from "../Widgets/DomainProps";

export interface LabelProps {
  label?: Partial<Label>;
  className?: string;
  id?: string;
  [key: string]: any;
}

function withLabel(Component: React.ComponentType<any>) {
  return (props: any) => {
    const labelProps: Label = { ...props.label } as Label;

    return labelProps.isApply ? (
      <div>
        <label
          htmlFor={props.id}
          id={labelProps.widgetStyle?.id ?? ""}
          className={`${labelProps.widgetStyle?.className ?? ""}`}
          style={labelProps.widgetStyle?.inline ?? {}}
        >
          <span>{labelProps.title}</span>
        </label>
        <Component {...props} />
      </div>
    ) : (
      <Component {...props} />
    );
  };
}

export default withLabel;
