import type { FC } from 'react'
import React from 'react'
import { useTranslation } from 'react-i18next'
import type { ScheduleTriggerNodeType } from './types'
import type { NodeProps } from '@/app/components/workflow/types'
import { getNextExecutionTime } from './utils/execution-time-calculator'
import TimezoneLabel from '@/app/components/base/timezone-label'

const i18nPrefix = 'workflow.nodes.triggerSchedule'

const Node: FC<NodeProps<ScheduleTriggerNodeType>> = ({
  data,
}) => {
  const { t } = useTranslation()

  return (
    <div className="mb-1 px-3 py-1">
      <div className="mb-1 text-[10px] font-medium uppercase tracking-wide text-text-tertiary">
        {t(`${i18nPrefix}.nextExecutionTime`)}
      </div>
      <div className="flex h-[26px] items-center rounded-md bg-workflow-block-parma-bg px-2 text-xs text-text-secondary">
        <div className="flex w-0 grow items-center gap-1 overflow-hidden">
          <span className="truncate" title={`${getNextExecutionTime(data)} ${data.timezone}`}>
            {getNextExecutionTime(data)}
          </span>
          <TimezoneLabel timezone={data.timezone} inline className="shrink-0 text-xs" />
        </div>
      </div>
    </div>
  )
}

export default React.memo(Node)
