"use client";

import { FC } from "react";
import { IconPlus } from "@tabler/icons-react";
import { Box, Group, Text } from "@mantine/core";
import CreateServiceKitButton from "@/app/services/components/desktop/CreateServiceKitButton/CreateServiceKitButton";
import ServiceTabSegmentedControl, {
    ServicesTab,
} from "@/app/services/components/shared/ServiceTabSegmentedControl/ServiceTabSegmentedControl";
import useCategoriesActions from "@/app/services/hooks/useCategoriesActions";
import useServicesActions from "@/app/services/hooks/useServicesActions";
import InlineButton from "@/components/ui/InlineButton/InlineButton";

type Props = {
    serviceTab: ServicesTab;
    onServiceTabChange: (serviceTab: ServicesTab) => void;
};

const ServicesDesktopHeader: FC<Props> = ({
    serviceTab,
    onServiceTabChange,
}) => {
    const { onCreateService } = useServicesActions();
    const { onCreateCategory } = useCategoriesActions();

    const getTabActions = () => {
        switch (serviceTab) {
            case ServicesTab.DEAL_SERVICE:
            case ServicesTab.PRODUCT_SERVICE:
                return (
                    <Group>
                        <InlineButton onClick={onCreateService}>
                            <IconPlus />
                            <Text>Услуга</Text>
                        </InlineButton>
                        <InlineButton onClick={onCreateCategory}>
                            <IconPlus />
                            <Text>Категория</Text>
                        </InlineButton>
                    </Group>
                );
            case ServicesTab.SERVICES_KITS:
                return <CreateServiceKitButton />;
            default:
                return <Box />;
        }
    };

    return (
        <Group
            wrap={"nowrap"}
            justify={"space-between"}>
            {getTabActions()}
            <ServiceTabSegmentedControl
                value={serviceTab}
                onChange={onServiceTabChange}
            />
        </Group>
    );
};

export default ServicesDesktopHeader;
