'use client';
import { jsxDEV as _jsxDEV } from "react/jsx-dev-runtime";
import { getTranslation } from '@payloadcms/translations';
import { tabHasName } from 'payload/shared';
import React, { useState } from 'react';
import { ErrorPill } from '../../../elements/ErrorPill/index.js';
import { WatchChildErrors } from '../../../forms/WatchChildErrors/index.js';
import { useTranslation } from '../../../providers/Translation/index.js';
import './index.scss';
const baseClass = 'tabs-field__tab-button';
export const TabComponent = ({ hidden, isActive, parentPath, setIsActive, tab })=>{
    const { i18n } = useTranslation();
    const [errorCount, setErrorCount] = useState(undefined);
    const path = [
        // removes parent 'tabs' path segment, i.e. `_index-0`
        ...parentPath ? parentPath.split('.').slice(0, -1) : [],
        ...tabHasName(tab) ? [
            tab.name
        ] : []
    ];
    const fieldHasErrors = errorCount > 0;
    return /*#__PURE__*/ _jsxDEV(React.Fragment, {
        children: [
            /*#__PURE__*/ _jsxDEV(WatchChildErrors, {
                fields: tab.fields,
                path: path,
                setErrorCount: setErrorCount
            }, void 0, false, {
                fileName: "src/fields/Tabs/Tab/index.tsx",
                lineNumber: 44,
                columnNumber: 7
            }, this),
            /*#__PURE__*/ _jsxDEV("button", {
                className: [
                    baseClass,
                    fieldHasErrors && `${baseClass}--has-error`,
                    isActive && `${baseClass}--active`,
                    hidden && `${baseClass}--hidden`
                ].filter(Boolean).join(' '),
                onClick: setIsActive,
                type: "button",
                children: [
                    tab.label ? getTranslation(tab.label, i18n) : tabHasName(tab) ? tab.name : '',
                    fieldHasErrors && /*#__PURE__*/ _jsxDEV(ErrorPill, {
                        count: errorCount,
                        i18n: i18n
                    }, void 0, false, {
                        fileName: "src/fields/Tabs/Tab/index.tsx",
                        lineNumber: 58,
                        columnNumber: 28
                    }, this)
                ]
            }, void 0, true, {
                fileName: "src/fields/Tabs/Tab/index.tsx",
                lineNumber: 45,
                columnNumber: 7
            }, this)
        ]
    }, void 0, true, {
        fileName: "src/fields/Tabs/Tab/index.tsx",
        lineNumber: 43,
        columnNumber: 5
    }, this);
};

//# sourceMappingURL=index.js.map