import { Card } from '@/components/ui/card'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Switch } from '@/components/ui/switch'
import { SystemSettings } from '@/types/system-params'

interface PasswordPolicyCardProps {
  settings: SystemSettings
  onSettingsChange: (updates: Partial<SystemSettings>) => void
}

export function PasswordPolicyCard({ settings, onSettingsChange }: PasswordPolicyCardProps) {
  const updatePasswordPolicy = (updates: Partial<SystemSettings['passwordPolicy']>) => {
    onSettingsChange({
      passwordPolicy: { ...settings.passwordPolicy, ...updates }
    })
  }

  return (
    <Card className="p-6">
      <h3 className="mb-4">密码策略</h3>
      <div className="space-y-4">
        <div>
          <Label>最小密码长度</Label>
          <Input
            type="number"
            value={settings.passwordPolicy.minLength}
            onChange={(e) => updatePasswordPolicy({ minLength: parseInt(e.target.value) || 8 })}
            min={6}
            max={32}
          />
        </div>
        <div className="space-y-3">
          <Label>密码复杂度要求</Label>
          <div className="flex items-center justify-between">
            <span className="text-sm">要求包含大写字母</span>
            <Switch
              checked={settings.passwordPolicy.requireUppercase}
              onCheckedChange={(checked) => updatePasswordPolicy({ requireUppercase: checked })}
            />
          </div>
          <div className="flex items-center justify-between">
            <span className="text-sm">要求包含小写字母</span>
            <Switch
              checked={settings.passwordPolicy.requireLowercase}
              onCheckedChange={(checked) => updatePasswordPolicy({ requireLowercase: checked })}
            />
          </div>
          <div className="flex items-center justify-between">
            <span className="text-sm">要求包含数字</span>
            <Switch
              checked={settings.passwordPolicy.requireNumbers}
              onCheckedChange={(checked) => updatePasswordPolicy({ requireNumbers: checked })}
            />
          </div>
          <div className="flex items-center justify-between">
            <span className="text-sm">要求包含特殊字符</span>
            <Switch
              checked={settings.passwordPolicy.requireSpecialChars}
              onCheckedChange={(checked) => updatePasswordPolicy({ requireSpecialChars: checked })}
            />
          </div>
        </div>
      </div>
    </Card>
  )
}