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 && !attribute.defaultOption) return <>-</>;
    const value = attribute.defaultValue;

    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 />;
    }
    if (type === "select") {
        return attribute.defaultOption?.label;
    }

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

export default AttributeDefaultValue;
