import type { Meta, StoryObj } from "@storybook/react";
import { SecretsManager } from "./secrets-manager";

const meta: Meta<typeof SecretsManager> = {
	title: "Widgets/SecretsManager",
	component: SecretsManager,
	parameters: {
		layout: "padded",
	},
	tags: ["autodocs"],
	argTypes: {
		secrets: { control: false },
		environments: { control: "object" },
		currentEnvironment: { control: "text" },
		hideValues: { control: "boolean" },
		editable: { control: "boolean" },
		onEnvironmentChange: { action: "environment changed" },
		onCreate: { action: "secret created" },
		onUpdate: { action: "secret updated" },
		onDelete: { action: "secret deleted" },
	},
};

export default meta;
type Story = StoryObj<typeof meta>;

/**
 * Default secrets manager with standard configuration.
 * Shows empty state ready for adding secrets.
 */
export const Default: Story = {
	args: {
		secrets: [],
		environments: ["development", "staging", "production"],
		currentEnvironment: "development",
		hideValues: true,
		editable: true,
	},
};

/**
 * Secrets manager populated with various secrets.
 * Demonstrates how secrets are displayed in a table.
 */
export const WithSecrets: Story = {
	args: {
		secrets: [
			{
				id: "1",
				key: "DATABASE_URL",
				value: "postgresql://user:password@localhost:5432/mydb",
				description: "Main database connection string",
				environment: "production",
				tags: ["database", "critical"],
				createdAt: new Date("2024-01-15"),
				updatedAt: new Date("2024-01-15"),
			},
			{
				id: "2",
				key: "API_KEY",
				value: "sk_live_1234567890abcdef",
				description: "Stripe API key for payment processing",
				environment: "production",
				tags: ["payment", "api"],
				createdAt: new Date("2024-01-16"),
				updatedAt: new Date("2024-01-20"),
			},
			{
				id: "3",
				key: "JWT_SECRET",
				value: "super-secret-jwt-signing-key-do-not-share",
				description: "Secret key for JWT token signing",
				environment: "production",
				tags: ["auth", "critical"],
				createdAt: new Date("2024-01-17"),
				updatedAt: new Date("2024-01-17"),
			},
			{
				id: "4",
				key: "REDIS_URL",
				value: "redis://localhost:6379",
				description: "Redis cache connection",
				environment: "production",
				tags: ["cache"],
				createdAt: new Date("2024-01-18"),
				updatedAt: new Date("2024-01-18"),
			},
		],
		environments: ["development", "staging", "production"],
		currentEnvironment: "production",
		hideValues: true,
		editable: true,
	},
};

/**
 * Secrets manager with multiple environments.
 * Shows secrets filtered by environment.
 */
export const MultipleEnvironments: Story = {
	args: {
		secrets: [
			{
				id: "1",
				key: "API_KEY",
				value: "sk_test_1234567890abcdef",
				description: "Test API key",
				environment: "development",
				tags: ["api"],
				createdAt: new Date("2024-01-15"),
				updatedAt: new Date("2024-01-15"),
			},
			{
				id: "2",
				key: "API_KEY",
				value: "sk_staging_1234567890abcdef",
				description: "Staging API key",
				environment: "staging",
				tags: ["api"],
				createdAt: new Date("2024-01-16"),
				updatedAt: new Date("2024-01-16"),
			},
			{
				id: "3",
				key: "API_KEY",
				value: "sk_live_1234567890abcdef",
				description: "Production API key",
				environment: "production",
				tags: ["api", "critical"],
				createdAt: new Date("2024-01-17"),
				updatedAt: new Date("2024-01-17"),
			},
			{
				id: "4",
				key: "DATABASE_URL",
				value: "postgresql://localhost:5432/dev",
				description: "Development database",
				environment: "development",
				tags: ["database"],
				createdAt: new Date("2024-01-18"),
				updatedAt: new Date("2024-01-18"),
			},
			{
				id: "5",
				key: "DATABASE_URL",
				value: "postgresql://staging.example.com.ai:5432/staging",
				description: "Staging database",
				environment: "staging",
				tags: ["database"],
				createdAt: new Date("2024-01-19"),
				updatedAt: new Date("2024-01-19"),
			},
			{
				id: "6",
				key: "DATABASE_URL",
				value: "postgresql://prod.example.com.ai:5432/production",
				description: "Production database",
				environment: "production",
				tags: ["database", "critical"],
				createdAt: new Date("2024-01-20"),
				updatedAt: new Date("2024-01-20"),
			},
		],
		environments: ["development", "staging", "production"],
		currentEnvironment: "development",
		hideValues: true,
		editable: true,
	},
};

/**
 * Empty state showing no secrets configured.
 * Useful for initial setup screens.
 */
export const EmptyState: Story = {
	args: {
		secrets: [],
		environments: ["development", "staging", "production"],
		currentEnvironment: "production",
		hideValues: true,
		editable: true,
	},
};

/**
 * Read-only secrets manager.
 * Users can view but not edit secrets.
 */
export const ReadOnly: Story = {
	args: {
		secrets: [
			{
				id: "1",
				key: "DATABASE_URL",
				value: "postgresql://user:password@localhost:5432/mydb",
				description: "Main database connection string",
				environment: "production",
				tags: ["database"],
				createdAt: new Date("2024-01-15"),
				updatedAt: new Date("2024-01-15"),
			},
			{
				id: "2",
				key: "API_KEY",
				value: "sk_live_1234567890abcdef",
				description: "API key for external service",
				environment: "production",
				tags: ["api"],
				createdAt: new Date("2024-01-16"),
				updatedAt: new Date("2024-01-16"),
			},
		],
		environments: ["development", "staging", "production"],
		currentEnvironment: "production",
		hideValues: true,
		editable: false,
	},
};
