'use client';
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import { getTranslation } from '@payloadcms/translations';
import { useRouter } from 'next/navigation.js';
import { formatAdminURL } from 'payload/shared';
import React from 'react';
import { usePreferences } from '../../providers/Preferences/index.js';
import { useTranslation } from '../../providers/Translation/index.js';
import { Button } from '../Button/index.js';
import './index.scss';
const baseClass = 'default-list-view-tabs';
export const DefaultListViewTabs = ({ collectionConfig, config, onChange, viewType })=>{
    const { i18n, t } = useTranslation();
    const { setPreference } = usePreferences();
    const router = useRouter();
    const isTrashEnabled = collectionConfig.trash;
    const isFoldersEnabled = collectionConfig.folders && config.folders;
    if (!isTrashEnabled && !isFoldersEnabled) {
        return null;
    }
    const handleViewChange = async (newViewType)=>{
        if (onChange) {
            onChange(newViewType);
        }
        if (newViewType === 'list' || newViewType === 'folders') {
            await setPreference(`collection-${collectionConfig.slug}`, {
                listViewType: newViewType
            });
        }
        let path = `/collections/${collectionConfig.slug}`;
        switch(newViewType){
            case 'folders':
                if (config.folders) {
                    path = `/collections/${collectionConfig.slug}/${config.folders.slug}`;
                }
                break;
            case 'trash':
                path = `/collections/${collectionConfig.slug}/trash`;
                break;
        }
        const url = formatAdminURL({
            adminRoute: config.routes.admin,
            path
        });
        router.push(url);
    };
    const allButtonLabel = `${t('general:all')} ${getTranslation(collectionConfig?.labels?.plural, i18n)}`;
    const allButtonId = allButtonLabel.toLowerCase().replace(/\s+/g, '-');
    return /*#__PURE__*/ _jsxDEV("div", {
        className: baseClass,
        children: [
            /*#__PURE__*/ _jsxDEV(Button, {
                buttonStyle: "tab",
                className: [
                    `${baseClass}__button`,
                    viewType === 'list' && `${baseClass}__button--active`
                ].filter(Boolean).join(' '),
                disabled: viewType === 'list',
                el: "button",
                id: allButtonId,
                onClick: ()=>handleViewChange('list'),
                children: [
                    t('general:all'),
                    " ",
                    getTranslation(collectionConfig?.labels?.plural, i18n)
                ]
            }, void 0, true, {
                fileName: "src/elements/DefaultListViewTabs/index.tsx",
                lineNumber: 76,
                columnNumber: 7
            }, this),
            isFoldersEnabled && /*#__PURE__*/ _jsxDEV(Button, {
                buttonStyle: "tab",
                className: [
                    `${baseClass}__button`,
                    viewType === 'folders' && `${baseClass}__button--active`
                ].filter(Boolean).join(' '),
                disabled: viewType === 'folders',
                el: "button",
                onClick: ()=>handleViewChange('folders'),
                children: t('folder:byFolder')
            }, void 0, false, {
                fileName: "src/elements/DefaultListViewTabs/index.tsx",
                lineNumber: 90,
                columnNumber: 9
            }, this),
            isTrashEnabled && /*#__PURE__*/ _jsxDEV(Button, {
                buttonStyle: "tab",
                className: [
                    `${baseClass}__button`,
                    viewType === 'trash' && `${baseClass}__button--active`
                ].filter(Boolean).join(' '),
                disabled: viewType === 'trash',
                el: "button",
                id: "trash-view-pill",
                onClick: ()=>handleViewChange('trash'),
                children: t('general:trash')
            }, void 0, false, {
                fileName: "src/elements/DefaultListViewTabs/index.tsx",
                lineNumber: 107,
                columnNumber: 9
            }, this)
        ]
    }, void 0, true, {
        fileName: "src/elements/DefaultListViewTabs/index.tsx",
        lineNumber: 75,
        columnNumber: 5
    }, this);
};

//# sourceMappingURL=index.js.map