import { FC } from "react";
import { IconCheck, IconX } from "@tabler/icons-react";
import { AttributeSchema } from "@/lib/client";
import {
    naiveDateTimeStringToUtc,
    utcDateTimeToLocalString,
    utcDateToLocalString,
} from "@/utils/datetime";

type Props = {
    attribute: AttributeSchema;
};

const AttributeDefaultValue: FC<Props> = ({ attribute }) => {
    if (!attribute.defaultValue) return <>-</>;
    const value = attribute.defaultValue;
    if (value === null) return <>-</>;

    const type = attribute.type.type;
    if (type === "datetime") {
        return utcDateTimeToLocalString(
            naiveDateTimeStringToUtc(value as string)
        );
    }
    if (type === "date") {
        return utcDateToLocalString(value as string);
    }
    if (type === "bool") {
        return value ? <IconCheck /> : <IconX />;
    }

    return <>{value}</>;
};

export default AttributeDefaultValue;
