import { test, expect } from '@playwright/test';

test.describe('Incident Time Validation', () => {
  test('incident time accepts H:i:s format', async ({ page }) => {
    await page.goto('/hr-manager/incidents/create');

    await page.waitForTimeout(2000);

    const incidentTypeLabel = page.getByLabel('Incident Type', { exact: false });
    if (await incidentTypeLabel.isVisible()) {
      await incidentTypeLabel.click();
      await page.waitForTimeout(500);

      const firstOption = page.locator('.ant-select-dropdown .ant-select-item').first();
      if (await firstOption.isVisible()) {
        await firstOption.click();
      }
    }

    const severityLabel = page.getByLabel('Severity', { exact: false });
    if (await severityLabel.isVisible()) {
      await severityLabel.click();
      await page.waitForTimeout(500);

      const firstSeverity = page.locator('.ant-select-dropdown .ant-select-item').first();
      if (await firstSeverity.isVisible()) {
        await firstSeverity.click();
      }
    }

    const descriptionField = page.getByLabel('Description', { exact: true });
    if (await descriptionField.isVisible()) {
      await descriptionField.fill('Test incident for time validation');
    }

    const timeField = page.getByLabel(/incident time/i);
    if (await timeField.isVisible()) {
      await timeField.fill('14:30:00');
    }

    const submitButton = page.getByRole('button', { name: /submit|save|create/i });
    if (await submitButton.isVisible()) {
      await submitButton.click();

      await expect(page.getByText(/incident_time.*format/i)).not.toBeVisible();
    } else {
      test.skip(true, 'Submit button not found - form structure may differ');
    }
  });
});
