/**
 * Copyright 2024 Phenix Real Time Solutions, Inc. Confidential and Proprietary. All Rights Reserved.
 */
import React, {Fragment} from 'react';

import moment from 'moment';

import {ISelectItemWithClassOptions} from 'interfaces';

import RadioButtonGroup from 'components/buttons/radio-button';
import {Label} from 'components/label';

import {RadioButtonContainer} from '.';

export const validityTimeOptions: ISelectItemWithClassOptions<string> = {
  hour: {
    label: '1 Hour',
    value: `${moment.duration(1, 'hour').asSeconds()}`
  },
  day: {
    label: '1 Day',
    value: `${moment.duration(1, 'day').asSeconds()}`
  },
  week: {
    label: '1 Week',
    value: `${moment.duration(1, 'week').asSeconds()}`
  },
  month: {
    label: '1 Month',
    value: `${moment.duration(1, 'month').asSeconds()}`
  },
  year: {
    label: '1 Year',
    value: `${moment.duration(1, 'year').asSeconds()}`
  },
  decade: {
    label: '10 Years',
    value: `${moment.duration(10, 'year').asSeconds()}`
  }
};

interface IValidityTimeComponent {
  onChange: (value: string) => void;
  currentValue: string;
}

export const ValidityTimeComponent = ({currentValue, onChange}: IValidityTimeComponent): React.JSX.Element => (
  <Fragment>
    <Label text="Valid For:" color="white" />
    <RadioButtonContainer className="testId-expirationTime">
      <RadioButtonGroup
        items={Object.values(validityTimeOptions)}
        currentValue={currentValue}
        handleOnChange={onChange}
      />
    </RadioButtonContainer>
  </Fragment>
);

export default ValidityTimeComponent;