import { SegmentedControl, SegmentedControlProps } from "@mantine/core";
import { FC } from "react";
import { omit } from "lodash";

export enum ServicePriceType {
    DEFAULT,
    BY_RANGE,
    BY_CATEGORY,
}

type RestProps = {
    onChange: (value: ServicePriceType) => void;
    value?: ServicePriceType;
};
type Props = Omit<SegmentedControlProps, "data" | "value" | "onChange"> &
    RestProps;
const ServicePriceTypeSegmentedControl: FC<Props> = props => {
    const { onChange, value } = props;

    const data = [
        {
            label: "По умолчанию",
            value: ServicePriceType.DEFAULT.toString(),
        },
        {
            label: "По диапазону",
            value: ServicePriceType.BY_RANGE.toString(),
        },
        {
            label: "По категории",
            value: ServicePriceType.BY_CATEGORY.toString(),
        },
    ];
    const handleChange = (value: string) => {
        onChange(Number(value));
    };

    const restProps = omit(props, ["onChange", "value"]);
    return (
        <SegmentedControl
            data={data}
            value={value?.toString()}
            onChange={handleChange}
            {...restProps}
        />
    );
};

export default ServicePriceTypeSegmentedControl;
